home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1994-09-01  |  28KB  |  828 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. /* Mods by PA0GRI */
  3. /* Modified to allow for configurable file names/locations - WG7J */
  4. #include "global.h"
  5. #include "netuser.h"
  6. #include "files.h"
  7. #include "mailbox.h"
  8.   
  9. #ifdef  MSDOS
  10. char System[] = "MSDOS";
  11. char *Startup   = "/autoexec.nos";      /* Initialization file */
  12. char *Userfile  = "/ftpusers";          /* Authorized FTP users and passwords */
  13. char *Hostfile  = "/net.rc";            /* hosts and passwords */
  14. char *Spoolqdir = "/spool";             /* Spool directory */
  15. char *Maillog   = "/spool/mail.log";    /* mail log */
  16. char *Mailspool = "/spool/mail";        /* Incoming mail */
  17. char *Mailqdir  = "/spool/mqueue";      /* Outgoing mail spool */
  18. char *LogsDir   = "/logs";              /* Logs directory */
  19. char *Mailqueue = "/spool/mqueue/*.wrk";/* Outgoing mail work files */
  20. char *Routeqdir = "/spool/rqueue";      /* queue for router */
  21. char *Alias = "/alias";             /* the alias file */
  22. char *Dfile = "/domain.txt";        /* Domain cache */
  23. char *Fdir  = "/finger";            /* Finger info directory */
  24. char *Fdbase = "/finger/dbase.dat"; /* Finger database */
  25. char *Pdbase = "/spool/names.dat"; /* Personal names databases (IW5DHE) */
  26. char *Arealist  = "/spool/areas";       /* List of message areas */
  27. char *Rewritefile = "/spool/rewrite";       /* Address rewrite file */
  28. char *Ftpmotd = "/spool/ftpmotd.txt";       /* FTP message of the day */
  29. char *CmdsHelpdir  = "/help";       /* Console/Sysop commands help file directory */
  30. #ifdef MAILBOX
  31. char *Signature = "/spool/signatur";        /* Mail signature file directory */
  32. char *Historyfile = "/spool/history";       /* Message ID history file */
  33. char *Helpdir   = "/spool/help";        /* Mailbox help file directory */
  34. char *Motdfile = "/spool/motd.txt";     /* Mailbox message of the day */
  35. #ifdef USERLOG
  36. char *UDefaults = "/spool/users.dat";       /* User preference file */
  37. char *UDefbak = "/spool/users.bak";
  38. char *Mregfile = "/spool/mreg.txt";     /* Mailbox registration message */
  39. #endif
  40. #endif /* MAILBOX */
  41. #ifdef CONVERS
  42. char *Cinfo = "/finger/dbase.dat";  /* Convers user info file */
  43. #ifdef CHANGE_PERSONAL
  44. char *Cinfobak = "/finger/dbase.bak";   /* Convers user info backup */
  45. #endif
  46. #ifdef CHANNELNAMES
  47. char *Channelfile = "/spool/channel.dat"; /* Convers Channel names */
  48. #endif
  49. char *ConvMotd = "/spool/convmotd.txt"; /* Convers Message of the Day */
  50. #endif
  51. #if (defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  52. char *Popusers  = "/popusers";          /* POP user and password file */
  53. #endif
  54. #if (defined(NNTP) || defined(NNTPS))
  55. char *Newsdir   = "/spool/news";        /* News messages and NNTP data */
  56. char *History   = "/spool/news/history";    /* NNTP article msgids and timestamps */
  57. #endif
  58. #if (defined(RLINE) || defined(MBFWD))
  59. char *Forwardfile = "/spool/forward.bbs";   /* Mail forwarding file */
  60. #endif
  61. #ifdef NETROM
  62. char *Netromfile = "/netrom.sav";       /* Netrom node save file */
  63. #endif
  64. char *Onexit = "/onexit.nos";           /* Commands to be executed on exiting */
  65. #ifdef EXPIRY
  66. char *Expirefile = "/spool/expire.dat"; /* Message expiration control file */
  67. #endif
  68. #ifdef  NNTPS
  69. char *Naccess   = "/spool/news/access";
  70. char *Active    = "/spool/news/active";     /* */
  71. char *Pointer   = "/spool/news/pointer";    /* */
  72. char *NInfo = "/spool/news/info";       /* */
  73. char *Nhelp = "/spool/news/help";       /* */
  74. char *Forward   = "/spool/news/forward";    /* */
  75. char *Poll  = "/spool/news/poll";       /* */
  76. #endif
  77. char Eol[]  = "\r\n";
  78. #define SEPARATOR   "/"
  79. #define ROOTDIR "/"
  80. #endif
  81.   
  82. #ifdef  UNIX
  83. char System[] = "UNIX";
  84. char *Startup   = "./startup.nos";      /* Initialization file */
  85. char *Config    = "./config.nos";       /* Device configuration list */
  86. char *Hostfile  = "./net.rc";           /* hosts and passwords */
  87. char *Userfile  = "./ftpusers";
  88. char *Ftpmotd   = "./ftpmotd.txt";       /* FTP message of the day */
  89. char *CmdsHelpdir  = "./help";           /* Console/Sysop commands help file directory */
  90. char *Mailspool = "./mail";
  91. char *Maillog   = "./mail.log";         /* mail log */
  92. char *Mailqdir  = "./mqueue";
  93. char *Mailqueue = "./mqueue/*.wrk";
  94. char *Routeqdir = "./rqueue";           /* queue for router */
  95. char *Alias = "./alias";            /* the alias file */
  96. char *Dfile = "./domain.txt";       /* Domain cache */
  97. char *Fdir  = "./finger";           /* Finger info directory */
  98. char *Motdfile  = "./motd.txt";     /* Mailbox message of the day */
  99. char *Fdbase = "./finger/dbase.dat"; /* Finger database */
  100. char *Arealist  = "./areas";            /* List of message areas */
  101. char *Helpdir   = "./help";         /* Mailbox help file directory */
  102. char *Rewritefile = "./rewrite";        /* Address rewrite file */
  103. char *Signature = "./signatur";         /* Mail signature file directory */
  104. char *Popusers  = "./popusers";         /* POP user and password file */
  105. char *Newsdir   = "./news";         /* News messages and NNTP data */
  106. char *Forwardfile = "./forward.bbs";        /* Mail forwarding file */
  107. char *Historyfile = "./history";        /* Message ID history file */
  108. char *Netromfile = "./netrom.sav";      /* Netrom node save file */
  109. char *UDefaults = "./users.dat";       /* User preference file */
  110. char *UDefbak = "./users.bak";
  111. #ifdef CONVERS
  112. char *Cinfo = "./finger/dbase.dat";  /* Convers user info file */
  113. #ifdef CHANGE_PERSONAL
  114. char *Cinfobak = "./finger/dbase.bak";   /* COnvers user info backup */
  115. #endif
  116. #ifdef CHANNELNAMES
  117. char *Channelfile = "./spool/channel.dat";  /* Convers channel names */
  118. #endif
  119. char *ConfMotd = "./spool/convmotd.txt";
  120. #endif
  121. char *Onexit = "./onexit.nos";           /* Commands to be executed on exiting */
  122. char *Expirefile = "./expire.dat"; /* Message expiration control file */
  123. #if (defined(NNTP) || defined(NNTPS))
  124. char *History   = "/spool/news/history";    /* NNTP article msgids and timestamps */
  125. #endif
  126. #ifdef  NNTPS
  127. char *Naccess   = "/spool/news/access";
  128. char *Active    = "/spool/news/active";     /* */
  129. char *Pointer   = "/spool/news/pointer";    /* */
  130. char *NInfo = "/spool/news/info";       /* */
  131. char *Nhelp = "/spool/news/help";       /* */
  132. char *Forward   = "/spool/news/forward";    /* */
  133. char *Poll  = "/spool/news/poll";       /* */
  134. #endif /* NNTPS */
  135. char Eol[]  = "\n";
  136. #define SEPARATOR   "/"
  137. #define ROOTDIR "."
  138.   
  139. #endif /* UNIX */
  140.   
  141. #ifdef  AMIGA
  142. char System[] = "AMIGA";
  143. char *Startup   = "TCPIP:nos-startup";
  144. char *Config    = "TCPIP:config.nos";       /* Device configuration list */
  145. char *Hostfile  = "TCPIP:net.rc";       /* hosts and passwords */
  146. char *Userfile  = "TCPIP:ftpusers";
  147. char *Mailspool = "TCPIP:spool/mail";
  148. char *Maillog   = "TCPIP:spool/mail.log";
  149. char *Mailqdir  = "TCPIP:spool/mqueue";
  150. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  151. char *Routeqdir = "TCPIP:spool/rqueue";     /* queue for router */
  152. char *Alias = "TCPIP:alias";        /* the alias file */
  153. char *Dfile = "TCPIP:domain.txt";       /* Domain cache */
  154. char *Fdir  = "TCPIP:finger";       /* Finger info directory */
  155. char *Fdbase = "TCPIP:finger/dbase.dat"; /* Finger database */
  156. char *CmdsHelpdir  = "TCPIP:help";       /* Console/Sysop commands help file directory */
  157. char *Arealist  = "TCPIP:spool/areas";      /* List of message areas */
  158. char *Helpdir   = "TCPIP:spool/help";       /* Mailbox help file directory */
  159. char *Rewritefile = "TCPIP:spool/rewrite";  /* Address rewrite file */
  160. char *Signature = "TCPIP:spool/signatur";   /* Mail signature file directory */
  161. char *Popusers  = "TCPIP:/popusers";        /* POP user and password file */
  162. char *Newsdir   = "TCPIP:spool/news";       /* News messages and NNTP data */
  163. char *Forwardfile = "TCPIP:spool/forward.bbs";  /* Mail forwarding file */
  164. char *Historyfile = "TCPIP:spool/history";  /* Message ID history file */
  165. char *UDefaults = "TCPIP:spool/users.dat";  /* User preference file */
  166. char *Netromfile = "TCPIP:netrom.sav";      /* Netrom node save file */
  167. char *Onexit = "TCPIP:onexit.nos";           /* Commands to be executed on exiting */
  168. char *Expirefile = "TCPIP:spool/expire.dat"; /* Message expiration control file */
  169. #if (defined(NNTP) || defined(NNTPS))
  170. char *History   = "TCPIP:spool/news/history";    /* NNTP article msgids and timestamps */
  171. #endif
  172. #ifdef  NNTPS
  173. char *Active    = "TCPIP:spool/news/active";     /* */
  174. char *Pointer   = "TCPIP:spool/news/pointer";    /* */
  175. char *NInfo = "TCPIP:spool/news/info";       /* */
  176. char *Nhelp = "TCPIP:spool/news/help";       /* */
  177. char *Forward   = "TCPIP:spool/news/forward";    /* */
  178. char *Poll  = "TCPIP:spool/news/poll";       /* */
  179. #endif
  180. char Eol[]  = "\r\n";
  181. #define SEPARATOR   "/"
  182. #endif
  183.   
  184. #ifdef  MAC
  185. char System[] = "MACOS";
  186. char *Startup   = "Mikes Hard Disk:nos.start";
  187. char *Config    = "Mikes Hard Disk:config.nos"; /* Device configuration list */
  188. char *Hostfile  = "Mikes Hard Disk:net.rc"; /* hosts and passwords */
  189. char *Userfile  = "Mikes Hard Disk:ftpusers";
  190. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  191. char *Maillog   = "Mikes Hard Disk:spool:mail.log:";
  192. char *Mailqdir  = "Mikes Hard Disk:spool:mqueue:";
  193. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  194. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";  /* queue for router */
  195. char *Alias = "Mikes Hard Disk:alias";      /* the alias file */
  196. char *Dfile = "Mikes Hard Disk:domain:txt";     /* Domain cache */
  197. char *Fdir  = "Mikes Hard Disk:finger";     /* Finger info directory */
  198. char *Fdbase = "Mikes Hard Disk:finger/dbase.dat"; /* Finger database */
  199. char *CmdsHelpdir  = "Mikes Hard Disk:help";       /* Console/Sysop commands help file directory */
  200. char *Arealist  = "Mikes Hard Disk:spool/areas";    /* List of message areas */
  201. char *Helpdir   = "Mikes Hard Disk:spool/help";     /* Mailbox help file directory */
  202. char *Rewritefile = "Mikes Hard Disk:spool/rewrite";    /* Address rewrite file */
  203. char *Signature = "Mikes Hard Disk:spool/signatur"; /* Mail signature file directory */
  204. char *Popusers  = "Mikes Hard Disk:/popusers";      /* POP user and password file */
  205. char *Newsdir   = "Mikes Hard Disk:spool/news"; /* News messages and NNTP data */
  206. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  207. char *Historyfile = "Mikes Hard Disk:spool/history";    /* Message ID history file */
  208. char *UDefaults = "Mikes Hard Disk:spool/users.dat";  /* User preference file */
  209. char *Netromfile = "Mikes Hard Disk:netrom.sav";    /* Netrom node save file */
  210. char *Onexit = "Mikes Hard Disk:onexit.nos";           /* Commands to be executed on exiting */
  211. char *Expirefile = "Mikes Hard Disk:spool/expire.dat"; /* Message expiration control file */
  212. #if (defined(NNTP) || defined(NNTPS))
  213. char *History   = "Mikes Hard Disk:spool/news/history";/* NNTP article msgids and timestamps */
  214. #endif
  215. #ifdef  NNTPS
  216. char *Naccess   = "Mikes Hard Disk:spool/news/access";
  217. char *Active    = "Mikes Hard Disk:spool/news/active";      /* */
  218. char *Pointer   = "Mikes Hard Disk:spool/news/pointer"; /* */
  219. char *NInfo = "Mikes Hard Disk:spool/news/info";        /* */
  220. char *Nhelp = "Mikes Hard Disk:spool/news/help";        /* */
  221. char *Forward   = "Mikes Hard Disk:spool/news/forward"; /* */
  222. char *Poll  = "Mikes Hard Disk:spool/news/poll";        /* */
  223. #endif
  224. char Eol[]  = "\r";
  225. #define SEPARATOR   ":"
  226. #endif
  227.   
  228. static char *rootdir = ROOTDIR;
  229. static int Assigned;
  230. static int Initroot;
  231.   
  232. static void setname __ARGS((char *name,char *file));
  233. static void tabs_to_spaces __ARGS((char *p));
  234. void assign_filenames __ARGS((char *config));
  235.   
  236. extern void undosify __ARGS((char *s));
  237.   
  238. /* Establish a root directory other than the default. Can only be called
  239.  * once, at startup time
  240.  */
  241. void
  242. initroot(root)
  243. char *root;
  244. {
  245.     if(Assigned) {
  246.         tputs("-f option used, -d ignored !\n");
  247.         return;
  248.     }
  249. #ifdef  MSDOS
  250.     undosify(root);
  251. #endif
  252.     rootdir = strdup( root );
  253.     Startup = rootdircat(Startup);
  254.     Userfile = rootdircat(Userfile);
  255.     Hostfile = rootdircat(Hostfile);
  256.     Maillog = rootdircat(Maillog);
  257.     Spoolqdir = rootdircat(Spoolqdir);
  258.     Mailspool = rootdircat(Mailspool);
  259.     Mailqdir = rootdircat(Mailqdir);
  260.     LogsDir = rootdircat(LogsDir);
  261.     Mailqueue = rootdircat(Mailqueue);
  262.     Routeqdir = rootdircat(Routeqdir);
  263.     Alias = rootdircat(Alias);
  264.     Dfile = rootdircat(Dfile);
  265.     Fdir = rootdircat(Fdir);
  266.     Fdbase = rootdircat(Fdbase);
  267.     Pdbase = rootdircat(Pdbase);
  268. #ifdef MAILCMDS
  269.     Arealist = rootdircat(Arealist);
  270. #endif
  271.     Rewritefile = rootdircat(Rewritefile);
  272.     Ftpmotd = rootdircat(Ftpmotd);
  273.     CmdsHelpdir = rootdircat(CmdsHelpdir);
  274. #ifdef MAILBOX
  275.     Signature = rootdircat(Signature);
  276.     Historyfile = rootdircat(Historyfile);
  277.     Helpdir = rootdircat(Helpdir);
  278.     Motdfile = rootdircat(Motdfile);
  279. #ifdef USERLOG
  280.     UDefaults = rootdircat(UDefaults);
  281.     UDefbak = rootdircat(UDefbak);
  282.     Mregfile = rootdircat(Mregfile);
  283. #endif
  284. #endif
  285. #ifdef CONVERS
  286.     Cinfo = rootdircat(Cinfo);
  287. #ifdef CHANGE_PERSONAL
  288.     Cinfobak = rootdircat(Cinfobak);
  289. #endif
  290. #ifdef CHANNELNAMES
  291.     Channelfile = rootdircat(Channelfile);
  292. #endif
  293.     ConvMotd = rootdircat(ConvMotd);
  294. #endif
  295. #if (defined(POP) || defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  296.     Popusers = rootdircat(Popusers);
  297. #endif
  298. #if (defined(NNTP) || defined(NNTPS))
  299.     Newsdir = rootdircat(Newsdir);
  300.     History = rootdircat(History);
  301. #endif
  302. #if (defined(MBFWD) || defined(RLINE))
  303.     Forwardfile = rootdircat(Forwardfile);
  304. #endif
  305. #ifdef NETROM
  306.     Netromfile = rootdircat(Netromfile);
  307. #endif
  308.     Onexit = rootdircat(Onexit);
  309. #ifdef EXPIRY
  310.     Expirefile = rootdircat(Expirefile);
  311. #endif
  312. #ifdef  NNTPS
  313.     Naccess = rootdircat(Naccess);
  314.     Active = rootdircat(Active);
  315.     Pointer = rootdircat(Pointer);
  316.     NInfo = rootdircat(NInfo);
  317.     Nhelp = rootdircat(Nhelp);
  318.     Forward = rootdircat(Forward);
  319.     Poll = rootdircat(Poll);
  320. #endif
  321.     Initroot = 1;
  322. }
  323.   
  324. /* Concatenate root, separator and arg strings into a malloc'ed output
  325.  * buffer, then remove repeated occurrences of the separator char
  326.  */
  327. char *
  328. rootdircat(filename)
  329. char *filename;
  330. {
  331.     char *out = filename;
  332.   
  333.     if(strlen(rootdir) > 0){
  334.         char *separator = SEPARATOR;
  335.         out = mallocw(strlen(rootdir)
  336.         + strlen(separator)
  337.         + strlen(filename) +1);
  338.         strcpy(out,rootdir);
  339.         strcat(out,separator);
  340.         strcat(out,filename);
  341.         if(*separator != '\0'){
  342.             char *p1, *p2;
  343.         /* Remove any repeated occurrences */
  344.             p1 = p2 = out;
  345.             while(*p2 != '\0'){
  346.                 *p1++ = *p2++;
  347.                 while(p2[0] == p2[-1] && p2[0] == *separator)
  348.                     p2++;
  349.             }
  350.             *p1 = '\0';
  351.         }
  352.     }
  353.     return out;
  354. }
  355.   
  356. #ifdef PPP
  357.   
  358. #ifdef notdef
  359. /* Read through FTPUSERS looking for user record
  360.  * Returns line which matches username, or NULLCHAR when no match.
  361.  * Each of the other variables must be copied before freeing the line.
  362.  */
  363. char *
  364. userlookup(username,password,directory,permission,ip_address)
  365. char *username;
  366. char **password;
  367. char **directory;
  368. long *permission;
  369. int32 *ip_address;
  370. {
  371.     FILE *fp;
  372.     char *buf;
  373.     char *cp;
  374.   
  375.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  376.         /* Userfile doesn't exist */
  377.         return NULLCHAR;
  378.   
  379.     buf = mallocw(128);
  380.     while ( fgets(buf,128,fp) != NULLCHAR ){
  381.         if(*buf == '#')
  382.             continue;   /* Comment */
  383.   
  384.         if((cp = strchr(buf,' ')) == NULLCHAR)
  385.             /* Bogus entry */
  386.             continue;
  387.         *cp++ = '\0';       /* Now points to password */
  388.   
  389.         if( stricmp(username,buf) == 0 )
  390.             break;      /* Found user */
  391.     }
  392.     if(feof(fp)){
  393.         /* username not found in file */
  394.         fclose(fp);
  395.         free(buf);
  396.         return NULLCHAR;
  397.     }
  398.     fclose(fp);
  399.   
  400.     if ( password != NULL )
  401.         *password = cp;
  402.   
  403.     /* Look for space after password field in file */
  404.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  405.         /* Invalid file entry */
  406.         free(buf);
  407.         return NULLCHAR;
  408.     }
  409.     *cp++ = '\0';   /* Now points to directory field */
  410.   
  411.     if ( directory != NULL )
  412.         *directory = cp;
  413.   
  414.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  415.         /* Permission field missing */
  416.         free(buf);
  417.         return NULLCHAR;
  418.     }
  419.     *cp++ = '\0';   /* now points to permission field */
  420.   
  421.     if (permission != NULL )
  422.         *permission = strtol( cp, NULLCHARP, 0 );
  423.   
  424.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  425.         /* IP address missing */
  426.         if ( ip_address != NULL )
  427.             *ip_address = 0L;
  428.     } else {
  429.         *cp++ = '\0';   /* now points at IP address field */
  430.         if ( ip_address != NULL )
  431.             *ip_address = resolve( cp );
  432.     }
  433.     return buf;
  434. }
  435. #endif
  436.   
  437. /* Read through FTPUSERS looking for user record
  438.  * Returns line which matches username, or NULLCHAR when no match.
  439.  * Each of the other variables must be copied before freeing the line.
  440.  */
  441. char *
  442. userlookup(username,password,directory,permission,ip_address)
  443. char *username;
  444. char **password;
  445. char **directory;
  446. long   *permission;
  447. int32 *ip_address;
  448. {
  449.     FILE *fp;
  450.     char *buf;
  451.     char *cp;
  452.     char *universal = NULLCHAR;
  453.   
  454.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  455.         /* Userfile doesn't exist */
  456.         return NULLCHAR;
  457.   
  458.     buf = mallocw(128);
  459.     while ( fgets(buf,128,fp) != NULLCHAR ){
  460.         if(*buf == '#')
  461.             continue;   /* Comment */
  462.   
  463.         if((cp = strpbrk(buf," \t")) == NULLCHAR)
  464.             /* Bogus entry */
  465.             continue;
  466.         *cp++ = '\0';       /* Now points to password */
  467.   
  468.         if( stricmp(username,buf) == 0 )
  469.             break;      /* Found user */
  470.         if(stricmp("univperm",buf) == 0)
  471.             universal = strdup(cp); /* remember their anon entry */
  472.     }
  473.     if((universal == NULLCHAR) && (feof(fp))){
  474.         /* username not found in file, nor was univperm */
  475.         fclose(fp);
  476.         free(buf);
  477.         return NULLCHAR;
  478.     }
  479.     if(feof(fp)){
  480.         /* restore anonymous to the buffer */
  481.         strcpy(cp = buf, universal);
  482.         free(universal);
  483.         universal = NULLCHAR;
  484.     }
  485.     if(universal != NULLCHAR)
  486.         free(universal);
  487.     fclose(fp);
  488.   
  489.     cp = skipwhite(cp);
  490.     if ( password != NULL )
  491.         *password = cp;
  492.   
  493.     /* Look for space or tab after password field in file */
  494.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  495.         /* Invalid file entry */
  496.         free(buf);
  497.         return NULLCHAR;
  498.     }
  499.     *cp++ = '\0';   /* Now points to directory field */
  500.     cp=skipwhite(cp);
  501.   
  502.     if ( directory != NULL )
  503.         *directory = cp;
  504.   
  505.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  506.         /* Permission field missing */
  507.         free(buf);
  508.         return NULLCHAR;
  509.     }
  510.     *cp++ = '\0';   /* now points to permission field */
  511.     cp=skipwhite(cp);
  512.   
  513.     if ( permission != NULL )   {
  514.         if(!strnicmp(cp,"0x",2))
  515.             *permission = htol(cp);
  516.         else
  517.             *permission = atol(cp);
  518.     }
  519.   
  520.     if((cp = strpbrk(cp," \t")) == NULLCHAR)    {
  521.         /* IP address missing */
  522.         if ( ip_address != NULL )
  523.             *ip_address = 0L;
  524.     } else {
  525.         *cp++ = '\0';   /* now points at IP address field */
  526.         if ( ip_address != NULL )
  527.             *ip_address = resolve( cp );
  528.     }
  529.     return buf;
  530. }
  531.   
  532. #endif /* PPP */
  533.   
  534.   
  535. /* Subroutine for logging in the user whose name is name and password is pass.
  536.    The buffer path should be long enough to keep a line from the userfile.
  537.    If pwdignore is true, the password check will be overridden.
  538.    The return value is the permissions field or -1 if the login failed.
  539.    Path is set to point at the path field, and pwdignore will be true if no
  540.    particular password was needed for this user.
  541.  */
  542. long
  543. userlogin(name,pass,path,len,pwdignore,defname)
  544. char *name;
  545. char *pass;
  546. char **path;
  547. int len;            /* Length of buffer pointed at by *path */
  548. int *pwdignore;
  549. char *defname;
  550. {
  551.     char *cp;
  552.     FILE *fp;
  553.     char *universal = NULLCHAR;
  554.     char *defalt = NULLCHAR;
  555.     int anony;
  556.  
  557.     long perm;
  558.     char *line,*user,*password,*privs,*directory;
  559.  
  560.     /* Check environment variables first - WG7J */
  561.     if((user=getenv("NOSSYSOP")) != NULL) {
  562.         if(strcmp(user,name) == 0) {
  563.             /* the right user name, now check password */
  564.             if((password=getenv("NOSPASSWD")) != NULL) {
  565.                 if(strcmp(password,pass) == 0) {
  566.                     *pwdignore = 0;
  567.                     if((directory=getenv("NOSPATH")) != NULL)
  568.                         strcpy(*path,directory);
  569.                     if((privs=getenv("NOSPRIVS")) != NULL) {
  570.                         if(strnicmp(privs,"0x",2) == 0)
  571.                             return htol(privs);
  572.                         else
  573.                             return atol(privs);
  574.                     } else
  575.                         return (FTP_READ + \
  576.                                 FTP_CREATE + \
  577.                                 FTP_WRITE + \
  578.                                 AX25_CMD + \
  579.                                 TELNET_CMD + \
  580.                                 NETROM_CMD + \
  581.                                 SYSOP_CMD + \
  582.                                 IS_EXPERT);
  583.  
  584.                 }
  585.             }
  586.         }
  587.     }
  588.  
  589.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE) {
  590.         /* Userfile doesn't exist */
  591.         *pwdignore = 0;
  592.         return -1;
  593.     }
  594.     while(fgets(*path,len,fp),!feof(fp)){
  595.         line = skipwhite(*path);
  596.         if(*line == '#')
  597.             continue;    /* Comment */
  598.         if((password = strpbrk(line," \t")) == NULLCHAR)
  599.             /* Bogus entry */
  600.             continue;
  601.         rip(line);
  602.         *password++ = '\0';
  603.          /* Now points to spaces or tabs before password */
  604.         password = skipwhite(password);
  605.          /* Now points to password */
  606.         if(stricmp(name,line) == 0)
  607.             break;        /* Found user name */
  608.         if(stricmp("univperm",line) == 0)
  609.             universal = strdup(password); /* remember their anon entry */
  610.     if(stricmp(defname,line) == 0)
  611.         defalt = strdup(password);  /* remember their default entry */
  612.     }
  613.     if((universal == NULLCHAR) && (defalt == NULLCHAR) && (feof(fp))){
  614.         /* User name not found in file, nor was default nor univperm */
  615.         fclose(fp);
  616.         /* No need to free universal ( == NULLCHAR ) remember !!! */
  617.         return -1;
  618.     }
  619.     if(feof(fp) && (defalt != NULLCHAR)){
  620.         /* restore anonymous to the buffer */
  621.             strcpy(password = *path, defalt);
  622.         free(defalt);
  623.         defalt = NULLCHAR;
  624.     }
  625.     else if(feof(fp)){
  626.         /* restore anonymous to the buffer */
  627.             strcpy(password = *path, universal);
  628.         free(universal);
  629.         universal = NULLCHAR;
  630.     }
  631.     
  632.     if(defalt != NULLCHAR)
  633.         free(defalt);
  634.     if(universal != NULLCHAR)
  635.         free(universal);
  636.     fclose(fp);
  637.  
  638.     /* Look for space or tab after password field in file */
  639.     if((directory = strpbrk(password," \t")) == NULLCHAR)
  640.         /* Invalid file entry */
  641.         return -1;
  642.     *directory++ = '\0';  /* Terminate password */
  643.     /* Find start of path */
  644.     directory = skipwhite(directory);
  645.     if(strlen(directory) + 1 > len )
  646.         /* not enough room for path */
  647.         return -1;
  648.  
  649.     if(strcmp(password,"*") == 0)
  650.         *pwdignore = 1;  /* User ID is password-free */
  651.     if(!(*pwdignore) && strcmp(password,pass) != 0)
  652.         /* Password required, but wrong one given */
  653.         return -1;
  654.  
  655.     /* Find permission field */
  656.     if((privs = strpbrk(directory," \t")) == NULLCHAR)
  657.         /* Permission field missing */
  658.         return -1;
  659.     /* Find start of permissions */
  660.     privs = skipwhite(privs);
  661.     if(!strnicmp(privs,"0x",2))
  662.         perm = htol(privs);
  663.     else
  664.         perm = atol(privs);
  665.  
  666.     /* Now copy the compound path, with possibly multiple paths and permissions */
  667.     strcpy(*path,directory);
  668.     dirformat(*path);
  669.  
  670.     /* Finally return the permission bits */
  671.     return perm;
  672. }
  673.  
  674. struct Nosfiles {
  675.     char *name;
  676.     char **path;
  677. };
  678.  
  679. struct Nosfiles Nfiles[] = {
  680.     "Startup",&Startup,
  681.     "Userfile",&Userfile,
  682.     "Hostfile",&Hostfile,
  683.     "Spoolqdir",&Spoolqdir,
  684.     "Maillog",&Maillog,
  685.     "Mailspool",&Mailspool,
  686.     "Mailqdir",&Mailqdir,
  687.     "LogsDir",&LogsDir,
  688.     "Mailqueue",&Mailqueue,
  689.     "Routeqdir",&Routeqdir,
  690.     "Alias",&Alias,
  691.     "Dfile",&Dfile,
  692.     "Fdir",&Fdir,
  693.     "Fdbase",&Fdbase,
  694.     "Pdbase",&Pdbase,
  695.     "Rewritefile",&Rewritefile,
  696.     "Onexit",&Onexit,
  697.     "Ftpmotd",&Ftpmotd,
  698.     "CmdsHelpdir",&CmdsHelpdir,
  699. #ifdef MAILBOX
  700.     "Signature",&Signature,
  701.     "Historyfile",&Historyfile,
  702.     "Helpdir",&Helpdir,
  703.     "Motdfile",&Motdfile,
  704. #ifdef MAILCMDS
  705.     "Arealist",&Arealist,
  706. #endif
  707. #ifdef USERLOG
  708.     "UDefaults",&UDefaults,
  709.     "UDefbak",&UDefbak,
  710.     "Mregfile",&Mregfile,
  711. #endif
  712. #endif
  713. #ifdef CONVERS
  714.     "Cinfo",&Cinfo,
  715. #ifdef CHANGE_PERSONAL
  716.     "Cinfobak",&Cinfobak,
  717. #endif
  718.     "ConvMotd",&ConvMotd,
  719. #ifdef CHANNELNAMES
  720.     "Channelfile",&Channelfile,
  721. #endif
  722. #endif
  723. #if (defined(POP) || defined(POP2CLIENT) || defined(POP2SERVER) || defined(POP3CLIENT) || defined(POP3SERVER))
  724.     "Popusers",&Popusers,
  725. #endif
  726. #if (defined(NNTP) || defined(NNTPS))
  727.     "Newsdir",&Newsdir,
  728.     "History",&History,
  729. #endif
  730. #if (defined(MBFWD) || defined(RLINE))
  731.     "Forwardfile",&Forwardfile,
  732. #endif
  733. #ifdef NETROM
  734.     "Netromfile",&Netromfile,
  735. #endif
  736. #ifdef EXPIRY
  737.     "Expirefile",&Expirefile,
  738. #endif
  739. #ifdef NNTPS
  740.     "Naccess",&Naccess,
  741.     "Active",&Active,
  742.     "Pointer",&Pointer,
  743.     "NInfo",&NInfo,
  744.     "Nhelp",&Nhelp,
  745.     "Forward",&Forward,
  746.     "Poll",&Poll,
  747. #endif
  748.     NULLCHAR,
  749. };
  750.  
  751. #if defined(MSDOS) || defined(UNIX)
  752. void setname(char *name,char *file) {
  753.     int i = 0;
  754.  
  755.     while(Nfiles[i].name != NULLCHAR) {
  756.         if(strcmp(name,Nfiles[i].name) == 0) {
  757.             if(Initroot)
  758.                 free(*Nfiles[i].path);
  759.             *Nfiles[i].path = strdup(file);
  760.             return;
  761.         }
  762.         i++;
  763.     }
  764. }
  765.  
  766. void tabs_to_spaces(char *p) {
  767.     while(*p != '\0') {
  768.         if(*p == '\t')
  769.             *p = ' ';
  770.         p++;
  771.     }
  772. }
  773.  
  774. void
  775. assign_filenames(char *config) {
  776.     FILE *fp;
  777.     char *name,*file,*cp;
  778.     int line;
  779. #define BUFLEN 128
  780.     char buf[BUFLEN+1];
  781.  
  782.     undosify(config);
  783.     if((fp = fopen(config,"r")) == NULL) {
  784.         tprintf("Cannot open %\n",config);
  785.         return;
  786.     }
  787.  
  788.     line = 0;
  789.     while(fgets(buf,BUFLEN,fp) != NULL) {
  790.         line++;
  791.         if(*buf == '#')         /* comment */
  792.             continue;
  793.         rip(buf);   /* delete ending \n */
  794.         tabs_to_spaces(buf);
  795.         name = buf;
  796.         while(*name == ' ')    /* no leading spaces */
  797.             name++;
  798.         if(*name == '\0')      /* blank line */
  799.             continue;
  800.         /* Search for filename */
  801.         if((file = strchr(name,'=')) == NULL) {
  802.             tprintf("Need '=', line %d of %s.\n",line,config);
  803.             continue;
  804.         }
  805.         *file++ = '\0';
  806.         /* cut trailing spaces */
  807.         if((cp = strchr(name,' ')) != NULL)
  808.             *cp = '\0';
  809.  
  810.         /* find start of filename */
  811.         while(*file == ' ')
  812.             file++;
  813.  
  814.         if(*file == '\0')
  815.             continue;
  816.  
  817.         /* cut trailing spaces */
  818.         if((cp = strchr(file,' ')) != NULL)
  819.             *cp = '\0';
  820.  
  821.         /* Now parse the name, and assign if valid */
  822.         setname(name,file);
  823.     }
  824.     fclose(fp);
  825.     Assigned = 1;
  826. }
  827. #endif
  828.