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