]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth-client: auth-master - Restructure reply parsing
authorStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 2 Oct 2017 12:39:41 +0000 (14:39 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 27 Aug 2025 11:35:32 +0000 (13:35 +0200)
Now it parses the received id into an integer rather than converting the expected id to a string.

src/lib-auth-client/auth-master.c

index 6e7df183551aed98f19a8cca8fb2fc8cbd5c6577..47b5ebfdc95909239970ce33c75ab8c429a801d6 100644 (file)
@@ -205,35 +205,33 @@ static int
 auth_master_handle_input(struct auth_master_connection *conn,
                         const char *const *args)
 {
-       const char *const *in_args = args;
-       const char *cmd, *id, *wanted_id;
-
-       cmd = *args; args++;
-       if (*args == NULL)
-               id = "";
-       else {
-               id = *args;
-               args++;
-       }
-
-       wanted_id = dec2str(conn->id_counter);
-       if (strcmp(id, wanted_id) == 0) {
-               e_debug(conn->conn.event, "auth input: %s",
-                       t_strarray_join(args, "\t"));
-               /* Returns 1 upon full completion, 0 upon successful partial
-                  completion (will be called again) and -1 upon error. */
-               return conn->reply_callback(cmd, args, conn->reply_context);
-       }
+       unsigned int id;
 
-       if (strcmp(cmd, "CUID") == 0) {
+       if (strcmp(args[0], "CUID") == 0) {
                e_error(conn->event, "%s is an auth client socket. "
                        "It should be a master socket.",
                        conn->auth_socket_path);
-       } else {
+               return -1;
+       }
+
+       if (args[1] == NULL || str_to_uint(args[1], &id) < 0) {
                e_error(conn->event, "BUG: Unexpected input: %s",
-                       t_strarray_join(in_args, "\t"));
+                       t_strarray_join(args, "\t"));
+               return -1;
        }
-       return -1;
+
+       if (id != conn->id_counter) {
+               e_error(conn->event,
+                       "Auth server sent reply with unknown ID %u", id);
+               return -1;
+       }
+
+       e_debug(conn->conn.event, "auth input: %s",
+               t_strarray_join(args, "\t"));
+
+       /* Returns 1 upon full completion, 0 upon successful partial
+          completion (will be called again) and -1 upon error. */
+       return conn->reply_callback(args[0], args + 2, conn->reply_context);
 }
 
 static int