From 4b3b283b1f3bf7192e9a9c849ed2d6006f96350a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 11 Oct 2024 13:29:33 +0200 Subject: [PATCH] smbd: Simplify make_connection_snum() Avoid nested if's, don't check for ISDIR twice Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/smbd/smb2_service.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/source3/smbd/smb2_service.c b/source3/smbd/smb2_service.c index b6e8ca54e85..7d241887399 100644 --- a/source3/smbd/smb2_service.c +++ b/source3/smbd/smb2_service.c @@ -785,22 +785,26 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn, I have disabled this chdir check (tridge) */ /* the alternative is just to check the directory exists */ - if ((ret = SMB_VFS_STAT(conn, smb_fname_cpath)) != 0 || - !S_ISDIR(smb_fname_cpath->st.st_ex_mode)) { - if (ret == 0 && !S_ISDIR(smb_fname_cpath->st.st_ex_mode)) { - DBG_ERR("'%s' is not a directory, when connecting to " - "[%s]\n", conn->connectpath, - lp_const_servicename(snum)); - } else { - DBG_ERR("'%s' does not exist or permission denied " - "when connecting to [%s] Error was %s\n", - conn->connectpath, - lp_const_servicename(snum), - strerror(errno)); - } + ret = SMB_VFS_STAT(conn, smb_fname_cpath); + if (ret != 0) { + DBG_ERR("'%s' does not exist or permission denied " + "when connecting to [%s] Error was %s\n", + conn->connectpath, + lp_const_servicename(snum), + strerror(errno)); status = NT_STATUS_BAD_NETWORK_NAME; goto err_root_exit; } + + if (!S_ISDIR(smb_fname_cpath->st.st_ex_mode)) { + DBG_ERR("'%s' is not a directory, when connecting to " + "[%s]\n", + conn->connectpath, + lp_const_servicename(snum)); + status = NT_STATUS_BAD_NETWORK_NAME; + goto err_root_exit; + } + conn->base_share_dev = smb_fname_cpath->st.st_ex_dev; /* Figure out the characteristics of the underlying filesystem. This