]> code.citadel.org Git - citadel.git/blobdiff - citadel/netproc.c
* Various changes to begin work on support for MIME messages
[citadel.git] / citadel / netproc.c
index 49b912d7a932155951e81f46529fa671709722e7..630254b1e1add6fbae6c2165eda3f0a868b090e7 100644 (file)
@@ -2,16 +2,9 @@
  * Citadel/UX Intelligent Network Processor for IGnet/Open networks v3.6
  * Designed and written by Art Cancro @ Uncensored Communications Group
  * See copyright.txt for copyright information
+ * $Id$
  */
 
-/*
- * Specify where netproc should log to, and the mode for opening the file.
- * If you are logging to a file, NPLOGMODE should be a; if you are logging to
- * a device or fifo it should be w.
- */
-#define NPLOGFILE      "./netproc.log" 
-#define NPLOGMODE      "a"
-
 /* How long it takes for an old node to drop off the network map */
 #define EXPIRY_TIME    (2592000L)
 
@@ -37,7 +30,9 @@
 #include <time.h>
 #include <signal.h>
 #include <errno.h>
+#include <syslog.h>
 #include "citadel.h"
+#include "tools.h"
 
 /* A list of users you wish to filter out of incoming traffic can be kept
  * in ./network/filterlist -- messages from these users will be automatically
 struct msglist {
        struct msglist *next;
        long m_num;
-       char m_rmname[20];
+       char m_rmname[ROOMNAMELEN];
        };
 
 struct rmlist {
        struct rmlist *next;
-       char rm_name[20];
+       char rm_name[ROOMNAMELEN];
        long rm_lastsent;
        };
 
@@ -73,75 +68,32 @@ struct syslist {
        char s_name[16];
        char s_type[4];
        char s_nexthop[128];
-       long s_lastcontact;
+       time_t s_lastcontact;
        char s_humannode[64];
        char s_phonenum[32];
        char s_gdom[64];
        };
 
-struct minfo {
-       char A[512];
-       char E[512];
-       long I;
-       char N[512];
-       char O[512];
-       char R[512];
-       long T;
-       char D[512];
-       char C[512];
-       char nexthop[32];
-       char H[512];
-       char S[512];
-       char B[512];
-       char G[512];
-       };
-
 
-void attach_to_server();
-void serv_read();
-void serv_write();
-void get_config();
+void attach_to_server(int argc, char **argv);
+void serv_read(char *buf, int bytes);
+void serv_write(char *buf, int nbytes);
+void get_config(void);
 
 struct filterlist *filter = NULL;
-char roomnames[MAXROOMS][20];
-char roomdirs[MAXROOMS][15];
 struct syslist *slist = NULL;
 
 struct config config;
 extern char bbs_home_directory[];
 extern int home_specified;
 
-int struncmp(lstr,rstr,len)
-char lstr[],rstr[];
-int len; {
-       int pos = 0;
-       char lc,rc;
-       while (pos<len) {
-               lc=tolower(lstr[pos]);
-               rc=tolower(rstr[pos]);
-               if ((lc==0)&&(rc==0)) return(0);
-               if (lc<rc) return(-1);
-               if (lc>rc) return(1);
-               pos=pos+1;
-               }
-       return(0);
-       }
 
-/* redefine strucmp, just in case we're using an old version of citadel.h
- * that has it as a separate routine
- */
-#ifndef strucmp
-#undef strucmp
-#endif
-#define strucmp(lstr,rstr) struncmp(lstr,rstr,32767)
-
-
-#ifdef NO_STRERROR
+#ifndef HAVE_STRERROR
 /*
  * replacement strerror() for systems that don't have it
  */
