nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

qmail-showctl.c (11191B)


      1 #include <sys/types.h>
      2 #include <sys/stat.h>
      3 #include "substdio.h"
      4 #include "subfd.h"
      5 #include "exit.h"
      6 #include "fmt.h"
      7 #include "str.h"
      8 #include "control.h"
      9 #include "constmap.h"
     10 #include "stralloc.h"
     11 #include "direntry.h"
     12 #include "uidgid.h"
     13 #include "auto_uids.h"
     14 #include "auto_users.h"
     15 #include "auto_qmail.h"
     16 #include "auto_break.h"
     17 #include "auto_patrn.h"
     18 #include "auto_spawn.h"
     19 #include "auto_split.h"
     20 
     21 stralloc me = {0};
     22 int meok;
     23 
     24 stralloc line = {0};
     25 char num[FMT_ULONG];
     26 
     27 uid_t auto_uida;
     28 uid_t auto_uidd;
     29 uid_t auto_uidl;
     30 uid_t auto_uido;
     31 uid_t auto_uidp;
     32 uid_t auto_uidq;
     33 uid_t auto_uidr;
     34 uid_t auto_uids;
     35 
     36 gid_t auto_gidn;
     37 gid_t auto_gidq;
     38 
     39 void safeput(buf,len)
     40 char *buf;
     41 unsigned int len;
     42 {
     43   char ch;
     44 
     45   while (len > 0) {
     46     ch = *buf;
     47     if ((ch < 32) || (ch > 126)) ch = '?';
     48     substdio_put(subfdout,&ch,1);
     49     ++buf;
     50     --len;
     51   }
     52 }
     53 
     54 void do_int(fn,def,pre,post)
     55 char *fn;
     56 char *def;
     57 char *pre;
     58 char *post;
     59 {
     60   int i;
     61   substdio_puts(subfdout,"\n");
     62   substdio_puts(subfdout,fn);
     63   substdio_puts(subfdout,": ");
     64   switch(control_readint(&i,fn)) {
     65     case 0:
     66       substdio_puts(subfdout,"(Default.) ");
     67       substdio_puts(subfdout,pre);
     68       substdio_puts(subfdout,def);
     69       substdio_puts(subfdout,post);
     70       substdio_puts(subfdout,".\n");
     71       break;
     72     case 1:
     73       if (i < 0) i = 0;
     74       substdio_puts(subfdout,pre);
     75       substdio_put(subfdout,num,fmt_uint(num,i));
     76       substdio_puts(subfdout,post);
     77       substdio_puts(subfdout,".\n");
     78       break;
     79     default:
     80       substdio_puts(subfdout,"Oops! Trouble reading this file.\n");
     81       break;
     82   }
     83 }
     84 
     85 void do_str(fn,flagme,def,pre)
     86 char *fn;
     87 int flagme;
     88 char *def;
     89 char *pre;
     90 {
     91   substdio_puts(subfdout,"\n");
     92   substdio_puts(subfdout,fn);
     93   substdio_puts(subfdout,": ");
     94   switch(control_readline(&line,fn)) {
     95     case 0:
     96       substdio_puts(subfdout,"(Default.) ");
     97       if (!stralloc_copys(&line,def)) {
     98 	substdio_puts(subfdout,"Oops! Out of memory.\n");
     99 	break;
    100       }
    101       if (flagme && meok)
    102 	if (!stralloc_copy(&line,&me)) {
    103 	  substdio_puts(subfdout,"Oops! Out of memory.\n");
    104 	  break;
    105 	}
    106     case 1:
    107       substdio_puts(subfdout,pre);
    108       safeput(line.s,line.len);
    109       substdio_puts(subfdout,".\n");
    110       break;
    111     default:
    112       substdio_puts(subfdout,"Oops! Trouble reading this file.\n");
    113       break;
    114   }
    115 }
    116 
    117 int do_lst(fn,def,pre,post)
    118 char *fn;
    119 char *def;
    120 char *pre;
    121 char *post;
    122 {
    123   int i;
    124   int j;
    125 
    126   substdio_puts(subfdout,"\n");
    127   substdio_puts(subfdout,fn);
    128   substdio_puts(subfdout,": ");
    129   switch(control_readfile(&line,fn,0)) {
    130     case 0:
    131       substdio_puts(subfdout,"(Default.) ");
    132       substdio_puts(subfdout,def);
    133       substdio_puts(subfdout,"\n");
    134       return 0;
    135     case 1:
    136       substdio_puts(subfdout,"\n");
    137       i = 0;
    138       for (j = 0;j < line.len;++j)
    139 	if (!line.s[j]) {
    140           substdio_puts(subfdout,pre);
    141           safeput(line.s + i,j - i);
    142           substdio_puts(subfdout,post);
    143           substdio_puts(subfdout,"\n");
    144 	  i = j + 1;
    145 	}
    146       return 1;
    147     default:
    148       substdio_puts(subfdout,"Oops! Trouble reading this file.\n");
    149       return -1;
    150   }
    151 }
    152 
    153 int main(void)
    154 {
    155   DIR *dir;
    156   direntry *d;
    157   struct stat stmrh;
    158   struct stat stmrhcdb;
    159 
    160   auto_uida = inituid(auto_usera);
    161   auto_uidd = inituid(auto_userd);
    162   auto_uidl = inituid(auto_userl);
    163   auto_uido = inituid(auto_usero);
    164   auto_uidp = inituid(auto_userp);
    165   auto_uidq = inituid(auto_userq);
    166   auto_uidr = inituid(auto_userr);
    167   auto_uids = inituid(auto_users);
    168 
    169   auto_gidn = initgid(auto_groupn);
    170   auto_gidq = initgid(auto_groupq);
    171 
    172   substdio_puts(subfdout,"qmail home directory: ");
    173   substdio_puts(subfdout,auto_qmail);
    174   substdio_puts(subfdout,".\n");
    175 
    176   substdio_puts(subfdout,"user-ext delimiter: ");
    177   substdio_puts(subfdout,auto_break);
    178   substdio_puts(subfdout,".\n");
    179 
    180   substdio_puts(subfdout,"paternalism (in decimal): ");
    181   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_patrn));
    182   substdio_puts(subfdout,".\n");
    183 
    184   substdio_puts(subfdout,"silent concurrency limit: ");
    185   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_spawn));
    186   substdio_puts(subfdout,".\n");
    187 
    188   substdio_puts(subfdout,"subdirectory split: ");
    189   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_split));
    190   substdio_puts(subfdout,".\n");
    191 
    192   substdio_puts(subfdout,"user ids: ");
    193   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uida));
    194   substdio_puts(subfdout,", ");
    195   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uidd));
    196   substdio_puts(subfdout,", ");
    197   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uidl));
    198   substdio_puts(subfdout,", ");
    199   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uido));
    200   substdio_puts(subfdout,", ");
    201   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uidp));
    202   substdio_puts(subfdout,", ");
    203   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uidq));
    204   substdio_puts(subfdout,", ");
    205   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uidr));
    206   substdio_puts(subfdout,", ");
    207   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_uids));
    208   substdio_puts(subfdout,".\n");
    209 
    210   substdio_puts(subfdout,"group ids: ");
    211   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_gidn));
    212   substdio_puts(subfdout,", ");
    213   substdio_put(subfdout,num,fmt_ulong(num,(unsigned long) auto_gidq));
    214   substdio_puts(subfdout,".\n");
    215 
    216   if (chdir(auto_qmail) == -1) {
    217     substdio_puts(subfdout,"Oops! Unable to chdir to ");
    218     substdio_puts(subfdout,auto_qmail);
    219     substdio_puts(subfdout,".\n");
    220     substdio_flush(subfdout);
    221     _exit(111);
    222   }
    223   if (chdir("control") == -1) {
    224     substdio_puts(subfdout,"Oops! Unable to chdir to control.\n");
    225     substdio_flush(subfdout);
    226     _exit(111);
    227   }
    228 
    229   dir = opendir(".");
    230   if (!dir) {
    231     substdio_puts(subfdout,"Oops! Unable to open current directory.\n");
    232     substdio_flush(subfdout);
    233     _exit(111);
    234   }
    235 
    236   meok = control_readline(&me,"me");
    237   if (meok == -1) {
    238     substdio_puts(subfdout,"Oops! Trouble reading control/me.");
    239     substdio_flush(subfdout);
    240     _exit(111);
    241   }
    242 
    243   do_lst("badmailfrom","Any MAIL FROM is allowed.",""," not accepted in MAIL FROM.");
    244   do_str("bouncefrom",0,"MAILER-DAEMON","Bounce user name is ");
    245   do_str("bouncehost",1,"bouncehost","Bounce host name is ");
    246   do_int("concurrencylocal","10","Local concurrency is ","");
    247   do_int("concurrencyremote","20","Remote concurrency is ","");
    248   do_int("databytes","0","SMTP DATA limit is "," bytes");
    249   do_str("defaultdomain",1,"defaultdomain","Default domain name is ");
    250   do_str("defaulthost",1,"defaulthost","Default host name is ");
    251   do_lst("dnsbllist","No dnsbl list configured.","List at "," configured for dnsbl check.");
    252   do_str("doublebouncehost",1,"doublebouncehost","2B recipient host: ");
    253   do_str("doublebounceto",0,"postmaster","2B recipient user: ");
    254   do_str("envnoathost",1,"envnoathost","Presumed domain name is ");
    255   do_str("helohost",1,"helohost","SMTP client HELO host name is ");
    256   do_str("idhost",1,"idhost","Message-ID host name is ");
    257   do_str("localiphost",1,"localiphost","Local IP address becomes ");
    258   do_lst("locals","Messages for me are delivered locally.","Messages for "," are delivered locally.");
    259   do_str("me",0,"undefined! Uh-oh","My name is ");
    260   do_lst("percenthack","The percent hack is not allowed.","The percent hack is allowed for user%host@",".");
    261   do_str("plusdomain",1,"plusdomain","Plus domain name is ");
    262   do_lst("qmqpservers","No QMQP servers.","QMQP server: ",".");
    263   do_int("queuelifetime","604800","Message lifetime in the queue is "," seconds");
    264 
    265   if (do_lst("rcpthosts","SMTP clients may send messages to any recipient.","SMTP clients may send messages to recipients at ","."))
    266     do_lst("morercpthosts","No effect.","SMTP clients may send messages to recipients at ",".");
    267   else
    268     do_lst("morercpthosts","No rcpthosts; morercpthosts is irrelevant.","No rcpthosts; doesn't matter that morercpthosts has ",".");
    269   /* XXX: check morercpthosts.cdb contents */
    270   substdio_puts(subfdout,"\nmorercpthosts.cdb: ");
    271   if (stat("morercpthosts",&stmrh) == -1)
    272     if (stat("morercpthosts.cdb",&stmrhcdb) == -1)
    273       substdio_puts(subfdout,"(Default.) No effect.\n");
    274     else
    275       substdio_puts(subfdout,"Oops! morercpthosts.cdb exists but morercpthosts doesn't.\n");
    276   else
    277     if (stat("morercpthosts.cdb",&stmrhcdb) == -1)
    278       substdio_puts(subfdout,"Oops! morercpthosts exists but morercpthosts.cdb doesn't.\n");
    279     else
    280       if (stmrh.st_mtime > stmrhcdb.st_mtime)
    281         substdio_puts(subfdout,"Oops! morercpthosts.cdb is older than morercpthosts.\n");
    282       else
    283         substdio_puts(subfdout,"Modified recently enough; hopefully up to date.\n");
    284 
    285   do_str("smtpgreeting",1,"smtpgreeting","SMTP greeting: 220 ");
    286   do_lst("smtproutes","No artificial SMTP routes.","SMTP route: ","");
    287   do_int("timeoutconnect","60","SMTP client connection timeout is "," seconds");
    288   do_int("timeoutremote","1200","SMTP client data timeout is "," seconds");
    289   do_int("timeoutsmtpd","1200","SMTP server data timeout is "," seconds");
    290   do_lst("virtualdomains","No virtual domains.","Virtual domain: ","");
    291 
    292   while ((d = readdir(dir))) {
    293     if (str_equal(d->d_name,".")) continue;
    294     if (str_equal(d->d_name,"..")) continue;
    295     if (str_equal(d->d_name,"bouncefrom")) continue;
    296     if (str_equal(d->d_name,"bouncehost")) continue;
    297     if (str_equal(d->d_name,"badmailfrom")) continue;
    298     if (str_equal(d->d_name,"bouncefrom")) continue;
    299     if (str_equal(d->d_name,"bouncehost")) continue;
    300     if (str_equal(d->d_name,"concurrencylocal")) continue;
    301     if (str_equal(d->d_name,"concurrencyremote")) continue;
    302     if (str_equal(d->d_name,"databytes")) continue;
    303     if (str_equal(d->d_name,"defaultdomain")) continue;
    304     if (str_equal(d->d_name,"defaulthost")) continue;
    305     if (str_equal(d->d_name,"dnsbllist")) continue;
    306     if (str_equal(d->d_name,"doublebouncehost")) continue;
    307     if (str_equal(d->d_name,"doublebounceto")) continue;
    308     if (str_equal(d->d_name,"envnoathost")) continue;
    309     if (str_equal(d->d_name,"helohost")) continue;
    310     if (str_equal(d->d_name,"idhost")) continue;
    311     if (str_equal(d->d_name,"localiphost")) continue;
    312     if (str_equal(d->d_name,"locals")) continue;
    313     if (str_equal(d->d_name,"me")) continue;
    314     if (str_equal(d->d_name,"morercpthosts")) continue;
    315     if (str_equal(d->d_name,"morercpthosts.cdb")) continue;
    316     if (str_equal(d->d_name,"percenthack")) continue;
    317     if (str_equal(d->d_name,"plusdomain")) continue;
    318     if (str_equal(d->d_name,"qmqpservers")) continue;
    319     if (str_equal(d->d_name,"queuelifetime")) continue;
    320     if (str_equal(d->d_name,"rcpthosts")) continue;
    321     if (str_equal(d->d_name,"smtpgreeting")) continue;
    322     if (str_equal(d->d_name,"smtproutes")) continue;
    323     if (str_equal(d->d_name,"timeoutconnect")) continue;
    324     if (str_equal(d->d_name,"timeoutremote")) continue;
    325     if (str_equal(d->d_name,"timeoutsmtpd")) continue;
    326     if (str_equal(d->d_name,"virtualdomains")) continue;
    327     substdio_puts(subfdout,"\n");
    328     substdio_puts(subfdout,d->d_name);
    329     substdio_puts(subfdout,": I have no idea what this file does.\n");
    330   }
    331 
    332   substdio_flush(subfdout);
    333   _exit(0);
    334 }