1 #
2
3 /*
4 * Mail -- a mail program
5 *
6 * Ingres 11/70. Unix version 6.0
7 *
8 * Local routines that are installation dependent.
9 * All fiddlers please note: if you make careful note of
10 * what you change here, I will incorporate your changes and
11 * you won't have to remake them each release.
12 */
13
14 static char *SccsId = "@(#)ing.local.c 2.1 07/01/81";
15
16 #include "rcv.h"
17 #include <errno.h>
18
19 /*
20 * Locate the user's mailbox file (ie, the place where new, unread
21 * mail is queued). At Ingres, it's in /usr/spool/mail/loginname.
22 */
23
findmail()24 findmail()
25 {
26 register char *cp;
27
28 cp = copy("/usr/spool/mail/", mailname);
29 copy(myname, cp);
30 }
31
32 /*
33 * Get rid of the queued mail.
34 */
35
demail()36 demail()
37 {
38 if (unlink(mailname) >= 0)
39 return;
40 close(creat(mailname, 0666));
41 alter(mailname);
42 }
43
44 /*
45 * Get an environment variable. At present, we only support
46 * "SHELL" and "HOME". This routine makes use of the getpw
47 * routine in the neighboring getname.c stuff.
48 */
49
50 char *
getenv(name)51 getenv(name)
52 char name[];
53 {
54 char pwline[LINESIZE];
55 static char val[30];
56 register char *cp, *dp;
57 register int cc;
58
59 if (equal(name, "SHELL"))
60 cc = 6;
61 else if (equal(name, "HOME"))
62 cc = 5;
63 else
64 return(NOSTR);
65 if (getpwnam(myname, pwline) < 0)
66 return(NOSTR);
67 for (cp = pwline; *cp && cc > 0;)
68 if (*cp++ == ':')
69 cc--;
70 dp = cp;
71 while (*cp != ':' && *cp != '\0' && *cp != '\n')
72 cp++;
73 *cp = '\0';
74 if (*dp == '\0')
75 return(NOSTR);
76 copy(dp, val);
77 return(val);
78 }
79
80 /*
81 * Discover user name. On Ingres, user names are rarely 1-1 with uids,
82 * so we look for this guy in the utmp file first, then try finding
83 * him in the passwd file on basis of uid if that fails.
84 */
85
86 struct utmp {
87 char u_name[8]; /* User login name. */
88 char u_tty; /* typewriter character */
89 char u_cfill; /* Unused for now. */
90 long u_time; /* Login time */
91 short u_wfill; /* Unused also */
92 };
93
username(uid,namebuf)94 username(uid, namebuf)
95 char namebuf[];
96 {
97 struct utmp ubuf;
98 register char *cp;
99 register int tty;
100 register FILE *fwho;
101
102 tty = ttyn(0);
103 if (tty == 'x')
104 goto useuid;
105
106 /*
107 * Dammit, I really do have to search the utmp file!
108 */
109
110 if ((fwho = fopen("/etc/utmp", "r")) == NULL)
111 goto useuid;
112 while (fread(&ubuf, 1, sizeof ubuf, fwho) > 0)
113 if (ubuf.u_tty == tty) {
114 strncpy(namebuf, ubuf.u_name, 8);
115 namebuf[8] = 0;
116 cp = index(namebuf, ' ');
117 if (cp != NOSTR)
118 *cp = 0;
119 return(0);
120 }
121 fclose(fwho);
122
123 useuid:
124 return(getname(uid, namebuf));
125 }
126
127 /*
128 * Unix routine to do an "fopen" on file descriptor
129 * The mode has to be repeated because you can't query its
130 * status
131 */
132
133 FILE *
fdopen(fd,mode)134 fdopen(fd, mode)
135 register char *mode;
136 {
137 extern int errno;
138 register FILE *iop;
139 extern FILE *_lastbuf;
140
141 for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
142 if (iop >= _lastbuf)
143 return(NULL);
144 iop->_cnt = 0;
145 iop->_file = fd;
146 if (*mode != 'r') {
147 iop->_flag |= _IOWRT;
148 if (*mode == 'a')
149 lseek(fd, 0L, 2);
150 } else
151 iop->_flag |= _IOREAD;
152 return(iop);
153 }
154
155 /*
156 * Copy s2 to s1, truncating or null-padding to always copy n bytes
157 * return s1
158 */
159
160 char *
strncpy(s1,s2,n)161 strncpy(s1, s2, n)
162 register char *s1, *s2;
163 {
164 register i;
165 register char *os1;
166
167 os1 = s1;
168 for (i = 0; i < n; i++)
169 if ((*s1++ = *s2++) == '\0') {
170 while (++i < n)
171 *s1++ = '\0';
172 return(os1);
173 }
174 return(os1);
175 }
176