1: #include    "parms.h"
   2: #include    "structs.h"
   3: #include    <pwd.h>
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: startup.c,v 1.7.0.3 85/03/18 20:56:44 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: static char *Bigversion = "Notesfiles: $Revision: 1.7.0.3 $";
   9: 
  10: /*
  11:  *	this file contains code and declarations that are common to
  12:  *	all main lines. This routine should be called by all
  13:  *	mainline routines immediately.
  14:  *
  15:  *	We also take care of the problem of some systems not honoring
  16:  *	the setuid bit when root runs a program.
  17:  *
  18:  *	Ray Essick	May 7, 1982
  19:  */
  20: 
  21: static char SysName[32];                /* holds system name */
  22: static char authsys[32];                /* author's system */
  23: 
  24: #if defined(UNAME)
  25: #include <sys/utsname.h>                /* uname syscall */
  26: #endif	defined(UNAME)
  27: 
  28: char   *hised = DFLTED;                 /* his favorite editor */
  29: char   *hisshell = DFLTSH;              /* his favorite shell */
  30: char   *hispager;
  31: char   *hismailer;
  32: int     nrows = 24;                 /* rows on screen */
  33: int     ncols = 80;                 /* width of screen */
  34: char   *histty = (char *) NULL;             /* tty as on command */
  35: int     intflag = 0;                    /* DEL hit recently */
  36: int     globuid = ANONUID;              /* his true user id */
  37: int     Notesuid = NOTESUID;                /* default to root? */
  38: int     Anonuid = ANONUID;
  39: int     Nindex = 12;                    /* # on index page */
  40: int     ignoresigs = 0;                 /* critical section */
  41: char   *Mstdir = MSTDIR;                /* store nf's here */
  42: char   *System = SysName;               /* point to it */
  43: char   *Authsystem = authsys;               /* init pointer */
  44: char   *Invokedas = "Unknown";              /* argv[0] */
  45: char    Seqname[WDLEN];                 /* sequencer name */
  46: struct when_f   Basetime;               /* zero time */
  47: 
  48: 
  49: struct passwd  *getpwnam ();
  50: 
  51: startup (argc, argv)
  52: int     argc;
  53: char  **argv;
  54: {
  55: 
  56:     struct passwd  *pw;
  57:     struct auth_f   whoami;
  58:     char   *p;
  59: 
  60: /*
  61:  *	Grab "notes" uid from /etc/passwd and also grab uid of
  62:  *	user running this process.
  63:  *	ditto for "anon".
  64:  */
  65: 
  66:     if ((pw = getpwnam (NOTES)) == NULL)        /* find notes uid */
  67:     {
  68:     fprintf (stderr, "Can't find uid for %s, assuming %d\n",
  69:         NOTES, NOTESUID);
  70: #ifdef  DYNADIR
  71:     fprintf (stderr, "Assuming Notesfiles live in %s\n",
  72:         Mstdir);
  73: #endif	DYNADIR
  74:     }
  75:     else
  76:     {
  77:     Notesuid = pw -> pw_uid & UIDMASK;
  78: #ifdef  DYNADIR
  79: /*
  80:  *	Select Mstdir based on the home directory for the "notes"
  81:  *	owner.  Make it one directory "above" the note's home directory.
  82:  *	(which in many places will be /usr/spool/notes/.utilities
  83:  */
  84:     if ((p = rindex (pw -> pw_dir, '/')) != NULL)   /* get end */
  85:     {
  86:         *p = '\0';                  /* terminate */
  87:         if (strlen (pw -> pw_dir) > 0)      /* non-empty */
  88:         Mstdir = strsave (pw -> pw_dir);    /* save it */
  89:     }
  90: #endif	DYNADIR
  91:     }
  92: 
  93:     if ((pw = getpwnam (ANON)) == NULL)         /* (prohibited) anon uid */
  94:     {
  95:     fprintf (stderr, "Can't find uid for %s, assuming %d\n",
  96:         ANON, ANONUID);
  97:     }
  98:     else
  99:     {
 100:     Anonuid = pw -> pw_uid & UIDMASK;
 101:     }
 102:     endpwent ();
 103: 
 104: /*
 105:  *	now resolve who is running the program, make sure that
 106:  *	we are setuid'ed away from root which breaks our locks
 107:  *	at this time (need a better locking mechanism).
 108:  *
 109:  *	We really want seteuid(), but V7 and a number of others
 110:  *	don't offer this.  4.2 Bsd does, so we use it there.
 111:  */
 112: 
 113:     globuid = getuid () & UIDMASK;          /* set this */
 114: #ifdef  RUNSUID
 115:     if (geteuid () == 0)                /* root access? */
 116:     {
 117: #ifdef  BSD42
 118:     seteuid (Notesuid);             /* we'll fix that */
 119: #else
 120:     setuid (Notesuid);              /* we'll fix that */
 121: #endif	BSD42
 122:     }
 123: #endif	RUNSUID
 124: 
 125:     getname (&whoami, 0);               /* get my name */
 126:     strcpy (Seqname, &whoami.aname);            /* load seq name */
 127: 
 128: /*
 129:  *	and now decide where we are
 130:  */
 131: 
 132: #ifdef  PORTBINARY                  /* to have portable binaries */
 133:     gethostname (SysName, sizeof (SysName));        /* load it */
 134: #endif	defined(PORTBINARY)
 135: 
 136: #ifdef  UNAME                       /* like PORTBINARY */
 137:     {
 138:     struct utsname  name;
 139:     uname (&name);                  /* UNIX 4.0 syscall */
 140:     strcpy (SysName, name.nodename);
 141:     }
 142: #endif	defined(UNAME)
 143: 
 144: #ifdef  WHOAMI
 145:     {
 146:     char    buf[BUFSIZ];
 147:     FILE * fd;
 148: 
 149:     if ((fd = fopen (WHOAMIFILE, "r")) == NULL) /* get file */
 150:     {
 151:         fprintf (stderr, "Cannot open %s\n", WHOAMIFILE);
 152:         exit (1);
 153:     }
 154:     for (;;)
 155:     {
 156:         if (fgets (buf, sizeof buf, fd) == NULL)
 157:         {
 158:         fprintf (stderr, "no sysname in %s\n", WHOAMIFILE);
 159:         fclose (fd);
 160:         exit (2);
 161:         }
 162:         if (sscanf (buf, "#define sysname \"%[^\"]\"", SysName) == 1)
 163:         {
 164:         fclose (fd);
 165:         break;
 166:         }
 167:     }
 168:     }
 169: #endif	WHOAMI
 170: 
 171:     /*
 172:      * Now that we have a copy of the System name loaded into
 173:      * the "SysName" array, let's make a copy to use for the
 174:      * user as his system. The "System" will get used for things
 175:      * like the generation of Unique ID's.
 176:      */
 177:     strcpy (Authsystem, System);            /* copy it */
 178: 
 179: #ifdef  FULLDOMAIN
 180:     /*
 181:      * append the domain information (if it isn't already there)
 182:      * to the Author system name.
 183:      */
 184:     if (index (Authsystem, '.') == (char *) NULL)
 185:     {
 186:     strcat (Authsystem, ".");
 187:     strcat (Authsystem, FULLDOMAIN);
 188:     }
 189: 
 190: #ifdef  IDDOMAIN
 191:     /*
 192:      *	append domain information if needed
 193:      *  to the system name as it is used in the unique id.
 194:      */
 195:     if (index (System, '.') == (char *) NULL)       /* if not there */
 196:     {
 197:     strcat (SysName, ".");              /* separator */
 198:     strcat (SysName, FULLDOMAIN);           /* append it */
 199:     }
 200: #endif	IDDOMAIN
 201: 
 202: #endif	FULLDOMAIN
 203: 
 204: /*
 205:  *	Decide what we were invoked as
 206:  *	and set up a few other values that don't fit anywhere.
 207:  */
 208: 
 209:     Invokedas = argv[0];
 210:     Basetime.w_year = 1970;             /* unix time 0 */
 211:     Basetime.w_month = 1;
 212:     Basetime.w_day = 1;
 213:     Basetime.w_hours = 0;
 214:     Basetime.w_mins = 0;
 215:     Basetime.w_gmttime = 0;
 216: 
 217: }

Defined functions

Defined variables

Anonuid defined in line 38; used 1 times
Authsystem defined in line 43; used 5 times
Basetime defined in line 46; used 7 times
Bigversion defined in line 8; never used
Invokedas defined in line 44; used 1 times
Mstdir defined in line 41; used 4 times
Nindex defined in line 39; never used
Notesuid defined in line 37; used 3 times
Seqname defined in line 45; used 1 times
SysName defined in line 21; used 7 times
System defined in line 42; used 2 times
authsys defined in line 22; used 1 times
  • in line 43
globuid defined in line 36; used 1 times
hised defined in line 28; never used
hismailer defined in line 31; never used
hispager defined in line 30; never used
hisshell defined in line 29; never used
histty defined in line 34; never used
ignoresigs defined in line 40; never used
intflag defined in line 35; used 4 times
ncols defined in line 33; never used
nrows defined in line 32; never used
rcsid defined in line 5; never used
Last modified: 1985-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1520
Valid CSS Valid XHTML 1.0 Strict