9 /* #include <cleanup.h>
11 /* int cleanup_map11_external(state, addr, maps, propagate)
12 /* CLEANUP_STATE *state;
17 /* int cleanup_map11_internal(state, addr, maps, propagate)
18 /* CLEANUP_STATE *state;
23 /* int cleanup_map11_tree(state, tree, maps, propagate)
24 /* CLEANUP_STATE *state;
29 /* This module performs one-to-one map lookups.
31 /* If an address has a mapping, the lookup result is
32 /* subjected to another iteration of rewriting and mapping.
33 /* Recursion continues until an address maps onto itself,
34 /* or until an unreasonable recursion level is reached.
35 /* An unmatched address extension is propagated when
36 /* \fIpropagate\fR is non-zero.
37 /* These functions return non-zero when the address was changed.
39 /* cleanup_map11_external() looks up the external (quoted) string
40 /* form of an address in the maps specified via the \fImaps\fR argument.
42 /* cleanup_map11_internal() is a wrapper around the
43 /* cleanup_map11_external() routine that transforms from
44 /* internal (quoted) string form to external form and back.
46 /* cleanup_map11_tree() is a wrapper around the
47 /* cleanup_map11_external() routine that transforms from
48 /* internal parse tree form to external form and back.
50 /* Recoverable errors: the global \fIcleanup_errs\fR flag is updated.
52 /* mail_addr_find(3) address lookups
53 /* mail_addr_map(3) address mappings
57 /* The Secure Mailer license must be distributed with this software.
60 /* IBM T.J. Watson Research
62 /* Yorktown Heights, NY 10598, USA
70 #ifdef STRCASECMP_IN_STRINGS_H
74 /* Utility library. */
83 #include <cleanup_user.h>
84 #include <mail_addr_map.h>
85 #include <quote_822_local.h>
87 /* Application-specific. */
91 #define STR vstring_str
92 #define MAX_RECURSION 10
94 /* cleanup_map11_external - one-to-one table lookups */
96 int cleanup_map11_external(CLEANUP_STATE
*state
, VSTRING
*addr
,
97 MAPS
*maps
, int propagate
)
106 * Produce sensible output even in the face of a recoverable error. This
107 * simplifies error recovery considerably because we can do delayed error
108 * checking in one place, instead of having error handling code all over
111 for (count
= 0; count
< MAX_RECURSION
; count
++) {
112 if ((new_addr
= mail_addr_map(maps
, STR(addr
), propagate
)) != 0) {
113 if (new_addr
->argc
> 1)
114 msg_warn("%s: multi-valued %s entry for %s",
115 state
->queue_id
, maps
->title
, STR(addr
));
116 saved_addr
= mystrdup(STR(addr
));
117 did_rewrite
|= strcmp(new_addr
->argv
[0], STR(addr
));
118 vstring_strcpy(addr
, new_addr
->argv
[0]);
119 expand_to_self
= !strcasecmp(saved_addr
, STR(addr
));
123 return (did_rewrite
);
124 } else if (dict_errno
!= 0) {
125 msg_warn("%s: %s map lookup problem for %s",
126 state
->queue_id
, maps
->title
, STR(addr
));
127 state
->errs
|= CLEANUP_STAT_WRITE
;
128 return (did_rewrite
);
130 return (did_rewrite
);
133 msg_warn("%s: unreasonable %s map nesting for %s",
134 state
->queue_id
, maps
->title
, STR(addr
));
135 return (did_rewrite
);
138 /* cleanup_map11_tree - rewrite address node */
140 int cleanup_map11_tree(CLEANUP_STATE
*state
, TOK822
*tree
,
141 MAPS
*maps
, int propagate
)
143 VSTRING
*temp
= vstring_alloc(100);
147 * Produce sensible output even in the face of a recoverable error. This
148 * simplifies error recovery considerably because we can do delayed error
149 * checking in one place, instead of having error handling code all over
152 tok822_externalize(temp
, tree
->head
, TOK822_STR_DEFL
);
153 did_rewrite
= cleanup_map11_external(state
, temp
, maps
, propagate
);
154 tok822_free_tree(tree
->head
);
155 tree
->head
= tok822_scan(STR(temp
), &tree
->tail
);
157 return (did_rewrite
);
160 /* cleanup_map11_internal - rewrite address internal form */
162 int cleanup_map11_internal(CLEANUP_STATE
*state
, VSTRING
*addr
,
163 MAPS
*maps
, int propagate
)
165 VSTRING
*temp
= vstring_alloc(100);
169 * Produce sensible output even in the face of a recoverable error. This
170 * simplifies error recovery considerably because we can do delayed error
171 * checking in one place, instead of having error handling code all over
174 quote_822_local(temp
, STR(addr
));
175 did_rewrite
= cleanup_map11_external(state
, temp
, maps
, propagate
);
176 unquote_822_local(addr
, STR(temp
));
178 return (did_rewrite
);