diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 95f2cbc0b0..93f287ca07 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -75,7 +75,7 @@ isc_boolean_t identify = ISC_FALSE, defname = ISC_TRUE, aaonly = ISC_FALSE, tcpmode = ISC_FALSE; -static char *opcodetext[] = { +static const char *opcodetext[] = { "QUERY", "IQUERY", "STATUS", @@ -94,7 +94,7 @@ static char *opcodetext[] = { "RESERVED15" }; -static char *rcodetext[] = { +static const char *rcodetext[] = { "NOERROR", "FORMERR", "SERVFAIL", @@ -494,6 +494,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { FILE *fp = NULL; int bargc; char *bargv[16]; + char bargv0[sizeof("dig")]; int i, n; int adrs[4]; int rc; @@ -1028,15 +1029,23 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { debug ("Batch line %s", batchline); bargc = 1; bargv[bargc] = strtok(batchline, " \t\r\n"); - while ((bargv[bargc] != NULL) && - (bargc < 14 )) { + while ((bargv[bargc] != NULL) && (bargc < 14 )) { bargc++; bargv[bargc] = strtok(NULL, " \t\r\n"); } - bargc--; - bargv[0] = "dig"; - reorder_args(bargc+1, (char**)bargv); - parse_args(ISC_TRUE, bargc+1, (char**)bargv); + + /* + * This silliness (instead of ``bargv[0] = "dig";'') + * dances around the const string issue. If in + * the future the 2nd argument to strncpy() is made + * longer than three characters, don't forget to resize + * bargv0 to accommodate it. + */ + strncpy(bargv0, "dig", sizeof(bargv0)); + bargv[0] = bargv0; + + reorder_args(bargc, (char **)bargv); + parse_args(ISC_TRUE, bargc, (char **)bargv); } } if (lookup_list.head == NULL) { diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index d898ed42e2..67ff0134d6 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -113,7 +113,7 @@ hex_dump(isc_buffer_t *b) { void -fatal(char *format, ...) { +fatal(const char *format, ...) { va_list args; va_start(args, format); @@ -137,7 +137,7 @@ fatal(char *format, ...) { #ifdef DEBUG void -debug(char *format, ...) { +debug(const char *format, ...) { va_list args; va_start(args, format); @@ -147,13 +147,13 @@ debug(char *format, ...) { } #else void -debug(char *format, ...) { +debug(const char *format, ...) { UNUSED(format); } #endif void -check_result(isc_result_t result, char *msg) { +check_result(isc_result_t result, const char *msg) { if (result != ISC_R_SUCCESS) { exitcode = 1; fatal("%s: %s", msg, isc_result_totext(result)); @@ -748,7 +748,7 @@ setup_lookup(dig_lookup_t *lookup) { dig_server_t *serv; dig_query_t *query; isc_region_t r; - isc_textregion_t tr; + isc_constregion_t tr; isc_buffer_t b; char store[MXNAME]; @@ -898,7 +898,7 @@ setup_lookup(dig_lookup_t *lookup) { tr.base=lookup->rttext; tr.length=strlen(lookup->rttext); } - result = dns_rdatatype_fromtext(&rdtype, &tr); + result = dns_rdatatype_fromtext(&rdtype, (isc_textregion_t *)&tr); check_result(result, "dns_rdatatype_fromtext"); if (rdtype == dns_rdatatype_axfr) { lookup->doing_xfr = ISC_TRUE; @@ -914,7 +914,7 @@ setup_lookup(dig_lookup_t *lookup) { tr.base=lookup->rctext; tr.length=strlen(lookup->rctext); } - result = dns_rdataclass_fromtext(&rdclass, &tr); + result = dns_rdataclass_fromtext(&rdclass, (isc_textregion_t *)&tr); check_result(result, "dns_rdataclass_fromtext"); add_type(lookup->sendmsg, lookup->name, rdclass, rdtype); diff --git a/bin/dig/host.c b/bin/dig/host.c index 21786351aa..526af8c63e 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -56,7 +56,7 @@ isc_boolean_t short_form = ISC_TRUE, showallsoa = ISC_FALSE, tcpmode = ISC_FALSE; -static char *opcodetext[] = { +static const char *opcodetext[] = { "QUERY", "IQUERY", "STATUS", @@ -75,7 +75,7 @@ static char *opcodetext[] = { "RESERVED15" }; -static char *rcodetext[] = { +static const char *rcodetext[] = { "NOERROR", "FORMERR", "SERVFAIL", @@ -95,7 +95,7 @@ static char *rcodetext[] = { "BADVERS" }; -static char *rtypetext[] = { +static const char *rtypetext[] = { "zero", /* 0 */ "has address", /* 1 */ "name server", /* 2 */ @@ -251,7 +251,7 @@ trying(int frmsize, char *frm, dig_lookup_t *lookup) { } static void -say_message(dns_name_t *name, char *msg, dns_rdata_t *rdata, +say_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata, dig_query_t *query) { isc_buffer_t *b = NULL, *b2 = NULL; @@ -280,8 +280,9 @@ say_message(dns_name_t *name, char *msg, dns_rdata_t *rdata, static isc_result_t -printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, - isc_boolean_t headers, dig_query_t *query) +printsection(dns_message_t *msg, dns_section_t sectionid, + const char *section_name, isc_boolean_t headers, + dig_query_t *query) { dns_name_t *name, *print_name; dns_rdataset_t *rdataset; @@ -293,7 +294,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, char t[4096]; isc_boolean_t first; isc_boolean_t no_rdata; - char *rtt; + const char *rtt; if (sectionid == DNS_SECTION_QUESTION) no_rdata = ISC_TRUE; @@ -349,11 +350,11 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, else if (rdata.type == 250) rtt = "signature"; else - rtt="unknown"; + rtt = "unknown"; say_message(print_name, rtt, &rdata, query); - loopresult = dns_rdataset_next( - rdataset); + loopresult = + dns_rdataset_next(rdataset); } } } @@ -378,7 +379,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, static isc_result_t printrdata(dns_message_t *msg, dns_rdataset_t *rdataset, dns_name_t *owner, - char *set_name, isc_boolean_t headers) + const char *set_name, isc_boolean_t headers) { isc_buffer_t target; isc_result_t result; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 6d9b061d5f..212f382905 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -133,19 +133,21 @@ struct dig_searchlist { ISC_LINK(dig_searchlist_t) link; }; -/* Routines in dighost.c */ +/* + * Routines in dighost.c. + */ void get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr); void -fatal(char *format, ...) ; +fatal(const char *format, ...); void -debug(char *format, ...) ; +debug(const char *format, ...); void -check_result(isc_result_t result, char *msg); +check_result(isc_result_t result, const char *msg); isc_boolean_t -isclass(char *text) ; +isclass(char *text); isc_boolean_t -istype(char *text) ; +istype(char *text); void setup_lookup(dig_lookup_t *lookup); void @@ -162,13 +164,15 @@ void setup_system(void); void free_lists(int exitcode); -dig_lookup_t -*requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers); +dig_lookup_t * +requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers); -/* Routines needed in dig.c and host.c */ +/* + * Routines needed in dig.c and host.c. + */ isc_result_t -printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) ; +printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers); void received(int bytes, int frmsize, char *frm, dig_query_t *query); void diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index e072a3a7ef..d15be12090 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. */ -/* $Id: dnssec-keygen.c,v 1.28 2000/06/01 02:32:12 bwelling Exp $ */ +/* $Id: dnssec-keygen.c,v 1.29 2000/06/01 18:49:16 tale Exp $ */ #include @@ -42,7 +42,7 @@ #define MAX_RSA 2048 /* XXX ogud update this when rsa library is updated */ -char *program = "dnssec-keygen"; +const char *program = "dnssec-keygen"; int verbose; static isc_boolean_t diff --git a/bin/dnssec/dnssec-makekeyset.c b/bin/dnssec/dnssec-makekeyset.c index e68fa07849..1dc2a3e815 100644 --- a/bin/dnssec/dnssec-makekeyset.c +++ b/bin/dnssec/dnssec-makekeyset.c @@ -41,7 +41,7 @@ #define BUFSIZE 2048 -char *program = "dnssec-makekeyset"; +const char *program = "dnssec-makekeyset"; int verbose; typedef struct keynode keynode_t; @@ -62,23 +62,23 @@ static isc_stdtime_t strtotime(char *str, isc_int64_t now, isc_int64_t base) { isc_int64_t val, offset; isc_result_t result; - char *endp = ""; + char *endp; if (str[0] == '+') { offset = strtol(str + 1, &endp, 0); + if (*endp != '\0') + fatal("time value %s is invalid", str); val = base + offset; - } - else if (strncmp(str, "now+", 4) == 0) { + } else if (strncmp(str, "now+", 4) == 0) { offset = strtol(str + 4, &endp, 0); + if (*endp != '\0') + fatal("time value %s is invalid", str); val = now + offset; - } - else { + } else { result = dns_time64_fromtext(str, &val); if (result != ISC_R_SUCCESS) fatal("time %s must be numeric", str); } - if (*endp != '\0') - fatal("time value %s is invalid", str); return ((isc_stdtime_t) val); } diff --git a/bin/dnssec/dnssec-signkey.c b/bin/dnssec/dnssec-signkey.c index 0e884a9e27..00b8738755 100644 --- a/bin/dnssec/dnssec-signkey.c +++ b/bin/dnssec/dnssec-signkey.c @@ -38,7 +38,7 @@ #include "dnssectool.h" -char *program = "dnssec-signkey"; +const char *program = "dnssec-signkey"; int verbose; #define BUFSIZE 2048 diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 2becc554a1..fb61ac6bd7 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -45,7 +45,7 @@ #include "dnssectool.h" -char *program = "dnssec-signzone"; +const char *program = "dnssec-signzone"; int verbose; /*#define USE_ZONESTATUS*/ @@ -1141,23 +1141,23 @@ static isc_stdtime_t strtotime(char *str, isc_int64_t now, isc_int64_t base) { isc_int64_t val, offset; isc_result_t result; - char *endp = ""; + char *endp; if (str[0] == '+') { offset = strtol(str + 1, &endp, 0); + if (*endp != '\0') + fatal("time value %s is invalid", str); val = base + offset; - } - else if (strncmp(str, "now+", 4) == 0) { + } else if (strncmp(str, "now+", 4) == 0) { offset = strtol(str + 4, &endp, 0); + if (*endp != '\0') + fatal("time value %s is invalid", str); val = now + offset; - } - else { + } else { result = dns_time64_fromtext(str, &val); if (result != ISC_R_SUCCESS) fatal("time %s must be numeric", str); } - if (*endp != '\0') - fatal("time value %s is invalid", str); return ((isc_stdtime_t) val); } diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index eedddb4cc5..0a7404ca27 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -32,10 +32,10 @@ #include "dnssectool.h" extern int verbose; -extern char *program; +extern const char *program; void -fatal(char *format, ...) { +fatal(const char *format, ...) { va_list args; fprintf(stderr, "%s: ", program); @@ -47,7 +47,7 @@ fatal(char *format, ...) { } void -check_result(isc_result_t result, char *message) { +check_result(isc_result_t result, const char *message) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "%s: %s: %s\n", program, message, isc_result_totext(result)); @@ -140,8 +140,8 @@ setup_logging(int verbose, isc_mem_t *mctx, isc_log_t **logp) { dns_log_init(log); dns_log_setcontext(log); - isc_log_settag(logconfig, program); - + RUNTIME_CHECK(isc_log_settag(logconfig, program) == ISC_R_SUCCESS); + /* * Set up a channel similar to default_stderr except: * - the logging level is passed in diff --git a/bin/dnssec/dnssectool.h b/bin/dnssec/dnssectool.h index 671eaf132c..7417bea930 100644 --- a/bin/dnssec/dnssectool.h +++ b/bin/dnssec/dnssectool.h @@ -16,14 +16,27 @@ */ #ifndef DNSSECTOOL_H -#define DNSSECTOOL_H +#define DNSSECTOOL_H 1 -void fatal(char *format, ...); -void check_result(isc_result_t result, char *message); -void vbprintf(int level, const char *fmt, ...); -char *nametostr(dns_name_t *name); -char *typetostr(const dns_rdatatype_t type); -char *algtostr(const dns_secalg_t alg); -void setup_logging(int verbose, isc_mem_t *mctx, isc_log_t **logp); +void +fatal(const char *format, ...); -#endif +void +check_result(isc_result_t result, const char *message); + +void +vbprintf(int level, const char *fmt, ...); + +char * +nametostr(dns_name_t *name); + +char * +typetostr(const dns_rdatatype_t type); + +char * +algtostr(const dns_secalg_t alg); + +void +setup_logging(int verbose, isc_mem_t *mctx, isc_log_t **logp); + +#endif /* DNSSEC_DNSSECTOOL_H */ diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index 1e442b8f25..b308a6b5a9 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -48,7 +48,7 @@ EXTERN dns_dispatchmgr_t * ns_g_dispatchmgr INIT(NULL); EXTERN isc_timermgr_t * ns_g_timermgr INIT(NULL); EXTERN isc_socketmgr_t * ns_g_socketmgr INIT(NULL); EXTERN omapi_object_t * ns_g_omapimgr INIT(NULL); -EXTERN char * ns_g_version INIT(VERSION); +EXTERN const char * ns_g_version INIT(VERSION); EXTERN in_port_t ns_g_port INIT(53); EXTERN ns_server_t * ns_g_server INIT(NULL); @@ -75,7 +75,7 @@ EXTERN const char * ns_g_chrootdir INIT(NULL); EXTERN isc_boolean_t ns_g_foreground INIT(ISC_FALSE); EXTERN isc_boolean_t ns_g_logstderr INIT(ISC_FALSE); -EXTERN char * ns_g_defaultpidfile INIT(NS_LOCALSTATEDIR +EXTERN const char * ns_g_defaultpidfile INIT(NS_LOCALSTATEDIR "/run/named.pid"); EXTERN const char * ns_g_username INIT(NULL); diff --git a/bin/named/interfacemgr.c b/bin/named/interfacemgr.c index 28999b127d..46c2597895 100644 --- a/bin/named/interfacemgr.c +++ b/bin/named/interfacemgr.c @@ -165,7 +165,7 @@ ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) { static isc_result_t ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, - char *name, ns_interface_t **ifpret) + const char *name, ns_interface_t **ifpret) { ns_interface_t *ifp; isc_result_t result; @@ -322,7 +322,7 @@ ns_interface_accepttcp(ns_interface_t *ifp) { static isc_result_t ns_interface_setup(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, - char *name, ns_interface_t **ifpret) + const char *name, ns_interface_t **ifpret) { isc_result_t result; ns_interface_t *ifp = NULL; diff --git a/bin/named/logconf.c b/bin/named/logconf.c index e349a1a016..71f4d2898a 100644 --- a/bin/named/logconf.c +++ b/bin/named/logconf.c @@ -70,7 +70,7 @@ channel_fromconf(dns_c_logchan_t *cchan, isc_logconfig_t *lctx) { isc_result_t result; isc_logdestination_t dest; unsigned int type; - int flags = 0; + unsigned int flags = 0; int level; type = ISC_LOG_TONULL; diff --git a/bin/named/main.c b/bin/named/main.c index fc2be1f55b..cc3c8c801d 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -43,8 +43,8 @@ #include #include -static isc_boolean_t want_stats = ISC_FALSE; -static char * program_name = "named"; +static isc_boolean_t want_stats = ISC_FALSE; +static const char * program_name = "named"; void ns_main_earlyfatal(const char *format, ...) { @@ -70,7 +70,9 @@ ns_main_earlyfatal(const char *format, ...) { } static void -assertion_failed(char *file, int line, isc_assertiontype_t type, char *cond) { +assertion_failed(const char *file, int line, isc_assertiontype_t type, + const char *cond) +{ /* * Handle assertion failures. */ @@ -101,7 +103,9 @@ assertion_failed(char *file, int line, isc_assertiontype_t type, char *cond) { } static void -library_fatal_error(char *file, int line, char *format, va_list args) { +library_fatal_error(const char *file, int line, const char *format, + va_list args) +{ /* * Handle isc_error_fatal() calls from our libraries. */ @@ -135,7 +139,9 @@ library_fatal_error(char *file, int line, char *format, va_list args) { } static void -library_unexpected_error(char *file, int line, char *format, va_list args) { +library_unexpected_error(const char *file, int line, const char *format, + va_list args) +{ /* * Handle isc_error_unexpected() calls from our libraries. */ diff --git a/bin/named/query.c b/bin/named/query.c index fbc150b151..6819fca299 100644 --- a/bin/named/query.c +++ b/bin/named/query.c @@ -718,7 +718,7 @@ query_isduplicate(ns_client_t *client, dns_name_t *name, } static isc_result_t -query_addadditional(void *arg, dns_name_t *name, dns_rdatatype_t qtype) { +query_addadditional(void *arg, dns_name_t *name, int qtype) { ns_client_t *client = arg; isc_result_t result, eresult; dns_dbnode_t *node, *znode; diff --git a/bin/named/server.c b/bin/named/server.c index e565b9ed95..53a0d537be 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -86,8 +86,11 @@ typedef struct { dns_aclconfctx_t *aclconf; } ns_load_t; -static void fatal(char *msg, isc_result_t result); -static void ns_server_reload(isc_task_t *task, isc_event_t *event); +static void +fatal(const char *msg, isc_result_t result); + +static void +ns_server_reload(isc_task_t *task, isc_event_t *event); static isc_result_t ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx, @@ -705,7 +708,13 @@ create_version_view(dns_c_ctx_t *cctx, dns_zonemgr_t *zmgr, dns_view_t **viewp) result = dns_c_ctx_getversion(cctx, &versiontext); if (result != ISC_R_SUCCESS) - versiontext = ns_g_version; + /* + * Removing the const qualifier from ns_g_version is ok + * because the resulting string is not modified, only + * copied into a new buffer. + */ + DE_CONST(ns_g_version, versiontext); + len = strlen(versiontext); if (len > 255) len = 255; /* Silently truncate. */ @@ -789,7 +798,7 @@ find_or_create_view(dns_c_view_t *cview, dns_viewlist_t *viewlist, dns_view_t **viewp) { isc_result_t result; - char *viewname; + const char *viewname; dns_rdataclass_t viewclass; dns_view_t *view = NULL; @@ -1325,11 +1334,11 @@ load_configuration(const char *filename, ns_server_t *server, "now using logging configuration from " "config file"); - if (dns_c_ctx_getpidfilename(cctx, &pidfilename) == - ISC_R_NOTFOUND) - pidfilename = ns_g_defaultpidfile; - ns_os_writepidfile(pidfilename); - + if (dns_c_ctx_getpidfilename(cctx, &pidfilename) != ISC_R_NOTFOUND) + ns_os_writepidfile(pidfilename); + else + ns_os_writepidfile(ns_g_defaultpidfile); + dns_aclconfctx_destroy(&aclconfctx); dns_c_ctx_delete(&cctx); @@ -1566,7 +1575,7 @@ ns_server_destroy(ns_server_t **serverp) { } static void -fatal(char *msg, isc_result_t result) { +fatal(const char *msg, isc_result_t result) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, ISC_LOG_CRITICAL, "%s: %s", msg, isc_result_totext(result)); diff --git a/bin/named/xfrout.c b/bin/named/xfrout.c index a22ddd4779..38b264d120 100644 --- a/bin/named/xfrout.c +++ b/bin/named/xfrout.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: xfrout.c,v 1.64 2000/05/30 23:14:48 bwelling Exp $ */ +/* $Id: xfrout.c,v 1.65 2000/06/01 18:44:26 tale Exp $ */ #include @@ -766,7 +766,7 @@ static void xfrout_senddone(isc_task_t *task, isc_event_t *event); static void -xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, char *msg); +xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, const char *msg); static void xfrout_maybe_destroy(xfrout_ctx_t *xfr); @@ -803,7 +803,7 @@ ns_xfr_start(ns_client_t *client, dns_rdatatype_t reqtype) { dns_rdataset_t *soa_rdataset; dns_rdata_t soa_rdata; isc_boolean_t have_soa = ISC_FALSE; - char *mnemonic = NULL; + const char *mnemonic = NULL; isc_mem_t *mctx = client->mctx; dns_message_t *request = client->message; xfrout_ctx_t *xfr = NULL; @@ -1469,7 +1469,7 @@ xfrout_senddone(isc_task_t *task, isc_event_t *event) { } static void -xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, char *msg) { +xfrout_fail(xfrout_ctx_t *xfr, isc_result_t result, const char *msg) { xfr->shuttingdown = ISC_TRUE; xfrout_log(xfr, ISC_LOG_ERROR, "%s: %s", msg, isc_result_totext(result));