1: /*
   2:  * This software is Copyright (c) 1986 by Rick Adams.
   3:  *
   4:  * Permission is hereby granted to copy, reproduce, redistribute or
   5:  * otherwise use this software as long as: there is no monetary
   6:  * profit gained specifically from the use or reproduction or this
   7:  * software, it is not sold, rented, traded or otherwise marketed, and
   8:  * this copyright notice is included prominently in any copy
   9:  * made.
  10:  *
  11:  * The author make no claims as to the fitness or correctness of
  12:  * this software for any use whatsoever, and it is provided as is.
  13:  * Any use of this software is at the user's own risk.
  14:  *
  15:  * This function initializes all the strings used for the various
  16:  * filenames.  They cannot be compiled into the program, since that
  17:  * would be non-portable.  With this convention, the netnews sub-system
  18:  * can be owned by any non-privileged user.  It is also possible
  19:  * to work when the administration randomly moves users from one
  20:  * filesystem to another.  The convention is that a particular user
  21:  * (HOME, see Makefile) is searched for in /etc/passwd and all files
  22:  * are presumed relative to there.  This method also allows one copy
  23:  * of the object code to be used on ANY machine.  (this code runs
  24:  * un-modified on 50+ machines at IH!!)
  25:  *
  26:  * The disadvantage to using this method is that all netnews programs
  27:  * (inews, readnews, rnews, checknews) must first search /etc/passwd
  28:  * before they can start up.  This can cause significant overhead if
  29:  * you have a big password file.
  30:  *
  31:  * Some games are played with ifdefs to get four .o files out of this
  32:  * one source file.  INEW is defined for inews, READ for readnews,
  33:  * CHKN for checknews, and EXP for expire.
  34:  */
  35: 
  36: #ifdef SCCSID
  37: static char *SccsId = "@(#)pathinit.c	1.17	1/17/86";
  38: #endif /* SCCSID */
  39: 
  40: #if defined(INEW) || defined(EXP)
  41: #include    "iparams.h"
  42: #endif /* INEW || EXP */
  43: 
  44: #ifdef READ
  45: #include    "rparams.h"
  46: #endif /* READ */
  47: 
  48: #if defined(CHKN)
  49: #include "params.h"
  50: #endif /* CHKN */
  51: 
  52: 
  53: char *FULLSYSNAME, *SPOOL, *LIB, *BIN, *ACTIVE, *SUBFILE, *ARTFILE,
  54:     *username, *userhome;
  55: 
  56: #ifdef INEW
  57: char *LOCKFILE, *SEQFILE, *ARTICLE, *INFILE, *TELLME;
  58: #endif /* INEW */
  59: 
  60: #if defined(INEW) || defined(READ)
  61: char *ALIASES;
  62: #endif /* INEW || READ */
  63: 
  64: #ifdef EXP
  65: char *OLDNEWS;
  66: #endif /* EXP */
  67: 
  68: #ifdef READ
  69: char *MAILPARSER;
  70: #endif /* READ */
  71: 
  72: #ifdef HIDDENNET
  73: char *LOCALSYSNAME;
  74: #endif /* HIDDENNET */
  75: 
  76: 
  77: struct passwd *getpwnam();
  78: char *rindex();
  79: 
  80: #define Sprintf(where,fmt,arg)  (void) sprintf(bfr,fmt,arg); where = AllocCpy(bfr)
  81: 
  82: char *
  83: AllocCpy(cp)
  84: register char *cp;
  85: {
  86:     register char *mp;
  87:     char *malloc();
  88: 
  89:     mp = malloc((unsigned)strlen(cp) + 1);
  90: 
  91:     if (mp == NULL)
  92:         xerror("malloc failed on %s",cp);
  93: 
  94:     (void) strcpy(mp, cp);
  95:     return mp;
  96: }
  97: 
  98: pathinit()
  99: {
 100: #if defined(INEW) && defined(NOTIFY)
 101:     FILE    *nfd;       /* notify file descriptor		*/
 102:     char *p;
 103: #endif /* INEW && NOTIFY */
 104: #ifndef ROOTID
 105:     struct passwd   *pw;    /* struct for pw lookup			*/
 106: #endif /* !ROOTID */
 107: #ifdef EXP
 108:     char *p;
 109: #endif /* EXP */
 110: #ifndef CHKN
 111:     struct utsname ubuf;
 112: 
 113:     uname(&ubuf);
 114: #ifdef HIDDENNET
 115:     FULLSYSNAME = AllocCpy(HIDDENNET);
 116:     LOCALSYSNAME = AllocCpy(ubuf.nodename);
 117: #else /* !HIDDENNET */
 118:     FULLSYSNAME = AllocCpy(ubuf.nodename);
 119: #endif /* !HIDDENNET */
 120: #endif /* !CHKN */
 121: 
 122: #ifdef HOME
 123:     /* Relative to the home directory of user HOME */
 124:     (void) sprintf(bfr, "%s/%s", logdir(HOME), SPOOLDIR);
 125:     SPOOL = AllocCpy(bfr);
 126:     (void) sprintf(bfr, "%s/%s", logdir(HOME), LIBDIR);
 127:     LIB = AllocCpy(bfr);
 128: #else /* !HOME */
 129:     /* Fixed paths defined in Makefile */
 130:     SPOOL = AllocCpy(SPOOLDIR);
 131:     LIB = AllocCpy(LIBDIR);
 132: #endif /* !HOME */
 133: 
 134: #ifdef IHCC
 135:     (void) sprintf(bfr, "%s/%s", logdir(HOME), BINDIR);
 136:     BIN = AllocCpy(bfr);
 137: #else /* !IHCC */
 138:     Sprintf(BIN, "%s", BINDIR);
 139: #endif /* !IHCC */
 140: 
 141:     Sprintf(ACTIVE, "%s/active", LIB);
 142: 
 143: #ifdef EXP
 144:     (void) strcpy(bfr, SPOOL);
 145:     p = rindex(bfr, '/');
 146:     if (p) {
 147:         strcpy(++p, "oldnews");
 148:         OLDNEWS = AllocCpy(bfr);
 149:     } else
 150:         OLDNEWS = AllocCpy("oldnews");
 151: #endif /* EXP */
 152: 
 153: #ifndef CHKN
 154:     Sprintf(SUBFILE, "%s/sys", LIB);
 155:     Sprintf(ARTFILE, "%s/history", LIB);
 156: # endif /* !CHKN */
 157: 
 158: # ifdef READ
 159: #ifdef SENDMAIL
 160:     Sprintf(MAILPARSER, "%s -oi -oem", SENDMAIL);
 161: #else /* !SENDMAIL */
 162:     Sprintf(MAILPARSER, "%s/recmail", LIB);
 163: #endif /* !SENDMAIL */
 164: # endif /* READ */
 165: 
 166: # if defined(READ) || defined(INEW)
 167:     Sprintf(ALIASES, "%s/aliases", LIB);
 168: # endif /* READ || INEW */
 169: # ifdef INEW
 170:     Sprintf(LOCKFILE, "%s/LOCK", LIB);
 171:     Sprintf(SEQFILE, "%s/seq", LIB);
 172:     Sprintf(ARTICLE, "%s/.arXXXXXX", SPOOL);
 173:     Sprintf(INFILE, "%s/.inXXXXXX", SPOOL);
 174: /*
 175:  * The person notified by the netnews sub-system.  Again, no name is
 176:  * compiled in, but instead the information is taken from a file.
 177:  * If the file does not exist, a "default" person will get the mail.
 178:  * If the file exists, but is empty, nobody will get the mail.  This
 179:  * may seem backwards, but is a better fail-safe.
 180:  */
 181: # ifdef NOTIFY
 182:     (void) sprintf(bfr, "%s/notify", LIB);
 183:     nfd = fopen(bfr, "r");
 184:     if (nfd != NULL) {
 185:         bfr[0] = '\0';
 186:         (void) fgets(bfr, BUFLEN, nfd);
 187:         if ((p = index(bfr, '\n')) != NULL) /* strip newline */
 188:             *p = '\0';
 189:         TELLME = AllocCpy(bfr);
 190:         (void) fclose(nfd);
 191:     } else
 192:         TELLME = AllocCpy(NOTIFY);
 193: # endif /* NOTIFY */
 194: 
 195: /*
 196:  * Since the netnews owner's id number is different on different
 197:  * systems, we'll extract it from the /etc/passwd file.  If no entry,
 198:  * default to root.  This id number seems to only be used to control who
 199:  * can input certain control messages or cancel any message.  Note that
 200:  * entry is the name from the "notify" file as found above if possible.
 201:  * Defining ROOTID in defs.h hardwires in a number and avoids
 202:  * another search of /etc/passwd.
 203:  */
 204: # ifndef ROOTID
 205:     if ((pw = getpwnam(TELLME)) != NULL)
 206:         ROOTID =  pw->pw_uid;
 207:     else if ((pw = getpwnam(HOME)) != NULL)
 208:         ROOTID =  pw->pw_uid;
 209:     else
 210:         ROOTID = 0;     /* nobody left, let only root */
 211: # endif /* !ROOTID */
 212: #endif /* INEW */
 213: }

Defined functions

Defined variables

ALIASES defined in line 61; used 2 times
ARTFILE defined in line 53; used 2 times
ARTICLE defined in line 57; used 2 times
BIN defined in line 53; used 6 times
INFILE defined in line 57; used 2 times
LOCALSYSNAME defined in line 73; used 2 times
LOCKFILE defined in line 57; used 2 times
MAILPARSER defined in line 69; used 4 times
OLDNEWS defined in line 65; used 5 times
SEQFILE defined in line 57; used 2 times
SPOOL defined in line 53; used 14 times
SUBFILE defined in line 53; used 2 times
SccsId defined in line 37; never used
TELLME defined in line 57; used 6 times

Defined macros

Sprintf defined in line 80; used 11 times
Last modified: 1986-01-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1831
Valid CSS Valid XHTML 1.0 Strict