]> jfr.im git - solanum.git/commitdiff
Clean up the provider status logic.
authorElizabeth Myers <redacted>
Tue, 5 Apr 2016 08:30:02 +0000 (03:30 -0500)
committerElizabeth Myers <redacted>
Tue, 5 Apr 2016 08:30:02 +0000 (03:30 -0500)
Provider status (done, running, not run) is now attached to the
provider-specific data of the client. A reference count of auth
instances is kept in the auth_client struct to determine if a client is
done or not.

This also moves a lot of the logic for manipulating provider data into
into the provider.h header for inlining (no point in a function call for
these simple accessors).

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

index 582944886cfaa9d5566d45a11743ce8da3dc333f..c9c7b2c408f4edfbfb5218c77007a90e7d909e74 100644 (file)
@@ -159,7 +159,7 @@ cancel_providers(struct auth_client *auth)
        {
                provider = ptr->data;
 
-               if(provider->cancel && is_provider_on(auth, provider->id))
+               if(provider->cancel && is_provider_running(auth, provider->id))
                        /* Cancel if required */
                        provider->cancel(auth);
        }
@@ -176,13 +176,12 @@ provider_done(struct auth_client *auth, provider_t id)
        rb_dlink_node *ptr;
        struct auth_provider *provider;
 
-       set_provider_off(auth, id);
        set_provider_done(auth, id);
 
-       if(!auth->providers)
+       if(!auth->refcount)
        {
                if(!auth->providers_starting)
-                       /* Only do this when there are no providers left */
+                       /* Providers aren't being executed and refcount is 0, accept */
                        accept_client(auth, -1);
                return;
        }
@@ -191,7 +190,7 @@ provider_done(struct auth_client *auth, provider_t id)
        {
                provider = ptr->data;
 
-               if(provider->completed != NULL && is_provider_on(auth, provider->id))
+               if(provider->completed != NULL && is_provider_running(auth, provider->id))
                        /* Notify pending clients who asked for it */
                        provider->completed(auth, id);
        }
@@ -237,7 +236,7 @@ reject_client(struct auth_client *auth, provider_t id, const char *data, const c
         */
        rb_helper_write(authd_helper, "R %x %c %s %s %s :%s", auth->cid, reject, auth->username, auth->hostname, data, buf);
 
-       set_provider_off(auth, id);
+       set_provider_done(auth, id);
        cancel_providers(auth);
 }
 
@@ -247,7 +246,7 @@ accept_client(struct auth_client *auth, provider_t id)
 {
        rb_helper_write(authd_helper, "A %x %s %s", auth->cid, auth->username, auth->hostname);
 
-       set_provider_off(auth, id);
+       set_provider_done(auth, id);
        cancel_providers(auth);
 }
 
@@ -307,7 +306,7 @@ 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->providers)
+       if(!auth->refcount)
                accept_client(auth, -1);
 }
 
@@ -368,7 +367,7 @@ provider_timeout_event(void *notused __unused)
                        struct auth_provider *provider = ptr->data;
                        const time_t timeout = get_provider_timeout(auth, provider->id);
 
-                       if(is_provider_on(auth, provider->id) && provider->timeout != NULL &&
+                       if(is_provider_running(auth, provider->id) && provider->timeout != NULL &&
                                timeout > 0 && timeout < curtime)
                        {
                                provider->timeout(auth);
@@ -376,38 +375,3 @@ provider_timeout_event(void *notused __unused)
                }
        }
 }
