]> jfr.im git - solanum.git/commitdiff
authd: Only use refcount for reference counting
authorSimon Arlott <sa.me.uk>
Sun, 1 May 2016 10:31:05 +0000 (11:31 +0100)
committerSimon Arlott <sa.me.uk>
Sun, 1 May 2016 10:31:05 +0000 (11:31 +0100)
Use providers_active for provider activity tracking.

authd/provider.c
authd/provider.h
authd/providers/blacklist.c
authd/providers/ident.c
authd/providers/opm.c
authd/providers/rdns.c

index 3b64c55a116f39d343e5c76201d3c89f15523e4f..b058928ed937bc3682fbd3ebe3e97d1739374f9b 100644 (file)
@@ -87,9 +87,13 @@ destroy_providers(void)
        /* Cancel outstanding connections */
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
+               auth_client_ref(auth);
+
                /* TBD - is this the right thing? */
                reject_client(auth, UINT32_MAX, "destroy",
                        "Authentication system is down... try reconnecting in a few seconds");
+
+               auth_client_unref(auth);
        }
 
        RB_DLINK_FOREACH_SAFE(ptr, nptr, auth_providers.head)
@@ -187,7 +191,7 @@ cancel_providers(struct auth_client *auth)
 
        auth->providers_cancelled = true;
 
-       if(auth->refcount > 0)
+       if(auth->providers_active > 0)
        {
                rb_dlink_node *ptr;
 
@@ -215,7 +219,7 @@ provider_done(struct auth_client *auth, uint32_t id)
 
        set_provider_done(auth, id);
 
-       if(auth->refcount == 0 && !auth->providers_starting)
+       if(auth->providers_active == 0 && !auth->providers_starting)
        {
                /* All done */
                accept_client(auth, UINT32_MAX);
@@ -237,7 +241,6 @@ provider_done(struct auth_client *auth, uint32_t id)
 void
 reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...)
 {
-       unsigned int refcount = auth->refcount;
        char buf[BUFSIZE];
        va_list args;
 
@@ -265,8 +268,6 @@ reject_client(struct auth_client *auth, uint32_t id, const char *data, const cha
 void
 accept_client(struct auth_client *auth, uint32_t id)
 {
-       unsigned int refcount = auth->refcount;
-
        rb_helper_write(authd_helper, "A %x %s %s", auth->cid, auth->username, auth->hostname);
 
        if(id != UINT32_MAX)
@@ -287,6 +288,7 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
                return;
 
        auth = rb_malloc(sizeof(struct auth_client));
+       auth_client_ref(auth);
        auth->cid = (uint32_t)lcid;
 
        if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
@@ -328,7 +330,7 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
                /* Execute providers */
                if(!provider->start(auth))
                        /* Rejected immediately */
-                       return;
+                       goto done;
 
                if(auth->providers_cancelled)
                        break;
@@ -336,8 +338,11 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
        auth->providers_starting = false;
 
        /* If no providers are running, accept the client */
-       if(auth->refcount == 0)
+       if(auth->providers_active == 0)
                accept_client(auth, UINT32_MAX);
+
+done:
+       auth_client_unref(auth);
 }
 
 /* Callback for the initiation */
@@ -379,7 +384,9 @@ handle_cancel_connection(int parc, char *parv[])
                return;
        }
 
+       auth_client_ref(auth);
        cancel_providers(auth);
+       auth_client_unref(auth);
 }
 
 static void
@@ -393,6 +400,8 @@ provider_timeout_event(void *notused __unused)
        {
                rb_dlink_node *ptr;
 
+               auth_client_ref(auth);
+
                RB_DLINK_FOREACH(ptr, auth_providers.head)
                {
                        struct auth_provider *provider = ptr->data;
@@ -404,5 +413,7 @@ provider_timeout_event(void *notused __unused)
                                provider->timeout(auth);
                        }
                }
+
+               auth_client_unref(auth);
        }
 }
index fc7d5feabce2d9ba5468382f55b5c6b119866544..fa606d50edf0b29c2982a646a93dc2dbd813e2f5 100644 (file)
@@ -59,6 +59,7 @@ struct auth_client
 
        bool providers_starting;                /* Providers are still warming up */
        bool providers_cancelled;               /* Providers are being cancelled */
+       unsigned int providers_active;          /* Number of active providers */
        unsigned int refcount;                  /* Held references */
 
        struct auth_client_data *data;          /* Provider-specific data */
@@ -188,7 +189,7 @@ set_provider_status(struct auth_client *auth, uint32_t provider, provider_status
 static inline void
 set_provider_running(struct auth_client *auth, uint32_t provider)
 {
-       auth_client_ref(auth);
+       auth->providers_active++;
        set_provider_status(auth, provider, PROVIDER_STATUS_RUNNING);
 }
 
@@ -198,7 +199,7 @@ static inline void
 set_provider_done(struct auth_client *auth, uint32_t provider)
 {
        set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
-       auth_client_unref(auth);
+       auth->providers_active--;
 }
 
 /* Check if provider is operating on this auth client */
index 769a34a424123035818f4fb5cf0c2b3a40790549..b0522c702d54037e07563496cd249a19e9b2936d 100644 (file)
@@ -266,6 +266,8 @@ blacklist_dns_callback(const char *result, bool status, query_type type, void *d
                set_provider_data(auth, SELF_PID, NULL);
                set_provider_timeout_absolute(auth, SELF_PID, 0);
                provider_done(auth, SELF_PID);
+
+               auth_client_unref(auth);
        }
 }
 
