276 static HTABLE *proxy_auth_maps;
285 static VSTRING *map_type_name_flags;
290 static int proxy_writer;
295 #define STR(x) vstring_str(x)
296 #define VSTREQ(x,y) (strcmp(STR(x),y) == 0)
300 static DICT *proxy_map_find(
const char *map_type_name,
int request_flags,
305 #define PROXY_COLON DICT_TYPE_PROXY ":"
306 #define PROXY_COLON_LEN (sizeof(PROXY_COLON) - 1)
307 #define READ_OPEN_FLAGS O_RDONLY
308 #define WRITE_OPEN_FLAGS (O_RDWR | O_CREAT)
314 #define PROXY_MAP_FIND_ERROR_RETURN(x) { *statp = (x); return (0); }
319 if (strchr(map_type_name,
':') == 0)
322 msg_warn(
"request for unapproved table: \"%s\"", map_type_name);
323 msg_warn(
"to approve this table for %s access, list %s:%s in %s:%s",
324 proxy_writer == 0 ?
"read-only" :
"read-write",
344 msg_info(
"proxy_map_find: %s",
STR(map_type_name_flags));
346 dict =
dict_open(map_type_name, proxy_writer ?
350 msg_panic(
"proxy_map_find: dict_open null result");
359 static void proxymap_sequence_service(
VSTREAM *client_stream)
364 const char *reply_key;
365 const char *reply_value;
380 reply_key = reply_value =
"";
381 }
else if ((dict = proxy_map_find(
STR(request_map), request_flags,
382 &reply_status)) == 0) {
383 reply_key = reply_value =
"";
387 dict_status =
dict_seq(dict, request_func, &reply_key, &reply_value);
388 if (dict_status == 0) {
390 }
else if (dict->
error == 0) {
392 reply_key = reply_value =
"";
396 reply_key = reply_value =
"";
412 static void proxymap_lookup_service(
VSTREAM *client_stream)
416 const char *reply_value;
429 }
else if ((dict = proxy_map_find(
STR(request_map), request_flags,
430 &reply_status)) == 0) {
432 }
else if (dict->
flags = ((dict->
flags & ~DICT_FLAG_RQST_MASK)
433 | (request_flags & DICT_FLAG_RQST_MASK)),
434 (reply_value =
dict_get(dict,
STR(request_key))) != 0) {
436 }
else if (dict->
error == 0) {
456 static void proxymap_update_service(
VSTREAM *client_stream)
479 }
else if (proxy_writer == 0) {
480 msg_warn(
"refusing %s update request on non-%s service",
483 }
else if ((dict = proxy_map_find(
STR(request_map), request_flags,
484 &reply_status)) == 0) {
487 dict->
flags = ((dict->
flags & ~DICT_FLAG_RQST_MASK)
488 | (request_flags & DICT_FLAG_RQST_MASK)
490 dict_status =
dict_put(dict,
STR(request_key),
STR(request_value));
491 if (dict_status == 0) {
493 }
else if (dict->
error == 0) {
511 static void proxymap_delete_service(
VSTREAM *client_stream)
530 }
else if (proxy_writer == 0) {
531 msg_warn(
"refusing %s delete request on non-%s service",
534 }
else if ((dict = proxy_map_find(
STR(request_map), request_flags,
535 &reply_status)) == 0) {
538 dict->
flags = ((dict->
flags & ~DICT_FLAG_RQST_MASK)
539 | (request_flags & DICT_FLAG_RQST_MASK)
542 if (dict_status == 0) {
544 }
else if (dict->
error == 0) {
562 static void proxymap_open_service(
VSTREAM *client_stream)
578 }
else if ((dict = proxy_map_find(
STR(request_map), request_flags,
579 &reply_status)) == 0) {
583 reply_flags = dict->
flags;
597 static void proxymap_service(
VSTREAM *client_stream,
char *unused_service,
605 msg_fatal(
"unexpected command-line argument: %s", argv[0]);
628 proxymap_lookup_service(client_stream);
630 proxymap_update_service(client_stream);
632 proxymap_delete_service(client_stream);
634 proxymap_sequence_service(client_stream);
636 proxymap_open_service(client_stream);
638 msg_warn(
"unrecognized request: \"%s\", ignored",
STR(request));
655 msg_info(
"dict_proxy_open(%s, 0%o, 0%o) called from internal routine",
656 map, open_flags, dict_flags);
659 return (
dict_open(map, open_flags, dict_flags));
664 static void post_jail_init(
char *service_name,
char **unused_argv)
678 msg_fatal(
"service name must be one of %s or %s",
696 while ((type_name =
mystrtokq(&bp, sep, parens)) != 0) {
702 if (strchr(type_name,
':') != 0
704 (void)
htable_enter(proxy_auth_maps, type_name, (
void *) 0);
712 if (proxy_writer != 0)
718 static void pre_accept(
char *unused_name,
char **unused_argv)
723 msg_info(
"table %s has changed -- restarting", table);
732 int main(
int argc,
char **argv)
#define DEF_TRANSPORT_MAPS
#define VAR_PROXY_WRITE_MAPS
#define CA_VSTREAM_CTL_TIMEOUT(v)
HTABLE_INFO * htable_locate(HTABLE *table, const char *key)
DICT * dict_proxy_open(const char *map, int open_flags, int dict_flags)
char * mystrdup(const char *str)
#define dict_put(dp, key, val)
void dict_register(const char *dict_name, DICT *dict_info)
#define DICT_FLAG_RQST_MASK
#define DICT_SEQ_FUN_FIRST
#define DEF_RELAY_DOMAINS
char * var_rcpt_canon_maps
NORETURN msg_panic(const char *fmt,...)
#define CA_MAIL_SERVER_STR_TABLE(v)
#define VAR_RELAY_DOMAINS
#define DEF_VIRT_ALIAS_DOMS
#define DICT_SEQ_FUN_NEXT
#define PROXY_MAP_FIND_ERROR_RETURN(x)
#define DEF_LOCAL_RCPT_MAPS
char * var_transport_maps
#define PROXY_REQ_SEQUENCE
#define RECV_ATTR_INT(name, val)
MAIL_VERSION_STAMP_DECLARE
char * mystrtokq(char **src, const char *sep, const char *parens)
DICT * dict_open(const char *, int, int)
char * var_virt_alias_maps
#define VAR_RELOCATED_MAPS
#define VAR_SEND_CANON_MAPS
NORETURN multi_server_main(int, char **, MULTI_SERVER_FN,...)
char * var_proxy_read_maps
char * var_virt_mailbox_maps
#define VAR_VIRT_ALIAS_MAPS
#define VAR_VIRT_MAILBOX_DOMS
#define VAR_VIRT_ALIAS_DOMS
#define MAIL_SERVICE_PROXYWRITE
HTABLE * htable_create(ssize_t size)
#define VAR_VIRT_MAILBOX_MAPS
#define CA_MAIL_SERVER_POST_INIT(v)
#define VAR_CANONICAL_MAPS
#define VAR_TRANSPORT_MAPS
#define VAR_LOCAL_RCPT_MAPS
#define PROXY_STAT_CONFIG
#define DEF_CANONICAL_MAPS
#define dict_get(dp, key)
#define DICT_FLAG_DUP_REPLACE
char * var_canonical_maps
#define CA_VSTREAM_CTL_START_DEADLINE
const char * dict_changed_name(void)
#define DEF_VIRT_ALIAS_MAPS
#define dict_seq(dp, f, key, val)
#define DEF_SMTPD_SND_AUTH_MAPS
DICT * dict_handle(const char *dict_name)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
char * var_virt_mailbox_doms
#define VAR_PROXY_READ_MAPS
#define DEF_RCPT_CANON_MAPS
char * var_local_rcpt_maps
#define MAIL_VERSION_STAMP_ALLOCATE
#define DEF_PROXY_WRITE_MAPS
const char * dict_flags_str(int dict_flags)
char * var_send_canon_maps
#define DICT_FLAG_INST_MASK
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
#define VSTREAM_FLAG_DEADLINE
#define DEF_PSC_CACHE_MAP
#define DEF_VIRT_MAILBOX_DOMS
#define SEND_ATTR_INT(name, val)
#define DEF_PROXY_READ_MAPS
#define VAR_RCPT_CANON_MAPS
NORETURN msg_fatal(const char *fmt,...)
int vstream_fflush(VSTREAM *stream)
char * var_proxy_write_maps
#define vstream_fstat(vp, fl)
char * var_relocated_maps
#define MAIL_SERVICE_PROXYMAP
char * var_relay_rcpt_maps
char * var_smtpd_snd_auth_maps
#define CA_VSTREAM_CTL_END
#define DICT_FLAG_SYNC_UPDATE
#define DEF_VIRT_MAILBOX_MAPS
#define VAR_PSC_CACHE_MAP
#define CA_MAIL_SERVER_PRE_ACCEPT(v)
void vstream_control(VSTREAM *stream, int name,...)
#define dict_del(dp, key)
#define VAR_SMTPD_SND_AUTH_MAPS
int main(int argc, char **argv)
#define SEND_ATTR_STR(name, val)
#define DEF_RELAY_RCPT_MAPS
char * var_virt_alias_doms
#define DEF_RELOCATED_MAPS
#define VAR_RELAY_RCPT_MAPS
#define DEF_SEND_CANON_MAPS
#define RECV_ATTR_STR(name, val)
HTABLE_INFO * htable_enter(HTABLE *table, const char *key, void *value)
void msg_info(const char *fmt,...)