Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / lib / krb / tkt_string.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: tkt_string.c,v 1.15 1999/09/16 20:41:55 assar Exp $");
25
26 /*
27  * This routine is used to generate the name of the file that holds
28  * the user's cache of server tickets and associated session keys.
29  *
30  * If it is set, krb_ticket_string contains the ticket file name.
31  * Otherwise, the filename is constructed as follows:
32  *
33  * If it is set, the environment variable "KRBTKFILE" will be used as
34  * the ticket file name.  Otherwise TKT_ROOT (defined in "krb.h") and
35  * the user's uid are concatenated to produce the ticket file name
36  * (e.g., "/tmp/tkt123").  A pointer to the string containing the ticket
37  * file name is returned.
38  */
39
40 static char krb_ticket_string[MaxPathLen] = "";
41
42 char *
43 tkt_string(void)
44 {
45     char *env;
46
47     if (!*krb_ticket_string) {
48         if ((env = getenv("KRBTKFILE"))) {
49             strlcpy (krb_ticket_string,
50                              env,
51                              sizeof(krb_ticket_string));
52         } else {
53             snprintf(krb_ticket_string, sizeof(krb_ticket_string),
54                      "%s%u",TKT_ROOT, (unsigned)getuid());
55         }
56     }
57     return krb_ticket_string;
58 }
59
60 /*
61  * This routine is used to set the name of the file that holds the user's
62  * cache of server tickets and associated session keys.
63  *
64  * The value passed in is copied into local storage.
65  *
66  * NOTE:  This routine should be called during initialization, before other
67  * Kerberos routines are called; otherwise tkt_string() above may be called
68  * and return an undesired ticket file name until this routine is called.
69  */
70
71 void
72 krb_set_tkt_string(const char *val)
73 {
74     strlcpy (krb_ticket_string, val, sizeof(krb_ticket_string));
75 }