@@ -352,6 +354,8 @@ blacklists_start(struct auth_client *auth)
                /* Nothing to do... */
                return true;
 
+       auth_client_ref(auth);
+
        set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct blacklist_user)));
 
        if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) &&
@@ -416,6 +420,8 @@ blacklists_cancel(struct auth_client *auth)
        set_provider_data(auth, SELF_PID, NULL);
        set_provider_timeout_absolute(auth, SELF_PID, 0);
        provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
@@ -427,6 +433,7 @@ blacklists_destroy(void)
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
                blacklists_cancel(auth);
+               /* auth is now invalid as we have no reference */
        }
 
        delete_all_blacklists();
index 959bdb5763fc2a04c44e17a05d8052cf84ebd4b8..e6f08b198affa6e2d274ae2f055b32ff512142a9 100644 (file)
@@ -188,6 +188,8 @@ client_fail(struct auth_client *auth, ident_message report)
 
        notice_client(auth->cid, messages[report]);
        provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
@@ -206,6 +208,8 @@ client_success(struct auth_client *auth)
 
        notice_client(auth->cid, messages[REPORT_FOUND]);
        provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 /* get_valid_ident
@@ -283,6 +287,7 @@ ident_destroy(void)
        {
                if(get_provider_data(auth, SELF_PID) != NULL)
                        client_fail(auth, REPORT_FAIL);
+               /* auth is now invalid as we have no reference */
        }
 }
 
@@ -303,6 +308,8 @@ ident_start(struct auth_client *auth)
                return true;
        }
 
+       auth_client_ref(auth);
+
        notice_client(auth->cid, messages[REPORT_LOOKUP]);
 
        set_provider_data(auth, SELF_PID, query);
index 560eecee09f121df929b1b4994f5bd642b1ed17b..8087bc972a64e9152990cc131c331e7d50a3bb0e 100644 (file)
@@ -563,6 +563,7 @@ create_listener(const char *ip, uint16_t port)
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
                opm_cancel(auth);
+               /* auth is now invalid as we have no reference */
        }
 
        /* Copy data */
@@ -631,6 +632,8 @@ opm_start(struct auth_client *auth)
                /* Nothing to do... */
                return true;
 
+       auth_client_ref(auth);
+
        set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct opm_lookup)));
 
        if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) &&
@@ -668,6 +671,8 @@ opm_cancel(struct auth_client *auth)
                set_provider_data(auth, SELF_PID, NULL);
                set_provider_timeout_absolute(auth, SELF_PID, 0);
                provider_done(auth, SELF_PID);
+
+               auth_client_unref(auth);
        }
 }
 
@@ -681,6 +686,7 @@ opm_destroy(void)
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
                opm_cancel(auth);
+               /* auth is now invalid as we have no reference */
        }
 }
 
@@ -723,6 +729,7 @@ set_opm_enabled(const char *key __unused, int parc __unused, const char **parv)
                        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
                        {
                                opm_cancel(auth);
+                               /* auth is now invalid as we have no reference */
                        }
                }
        }
@@ -847,6 +854,8 @@ delete_opm_scanner(const char *key __unused, int parc __unused, const char **par
                if(lookup == NULL)
                        continue;
 
+               auth_client_ref(auth);
+
                RB_DLINK_FOREACH(ptr, lookup->scans.head)
                {
                        struct opm_scan *scan = ptr->data;
@@ -863,6 +872,8 @@ delete_opm_scanner(const char *key __unused, int parc __unused, const char **par
                                break;
                        }
                }
+
+               auth_client_unref(auth);
        }
 
        rb_dlinkDelete(&proxy->node, &proxy_scanners);
@@ -888,6 +899,7 @@ delete_opm_scanner_all(const char *key __unused, int parc __unused, const char *
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
                opm_cancel(auth);
+               /* auth is now invalid as we have no reference */
        }
 
        opm_enable = false;
index d263415a8544cd4cc4f58c638f1e1d0facea9737..ff0bb07802f7b4dc74d964d1f8bd3cd3440f972c 100644 (file)
@@ -90,6 +90,8 @@ client_fail(struct auth_client *auth, dns_message report)
        set_provider_data(auth, SELF_PID, NULL);
        set_provider_timeout_absolute(auth, SELF_PID, 0);
        provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
@@ -107,6 +109,8 @@ client_success(struct auth_client *auth)
        set_provider_data(auth, SELF_PID, NULL);
        set_provider_timeout_absolute(auth, SELF_PID, 0);
        provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
@@ -119,6 +123,7 @@ rdns_destroy(void)
        {
                if(get_provider_data(auth, SELF_PID) != NULL)
                        client_fail(auth, REPORT_FAIL);
+               /* auth is now invalid as we have no reference */
        }
 }
 
@@ -127,6 +132,8 @@ rdns_start(struct auth_client *auth)
 {
        struct user_query *query = rb_malloc(sizeof(struct user_query));
 
+       auth_client_ref(auth);
+
        set_provider_data(auth, SELF_PID, query);
        set_provider_timeout_relative(auth, SELF_PID, rdns_timeout);