From 0e8a0f3bd4b0e1f4bebb70317ff60ce7339a520d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 29 Jul 2024 04:24:30 -0700 Subject: [PATCH] smbd: Simplify check_user_ok() Don't walk the cache at all if we get UID_FIELD_INVALID Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/smbd/uid.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 2f390651a0e..e8f51003a1e 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -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; ivuid_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; ivuid_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); } }