]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't use hardcoded protocol list for auth process, string is just fine.
authorTimo Sirainen <tss@iki.fi>
Sat, 29 May 2004 17:06:49 +0000 (20:06 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 29 May 2004 17:06:49 +0000 (20:06 +0300)
--HG--
branch : HEAD

src/auth/auth-client-interface.h
src/auth/mech.c
src/auth/mech.h
src/auth/passdb-pam.c
src/auth/passdb-vpopmail.c
src/imap-login/client-authenticate.c
src/lib-auth/auth-client.h
src/lib-auth/auth-server-request.c
src/pop3-login/client-authenticate.c

index 5f9fbb3842537406bb039983caab46986bcc9ef4..d7a44b4330e071fbabce5e97b14f1f37b91d58a1 100644 (file)
@@ -4,6 +4,9 @@
 /* max. size for auth_client_request_continue.data[] */
 #define AUTH_CLIENT_MAX_REQUEST_DATA_SIZE 4096
 
+/* sizeof(struct auth_client_request_new->protocol) */
+#define AUTH_CLIENT_PROTOCOL_BUF_SIZE 12
+
 /* Client process must finish with single authentication requests in this time,
    or the whole connection will be killed. */
 #define AUTH_REQUEST_TIMEOUT 120
@@ -17,11 +20,6 @@ enum auth_mech {
        AUTH_MECH_COUNT
 };
 
-enum auth_protocol {
-       AUTH_PROTOCOL_IMAP      = 0x01,
-       AUTH_PROTOCOL_POP3      = 0x02
-};
-
 enum auth_client_request_new_flags {
        AUTH_CLIENT_FLAG_SSL_VALID_CLIENT_CERT = 0x01
 };
@@ -54,8 +52,8 @@ struct auth_client_request_new {
        unsigned int id; /* unique ID for the request */
 
        enum auth_mech mech;
-       enum auth_protocol protocol;
-        enum auth_client_request_new_flags flags;
+       enum auth_client_request_new_flags flags;
+       char protocol[AUTH_CLIENT_PROTOCOL_BUF_SIZE];
 };
 
 /* Continue authentication request */
index e1cacc6b77f0bee84e26a369bab85380a7198e91..3656a55a147492dc71782e662fd06e1857fabf86 100644 (file)
@@ -110,7 +110,8 @@ void mech_request_new(struct auth_client_connection *conn,
                auth_request->created = ioloop_time;
                auth_request->conn = conn;
                auth_request->id = request->id;
-               auth_request->protocol = request->protocol;
+               strocpy(auth_request->protocol, request->protocol,
+                       sizeof(auth_request->protocol));
 
                hash_insert(conn->auth_requests, POINTER_CAST(request->id),
                            auth_request);
@@ -260,16 +261,7 @@ auth_request_get_var_expand_table(const struct auth_request *auth_request,
        tab[2].value = strchr(auth_request->user, '@');
        if (tab[2].value != NULL)
                tab[2].value = escape_func(tab[2].value+1);
-
-       switch (auth_request->protocol) {
-       case AUTH_PROTOCOL_IMAP:
-               tab[3].value = "IMAP";
-               break;
-       case AUTH_PROTOCOL_POP3:
-               tab[3].value = "POP3";
-               break;
-       }
-
+       tab[3].value = auth_request->protocol;
        return tab;
 }
 
index 3a1ed5a0f80ed32e0b85c8cc09b325f0d3df1adb..c98d45a91af899c2f61653bf189b528f0ec1133c 100644 (file)
@@ -19,7 +19,7 @@ struct auth_request {
        unsigned int id;
        time_t created;
 
-       enum auth_protocol protocol;
+       char protocol[AUTH_CLIENT_PROTOCOL_BUF_SIZE];
        mech_callback_t *callback;
 
        int (*auth_continue)(struct auth_request *auth_request,
index 0a50aac6f781acaf8295fa0ded8fd7583c28fe36..ee281ddc0909923a0645408af6fa5b892a4afd20 100644 (file)
@@ -330,14 +330,7 @@ pam_verify_plain(struct auth_request *request, const char *password,
        int fd[2];
        pid_t pid;
 
-       service = service_name != NULL ? service_name :
-               request->protocol == AUTH_PROTOCOL_IMAP ? "imap" :
-               request->protocol == AUTH_PROTOCOL_POP3 ? "pop3" : NULL;
-       if (service == NULL) {
-               i_error("Unknown protocol %d in auth request",
-                       request->protocol);
-       }
-
+       service = service_name != NULL ? service_name : request->protocol;
        if (pipe(fd) < 0) {
                i_error("PAM: pipe() failed: %m");
                callback(PASSDB_RESULT_INTERNAL_FAILURE, request);
index 609e2bd4848d17daf8fc27d3ae339d6ecd4f0e6f..f69a6cba52e35bd91f1316a8598552846827b63c 100644 (file)
@@ -30,14 +30,12 @@ vpopmail_verify_plain(struct auth_request *request, const char *password,
        }
 
        if (((vpw->pw_gid & NO_IMAP) != 0 &&
-            request->protocol == AUTH_PROTOCOL_IMAP) ||
+            strcmp(request->protocol, "IMAP") == 0) ||
            ((vpw->pw_gid & NO_POP) != 0 &&
-            request->protocol == AUTH_PROTOCOL_POP3)) {
+            strcmp(request->protocol, "POP3") == 0)) {
                if (verbose) {
                        i_info("vpopmail(%s@%s): %s disabled",
-                              vpop_user, vpop_domain,
-                              request->protocol == AUTH_PROTOCOL_IMAP ?
-                              "IMAP" : "POP3");
+                              vpop_user, vpop_domain, request->protocol);
                }
                callback(PASSDB_RESULT_USER_DISABLED, request);
                return;
index 0bb91ca667aa4ff0ce1fbf61589c1e01c388353f..c9305d0a9276c6197f597d8927fdd9fa4da1df9a 100644 (file)
@@ -207,8 +207,7 @@ int cmd_login(struct imap_client *client, struct imap_arg *args)
        client_ref(client);
 
        client->common.auth_request =
-               auth_client_request_new(auth_client, AUTH_MECH_PLAIN,
-                                       AUTH_PROTOCOL_IMAP,
+               auth_client_request_new(auth_client, AUTH_MECH_PLAIN, "IMAP",
                                        client_get_auth_flags(client),
                                        login_callback, client, &error);
        if (client->common.auth_request == NULL) {
@@ -336,8 +335,7 @@ int cmd_authenticate(struct imap_client *client, struct imap_arg *args)
 
        client_ref(client);
        client->common.auth_request =
-               auth_client_request_new(auth_client, mech->mech,
-                                       AUTH_PROTOCOL_IMAP,
+               auth_client_request_new(auth_client, mech->mech, "IMAP",
                                        client_get_auth_flags(client),
                                        authenticate_callback,
                                        client, &error);
index 830b6654b038a27b58b58f13b237a6617e70c19b..411db4554f9307092bca1115bd1598dd5cca46c4 100644 (file)
@@ -30,7 +30,7 @@ void auth_client_connect_missing_servers(struct auth_client *client);
    happens for the request. */
 struct auth_request *
 auth_client_request_new(struct auth_client *client,
-                       enum auth_mech mech, enum auth_protocol protocol,
+                       enum auth_mech mech, const char *protocol,
                        enum auth_client_request_new_flags flags,
                        auth_request_callback_t *callback, void *context,
                        const char **error_r);
index dd9251f6fa3692bfed92cd9d902e5e7a6d3d4c41..48983dd1ecd5ea72c7d2316d0beebec47ee63754 100644 (file)
@@ -11,7 +11,7 @@ struct auth_request {
         struct auth_server_connection *conn;
 
        enum auth_mech mech;
-       enum auth_protocol protocol;
+       char protocol[AUTH_CLIENT_PROTOCOL_BUF_SIZE];
        enum auth_client_request_new_flags flags;
 
        unsigned int id;
@@ -34,7 +34,8 @@ static int auth_server_send_new_request(struct auth_server_connection *conn,
 
        auth_request.type = AUTH_CLIENT_REQUEST_NEW;
        auth_request.id = request->id;
-       auth_request.protocol = request->protocol;
+       strocpy(auth_request.protocol, request->protocol,
+               sizeof(auth_request.protocol));
        auth_request.mech = request->mech;
        auth_request.flags = request->flags;
 
@@ -178,7 +179,7 @@ void auth_server_requests_remove_all(struct auth_server_connection *conn)
 
 struct auth_request *
 auth_client_request_new(struct auth_client *client,
-                       enum auth_mech mech, enum auth_protocol protocol,
+                       enum auth_mech mech, const char *protocol,
                        enum auth_client_request_new_flags flags,
                        auth_request_callback_t *callback, void *context,
                        const char **error_r)
@@ -193,7 +194,7 @@ auth_client_request_new(struct auth_client *client,
        request = i_new(struct auth_request, 1);
        request->conn = conn;
        request->mech = mech;
-       request->protocol = protocol;
+       strocpy(request->protocol, protocol, sizeof(request->protocol));
        request->flags = flags;
        request->id = ++client->request_id_counter;
        if (request->id == 0) {
index 31b5cb5760a73b477f78e2b2be9486880d5f5106..6dfa6343a4386135ea6216d1c6dde877619ea00b 100644 (file)
@@ -206,8 +206,7 @@ int cmd_pass(struct pop3_client *client, const char *args)
 
        client_ref(client);
        client->common.auth_request =
-               auth_client_request_new(auth_client, AUTH_MECH_PLAIN,
-                                       AUTH_PROTOCOL_POP3,
+               auth_client_request_new(auth_client, AUTH_MECH_PLAIN, "POP3",
                                         client_get_auth_flags(client),
                                        login_callback, client, &error);
        if (client->common.auth_request != NULL) {
@@ -316,8 +315,7 @@ int cmd_auth(struct pop3_client *client, const char *args)
 
        client_ref(client);
        client->common.auth_request =
-               auth_client_request_new(auth_client, mech->mech,
-                                       AUTH_PROTOCOL_POP3,
+               auth_client_request_new(auth_client, mech->mech, "POP3",
                                         client_get_auth_flags(client),
                                        authenticate_callback, client, &error);
        if (client->common.auth_request != NULL) {