]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth-client: auth-master - Move auth_master_pass_lookup()
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sun, 19 Apr 2020 17:14:03 +0000 (19:14 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 27 Aug 2025 11:34:57 +0000 (13:34 +0200)
src/lib-auth-client/auth-master.c
src/lib-auth-client/auth-master.h

index cadd294eb820638767ed4982d24c4a4308832fff..167db83371927df0abfc4bcc1f4d5d830b6afc7b 100644 (file)
@@ -539,6 +539,74 @@ static bool auth_lookup_reply_callback(const char *cmd, const char *const *args,
        return TRUE;
 }
 
+int auth_master_pass_lookup(struct auth_master_connection *conn,
+                           const char *user, const struct auth_user_info *info,
+                           pool_t pool, const char *const **fields_r)
+{
+       struct auth_master_lookup_ctx ctx;
+       string_t *str;
+
+       if (!is_valid_string(user) || !is_valid_string(info->protocol)) {
+               /* non-allowed characters, the user can't exist */
+               *fields_r = NULL;
+               return 0;
+       }
+
+       i_zero(&ctx);
+       ctx.conn = conn;
+       ctx.return_value = -1;
+       ctx.pool = pool;
+       ctx.expected_reply = "PASS";
+       ctx.user = user;
+
+       conn->reply_callback = auth_lookup_reply_callback;
+       conn->reply_context = &ctx;
+
+       str = t_str_new(128);
+       str_printfa(str, "PASS\t%u\t%s",
+                   auth_master_next_request_id(conn), user);
+       auth_user_info_export(str, info);
+       str_append_c(str, '\n');
+
+       auth_master_user_event_create(
+               conn, t_strdup_printf("passdb lookup(%s): ", user), info);
+       event_add_str(conn->event, "user", user);
+
+       struct event_passthrough *e =
+               event_create_passthrough(conn->event)->
+               set_name("auth_client_passdb_lookup_started");
+       e_debug(e->event(), "Started passdb lookup");
+
+       (void)auth_master_run_cmd(conn, str_c(str));
+
+       *fields_r = ctx.fields != NULL ? ctx.fields :
+               p_new(pool, const char *, 1);
+
+       if (ctx.return_value <= 0) {
+               struct event_passthrough *e =
+                       event_create_passthrough(conn->event)->
+                       set_name("auth_client_passdb_lookup_finished");
+               if ((*fields_r)[0] == NULL) {
+                       e->add_str("error", "Lookup failed");
+                       e_debug(e->event(), "Passdb lookup failed");
+               } else {
+                       e->add_str("error", (*fields_r)[0]);
+                       e_debug(e->event(), "Passdb lookup failed: %s",
+                               (*fields_r)[0]);
+               }
+       } else {
+               struct event_passthrough *e =
+                       event_create_passthrough(conn->event)->
+                       set_name("auth_client_passdb_lookup_finished");
+               e_debug(e->event(), "Finished passdb lookup (%s)",
+                       t_strarray_join(*fields_r, " "));
+       }
+       auth_master_event_finish(conn);
+
+       conn->reply_context = NULL;
+       return ctx.return_value;
+}
+
 int auth_master_user_lookup(struct auth_master_connection *conn,
                            const char *user, const struct auth_user_info *info,
                            pool_t pool, const char **username_r,
@@ -655,74 +723,6 @@ int auth_user_fields_parse(const char *const *fields, pool_t pool,
        return 0;
 }
 
-int auth_master_pass_lookup(struct auth_master_connection *conn,
-                           const char *user, const struct auth_user_info *info,
-                           pool_t pool, const char *const **fields_r)
-{
-       struct auth_master_lookup_ctx ctx;
-       string_t *str;
-
-       if (!is_valid_string(user) || !is_valid_string(info->protocol)) {
-               /* non-allowed characters, the user can't exist */
-               *fields_r = NULL;
-               return 0;
-       }
-
-       i_zero(&ctx);
-       ctx.conn = conn;
-       ctx.return_value = -1;
-       ctx.pool = pool;
-       ctx.expected_reply = "PASS";
-       ctx.user = user;
-
-       conn->reply_callback = auth_lookup_reply_callback;
-       conn->reply_context = &ctx;
-
-       str = t_str_new(128);
-       str_printfa(str, "PASS\t%u\t%s",
-                   auth_master_next_request_id(conn), user);
-       auth_user_info_export(str, info);
-       str_append_c(str, '\n');
-
-       auth_master_user_event_create(
-               conn, t_strdup_printf("passdb lookup(%s): ", user), info);
-       event_add_str(conn->event, "user", user);
-
-       struct event_passthrough *e =
-               event_create_passthrough(conn->event)->
-               set_name("auth_client_passdb_lookup_started");
-       e_debug(e->event(), "Started passdb lookup");
-
-       (void)auth_master_run_cmd(conn, str_c(str));
-
-       *fields_r = ctx.fields != NULL ? ctx.fields :
-               p_new(pool, const char *, 1);
-
-       if (ctx.return_value <= 0) {
-               struct event_passthrough *e =
-                       event_create_passthrough(conn->event)->
-                       set_name("auth_client_passdb_lookup_finished");
-               if ((*fields_r)[0] == NULL) {
-                       e->add_str("error", "Lookup failed");
-                       e_debug(e->event(), "Passdb lookup failed");
-               } else {
-                       e->add_str("error", (*fields_r)[0]);
-                       e_debug(e->event(), "Passdb lookup failed: %s",
-                               (*fields_r)[0]);
-               }
-       } else {
-               struct event_passthrough *e =
-                       event_create_passthrough(conn->event)->
-                       set_name("auth_client_passdb_lookup_finished");
-               e_debug(e->event(), "Finished passdb lookup (%s)",
-                       t_strarray_join(*fields_r, " "));
-       }
-       auth_master_event_finish(conn);
-
-       conn->reply_context = NULL;
-       return ctx.return_value;
-}
-
 struct auth_master_user_list_ctx {
        struct auth_master_connection *conn;
        string_t *username;
index 5a3cc1519d3179e350f39493892a3187e9f1b44c..16aa35105e485777544bcbf8e7d5d4c314e88e0e 100644 (file)
@@ -36,6 +36,11 @@ struct auth_user_info {
        bool debug;
 };
 
+/* Do a PASS lookup (the actual password isn't returned). */
+int auth_master_pass_lookup(struct auth_master_connection *conn,
+                           const char *user, const struct auth_user_info *info,
+                           pool_t pool, const char *const **fields_r);
+
 struct auth_user_reply {
        uid_t uid;
        gid_t gid;
@@ -51,10 +56,6 @@ int auth_master_user_lookup(struct auth_master_connection *conn,
                            const char *user, const struct auth_user_info *info,
                            pool_t pool, const char **username_r,
                            const char *const **fields_r);
-/* Do a PASS lookup (the actual password isn't returned). */
-int auth_master_pass_lookup(struct auth_master_connection *conn,
-                           const char *user, const struct auth_user_info *info,
-                           pool_t pool, const char *const **fields_r);
 
 /* Parse userdb extra fields into auth_user_reply structure. */
 int auth_user_fields_parse(const char *const *fields, pool_t pool,