]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
style cleanup
authorEvan Hunt <each@isc.org>
Mon, 16 Dec 2019 00:45:17 +0000 (16:45 -0800)
committerEvan Hunt <each@isc.org>
Mon, 13 Jul 2020 19:41:04 +0000 (12:41 -0700)
clean up style in rndc and the control channel in preparation for
changing them to use the new network manager.

bin/named/controlconf.c
bin/rndc/rndc.c
lib/isccc/ccmsg.c

index 6d6e4078d75f7a005624ca6baadc3bbae7888b32..5e3fe4f36e2867fa13ba0d58b6085ccecf14d522 100644 (file)
@@ -198,8 +198,8 @@ maybe_free_connection(controlconnection_t *conn) {
 
 static void
 shutdown_listener(controllistener_t *listener) {
-       controlconnection_t *conn;
-       controlconnection_t *next;
+       controlconnection_t *conn = NULL;
+       controlconnection_t *next = NULL;
 
        if (!listener->exiting) {
                char socktext[ISC_SOCKADDR_FORMATSIZE];
@@ -341,7 +341,7 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
        isc_stdtime_t now;
        isc_buffer_t b;
        isc_region_t r;
-       isc_buffer_t *text;
+       isc_buffer_t *text = NULL;
        isc_result_t result;
        isc_result_t eresult;
        isccc_sexpr_t *_ctrl = NULL;
@@ -573,7 +573,7 @@ control_timeout(isc_task_t *task, isc_event_t *event) {
 
 static isc_result_t
 newconnection(controllistener_t *listener, isc_socket_t *sock) {
-       controlconnection_t *conn;
+       controlconnection_t *conn = NULL;
        isc_interval_t interval;
        isc_result_t result;
 
@@ -631,7 +631,7 @@ static void
 control_newconn(isc_task_t *task, isc_event_t *event) {
        isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event;
        controllistener_t *listener = event->ev_arg;
-       isc_socket_t *sock;
+       isc_socket_t *sock = NULL;
        isc_sockaddr_t peeraddr;
        isc_result_t result;
 
@@ -693,8 +693,8 @@ cleanup:
 
 static void
 controls_shutdown(named_controls_t *controls) {
-       controllistener_t *listener;
-       controllistener_t *next;
+       controllistener_t *listener = NULL;
+       controllistener_t *next = NULL;
 
        for (listener = ISC_LIST_HEAD(controls->listeners); listener != NULL;
             listener = next)
@@ -717,9 +717,9 @@ named_controls_shutdown(named_controls_t *controls) {
 static isc_result_t
 cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname,
                const cfg_obj_t **objp) {
-       const cfg_listelt_t *element;
-       const char *str;
-       const cfg_obj_t *obj;
+       const cfg_listelt_t *element = NULL;
+       const char *str = NULL;
+       const cfg_obj_t *obj = NULL;
 
        for (element = cfg_list_first(keylist); element != NULL;
             element = cfg_list_next(element))
@@ -741,11 +741,11 @@ cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname,
 static void
 controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx,
                       controlkeylist_t *keyids) {
-       const cfg_listelt_t *element;
+       const cfg_listelt_t *element = NULL;
        char *newstr = NULL;
-       const char *str;
-       const cfg_obj_t *obj;
-       controlkey_t *key;
+       const char *str = NULL;
+       const cfg_obj_t *obj = NULL;
+       controlkey_t *key = NULL;
 
        for (element = cfg_list_first(keylist); element != NULL;
             element = cfg_list_next(element))
@@ -767,8 +767,8 @@ controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx,
 static void
 register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist,
              controlkeylist_t *keyids, isc_mem_t *mctx, const char *socktext) {
-       controlkey_t *keyid, *next;
-       const cfg_obj_t *keydef;
+       controlkey_t *keyid = NULL, *next = NULL;
+       const cfg_obj_t *keydef = NULL;
        char secret[1024];
        isc_buffer_t b;
        isc_result_t result;
@@ -801,10 +801,9 @@ register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist,
                        algstr = cfg_obj_asstring(algobj);
                        secretstr = cfg_obj_asstring(secretobj);
 
-                       if (named_config_getkeyalgorithm2(algstr, NULL,
-                                                         &algtype, NULL) !=
-                           ISC_R_SUCCESS)
-                       {
+                       result = named_config_getkeyalgorithm2(algstr, NULL,
+                                                              &algtype, NULL);
+                       if (result != ISC_R_SUCCESS) {
                                cfg_obj_log(control, named_g_lctx,
                                            ISC_LOG_WARNING,
                                            "unsupported algorithm '%s' in "
@@ -841,11 +840,12 @@ register_keys(const cfg_obj_t *control, const cfg_obj_t *keylist,
        }
 }
 
-#define CHECK(x)                             \
-       do {                                 \
-               result = (x);                \
-               if (result != ISC_R_SUCCESS) \
-                       goto cleanup;        \
+#define CHECK(x)                               \
+       do {                                   \
+               result = (x);                  \
+               if (result != ISC_R_SUCCESS) { \
+                       goto cleanup;          \
+               }                              \
        } while (0)
 
 static isc_result_t
@@ -895,9 +895,8 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids) {
        algstr = cfg_obj_asstring(algobj);
        secretstr = cfg_obj_asstring(secretobj);
 
-       if (named_config_getkeyalgorithm2(algstr, NULL, &algtype, NULL) !=
-           ISC_R_SUCCESS)
-       {
+       result = named_config_getkeyalgorithm2(algstr, NULL, &algtype, NULL);
+       if (result != ISC_R_SUCCESS) {
                cfg_obj_log(key, named_g_lctx, ISC_LOG_WARNING,
                            "unsupported algorithm '%s' in "
                            "key '%s' for use with command "
@@ -970,8 +969,8 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
                const cfg_obj_t *control, const cfg_obj_t *config,
                isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx,
                const char *socktext, isc_sockettype_t type) {
-       controllistener_t *listener;
-       const cfg_obj_t *allow;
+       controllistener_t *listener = NULL;
+       const cfg_obj_t *allow = NULL;
        const cfg_obj_t *global_keylist = NULL;
        const cfg_obj_t *control_keylist = NULL;
        dns_acl_t *new_acl = NULL;
@@ -1064,7 +1063,7 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
        }
 
        if (control != NULL) {
-               const cfg_obj_t *readonly;
+               const cfg_obj_t *readonly = NULL;
 
                readonly = cfg_tuple_get(control, "read-only");
                if (!cfg_obj_isvoid(readonly)) {
@@ -1123,35 +1122,25 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
             isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx,
             const char *socktext, isc_sockettype_t type) {
        isc_mem_t *mctx = cp->server->mctx;
-       controllistener_t *listener;
-       const cfg_obj_t *allow;
+       controllistener_t *listener = NULL;
+       const cfg_obj_t *allow = NULL;
        const cfg_obj_t *global_keylist = NULL;
        const cfg_obj_t *control_keylist = NULL;
        dns_acl_t *new_acl = NULL;
        isc_result_t result = ISC_R_SUCCESS;
 
        listener = isc_mem_get(mctx, sizeof(*listener));
-
-       listener->mctx = NULL;
+       *listener = (controllistener_t){ .controls = cp,
+                                        .task = cp->server->task,
+                                        .address = *addr,
+                                        .type = type };
        isc_mem_attach(mctx, &listener->mctx);
-       listener->controls = cp;
-       listener->task = cp->server->task;
-       listener->address = *addr;
-       listener->sock = NULL;
-       listener->listening = false;
-       listener->exiting = false;
-       listener->acl = NULL;
-       listener->type = type;
-       listener->perm = 0;
-       listener->owner = 0;
-       listener->group = 0;
-       listener->readonly = false;
        ISC_LINK_INIT(listener, link);
        ISC_LIST_INIT(listener->keys);
        ISC_LIST_INIT(listener->connections);
 
        /*
-        * Make the acl.
+        * Make the ACL.
         */
        if (control != NULL && type == isc_sockettype_tcp) {
                allow = cfg_tuple_get(control, "allow");
@@ -1161,8 +1150,8 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
                result = dns_acl_any(mctx, &new_acl);
        }
 
-       if ((result == ISC_R_SUCCESS) && (control != NULL)) {
-               const cfg_obj_t *readonly;
+       if (result == ISC_R_SUCCESS && control != NULL) {
+               const cfg_obj_t *readonly = NULL;
 
                readonly = cfg_tuple_get(control, "read-only");
                if (!cfg_obj_isvoid(readonly)) {
@@ -1242,6 +1231,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
                result = isc_socket_permunix(&listener->address, listener->perm,
                                             listener->owner, listener->group);
        }
+
        if (result == ISC_R_SUCCESS) {
                result = control_listen(listener);
        }
@@ -1279,7 +1269,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
 isc_result_t
 named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                         cfg_aclconfctx_t *aclconfctx) {
-       controllistener_t *listener;
+       controllistener_t *listener = NULL;
        controllistenerlist_t new_listeners;
        const cfg_obj_t *controlslist = NULL;
        const cfg_listelt_t *element, *element2;
@@ -1304,7 +1294,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                for (element = cfg_list_first(controlslist); element != NULL;
                     element = cfg_list_next(element))
                {
-                       const cfg_obj_t *controls;
+                       const cfg_obj_t *controls = NULL;
                        const cfg_obj_t *inetcontrols = NULL;
 
                        controls = cfg_listelt_value(element);
@@ -1317,8 +1307,8 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                             element2 != NULL;
                             element2 = cfg_list_next(element2))
                        {
-                               const cfg_obj_t *control;
-                               const cfg_obj_t *obj;
+                               const cfg_obj_t *control = NULL;
+                               const cfg_obj_t *obj = NULL;
                                isc_sockaddr_t addr;
 
                                /*
@@ -1375,7 +1365,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                for (element = cfg_list_first(controlslist); element != NULL;
                     element = cfg_list_next(element))
                {
-                       const cfg_obj_t *controls;
+                       const cfg_obj_t *controls = NULL;
                        const cfg_obj_t *unixcontrols = NULL;
 
                        controls = cfg_listelt_value(element);
@@ -1388,8 +1378,8 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                             element2 != NULL;
                             element2 = cfg_list_next(element2))
                        {
-                               const cfg_obj_t *control;
-                               const cfg_obj_t *path;
+                               const cfg_obj_t *control = NULL;
+                               const cfg_obj_t *path = NULL;
                                isc_sockaddr_t addr;
                                isc_result_t result;
 
index 7a3123e19acd24e9939250c044fcf3e091505ca8..58e9a43d8e347bab16583fa6471c6494041c95ea 100644 (file)
 
 #define SERVERADDRS 10
 
-const char *progname;
+const char *progname = NULL;
 bool verbose;
 
-static const char *admin_conffile;
-static const char *admin_keyfile;
+static const char *admin_conffile = NULL;
+static const char *admin_keyfile = NULL;
 static const char *version = PACKAGE_VERSION;
 static const char *servername = NULL;
 static isc_sockaddr_t serveraddrs[SERVERADDRS];
@@ -69,18 +69,18 @@ static int nserveraddrs;
 static int currentaddr = 0;
 static unsigned int remoteport = 0;
 static isc_socketmgr_t *socketmgr = NULL;
-static isc_buffer_t *databuf;
+static isc_buffer_t *databuf = NULL;
 static isccc_ccmsg_t ccmsg;
 static uint32_t algorithm;
 static isccc_region_t secret;
 static bool failed = false;
 static bool c_flag = false;
-static isc_mem_t *rndc_mctx;
+static isc_mem_t *rndc_mctx = NULL;
 static atomic_uint_fast32_t sends = ATOMIC_VAR_INIT(0);
 static atomic_uint_fast32_t recvs = ATOMIC_VAR_INIT(0);
 static atomic_uint_fast32_t connects = ATOMIC_VAR_INIT(0);
-static char *command;
-static char *args;
+static char *command = NULL;
+static char *args = NULL;
 static char program[256];
 static isc_socket_t *sock = NULL;
 static uint32_t serial;
@@ -114,7 +114,7 @@ command is one of the following:\n\
                Close, rename and re-open the DNSTAP output file(s).\n\
   dumpdb [-all|-cache|-zones|-adb|-bad|-fail] [view ...]\n\
                Dump cache(s) to the dump file (named_dump.db).\n\
-  flush        Flushes all of the server's caches.\n\
+  flush         Flushes all of the server's caches.\n\
   flush [view] Flushes the server's cache for a view.\n\
   flushname name [view]\n\
                Flush the given name from the server's cache(s)\n\
@@ -652,7 +652,7 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
                if (servers != NULL) {
                        for (elt = cfg_list_first(servers); elt != NULL;
                             elt = cfg_list_next(elt)) {
-                               const char *name;
+                               const char *name = NULL;
                                server = cfg_listelt_value(elt);
                                name = cfg_obj_asstring(
                                        cfg_map_getname(server));
@@ -689,9 +689,11 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
                DO("get config key list", cfg_map_get(config, "key", &keys));
                for (elt = cfg_list_first(keys); elt != NULL;
                     elt = cfg_list_next(elt)) {
+                       const char *name = NULL;
+
                        key = cfg_listelt_value(elt);
-                       if (strcasecmp(cfg_obj_asstring(cfg_map_getname(key)),
-                                      keyname) == 0) {
+                       name = cfg_obj_asstring(cfg_map_getname(key));
+                       if (strcasecmp(name, keyname) == 0) {
                                break;
                        }
                }
@@ -990,7 +992,6 @@ main(int argc, char **argv) {
        DO("create task manager",
           isc_taskmgr_create(rndc_mctx, 1, 0, NULL, &taskmgr));
        DO("create task", isc_task_create(taskmgr, 0, &task));
-
        isc_log_create(rndc_mctx, &log, &logconfig);
        isc_log_setcontext(log);
        isc_log_settag(logconfig, progname);
index 07a2d403ff270ebca8d57c073548eebffaf61955..b3ce556efb914676bda969f6ba4bf69a7a2b33d4 100644 (file)
@@ -46,7 +46,7 @@ recv_message(isc_task_t *, isc_event_t *);
 static void
 recv_length(isc_task_t *task, isc_event_t *ev_in) {
        isc_socketevent_t *ev = (isc_socketevent_t *)ev_in;
-       isc_event_t *dev;
+       isc_event_t *dev = NULL;
        isccc_ccmsg_t *ccmsg = ev_in->ev_arg;
        isc_region_t region;
        isc_result_t result;
@@ -101,10 +101,10 @@ send_and_free:
 static void
 recv_message(isc_task_t *task, isc_event_t *ev_in) {
        isc_socketevent_t *ev = (isc_socketevent_t *)ev_in;
-       isc_event_t *dev;
+       isc_event_t *dev = NULL;
        isccc_ccmsg_t *ccmsg = ev_in->ev_arg;
 
-       (void)task;
+       UNUSED(task);
 
        INSIST(VALID_CCMSG(ccmsg));
 
@@ -131,19 +131,17 @@ isccc_ccmsg_init(isc_mem_t *mctx, isc_socket_t *sock, isccc_ccmsg_t *ccmsg) {
        REQUIRE(sock != NULL);
        REQUIRE(ccmsg != NULL);
 
-       ccmsg->magic = CCMSG_MAGIC;
-       ccmsg->size = 0;
-       ccmsg->buffer.base = NULL;
-       ccmsg->buffer.length = 0;
-       ccmsg->maxsize = 4294967295U; /* Largest message possible. */
-       ccmsg->mctx = mctx;
-       ccmsg->sock = sock;
-       ccmsg->task = NULL;               /* None yet. */
-       ccmsg->result = ISC_R_UNEXPECTED; /* None yet. */
-                                         /*
-                                          * Should probably initialize the
-                                          *event here, but it can wait.
-                                          */
+       *ccmsg = (isccc_ccmsg_t){
+               .magic = CCMSG_MAGIC,
+               .maxsize = 0xffffffffU, /* Largest message possible. */
+               .mctx = mctx,
+               .sock = sock,
+               .result = ISC_R_UNEXPECTED /* None yet. */
+       };
+
+       /*
+        * Should probably initialize the event here, but it can wait.
+        */
 }
 
 void
@@ -197,21 +195,6 @@ isccc_ccmsg_cancelread(isccc_ccmsg_t *ccmsg) {
        isc_socket_cancel(ccmsg->sock, NULL, ISC_SOCKCANCEL_RECV);
 }
 
-#if 0
-void
-isccc_ccmsg_freebuffer(isccc_ccmsg_t*ccmsg) {
-       REQUIRE(VALID_CCMSG(ccmsg));
-
-       if (ccmsg->buffer.base == NULL) {
-               return;
-       }
-
-       isc_mem_put(ccmsg->mctx,ccmsg->buffer.base,ccmsg->buffer.length);
-       ccmsg->buffer.base = NULL;
-       ccmsg->buffer.length = 0;
-}
-#endif /* if 0 */
-
 void
 isccc_ccmsg_invalidate(isccc_ccmsg_t *ccmsg) {
        REQUIRE(VALID_CCMSG(ccmsg));