1e6f856bfbb0472e33c3489823cbb5429333cd59
[openafs.git] / src / auth / userok.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14 #include <roken.h>
15 #include <afs/opr.h>
16
17 #include <ctype.h>
18
19 #include <afs/pthread_glock.h>
20 #include <rx/xdr.h>
21 #include <rx/rx.h>
22 #include <rx/rx_identity.h>
23 #include <afs/afsutil.h>
24 #include <afs/fileutil.h>
25
26 #include "base64.h"
27 #include "auth.h"
28 #include "cellconfig.h"
29 #include "keys.h"
30 #include "afs/audit.h"
31
32 /* The display names for localauth and noauth identities; they aren't used
33  * inside tickets or anything, but just serve as something to display in logs,
34  * etc. */
35 #define AFS_LOCALAUTH_NAME "<LocalAuth>"
36 #define AFS_LOCALAUTH_LEN  (sizeof(AFS_LOCALAUTH_NAME)-1)
37 #define AFS_NOAUTH_NAME "<NoAuth>"
38 #define AFS_NOAUTH_LEN  (sizeof(AFS_NOAUTH_NAME)-1)
39
40 static int ParseLine(char *buffer, struct rx_identity *user);
41
42 static void
43 UserListFileName(struct afsconf_dir *adir,
44                  char *buffer, size_t len)
45 {
46     strcompose(buffer, len, adir->name, "/",
47                AFSDIR_ULIST_FILE, NULL);
48 }
49
50 #if !defined(UKERNEL)
51 int
52 afsconf_CheckAuth(void *arock, struct rx_call *acall)
53 {
54     struct afsconf_dir *adir = (struct afsconf_dir *) arock;
55     int rc;
56     LOCK_GLOBAL_MUTEX;
57     rc = ((afsconf_SuperUser(adir, acall, NULL) == 0) ? 10029 : 0);
58     UNLOCK_GLOBAL_MUTEX;
59     return rc;
60 }
61 #endif /* !defined(UKERNEL) */
62
63 static int
64 GetNoAuthFlag(struct afsconf_dir *adir)
65 {
66     if (access(AFSDIR_SERVER_NOAUTH_FILEPATH, 0) == 0) {
67         osi_audit(NoAuthEvent, 0, AUD_END);     /* some random server is running noauth */
68         return 1;               /* if /usr/afs/local/NoAuth file exists, allow access */
69     }
70     return 0;
71 }
72
73
74 int
75 afsconf_GetNoAuthFlag(struct afsconf_dir *adir)
76 {
77     int rc;
78
79     LOCK_GLOBAL_MUTEX;
80     rc = GetNoAuthFlag(adir);
81     UNLOCK_GLOBAL_MUTEX;
82     return rc;
83 }
84
85 void
86 afsconf_SetNoAuthFlag(struct afsconf_dir *adir, int aflag)
87 {
88     afs_int32 code;
89
90     LOCK_GLOBAL_MUTEX;
91     if (aflag == 0) {
92         /* turn off noauth flag */
93         code = (unlink(AFSDIR_SERVER_NOAUTH_FILEPATH) ? errno : 0);
94         osi_audit(NoAuthDisableEvent, code, AUD_END);
95     } else {
96         /* try to create file */
97         code =
98             open(AFSDIR_SERVER_NOAUTH_FILEPATH, O_CREAT | O_TRUNC | O_RDWR,
99                  0666);
100         if (code >= 0) {
101             close(code);
102             osi_audit(NoAuthEnableEvent, 0, AUD_END);
103         } else
104             osi_audit(NoAuthEnableEvent, errno, AUD_END);
105     }
106     UNLOCK_GLOBAL_MUTEX;
107 }
108
109 /*!
110  * Remove an identity from the UserList file
111  *
112  * This function removes the given identity from the user list file.
113  * For the purposes of identifying entries to remove, only the
114  * type and exportedName portions of the identity are used. Callers
115  * should remember that a given identity may be listed in the file in
116  * a number of different ways.
117  *
118  * @param adir
119  *      A structure representing the configuration directory currently
120  *      in use
121  * @param user
122  *      The RX identity to delete
123  *
124  * @returns
125  *      0 on success, an error code on failure
126  */
127
128 int
129 afsconf_DeleteIdentity(struct afsconf_dir *adir, struct rx_identity *user)
130 {
131     char tbuffer[1024];
132     char nbuffer[1024];
133     char *copy;
134     FILE *tf;
135     FILE *nf;
136     int flag;
137     char *tp;
138     int found;
139     struct stat tstat;
140     struct rx_identity identity;
141     afs_int32 code;
142
143     memset(&identity, 0, sizeof(struct rx_identity));
144
145     LOCK_GLOBAL_MUTEX;
146     UserListFileName(adir, tbuffer, sizeof tbuffer);
147 #ifndef AFS_NT40_ENV
148     {
149         /*
150          * We attempt to fully resolve this pathname, so that the rename
151          * of the temporary file will work even if UserList is a symlink
152          * into a different filesystem.
153          */
154         char resolved_path[1024];
155
156         if (realpath(tbuffer, resolved_path)) {
157             strcpy(tbuffer, resolved_path);
158         }
159     }
160 #endif /* AFS_NT40_ENV */
161     tf = fopen(tbuffer, "r");
162     if (!tf) {
163         UNLOCK_GLOBAL_MUTEX;
164         return -1;
165     }
166     code = stat(tbuffer, &tstat);
167     if (code < 0) {
168         UNLOCK_GLOBAL_MUTEX;
169         return code;
170     }
171     strcpy(nbuffer, tbuffer);
172     strcat(nbuffer, ".NXX");
173     nf = fopen(nbuffer, "w+");
174     if (!nf) {
175         fclose(tf);
176         UNLOCK_GLOBAL_MUTEX;
177         return EIO;
178     }
179     flag = 0;
180     found = 0;
181     while (1) {
182         /* check for our user id */
183         tp = fgets(nbuffer, sizeof(nbuffer), tf);
184         if (tp == NULL)
185             break;
186
187         copy = strdup(nbuffer);
188         if (copy == NULL) {
189             flag = 1;
190             break;
191         }
192         code = ParseLine(copy, &identity);
193         if (code == 0 && rx_identity_match(user, &identity)) {
194             /* found the guy, don't copy to output file */
195             found = 1;
196         } else {
197             /* otherwise copy original line to output */
198             fprintf(nf, "%s", nbuffer);
199         }
200         free(copy);
201         rx_identity_freeContents(&identity);
202     }
203     fclose(tf);
204     if (ferror(nf))
205         flag = 1;
206     if (fclose(nf) == EOF)
207         flag = 1;
208     strcpy(nbuffer, tbuffer);
209     strcat(nbuffer, ".NXX");    /* generate new file name again */
210     if (flag == 0) {
211         /* try the rename */
212         flag = renamefile(nbuffer, tbuffer);
213         if (flag == 0)
214             flag = chmod(tbuffer, tstat.st_mode);
215     } else
216         unlink(nbuffer);
217
218     /* finally, decide what to return to the caller */
219     UNLOCK_GLOBAL_MUTEX;
220     if (flag)
221         return EIO;             /* something mysterious went wrong */
222     if (!found)
223         return ENOENT;          /* entry wasn't found, no changes made */
224     return 0;                   /* everything was fine */
225 }
226
227 /*!
228  * Remove a legacy Kerberos 4 name from the UserList file.
229  *
230  * This function removes a Kerberos 4 name from the super user list. It
231  * can only remove names which were added by the afsconf_AddUser interface,
232  * or with an explicit Kerberos v4 type.
233  *
234  * @param[in] adir
235  *      A structure representing the configuration directory
236  * @param[in] name
237  *      The Kerberos v4 name to remove
238  *
239  * @returns
240  *      0 on success, an error code upon failure.
241  *
242  * Note that this function is deprecated. New callers should use
243  * afsconf_DeleteIdentity instead.
244  */
245
246 int
247 afsconf_DeleteUser(struct afsconf_dir *adir, char *name)
248 {
249     struct rx_identity *user;
250     int code;
251
252     user = rx_identity_new(RX_ID_KRB4, name, name, strlen(name));
253     if (!user)
254         return ENOMEM;
255
256     code = afsconf_DeleteIdentity(adir, user);
257
258     rx_identity_free(&user);
259
260     return code;
261 }
262
263 /* This is a multi-purpose funciton for use by either
264  * GetNthIdentity or GetNthUser. The parameter 'id' indicates
265  * whether we are counting all identities (if true), or just
266  * ones which can be represented by the old-style interfaces
267  */
268 static int
269 GetNthIdentityOrUser(struct afsconf_dir *dir, int count,
270                      struct rx_identity **identity, int id)
271 {
272     bufio_p bp;
273     char tbuffer[1024];
274     struct rx_identity fileUser;
275     afs_int32 code;
276
277     LOCK_GLOBAL_MUTEX;
278     UserListFileName(dir, tbuffer, sizeof(tbuffer));
279     bp = BufioOpen(tbuffer, O_RDONLY, 0);
280     if (!bp) {
281         UNLOCK_GLOBAL_MUTEX;
282         return EIO;
283     }
284     while (1) {
285         code = BufioGets(bp, tbuffer, sizeof(tbuffer));
286         if (code < 0)
287             break;
288
289         code = ParseLine(tbuffer, &fileUser);
290         if (code != 0)
291             break;
292
293         if (id || fileUser.kind == RX_ID_KRB4)
294             count--;
295
296         if (count < 0)
297             break;
298         else
299             rx_identity_freeContents(&fileUser);
300     }
301     if (code == 0) {
302         *identity = rx_identity_copy(&fileUser);
303         rx_identity_freeContents(&fileUser);
304     }
305
306     BufioClose(bp);
307
308     UNLOCK_GLOBAL_MUTEX;
309     return code;
310 }
311
312 /*!
313  * Return the Nth super user identity from the UserList
314  *
315  * @param[in] dir
316  *      A structure representing the configuration directory
317  * @param[in] count
318  *      A count (from zero) of the entries to return from the
319  *      UserList
320  * @param[out] identity
321  *      A pointer to the Nth identity
322  * @returns
323  *      0 on success, non-zero on failure
324  */
325
326 int
327 afsconf_GetNthIdentity(struct afsconf_dir *dir, int count,
328                        struct rx_identity **identity)
329 {
330    return GetNthIdentityOrUser(dir, count, identity, 1);
331 }
332
333 /*!
334  * Return the Nth Kerberos v4 identity from the UserList
335  *
336  * This returns the Nth old, kerberos v4 style name from
337  * the UserList file. In counting entries it skips any other
338  * name types it encounters - so will hide any new-style
339  * identities from its callers.
340  *
341  * @param[in] dir
342  *      A structure representing the configuration directory
343  * @param[in] count
344  *      A count (from zero) of the entries to return from the
345  *      UserList
346  * @param abuffer
347  *      A string in which to write the name of the Nth identity
348  * @param abufferLen
349  *      The length of the buffer passed in abuffer
350  * @returns
351  *      0 on success, non-zero on failure
352  *
353  * This function is deprecated, all new callers should use
354  * GetNthIdentity instead. This function is particularly dangerous
355  * as it will hide any new-style identities from callers.
356  */
357
358 int
359 afsconf_GetNthUser(struct afsconf_dir *adir, afs_int32 an, char *abuffer,
360                    afs_int32 abufferLen)
361 {
362     struct rx_identity *identity;
363     int code;
364
365     code = GetNthIdentityOrUser(adir, an, &identity, 0);
366     if (code == 0) {
367         strlcpy(abuffer, identity->displayName, abufferLen);
368         rx_identity_free(&identity);
369     }
370     return code;
371 }
372
373 /*!
374  * Parse a UserList list
375  *
376  * Parse a line of data from a UserList file
377  *
378  * This parses a line of data in a UserList, and populates the passed
379  * rx_identity structure with the information about the user.
380  *
381  * @param buffer        A string containing the line to be parsed
382  * @param user          The user structure to be populated
383  *
384  * Note that the user->displayName, and user->exportedName.val fields
385  * must be freed with free() by the caller.
386  *
387  * This function damages the buffer thats passed to it. Callers are
388  * expected to make a copy if they want the buffer preserved.
389  *
390  * @return
391  *      0 on success, non-zero on failure.
392  */
393
394 static int
395 ParseLine(char *buffer, struct rx_identity *user)
396 {
397     char *ptr;
398     char *ename;
399     char *displayName;
400     char *decodedName;
401     char name[64+1];
402     int len;
403     int kind;
404     int code;
405
406     if (buffer[0] == ' ') { /* extended names have leading space */
407         ptr = buffer + 1;
408         code = sscanf(ptr, "%i", &kind);
409         if (code != 1)
410             return EINVAL;
411
412         strsep(&ptr, " "); /* skip the bit we just read with scanf */
413         ename = strsep(&ptr, " "); /* Pull out the ename */
414         displayName = strsep(&ptr, " "); /* Display name runs to the end */
415         if (ename == NULL || displayName == NULL)
416             return EINVAL;
417
418         decodedName = malloc(strlen(ename));
419         if (decodedName == NULL)
420             return ENOMEM;
421
422         len = base64_decode(ename, decodedName);
423         if (len<0) {
424             free(decodedName);
425             return EINVAL;
426         }
427
428         rx_identity_populate(user, kind, displayName, decodedName, len);
429         free(decodedName);
430
431         return 0; /* Success ! */
432     }
433
434     /* No extended name, try for a legacy name */
435     code = sscanf(buffer, "%64s", name);
436     if (code != 1)
437         return EINVAL;
438
439     rx_identity_populate(user, RX_ID_KRB4, name, name, strlen(name));
440     return 0;
441 }
442
443 /*!
444  * Check if a given identity is in the UserList file,
445  * and thus is a super user
446  *
447  * @param adir
448  *      A structure representing the configuration directory to check
449  * @param user
450  *      The identity to check
451  * @returns
452  *      True if the user is listed in the UserList, otherwise false
453  */
454
455 int
456 afsconf_IsSuperIdentity(struct afsconf_dir *adir,
457                         struct rx_identity *user)
458 {
459     bufio_p bp;
460     char tbuffer[1024];
461     struct rx_identity fileUser;
462     int match;
463     afs_int32 code;
464
465     UserListFileName(adir, tbuffer, sizeof tbuffer);
466     bp = BufioOpen(tbuffer, O_RDONLY, 0);
467     if (!bp)
468         return 0;
469     match = 0;
470     while (!match) {
471         code = BufioGets(bp, tbuffer, sizeof(tbuffer));
472         if (code < 0)
473             break;
474
475         code = ParseLine(tbuffer, &fileUser);
476         if (code != 0)
477            break;
478
479         match = rx_identity_match(user, &fileUser);
480
481         rx_identity_freeContents(&fileUser);
482     }
483     BufioClose(bp);
484     return match;
485 }
486
487 /* add a user to the user list, checking for duplicates */
488 int
489 afsconf_AddIdentity(struct afsconf_dir *adir, struct rx_identity *user)
490 {
491     FILE *tf;
492     afs_int32 code;
493     char *ename;
494     char tbuffer[256];
495
496     LOCK_GLOBAL_MUTEX;
497     if (afsconf_IsSuperIdentity(adir, user)) {
498         UNLOCK_GLOBAL_MUTEX;
499         return EEXIST;          /* already in the list */
500     }
501
502     UserListFileName(adir, tbuffer, sizeof tbuffer);
503     tf = fopen(tbuffer, "a+");
504     if (!tf) {
505         UNLOCK_GLOBAL_MUTEX;
506         return EIO;
507     }
508     if (user->kind == RX_ID_KRB4) {
509         fprintf(tf, "%s\n", user->displayName);
510     } else {
511         base64_encode(user->exportedName.val, user->exportedName.len,
512                       &ename);
513         fprintf(tf, " %d %s %s\n", user->kind, ename, user->displayName);
514         free(ename);
515     }
516     code = 0;
517     if (ferror(tf))
518         code = EIO;
519     if (fclose(tf))
520         code = EIO;
521     UNLOCK_GLOBAL_MUTEX;
522     return code;
523 }
524
525 int
526 afsconf_AddUser(struct afsconf_dir *adir, char *aname)
527 {
528     struct rx_identity *user;
529     int code;
530
531     user = rx_identity_new(RX_ID_KRB4, aname, aname, strlen(aname));
532     if (user == NULL)
533         return ENOMEM;
534
535     code = afsconf_AddIdentity(adir, user);
536
537     rx_identity_free(&user);
538
539     return code;
540 }
541
542 /* special CompFindUser routine that builds up a princ and then
543         calls finduser on it. If found, returns char * to user string,
544         otherwise returns NULL. The resulting string should be immediately
545         copied to other storage prior to release of mutex. */
546 static int
547 CompFindUser(struct afsconf_dir *adir, char *name, char *sep, char *inst,
548              char *realm, struct rx_identity **identity)
549 {
550     static char fullname[MAXKTCNAMELEN + MAXKTCNAMELEN + MAXKTCREALMLEN + 3];
551     struct rx_identity *testId;
552
553     /* always must have name */
554     if (!name || !name[0]) {
555         return 0;
556     }
557     strcpy(fullname, name);
558
559     /* might have instance */
560     if (inst && inst[0]) {
561         if (!sep || !sep[0]) {
562             return 0;
563         }
564
565         strcat(fullname, sep);
566         strcat(fullname, inst);
567     }
568
569     /* might have realm */
570     if (realm && realm[0]) {
571         strcat(fullname, "@");
572         strcat(fullname, realm);
573     }
574
575     testId = rx_identity_new(RX_ID_KRB4, fullname, fullname, strlen(fullname));
576     if (afsconf_IsSuperIdentity(adir, testId)) {
577         if (identity)
578              *identity = testId;
579         else
580              rx_identity_free(&testId);
581         return 1;
582     }
583
584     rx_identity_free(&testId);
585     return 0;
586 }
587
588 static int
589 kerberosSuperUser(struct afsconf_dir *adir, char *tname, char *tinst,
590                   char *tcell, struct rx_identity **identity)
591 {
592     char tcell_l[MAXKTCREALMLEN] = "";
593     char *tmp;
594     static char lcell[MAXCELLCHARS] = "";
595     static char lrealms[AFS_NUM_LREALMS][AFS_REALM_SZ];
596     static int  num_lrealms = -1;
597     int lrealm_match = 0, i;
598     int flag;
599
600     /* generate lowercased version of cell name */
601     if (tcell) {
602         strcpy(tcell_l, tcell);
603         tmp = tcell_l;
604         while (*tmp) {
605             *tmp = tolower(*tmp);
606             tmp++;
607         }
608     }
609
610     /* determine local cell name. It's static, so will only get
611      * calculated the first time through */
612     if (!lcell[0])
613         afsconf_GetLocalCell(adir, lcell, sizeof(lcell));
614
615     /* if running a krb environment, also get the local realm */
616     /* note - this assumes AFS_REALM_SZ <= MAXCELLCHARS */
617     /* just set it to lcell if it fails */
618     if (num_lrealms == -1) {
619         for (i=0; i<AFS_NUM_LREALMS; i++) {
620             if (afs_krb_get_lrealm(lrealms[i], i) != 0 /*KSUCCESS*/)
621                 break;
622         }
623
624         if (i == 0) {
625             strncpy(lrealms[0], lcell, AFS_REALM_SZ);
626             num_lrealms = 1;
627         } else {
628             num_lrealms = i;
629         }
630     }
631
632     /* See if the ticket cell matches one of the local realms */
633     lrealm_match = 0;
634     for ( i=0;i<num_lrealms;i++ ) {
635         if (!strcasecmp(lrealms[i], tcell)) {
636             lrealm_match = 1;
637             break;
638         }
639     }
640
641     /* If yes, then make sure that the name is not present in
642      * an exclusion list */
643     if (lrealm_match) {
644         char uname[MAXKTCNAMELEN + MAXKTCNAMELEN + MAXKTCREALMLEN + 3];
645         if (tinst && tinst[0])
646             snprintf(uname,sizeof(uname),"%s.%s@%s",tname,tinst,tcell);
647         else
648             snprintf(uname,sizeof(uname),"%s@%s",tname,tcell);
649
650         if (afs_krb_exclusion(uname))
651             lrealm_match = 0;
652     }
653
654     /* start with no authorization */
655     flag = 0;
656
657     /* localauth special case */
658     if ((tinst == NULL || strlen(tinst) == 0) &&
659         (tcell == NULL || strlen(tcell) == 0)
660         && !strcmp(tname, AUTH_SUPERUSER)) {
661         if (identity)
662             *identity = rx_identity_new(RX_ID_KRB4, AFS_LOCALAUTH_NAME,
663                                         AFS_LOCALAUTH_NAME, AFS_LOCALAUTH_LEN);
664         flag = 1;
665
666         /* cell of connection matches local cell or one of the realms */
667     } else if (!strcasecmp(tcell, lcell) || lrealm_match) {
668         if (CompFindUser(adir, tname, ".", tinst, NULL, identity)) {
669             flag = 1;
670         }
671         /* cell of conn doesn't match local cell or realm */
672     } else {
673         if (CompFindUser(adir, tname, ".", tinst, tcell, identity)) {
674             flag = 1;
675         } else if (CompFindUser(adir, tname, ".", tinst, tcell_l, identity)) {
676             flag = 1;
677         }
678     }
679
680     return flag;
681 }
682
683 static int
684 rxkadSuperUser(struct afsconf_dir *adir, struct rx_call *acall,
685                struct rx_identity **identity)
686 {
687     char tname[MAXKTCNAMELEN];  /* authentication from ticket */
688     char tinst[MAXKTCNAMELEN];
689     char tcell[MAXKTCREALMLEN];
690
691     afs_uint32 exp;
692     int code;
693
694     /* get auth details from server connection */
695     code = rxkad_GetServerInfo(rx_ConnectionOf(acall), NULL, &exp, tname,
696                                tinst, tcell, NULL);
697     if (code)
698         return 0;               /* bogus connection/other error */
699
700     return kerberosSuperUser(adir, tname, tinst, tcell, identity);
701 }
702
703 /*!
704  * Check whether the user authenticated on a given RX call is a super
705  * user or not. If they are, return a pointer to the identity of that
706  * user.
707  *
708  * @param[in] adir
709  *      The configuration directory currently in use
710  * @param[in] acall
711  *      The RX call whose authenticated identity is being checked
712  * @param[out] identity
713  *      The RX identity of the user. Caller must free this structure.
714  * @returns
715  *      True if the user is a super user, or if the server is running
716  *      in noauth mode. Otherwise, false.
717  */
718 afs_int32
719 afsconf_SuperIdentity(struct afsconf_dir *adir, struct rx_call *acall,
720                       struct rx_identity **identity)
721 {
722     struct rx_connection *tconn;
723     afs_int32 code;
724     int flag;
725
726     LOCK_GLOBAL_MUTEX;
727     if (!adir) {
728         UNLOCK_GLOBAL_MUTEX;
729         return 0;
730     }
731
732     if (afsconf_GetNoAuthFlag(adir)) {
733         if (identity)
734             *identity = rx_identity_new(RX_ID_KRB4, AFS_NOAUTH_NAME,
735                                         AFS_NOAUTH_NAME, AFS_NOAUTH_LEN);
736         UNLOCK_GLOBAL_MUTEX;
737         return 1;
738     }
739
740     tconn = rx_ConnectionOf(acall);
741     code = rx_SecurityClassOf(tconn);
742     if (code == 0) {
743         UNLOCK_GLOBAL_MUTEX;
744         return 0;               /* not authenticated at all, answer is no */
745     } else if (code == 1) {
746         /* bcrypt tokens */
747         UNLOCK_GLOBAL_MUTEX;
748         return 0;               /* not supported any longer */
749     } else if (code == 2) {
750         flag = rxkadSuperUser(adir, acall, identity);
751         UNLOCK_GLOBAL_MUTEX;
752         return flag;
753     } else {                    /* some other auth type */
754         UNLOCK_GLOBAL_MUTEX;
755         return 0;               /* mysterious, just say no */
756     }
757 }
758
759 /*!
760  * Check whether the user authenticated on a given RX call is a super
761  * user or not. If they are, return a pointer to the name of that
762  * user.
763  *
764  * @param[in] adir
765  *      The configuration directory currently in use
766  * @param[in] acall
767  *      The RX call whose authenticated identity is being checked
768  * @param[out] namep
769  *      A printable version of the name of the user
770  * @returns
771  *      True if the user is a super user, or if the server is running
772  *      in noauth mode. Otherwise, false.
773  *
774  * This function is provided for backwards compatibility. New callers
775  * should use the afsconf_SuperIdentity function.
776  */
777
778 afs_int32
779 afsconf_SuperUser(struct afsconf_dir *adir, struct rx_call *acall,
780                   char *namep)
781 {
782     struct rx_identity *identity;
783     int ret;
784
785     if (namep) {
786         ret = afsconf_SuperIdentity(adir, acall, &identity);
787         if (ret) {
788             if (identity->kind == RX_ID_KRB4) {
789                 strlcpy(namep, identity->displayName, MAXKTCNAMELEN-1);
790             } else {
791                 snprintf(namep, MAXKTCNAMELEN-1, "eName: %s",
792                          identity->displayName);
793             }
794             rx_identity_free(&identity);
795         }
796     } else {
797         ret = afsconf_SuperIdentity(adir, acall, NULL);
798     }
799
800     return ret;
801 }