Skip to content

Commit f2935d3

Browse files
vlendecslowfranklin
authored andcommitted
libsmbclient: Intercept "smb311_posix.statinfo" attribute
Directly get a "struct stat" plus a 32-bit uint32 for the dosatts Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Mon Jun 16 16:08:20 UTC 2025 on atb-devel-224
1 parent 043a675 commit f2935d3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

source3/libsmb/libsmb_xattr.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "rpc_client/cli_lsarpc.h"
3434
#include "../libcli/security/security.h"
3535
#include "lib/util/string_wrappers.h"
36+
#include "source3/include/trans2.h"
3637

3738
/*
3839
* Find an lsa pipe handle associated with a cli struct.
@@ -2251,6 +2252,70 @@ SMBC_fgetxattr_ctx(SMBCCTX *context,
22512252
return len;
22522253
}
22532254

2255+
if (strequal(name, "smb311_posix.statinfo")) {
2256+
struct stat st = {};
2257+
struct timespec t = {};
2258+
DATA_BLOB out = {};
2259+
uint32_t *_attrs = NULL;
2260+
NTSTATUS status;
2261+
2262+
if (size != (sizeof(struct stat) + 4)) {
2263+
TALLOC_FREE(frame);
2264+
errno = EINVAL;
2265+
return -1;
2266+
}
2267+
2268+
status = cli_smb2_query_info_fnum(file->targetcli,
2269+
file->cli_fd,
2270+
SMB2_0_INFO_FILE,
2271+
FSCC_FILE_POSIX_INFORMATION,
2272+
65536,
2273+
NULL,
2274+
0,
2275+
0,
2276+
frame,
2277+
&out);
2278+
if (!NT_STATUS_IS_OK(status)) {
2279+
TALLOC_FREE(frame);
2280+
errno = map_errno_from_nt_status(status);
2281+
return -1;
2282+
}
2283+
2284+
if (out.length < 80) {
2285+
TALLOC_FREE(frame);
2286+
errno = EIO;
2287+
return -1;
2288+
}
2289+
2290+
t = nt_time_to_unix_timespec(PULL_LE_U64(out.data, 8));
2291+
st.st_atime = t.tv_sec;
2292+
set_atimensec(&st, t.tv_nsec);
2293+
2294+
t = nt_time_to_unix_timespec(PULL_LE_U64(out.data, 16));
2295+
st.st_mtime = t.tv_sec;
2296+
set_mtimensec(&st, t.tv_nsec);
2297+
2298+
t = nt_time_to_unix_timespec(PULL_LE_U64(out.data, 24));
2299+
st.st_ctime = t.tv_sec;
2300+
set_ctimensec(&st, t.tv_nsec);
2301+
2302+
st.st_size = PULL_LE_U64(out.data, 32);
2303+
st.st_ino = PULL_LE_U64(out.data, 52);
2304+
st.st_dev = PULL_LE_U32(out.data, 60);
2305+
st.st_nlink = PULL_LE_U32(out.data, 68);
2306+
st.st_mode = PULL_LE_U32(out.data, 76);
2307+
2308+
memcpy(discard_const_p(char, value), &st, sizeof(struct stat));
2309+
2310+
_attrs = (uint32_t *)(discard_const_p(char, value) +
2311+
sizeof(struct stat));
2312+
*_attrs = PULL_LE_U32(out.data, 48);
2313+
2314+
TALLOC_FREE(frame);
2315+
2316+
return sizeof(struct stat);
2317+
}
2318+
22542319
ret = SMBC_getxattr_ctx(context, file->fname, name, value, size);
22552320

22562321
{

0 commit comments

Comments
 (0)