20120307 postconf -X option to exclude parameters from main.cf (require two-finger action, because this is irreversible). Files: postconf/postconf.[hc], postconf/postconf_edit.c. diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.10-20120306/src/postconf/postconf.c src/postconf/postconf.c *** /var/tmp/postfix-2.10-20120306/src/postconf/postconf.c Tue Jan 24 19:41:08 2012 --- src/postconf/postconf.c Thu Mar 8 08:34:30 2012 *************** *** 13,19 **** /* \fBpostconf\fR [\fB-ev\fR] [\fB-c \fIconfig_dir\fR] /* [\fIparameter=value ...\fR] /* ! /* \fBpostconf\fR [\fB-#v\fR] [\fB-c \fIconfig_dir\fR] /* [\fIparameter ...\fR] /* /* \fBManaging master.cf:\fR --- 13,19 ---- /* \fBpostconf\fR [\fB-ev\fR] [\fB-c \fIconfig_dir\fR] /* [\fIparameter=value ...\fR] /* ! /* \fBpostconf\fR [\fB-#vX\fR] [\fB-c \fIconfig_dir\fR] /* [\fIparameter ...\fR] /* /* \fBManaging master.cf:\fR *************** *** 267,272 **** --- 267,282 ---- /* .IP \fB-v\fR /* Enable verbose logging for debugging purposes. Multiple \fB-v\fR /* options make the software increasingly verbose. + /* .IP \fB-X\fR + /* Edit the \fBmain.cf\fR configuration file, and remove + /* the parameters given on the \fBpostconf\fR(1) command line. + /* The file is copied to a temporary file then renamed into + /* place. + /* Specify a list of parameter names, not \fIname\fR=\fIvalue\fR + /* pairs. There is no \fBpostconf\fR(1) command to perform + /* the reverse operation. + /* + /* This feature is available with Postfix 2.10 and later. /* .IP \fB-#\fR /* Edit the \fBmain.cf\fR configuration file, and comment out /* the parameters given on the \fBpostconf\fR(1) command line, *************** *** 412,418 **** /* * Parse JCL. */ ! while ((ch = GETOPT(argc, argv, "aAbc:C:deEf#hlmMntv")) > 0) { switch (ch) { case 'a': cmd_mode |= SHOW_SASL_SERV; --- 422,428 ---- /* * Parse JCL. */ ! while ((ch = GETOPT(argc, argv, "aAbc:C:deEf#hlmMntvX")) > 0) { switch (ch) { case 'a': cmd_mode |= SHOW_SASL_SERV; *************** *** 480,503 **** ext_argv = argv_alloc(2); argv_add(ext_argv, "bounce", "-SVndump_templates", (char *) 0); break; case 'v': msg_verbose++; break; default: ! msg_fatal("usage: %s [-a (server SASL types)] [-A (client SASL types)] [-b (bounce templates)] [-c config_dir] [-C param_class] [-d (defaults)] [-e (edit)] [-f (fold lines)] [-# (comment-out)] [-h (no names)] [-l (lock types)] [-m (map types)] [-M (master.cf)] [-n (non-defaults)] [-v] [name...]", argv[0]); } } /* * Sanity check. */ ! junk = (cmd_mode & (SHOW_DEFS | SHOW_NONDEF | SHOW_MAPS | SHOW_LOCKS | EDIT_MAIN | SHOW_SASL_SERV | SHOW_SASL_CLNT | COMMENT_OUT | SHOW_MASTER)); if (junk != 0 && ((junk != SHOW_DEFS && junk != SHOW_NONDEF && junk != SHOW_MAPS && junk != SHOW_LOCKS && junk != EDIT_MAIN && junk != SHOW_SASL_SERV && junk != SHOW_SASL_CLNT ! && junk != COMMENT_OUT && junk != SHOW_MASTER) || ext_argv != 0)) ! msg_fatal("specify one of -a, -A, -b, -d, -e, -#, -l, -m, -M and -n"); /* * Display bounce template information and exit. --- 490,518 ---- ext_argv = argv_alloc(2); argv_add(ext_argv, "bounce", "-SVndump_templates", (char *) 0); break; + case 'X': + /* This is irreversible, therefore require two-finger action. */ + cmd_mode = EDIT_EXCL; + break; case 'v': msg_verbose++; break; default: ! msg_fatal("usage: %s [-a (server SASL types)] [-A (client SASL types)] [-b (bounce templates)] [-c config_dir] [-C param_class] [-d (defaults)] [-e (edit)] [-f (fold lines)] [-# (comment-out)] [-h (no names)] [-l (lock types)] [-m (map types)] [-M (master.cf)] [-n (non-defaults)] [-v] [-X (exclude)] [name...]", argv[0]); } } /* * Sanity check. */ ! junk = (cmd_mode & (SHOW_DEFS | SHOW_NONDEF | SHOW_MAPS | SHOW_LOCKS | EDIT_MAIN | SHOW_SASL_SERV | SHOW_SASL_CLNT | COMMENT_OUT | SHOW_MASTER | EDIT_EXCL)); if (junk != 0 && ((junk != SHOW_DEFS && junk != SHOW_NONDEF && junk != SHOW_MAPS && junk != SHOW_LOCKS && junk != EDIT_MAIN && junk != SHOW_SASL_SERV && junk != SHOW_SASL_CLNT ! && junk != COMMENT_OUT && junk != SHOW_MASTER ! && junk != EDIT_EXCL) || ext_argv != 0)) ! msg_fatal("specify one of -a, -A, -b, -d, -e, -#, -l, -m, -M, -n, and -X"); /* * Display bounce template information and exit. *************** *** 555,561 **** /* * Edit main.cf. */ ! else if (cmd_mode & (EDIT_MAIN | COMMENT_OUT)) { edit_parameters(cmd_mode, argc - optind, argv + optind); } else if (cmd_mode == DEF_MODE && argv[optind] && strchr(argv[optind], '=')) { --- 570,576 ---- /* * Edit main.cf. */ ! else if (cmd_mode & (EDIT_MAIN | COMMENT_OUT | EDIT_EXCL)) { edit_parameters(cmd_mode, argc - optind, argv + optind); } else if (cmd_mode == DEF_MODE && argv[optind] && strchr(argv[optind], '=')) { diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.10-20120306/src/postconf/postconf.h src/postconf/postconf.h *** /var/tmp/postfix-2.10-20120306/src/postconf/postconf.h Tue Jan 17 12:25:12 2012 --- src/postconf/postconf.h Wed Mar 7 15:59:40 2012 *************** *** 30,35 **** --- 30,36 ---- #define COMMENT_OUT (1<<9) /* #-out selected main.cf entries */ #define SHOW_MASTER (1<<10) /* show master.cf entries */ #define FOLD_LINE (1<<11) /* fold long *.cf entries */ + #define EDIT_EXCL (1<<12) /* exclude main.cf entries */ #define DEF_MODE SHOW_NAME /* default mode */ diff --exclude=man --exclude=html --exclude=README_FILES --exclude=.indent.pro --exclude=Makefile.in -bcr /var/tmp/postfix-2.10-20120306/src/postconf/postconf_edit.c src/postconf/postconf_edit.c *** /var/tmp/postfix-2.10-20120306/src/postconf/postconf_edit.c Thu Nov 24 19:24:23 2011 --- src/postconf/postconf_edit.c Thu Mar 8 08:35:01 2012 *************** *** 88,106 **** table = htable_create(argc); while ((cp = *argv++) != 0) { if (strchr(cp, '\n') != 0) ! msg_fatal("-e or -# accepts no multi-line input"); while (ISSPACE(*cp)) cp++; if (*cp == '#') ! msg_fatal("-e or -# accepts no comment input"); if (mode & EDIT_MAIN) { if ((err = split_nameval(cp, &edit_key, &edit_val)) != 0) msg_fatal("%s: \"%s\"", err, cp); ! } else if (mode & COMMENT_OUT) { if (*cp == 0) ! msg_fatal("-# requires non-blank parameter names"); if (strchr(cp, '=') != 0) ! msg_fatal("-# requires parameter names only"); edit_key = mystrdup(cp); trimblanks(edit_key, 0); edit_val = 0; --- 88,106 ---- table = htable_create(argc); while ((cp = *argv++) != 0) { if (strchr(cp, '\n') != 0) ! msg_fatal("-e, -X, or -# accepts no multi-line input"); while (ISSPACE(*cp)) cp++; if (*cp == '#') ! msg_fatal("-e, -X, or -# accepts no comment input"); if (mode & EDIT_MAIN) { if ((err = split_nameval(cp, &edit_key, &edit_val)) != 0) msg_fatal("%s: \"%s\"", err, cp); ! } else if (mode & (COMMENT_OUT | EDIT_EXCL)) { if (*cp == 0) ! msg_fatal("-X or -# requires non-blank parameter names"); if (strchr(cp, '=') != 0) ! msg_fatal("-X or -# requires parameter names only"); edit_key = mystrdup(cp); trimblanks(edit_key, 0); edit_val = 0; *************** *** 164,171 **** vstream_fprintf(dst, "%s = %s\n", STR(key), cvalue->value); else if (mode & COMMENT_OUT) vstream_fprintf(dst, "#%s", cp); - else - msg_panic("edit_parameters: unknown mode %d", mode); } else { vstream_fputs(STR(buf), dst); } --- 164,169 ----