2 * conf.c -- dump fetchmail configuration as Python dictionary initializer
4 * For license terms, see the file COPYING in this directory.
12 #if defined(STDC_HEADERS)
15 #if defined(HAVE_UNISTD_H)
22 #include "fetchmail.h"
24 /* Python prettyprinting functions */
26 static int indent_level;
28 static void indent(char ic)
29 /* indent current line */
33 if (ic == ')' || ic == ']' || ic == '}')
37 * The guard here is a kluge. It depends on the fact that in the
38 * particular structure we're dumping, opening [s are always
39 * initializers for dictionary members and thus will be preceded
44 for (i = 0; i < indent_level / 2; i++)
56 if (ic == '(' || ic == '[' || ic == '{')
61 static void stringdump(const char *name, const char *member)
62 /* dump a string member with current indent */
65 fprintf(stdout, "\"%s\":", name);
67 fprintf(stdout, "\"%s\"", visbuf(member));
69 fputs("None", stdout);
73 static void numdump(const char *name, const int num)
74 /* dump a numeric quantity at current indent */
77 fprintf(stdout, "'%s':%d,\n", name, NUM_VALUE_OUT(num));
80 static void booldump(const char *name, const int onoff)
81 /* dump a boolean quantity at current indent */
85 fprintf(stdout, "'%s':TRUE,\n", name);
87 fprintf(stdout, "'%s':FALSE,\n", name);
90 static void listdump(const char *name, struct idlist *list)
91 /* dump a string list member with current indent */
94 fprintf(stdout, "\"%s\":", name);
97 fputs("None,\n", stdout);
103 for (idp = list; idp; idp = idp->next)
106 fprintf(stdout, "\"%s\"", visbuf(idp->id));
110 fputs("],\n", stdout);
115 * Note: this function dumps the entire configuration,
116 * after merging of the defaults record (if any). It
117 * is intended to produce output parseable by a configuration
118 * front end, not anything especially comfortable for humans.
121 void dump_config(struct runctl *runp, struct query *querylist)
122 /* dump the in-core configuration in recompilable form */
130 * These had better match the values fetchmailconf is expecting!
131 * (We don't want to import them from Tkinter because the user
132 * might not have it installed.)
134 fputs("TRUE=1; FALSE=0\n\n", stdout);
137 * We need this in order to know whether `interface' and `monitor'
138 * are valid options or not.
141 fputs("os_type = 'linux'\n", stdout);
142 #elif defined(__FreeBSD__)
143 fputs("os_type = 'freebsd'\n", stdout);
145 fputs("os_type = 'generic'\n", stdout);
149 * This should be approximately in sync with the -V option dumping
152 printf("feature_options = (");
155 #endif /* POP2_ENABLE */
158 #endif /* POP3_ENABLE */
161 #endif /* IMAP_ENABLE */
165 #if defined(KERBEROS_V4)
166 printf("'kerberos',");
167 #endif /* defined(IMAP4) */
170 #endif /* RPA_ENABLE */
173 #endif /* SDPS_ENABLE */
176 #endif /* ETRN_ENABLE */
179 #endif /* ODMR_ENABLE */
182 #endif /* SSL_ENABLE */
185 #endif /* OPIE_ENABLE */
188 #endif /* INET6_ENABLE */
191 #endif /* NET_SECURITY */
194 fputs("# Start of configuration initializer\n", stdout);
195 fputs("fetchmailrc = ", stdout);
198 numdump("poll_interval", runp->poll_interval);
199 stringdump("logfile", runp->logfile);
200 stringdump("idfile", runp->idfile);
201 stringdump("postmaster", runp->postmaster);
202 booldump("bouncemail", runp->bouncemail);
203 booldump("spambounce", runp->spambounce);
204 stringdump("properties", runp->properties);
205 booldump("invisible", runp->invisible);
206 booldump("showdots", runp->showdots);
207 booldump("syslog", runp->use_syslog);
211 fputs(" 'servers': []\n", stdout);
216 fputs("# List of server entries begins here\n", stdout);
218 fputs("'servers': ", stdout);
221 for (ctl = querylist; ctl; ctl = ctl->next)
224 * First, the server stuff.
226 if (!ctl->server.lead_server)
231 * Every time we see a leading server entry after the first one,
232 * it implicitly ends the both (a) the list of user structures
233 * associated with the previous entry, and (b) that previous entry.
245 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
249 (ctl->server.protocol == P_POP3 &&
251 ctl->server.port == KPOP_PORT &&
253 ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT ) &&
255 ctl->server.authenticate == A_KERBEROS_V4);
257 stringdump("pollname", ctl->server.pollname);
258 booldump("active", !ctl->server.skip);
259 stringdump("via", ctl->server.via);
260 stringdump("protocol",
261 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
263 numdump("port", ctl->server.port);
265 stringdump("port", ctl->server.service);
267 numdump("timeout", ctl->server.timeout);
268 numdump("interval", ctl->server.interval);
270 if (ctl->server.envelope == STRING_DISABLED)
271 stringdump("envelope", NULL);
272 else if (ctl->server.envelope == NULL)
273 stringdump("envelope", "Received");
275 stringdump("envelope", ctl->server.envelope);
276 numdump("envskip", ctl->server.envskip);
277 stringdump("qvirtual", ctl->server.qvirtual);
279 if (ctl->server.authenticate == A_ANY)
280 stringdump("auth", "any");
281 else if (ctl->server.authenticate == A_PASSWORD)
282 stringdump("auth", "password");
283 else if (ctl->server.authenticate == A_OTP)
284 stringdump("auth", "otp");
285 else if (ctl->server.authenticate == A_NTLM)
286 stringdump("auth", "ntlm");
287 else if (ctl->server.authenticate == A_CRAM_MD5)
288 stringdump("auth", "cram-md5");
289 else if (ctl->server.authenticate == A_GSSAPI)
290 stringdump("auth", "gssapi");
291 else if (ctl->server.authenticate == A_KERBEROS_V4)
292 stringdump("auth", "kerberos_v4");
293 else if (ctl->server.authenticate == A_KERBEROS_V5)
294 stringdump("auth", "kerberos_v5");
295 else if (ctl->server.authenticate == A_SSH)
296 stringdump("auth", "ssh");
298 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
299 booldump("dns", ctl->server.dns);
300 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
301 booldump("uidl", ctl->server.uidl);
303 listdump("aka", ctl->server.akalist);
304 listdump("localdomains", ctl->server.localdomains);
306 #if defined(linux) || defined(__FreeBSD__)
307 stringdump("interface", ctl->server.interface);
308 stringdump("monitor", ctl->server.monitor);
309 #endif /* linux || __FreeBSD__ */
311 stringdump("plugin", ctl->server.plugin);
312 stringdump("plugout", ctl->server.plugout);
313 stringdump("principal", ctl->server.principal);
316 fputs("'users': ", stdout);
322 stringdump("remote", ctl->remotename);
323 stringdump("password", ctl->password);
326 fprintf(stdout, "'localnames':[");
327 for (idp = ctl->localnames; idp; idp = idp->next)
329 char namebuf[USERNAMELEN + 1];
331 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
332 namebuf[USERNAMELEN] = '\0';
334 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
336 fprintf(stdout, "\"%s\"", namebuf);
341 fputs(", '*'", stdout);
342 fputs("],\n", stdout);
344 booldump("fetchall", ctl->fetchall);
345 booldump("keep", ctl->keep);
346 booldump("flush", ctl->flush);
347 booldump("rewrite", ctl->rewrite);
348 booldump("stripcr", ctl->stripcr);
349 booldump("forcecr", ctl->forcecr);
350 booldump("pass8bits", ctl->pass8bits);
351 booldump("dropstatus", ctl->dropstatus);
352 booldump("dropdelivered", ctl->dropdelivered);
353 booldump("mimedecode", ctl->mimedecode);
354 booldump("idle", ctl->idle);
356 stringdump("mda", ctl->mda);
357 stringdump("bsmtp", ctl->bsmtp);
359 if (ctl->listener == LMTP_MODE)
360 fputs("'lmtp':TRUE,\n", stdout);
362 fputs("'lmtp':FALSE,\n", stdout);
365 stringdump("netsec", ctl->server.netsec);
366 #endif /* INET6_ENABLE */
367 stringdump("preconnect", ctl->preconnect);
368 stringdump("postconnect", ctl->postconnect);
369 numdump("limit", ctl->limit);
370 numdump("warnings", ctl->warnings);
371 numdump("fetchlimit", ctl->fetchlimit);
372 numdump("batchlimit", ctl->batchlimit);
374 booldump("ssl", ctl->use_ssl);
375 stringdump("sslkey", ctl->sslkey);
376 stringdump("sslcert", ctl->sslcert);
377 #endif /* SSL_ENABLE */
378 numdump("expunge", ctl->expunge);
379 stringdump("properties", ctl->properties);
380 listdump("smtphunt", ctl->smtphunt);
381 stringdump("smtpaddress", ctl->smtpaddress);
382 stringdump("smtpname", ctl->smtpname);
385 fprintf(stdout, "'antispam':'");
387 fputs("'\n", stdout);
390 for (idp = ctl->antispam; idp; idp = idp->next)
392 fprintf(stdout, "%d", idp->val.status.num);
396 fputs("',\n", stdout);
398 listdump("mailboxes", ctl->mailboxes);
405 /* end last span of user entries and last server entry */
409 /* end array of servers */
413 /* end top-level dictionary */
415 fputs("# End of initializer\n", stdout);
418 /* conf.c ends here */