X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fcitmail.c;h=bd4049008f6677c5e762307cf1a3289df0acd1b7;hb=HEAD;hp=4dec56b212d4846182f005687933e4f8eb226710;hpb=54b54a07b29cd57a19728f468e19cf887cda3873;p=citadel.git diff --git a/citadel/citmail.c b/citadel/citmail.c deleted file mode 100644 index 4dec56b21..000000000 --- a/citadel/citmail.c +++ /dev/null @@ -1,796 +0,0 @@ -/* - * citmail.c v4.0 - * - * This program may be used as a local mail delivery agent, which will allow - * all Citadel users to receive Internet e-mail. To enable this functionality, - * you must tell sendmail, smail, or whatever mailer you are using, that this - * program is your local mail delivery agent. This program is a direct - * replacement for lmail, deliver, or whatever. - * - * Usage: - * - * citmail - Deliver a message - * citmail -t - Address test mode (will not deliver) - * citmail -i - Run as an SMTP daemon (typically from inetd) - * - */ - -#include "sysdep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "citadel.h" - -#define LOCAL 0 -#define REMOTE 1 -#define UUCP 2 -#define CCITADEL 3 - -#undef tolower -#define tolower(x) isupper(x) ? (x+'a'-'A') : x - -char *monthdesc[] = { "Jan","Feb","Mar","Apr","May","Jun", - "Jul","Aug","Sep","Oct","Nov","Dec" }; - - - -void LoadInternetConfig(); -void get_config(); -int IsHostLocal(); -struct config config; - -char ALIASES[128]; -char CIT86NET[128]; -char SENDMAIL[128]; -char FALLBACK[128]; -char GW_DOMAIN[128]; -char TABLEFILE[128]; -char OUTGOING_FQDN[128]; -int RUN_NETPROC = 1; - -int struncmp(lstr,rstr,l) -char lstr[],rstr[]; { - int pos = 0; - char lc,rc; - while (1) { - if (pos==l) return(0); - lc=tolower(lstr[pos]); - rc=tolower(rstr[pos]); - if ((lc==0)&&(rc==0)) return(0); - if (lcrc) return(1); - pos=pos+1; - } - } - -long conv_date(sdbuf) -char sdbuf[]; { - int a,b,cpos,tend,tval; - long now; - struct tm *tmbuf; - char dbuf[128]; - - strcpy(dbuf,sdbuf); - time(&now); - tmbuf = (struct tm *)localtime(&now); - - /* get rid of + or - timezone mods */ - for (a=0; a=0; --a) - if ((dbuf[a]==':')&&(atoi(&dbuf[a-1])!=0)) cpos=a; - if (cpos>=0) { - cpos = cpos - 2; - tend = strlen(dbuf); - for (a=tend; a>=cpos; --a) if (dbuf[a]==' ') tend=a; - - tmbuf->tm_hour = atoi(&dbuf[cpos]); - tmbuf->tm_min = atoi(&dbuf[cpos+3]); - tmbuf->tm_sec = atoi(&dbuf[cpos+6]); - - do { - strcpy(&dbuf[cpos],&dbuf[cpos+1]); - } while ((dbuf[cpos]!=32)&&(dbuf[cpos]!=0)); - } - - /* next try to extract a month */ - - tval = (-1); - for (a=0; a= 0) { - tmbuf->tm_mon = tval; - strcpy(&dbuf[cpos],&dbuf[cpos+3]); - } - - /* now the year */ - - for (a=0; a=1900) && (dbuf[a]!=32)) { - tmbuf->tm_year = atoi(&dbuf[a]) - 1900; - strcpy(&dbuf[a],&dbuf[a+4]); - } - - /* whatever's left is the mday (hopefully) */ - - for (a=0; a=1)&&(atoi(&dbuf[a])<=31) - && ( (a==0)||(dbuf[a-1]==' ') ) ) { - tmbuf->tm_mday = atoi(&dbuf[a]); - strcpy(&dbuf[a],&dbuf[a+2]); - } - - return((long)mktime(tmbuf)); - } - - -#ifdef NO_STRERROR -/* - * replacement strerror() for systems that don't have it - */ -char *strerror(e) -int e; { - static char buf[32]; - - sprintf(buf,"errno = %d",e); - return(buf); - } -#endif - -int haschar(st,ch) -char st[]; -int ch; { - int a,b; - b=0; - for (a=0; a=0) { - while(read(us,&ust,sizeof(struct usersupp))>0) { - if (lookfor == ust.usernum) { - strcpy(recp,ust.fullname); - close(us); - return(2); - } - if (!strucmp(ust.fullname,a_recp)) { - strcpy(recp,ust.fullname); - close(us); - return(3); - } - if (!struncmp(ust.fullname,a_recp,strlen(a_recp))) { - strcpy(recp,ust.fullname); - found_closest_match = 1; - } - } - close(us); - } - if (getpwnam(recp)!=NULL) return(1); - if (found_closest_match) return(3); - return(0); - } - -/* strip leading and trailing spaces */ -void striplt(buf) -char buf[]; { - while ( (strlen(buf)>0) && (buf[0]==32) ) strcpy(buf,&buf[1]); - while (buf[strlen(buf)-1] == 32) buf[strlen(buf)-1] = 0; - } - - -/* - * Check to see if a given FQDN really maps to a Citadel network node - */ -void host_alias(char host[]) { - - int a; - - /* What name is the local host known by? */ - /* if (!strucmp(host, config.c_fqdn)) { */ - if (IsHostLocal(host)) { - strcpy(host, config.c_nodename); - return; - } - - /* Other hosts in the gateway domain? */ - for (a=0; a */ - strcpy(name,rfc822); - for (a=0; a 0) && (name[a]!='>') ); - strcpy(&name[a],&name[a+1]); - } - - /* strip anything to the left of a bang */ - while ( (strlen(name)>0) && (haschar(name,'!')>0) ) - strcpy(name,&name[1]); - - /* and anything to the right of a @ or % */ - for (a=0; a 0) && (name[0]!='(') ) { - strcpy(&name[0],&name[1]); - } - strcpy(&name[0],&name[1]); - for (a=0; a 0) && (name[0]!=34) ) { - strcpy(&name[0],&name[1]); - } - strcpy(&name[0],&name[1]); - for (a=0; a 0) && (user[a]!=')') ); - strcpy(&user[a],&user[a+1]); - } - - /* if there's a set of angle brackets, strip it down to that */ - if ( (haschar(user,'<') == 1) && (haschar(user,'>') == 1) ) { - while ( (strlen(user) > 0) && (user[0]!='<') ) { - strcpy(&user[0],&user[1]); - } - strcpy(&user[0],&user[1]); - for (a=0; a') user[a]=0; - } - - /* strip anything to the left of a bang */ - while ( (strlen(user)>0) && (haschar(user,'!')>0) ) - strcpy(user,&user[1]); - - /* and anything to the right of a @ or % */ - for (a=0; a 0) && (node[a]!=')') ); - strcpy(&node[a],&node[a+1]); - } - - /* if there's a set of angle brackets, strip it down to that */ - if ( (haschar(node,'<') == 1) && (haschar(node,'>') == 1) ) { - while ( (strlen(node) > 0) && (node[0]!='<') ) { - strcpy(&node[0],&node[1]); - } - strcpy(&node[0],&node[1]); - for (a=0; a') node[a]=0; - } - - /* strip anything to the left of a @ */ - while ( (strlen(node)>0) && (haschar(node,'@')>0) ) - strcpy(node,&node[1]); - - /* strip anything to the left of a % */ - while ( (strlen(node)>0) && (haschar(node,'%')>0) ) - strcpy(node,&node[1]); - - /* reduce multiple system bang paths to node!user */ - while ( (strlen(node)>0) && (haschar(node,'!')>1) ) - strcpy(node,&node[1]); - - /* now get rid of the user portion of a node!user string */ - for (a=0; a0) { - fprintf(temp,"U%s%c", subject, 0); - } - putc('M',temp); - if (strcmp(buf, ".")) loopcopy(temp, stdin); - putc(0,temp); - fclose(temp); - } - -void do_roommail(recp) /* pipe public message through netproc */ -char recp[]; { - long now; - FILE *temp; - int a; - char buf[128],userbuf[128],frombuf[128],nodebuf[128]; - char subject[128], from[256]; - - strcpy(subject,""); - sprintf(from, "postmaster@%s", config.c_nodename); - strcpy(recp,&recp[5]); - for (a=0; a0) { - fprintf(temp,"U%s",subject); putc(0,temp); - } - putc('M',temp); - if (strcmp(buf, ".")) loopcopy(temp, stdin); - putc(0,temp); - fclose(temp); - } - -void do_uudecode(target) -char *target; { - static char buf[1024]; - FILE *fp; - - sprintf(buf,"cd %s; uudecode",target); - - fp=popen(buf,"w"); - if (fp==NULL) return; - while (fgets(buf,1024,stdin)!=NULL) { - fprintf(fp,"%s",buf); - } - pclose(fp); - - } - -void do_fallback(recp) -char recp[]; { - static char buf[1024]; - FILE *fp; - - sprintf(buf, FALLBACK, recp); - fp=popen(buf,"w"); - if (fp==NULL) fp = popen("cat >/dev/null", "w"); - loopcopy(fp, stdin); - pclose(fp); - } - -int alias(name) -char *name; { - FILE *fp; - int a; - char abuf[256]; - - fp=fopen(ALIASES,"r"); - if (fp==NULL) { - syslog(LOG_ERR,"cannot open %s: %s",ALIASES,strerror(errno)); - return(2); - } - - while (fgets(abuf,256,fp)!=NULL) { - strip_trailing_whitespace(abuf); - for (a=0; a0) && (buf[strlen(buf)-1]>0) && (buf[strlen(buf)-1]<32) ) { - buf[strlen(buf)-1] = 0; - } - - /* null-pad to allow some lazy compares */ - buf[strlen(buf)+1] = 0; - buf[strlen(buf)+2] = 0; - buf[strlen(buf)+3] = 0; - - if (!struncmp(buf, "QUIT", 4)) { - printf("221 Later, dude.\n"); - } - else if (!struncmp(buf, "HELP", 4)) { - printf("214 You think _you_ need help?\n"); - } - else if (!struncmp(buf, "HELO", 4)) { - printf("250 Howdy ho, Mr. Hankey!\n"); - } - else if (!struncmp(buf, "MAIL", 4)) { - printf("250 Sure, whatever...\n"); - } - - - else if (!struncmp(buf, "RCPT To: ", 9)) { - if (strlen(recp) > 0) { - printf("571 Multiple recipients not supported.\n"); - } - else { - strcpy(recp, &buf[9]); - if (haschar(recp, ',')) { - printf("571 Multiple recipients not supported.\n"); - strcpy(recp, ""); - } - else { - syslog(LOG_NOTICE,"recp: %s",recp); - for (a=0; a<2; ++a) { - alias(recp); - } - - /* did we alias it back to a remote address? */ - if ( (haschar(recp,'%')) - || (haschar(recp,'@')) - || (haschar(recp,'!')) ) { - - process_rfc822_addr(recp, user, node, name); - host_alias(node); - - /* If there are dots, it's an Internet host, so feed it - * back to an external mail transport agent such as sendmail. - */ - if (haschar(node, '.')) { - printf("571 Away with thee, spammer!\n"); - strcpy(recp, ""); - } - - /* Otherwise, we're dealing with Citadel mail. */ - else { - sprintf(recp, "%s!%s", node, user); - deliver_to_ignet = 1; - printf("250 IGnet recipient.\n"); - } - } - else { - printf("250 Local recipient.\n"); - } - - } - - } - } - - - - else if (!struncmp(buf, "RCPT", 4)) { - printf("501 Only 'To:' commands are supported.\n"); - } - else if (!struncmp(buf, "DATA", 4)) { - if (strlen(recp) > 0) { - printf("354 Sock it to me, baby...\n"); - fflush(stdout); - deliver(recp, is_test, deliver_to_ignet); - printf("250 Cool beans!\n"); - } - else { - printf("503 No recipient has been specified.\n"); - } - } - else { - printf("500 Huh?\n"); - } - - } while (struncmp(buf,"QUIT",4)); - } - - else { - /*** Non-SMTP delivery mode ***/ - syslog(LOG_NOTICE,"recp: %s",recp); - for (a=0; a<2; ++a) { - alias(recp); - } - - /* did we alias it back to a remote address? */ - if ( (haschar(recp,'%')) - || (haschar(recp,'@')) - || (haschar(recp,'!')) ) { - - process_rfc822_addr(recp, user, node, name); - host_alias(node); - - /* If there are dots, it's an Internet host, so feed it - * back to an external mail transport agent such as sendmail. - */ - if (haschar(node, '.')) { - sprintf(buf, SENDMAIL, recp); - system(buf); - exit(0); - } - - /* Otherwise, we're dealing with Citadel mail. */ - else { - sprintf(recp, "%s!%s", node, user); - deliver_to_ignet = 1; - } - - } - - deliver(recp, is_test, deliver_to_ignet); - } - - closelog(); - if (RUN_NETPROC) execlp("./netproc","netproc",NULL); - exit(0); - } -