[Samba] Fruit & uchg

Andrew Walker walker.aj325 at gmail.com
Wed Apr 28 16:36:43 UTC 2021


On Wed, Apr 28, 2021 at 12:12 PM Jeremy Allison <jra at samba.org> wrote:

> On Wed, Apr 28, 2021 at 08:43:50AM -0400, Andrew Walker via samba wrote:
> >>
> >> A script could of course set the flag completely from the client side,
> >> finding files through AFP that have uchg set and set it on the same file
> >> through SMB. Probably easier to do it that way anyway but I’m still
> >> interested what actually gets stored in that attribute.
> >>
> >
> https://gitlab.com/samba-team/devel/samba/-/raw/master/librpc/idl/xattr.idl
> >
> >This should give an idea about what's stored in the xattr.
>
> You can also unpack/pack them with ndrdump I think.
>
> $ ndrdump xattr
> Usage: ndrdump [-?V] [-?|--help] [--usage] [-c|--context-file=CTX-FILE]
> [--validate] [--dump-data] [-l|--load-dso=STRING] [--ndr64]
>          [--quiet] [--base64-input] [--hex-input] [--input=INPUT]
> [--print-after-parse-failure] [-d|--debuglevel=DEBUGLEVEL] [--debug-stderr]
>          [-s|--configfile=CONFIGFILE] [--option=name=value]
> [-l|--log-basename=LOGFILEBASE] [--leak-report] [--leak-report-full]
>          [-V|--version] <pipe|uuid> <format> <in|out|struct> [<filename>]
>
> You must specify a function
> known functions on 'xattr' are:
> known public structures on 'xattr' are:
>         xattr_DosAttrib
>         xattr_DOSATTRIB
>         xattr_DosEAs
>         tdb_xattrs
>         xattr_DosStreams
>         security_descriptor_hash_v2
>         security_descriptor_hash_v3
>         security_descriptor_hash_v4
>         xattr_NTACL
>         xattr_sys_acl_hash_wrapper
>
> xattr_DOSATTRIB is the one you want I think.
>

Same can be done through python bindings:

>> from samba.ndr import ndr_unpack, ndr_pack
>>> from samba.dcerpc import xattr
>>> import samba.xattr_native
>>> from samba.samba3 import libsmb_samba_internal as libsmb
^^^ import all the things

>>> attr = samba.xattr_native.wrap_getxattr("/mnt/dozer/POSIX/dump.txt",
"user.DOSATTRIB")
>>> dosinfo = ndr_unpack(samba.dcerpc.xattr.DOSATTRIB, attr)
^^^ get the xattr and unpack it

>>> dosinfo.info.attrib
32
>>> bool(dosinfo.info.attrib & libsmb.FILE_ATTRIBUTE_ARCHIVE)
True
>>> bool(dosinfo.info.attrib & libsmb.FILE_ATTRIBUTE_READONLY)
False
^^^ yay, we have DOS attributes

>>> dosinfo.info.attrib |= libsmb.FILE_ATTRIBUTE_READONLY
>>> dosinfo.info.attrib
33
^^^ make some changes

>>> new_dosinfo = ndr_pack(dosinfo)
>>> samba.xattr_native.wrap_setxattr("/mnt/dozer/POSIX/dump.txt",
"user.DOSATTRIB", new_dosinfo)
^^^ repack and write

>>> newattr = samba.xattr_native.wrap_getxattr("/mnt/dozer/POSIX/dump.txt",
"user.DOSATTRIB")
>>> finaldosinfo = ndr_unpack(samba.dcerpc.xattr.DOSATTRIB, newattr)
>>> finaldosinfo.info.attrib
33
>>> quit()
^^^ verify it was written

truenas# smbclient //127.0.0.1/POSIX -U smbuser
Enter WORKGROUP\smbuser's password:
Try "help" to get a list of possible commands.
smb: \> allinfo dump.txt
altname: dump.txt
create_time:    Fri Apr 23 17:49:40 2021 PDT
access_time:    Wed Apr 28 06:06:35 2021 PDT
write_time:     Fri Apr 23 17:59:47 2021 PDT
change_time:    Fri Apr 23 17:59:47 2021 PDT
attributes: RA (21)
stream: [:com.apple.TextEncoding:$DATA], 15 bytes
stream: [:com.apple.lastuseddate#PS:$DATA], 16 bytes
stream: [:com.apple.macl:$DATA], 72 bytes
stream: [:com.apple.metadatakMDLabel_anemgxoe73iplck2hfuumqxdbu:$DATA], 89
bytes
stream: [::$DATA], 319707 bytes
smb: \>

^^^ and we can see it via smbclient


More information about the samba mailing list