1 /* $NetBSD: postconf.h,v 1.1.1.3 2014/07/06 19:27:53 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* postconf 3h 6 /* SUMMARY 7 /* module interfaces 8 /* SYNOPSIS 9 /* #include <postconf.h> 10 /* DESCRIPTION 11 /* .nf 12 13 /* 14 * System library. 15 */ 16 #include <unistd.h> 17 18 /* 19 * Utility library. 20 */ 21 #include <htable.h> 22 #include <argv.h> 23 #include <dict.h> 24 #include <name_code.h> 25 26 /* 27 * What we're supposed to be doing. 28 */ 29 #define PCF_SHOW_NONDEF (1<<0) /* show main.cf non-default settings */ 30 #define PCF_SHOW_DEFS (1<<1) /* show main.cf default setting */ 31 #define PCF_HIDE_NAME (1<<2) /* hide main.cf parameter name */ 32 #define PCF_SHOW_MAPS (1<<3) /* show map types */ 33 #define PCF_EDIT_CONF (1<<4) /* edit main.cf or master.cf */ 34 #define PCF_SHOW_LOCKS (1<<5) /* show mailbox lock methods */ 35 #define PCF_SHOW_EVAL (1<<6) /* expand main.cf right-hand sides */ 36 #define PCF_SHOW_SASL_SERV (1<<7) /* show server auth plugin types */ 37 #define PCF_SHOW_SASL_CLNT (1<<8) /* show client auth plugin types */ 38 #define PCF_COMMENT_OUT (1<<9) /* #-out selected main.cf entries */ 39 #define PCF_MASTER_ENTRY (1<<10) /* manage master.cf entries */ 40 #define PCF_FOLD_LINE (1<<11) /* fold long *.cf entries */ 41 #define PCF_EDIT_EXCL (1<<12) /* exclude main.cf entries */ 42 #define PCF_MASTER_FLD (1<<13) /* hierarchical pathname */ 43 #define PCF_MAIN_PARAM (1<<14) /* manage main.cf entries */ 44 #define PCF_EXP_DSN_TEMPL (1<<15) /* expand bounce templates */ 45 #define PCF_PARAM_CLASS (1<<16) /* select parameter class */ 46 #define PCF_MAIN_OVER (1<<17) /* override parameter values */ 47 #define PCF_DUMP_DSN_TEMPL (1<<18) /* show bounce templates */ 48 #define PCF_MASTER_PARAM (1<<19) /* manage master.cf -o name=value */ 49 50 #define PCF_DEF_MODE 0 51 52 /* 53 * Structure for one "valid parameter" (built-in, service-defined or valid 54 * user-defined). See the postconf_builtin, postconf_service and 55 * postconf_user modules for narrative text. 56 */ 57 typedef struct { 58 int flags; /* see below */ 59 char *param_data; /* mostly, the default value */ 60 const char *(*convert_fn) (char *); /* value to string */ 61 } PCF_PARAM_NODE; 62 63 /* Values for flags. See the postconf_node module for narrative text. */ 64 #define PCF_PARAM_FLAG_RAW (1<<0) /* raw parameter value */ 65 #define PCF_PARAM_FLAG_BUILTIN (1<<1) /* built-in parameter name */ 66 #define PCF_PARAM_FLAG_SERVICE (1<<2) /* service-defined parameter name */ 67 #define PCF_PARAM_FLAG_USER (1<<3) /* user-defined parameter name */ 68 #define PCF_PARAM_FLAG_LEGACY (1<<4) /* legacy parameter name */ 69 #define PCF_PARAM_FLAG_READONLY (1<<5) /* legacy parameter name */ 70 #define PCF_PARAM_FLAG_DBMS (1<<6) /* dbms-defined parameter name */ 71 72 #define PCF_PARAM_MASK_CLASS \ 73 (PCF_PARAM_FLAG_BUILTIN | PCF_PARAM_FLAG_SERVICE | PCF_PARAM_FLAG_USER) 74 #define PCF_PARAM_CLASS_OVERRIDE(node, class) \ 75 ((node)->flags = (((node)->flags & ~PCF_PARAM_MASK_CLASS) | (class))) 76 77 #define PCF_RAW_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_RAW) 78 #define PCF_LEGACY_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_LEGACY) 79 #define PCF_READONLY_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_READONLY) 80 #define PCF_DBMS_PARAMETER(node) ((node)->flags & PCF_PARAM_FLAG_DBMS) 81 82 /* Values for param_data. See postconf_node module for narrative text. */ 83 #define PCF_PARAM_NO_DATA ((char *) 0) 84 85 /* 86 * Lookup table for global "valid parameter" information. 87 */ 88 #define PCF_PARAM_TABLE HTABLE 89 #define PCF_PARAM_INFO HTABLE_INFO 90 91 extern PCF_PARAM_TABLE *pcf_param_table; 92 93 /* 94 * postconf_node.c. 95 */ 96 #define PCF_PARAM_TABLE_CREATE(size) htable_create(size); 97 #define PCF_PARAM_NODE_CAST(ptr) ((PCF_PARAM_NODE *) (ptr)) 98 99 #define PCF_PARAM_TABLE_LIST(table) htable_list(table) 100 #define PCF_PARAM_INFO_NAME(ht) ((const char *) (ht)->key) 101 #define PCF_PARAM_INFO_NODE(ht) PCF_PARAM_NODE_CAST((ht)->value) 102 103 #define PCF_PARAM_TABLE_FIND(table, name) \ 104 PCF_PARAM_NODE_CAST(htable_find((table), (name))) 105 #define PCF_PARAM_TABLE_LOCATE(table, name) htable_locate((table), (name)) 106 #define PCF_PARAM_TABLE_ENTER(table, name, flags, data, func) \ 107 htable_enter((table), (name), (char *) pcf_make_param_node((flags), \ 108 (data), (func))) 109 110 extern PCF_PARAM_NODE *pcf_make_param_node(int, char *, const char *(*) (char *)); 111 extern const char *pcf_convert_param_node(int, const char *, PCF_PARAM_NODE *); 112 extern VSTRING *pcf_param_string_buf; 113 114 /* 115 * Structure of one master.cf entry. 116 */ 117 typedef struct { 118 char *name_space; /* service/type, parameter name space */ 119 ARGV *argv; /* null, or master.cf fields */ 120 DICT *all_params; /* null, or all name=value entries */ 121 HTABLE *valid_names; /* null, or "valid" parameter names */ 122 } PCF_MASTER_ENT; 123 124 #define PCF_MASTER_MIN_FIELDS 8 /* mandatory field minimum */ 125 126 #define PCF_MASTER_NAME_SERVICE "service" 127 #define PCF_MASTER_NAME_TYPE "type" 128 #define PCF_MASTER_NAME_PRIVATE "private" 129 #define PCF_MASTER_NAME_UNPRIV "unprivileged" 130 #define PCF_MASTER_NAME_CHROOT "chroot" 131 #define PCF_MASTER_NAME_WAKEUP "wakeup" 132 #define PCF_MASTER_NAME_MAXPROC "process_limit" 133 #define PCF_MASTER_NAME_CMD "command" 134 135 #define PCF_MASTER_FLD_SERVICE 0 /* service name */ 136 #define PCF_MASTER_FLD_TYPE 1 /* service type */ 137 #define PCF_MASTER_FLD_PRIVATE 2 /* private service */ 138 #define PCF_MASTER_FLD_UNPRIV 3 /* unprivileged service */ 139 #define PCF_MASTER_FLD_CHROOT 4 /* chrooted service */ 140 #define PCF_MASTER_FLD_WAKEUP 5 /* wakeup timer */ 141 #define PCF_MASTER_FLD_MAXPROC 6 /* process limit */ 142 #define PCF_MASTER_FLD_CMD 7 /* command */ 143 144 #define PCF_MASTER_FLD_WILDC -1 /* wild-card */ 145 #define PCF_MASTER_FLD_NONE -2 /* not available */ 146 147 /* 148 * Lookup table for master.cf entries. The table is terminated with an entry 149 * that has a null argv member. 150 */ 151 PCF_MASTER_ENT *pcf_master_table; 152 153 /* 154 * Line-wrapping support. 155 */ 156 #define PCF_LINE_LIMIT 80 /* try to fold longer lines */ 157 #define PCF_SEPARATORS " \t\r\n" 158 #define PCF_INDENT_LEN 4 /* indent long text by 4 */ 159 #define PCF_INDENT_TEXT " " 160 161 /* 162 * XXX Global so that postconf_builtin.c call-backs can see it. 163 */ 164 extern int pcf_cmd_mode; 165 166 /* 167 * postconf_misc.c. 168 */ 169 extern void pcf_set_config_dir(void); 170 171 /* 172 * postconf_main.c 173 */ 174 extern void pcf_read_parameters(void); 175 extern void pcf_set_parameters(char **); 176 extern void pcf_show_parameters(VSTREAM *, int, int, char **); 177 178 /* 179 * postconf_edit.c 180 */ 181 extern void pcf_edit_main(int, int, char **); 182 extern void pcf_edit_master(int, int, char **); 183 184 /* 185 * postconf_master.c. 186 */ 187 extern const char pcf_daemon_options_expecting_value[]; 188 extern void pcf_read_master(int); 189 extern void pcf_show_master_entries(VSTREAM *, int, int, char **); 190 extern const char *pcf_parse_master_entry(PCF_MASTER_ENT *, const char *); 191 extern void pcf_print_master_entry(VSTREAM *, int, PCF_MASTER_ENT *); 192 extern void pcf_free_master_entry(PCF_MASTER_ENT *); 193 extern void pcf_show_master_fields(VSTREAM *, int, int, char **); 194 extern void pcf_edit_master_field(PCF_MASTER_ENT *, int, const char *); 195 extern void pcf_show_master_params(VSTREAM *, int, int, char **); 196 extern void pcf_edit_master_param(PCF_MASTER_ENT *, int, const char *, const char *); 197 198 #define PCF_WARN_ON_OPEN_ERROR 0 199 #define PCF_FAIL_ON_OPEN_ERROR 1 200 201 #define PCF_MASTER_BLANKS " \t\r\n" /* XXX */ 202 203 /* 204 * Master.cf parameter namespace management. The idea is to manage master.cf 205 * "-o name=value" settings with other tools than text editors. 206 * 207 * The natural choice is to use "service-name.service-type.parameter-name", but 208 * unfortunately the '.' may appear in service and parameter names. 209 * 210 * For example, a spawn(8) listener can have a service name 127.0.0.1:10028. 211 * This service name becomes part of a service-dependent parameter name 212 * "127.0.0.1:10028_time_limit". All those '.' characters mean we can't use 213 * '.' as the parameter namespace delimiter. 214 * 215 * (We could require that such service names are specified as $foo:port with 216 * the value of "foo" defined in main.cf or at the top of master.cf.) 217 * 218 * But it is easier if we use '/' instead. 219 */ 220 #define PCF_NAMESP_SEP_CH '/' 221 #define PCF_NAMESP_SEP_STR "/" 222 223 #define PCF_LEGACY_SEP_CH '.' 224 225 /* 226 * postconf_match.c. 227 */ 228 #define PCF_MATCH_WILDC_STR "*" 229 #define PCF_MATCH_ANY(p) ((p)[0] == PCF_MATCH_WILDC_STR[0] && (p)[1] == 0) 230 #define PCF_MATCH_STRING(p, s) (PCF_MATCH_ANY(p) || strcmp((p), (s)) == 0) 231 232 extern ARGV *pcf_parse_service_pattern(const char *, int, int); 233 extern int pcf_parse_field_pattern(const char *); 234 235 #define PCF_IS_MAGIC_SERVICE_PATTERN(pat) \ 236 (PCF_MATCH_ANY((pat)->argv[0]) || PCF_MATCH_ANY((pat)->argv[1])) 237 #define PCF_MATCH_SERVICE_PATTERN(pat, name, type) \ 238 (PCF_MATCH_STRING((pat)->argv[0], (name)) \ 239 && PCF_MATCH_STRING((pat)->argv[1], (type))) 240 241 #define pcf_is_magic_field_pattern(pat) ((pat) == PCF_MASTER_FLD_WILDC) 242 #define pcf_str_field_pattern(pat) ((const char *) (pcf_field_name_offset[pat].name)) 243 244 #define PCF_IS_MAGIC_PARAM_PATTERN(pat) PCF_MATCH_ANY(pat) 245 #define PCF_MATCH_PARAM_PATTERN(pat, name) PCF_MATCH_STRING((pat), (name)) 246 247 /* The following is not part of the postconf_match API. */ 248 extern NAME_CODE pcf_field_name_offset[]; 249 250 /* 251 * postconf_builtin.c. 252 */ 253 extern void pcf_register_builtin_parameters(const char *, pid_t); 254 255 /* 256 * postconf_service.c. 257 */ 258 extern void pcf_register_service_parameters(void); 259 260 /* 261 * Parameter context structure. 262 */ 263 typedef struct { 264 PCF_MASTER_ENT *local_scope; 265 int param_class; 266 } PCF_PARAM_CTX; 267 268 /* 269 * postconf_user.c. 270 */ 271 extern void pcf_register_user_parameters(void); 272 273 /* 274 * postconf_dbms.c 275 */ 276 extern void pcf_register_dbms_parameters(const char *, 277 const char *(*) (const char *, int, PCF_MASTER_ENT *), 278 PCF_MASTER_ENT *); 279 280 /* 281 * postconf_lookup.c. 282 */ 283 extern const char *pcf_lookup_parameter_value(int, const char *, 284 PCF_MASTER_ENT *, 285 PCF_PARAM_NODE *); 286 287 extern char *pcf_expand_parameter_value(VSTRING *, int, const char *, 288 PCF_MASTER_ENT *); 289 290 /* 291 * postconf_print.c. 292 */ 293 extern void pcf_print_line(VSTREAM *, int, const char *,...); 294 295 /* 296 * postconf_unused.c. 297 */ 298 extern void pcf_flag_unused_main_parameters(void); 299 extern void pcf_flag_unused_master_parameters(void); 300 301 /* 302 * postconf_other.c. 303 */ 304 extern void pcf_show_maps(void); 305 extern void pcf_show_locks(void); 306 extern void pcf_show_sasl(int); 307 308 /* LICENSE 309 /* .ad 310 /* .fi 311 /* The Secure Mailer license must be distributed with this software. 312 /* AUTHOR(S) 313 /* Wietse Venema 314 /* IBM T.J. Watson Research 315 /* P.O. Box 704 316 /* Yorktown Heights, NY 10598, USA 317 /*--*/ 318