BSD 4 development
[unix-history] / usr / src / cmd / ucbmail / c.local.c
index 351871a..0e32538 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * Mail -- a mail program
  *
 /*
  * Mail -- a mail program
  *
- * EECS Cory 11/70 Version 6.9.
+ * EECS Cory 11/70 Version 7.0
  *
  * Local routines that are installation dependent.
  * All fiddlers please note:  if you make careful note of
  *
  * Local routines that are installation dependent.
  * All fiddlers please note:  if you make careful note of
  */
 
 #include "rcv.h"
  */
 
 #include "rcv.h"
+#include <pwd.h>
 
 /*
  * Locate the user's mailbox file (ie, the place where new, unread
 
 /*
  * Locate the user's mailbox file (ie, the place where new, unread
- * mail is queued).  At Cory, it is in /usr/mail/name.
+ * mail is queued).  At Cory, it is in /usr/spool/mail/name.
  */
 
 findmail()
 {
        register char *cp;
 
  */
 
 findmail()
 {
        register char *cp;
 
-       cp = copy("/usr/mail/", mailname);
+       cp = copy("/usr/spool/mail/", mailname);
        copy(myname, cp);
 }
 
 /*
  * Get rid of the queued mail.
        copy(myname, cp);
 }
 
 /*
  * Get rid of the queued mail.
- * This is essential "mail -n > /dev/null &"
  */
 
 demail()
 {
        register int p;
  */
 
 demail()
 {
        register int p;
-
-       if (uid == 0) {
-               remove(mailname);
-               return;
-       }
-       if ((p = fork()) != 0)
-               return;
-       for (p = 0; p < 15; p++)
-                close(p);
-       open("/dev/null", 2);
-       dup(0);
-       dup(0);
-       for (p = SIGHUP; p <= SIGQUIT; p++)
-               signal(p, SIG_IGN);
-       execl(MAIL, "mail", "-n", 0);
-       perror(MAIL);
-       exit(1);
-}
-
-/*
- * Get the value of an environment variable.
- */
-
-char *
-getenv(name)
-       char name[];
-{
-       register int t;
-       static char val[30];
-
-       t = ttyn(2);
-       hget(t);
-       if (equal(name, "SHELL"))
-               return("/bin/csh");
-       if (!equal(name, "HOME"))
-               return(NOSTR);
-       copy(hgethome(), val);
-       return(val);
+       
+       close(creat(mailname, 0666));
+       alter(mailname);
 }
 
 /*
  * Mail file lock / unlock.
 }
 
 /*
  * Mail file lock / unlock.
- * Insignificant in version 6.
+ * Insignificant on Cory version 7, since /usr/spool/mail not
+ * generally writable.
  */
 
 lock(name)
  */
 
 lock(name)
@@ -99,34 +65,44 @@ unlock()
 username(uid, namebuf)
        char namebuf[];
 {
 username(uid, namebuf)
        char namebuf[];
 {
+       register char *np;
 
 
+       if (uid == getuid() && (np = getenv("USER")) != NOSTR) {
+               strncpy(namebuf, np, 9);
+               return(0);
+       }
        return(getname(uid, namebuf));
 }
 
 /*
        return(getname(uid, namebuf));
 }
 
 /*
- * Unix routine to do an "fopen" on file descriptor
- * The mode has to be repeated because you can't query its
- * status
+ * Discover user name from uid.  Uses the fancy hashed passwd
+ * data base available only on Cory Unix.
  */
 
  */
 
-FILE *
-fdopen(fd, mode)
-register char *mode;
+getname(uid, namebuf)
+       char namebuf[];
 {
 {
-       extern int errno;
-       register FILE *iop;
-       extern FILE *_lastbuf;
-
-       for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++)
-               if (iop >= _lastbuf)
-                       return(NULL);
-       iop->_cnt = 0;
-       iop->_file = fd;
-       if (*mode != 'r') {
-               iop->_flag |= _IOWRT;
-               if (*mode == 'a')
-                       lseek(fd, 0L, 2);
-       } else
-               iop->_flag |= _IOREAD;
-       return(iop);
+       struct passwd *gp;
+       struct passwd *getpwuid();
+
+       gp = getpwuid(uid);
+       if (gp == (struct passwd *) 0)
+               return(-1);
+       strcpy(namebuf, gp->pw_name);
+       return(0);
+}
+
+/*
+ * Cory hall getuserid
+ */
+
+getuserid(name)
+       char name[];
+{
+       struct passwd *gp;
+       struct passwd *getpwnam();
+
+       if ((gp = getpwnam(name)) == (struct passwd *) 0)
+               return(-1);
+       return(gp->pw_uid);
 }
 }