home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / FILES.C < prev    next >
C/C++ Source or Header  |  1993-03-07  |  11KB  |  342 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. /*
  3.  *      25/06/92    paul@wolf.demon.co.uk added '@' and '~' password
  4.  *                  flags
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "global.h"
  9. #include "netuser.h"
  10. #include "files.h"
  11.  
  12. #ifdef    MSDOS
  13. char *Startup = "/autoexec.net";    /* Initialization file */
  14. char *Userfile = "/ftpusers";    /* Authorized FTP users and passwords */
  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 *Mailqueue = "/spool/mqueue/*.wrk";    /* Outgoing mail work files */
  19. char *Routeqdir = "/spool/rqueue";        /* queue for router */
  20. char *Alias = "/alias";        /* the alias file */
  21. char *Dfile = "/domain.txt";    /* Domain cache */
  22. char *Dzones = "/spool/zones";    /* Zone file directory */
  23. char *Dscripts = "/spool/scripts";    /* Script file directory */
  24. char *Dboot = "/named.boo";    /* Nameserver boot file */
  25. char *Fdir = "/finger";        /* Finger info directory */
  26. char *Arealist = "/spool/areas";/* List of message areas */
  27. char *Helpdir = "/spool/help";    /* Mailbox help file directory */
  28. char *Rewritefile = "/spool/rewrite"; /* Address rewrite file */
  29. char *Newsdir = "/spool/news";        /* News messages and NNTP data */
  30. char *Popusers = "/popusers";        /* POP user and passwd file */
  31. char *Signature = "/spool/signatur"; /* Mail signature file directory */
  32. char *Forwardfile = "/spool/forward.bbs"; /* Mail forwarding file */
  33. char *Historyfile = "/spool/history"; /* Message ID history file */
  34. char *Scripts = "/scripts";    /* PPP up/down scripts */
  35. char *Mailkill = "/mailkill"; /* SMTP sender reject file */
  36. char Eol[] = "\r\n";
  37. #define    SEPARATOR    "/"
  38. #endif
  39.  
  40. #ifdef    UNIX
  41. char *Startup = "./startup.net";    /* Initialization file */
  42. char *Config = "./config.net";    /* Device configuration list */
  43. char *Userfile = "./ftpusers";
  44. char *Mailspool = "./mail";
  45. char *Maillog = "./mail.log";    /* mail log */
  46. char *Mailqdir = "./mqueue";
  47. char *Mailqueue = "./mqueue/*.wrk";
  48. char *Routeqdir = "./rqueue";        /* queue for router */
  49. char *Alias = "./alias";    /* the alias file */
  50. char *Dfile = "./domain.txt";    /* Domain cache */
  51. char *Fdir = "./finger";        /* Finger info directory */
  52. char *Arealist = "./areas";        /* List of message areas */
  53. char *Helpdir = "./help";    /* Mailbox help file directory */
  54. char *Rewritefile = "./rewrite"; /* Address rewrite file */
  55. char *Newsdir = "./news";        /* News messages and NNTP data */
  56. char *Popusers = "./popusers";        /* POP user and passwd file */
  57. char *Signature = "./signatur"; /* Mail signature file directory */
  58. char *Forwardfile = "./forward.bbs"; /* Mail forwarding file */
  59. char *Historyfile = "./history"; /* Message ID history file */
  60. #define    SEPARATOR    "/"
  61. char Eol[] = "\n";
  62. #endif
  63.  
  64. #ifdef    AMIGA
  65. char *Startup = "TCPIP:net-startup";
  66. char *Config = "TCPIP:config.net";    /* Device configuration list */
  67. char *Userfile = "TCPIP:ftpusers";
  68. char *Mailspool = "TCPIP:spool/mail";
  69. char *Maillog = "TCPIP:spool/mail.log";
  70. char *Mailqdir = "TCPIP:spool/mqueue";
  71. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  72. char *Routeqdir = "TCPIP:spool/rqueue";        /* queue for router */
  73. char *Alias = "TCPIP:alias";    /* the alias file */
  74. char *Dfile = "TCPIP:domain.txt";    /* Domain cache */
  75. char *Fdir = "TCPIP:finger";        /* Finger info directory */
  76. char *Arealist = "TCPIP:spool/areas";    /* List of message areas */
  77. char *Helpdir = "TCPIP:spool/help";    /* Mailbox help file directory */
  78. char *Rewritefile = "TCPIP:spool/rewrite"; /* Address rewrite file */
  79. char *Newsdir = "TCPIP:spool/news";    /* News messages and NNTP data */
  80. char *Popusers = "TCPIP:/popusers";    /* POP user and passwd file */
  81. char *Signature = "TCPIP:spool/signatur"; /* Mail signature file directory */
  82. char *Forwardfile = "TCPIP:spool/forward.bbs"; /* Mail forwarding file */
  83. char *Historyfile = "TCPIP:spool/history"; /* Message ID history file */
  84. #define    SEPARATOR    "/"
  85. char Eol[] = "\r\n";
  86. #endif
  87.  
  88. #ifdef    MAC
  89. char *Startup ="Mikes Hard Disk:net.start";
  90. char *Config = "Mikes Hard Disk:config.net";    /* Device configuration list */
  91. char *Userfile = "Mikes Hard Disk:ftpusers";
  92. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  93. char *Maillog = "Mikes Hard Disk:spool:mail.log:";
  94. char *Mailqdir = "Mikes Hard Disk:spool:mqueue:";
  95. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  96. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";    /* queue for router */
  97. char *Alias = "Mikes Hard Disk:alias";    /* the alias file */
  98. char *Dfile = "Mikes Hard Disk:domain:txt";    /* Domain cache */
  99. char *Fdir = "Mikes Hard Disk:finger";        /* Finger info directory */
  100. char *Arealist = "Mikes Hard Disk:spool/areas";    /* List of message areas */
  101. char *Helpdir = "Mikes Hard Disk:spool/help"; /* Mailbox help file directory */
  102. char *Rewritefile = "Mikes Hard Disk:spool/rewrite"; /* Address rewrite file */
  103. char *Newsdir = "Mikes Hard Disk:spool/news"; /* News messages and NNTP data */
  104. char *Popusers = "Mikes Hard Disk:/popusers";    /* POP user and passwd file */
  105. char *Signature = "Mikes Hard Disk:spool/signatur"; /* Mail signature file directory */
  106. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  107. char *Historyfile = "Mikes Hard Disk:spool/history"; /* Message ID history file */
  108. #define    SEPARATOR    ":"
  109. char Eol[] = "\r";
  110. #endif
  111.  
  112. static char *rootdir = "";
  113.  
  114. /* Establish a root directory other than the default. Can only be called
  115.  * once, at startup time
  116.  */
  117. void
  118. initroot(root)
  119. char *root;
  120. {
  121.     rootdir = strdup( root );
  122.  
  123.     Startup = rootdircat(Startup);
  124.     Userfile = rootdircat(Userfile);
  125.     Maillog = rootdircat(Maillog);
  126.     Mailspool = rootdircat(Mailspool);
  127.     Mailqdir = rootdircat(Mailqdir);
  128.     Mailqueue = rootdircat(Mailqueue);
  129.     Routeqdir = rootdircat(Routeqdir);
  130.     Alias = rootdircat(Alias);
  131.     Dfile = rootdircat(Dfile);
  132.     Dzones = rootdircat(Dzones);
  133.     Dscripts = rootdircat(Dscripts);
  134.     Dboot = rootdircat(Dboot);
  135.     Fdir = rootdircat(Fdir);
  136.     Arealist = rootdircat(Arealist);
  137.     Helpdir = rootdircat(Helpdir);
  138.     Rewritefile = rootdircat(Rewritefile);
  139.     Newsdir = rootdircat(Newsdir);
  140.     Signature = rootdircat(Signature);
  141.     Forwardfile = rootdircat(Forwardfile);
  142.     Historyfile = rootdircat(Historyfile);
  143.     Scripts = rootdircat(Scripts);
  144.     Mailkill = rootdircat(Mailkill);
  145. }
  146.  
  147. /* Concatenate root, separator and arg strings into a malloc'ed output
  148.  * buffer, then remove repeated occurrences of the separator char
  149.  */
  150. char *
  151. rootdircat(filename)
  152. char *filename;
  153. {
  154.     char *out = filename;
  155.  
  156.     if ( strlen(rootdir) > 0 ) {
  157.         char *separator = SEPARATOR;
  158.  
  159.         out = mallocw( strlen(rootdir)
  160.                 + strlen(separator)
  161.                 + strlen(filename) + 1);
  162.  
  163.         strcpy(out,rootdir);
  164.         strcat(out,separator);
  165.         strcat(out,filename);
  166.         if(*separator != '\0'){
  167.             char *p1, *p2;
  168.  
  169.             /* Remove any repeated occurrences */
  170.             p1 = p2 = out;
  171.             while(*p2 != '\0'){
  172.                 *p1++ = *p2++;
  173.                 while(p2[0] == p2[-1] && p2[0] == *separator)
  174.                     p2++;
  175.             }
  176.             *p1 = '\0';
  177.         }
  178.     }
  179.     return out;
  180. }
  181.  
  182. /* Read through FTPUSERS looking for user record
  183.  * Returns line which matches username, or NULLCHAR when no match.
  184.  * Each of the other variables must be copied before freeing the line.
  185.  */
  186. char *
  187. userlookup(username,password,directory,permission,ip_address)
  188. char *username;
  189. char **password;
  190. char **directory;
  191. int   *permission;
  192. int32 *ip_address;
  193. {
  194.     FILE *fp;
  195.     char *buf;
  196.     char *cp;
  197.  
  198.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  199.         /* Userfile doesn't exist */
  200.         return NULLCHAR;
  201.  
  202.     buf = mallocw(128);
  203.     while ( fgets(buf,128,fp) != NULLCHAR ){
  204.         if(*buf == '#')
  205.             continue;    /* Comment */
  206.  
  207.         if((cp = strchr(buf,' ')) == NULLCHAR)
  208.             /* Bogus entry */
  209.             continue;
  210.         *cp++ = '\0';        /* Now points to password */
  211.  
  212.         if( stricmp(username,buf) == 0 )
  213.             break;        /* Found user */
  214.     }
  215.     if(feof(fp)){
  216.         /* username not found in file */
  217.         fclose(fp);
  218.         free(buf);
  219.         return NULLCHAR;
  220.     }
  221.     fclose(fp);
  222.  
  223.     if ( password != NULL )
  224.         *password = cp;
  225.  
  226.     /* Look for space after password field in file */
  227.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  228.         /* Invalid file entry */
  229.         free(buf);
  230.         return NULLCHAR;
  231.     }
  232.     *cp++ = '\0';    /* Now points to directory field */
  233.  
  234.     if ( directory != NULL )
  235.         *directory = cp;
  236.  
  237.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  238.         /* Permission field missing */
  239.         free(buf);
  240.         return NULLCHAR;
  241.     }
  242.     *cp++ = '\0';    /* now points to permission field */
  243.  
  244.     if ( permission != NULL )
  245.         *permission = (int)strtol( cp, NULLCHARP, 0 );
  246.  
  247.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  248.         /* IP address missing */
  249.         if ( ip_address != NULL )
  250.             *ip_address = 0L;
  251.     } else {
  252.         *cp++ = '\0';    /* now points at IP address field */
  253.         if ( ip_address != NULL )
  254.             *ip_address = resolve( cp );
  255.     }
  256.     return buf;
  257. }
  258.  
  259. /* Subroutine for logging in the user whose name is name and password is pass.
  260.  * The buffer path should be long enough to keep a line from the userfile.
  261.  * If pwdignore is true, the password check will be overridden.
  262.  * The return value is the permissions field or -1 if the login failed.
  263.  * Path is set to point at the path field, and pwdignore will be true if no
  264.  * particular password was needed for this user.
  265.  */
  266. int
  267. userlogin(name,pass,path,len,pwdignore)
  268. char *name;
  269. char *pass;
  270. char **path;
  271. int len;            /* Length of buffer pointed at by *path */
  272. int *pwdignore;
  273. {
  274.     char *buf;
  275.     char *password;
  276.     char *directory;
  277.     int permission;
  278.     int anonymous;
  279.     char *cp;
  280.     int failed=0;
  281.  
  282.     if ( (buf = userlookup( name, &password, &directory,
  283.             &permission, NULL )) == NULLCHAR ) {
  284.         return -1;
  285.     }
  286.  
  287.     anonymous = *pwdignore;
  288.     if ( strcmp(password,"*") == 0 )
  289.         anonymous = TRUE;    /* User ID is password-free */
  290.  
  291.     if ( strcmp(password,"~") == 0 )
  292.         failed=1;           /* 'Dummy' user - (needed for SMTP bouncing) */
  293.  
  294.     if ( strcmp(password,"@") == 0 )
  295.     {
  296.         anonymous = TRUE;   /* Only check for '@' in the password */
  297.         if (strchr(pass,'@') == NULLCHAR)
  298.             failed=1;
  299.     }
  300.  
  301.     if((!anonymous && strcmp(password,pass) != 0)||(failed)) {
  302.         /* Password required, but wrong one given */
  303.         free(buf);
  304.         return -1;
  305.     }
  306.  
  307.     if ( strlen( directory ) + 1 > len ) {
  308.         /* not enough room for path */
  309.         free(buf);
  310.         return -1;
  311.     }
  312.  
  313. #if   defined(AMIGA)
  314.     /*
  315.      * Well, on the Amiga, a file can be referenced by many names:
  316.      * device names (DF0:) or volume names (My_Disk:).  This hunk of code
  317.      * passed the pathname specified in the ftpusers file, and gets the
  318.      * absolute path copied into the user's buffer.  We really should just
  319.      * allocate the buffer and return a pointer to it, since the caller
  320.      * really doesn't have a good idea how long the path string is..
  321.      */
  322.     if ( (directory = pathname("", directory)) != NULLCHAR ) {
  323.         strcpy(*path, directory);
  324.         free(directory);
  325.     } else {
  326.         **path = '\0';
  327.     }
  328. #else
  329.     strcpy(*path,directory);
  330.     /* Convert any backslashes to forward slashes, for backward
  331.      * compatibility with the old NET
  332.      */
  333.     while((cp = strchr(*path,'\\')) != NULLCHAR)
  334.         *cp = '/';
  335. #endif
  336.     free(buf);
  337.     *pwdignore = anonymous;
  338.     /* Finally return the permission bits */
  339.     return permission;
  340. }
  341.  
  342.