]> jfr.im git - solanum.git/blobdiff - authd/provider.h
chmode: Get elevated access for op-only queries
[solanum.git] / authd / provider.h
index 2e8179fb9edc7b329fb3631795e983b1973d2940..4000c5d804213c9096383609a2aca06a06ce1814 100644 (file)
@@ -18,8 +18,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __CHARYBDIS_AUTHD_PROVIDER_H__
-#define __CHARYBDIS_AUTHD_PROVIDER_H__
+#ifndef __SOLANUM_AUTHD_PROVIDER_H__
+#define __SOLANUM_AUTHD_PROVIDER_H__
 
 #include "stdinc.h"
 #include "authd.h"
@@ -44,7 +44,9 @@ struct auth_client_data
 
 struct auth_client
 {
-       uint16_t cid;                           /* Client ID */
+       uint32_t cid;                           /* Client ID */
+
+       int protocol;                           /* IP protocol (TCP/SCTP) */
 
        char l_ip[HOSTIPLEN + 1];               /* Listener IP address */
        uint16_t l_port;                        /* Listener port */
@@ -58,6 +60,8 @@ struct auth_client
        char username[USERLEN + 1];             /* Used for ident lookup */
 
        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 */
@@ -101,10 +105,10 @@ struct auth_provider
 
 extern struct auth_provider rdns_provider;
 extern struct auth_provider ident_provider;
-extern struct auth_provider blacklist_provider;
+extern struct auth_provider dnsbl_provider;
 extern struct auth_provider opm_provider;
 
-extern rb_dictionary *auth_providers;
+extern rb_dlink_list auth_providers;
 extern rb_dictionary *auth_clients;
 
 void load_provider(struct auth_provider *provider);
@@ -115,25 +119,49 @@ void destroy_providers(void);
 void cancel_providers(struct auth_client *auth);
 
 void provider_done(struct auth_client *auth, uint32_t id);
-void accept_client(struct auth_client *auth, uint32_t id);
+void accept_client(struct auth_client *auth);
 void reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...);
 
 void handle_new_connection(int parc, char *parv[]);
 void handle_cancel_connection(int parc, char *parv[]);
+void auth_client_free(struct auth_client *auth);
 
+static inline void
+auth_client_ref(struct auth_client *auth)
+{
+       auth->refcount++;
+}
+
+static inline void
+auth_client_unref(struct auth_client *auth)
+{
+       auth->refcount--;
+       if (auth->refcount == 0)
+               auth_client_free(auth);
+}
 
 /* Get a provider by name */
 static inline struct auth_provider *
-get_provider(const char *name)
+find_provider(const char *name)
 {
-       return rb_dictionary_retrieve(auth_providers, name);
+       rb_dlink_node *ptr;
+
+       RB_DLINK_FOREACH(ptr, auth_providers.head)
+       {
+               struct auth_provider *provider = ptr->data;
+
+               if(strcasecmp(provider->name, name) == 0)
+                       return provider;
+       }
+
+       return NULL;
 }
 
 /* Get a provider's id by name */
 static inline bool
-get_provider_id(const char *name, int *id)
+get_provider_id(const char *name, uint32_t *id)
 {
-       struct auth_provider *provider = get_provider(name);
+       struct auth_provider *provider = find_provider(name);
 
        if(provider != NULL)
        {
@@ -151,31 +179,6 @@ get_provider_status(struct auth_client *auth, uint32_t provider)
        return auth->data[provider].status;
 }
 
-/* Set a provider's raw status */
-static inline void
-set_provider_status(struct auth_client *auth, uint32_t provider, provider_status_t status)
-{
-       auth->data[provider].status = status;
-}
-
-/* Set the provider as running
- * If you're doing asynchronous work call this */
-static inline void
-set_provider_running(struct auth_client *auth, uint32_t provider)
-{
-       auth->refcount++;
-       set_provider_status(auth, provider, PROVIDER_STATUS_RUNNING);
-}
-
-/* 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, uint32_t 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_running(struct auth_client *auth, uint32_t provider)
@@ -190,6 +193,19 @@ is_provider_done(struct auth_client *auth, uint32_t provider)
        return get_provider_status(auth, provider) == PROVIDER_STATUS_DONE;
 }
 
+/* Check if provider doesn't exist or has finished on this client */
+static inline bool
+run_after_provider(struct auth_client *auth, const char *name)
+{
+       uint32_t id;
+
+       if (get_provider_id(name, &id)) {
+               return get_provider_status(auth, id) == PROVIDER_STATUS_DONE;
+       } else {
+               return true;
+       }
+}
+
 /* Get provider auth client data */
 static inline void *
 get_provider_data(struct auth_client *auth, uint32_t id)
@@ -227,4 +243,4 @@ get_provider_timeout(struct auth_client *auth, uint32_t id)
        return auth->data[id].timeout;
 }
 
-#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */
+#endif /* __SOLANUM_AUTHD_PROVIDER_H__ */