]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
acl: Add acl_id_is_valid()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 22 Apr 2026 12:43:58 +0000 (15:43 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 1 May 2026 06:08:53 +0000 (06:08 +0000)
Returns TRUE if the ACL identifier string is at most ACL_ID_MAX_LEN
(1024) bytes long, contains no control characters and is valid UTF-8.

src/plugins/acl/acl-rights.c
src/plugins/acl/acl-rights.h

index 654ee00aefd1602358a532914de62626a34cc3ad..5729f8b52aa0d2593f40f91d68e850fb47b129fc 100644 (file)
@@ -3,11 +3,14 @@
 #include "lib.h"
 #include "array.h"
 #include "str.h"
+#include "unichar.h"
 /* <settings checks> */
 #include "strescape.h"
 /* </settings checks> */
 #include "acl-api-private.h"
 
+#include <ctype.h>
+
 /* <settings checks> */
 const struct acl_letter_map acl_letter_map[] = {
        { 'l', MAIL_ACL_LOOKUP },
@@ -44,6 +47,19 @@ static_assert(N_ELEMENTS(acl_letter_map) == N_ELEMENTS(all_mailbox_rights),
 
 /* </settings checks> */
 
+bool acl_id_is_valid(const char *id)
+{
+       size_t len = strlen(id);
+
+       if (len > ACL_ID_MAX_LEN)
+               return FALSE;
+       for (size_t i = 0; i < len; i++) {
+               if (i_iscntrl(id[i]))
+                       return FALSE;
+       }
+       return uni_utf8_data_is_valid((const unsigned char *)id, len);
+}
+
 void acl_rights_write_id(string_t *dest, const struct acl_rights *right)
 {
        switch (right->id_type) {
index 88ef73e3b4794715a86c9364a8e90b25fd2b409b..32163e7c3d7d62bf0bee34fe6685b5746a5d4d28 100644 (file)
@@ -34,6 +34,8 @@
 #define ACL_ID_NAME_GROUP_PREFIX "group="
 #define ACL_ID_NAME_GROUP_OVERRIDE_PREFIX "group-override="
 
+#define ACL_ID_MAX_LEN 1024
+
 struct acl_letter_map {
        const char letter;
        const char *name;
@@ -104,6 +106,10 @@ struct acl_rights_update {
        time_t last_change;
 };
 
+/* Returns TRUE if the ACL identifier string is valid: no longer than
+   ACL_ID_MAX_LEN bytes, no control characters and valid UTF-8. */
+bool acl_id_is_valid(const char *id);
+
 /* Returns the canonical ID for the right. */
 const char *acl_rights_get_id(const struct acl_rights *right);