]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: auth-sasl - Add auth_sasl_request_set_authid()
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 14 Mar 2023 00:40:02 +0000 (01:40 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Oct 2025 08:41:22 +0000 (08:41 +0000)
src/auth/auth-sasl.c
src/auth/auth-sasl.h
src/auth/sasl-server.h

index 56fe0220abf70771167b0266b86df403f1f0698d..bb6d0067ae2390fb2a4269946c60a0020297655c 100644 (file)
  * Request
  */
 
+bool
+auth_sasl_request_set_authid(struct auth_request *request,
+                            enum sasl_server_authid_type authid_type,
+                            const char *authid)
+{
+       const char *error;
+
+       switch (authid_type) {
+       case SASL_SERVER_AUTHID_TYPE_USERNAME:
+               if (!auth_request_set_username(request, authid, &error)) {
+                       e_info(request->event, "%s", error);
+                       return FALSE;
+               }
+               return TRUE;
+       case SASL_SERVER_AUTHID_TYPE_ANONYMOUS:
+               i_assert(*request->set->anonymous_username != '\0');
+
+               /* Temporarily set the user to the one that was given, so that
+                  the log  message goes right */
+               auth_request_set_username_forced(request, authid);
+               e_info(request->event, "anonymous login");
+               auth_request_set_username_forced(
+                       request, request->set->anonymous_username);
+               return TRUE;
+       case SASL_SERVER_AUTHID_TYPE_EXTERNAL:
+               i_assert(authid == NULL || *authid == '\0');
+               if (request->fields.user == NULL) {
+                       e_info(request->event, "Username not known");
+                       return FALSE;
+               }
+
+               /* This call is done simply to put the username through
+                  translation settings */
+               if (!auth_request_set_username(request, "", &error)) {
+                       e_info(request->event, "Invalid username");
+                       return FALSE;
+               }
+               return TRUE;
+       }
+       i_unreached();
+}
+
 void
 auth_sasl_request_output(struct auth_request *request,
                         const struct sasl_server_output *output)
index 5cbce40c9ad1bb4ecb89ac7f08caa60af8c59a7f..a0885acd3850afce746fa0ae8277198d570bd7ac 100644 (file)
@@ -15,6 +15,11 @@ struct auth_sasl_mech_module {
  * Request
  */
 
+bool
+auth_sasl_request_set_authid(struct auth_request *request,
+                            enum sasl_server_authid_type authid_type,
+                            const char *authid);
+
 void
 auth_sasl_request_output(struct auth_request *request,
                         const struct sasl_server_output *output);
index 063c85d5376f0965e531441b18f56a26a91b5b82..423ca2ea6a41deb19d1c3e1d58055144f235701c 100644 (file)
@@ -36,4 +36,17 @@ struct sasl_server_output {
        size_t data_size;
 };
 
+/*
+ * Request
+ */
+
+enum sasl_server_authid_type {
+       /* Normal authentication ID (username) */
+       SASL_SERVER_AUTHID_TYPE_USERNAME = 0,
+       /* Anonymous credentials; there is no verified authentication ID. */
+       SASL_SERVER_AUTHID_TYPE_ANONYMOUS,
+       /* The authentication ID is set and verified by an external source. */
+       SASL_SERVER_AUTHID_TYPE_EXTERNAL,
+};
+
 #endif