]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:dsdb: let samaccountname_bad_chars_check() use strstr_for_invalid_account_characters() gitlab/master
authorStefan Metzmacher <metze@samba.org>
Thu, 23 Apr 2026 17:11:49 +0000 (19:11 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 27 May 2026 09:42:29 +0000 (09:42 +0000)
We don't need this logic twice...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Wed May 27 09:42:29 UTC 2026 on atb-devel-224

source4/dsdb/samdb/ldb_modules/samldb.c

index d5c0efd8710cabf4da030184e113dd08dbac6fcc..625e812e91df86843c1afa43afc8602626a7bbcf 100644 (file)
@@ -358,42 +358,41 @@ static int samaccountname_bad_chars_check(struct samldb_ctx *ac,
         * Additionally, Samba collapses multiple spaces, and Windows doesn't.
         */
        struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
-       size_t i;
+       const char *inv = NULL;
 
-       for (i = 0; name[i] != '\0'; i++) {
-               uint8_t c = name[i];
-               const char *p = NULL;
+       inv = strstr_for_invalid_account_characters(name);
+       if (inv != NULL) {
+               char c = *inv;
 
-               if (c < 32 || c == 127) {
+               if (c == '\0') {
                        ldb_asprintf_errstring(
                                ldb,
-                               "samldb: sAMAccountName contains invalid "
-                               "0x%.2x character\n", c);
+                               "samldb: sAMAccountName is empty\n");
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
-               p = strchr("\"[]:;|=+*?<>/\\,", c);
-               if (p != NULL) {
+
+               if (c == '.') {
+                       ldb_asprintf_errstring(
+                               ldb,
+                               "samldb: sAMAccountName ends with '.'");
+                       return LDB_ERR_CONSTRAINT_VIOLATION;
+               }
+
+               if (isprint(c)) {
                        ldb_asprintf_errstring(
                                ldb,
                                "samldb: sAMAccountName contains invalid "
                                "'%c' character\n", c);
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
-       }
 
-       if (i == 0) {
                ldb_asprintf_errstring(
                        ldb,
-                       "samldb: sAMAccountName is empty\n");
+                       "samldb: sAMAccountName contains invalid "
+                       "0x%.2x character\n", c);
                return LDB_ERR_CONSTRAINT_VIOLATION;
        }
 
-       if (name[i - 1] == '.') {
-               ldb_asprintf_errstring(
-                       ldb,
-                       "samldb: sAMAccountName ends with '.'");
-               return LDB_ERR_CONSTRAINT_VIOLATION;
-       }
        return LDB_SUCCESS;
 }