From: Volker Lendecke Date: Tue, 29 Apr 2025 12:04:26 +0000 (+0200) Subject: libsmbclient: Allow O_PATH for smbc_open() X-Git-Tag: tevent-0.17.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40d7c38abfc12c4836c828987a40f9345964f0f8;p=thirdparty%2Fsamba.git libsmbclient: Allow O_PATH for smbc_open() Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index 2b29287200f..14a567f67d2 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -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 ... */