From 1dc92d5af0dddcee977aab6da545951c051b2c58 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Thu, 20 Nov 2014 20:16:58 +0000 Subject: Const-ification --- src/src/acl.c | 2 +- src/src/dns.c | 35 ++++++++++++++++++----------------- src/src/exim.c | 7 ++++--- src/src/functions.h | 14 +++++++------- src/src/local_scan.h | 2 +- src/src/lookups/dnsdb.c | 2 +- src/src/match.c | 19 ++++++++++--------- src/src/string.c | 4 ++-- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/src/acl.c b/src/src/acl.c index fe1e254bd..4ee70bf31 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -1550,7 +1550,7 @@ for (rr = dns_next_rr(&dnsa, &dnss, RESET_ANSWERS); assertion: legitimate SMTP clients are all explicitly authorized with CSA SRV records of their own. */ - if (found != domain) + if (Ustrcmp(found, domain) != 0) { if (port & 1) return t->data.val = CSA_FAIL_EXPLICIT; diff --git a/src/src/dns.c b/src/src/dns.c index 3d047abba..66633f741 100644 --- a/src/src/dns.c +++ b/src/src/dns.c @@ -46,7 +46,7 @@ Returns: length of returned data, or -1 on error (h_errno set) */ static int -fakens_search(uschar *domain, int type, uschar *answerptr, int size) +fakens_search(const uschar *domain, int type, uschar *answerptr, int size) { int len = Ustrlen(domain); int asize = size; /* Locally modified */ @@ -443,7 +443,7 @@ Returns: bool indicating presence of AD bit */ BOOL -dns_is_secure(dns_answer *dnsa) +dns_is_secure(const dns_answer *dnsa) { #ifdef DISABLE_DNSSEC DEBUG(D_dns) @@ -510,7 +510,7 @@ Returns: the return code */ static int -dns_return(uschar *name, int type, int rc) +dns_return(const uschar * name, int type, int rc) { res_state resp = os_get_dns_resolver_res(); tree_node *node = store_get_perm(sizeof(tree_node) + 290); @@ -549,7 +549,7 @@ Returns: DNS_SUCCEED successful lookup */ int -dns_basic_lookup(dns_answer *dnsa, uschar *name, int type) +dns_basic_lookup(dns_answer *dnsa, const uschar *name, int type) { #ifndef STAND_ALONE int rc = -1; @@ -597,7 +597,7 @@ For SRV records, we omit the initial _smtp._tcp. components at the start. */ if (check_dns_names_pattern[0] != 0 && type != T_PTR && type != T_TXT) { - uschar *checkname = name; + const uschar *checkname = name; int ovector[3*(EXPAND_MAXN+1)]; if (regex_check_dns_names == NULL) @@ -613,7 +613,7 @@ if (check_dns_names_pattern[0] != 0 && type != T_PTR && type != T_TXT) while (*checkname++ != '.'); } - if (pcre_exec(regex_check_dns_names, NULL, CS checkname, Ustrlen(checkname), + if (pcre_exec(regex_check_dns_names, NULL, CCS checkname, Ustrlen(checkname), 0, PCRE_EOPT, ovector, sizeof(ovector)/sizeof(int)) < 0) { DEBUG(D_dns) @@ -650,7 +650,7 @@ domains, and interfaces to a fake nameserver for certain special zones. */ if (running_in_test_harness) dnsa->answerlen = fakens_search(name, type, dnsa->answer, MAXPACKET); else - dnsa->answerlen = res_search(CS name, C_IN, type, dnsa->answer, MAXPACKET); + dnsa->answerlen = res_search(CCS name, C_IN, type, dnsa->answer, MAXPACKET); if (dnsa->answerlen > MAXPACKET) { @@ -671,9 +671,9 @@ if (dnsa->answerlen < 0) switch (h_errno) name, dns_text_type(type)); /* Cut this out for various test programs */ - #ifndef STAND_ALONE +#ifndef STAND_ALONE save = deliver_domain; - deliver_domain = name; /* set $domain */ + deliver_domain = string_copy(name); /* set $domain */ rc = match_isinlist(name, &dns_again_means_nonexist, 0, NULL, NULL, MCL_DOMAIN, TRUE, NULL); deliver_domain = save; @@ -686,9 +686,9 @@ if (dnsa->answerlen < 0) switch (h_errno) "DNS_NOMATCH\n", name); return dns_return(name, type, DNS_NOMATCH); - #else /* For stand-alone tests */ +#else /* For stand-alone tests */ return dns_return(name, type, DNS_AGAIN); - #endif +#endif case NO_RECOVERY: DEBUG(D_dns) debug_printf("DNS lookup of %s (%s) gave NO_RECOVERY\n" @@ -749,10 +749,11 @@ Returns: DNS_SUCCEED successful lookup */ int -dns_lookup(dns_answer *dnsa, uschar *name, int type, uschar **fully_qualified_name) +dns_lookup(dns_answer *dnsa, const uschar *name, int type, + uschar **fully_qualified_name) { int i; -uschar *orig_name = name; +const uschar *orig_name = name; /* Loop to follow CNAME chains so far, but no further... */ @@ -816,7 +817,7 @@ for (i = 0; i < 10; i++) if (cname_rr.data == NULL) return DNS_FAIL; datalen = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen, - cname_rr.data, (DN_EXPAND_ARG4_TYPE)data, 256); + cname_rr.data, (DN_EXPAND_ARG4_TYPE)data, sizeof(data)); if (datalen < 0) return DNS_FAIL; name = data; @@ -858,7 +859,7 @@ Returns: DNS_SUCCEED successful lookup */ int -dns_special_lookup(dns_answer *dnsa, uschar *name, int type, +dns_special_lookup(dns_answer *dnsa, const uschar *name, int type, uschar **fully_qualified_name) { if (type >= 0) return dns_lookup(dnsa, name, type, fully_qualified_name); @@ -872,7 +873,7 @@ root servers. */ if (type == T_ZNS) { - uschar *d = name; + const uschar *d = name; while (d != 0) { int rc = dns_lookup(dnsa, d, T_NS, fully_qualified_name); @@ -905,7 +906,7 @@ if (type == T_CSA) rc = dns_lookup(dnsa, srvname, T_SRV, NULL); if (rc == DNS_SUCCEED || rc == DNS_AGAIN) { - if (rc == DNS_SUCCEED) *fully_qualified_name = name; + if (rc == DNS_SUCCEED) *fully_qualified_name = string_copy(name); return rc; } diff --git a/src/src/exim.c b/src/src/exim.c index 32139bd33..3f7473776 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -131,10 +131,11 @@ Returns: TRUE or FALSE */ BOOL -regex_match_and_setup(const pcre *re, uschar *subject, int options, int setup) +regex_match_and_setup(const pcre *re, const uschar *subject, int options, int setup) { int ovector[3*(EXPAND_MAXN+1)]; -int n = pcre_exec(re, NULL, CS subject, Ustrlen(subject), 0, +uschar * s = string_copy(subject); /* de-constifying */ +int n = pcre_exec(re, NULL, CS s, Ustrlen(s), 0, PCRE_EOPT | options, ovector, sizeof(ovector)/sizeof(int)); BOOL yield = n >= 0; if (n == 0) n = EXPAND_MAXN + 1; @@ -144,7 +145,7 @@ if (yield) expand_nmax = (setup < 0)? 0 : setup + 1; for (nn = (setup < 0)? 0 : 2; nn < n*2; nn += 2) { - expand_nstring[expand_nmax] = subject + ovector[nn]; + expand_nstring[expand_nmax] = s + ovector[nn]; expand_nlength[expand_nmax++] = ovector[nn+1] - ovector[nn]; } expand_nmax--; diff --git a/src/src/functions.h b/src/src/functions.h index 2074bb2f1..f7d5449bd 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -146,10 +146,10 @@ extern BOOL dkim_transport_write_message(address_item *, int, int, extern dns_address *dns_address_from_rr(dns_answer *, dns_record *); extern void dns_build_reverse(uschar *, uschar *); extern void dns_init(BOOL, BOOL, BOOL); -extern int dns_basic_lookup(dns_answer *, uschar *, int); -extern BOOL dns_is_secure(dns_answer *); -extern int dns_lookup(dns_answer *, uschar *, int, uschar **); -extern int dns_special_lookup(dns_answer *, uschar *, int, uschar **); +extern int dns_basic_lookup(dns_answer *, const uschar *, int); +extern BOOL dns_is_secure(const dns_answer *); +extern int dns_lookup(dns_answer *, const uschar *, int, uschar **); +extern int dns_special_lookup(dns_answer *, const uschar *, int, uschar **); extern dns_record *dns_next_rr(dns_answer *, dns_scan *, int); extern uschar *dns_text_type(int); extern void dscp_list_to_stream(FILE *); @@ -225,7 +225,7 @@ extern int match_address_list(uschar *, BOOL, BOOL, uschar **, extern int match_check_list(uschar **, int, tree_node **, unsigned int **, int(*)(void *, uschar *, uschar **, uschar **), void *, int, const uschar *, uschar **); -extern int match_isinlist(uschar *, uschar **, int, tree_node **, +extern int match_isinlist(const uschar *, uschar **, int, tree_node **, unsigned int *, int, BOOL, uschar **); extern int match_check_string(uschar *, uschar *, int, BOOL, BOOL, BOOL, uschar **); @@ -302,7 +302,7 @@ extern void receive_swallow_smtp(void); #ifdef WITH_CONTENT_SCAN extern int regex(uschar **); #endif -extern BOOL regex_match_and_setup(const pcre *, uschar *, int, int); +extern BOOL regex_match_and_setup(const pcre *, const uschar *, int, int); extern const pcre *regex_must_compile(uschar *, BOOL, BOOL); extern void retry_add_item(address_item *, uschar *, int); extern BOOL retry_check_address(uschar *, host_item *, uschar *, BOOL, @@ -392,7 +392,7 @@ extern uschar *string_base62(unsigned long int); extern uschar *string_cat(uschar *, int *, int *, const uschar *, int); extern uschar *string_copy_dnsdomain(uschar *); extern uschar *string_copy_malloc(uschar *); -extern uschar *string_copylc(uschar *); +extern uschar *string_copylc(const uschar *); extern uschar *string_copynlc(uschar *, int); extern uschar *string_dequote(uschar **); extern BOOL string_format(uschar *, int, const char *, ...) ALMOST_PRINTF(3,4); diff --git a/src/src/local_scan.h b/src/src/local_scan.h index 770348a9b..6df601af4 100644 --- a/src/src/local_scan.h +++ b/src/src/local_scan.h @@ -191,7 +191,7 @@ extern int smtp_fflush(void); extern void smtp_printf(const char *, ...) PRINTF_FUNCTION(1,2); extern void smtp_vprintf(const char *, va_list); extern uschar *string_copy(const uschar *); -extern uschar *string_copyn(uschar *, int); +extern uschar *string_copyn(const uschar *, int); extern uschar *string_sprintf(const char *, ...) ALMOST_PRINTF(1,2); /* End of local_scan.h */ diff --git a/src/src/lookups/dnsdb.c b/src/src/lookups/dnsdb.c index 5a82b340d..7c2d1a540 100644 --- a/src/src/lookups/dnsdb.c +++ b/src/src/lookups/dnsdb.c @@ -498,7 +498,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer))) the subdomain assertions in the port field, else analyse the direct authorization status in the weight field. */ - if (found != domain) + if (Ustrcmp(found, domain) != 0) { if (port & 1) *s = 'X'; /* explicit authorization required */ else *s = '?'; /* no subdomain assertions here */ diff --git a/src/src/match.c b/src/src/match.c index 604157da3..97c4ea045 100644 --- a/src/src/match.c +++ b/src/src/match.c @@ -15,8 +15,8 @@ strings, domains, and local parts. */ typedef struct check_string_block { - uschar *origsubject; /* caseful; keep these two first, in */ - uschar *subject; /* step with the block below */ + const uschar *origsubject; /* caseful; keep these two first, in */ + const uschar *subject; /* step with the block below */ int expand_setup; BOOL use_partial; BOOL caseless; @@ -94,7 +94,7 @@ Returns: OK if matched static int check_string(void *arg, uschar *pattern, uschar **valueptr, uschar **error) { -check_string_block *cb = (check_string_block *)arg; +const check_string_block *cb = arg; int search_type, partial, affixlen, starflags; int expand_setup = cb->expand_setup; uschar *affix; @@ -111,7 +111,7 @@ if (valueptr != NULL) *valueptr = NULL; /* For non-lookup matches */ it works if the pattern uses (?-i) to turn off case-independence, overriding "caseless". */ -s = (pattern[0] == '^')? cb->origsubject : cb->subject; +s = string_copy(pattern[0] == '^' ? cb->origsubject : cb->subject); /* If required to set up $0, initialize the data but don't turn on by setting expand_nmax until the match is assured. */ @@ -131,7 +131,7 @@ if (pattern[0] == '^') { const pcre *re = regex_must_compile(pattern, cb->caseless, FALSE); return ((expand_setup < 0)? - pcre_exec(re, NULL, CS s, Ustrlen(s), 0, PCRE_EOPT, NULL, 0) >= 0 + pcre_exec(re, NULL, CCS s, Ustrlen(s), 0, PCRE_EOPT, NULL, 0) >= 0 : regex_match_and_setup(re, s, 0, expand_setup) )? @@ -366,7 +366,7 @@ Arguments: type MCL_STRING, MCL_DOMAIN, MCL_HOST, MCL_ADDRESS, or MCL_LOCALPART */ -static uschar * +static const uschar * get_check_key(void *arg, int type) { switch(type) @@ -489,7 +489,7 @@ else if (type == MCL_DOMAIN && deliver_domain == NULL) { check_string_block *cb = (check_string_block *)arg; - deliver_domain = cb->subject; + deliver_domain = string_copy(cb->subject); list = expand_string(*listptr); deliver_domain = NULL; } @@ -701,7 +701,7 @@ while ((sss = string_nextinlist(&list, &sep, buffer, sizeof(buffer))) != NULL) cached = US" - cached"; if (valueptr != NULL) { - uschar *key = get_check_key(arg, type); + const uschar *key = get_check_key(arg, type); namedlist_cacheblock *p; for (p = nb->cache_data; p != NULL; p = p->next) { @@ -952,7 +952,8 @@ Returns: OK if matched a non-negated item */ int -match_isinlist(uschar *s, uschar **listptr, int sep, tree_node **anchorptr, +match_isinlist(const uschar *s, uschar **listptr, int sep, + tree_node **anchorptr, unsigned int *cache_bits, int type, BOOL caseless, uschar **valueptr) { unsigned int *local_cache_bits = cache_bits; diff --git a/src/src/string.c b/src/src/string.c index 775709dc6..71c7f6f8e 100644 --- a/src/src/string.c +++ b/src/src/string.c @@ -457,7 +457,7 @@ Returns: copy of string in new store, with letters lowercased */ uschar * -string_copylc(uschar *s) +string_copylc(const uschar *s) { uschar *ss = store_get(Ustrlen(s) + 1); uschar *p = ss; @@ -483,7 +483,7 @@ Returns: copy of string in new store */ uschar * -string_copyn(uschar *s, int n) +string_copyn(const uschar *s, int n) { uschar *ss = store_get(n + 1); Ustrncpy(ss, s, n); -- cgit v1.2.3