1 /* $NetBSD: cleanup_rewrite.c,v 1.1.1.1 2009/06/23 10:08:43 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* cleanup_rewrite 3 6 /* SUMMARY 7 /* address canonicalization 8 /* SYNOPSIS 9 /* #include <cleanup.h> 10 /* 11 /* int cleanup_rewrite_external(context_name, result, addr) 12 /* const char *context; 13 /* VSTRING *result; 14 /* const char *addr; 15 /* 16 /* int cleanup_rewrite_internal(context_name, result, addr) 17 /* const char *context; 18 /* VSTRING *result; 19 /* const char *addr; 20 /* 21 /* int cleanup_rewrite_tree(context_name, tree) 22 /* const char *context; 23 /* TOK822 *tree; 24 /* DESCRIPTION 25 /* This module rewrites addresses to canonical form, adding missing 26 /* domains and stripping source routes etc., and performs 27 /* \fIcanonical\fR map lookups to map addresses to official form. 28 /* These functions return non-zero when the address was changed. 29 /* 30 /* cleanup_rewrite_init() performs one-time initialization. 31 /* 32 /* cleanup_rewrite_external() rewrites the external (quoted) string 33 /* form of an address. 34 /* 35 /* cleanup_rewrite_internal() is a wrapper around the 36 /* cleanup_rewrite_external() routine that transforms from 37 /* internal (quoted) string form to external form and back. 38 /* 39 /* cleanup_rewrite_tree() is a wrapper around the 40 /* cleanup_rewrite_external() routine that transforms from 41 /* internal parse tree form to external form and back. 42 /* 43 /* Arguments: 44 /* .IP context_name 45 /* The name of an address rewriting context that supplies 46 /* the equivalents of myorigin and mydomain. 47 /* .IP result 48 /* Result buffer. 49 /* .IP addr 50 /* Input buffer. 51 /* DIAGNOSTICS 52 /* LICENSE 53 /* .ad 54 /* .fi 55 /* The Secure Mailer license must be distributed with this software. 56 /* AUTHOR(S) 57 /* Wietse Venema 58 /* IBM T.J. Watson Research 59 /* P.O. Box 704 60 /* Yorktown Heights, NY 10598, USA 61 /*--*/ 62 63 /* System library. */ 64 65 #include <sys_defs.h> 66 67 /* Utility library. */ 68 69 #include <msg.h> 70 #include <vstring.h> 71 72 /* Global library. */ 73 74 #include <tok822.h> 75 #include <rewrite_clnt.h> 76 #include <quote_822_local.h> 77 78 /* Application-specific. */ 79 80 #include "cleanup.h" 81 82 #define STR vstring_str 83 84 /* cleanup_rewrite_external - rewrite address external form */ 85 86 int cleanup_rewrite_external(const char *context_name, VSTRING *result, 87 const char *addr) 88 { 89 rewrite_clnt(context_name, addr, result); 90 return (strcmp(STR(result), addr) != 0); 91 } 92 93 /* cleanup_rewrite_tree - rewrite address node */ 94 95 int cleanup_rewrite_tree(const char *context_name, TOK822 *tree) 96 { 97 VSTRING *dst = vstring_alloc(100); 98 VSTRING *src = vstring_alloc(100); 99 int did_rewrite; 100 101 tok822_externalize(src, tree->head, TOK822_STR_DEFL); 102 did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src)); 103 tok822_free_tree(tree->head); 104 tree->head = tok822_scan(STR(dst), &tree->tail); 105 vstring_free(dst); 106 vstring_free(src); 107 return (did_rewrite); 108 } 109 110 /* cleanup_rewrite_internal - rewrite address internal form */ 111 112 int cleanup_rewrite_internal(const char *context_name, 113 VSTRING *result, const char *addr) 114 { 115 VSTRING *dst = vstring_alloc(100); 116 VSTRING *src = vstring_alloc(100); 117 int did_rewrite; 118 119 quote_822_local(src, addr); 120 did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src)); 121 unquote_822_local(result, STR(dst)); 122 vstring_free(dst); 123 vstring_free(src); 124 return (did_rewrite); 125 } 126