]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZGetSender.c
finalize -3
[1ts-debian.git] / zephyr / lib / ZGetSender.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZGetSender.c function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #include <internal.h>
14
15 #ifndef lint
16 static const char rcsid_ZGetSender_c[] =
17     "$Id$";
18 #endif
19
20 #include <pwd.h>
21
22 char *ZGetSender()
23 {
24     struct passwd *pw;
25 #ifdef HAVE_KRB4
26     char pname[ANAME_SZ], pinst[INST_SZ], prealm[REALM_SZ];
27     static char sender[ANAME_SZ+INST_SZ+REALM_SZ+3] = "";
28 #else
29     static char sender[128] = "";
30 #endif
31
32     /* Return it if already cached */
33     if (*sender)
34         return (sender);
35
36 #ifdef HAVE_KRB4
37     if (krb_get_tf_fullname((char *)TKT_FILE, pname, pinst, prealm) == KSUCCESS)
38     {
39         (void) sprintf(sender, "%s%s%s@%s", pname, (pinst[0]?".":""),
40                        pinst, prealm);
41         return (sender);
42     }
43 #endif
44
45     /* XXX a uid_t is a u_short (now),  but getpwuid
46      * wants an int. AARGH! */
47     pw = getpwuid((int) getuid());
48     if (!pw)
49         return ("unknown");
50     (void) sprintf(sender, "%s@%s", pw->pw_name, __Zephyr_realm);
51     return (sender);
52 }