[Samba] Question about smbc_stat() and smbc_statvfs() in libsmbclient

Peter Eriksson pen at lysator.liu.se
Mon May 25 21:36:18 UTC 2020

I’ve been writing some code that uses libsmbclient to talk to SMB servers and I’m a little bit confused why ‘smbc_stat()’ sets the
st_uid & st_gid to the uid & gid of the process calling it, instead of trying to map the real owner & group of the path or setting it to -1:-1 if it can’t do that...

But there is probably some good reason for this?

Ie, if I call something like this:

> main() {
>  struct stat sb;
>  …(connect to share etc)
> smbc_stat(“smb://user@server/share/dir <smb://user@server/share/dir>”, &sb);
> printf(“uid = %d, gid = %d\n”, sb.st_uid, sb.st_gid);
> }

Then my local uid&gid will be printed and not the owner of ‘dir’ (not even the user I’m connecting as).

I can get the real owner & group via:

>  const char *owner_attr = "system.nt_sec_desc.owner+";
>  const char *group_attr = "system.nt_sec_desc.group+";
>  char buf[256];
> smbc_getxattr(path, owner_attr, buf, sizeof(buf)):
> printf("Owner='%s'\n", path, buf);
> smbc_getxattr(path, group_attr, buf, sizeof(buf)) < 0)
> printf(“Group=%s\n”, buf);

(And then manually translating the username & group in but to an uid/gid - so I can work around it but it’s annoying anyway :-)

Also, the smbc_statvfs() function assigns the “f_frsize” to some silly value (2 for me) instead of a more realistic value. I’m assuming this is because that value never is sent over the “wire”?

- Peter

More information about the samba mailing list