static void pcf_print_parameter(VSTREAM *fp, int mode, const char *name, PCF_PARAM_NODE *node) { const char *value; /* * Use the default or actual value. */ value = pcf_lookup_parameter_value(mode, name, (PCF_MASTER_ENT *) 0, node); /* * Optionally expand $name in the parameter value. Print the result with * or without the name= prefix. */ if (value != 0) { if (mode & PCF_HIDE_VALUE) { pcf_print_line(fp, mode, "%s\n", name); } else { if ((mode & PCF_SHOW_EVAL) != 0 && PCF_RAW_PARAMETER(node) == 0) value = pcf_expand_parameter_value((VSTRING *) 0, mode, value, (PCF_MASTER_ENT *) 0); if ((mode & PCF_HIDE_NAME) == 0) { pcf_print_line(fp, mode, "%s = %s\n", name, value); } else { pcf_print_line(fp, mode, "%s\n", value); } } if (msg_verbose) vstream_fflush(fp); } }
static const char *pcf_mynetworks(void) { static const char *networks; const char *junk; /* * Use cached result. */ if (networks) return (networks); if (var_inet_interfaces == 0) { if ((pcf_cmd_mode & PCF_SHOW_DEFS) || (junk = mail_conf_lookup_eval(VAR_INET_INTERFACES)) == 0) junk = pcf_expand_parameter_value((VSTRING *) 0, pcf_cmd_mode, DEF_INET_INTERFACES, (PCF_MASTER_ENT *) 0); var_inet_interfaces = mystrdup(junk); } if (var_mynetworks_style == 0) { if ((pcf_cmd_mode & PCF_SHOW_DEFS) || (junk = mail_conf_lookup_eval(VAR_MYNETWORKS_STYLE)) == 0) junk = pcf_expand_parameter_value((VSTRING *) 0, pcf_cmd_mode, DEF_MYNETWORKS_STYLE, (PCF_MASTER_ENT *) 0); var_mynetworks_style = mystrdup(junk); } if (var_inet_protocols == 0) { if ((pcf_cmd_mode & PCF_SHOW_DEFS) || (junk = mail_conf_lookup_eval(VAR_INET_PROTOCOLS)) == 0) junk = pcf_expand_parameter_value((VSTRING *) 0, pcf_cmd_mode, DEF_INET_PROTOCOLS, (PCF_MASTER_ENT *) 0); var_inet_protocols = mystrdup(junk); (void) inet_proto_init(VAR_INET_PROTOCOLS, var_inet_protocols); } return (networks = mystrdup(mynetworks())); }
void pcf_register_dbms_parameters(const char *param_value, const char *(flag_parameter) (const char *, int, PCF_MASTER_ENT *), PCF_MASTER_ENT *local_scope) { char *bufp; static VSTRING *buffer = 0; /* * XXX This does not examine both sides of conditional macro expansion, * and may expand the "wrong" conditional macros. This is the best we can * do for legacy database configuration support. */ if (buffer == 0) buffer = vstring_alloc(100); bufp = pcf_expand_parameter_value(buffer, PCF_SHOW_EVAL, param_value, local_scope); pcf_register_dbms_helper(bufp, flag_parameter, local_scope); }
static void pcf_print_master_param(VSTREAM *fp, int mode, PCF_MASTER_ENT *masterp, const char *param_name, const char *param_value) { if (mode & PCF_HIDE_VALUE) { pcf_print_line(fp, mode, "%s%c%s\n", masterp->name_space, PCF_NAMESP_SEP_CH, param_name); } else { if ((mode & PCF_SHOW_EVAL) != 0) param_value = pcf_expand_parameter_value((VSTRING *) 0, mode, param_value, masterp); if ((mode & PCF_HIDE_NAME) == 0) { pcf_print_line(fp, mode, "%s%c%s = %s\n", masterp->name_space, PCF_NAMESP_SEP_CH, param_name, param_value); } else { pcf_print_line(fp, mode, "%s\n", param_value); } } if (msg_verbose) vstream_fflush(fp); }
static void pcf_print_master_field(VSTREAM *fp, int mode, PCF_MASTER_ENT *masterp, int field) { char **argv = masterp->argv->argv; const char *arg; const char *aval; int arg_len; int line_len; int in_daemon_options; int need_parens; /* * Show the field value, or the first value in the case of a multi-column * field. */ #define ADD_CHAR(ch) ADD_TEXT((ch), 1) line_len = 0; if ((mode & PCF_HIDE_NAME) == 0) { ADD_TEXT(argv[0], strlen(argv[0])); ADD_CHAR(PCF_NAMESP_SEP_STR); ADD_TEXT(argv[1], strlen(argv[1])); ADD_CHAR(PCF_NAMESP_SEP_STR); ADD_TEXT(pcf_str_field_pattern(field), strlen(pcf_str_field_pattern(field))); } if ((mode & (PCF_HIDE_NAME | PCF_HIDE_VALUE)) == 0) { ADD_TEXT(" = ", 3); } if ((mode & PCF_HIDE_VALUE) == 0) { if (line_len > 0 && line_len + strlen(argv[field]) > PCF_LINE_LIMIT) { vstream_fputs("\n" PCF_INDENT_TEXT, fp); line_len = PCF_INDENT_LEN; } ADD_TEXT(argv[field], strlen(argv[field])); } /* * Format the daemon command-line options and non-option arguments. Here, * we have no data-dependent preference for column positions, but we do * have argument grouping preferences. */ if (field == PCF_MASTER_FLD_CMD && (mode & PCF_HIDE_VALUE) == 0) { in_daemon_options = 1; for (field += 1; (arg = argv[field]) != 0; field++) { arg_len = strlen(arg); aval = 0; need_parens = 0; if (in_daemon_options) { /* * We make no special case for generic options (-v -D) * options. */ if (arg[0] != '-' || strcmp(arg, "--") == 0) { in_daemon_options = 0; } else if (strchr(pcf_daemon_options_expecting_value, arg[1]) != 0 && (aval = argv[field + 1]) != 0) { /* Force line break before option with value. */ line_len = PCF_LINE_LIMIT; /* * Optionally, expand $name in parameter value. */ if (strcmp(arg, "-o") == 0 && (mode & PCF_SHOW_EVAL) != 0) aval = pcf_expand_parameter_value((VSTRING *) 0, mode, aval, masterp); /* * Keep option and value on the same line. */ arg_len += strlen(aval) + 1; if ((need_parens = aval[strcspn(aval, PCF_MASTER_BLANKS)]) != 0) arg_len += 2; } } else { need_parens = arg[strcspn(arg, PCF_MASTER_BLANKS)]; } /* * Insert a line break when the next item won't fit. */ if (line_len > PCF_INDENT_LEN) { if ((mode & PCF_FOLD_LINE) == 0 || line_len + 1 + arg_len < PCF_LINE_LIMIT) { ADD_SPACE; } else { vstream_fputs("\n" PCF_INDENT_TEXT, fp); line_len = PCF_INDENT_LEN; } } if (in_daemon_options == 0 && need_parens) ADD_TEXT("{", 1); ADD_TEXT(arg, strlen(arg)); if (in_daemon_options == 0 && need_parens) ADD_TEXT("}", 1); if (aval) { ADD_SPACE; if (need_parens) ADD_TEXT("{", 1); ADD_TEXT(aval, strlen(aval)); if (need_parens) ADD_TEXT("}", 1); field += 1; /* Force line break after option with value. */ line_len = PCF_LINE_LIMIT; } } } vstream_fputs("\n", fp); if (msg_verbose) vstream_fflush(fp); }
void pcf_print_master_entry(VSTREAM *fp, int mode, PCF_MASTER_ENT *masterp) { char **argv = masterp->argv->argv; const char *arg; const char *aval; int arg_len; int line_len; int field; int in_daemon_options; int need_parens; static int column_goal[] = { 0, /* service */ 11, /* type */ 17, /* private */ 25, /* unpriv */ 33, /* chroot */ 41, /* wakeup */ 49, /* maxproc */ 57, /* command */ }; #define ADD_TEXT(text, len) do { \ vstream_fputs(text, fp); line_len += len; } \ while (0) #define ADD_SPACE ADD_TEXT(" ", 1) /* * Show the standard fields at their preferred column position. Use at * least one-space column separation. */ for (line_len = 0, field = 0; field < PCF_MASTER_MIN_FIELDS; field++) { arg = argv[field]; if (line_len > 0) { do { ADD_SPACE; } while (line_len < column_goal[field]); } ADD_TEXT(arg, strlen(arg)); } /* * Format the daemon command-line options and non-option arguments. Here, * we have no data-dependent preference for column positions, but we do * have argument grouping preferences. */ in_daemon_options = 1; for ( /* void */ ; (arg = argv[field]) != 0; field++) { arg_len = strlen(arg); aval = 0; need_parens = 0; if (in_daemon_options) { /* * Try to show the generic options (-v -D) on the first line, and * non-options on a later line. */ if (arg[0] != '-' || strcmp(arg, "--") == 0) { in_daemon_options = 0; #if 0 if (mode & PCF_FOLD_LINE) /* Force line wrap. */ line_len = PCF_LINE_LIMIT; #endif } /* * Special processing for options that require a value. */ else if (strchr(pcf_daemon_options_expecting_value, arg[1]) != 0 && (aval = argv[field + 1]) != 0) { /* Force line wrap before option with value. */ line_len = PCF_LINE_LIMIT; /* * Optionally, expand $name in parameter value. */ if (strcmp(arg, "-o") == 0 && (mode & PCF_SHOW_EVAL) != 0) aval = pcf_expand_parameter_value((VSTRING *) 0, mode, aval, masterp); /* * Keep option and value on the same line. */ arg_len += strlen(aval) + 3; if ((need_parens = aval[strcspn(aval, PCF_MASTER_BLANKS)]) != 0) arg_len += 2; } } else { need_parens = arg[strcspn(arg, PCF_MASTER_BLANKS)]; } /* * Insert a line break when the next item won't fit. */ if (line_len > PCF_INDENT_LEN) { if ((mode & PCF_FOLD_LINE) == 0 || line_len + 1 + arg_len < PCF_LINE_LIMIT) { ADD_SPACE; } else { vstream_fputs("\n" PCF_INDENT_TEXT, fp); line_len = PCF_INDENT_LEN; } } if (in_daemon_options == 0 && need_parens) ADD_TEXT("{", 1); ADD_TEXT(arg, strlen(arg)); if (in_daemon_options == 0 && need_parens) ADD_TEXT("}", 1); if (aval) { ADD_TEXT(" ", 1); if (need_parens) ADD_TEXT("{", 1); ADD_TEXT(aval, strlen(aval)); if (need_parens) ADD_TEXT("}", 1); field += 1; /* Force line wrap after option with value. */ line_len = PCF_LINE_LIMIT; } } vstream_fputs("\n", fp); if (msg_verbose) vstream_fflush(fp); }