postconf_builtin.c [plain text]
#include <sys_defs.h>
#include <string.h>
#ifdef USE_PATHS_H
#include <paths.h>
#endif
#include <msg.h>
#include <mymalloc.h>
#include <htable.h>
#include <vstring.h>
#include <get_hostname.h>
#include <stringops.h>
#include <mynetworks.h>
#include <mail_conf.h>
#include <mail_params.h>
#include <mail_version.h>
#include <mail_proto.h>
#include <mail_addr.h>
#include <inet_proto.h>
#include <server_acl.h>
#include <postconf.h>
#include "time_vars.h"
#include "bool_vars.h"
#include "int_vars.h"
#include "str_vars.h"
#include "raw_vars.h"
#include "nint_vars.h"
#include "nbool_vars.h"
#include "long_vars.h"
#include "install_vars.h"
static const CONFIG_TIME_TABLE pcf_time_table[] = {
#include "time_table.h"
0,
};
static const CONFIG_BOOL_TABLE pcf_bool_table[] = {
#include "bool_table.h"
0,
};
static const CONFIG_INT_TABLE pcf_int_table[] = {
#include "int_table.h"
0,
};
static const CONFIG_STR_TABLE pcf_str_table[] = {
#include "str_table.h"
#include "install_table.h"
0,
};
static const CONFIG_RAW_TABLE pcf_raw_table[] = {
#include "raw_table.h"
0,
};
static const CONFIG_NINT_TABLE pcf_nint_table[] = {
#include "nint_table.h"
0,
};
static const CONFIG_NBOOL_TABLE pcf_nbool_table[] = {
#include "nbool_table.h"
0,
};
static const CONFIG_LONG_TABLE pcf_long_table[] = {
#include "long_table.h"
0,
};
static const CONFIG_STR_TABLE pcf_legacy_str_table[] = {
{"virtual_maps", ""},
{"fallback_relay", ""},
{"authorized_verp_clients", ""},
{"smtpd_client_connection_limit_exceptions", ""},
{"postscreen_dnsbl_ttl", ""},
0,
};
static const char *pcf_check_myhostname(void);
static const char *pcf_check_mydomainname(void);
static const char *pcf_mynetworks(void);
#include "str_fn_vars.h"
static const CONFIG_STR_FN_TABLE pcf_str_fn_table[] = {
#include "str_fn_table.h"
0,
};
static CONFIG_STR_TABLE pcf_adhoc_procname = {VAR_PROCNAME};
static CONFIG_INT_TABLE pcf_adhoc_pid = {VAR_PID};
#define STR(x) vstring_str(x)
static const char *pcf_check_myhostname(void)
{
static const char *name;
const char *dot;
const char *domain;
if (name)
return (name);
name = get_hostname();
if ((dot = strchr(name, '.')) == 0) {
if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
domain = DEF_MYDOMAIN;
name = concatenate(name, ".", domain, (char *) 0);
}
return (name);
}
static void pcf_get_myhostname(void)
{
const char *name;
if ((name = mail_conf_lookup_eval(VAR_MYHOSTNAME)) == 0)
name = pcf_check_myhostname();
var_myhostname = mystrdup(name);
}
static const char *pcf_check_mydomainname(void)
{
static const char *domain;
char *dot;
if (domain)
return (domain);
if (var_myhostname == 0)
pcf_get_myhostname();
if ((dot = strchr(var_myhostname, '.')) == 0)
return (domain = DEF_MYDOMAIN);
return (domain = mystrdup(dot + 1));
}
static const char *pcf_mynetworks(void)
{
static const char *networks;
const char *junk;
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()));
}
static const char *pcf_conv_bool_parameter(void *ptr)
{
CONFIG_BOOL_TABLE *cbt = (CONFIG_BOOL_TABLE *) ptr;
return (cbt->defval ? "yes" : "no");
}
static const char *pcf_conv_time_parameter(void *ptr)
{
CONFIG_TIME_TABLE *ctt = (CONFIG_TIME_TABLE *) ptr;
return (ctt->defval);
}
static const char *pcf_conv_int_parameter(void *ptr)
{
CONFIG_INT_TABLE *cit = (CONFIG_INT_TABLE *) ptr;
return (STR(vstring_sprintf(pcf_param_string_buf, "%d", cit->defval)));
}
static const char *pcf_conv_str_parameter(void *ptr)
{
CONFIG_STR_TABLE *cst = (CONFIG_STR_TABLE *) ptr;
return (cst->defval);
}
static const char *pcf_conv_str_fn_parameter(void *ptr)
{
CONFIG_STR_FN_TABLE *cft = (CONFIG_STR_FN_TABLE *) ptr;
return (cft->defval());
}
static const char *pcf_conv_raw_parameter(void *ptr)
{
CONFIG_RAW_TABLE *rst = (CONFIG_RAW_TABLE *) ptr;
return (rst->defval);
}
static const char *pcf_conv_nint_parameter(void *ptr)
{
CONFIG_NINT_TABLE *rst = (CONFIG_NINT_TABLE *) ptr;
return (rst->defval);
}
static const char *pcf_conv_nbool_parameter(void *ptr)
{
CONFIG_NBOOL_TABLE *bst = (CONFIG_NBOOL_TABLE *) ptr;
return (bst->defval);
}
static const char *pcf_conv_long_parameter(void *ptr)
{
CONFIG_LONG_TABLE *clt = (CONFIG_LONG_TABLE *) ptr;
return (STR(vstring_sprintf(pcf_param_string_buf, "%ld", clt->defval)));
}
void pcf_register_builtin_parameters(const char *procname, pid_t pid)
{
const char *myname = "pcf_register_builtin_parameters";
const CONFIG_TIME_TABLE *ctt;
const CONFIG_BOOL_TABLE *cbt;
const CONFIG_INT_TABLE *cit;
const CONFIG_STR_TABLE *cst;
const CONFIG_STR_FN_TABLE *cft;
const CONFIG_RAW_TABLE *rst;
const CONFIG_NINT_TABLE *nst;
const CONFIG_NBOOL_TABLE *bst;
const CONFIG_LONG_TABLE *lst;
if (pcf_param_table != 0)
msg_panic("%s: global parameter table is already initialized", myname);
pcf_param_table = PCF_PARAM_TABLE_CREATE(1000);
for (ctt = pcf_time_table; ctt->name; ctt++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, ctt->name,
PCF_PARAM_FLAG_BUILTIN, (void *) ctt,
pcf_conv_time_parameter);
for (cbt = pcf_bool_table; cbt->name; cbt++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, cbt->name,
PCF_PARAM_FLAG_BUILTIN, (void *) cbt,
pcf_conv_bool_parameter);
for (cit = pcf_int_table; cit->name; cit++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, cit->name,
PCF_PARAM_FLAG_BUILTIN, (void *) cit,
pcf_conv_int_parameter);
for (cst = pcf_str_table; cst->name; cst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, cst->name,
PCF_PARAM_FLAG_BUILTIN, (void *) cst,
pcf_conv_str_parameter);
for (cft = pcf_str_fn_table; cft->name; cft++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, cft->name,
PCF_PARAM_FLAG_BUILTIN, (void *) cft,
pcf_conv_str_fn_parameter);
for (rst = pcf_raw_table; rst->name; rst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, rst->name,
PCF_PARAM_FLAG_BUILTIN | PCF_PARAM_FLAG_RAW,
(void *) rst, pcf_conv_raw_parameter);
for (nst = pcf_nint_table; nst->name; nst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, nst->name,
PCF_PARAM_FLAG_BUILTIN, (void *) nst,
pcf_conv_nint_parameter);
for (bst = pcf_nbool_table; bst->name; bst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, bst->name,
PCF_PARAM_FLAG_BUILTIN, (void *) bst,
pcf_conv_nbool_parameter);
for (lst = pcf_long_table; lst->name; lst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, lst->name,
PCF_PARAM_FLAG_BUILTIN, (void *) lst,
pcf_conv_long_parameter);
for (cst = pcf_legacy_str_table; cst->name; cst++)
PCF_PARAM_TABLE_ENTER(pcf_param_table, cst->name,
PCF_PARAM_FLAG_LEGACY, (void *) cst,
pcf_conv_str_parameter);
pcf_adhoc_procname.defval = mystrdup(procname);
PCF_PARAM_TABLE_ENTER(pcf_param_table, pcf_adhoc_procname.name,
PCF_PARAM_FLAG_BUILTIN | PCF_PARAM_FLAG_READONLY,
(void *) &pcf_adhoc_procname, pcf_conv_str_parameter);
pcf_adhoc_pid.defval = pid;
PCF_PARAM_TABLE_ENTER(pcf_param_table, pcf_adhoc_pid.name,
PCF_PARAM_FLAG_BUILTIN | PCF_PARAM_FLAG_READONLY,
(void *) &pcf_adhoc_pid, pcf_conv_int_parameter);
}