summaryrefslogtreecommitdiff
path: root/lib/ZGetSender.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-06-25 23:35:17 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-06-25 23:35:17 +0000
commit7e0cdcbbf780fd3edbbbb9fd084e49eb5b68d434 (patch)
tree5162f7a41678aa4248f045508b7be3d8861e99e1 /lib/ZGetSender.c
parent2c8deb46a0f8da453f53e167a2e90f83fb50fd4c (diff)
Initial revision
Diffstat (limited to 'lib/ZGetSender.c')
-rw-r--r--lib/ZGetSender.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/ZGetSender.c b/lib/ZGetSender.c
new file mode 100644
index 0000000..bee171a
--- /dev/null
+++ b/lib/ZGetSender.c
@@ -0,0 +1,61 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZGetSender.c function.
+ *
+ * Created by: Robert French
+ *
+ * $Source$
+ * $Author$
+ *
+ * Copyright (c) 1987 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, see the file
+ * "mit-copyright.h".
+ */
+/* $Header$ */
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+#include <pwd.h>
+
+char *ZGetSender()
+{
+ char *tktfile;
+ static char sender[128] = "";
+ char pname[ANAME_SZ],pinst[INST_SZ];
+ FILE *fp;
+ struct passwd *pw;
+
+ if (*sender)
+ return (sender);
+
+ tktfile = (char *)TKT_FILE;
+ if (!(fp = fopen(tktfile,"r"))) {
+ pw = getpwuid(getuid());
+ if (!pw)
+ return ("unauth");
+ sprintf(sender,"%s@UNAUTH",pw->pw_name);
+ return (sender);
+ }
+ getst(fp,pname,ANAME_SZ);
+ getst(fp,pinst,INST_SZ);
+ sprintf(sender,"%s%s%s@%s",pname,(pinst[0]?".":""),pinst,
+ __Zephyr_realm);
+
+ return (sender);
+}
+
+static getst(fp,s,n)
+ FILE *fp;
+ char *s;
+ int n;
+{
+ int count;
+
+ count = n;
+ while (fread(s,1,1,fp) && --count)
+ if (!*(s++))
+ return;
+ *(s++) = '\0';
+ return;
+}