-
-void *
-get_provider_data(struct auth_client *auth, uint32_t id)
-{
-       lrb_assert(id < rb_dlink_list_length(&auth_providers));
-       return auth->data[id].data;
-}
-
-void
-set_provider_data(struct auth_client *auth, uint32_t id, void *data)
-{
-       lrb_assert(id < rb_dlink_list_length(&auth_providers));
-       auth->data[id].data = data;
-}
-
-void
-set_provider_timeout_relative(struct auth_client *auth, uint32_t id, time_t timeout)
-{
-       lrb_assert(id < rb_dlink_list_length(&auth_providers));
-       auth->data[id].timeout = timeout + rb_current_time();
-}
-
-void
-set_provider_timeout_absolute(struct auth_client *auth, uint32_t id, time_t timeout)
-{
-       lrb_assert(id < rb_dlink_list_length(&auth_providers));
-       auth->data[id].timeout = timeout;
-}
-
-time_t
-get_provider_timeout(struct auth_client *auth, uint32_t id)
-{
-       lrb_assert(id < rb_dlink_list_length(&auth_providers));
-       return auth->data[id].timeout;
-}
index 3e57fa180a03e2c2badb1cd1ce4eea9f36184c1b..b04cf0093b9415d2511c0272b61b69f57e8f8f52 100644 (file)
@@ -36,10 +36,18 @@ typedef enum
        PROVIDER_OPM,
 } provider_t;
 
+typedef enum
+{
+       PROVIDER_STATUS_NOTRUN = 0,
+       PROVIDER_STATUS_RUNNING,
+       PROVIDER_STATUS_DONE,
+} provider_status_t;
+
 struct auth_client_data
 {
-       time_t timeout;         /* Provider timeout */
-       void *data;             /* Proivder data */
+       time_t timeout;                 /* Provider timeout */
+       void *data;                     /* Provider data */
+       provider_status_t status;       /* Provider status */
 };
 
 struct auth_client
@@ -57,10 +65,8 @@ struct auth_client
        char hostname[HOSTLEN + 1];             /* Used for DNS lookup */
        char username[USERLEN + 1];             /* Used for ident lookup */
 
-       uint32_t providers;                     /* Providers at work,
-                                                * none left when set to 0 */
-       uint32_t providers_done;                /* Providers completed */
        bool providers_starting;                /* Providers are still warming up */
+       unsigned int refcount;                  /* Held references */
 
        struct auth_client_data *data;          /* Provider-specific data */
 };
