2086
|
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 * $Source$
|
|
7 * $Author: warmenhoven $
|
|
8 *
|
|
9 * Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology.
|
|
10 * For copying and distribution information, see the file
|
|
11 * "mit-copyright.h".
|
|
12 */
|
|
13 /* $Header$ */
|
|
14
|
|
15 #include <internal.h>
|
|
16
|
|
17 #ifndef lint
|
|
18 static const char rcsid_ZGetSender_c[] =
|
|
19 "$Id: ZGetSender.c 2096 2001-07-31 01:00:39Z warmenhoven $";
|
|
20 #endif
|
|
21
|
|
22 #include <pwd.h>
|
|
23
|
|
24 char *ZGetSender()
|
|
25 {
|
|
26 struct passwd *pw;
|
|
27 #ifdef ZEPHYR_USES_KERBEROS
|
|
28 char pname[ANAME_SZ], pinst[INST_SZ], prealm[REALM_SZ];
|
|
29 static char sender[ANAME_SZ+INST_SZ+REALM_SZ+3] = "";
|
|
30 #else
|
|
31 static char sender[128] = "";
|
|
32 #endif
|
|
33
|
|
34 /* Return it if already cached */
|
|
35 if (*sender)
|
|
36 return (sender);
|
|
37
|
|
38 #ifdef ZEPHYR_USES_KERBEROS
|
|
39 if (krb_get_tf_fullname((char *)TKT_FILE, pname, pinst, prealm) == KSUCCESS)
|
|
40 {
|
|
41 (void) sprintf(sender, "%s%s%s@%s", pname, (pinst[0]?".":""),
|
|
42 pinst, prealm);
|
|
43 return (sender);
|
|
44 }
|
|
45 #endif
|
|
46
|
|
47 /* XXX a uid_t is a u_short (now), but getpwuid
|
|
48 * wants an int. AARGH! */
|
|
49 pw = getpwuid((int) getuid());
|
|
50 if (!pw)
|
|
51 return ("unknown");
|
|
52 (void) sprintf(sender, "%s@%s", pw->pw_name, __Zephyr_realm);
|
|
53 return (sender);
|
|
54 }
|