From: Timo Sirainen Date: Sat, 29 May 2004 17:06:49 +0000 (+0300) Subject: Don't use hardcoded protocol list for auth process, string is just fine. X-Git-Tag: 1.1.alpha1~4030 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d701b8abc45d6d3881ee19ffc6f38b23d35eea5;p=thirdparty%2Fdovecot%2Fcore.git Don't use hardcoded protocol list for auth process, string is just fine. --HG-- branch : HEAD --- diff --git a/src/auth/auth-client-interface.h b/src/auth/auth-client-interface.h index 5f9fbb3842..d7a44b4330 100644 --- a/src/auth/auth-client-interface.h +++ b/src/auth/auth-client-interface.h @@ -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 */ diff --git a/src/auth/mech.c b/src/auth/mech.c index e1cacc6b77..3656a55a14 100644 --- a/src/auth/mech.c +++ b/src/auth/mech.c @@ -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; } diff --git a/src/auth/mech.h b/src/auth/mech.h index 3a1ed5a0f8..c98d45a91a 100644 --- a/src/auth/mech.h +++ b/src/auth/mech.h @@ -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, diff --git a/src/auth/passdb-pam.c b/src/auth/passdb-pam.c index 0a50aac6f7..ee281ddc09 100644 --- a/src/auth/passdb-pam.c +++ b/src/auth/passdb-pam.c @@ -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); diff --git a/src/auth/passdb-vpopmail.c b/src/auth/passdb-vpopmail.c index 609e2bd484..f69a6cba52 100644 --- a/src/auth/passdb-vpopmail.c +++ b/src/auth/passdb-vpopmail.c @@ -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; diff --git a/src/imap-login/client-authenticate.c b/src/imap-login/client-authenticate.c index 0bb91ca667..c9305d0a92 100644 --- a/src/imap-login/client-authenticate.c +++ b/src/imap-login/client-authenticate.c @@ -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); diff --git a/src/lib-auth/auth-client.h b/src/lib-auth/auth-client.h index 830b6654b0..411db4554f 100644 --- a/src/lib-auth/auth-client.h +++ b/src/lib-auth/auth-client.h @@ -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); diff --git a/src/lib-auth/auth-server-request.c b/src/lib-auth/auth-server-request.c index dd9251f6fa..48983dd1ec 100644 --- a/src/lib-auth/auth-server-request.c +++ b/src/lib-auth/auth-server-request.c @@ -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) { diff --git a/src/pop3-login/client-authenticate.c b/src/pop3-login/client-authenticate.c index 31b5cb5760..6dfa6343a4 100644 --- a/src/pop3-login/client-authenticate.c +++ b/src/pop3-login/client-authenticate.c @@ -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) {