]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmbclient: Allow O_PATH for smbc_open()
authorVolker Lendecke <vl@samba.org>
Tue, 29 Apr 2025 12:04:26 +0000 (14:04 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 16 Jun 2025 15:05:32 +0000 (15:05 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/libsmb/libsmb_file.c

index 2b29287200f95802045e8cfd68a7c3db057968eb..14a567f67d20ec5d3622b948c5f9df30e6d06a62 100644 (file)
@@ -139,8 +139,44 @@ SMBC_open_ctx(SMBCCTX *context,
        }
        /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/
 
-       status = cli_open(targetcli, targetpath, flags,
-                         context->internal->share_mode, &fd);
+       /*
+        * Random error that the O_PATH if-block will never return
+        */
+       status = NT_STATUS_LDAP(0);
+
+#ifdef O_PATH
+       if (flags & O_PATH) {
+               if ((flags & ~O_PATH) != 0) {
+                       SAFE_FREE(file);
+                       TALLOC_FREE(frame);
+                       errno = EINVAL;
+                       return NULL;
+               }
+               status = cli_ntcreate(
+                       targetcli,  /* cli */
+                       targetpath, /* fname */
+                       0,          /* CreateFlags */
+                       SEC_FILE_READ_ATTRIBUTE | SEC_FILE_READ_EA |
+                       SEC_STD_READ_CONTROL, /* DesiredAccess
+                                              */
+                       0, /* FileAttributes */
+                       FILE_SHARE_READ | FILE_SHARE_WRITE |
+                       FILE_SHARE_DELETE, /* ShareAccess */
+                       FILE_OPEN, /* CreateDisposition */
+                       0x0,       /* CreateOptions */
+                       0x0,       /* SecurityFlags */
+                       &fd,       /* pfid */
+                       NULL);     /* cr */
+       }
+#endif
+       if (NT_STATUS_EQUAL(status, NT_STATUS_LDAP(0))) {
+               status = cli_open(targetcli,
+                                 targetpath,
+                                 flags,
+                                 context->internal->share_mode,
+                                 &fd);
+       }
+
        if (!NT_STATUS_IS_OK(status)) {
 
                /* Handle the error ... */