-char *strerror(e)
-int e; {
+char *strerror(int e)
+{
        static char buf[32];
 
        sprintf(buf,"errno = %d",e);
@@ -150,43 +102,19 @@ int e; {
 #endif
 
 
-void strip_trailing_whitespace(buf)
-char buf[]; {
+void strip_trailing_whitespace(char *buf)
+{
        while(isspace(buf[strlen(buf)-1]))
                buf[strlen(buf)-1]=0;
        }
 
 
-/*
- * for performance optimization, netproc loads the list of room names (and
- * their corresponding directory names, if applicable) into a table in memory.
- */
-int load_roomnames() {
-       FILE *fp;
-       struct quickroom qbuf;
-       int i;
-
-       fp=fopen("./quickroom","rb");
-       if (fp==NULL) return(1);
-       for (i=0; i<MAXROOMS; ++i) {
-               if (fread((char *)&qbuf,sizeof(struct quickroom),1,fp)!=1)
-                       return(1);
-               strcpy(roomnames[i],qbuf.QRname);
-               if (qbuf.QRflags & QR_DIRECTORY)
-                       strcpy(roomdirs[i],qbuf.QRdirname);
-               else
-                       strcpy(roomdirs[i],config.c_bucket_dir);
-               }
-       fclose(fp);
-       return(0);
-       }
-
 /*
  * we also load the network/mail.sysinfo table into memory, make changes
  * as we learn more about the network from incoming messages, and write
  * the table back to disk when we're done.
  */
-int load_syslist() {
+int load_syslist(void) {
        FILE *fp;
        struct syslist *stemp;
        char insys = 0;
@@ -249,12 +177,12 @@ int load_syslist() {
 /* now we have to set up two "special" nodes on the list: one
  * for the local node, and one for an Internet gateway
  */
-void setup_special_nodes() {
+void setup_special_nodes(void) {
        struct syslist *stemp,*slocal;
 
        slocal = NULL;
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,config.c_nodename)) slocal=stemp;
+               if (!strcasecmp(stemp->s_name,config.c_nodename)) slocal=stemp;
                }
        if (slocal==NULL) {
                slocal =(struct syslist *)malloc(sizeof(struct syslist));
@@ -270,7 +198,7 @@ void setup_special_nodes() {
 
        slocal = NULL;
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,"internet")) slocal=stemp;
+               if (!strcasecmp(stemp->s_name,"internet")) slocal=stemp;
                }
        if (slocal==NULL) {
                slocal =(struct syslist *)malloc(sizeof(struct syslist));
@@ -290,15 +218,15 @@ void setup_special_nodes() {
 /*
  * here's the routine to write the table back to disk.
  */
-void rewrite_syslist() {
+void rewrite_syslist(void) {
        struct syslist *stemp;
        FILE *newfp;
-       long now;
+       time_t now;
 
        time(&now);
        newfp=fopen("network/mail.sysinfo","w");
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,config.c_nodename)) {
+               if (!strcasecmp(stemp->s_name,config.c_nodename)) {
                        time(&stemp->s_lastcontact);
                        strcpy(stemp->s_type,"bin");
                        strcpy(stemp->s_humannode,config.c_humannode);
@@ -335,8 +263,8 @@ void rewrite_syslist() {
 /* call this function with the node name of a system and it returns a pointer
  * to its syslist structure.
  */
-struct syslist *get_sys_ptr(sysname)
-char *sysname; {
+struct syslist *get_sys_ptr(char *sysname)
+{
        static char sysnambuf[16];
        static struct syslist *sysptrbuf = NULL;
        struct syslist *stemp;
@@ -359,38 +287,23 @@ char *sysname; {
 /*
  * make sure only one copy of netproc runs at a time, using lock files
  */
-int set_lockfile() {
+int set_lockfile(void) {
        FILE *lfp;
-       int ok = 1;
        int onppid;
-       char buf[64];
 
-       if (access(LOCKFILE,0)==0) {
-
-       /* 
-        * if the /proc filesystem is available, we can further check to
-        * make sure that the process that wrote the lock file is actually
-        * running, and didn't simply terminate and not clean up after itself
-        */
-#ifdef HAVE_PROC_FS
-               lfp = fopen(LOCKFILE,"r");
-               fscanf(lfp,"%d",&onppid);
-               fclose(lfp);
-               sprintf(buf,"/proc/%d/cmdline",onppid);
-               if (access(buf,0)==0) ok = 0;
-#else
-               ok = 0;
-#endif
+       if ((lfp = fopen(LOCKFILE,"r")) != NULL) {
+                fscanf(lfp,"%d",&onppid);
+                fclose(lfp);
+               if (!kill(onppid, 0) || errno == EPERM) return 1;
                }
 
-       if (ok == 0) return(1);
        lfp=fopen(LOCKFILE,"w");
        fprintf(lfp,"%d\n",getpid());
        fclose(lfp);
        return(0);
        }
 
-void remove_lockfile() {
+void remove_lockfile(void) {
        unlink(LOCKFILE);
        }
 
@@ -401,14 +314,15 @@ void remove_lockfile() {
  * The cleanup() routine makes a check to ensure it's not reentering, in
  * case the ipc module looped it somehow.
  */
-void nq_cleanup(e)
-int e; {
+void nq_cleanup(int e)
+{
        remove_lockfile();
+       closelog();
        exit(e);
        }
 
-void cleanup(e)
-int e; {
+void cleanup(int e)
+{
        static int nested = 0;
 
        alarm(30);
@@ -422,15 +336,15 @@ int e; {
  * client-side IPC modules expect logoff() to be defined.  They call logoff()
  * when a problem connecting or staying connected to the server occurs.
  */
-void logoff(e)
-int e; {
+void logoff(int e)
+{
        cleanup(e);
        }
 
 /*
  * If there is a kill file in place, this function will process it.
  */
-void load_filterlist() {
+void load_filterlist(void) {
        FILE *fp;
        struct filterlist *fbuf;
        char sbuf[256];
@@ -467,46 +381,45 @@ void load_filterlist() {
        }
 
 /* returns 1 if user/message/room combination is in the kill file */
-int is_banned(k_person,k_room,k_system)
-char *k_person,*k_room,*k_system; {
+int is_banned(char *k_person, char *k_room, char *k_system)
+{
        struct filterlist *fptr;
 
        for (fptr=filter; fptr!=NULL; fptr=fptr->next) if (
-        ((!strucmp(fptr->f_person,k_person))||(!strcmp(fptr->f_person,"*")))
+        ((!strcasecmp(fptr->f_person,k_person))||(!strcmp(fptr->f_person,"*")))
        &&
-        ((!strucmp(fptr->f_room,k_room))||(!strcmp(fptr->f_room,"*")))
+        ((!strcasecmp(fptr->f_room,k_room))||(!strcmp(fptr->f_room,"*")))
        &&
-        ((!strucmp(fptr->f_system,k_system))||(!strcmp(fptr->f_system,"*")))
+        ((!strcasecmp(fptr->f_system,k_system))||(!strcmp(fptr->f_system,"*")))
        ) return(1);
 
        return(0);
        }
 
-int get_sysinfo_type(name)     /* determine routing from sysinfo file */
-char name[]; {
+int get_sysinfo_type(char *name)       /* determine routing from sysinfo file */
+             {
        struct syslist *stemp;
 GETSN: for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-           if (!strucmp(stemp->s_name,name)) {
-               if (!strucmp(stemp->s_type,"use")) {
+           if (!strcasecmp(stemp->s_name,name)) {
+               if (!strcasecmp(stemp->s_type,"use")) {
                        strcpy(name,stemp->s_nexthop);
                        goto GETSN;
                        }
-               if (!strucmp(stemp->s_type,"bin")) {
+               if (!strcasecmp(stemp->s_type,"bin")) {
                        return(M_BINARY);
                        }
-               if (!strucmp(stemp->s_type,"uum")) {
+               if (!strcasecmp(stemp->s_type,"uum")) {
                        return(M_INTERNET);
                        }
                }
            }
-       printf("netproc: cannot find system '%s' in mail.sysinfo\n",name);
+       syslog(LOG_ERR, "cannot find system '%s' in mail.sysinfo", name);
        return(-1);
        }
 
 
-void fpgetfield(fp,string)
-FILE *fp;
-char string[]; {
+void fpgetfield(FILE *fp, char *string)
+{
        int a,b;
 
        strcpy(string,"");
@@ -528,9 +441,8 @@ char string[]; {
  * Load all of the fields of a message, except the actual text, into a
  * table in memory (so we know how to process the message).
  */
-void msgfind(msgfile,buffer)
-char *msgfile;
-struct minfo *buffer; {
+void msgfind(char *msgfile, struct minfo *buffer)
+{
        int b,e,mtype,aflag;
        char bbb[1024];
        char userid[1024];
@@ -539,12 +451,12 @@ struct minfo *buffer; {
        strcpy(userid,"");
        fp=fopen(msgfile,"rb");
        if (fp==NULL) {
-               fprintf(stderr,"Can't open message file: %s\n",strerror(errno));
+               syslog(LOG_ERR, "can't open message file: %s",strerror(errno));
                return;
                }
        e=getc(fp);
        if (e!=255) {
-               fprintf(stdout,"Incorrect message format\n");
+               syslog(LOG_ERR, "incorrect message format");
                goto END;
                }
        mtype=getc(fp); aflag=getc(fp);
@@ -598,20 +510,20 @@ END:      if (buffer->I==0L) buffer->I=buffer->T;
        fclose(fp);
        }
 
-void ship_to(filenm,sysnm)     /* send spool file filenm to system sysnm */
-char *filenm;
-char *sysnm; {
+void ship_to(char *filenm, char *sysnm)        /* send spool file filenm to system sysnm */
+             
+             {
        char sysflnm[100];
        char commbuf1[100];
        char commbuf2[100];
        FILE *sysflfd;
 
 #ifdef DEBUG
-       fprintf(stdout,"netproc: shipping %s to %s\n",filenm,sysnm);
+       syslog(LOG_NOTICE, "shipping %s to %s", filenm, sysnm);
 #endif
        sprintf(sysflnm,"./network/systems/%s",sysnm);
        sysflfd=fopen(sysflnm,"r");
-       if (sysflfd==NULL) fprintf(stdout,"netproc: cannot open %s\n",sysflnm);
+       if (sysflfd==NULL) syslog(LOG_ERR, "cannot open %s", sysflnm);
        fgets(commbuf1,99,sysflfd);
        commbuf1[strlen(commbuf1)-1] = 0;
        fclose(sysflfd);
@@ -621,40 +533,56 @@ char *sysnm; {
 
 /*
  * proc_file_transfer()  -  handle a simple file transfer packet
+ *
  */
-void proc_file_transfer(tname)
-char *tname; { /* name of temp file containing the whole message */
-       char buf[128];
-       char dest_dir[32];
+void proc_file_transfer(char *tname)
+{      /* name of temp file containing the whole message */
+       char buf[256];
+       char dest_room[ROOMNAMELEN];
+       char subdir_name[256];
        FILE *tfp,*uud;
-       int a,b;
+       int a;
 
-       printf("netproc: processing network file transfer...\n");
-       strcpy(dest_dir,config.c_bucket_dir);
+       syslog(LOG_NOTICE, "processing network file transfer...");
 
        tfp=fopen(tname,"rb");
-       if (tfp==NULL) printf("netproc: cannot open %s\n",tname);
+       if (tfp==NULL) syslog(LOG_ERR, "cannot open %s", tname);
        getc(tfp); getc(tfp); getc(tfp);
        do {
                a=getc(tfp);
                if (a!='M') {
                        fpgetfield(tfp,buf);
-                       if (a=='O') for (b=0; b<MAXROOMS; ++b) {
-                               if (!strucmp(buf,roomnames[b]))
-                                       strcpy(dest_dir,roomdirs[b]);
+                       if (a=='O') {
+                               strcpy(dest_room, buf);
                                }
                        }
                } while ((a!='M')&&(a>=0));
        if (a!='M') {
                fclose(tfp);
-               printf("netproc: no message text for file transfer\n");
+               syslog(LOG_ERR, "no message text for file transfer");
                return;
                }
 
-       sprintf(buf,"cd %s/files/%s; exec %s",bbs_home_directory,dest_dir,UUDECODE);
+       strcpy(subdir_name, "---xxx---");
+       sprintf(buf, "GOTO %s", dest_room);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0]=='2') {
+               extract(subdir_name, &buf[4], 2);
+               if (strlen(subdir_name) == 0) strcpy(subdir_name, "--xxx--");
+               }
+
+       /* Change to the room's directory; if that fails, change to the
+        * bitbucket directory.  Then run uudecode.
+        */
+       sprintf(buf,"(cd %s/files/%s || cd %s/files/%s ) ; exec %s",
+               bbs_home_directory, subdir_name,
+               bbs_home_directory, config.c_bucket_dir,
+               UUDECODE);
+
        uud=(FILE *)popen(buf,"w");
        if (uud==NULL) {
-               printf("netproc: cannot open uudecode pipe\n");
+               syslog(LOG_ERR, "cannot open uudecode pipe");
                fclose(tfp);
                return;
                }
@@ -672,13 +600,13 @@ char *tname; {    /* name of temp file containing the whole message */
 
 
 /* send a bounce message */
-void bounce(bminfo)
-struct minfo *bminfo; {
+void bounce(struct minfo *bminfo)
+{
 
        FILE *bounce;
        char bfilename[64];
        static int bseq = 1;
-       long now;
+       time_t now;
 
        sprintf(bfilename,"./network/spoolin/bounce.%d.%d",getpid(),bseq++);
        bounce = fopen(bfilename,"wb");
@@ -714,18 +642,20 @@ struct minfo *bminfo; {
 /*
  * process incoming files in ./network/spoolin
  */
-void inprocess() {
+void inprocess(void) {
        FILE *fp,*message,*testfp,*ls;
        static struct minfo minfo;
        struct recentmsg recentmsg;
        char tname[128],aaa[1024],iname[256],sfilename[256],pfilename[256];
        int a,b;
+       int FieldID;
        struct syslist *stemp;
        char *ptr = NULL;
        char buf[256];
        long msglen;
        int bloklen;
 
+
        sprintf(tname,"/tmp/net.t%d",getpid()); /* temp file name */
        sprintf(iname,"/tmp/net.i%d",getpid()); /* temp file name */
 
@@ -738,8 +668,7 @@ void inprocess() {
        sprintf(aaa,"cd %s/network/spoolin; ls",bbs_home_directory);
        ls=popen(aaa,"r");
        if (ls==NULL) {
-               fprintf(stderr,"netproc: could not open dir cmd: %s\n",
-                       strerror(errno));
+               syslog(LOG_ERR, "could not open dir cmd: %s", strerror(errno));
                }
        if (ls!=NULL) {
                do {
@@ -747,21 +676,18 @@ void inprocess() {
                        if (ptr!=NULL) sfilename[strlen(sfilename)-1] = 0;
                        } while( (ptr!=NULL)&&((!strcmp(sfilename,"."))
                                 ||(!strcmp(sfilename,".."))));
-               if (ptr!=NULL) printf("netproc: processing %s\n",sfilename);
+               if (ptr!=NULL) syslog(LOG_NOTICE, "processing %s", sfilename);
                pclose(ls);
                }
 
       if (ptr!=NULL) {
        sprintf(pfilename,"%s/network/spoolin/%s",bbs_home_directory,sfilename);
-       fprintf(stderr,"netproc: processing <%s>\n", pfilename);
-       fflush(stderr);
+       syslog(LOG_NOTICE, "processing <%s>", pfilename);
        
-       fp=fopen(pfilename,"r");
-       if(fp == NULL) {
-           fprintf(stderr, "netproc: cannot open <%s>: %s\n",
-                       pfilename,strerror(errno));
-           fflush(stderr);
-           fp = fopen("/dev/null","r");
+       fp = fopen(pfilename, "rb");
+       if (fp == NULL) {
+           syslog(LOG_ERR, "cannot open %s: %s", pfilename, strerror(errno));
+           fp = fopen("/dev/null" ,"rb");
            }
                
 NXMSG: /* Seek to the beginning of the next message */
@@ -769,21 +695,25 @@ NXMSG:    /* Seek to the beginning of the next message */
                a=getc(fp);
                } while((a!=255)&&(a>=0));
        if (a<0) goto ENDSTR;
-       message=fopen(tname,"wb");
-       putc(255,message);
+
+       message = fopen(tname,"wb");    /* This crates the temporary file. */
+       if (message == NULL) {
+               syslog(LOG_ERR, "error creating %s: %s", tname,strerror(errno));
+               goto ENDSTR;
+               }
+       putc(255,message);              /* 0xFF (start-of-message) */
+       a = getc(fp); putc(a, message); /* type */
+       a = getc(fp); putc(a, message); /* mode */
        do {
+               FieldID = getc(fp);     /* Header field ID */
+               putc(FieldID, message);
                do {
-                       a=getc(fp);
-                       putc(a,message);
-                       } while(a>0);
-               a=getc(fp);
-               putc(a,message);
-               } while ((a!='M') && (a>0));
-       do {
-               a=getc(fp);
-               putc(a,message);
-               } while(a>0);
-       msglen = ftell(fp);
+                       a = getc(fp);
+                       putc(a, message);
+                       } while (a > 0);
+               } while ((FieldID != 'M') && (a >= 0)); /* M is always last */
+
+       msglen = ftell(message);
        fclose(message);
 
        /* process the individual mesage */
@@ -796,23 +726,22 @@ NXMSG:    /* Seek to the beginning of the next message */
        strncpy(recentmsg.RMnodename,minfo.N,9);
        recentmsg.RMnodename[9]=0;
        recentmsg.RMnum=minfo.I;
-       printf("netproc: #%ld fm <%s> in <%s> @ <%s>\n",
+       syslog(LOG_NOTICE, "#%ld fm <%s> in <%s> @ <%s>",
                minfo.I,minfo.A,minfo.O,minfo.N);
        if (strlen(minfo.R)>0) {
-               printf("         to <%s>",minfo.R);
+               syslog(LOG_NOTICE, "     to <%s>",minfo.R);
                if (strlen(minfo.D)>0) {
-                       printf(" @ <%s>",minfo.D);
+                       syslog(LOG_NOTICE, "     @ <%s>",minfo.D);
                        }
-               printf("\n");
                }
-       fflush(stdout);
-       if (!strucmp(minfo.D,FQDN)) strcpy(minfo.D,NODENAME);
+       if (!strcasecmp(minfo.D,FQDN)) strcpy(minfo.D,NODENAME);
 
        /* this routine updates our info on the system that sent the message */
        stemp = get_sys_ptr(minfo.N);
        if ((stemp == NULL) && (get_sys_ptr(minfo.nexthop) != NULL)) {
                /* add non-neighbor system to map */
-               printf("Adding non-neighbor system <%s> to map\n", slist->s_name);
+               syslog(LOG_NOTICE, "Adding non-neighbor system <%s> to map",
+                       slist->s_name);
                stemp = (struct syslist *)malloc((long)sizeof(struct syslist));
                stemp->next = slist;
                slist = stemp;
@@ -821,9 +750,10 @@ NXMSG:     /* Seek to the beginning of the next message */
                strcpy(slist->s_nexthop,minfo.nexthop);
                time(&slist->s_lastcontact);
                }
-       else if ((stemp == NULL) && (!strucmp(minfo.N,minfo.nexthop))) {
+       else if ((stemp == NULL) && (!strcasecmp(minfo.N,minfo.nexthop))) {
                /* add neighbor system to map */
-               printf("Adding neighbor system <%s> to map\n", slist->s_name);
+               syslog(LOG_NOTICE, "Adding neighbor system <%s> to map",
+                       slist->s_name);
                sprintf(aaa,"%s/network/systems/%s",bbs_home_directory,minfo.N);
                testfp=fopen(aaa,"r");
                if (testfp!=NULL) {
@@ -847,19 +777,18 @@ NXMSG:    /* Seek to the beginning of the next message */
                }
 
        /* route the message if necessary */
-       if ((strucmp(minfo.D,NODENAME))&&(minfo.D[0]!=0)) { 
+       if ((strcasecmp(minfo.D,NODENAME))&&(minfo.D[0]!=0)) { 
                a = get_sysinfo_type(minfo.D);
-               printf("netproc: routing message to system <%s>\n",minfo.D);
+               syslog(LOG_NOTICE, "routing message to system <%s>", minfo.D);
                fflush(stdout);
                if (a==M_INTERNET) {
                        if (fork()==0) {
-                               printf("netproc: netmailer %s\n", tname);
+                               syslog(LOG_NOTICE, "netmailer %s", tname);
                                fflush(stdout);
                                execlp("./netmailer","netmailer",
                                        tname,NULL);
-                               printf("netproc: error running netmailer: %s\n",
+                               syslog(LOG_ERR, "error running netmailer: %s",
                                        strerror(errno));
-                               fflush(stdout);
                                exit(errno);
                                }
                        else while (wait(&b)!=(-1));
@@ -873,14 +802,14 @@ NXMSG:    /* Seek to the beginning of the next message */
                }
 
        /* check to see if it's a file transfer */
-       else if (!struncmp(minfo.S,"FILE",4)) {
+       else if (!strncasecmp(minfo.S,"FILE",4)) {
                proc_file_transfer(tname);
                }
 
        /* otherwise process it as a normal message */
        else {
 
-               if (!strucmp(minfo.R, "postmaster")) {
+               if (!strcasecmp(minfo.R, "postmaster")) {
                        strcpy(minfo.R, "");
                        strcpy(minfo.C, "Aide");
                        }
@@ -902,7 +831,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') {
-                       puts(buf); fflush(stdout);
+                       syslog(LOG_ERR, "%s", buf);
                        sprintf(buf,"GOTO _BITBUCKET_");
                        serv_puts(buf);
                        serv_gets(buf);
@@ -911,23 +840,16 @@ NXMSG:    /* Seek to the beginning of the next message */
                /* Open the temporary file containing the message */
                message = fopen(tname, "rb");
                if (message == NULL) {
-                       fprintf(stderr, "netproc: cannot open %s: %s\n",
+                       syslog(LOG_ERR, "cannot open %s: %s",
                                tname, strerror(errno));
                        unlink(tname);
                        goto NXMSG;
                        }
 
-               /* Measure the message */
-               fseek(message, 0L, 2);
-               msglen = ftell(fp);
-               fseek(message, 0L, 0);
-
                /* Transmit the message to the server */
                sprintf(buf, "ENT3 1|%s|%ld", minfo.R, msglen);
-               printf("< %s\n", buf);
                serv_puts(buf);
                serv_gets(buf);
-               printf("> %s\n", buf);
                if (!strncmp(buf, "570", 3)) {
                        /* no such user, do a bounce */
                        bounce(&minfo);
@@ -939,9 +861,9 @@ NXMSG:      /* Seek to the beginning of the next message */
                        while (msglen > 0L) {
                                bloklen = ((msglen >= 255L) ? 255 : ((int)msglen));
                                if (fread(buf, bloklen, 1, message) < 1) {
-                                       fprintf(stderr, "netproc: error trying to read %d bytes: %s\n",
-                                               bloklen, strerror(errno));
-                                       fflush(stderr);
+                                       syslog(LOG_ERR,
+                                          "error trying to read %d bytes: %s",
+                                          bloklen, strerror(errno));
                                        }
                                serv_write(buf, bloklen);
                                msglen = msglen - (long)bloklen;
@@ -950,8 +872,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                        serv_gets(buf);
                        }
                else {
-                       puts(buf);
-                       fflush(stdout); 
+                       syslog(LOG_ERR, "%s", buf);
                        }
 
                fclose(message);
@@ -968,16 +889,16 @@ ENDSTR:   fclose(fp);
     }
 
 
-int checkpath(path,sys)        /* Checks to see whether its ok to send */
-char path[];           /* Returns 1 for ok, send message       */
-char sys[]; {          /* Returns 0 if message already there   */
+int checkpath(char *path, char *sys)   /* Checks to see whether its ok to send */
+                       /* Returns 1 for ok, send message       */
+            {          /* Returns 0 if message already there   */
        int a;
        char sys2[512];
        strcpy(sys2,sys);
        strcat(sys2,"!");
 
 #ifdef DEBUG
-       printf("netproc: checkpath <%s> <%s> ... ",path,sys);
+       syslog(LOG_NOTICE, "checkpath <%s> <%s> ... ", path, sys);
 #endif
        for (a=0; a<strlen(path); ++a) {
                if (!strncmp(&path[a],sys2,strlen(sys2))) return(0);
@@ -988,10 +909,8 @@ char sys[]; {              /* Returns 0 if message already there   */
 /*
  * implement split horizon algorithm
  */
-int ismsgok(mpos,mmfp,sysname)
-long mpos;
-FILE *mmfp;
-char *sysname; {
+int ismsgok(long int mpos, FILE *mmfp, char *sysname)
+{
        int a;
        int ok = 0;             /* fail safe - no path, don't send it */
        char fbuf[256];
@@ -1007,15 +926,15 @@ char *sysname; {
                        }
                }
 #ifdef DEBUG
-       printf("%s\n", ((ok)?"SEND":"(no)") );
+       syslog(LOG_NOTICE, "%s", ((ok)?"SEND":"(no)") );
 #endif
        return(ok);
        }
 
-int spool_out(cmlist,destfp,sysname)   /* spool list of messages to a file */
-struct msglist *cmlist;                        /* returns # of msgs spooled */
-FILE *destfp; 
-char *sysname;
+int spool_out(struct msglist *cmlist, FILE *destfp, char *sysname)     /* spool list of messages to a file */
+                                               /* returns # of msgs spooled */
+              
+              
 {
        struct msglist *cmptr;
        FILE *mmfp;
@@ -1036,7 +955,7 @@ char *sysname;
        for (cmptr=cmlist; cmptr!=NULL; cmptr=cmptr->next) {
 
                /* make sure we're in the correct room... */
-               if (strucmp(curr_rm, cmptr->m_rmname)) {
+               if (strcasecmp(curr_rm, cmptr->m_rmname)) {
                        sprintf(buf, "GOTO %s", cmptr->m_rmname);
                        serv_puts(buf);
                        serv_gets(buf);
@@ -1044,7 +963,7 @@ char *sysname;
                                strcpy(curr_rm, cmptr->m_rmname);
                                }
                        else {
-                               fprintf(stderr,"%s\n", buf);
+                               syslog(LOG_ERR, "%s", buf);
                                }
                        }
 
@@ -1063,7 +982,7 @@ char *sysname;
                                }
                        }
                else {                                  /* or print the err */
-                       fprintf(stderr, "%s\n", buf);
+                       syslog(LOG_ERR, "%s", buf);
                        }
                fclose(mmfp);
        
@@ -1099,8 +1018,8 @@ char *sysname;
        return(msgs_spooled);
        }
 
-void outprocess(sysname) /* send new room messages to sysname */
-char *sysname; {
+void outprocess(char *sysname) /* send new room messages to sysname */
+               {
        char sysflnm[64];
        char srmname[32];
        char shiptocmd[128];
@@ -1137,7 +1056,7 @@ char *sysname; {
                strip_trailing_whitespace(rmptr->rm_name);
                rmptr->rm_lastsent = atol(lbuf);
                if (crmlist==NULL) crmlist=rmptr;
-               else if (!strucmp(rmptr->rm_name,"control")) {
+               else if (!strcasecmp(rmptr->rm_name,"control")) {
                        /* control has to be first in room list */
                        rmptr->next = crmlist;
                        crmlist = rmptr;
@@ -1159,7 +1078,7 @@ char *sysname; {
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0]!='2') {
-                       fprintf(stderr, "%s\n", buf);
+                       syslog(LOG_ERR, "%s", buf);
                        }
                else {
                        sprintf(buf, "MSGS GT|%ld", rmptr->rm_lastsent);
@@ -1186,7 +1105,7 @@ char *sysname; {
                                        }
                                }
                        else {          /* print error from "msgs all" */
-                               fprintf(stderr, "%s\n", buf);
+                               syslog(LOG_ERR, "%s", buf);
                                }
                        }
                }
@@ -1196,18 +1115,15 @@ char *sysname; {
                ++outgoing_msgs;
                cmptr2 = cmptr2->next;
                }
-       printf("netproc: %d messages to be spooled to %s\n",
+       syslog(LOG_NOTICE, "%d messages to be spooled to %s",
                outgoing_msgs,sysname);
-       fflush(stdout);
 
 /*
  * Spool out the messages, but only if there are any.
  */
-       fflush(stdout);
        if (outgoing_msgs!=0) outgoing_msgs=spool_out(cmlist,tempflfp,sysname);
-       printf("netproc: %d messages actually spooled\n",
+       syslog(LOG_NOTICE, "%d messages actually spooled",
                outgoing_msgs);
-       fflush(stdout);
 
 /*
  * Deallocate list of spooled messages.
@@ -1221,8 +1137,7 @@ char *sysname; {
 /*
  * Rewrite system file and deallocate room list.
  */
-       printf("Spooling...\n");
-       fflush(stdout);
+       syslog(LOG_NOTICE, "Spooling...");
        sysflfp=fopen(sysflnm,"w");
        fprintf(sysflfp,"%s\n",shiptocmd);
        for (rmptr=crmlist; rmptr!=NULL; rmptr=rmptr->next)  
@@ -1246,21 +1161,21 @@ char *sysname; {
 /*
  * Connect netproc to the Citadel server running on this computer.
  */
-void np_attach_to_server() {
+void np_attach_to_server(void) {
        char buf[256];
        char portname[8];
        char *args[] = { "netproc", "localhost", NULL, NULL } ;
 
-       printf("Attaching to server...\n");
+       syslog(LOG_NOTICE, "Attaching to server...");
        sprintf(portname, "%d", config.c_port_number);
        args[2] = portname;
        attach_to_server(3, args);
        serv_gets(buf);
-       printf("%s\n",&buf[4]);
+       syslog(LOG_NOTICE, "%s", &buf[4]);
        sprintf(buf,"IPGM %d", config.c_ipgm_secret);
        serv_puts(buf);
        serv_gets(buf);
-       printf("%s\n",&buf[4]);
+       syslog(LOG_NOTICE, "%s", &buf[4]);
        if (buf[0]!='2') {
                cleanup(2);
                }
@@ -1271,40 +1186,39 @@ void np_attach_to_server() {
 /*
  * main
  */
-void main(argc,argv)
-int argc;
-char *argv[];
+int main(int argc, char **argv)
 {
        char allst[32];
        FILE *allfp;
        int a;
+       int import_only = 0;    /* if set to 1, don't export anything */
 
-
+       openlog("netproc", LOG_PID, LOG_USER);
        strcpy(bbs_home_directory, BBSDIR);
 
        /*
         * Change directories if specified
         */
-       if (argv > 0) for (a=1; a<argc; ++a) {
+       for (a=1; a<argc; ++a) {
                if (!strncmp(argv[a], "-h", 2)) {
                        strcpy(bbs_home_directory, argv[a]);
                        strcpy(bbs_home_directory, &bbs_home_directory[2]);
                        home_specified = 1;
                        }
+               else if (!strcmp(argv[a], "-i")) {
+                       import_only = 1;
+                       }
                else {
-                       fprintf(stderr, "netproc: usage: netproc [-hHomeDir]\n");
+                       fprintf(stderr, "netproc: usage: ");
+                       fprintf(stderr, "netproc [-hHomeDir] [-i]\n");
                        exit(1);
                        }
                }
 
        get_config();
 
-       /* write all messages to the log from this point onward */
-       freopen(NPLOGFILE,NPLOGMODE,stdout);
-       freopen(NPLOGFILE,NPLOGMODE,stderr);
-
        if (set_lockfile()!=0) {
-               fprintf(stderr,"netproc: lock file exists: already running\n");
+               syslog(LOG_NOTICE, "lock file exists: already running");
                cleanup(1);
                }
 
@@ -1313,29 +1227,31 @@ char *argv[];
        signal(SIGHUP,cleanup);
        signal(SIGTERM,cleanup);
 
-       printf("netproc: started.  pid=%d\n",getpid());
+       syslog(LOG_NOTICE, "started.  pid=%d", getpid());
        fflush(stdout);
        np_attach_to_server();
        fflush(stdout);
 
-       if (load_roomnames()!=0) fprintf(stdout,"netproc: cannot load rooms\n");
-       if (load_syslist()!=0) fprintf(stdout,"netproc: cannot load sysinfo\n");
+       if (load_syslist()!=0) syslog(LOG_ERR, "cannot load sysinfo");
        setup_special_nodes();
 
        inprocess();    /* first collect incoming stuff */
 
-       allfp=(FILE *)popen("cd ./network/systems; ls","r");
-       if (allfp!=NULL) {
-               while (fgets(allst,32,allfp)!=NULL) {
-                       allst[strlen(allst)-1] = 0;
-                       outprocess(allst);
+       if (import_only != 1) {
+               allfp=(FILE *)popen("cd ./network/systems; ls","r");
+               if (allfp!=NULL) {
+                       while (fgets(allst,32,allfp)!=NULL) {
+                               allst[strlen(allst)-1] = 0;
+                               outprocess(allst);
+                               }
+                       pclose(allfp);
                        }
-               pclose(allfp);
+               /* import again in case anything new was generated */
+               inprocess();
                }
 
-       inprocess();    /* incoming again in case anything new was generated */
        rewrite_syslist();
-       printf("netproc: processing ended.\n");
+       syslog(LOG_NOTICE, "processing ended.");
        cleanup(0);
+       return 0;
        }
-