]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify check_user_ok()
authorVolker Lendecke <vl@samba.org>
Mon, 29 Jul 2024 11:24:30 +0000 (04:24 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 6 Aug 2024 16:29:33 +0000 (16:29 +0000)
Don't walk the cache at all if we get UID_FIELD_INVALID

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/uid.c

index 2f390651a0ef5fe5ff8569dd81a182c374e87822..e8f51003a1e4118a2354c5a6df4c2f7b9f5f98b3 100644 (file)
@@ -268,7 +268,6 @@ static bool check_user_ok(connection_struct *conn,
 {
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
-       unsigned int i;
        bool readonly_share = false;
        bool admin_user = false;
        struct vuid_cache_entry *ent = NULL;
@@ -276,24 +275,21 @@ static bool check_user_ok(connection_struct *conn,
        NTSTATUS status;
        bool ok;
 
-       for (i=0; i<VUID_CACHE_SIZE; i++) {
-               ent = &conn->vuid_cache->array[i];
-               if (ent->vuid == vuid) {
-                       if (vuid == UID_FIELD_INVALID) {
-                               /*
-                                * Slow path, we don't care
-                                * about the array traversal.
-                               */
-                               continue;
+       if (vuid != UID_FIELD_INVALID) {
+               unsigned int i;
+
+               for (i=0; i<VUID_CACHE_SIZE; i++) {
+                       ent = &conn->vuid_cache->array[i];
+                       if (ent->vuid == vuid) {
+                               free_conn_state_if_unused(conn);
+                               conn->session_info = ent->session_info;
+                               conn->read_only = ent->read_only;
+                               conn->share_access = ent->share_access;
+                               conn->vuid = ent->vuid;
+                               conn->veto_list = ent->veto_list;
+                               conn->hide_list = ent->hide_list;
+                               return(True);
                        }
-                       free_conn_state_if_unused(conn);
-                       conn->session_info = ent->session_info;
-                       conn->read_only = ent->read_only;
-                       conn->share_access = ent->share_access;
-                       conn->vuid = ent->vuid;
-                       conn->veto_list = ent->veto_list;
-                       conn->hide_list = ent->hide_list;
-                       return(True);
                }
        }