| |
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 * Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology. |
| |
7 * For copying and distribution information, see the file |
| |
8 * "mit-copyright.h". |
| |
9 */ |
| |
10 |
| |
11 #include "internal.h" |
| |
12 |
| |
13 #ifndef WIN32 |
| |
14 #include <pwd.h> |
| |
15 #endif |
| |
16 |
| |
17 char *ZGetSender() |
| |
18 { |
| |
19 struct passwd *pw; |
| |
20 #ifdef ZEPHYR_USES_KERBEROS |
| |
21 char pname[ANAME_SZ]; |
| |
22 char pinst[INST_SZ]; |
| |
23 char prealm[REALM_SZ]; |
| |
24 static char sender[ANAME_SZ+INST_SZ+REALM_SZ+3] = ""; |
| |
25 long int kerror; |
| |
26 #else |
| |
27 static char sender[128] = ""; |
| |
28 #endif |
| |
29 |
| |
30 #ifdef WIN32 |
| |
31 unsigned long sender_size = sizeof(sender) - 1; |
| |
32 #endif |
| |
33 |
| |
34 #ifdef ZEPHYR_USES_KERBEROS |
| |
35 if ((kerror = krb_get_tf_fullname((char *)TKT_FILE, pname, pinst, prealm)) == KSUCCESS) |
| |
36 { |
| |
37 sprintf(sender, "%s%s%s@%s", pname, (pinst[0] ? "." : ""), pinst, prealm); |
| |
38 return sender; |
| |
39 } |
| |
40 #endif |
| |
41 |
| |
42 #ifdef WIN32 |
| |
43 GetUserName(sender, &sender_size); |
| |
44 #else |
| |
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 sprintf(sender, "%s@%s", pw->pw_name, __Zephyr_realm); |
| |
51 #endif |
| |
52 return sender; |
| |
53 } |