@@ -120,44 +126,93 @@ void reject_client(struct auth_client *auth, provider_t id, const char *data, co
 void handle_new_connection(int parc, char *parv[]);
 void handle_cancel_connection(int parc, char *parv[]);
 
-void *get_provider_data(struct auth_client *auth, uint32_t id);
-void set_provider_data(struct auth_client *auth, uint32_t id, void *data);
-void set_provider_timeout_relative(struct auth_client *auth, uint32_t id, time_t timeout);
-void set_provider_timeout_absolute(struct auth_client *auth, uint32_t id, time_t timeout);
-time_t get_provider_timeout(struct auth_client *auth, uint32_t id);
 
-/* Provider is operating on this auth_client (set this if you have async work to do) */
+/* Get a provider's raw status */
+static inline provider_status_t
+get_provider_status(struct auth_client *auth, provider_t provider)
+{
+       return auth->data[provider].status;
+}
+
+/* Set a provider's raw status */
 static inline void
-set_provider_on(struct auth_client *auth, provider_t provider)
+set_provider_status(struct auth_client *auth, provider_t provider, provider_status_t status)
 {
-       auth->providers |= (1 << provider);
+       auth->data[provider].status = status;
 }
 
-/* Provider is no longer operating on this auth client (you should use provider_done) */
+/* Set the provider as running
+ * If you're doing asynchronous work call this */
 static inline void
-set_provider_off(struct auth_client *auth, provider_t provider)
+set_provider_running(struct auth_client *auth, provider_t provider)
 {
-       auth->providers &= ~(1 << provider);
+       auth->refcount++;
+       set_provider_status(auth, provider, PROVIDER_STATUS_RUNNING);
 }
 
-/* Set the provider to done (you should use provider_done) */
+/* Provider is no longer operating on this auth client
+ * You should use provider_done and not this */
 static inline void
 set_provider_done(struct auth_client *auth, provider_t provider)
 {
-       auth->providers_done |= (1 << provider);
+       auth->refcount--;
+       set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
 }
 
 /* Check if provider is operating on this auth client */
 static inline bool
-is_provider_on(struct auth_client *auth, provider_t provider)
+is_provider_running(struct auth_client *auth, provider_t provider)
 {
-       return auth->providers & (1 << provider);
+       return get_provider_status(auth, provider) == PROVIDER_STATUS_RUNNING;
 }
 
+/* Check if provider has finished on this client */
 static inline bool
 is_provider_done(struct auth_client *auth, provider_t provider)
 {
-       return auth->providers_done & (1 << provider);
+       return get_provider_status(auth, provider) == PROVIDER_STATUS_DONE;
+}
+
+/* Get provider auth client data */
+static inline void *
+get_provider_data(struct auth_client *auth, uint32_t id)
+{
+       lrb_assert(id < rb_dlink_list_length(&auth_providers));
+       return auth->data[id].data;
+}
+
+/* Set provider auth client data */
+static inline void
+set_provider_data(struct auth_client *auth, uint32_t id, void *data)
+{
+       lrb_assert(id < rb_dlink_list_length(&auth_providers));
+       auth->data[id].data = data;
+}
+
+/* Set timeout relative to current time on provider
+ * When the timeout lapses, the provider's timeout call will execute */
+static inline void
+set_provider_timeout_relative(struct auth_client *auth, uint32_t id, time_t timeout)
+{
+       lrb_assert(id < rb_dlink_list_length(&auth_providers));
+       auth->data[id].timeout = timeout + rb_current_time();
+}
+
+/* Set timeout value in absolute time (Unix timestamp)
+ * When the timeout lapses, the provider's timeout call will execute */
+static inline void
+set_provider_timeout_absolute(struct auth_client *auth, uint32_t id, time_t timeout)
+{
+       lrb_assert(id < rb_dlink_list_length(&auth_providers));
+       auth->data[id].timeout = timeout;
+}
+
+/* Get the timeout value for the provider */
+static inline time_t
+get_provider_timeout(struct auth_client *auth, uint32_t id)
+{
+       lrb_assert(id < rb_dlink_list_length(&auth_providers));
+       return auth->data[id].timeout;
 }
 
 #endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */
index d387541e12906ff2143d238395c7ce158a60697c..1c6abf456613b39e38cca8ed8512cae41993eefc 100644 (file)
@@ -356,7 +356,7 @@ blacklists_start(struct auth_client *auth)
                /* This probably can't happen but let's handle this case anyway */
                lookup_all_blacklists(auth);
 
-       set_provider_on(auth, PROVIDER_BLACKLIST);
+       set_provider_running(auth, PROVIDER_BLACKLIST);
        return true;
 }
 
index 9a31b911ba3a3d4e24c9cd007f4ec25ceb4edcff..2f08c55073aee4230d5f788603443e654ad0ce18 100644 (file)
@@ -324,7 +324,7 @@ ident_start(struct auth_client *auth)
                        GET_SS_LEN(&l_addr), ident_connected,
                        auth, ident_timeout);
 
-       set_provider_on(auth, PROVIDER_IDENT);
+       set_provider_running(auth, PROVIDER_IDENT);
 
        return true;
 }
index 1d76f647d6fa5d9ae4abb4e8cc0c201b72ad717a..4f0b3d5c5b60995fd7f5fea5f5e81422195a0028 100644 (file)
@@ -669,7 +669,7 @@ opm_start(struct auth_client *auth)
                /* This probably can't happen but let's handle this case anyway */
                opm_scan(auth);
 
-       set_provider_on(auth, PROVIDER_BLACKLIST);
+       set_provider_running(auth, PROVIDER_BLACKLIST);
        return true;
 }
 
index 8b4dd5002e4c73220d940f349a0ae6e2f77d04f6..25cd2813025452437c62f17dc98e5f7d4f350055 100644 (file)
@@ -131,7 +131,7 @@ rdns_start(struct auth_client *auth)
        query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
 
        notice_client(auth->cid, messages[REPORT_LOOKUP]);
-       set_provider_on(auth, PROVIDER_RDNS);
+       set_provider_running(auth, PROVIDER_RDNS);
        return true;
 }