1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*++
/* NAME
/* local_transport 3
/* SUMMARY
/* determine if transport delivers locally
/* SYNOPSIS
/* #include <local_transport.h>
/*
/* const char *get_def_local_transport()
/*
/* int match_def_local_transport(transport)
/* const char *transport;
/*
/* int match_any_local_transport(transport)
/* const char *transport;
/* DESCRIPTION
/* This module uses the information kept in the "local_transports"
/* configuration parameter, which lists the name of the default
/* local transport, followed by the names of zero or more other
/* transports that deliver locally.
/*
/* get_def_local_transport() returns the name of the default local
/* transport, that is, the first transport name specified with
/* the "local_transports" configuration parameter.
/*
/* match_def_local_transport() determines if the named transport is
/* identical to the default local transport.
/*
/* match_any_local_transport() determines if the named transport is
/* listed in the "local_transports" configuration parameter.
/* SEE ALSO
/* resolve_local(3), see if address resolves locally
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System library. */
#include <sys_defs.h>
#include <string.h>
/* Utility library. */
#include <msg.h>
#include <mymalloc.h>
#include <string_list.h>
/* Global library. */
#include <mail_params.h>
#include <local_transport.h>
/* Application-specific */
static STRING_LIST *local_transport_list;
static char *local_transport_name;
/* local_transport_init - initialize lookup table */
static void local_transport_init(void)
{
char *myname = "local_transport_init";
/*
* Sanity check.
*/
if (local_transport_list || local_transport_name)
msg_panic("local_transport_init: duplicate initialization");
/*
* Initialize.
*/
local_transport_list = string_list_init(var_local_transports);
local_transport_name = mystrndup(var_local_transports,
strcspn(var_local_transports, ", \t\r\n"));
/*
* Sanity check.
*/
if (!match_any_local_transport(local_transport_name)
|| !match_def_local_transport(local_transport_name))
msg_panic("%s: unable to intialize", myname);
}
/* get_def_local_transport - determine default local transport */
const char *get_def_local_transport(void)
{
/*
* Initialize on the fly.
*/
if (local_transport_name == 0)
local_transport_init();
/*
* Return the first transport listed.
*/
return (local_transport_name);
}
/* match_def_local_transport - match against default local transport */
int match_def_local_transport(const char *transport)
{
/*
* Initialize on the fly.
*/
if (local_transport_list == 0)
local_transport_init();
/*
* Compare the transport against the list of transports that are listed
* as delivering locally.
*/
return (strcmp(transport, local_transport_name) == 0);
}
/* match_any_local_transport - match against list of local transports */
int match_any_local_transport(const char *transport)
{
/*
* Initialize on the fly.
*/
if (local_transport_list == 0)
local_transport_init();
/*
* Compare the transport against the list of transports that are listed
* as delivering locally.
*/
return (string_list_match(local_transport_list, transport));
}
#ifdef TEST
#include <vstream.h>
#include <mail_conf.h>
int main(int argc, char **argv)
{
if (argc != 2)
msg_fatal("usage: %s transport", argv[0]);
mail_conf_read();
vstream_printf("%s\n", match_any_local_transport(argv[1]) ? "yes" : "no");
vstream_fflush(VSTREAM_OUT);
}
#endif
|