[Dovecot] [PATCH, RFC 7/13] OTP: add auth_request_set_credentials()

Andrey Panin pazke at donpac.ru
Mon Jun 26 15:58:09 EEST 2006


Add auth_request_set_credentials() function.

diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/auth-request.c dovecot/src/auth/auth-request.c
--- dovecot.vanilla/src/auth/auth-request.c	2006-06-23 13:42:22.123507928 +0400
+++ dovecot/src/auth/auth-request.c	2006-06-23 13:44:31.427850680 +0400
@@ -508,6 +508,37 @@ void auth_request_lookup_credentials(str
 	}
 }
 
+void auth_request_set_credentials(struct auth_request *request,
+				  enum passdb_credentials credentials,
+				  const char *data,
+				  set_credentials_callback_t *callback)
+{
+	struct passdb_module *passdb = request->passdb->passdb;
+	const char *cache_key, *new_credentials;
+
+	i_assert(credentials == PASSDB_CREDENTIALS_OTP);
+
+	cache_key = passdb_cache == NULL ? NULL : passdb->cache_key;
+	if (cache_key != NULL) {
+		auth_cache_remove(passdb_cache, request, cache_key);
+	}
+
+	request->private_callback.set_credentials = callback;
+
+	new_credentials = t_strconcat("{",
+		passdb_credentials_to_str(credentials), "}", data, NULL);
+
+	if (passdb->blocking) {
+		passdb_blocking_set_credentials(request, new_credentials);
+	} else if (passdb->iface.set_credentials != NULL) {
+		passdb->iface.set_credentials(request, new_credentials,
+					      callback);
+	} else {
+		/* this passdb doesn't support credentials update */
+		callback(PASSDB_RESULT_INTERNAL_FAILURE, request);
+	}
+}
+
 void auth_request_userdb_callback(struct auth_stream_reply *reply,
 				  struct auth_request *request)
 {
diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/auth-request.h dovecot/src/auth/auth-request.h
--- dovecot.vanilla/src/auth/auth-request.h	2006-06-23 13:42:22.123507928 +0400
+++ dovecot/src/auth/auth-request.h	2006-06-23 13:44:31.427850680 +0400
@@ -59,6 +59,7 @@ struct auth_request {
 	union {
 		verify_plain_callback_t *verify_plain;
 		lookup_credentials_callback_t *lookup_credentials;
+		set_credentials_callback_t *set_credentials;
                 userdb_callback_t *userdb;
 	} private_callback;
         enum passdb_credentials credentials;
@@ -149,6 +150,10 @@ void auth_request_verify_plain_callback(
 void auth_request_lookup_credentials_callback(enum passdb_result result,
 					      const char *credentials,
 					      struct auth_request *request);
+void auth_request_set_credentials(struct auth_request *request,
+				  enum passdb_credentials credentials,
+				  const char *data,
+				  set_credentials_callback_t *callback);
 void auth_request_userdb_callback(struct auth_stream_reply *reply,
 				  struct auth_request *request);
 
diff -urdpNX /usr/share/dontdiff -x Makefile dovecot.vanilla/src/auth/passdb.h dovecot/src/auth/passdb.h
--- dovecot.vanilla/src/auth/passdb.h	2006-06-23 13:44:31.413852808 +0400
+++ dovecot/src/auth/passdb.h	2006-06-23 13:44:31.427850680 +0400
@@ -37,6 +37,8 @@ typedef void verify_plain_callback_t(enu
 typedef void lookup_credentials_callback_t(enum passdb_result result,
 					   const char *password,
 					   struct auth_request *request);
+typedef void set_credentials_callback_t(enum passdb_result result,
+					struct auth_request *request);
 
 struct passdb_module_interface {
 	const char *name;
@@ -54,6 +56,11 @@ struct passdb_module_interface {
 	   auth_request->credentials. */
 	void (*lookup_credentials)(struct auth_request *request, 
 				   lookup_credentials_callback_t *callback);
+
+	/* Update credentials */
+	int (*set_credentials)(struct auth_request *request,
+			       const char *new_credentials,
+			       set_credentials_callback_t *callback);
 };
 
 struct passdb_module {



More information about the dovecot mailing list