| 1 | #include "substdio.h" |
| 2 | #include "subfd.h" |
| 3 | #include "exit.h" |
| 4 | #include "fmt.h" |
| 5 | #include "str.h" |
| 6 | #include "control.h" |
| 7 | #include "constmap.h" |
| 8 | #include "stralloc.h" |
| 9 | #include "direntry.h" |
| 10 | #include "auto_qmail.h" |
| 11 | |
| 12 | stralloc me = {0}; |
| 13 | int meok; |
| 14 | |
| 15 | stralloc line = {0}; |
| 16 | char num[FMT_ULONG]; |
| 17 | |
| 18 | void safeput(buf,len) |
| 19 | char *buf; |
| 20 | unsigned int len; |
| 21 | { |
| 22 | char ch; |
| 23 | |
| 24 | while (len > 0) { |
| 25 | ch = *buf; |
| 26 | if ((ch < 32) || (ch > 126)) ch = '?'; |
| 27 | substdio_put(subfdout,&ch,1); |
| 28 | ++buf; |
| 29 | --len; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void do_int(fn,def,pre,post) |
| 34 | char *fn; |
| 35 | char *def; |
| 36 | char *pre; |
| 37 | char *post; |
| 38 | { |
| 39 | int i; |
| 40 | substdio_puts(subfdout,"\n"); |
| 41 | substdio_puts(subfdout,fn); |
| 42 | substdio_puts(subfdout,": "); |
| 43 | switch(control_readint(&i,fn)) { |
| 44 | case 0: |
| 45 | substdio_puts(subfdout,"(Default.) "); |
| 46 | substdio_puts(subfdout,pre); |
| 47 | substdio_puts(subfdout,def); |
| 48 | substdio_puts(subfdout,post); |
| 49 | substdio_puts(subfdout,".\n"); |
| 50 | break; |
| 51 | case 1: |
| 52 | if (i < 0) i = 0; |
| 53 | substdio_puts(subfdout,pre); |
| 54 | substdio_put(subfdout,num,fmt_uint(num,i)); |
| 55 | substdio_puts(subfdout,post); |
| 56 | substdio_puts(subfdout,".\n"); |
| 57 | break; |
| 58 | default: |
| 59 | substdio_puts(subfdout,"Oops! Trouble reading this file.\n"); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void do_str(fn,flagme,def,pre) |
| 65 | char *fn; |
| 66 | int flagme; |
| 67 | char *def; |
| 68 | char *pre; |
| 69 | { |
| 70 | substdio_puts(subfdout,"\n"); |
| 71 | substdio_puts(subfdout,fn); |
| 72 | substdio_puts(subfdout,": "); |
| 73 | switch(control_readline(&line,fn)) { |
| 74 | case 0: |
| 75 | substdio_puts(subfdout,"(Default.) "); |
| 76 | if (!stralloc_copys(&line,def)) { |
| 77 | substdio_puts(subfdout,"Oops! Out of memory.\n"); |
| 78 | break; |
| 79 | } |
| 80 | if (flagme && meok) |
| 81 | if (!stralloc_copy(&line,&me)) { |
| 82 | substdio_puts(subfdout,"Oops! Out of memory.\n"); |
| 83 | break; |
| 84 | } |
| 85 | case 1: |
| 86 | substdio_puts(subfdout,pre); |
| 87 | safeput(line.s,line.len); |
| 88 | substdio_puts(subfdout,".\n"); |
| 89 | break; |
| 90 | default: |
| 91 | substdio_puts(subfdout,"Oops! Trouble reading this file.\n"); |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void do_lst(fn,def,pre,post) |
| 97 | char *fn; |
| 98 | char *def; |
| 99 | char *pre; |
| 100 | char *post; |
| 101 | { |
| 102 | int i; |
| 103 | int j; |
| 104 | |
| 105 | substdio_puts(subfdout,"\n"); |
| 106 | substdio_puts(subfdout,fn); |
| 107 | substdio_puts(subfdout,": "); |
| 108 | switch(control_readfile(&line,fn)) { |
| 109 | case 0: |
| 110 | substdio_puts(subfdout,"(Default.) "); |
| 111 | substdio_puts(subfdout,def); |
| 112 | substdio_puts(subfdout,"\n"); |
| 113 | break; |
| 114 | case 1: |
| 115 | substdio_puts(subfdout,"\n"); |
| 116 | i = 0; |
| 117 | for (j = 0;j < line.len;++j) |
| 118 | if (!line.s[j]) { |
| 119 | substdio_puts(subfdout,pre); |
| 120 | safeput(line.s + i,j - i); |
| 121 | substdio_puts(subfdout,post); |
| 122 | substdio_puts(subfdout,"\n"); |
| 123 | i = j + 1; |
| 124 | } |
| 125 | break; |
| 126 | default: |
| 127 | substdio_puts(subfdout,"Oops! Trouble reading this file.\n"); |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void main() |
| 133 | { |
| 134 | DIR *dir; |
| 135 | direntry *d; |
| 136 | |
| 137 | substdio_puts(subfdout,"The qmail control files are stored in "); |
| 138 | substdio_puts(subfdout,auto_qmail); |
| 139 | substdio_puts(subfdout,"/control.\n"); |
| 140 | |
| 141 | if (chdir(auto_qmail) == -1) { |
| 142 | substdio_puts(subfdout,"Oops! Unable to chdir to "); |
| 143 | substdio_puts(subfdout,auto_qmail); |
| 144 | substdio_puts(subfdout,".\n"); |
| 145 | substdio_flush(subfdout); |
| 146 | _exit(111); |
| 147 | } |
| 148 | if (chdir("control") == -1) { |
| 149 | substdio_puts(subfdout,"Oops! Unable to chdir to control.\n"); |
| 150 | substdio_flush(subfdout); |
| 151 | _exit(111); |
| 152 | } |
| 153 | |
| 154 | dir = opendir("."); |
| 155 | if (!dir) { |
| 156 | substdio_puts(subfdout,"Oops! Unable to open current directory.\n"); |
| 157 | substdio_flush(subfdout); |
| 158 | _exit(111); |
| 159 | } |
| 160 | |
| 161 | meok = control_readline(&me,"me"); |
| 162 | if (meok == -1) { |
| 163 | substdio_puts(subfdout,"Oops! Trouble reading control/me."); |
| 164 | substdio_flush(subfdout); |
| 165 | _exit(111); |
| 166 | } |
| 167 | |
| 168 | do_lst("badmailfrom","Any MAIL FROM is allowed.",""," not accepted in MAIL FROM."); |
| 169 | do_str("bouncefrom",0,"MAILER-DAEMON","Bounce user name is "); |
| 170 | do_str("bouncehost",1,"bouncehost","Bounce host name is "); |
| 171 | do_int("concurrencylocal","10","Local concurrency is ",""); |
| 172 | do_int("concurrencyremote","20","Remote concurrency is ",""); |
| 173 | do_str("defaultdomain",1,"defaultdomain","Default domain name is "); |
| 174 | do_str("defaulthost",1,"defaulthost","Default host name is "); |
| 175 | do_str("doublebouncehost",1,"doublebouncehost","2B recipient host: "); |
| 176 | do_str("doublebounceto",0,"postmaster","2B recipient user: "); |
| 177 | do_str("envnoathost",1,"envnoathost","Presumed domain name is "); |
| 178 | do_str("helohost",1,"helohost","SMTP client HELO host name is "); |
| 179 | do_str("idhost",1,"idhost","Message-ID host name is "); |
| 180 | do_str("localiphost",1,"localiphost","Local IP address becomes "); |
| 181 | do_lst("locals","Messages for me are delivered locally.","Messages for "," are delivered locally."); |
| 182 | do_str("me",0,"undefined! Uh-oh","My name is "); |
| 183 | do_lst("percenthack","The percent hack is not allowed.","The percent hack is allowed for user%host@","."); |
| 184 | do_str("plusdomain",1,"plusdomain","Plus domain name is "); |
| 185 | do_int("queuelifetime","604800","Message lifetime in the queue is "," seconds"); |
| 186 | do_lst("rcpthosts","SMTP clients may send messages to any recipient.","SMTP clients may send messages to recipients at ","."); |
| 187 | do_lst("recipientmap","No redirections.","Redirection: ",""); |
| 188 | do_lst("relayhosts","No relayhosts","Relay host: ",""); |
| 189 | do_str("smtpgreeting",1,"smtpgreeting","SMTP greeting: 220 "); |
| 190 | do_lst("smtproutes","No artificial SMTP routes.","SMTP route: ",""); |
| 191 | do_int("timeoutconnect","60","SMTP client connection timeout is "," seconds"); |
| 192 | do_int("timeoutremote","1200","SMTP client data timeout is "," seconds"); |
| 193 | do_int("timeoutsmtpd","1200","SMTP server data timeout is "," seconds"); |
| 194 | do_lst("virtualdomains","No virtual domains.","Virtual domain: ",""); |
| 195 | |
| 196 | while (d = readdir(dir)) { |
| 197 | if (str_equal(d->d_name,".")) continue; |
| 198 | if (str_equal(d->d_name,"..")) continue; |
| 199 | if (str_equal(d->d_name,"bouncefrom")) continue; |
| 200 | if (str_equal(d->d_name,"bouncehost")) continue; |
| 201 | if (str_equal(d->d_name,"badmailfrom")) continue; |
| 202 | if (str_equal(d->d_name,"bouncefrom")) continue; |
| 203 | if (str_equal(d->d_name,"bouncehost")) continue; |
| 204 | if (str_equal(d->d_name,"concurrencylocal")) continue; |
| 205 | if (str_equal(d->d_name,"concurrencyremote")) continue; |
| 206 | if (str_equal(d->d_name,"defaultdomain")) continue; |
| 207 | if (str_equal(d->d_name,"defaulthost")) continue; |
| 208 | if (str_equal(d->d_name,"doublebouncehost")) continue; |
| 209 | if (str_equal(d->d_name,"doublebounceto")) continue; |
| 210 | if (str_equal(d->d_name,"envnoathost")) continue; |
| 211 | if (str_equal(d->d_name,"helohost")) continue; |
| 212 | if (str_equal(d->d_name,"idhost")) continue; |
| 213 | if (str_equal(d->d_name,"localiphost")) continue; |
| 214 | if (str_equal(d->d_name,"locals")) continue; |
| 215 | if (str_equal(d->d_name,"me")) continue; |
| 216 | if (str_equal(d->d_name,"percenthack")) continue; |
| 217 | if (str_equal(d->d_name,"plusdomain")) continue; |
| 218 | if (str_equal(d->d_name,"queuelifetime")) continue; |
| 219 | if (str_equal(d->d_name,"rcpthosts")) continue; |
| 220 | if (str_equal(d->d_name,"recipientmap")) continue; |
| 221 | if (str_equal(d->d_name,"relayhosts")) continue; |
| 222 | if (str_equal(d->d_name,"smtpgreeting")) continue; |
| 223 | if (str_equal(d->d_name,"smtproutes")) continue; |
| 224 | if (str_equal(d->d_name,"timeoutconnect")) continue; |
| 225 | if (str_equal(d->d_name,"timeoutremote")) continue; |
| 226 | if (str_equal(d->d_name,"timeoutsmtpd")) continue; |
| 227 | if (str_equal(d->d_name,"virtualdomains")) continue; |
| 228 | substdio_puts(subfdout,"\n"); |
| 229 | substdio_puts(subfdout,d->d_name); |
| 230 | substdio_puts(subfdout,": I have no idea what this file does.\n"); |
| 231 | } |
| 232 | |
| 233 | substdio_flush(subfdout); |
| 234 | _exit(0); |
| 235 | } |