Postfix3.3.1
postconf_service.c
[詳解]
1 /*++
2 /* NAME
3 /* postconf_service 3
4 /* SUMMARY
5 /* service-defined main.cf parameter name support
6 /* SYNOPSIS
7 /* #include <postconf.h>
8 /*
9 /* void pcf_register_service_parameters()
10 /* DESCRIPTION
11 /* Service-defined parameter names are created by appending
12 /* postfix-defined suffixes to master.cf service names. All
13 /* service-defined parameters have default values that are
14 /* defined by a built-in parameter.
15 /*
16 /* pcf_register_service_parameters() adds the service-defined
17 /* parameters to the global name space. This function must be
18 /* called after the built-in parameters are added to the global
19 /* name space, and after the master.cf file is read.
20 /* DIAGNOSTICS
21 /* Problems are reported to the standard error stream.
22 /* LICENSE
23 /* .ad
24 /* .fi
25 /* The Secure Mailer license must be distributed with this software.
26 /* AUTHOR(S)
27 /* Wietse Venema
28 /* IBM T.J. Watson Research
29 /* P.O. Box 704
30 /* Yorktown Heights, NY 10598, USA
31 /*
32 /* Wietse Venema
33 /* Google, Inc.
34 /* 111 8th Avenue
35 /* New York, NY 10011, USA
36 /*--*/
37 
38 /* System library. */
39 
40 #include <sys_defs.h>
41 #include <string.h>
42 
43 /* Utility library. */
44 
45 #include <msg.h>
46 #include <mymalloc.h>
47 #include <htable.h>
48 #include <vstring.h>
49 #include <stringops.h>
50 #include <argv.h>
51 
52 /* Global library. */
53 
54 #include <mail_params.h>
55 
56 /* Application-specific. */
57 
58 #include <postconf.h>
59 
60  /*
61  * Basename of programs in $daemon_directory. XXX These belong in a header
62  * file, or they should be made configurable.
63  */
64 #ifndef MAIL_PROGRAM_LOCAL
65 #define MAIL_PROGRAM_LOCAL "local"
66 #define MAIL_PROGRAM_ERROR "error"
67 #define MAIL_PROGRAM_VIRTUAL "virtual"
68 #define MAIL_PROGRAM_SMTP "smtp"
69 #define MAIL_PROGRAM_LMTP "lmtp"
70 #define MAIL_PROGRAM_PIPE "pipe"
71 #define MAIL_PROGRAM_SPAWN "spawn"
72 #endif
73 
74  /*
75  * Ad-hoc name-value string pair.
76  */
77 typedef struct {
78  const char *name;
79  const char *value;
81 
82 #define STR(x) vstring_str(x)
83 
84 /* pcf_convert_service_parameter - get service parameter string value */
85 
86 static const char *pcf_convert_service_parameter(void *ptr)
87 {
88  return (STR(vstring_sprintf(pcf_param_string_buf, "$%s", (char *) ptr)));
89 }
90 
91 /* pcf_register_service_parameter - add service parameter name and default */
92 
93 static void pcf_register_service_parameter(const char *service,
94  const char *suffix,
95  const char *defparam)
96 {
97  char *name = concatenate(service, suffix, (char *) 0);
98  PCF_PARAM_NODE *node;
99 
100  /*
101  * Skip service parameter names that have built-in definitions. This
102  * happens with message delivery transports that have a non-default
103  * per-destination concurrency or recipient limit, such as local(8).
104  *
105  * Some parameters were tentatively flagged as built-in, but they are
106  * service parameters with their own default value. We don't change the
107  * default but we correct the parameter class.
108  */
109  if ((node = PCF_PARAM_TABLE_FIND(pcf_param_table, name)) != 0) {
111  } else {
113  (void *) defparam, pcf_convert_service_parameter);
114  }
115  myfree(name);
116 }
117 
118 /* pcf_register_service_parameters - add all service parameters with defaults */
119 
121 {
122  const char *myname = "pcf_register_service_parameters";
123  static const PCF_STRING_NV pipe_params[] = {
124  /* suffix, default parameter name */
126 #define service_params (pipe_params + 1)
143  0,
144  };
145  static const PCF_STRING_NV spawn_params[] = {
146  /* suffix, default parameter name */
148  0,
149  };
150  typedef struct {
151  const char *progname;
152  const PCF_STRING_NV *params;
153  } PCF_SERVICE_DEF;
154  static const PCF_SERVICE_DEF service_defs[] = {
160  MAIL_PROGRAM_PIPE, pipe_params,
161  MAIL_PROGRAM_SPAWN, spawn_params,
162  0,
163  };
164  const PCF_STRING_NV *sp;
165  const char *progname;
166  const char *service;
167  PCF_MASTER_ENT *masterp;
168  ARGV *argv;
169  const PCF_SERVICE_DEF *sd;
170 
171  /*
172  * Sanity checks.
173  */
174  if (pcf_param_table == 0)
175  msg_panic("%s: global parameter table is not initialized", myname);
176  if (pcf_master_table == 0)
177  msg_panic("%s: master table is not initialized", myname);
178 
179  /*
180  * Extract service names from master.cf and generate service parameter
181  * information.
182  */
183  for (masterp = pcf_master_table; (argv = masterp->argv) != 0; masterp++) {
184 
185  /*
186  * Add service parameters for message delivery transports or spawn
187  * programs.
188  */
189  progname = argv->argv[7];
190  for (sd = service_defs; sd->progname; sd++) {
191  if (strcmp(sd->progname, progname) == 0) {
192  service = argv->argv[0];
193  for (sp = sd->params; sp->name; sp++)
194  pcf_register_service_parameter(service, sp->name, sp->value);
195  break;
196  }
197  }
198  }
199 }
#define VAR_DEST_CON_LIMIT
Definition: mail_params.h:843
#define VAR_DELIVERY_SLOT_DISCOUNT
Definition: mail_params.h:821
void myfree(void *ptr)
Definition: mymalloc.c:207
const char * value
#define _CONC_NEG_FDBACK
Definition: mail_params.h:3503
#define MAIL_PROGRAM_VIRTUAL
#define _MIN_DELIVERY_SLOTS
Definition: mail_params.h:827
#define _STACK_RCPT_LIMIT
Definition: mail_params.h:794
PCF_MASTER_ENT * pcf_master_table
Definition: postconf.c:611
Definition: argv.h:17
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
#define _CONC_POS_FDBACK
Definition: mail_params.h:3498
#define _XPORT_RCPT_LIMIT
Definition: mail_params.h:789
#define VAR_DELIVERY_SLOT_LOAN
Definition: mail_params.h:816
#define _CONC_COHORT_LIM
Definition: mail_params.h:3511
#define VAR_CONC_NEG_FDBACK
Definition: mail_params.h:3502
char ** argv
Definition: argv.h:20
#define MAIL_PROGRAM_LMTP
#define PCF_PARAM_TABLE_FIND(table, name)
Definition: postconf.h:106
#define PCF_PARAM_CLASS_OVERRIDE(node, class)
Definition: postconf.h:74
#define VAR_DEST_RCPT_LIMIT
Definition: mail_params.h:855
#define VAR_INIT_DEST_CON
Definition: mail_params.h:838
const char * name
#define VAR_CONC_COHORT_LIM
Definition: mail_params.h:3510
#define VAR_XPORT_REFILL_LIMIT
Definition: mail_params.h:798
#define _XPORT_REFILL_LIMIT
Definition: mail_params.h:799
#define _MAXTIME
Definition: mail_params.h:546
#define VAR_DELIVERY_SLOT_COST
Definition: mail_params.h:811
#define service_params
#define _DEST_RATE_DELAY
Definition: mail_params.h:3520
#define _XPORT_RATE_DELAY
Definition: mail_params.h:3525
#define PCF_PARAM_FLAG_SERVICE
Definition: postconf.h:66
void pcf_register_service_parameters(void)
ARGV * argv
Definition: postconf.h:122
#define _XPORT_REFILL_DELAY
Definition: mail_params.h:804
#define VAR_COMMAND_MAXTIME
Definition: mail_params.h:545
#define VAR_CONC_POS_FDBACK
Definition: mail_params.h:3497
#define PCF_PARAM_TABLE_ENTER(table, name, flags, data, func)
Definition: postconf.h:109
#define MAIL_PROGRAM_SMTP
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
Definition: vstring.c:602
#define MAIL_PROGRAM_LOCAL
#define VAR_XPORT_RATE_DELAY
Definition: mail_params.h:3524
#define _DELIVERY_SLOT_DISCOUNT
Definition: mail_params.h:822
#define MAIL_PROGRAM_PIPE
#define MAIL_PROGRAM_SPAWN
char * concatenate(const char *arg0,...)
Definition: concatenate.c:42
VSTRING * pcf_param_string_buf
#define _DEST_RCPT_LIMIT
Definition: mail_params.h:856
PCF_PARAM_TABLE * pcf_param_table
Definition: postconf.c:610
#define MAIL_PROGRAM_ERROR
#define _INIT_DEST_CON
Definition: mail_params.h:839
#define VAR_XPORT_RCPT_LIMIT
Definition: mail_params.h:788
#define VAR_XPORT_REFILL_DELAY
Definition: mail_params.h:803
#define VAR_DEST_RATE_DELAY
Definition: mail_params.h:3519
#define _DELIVERY_SLOT_LOAN
Definition: mail_params.h:817
#define _DELIVERY_SLOT_COST
Definition: mail_params.h:812
#define VAR_STACK_RCPT_LIMIT
Definition: mail_params.h:793
#define VAR_MIN_DELIVERY_SLOTS
Definition: mail_params.h:826
#define STR(x)
#define _DEST_CON_LIMIT
Definition: mail_params.h:844