Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / krb / get_tf_fullname.c
1 /* 
2   Copyright (C) 1989 by the Massachusetts Institute of Technology
3
4    Export of this software from the United States of America is assumed
5    to require a specific license from the United States Government.
6    It is the responsibility of any person or organization contemplating
7    export to obtain such a license before exporting.
8
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission.  M.I.T. makes no representations about the suitability of
17 this software for any purpose.  It is provided "as is" without express
18 or implied warranty.
19
20   */
21
22 #include "krb_locl.h"
23
24 RCSID("$Id: get_tf_fullname.c,v 1.8 1999/09/16 20:41:51 assar Exp $");
25
26 /*
27  * This file contains a routine to extract the fullname of a user
28  * from the ticket file.
29  */
30
31 /*
32  * krb_get_tf_fullname() takes four arguments: the name of the 
33  * ticket file, and variables for name, instance, and realm to be
34  * returned in.  Since the realm of a ticket file is not really fully 
35  * supported, the realm used will be that of the the first ticket in 
36  * the file as this is the one that was obtained with a password by
37  * krb_get_in_tkt().
38  */
39
40 int
41 krb_get_tf_fullname(char *ticket_file, char *name, char *instance, char *realm)
42 {
43     int tf_status;
44     CREDENTIALS c;
45
46     if ((tf_status = tf_init(ticket_file, R_TKT_FIL)) != KSUCCESS)
47         return(tf_status);
48
49     if (((tf_status = tf_get_pname(c.pname)) != KSUCCESS) ||
50         ((tf_status = tf_get_pinst(c.pinst)) != KSUCCESS))
51         return (tf_status);
52     
53     if (name)
54         strlcpy (name, c.pname, ANAME_SZ);
55     if (instance)
56         strlcpy (instance, c.pinst, INST_SZ);
57     if ((tf_status = tf_get_cred(&c)) == KSUCCESS) {
58         if (realm)
59             strlcpy (realm, c.realm, REALM_SZ);
60     }
61     else {
62         if (tf_status == EOF)
63             return(KFAILURE);
64         else
65             return(tf_status);
66     }    
67     tf_close();
68     
69     return(tf_status);
70 }