home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1992-05-03  |  10KB  |  319 lines

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