7 /* caching resolve client
9 /* #include <smtpd_resolve.h>
11 /* void smtpd_resolve_init(cache_size)
14 /* const RESOLVE_REPLY *smtpd_resolve_addr(addr)
17 /* This module maintains a resolve client cache that persists
18 /* across SMTP sessions (not process life times). Addresses
19 /* are always resolved in local rewriting context.
21 /* smtpd_resolve_init() initializes the cache and must
22 /* called once before the cache can be used.
24 /* smtpd_resolve_addr() resolves one address or returns
25 /* a known result from cache.
29 /* The requested cache size.
31 /* The address to resolve.
33 /* All errors are fatal.
35 /* The recipient address is always case folded to lowercase.
36 /* Changing this requires great care, since the address is used
37 /* for policy lookups.
41 /* The Secure Mailer license must be distributed with this software.
44 /* IBM T.J. Watson Research
46 /* Yorktown Heights, NY 10598, USA
53 /* Utility library. */
59 #include <stringops.h>
63 #include <rewrite_clnt.h>
64 #include <resolve_clnt.h>
65 #include <mail_proto.h>
67 /* Application-specific. */
69 #include <smtpd_resolve.h>
71 static CTABLE
*smtpd_resolve_cache
;
73 #define STR(x) vstring_str(x)
75 /* resolve_pagein - page in an address resolver result */
77 static void *resolve_pagein(const char *addr
, void *unused_context
)
79 static VSTRING
*query
;
83 * Initialize on the fly.
86 query
= vstring_alloc(10);
91 reply
= (RESOLVE_REPLY
*) mymalloc(sizeof(*reply
));
92 resolve_clnt_init(reply
);
95 * Resolve the address.
97 rewrite_clnt_internal(MAIL_ATTR_RWR_LOCAL
, addr
, query
);
98 resolve_clnt_query(STR(query
), reply
);
99 lowercase(STR(reply
->recipient
)); /* XXX */
104 return ((void *) reply
);
107 /* resolve_pageout - page out an address resolver result */
109 static void resolve_pageout(void *data
, void *unused_context
)
111 RESOLVE_REPLY
*reply
= (RESOLVE_REPLY
*) data
;
113 resolve_clnt_free(reply
);
114 myfree((void *) reply
);
117 /* smtpd_resolve_init - set up global cache */
119 void smtpd_resolve_init(int cache_size
)
125 if (smtpd_resolve_cache
)
126 msg_panic("smtpd_resolve_init: multiple initialization");
129 * Initialize the resolved address cache. Note: the cache persists across
130 * SMTP sessions so we cannot make it dependent on session state.
132 smtpd_resolve_cache
= ctable_create(cache_size
, resolve_pagein
,
133 resolve_pageout
, (void *) 0);
136 /* smtpd_resolve_addr - resolve cached addres */
138 const RESOLVE_REPLY
*smtpd_resolve_addr(const char *addr
)
144 if (smtpd_resolve_cache
== 0)
145 msg_panic("smtpd_resolve_addr: missing initialization");
148 * Reply from the read-through cache.
150 return (const RESOLVE_REPLY
*) ctable_locate(smtpd_resolve_cache
, addr
);