samba-tool: add command to dump dosinfo xattr from a file
authorRalph Boehme <slow@samba.org>
Fri, 25 Sep 2015 23:16:50 +0000 (01:16 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 29 Sep 2015 04:00:49 +0000 (06:00 +0200)
Add a new command "getdosinfo" to samba-tool to dump dosinfo xattr from
a file.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Tue Sep 29 06:00:49 CEST 2015 on sn-devel-104

librpc/idl/xattr.idl
python/samba/netcmd/ntacl.py
python/samba/ntacls.py

index b4c1b98b21fbdaec2fbd61f0b71eafe529861fc4..efbc84e3fa69e6f415db494b5816226494e1bddc 100644 (file)
@@ -20,6 +20,7 @@ import "security.idl";
 interface xattr
 {
        const char *XATTR_DOSATTRIB_NAME = "user.DosAttrib";
+       const char *XATTR_DOSATTRIB_NAME_S3 = "user.DOSATTRIB";
        const int XATTR_DOSATTRIB_ESTIMATED_SIZE = 64;
 
        /* we store basic dos attributes in a DosAttrib xattr. By
index dff1550ede7689ca0f2ed030f5c710545f933db5..eaea0e7af1711729b2bbb3b85a3a3b9e4f378c3a 100644 (file)
@@ -19,7 +19,7 @@
 from samba.credentials import DONT_USE_KERBEROS
 import samba.getopt as options
 from samba.dcerpc import security, idmap
-from samba.ntacls import setntacl, getntacl
+from samba.ntacls import setntacl, getntacl,getdosinfo
 from samba import Ldb
 from samba.ndr import ndr_unpack, ndr_print
 from samba.samdb import SamDB
@@ -95,6 +95,27 @@ class cmd_ntacl_set(Command):
             logger.warning("Please note that POSIX permissions have NOT been changed, only the stored NT ACL")
 
 
+class cmd_dosinfo_get(Command):
+    """Get DOS info of a file from xattr."""
+    synopsis = "%prog <file> [options]"
+
+    takes_optiongroups = {
+        "sambaopts": options.SambaOptions,
+        "credopts": options.CredentialsOptions,
+        "versionopts": options.VersionOptions,
+        }
+
+    takes_args = ["file"]
+
+    def run(self, file, credopts=None, sambaopts=None, versionopts=None):
+        lp = sambaopts.get_loadparm()
+        s3conf = s3param.get_context()
+        s3conf.load(lp.configfile)
+
+        dosinfo = getdosinfo(lp, file)
+        if dosinfo:
+            self.outf.write(ndr_print(dosinfo))
+
 class cmd_ntacl_get(Command):
     """Get ACLs of a file."""
     synopsis = "%prog <file> [options]"
@@ -257,4 +278,5 @@ class cmd_ntacl(SuperCommand):
     subcommands["get"] = cmd_ntacl_get()
     subcommands["sysvolreset"] = cmd_ntacl_sysvolreset()
     subcommands["sysvolcheck"] = cmd_ntacl_sysvolcheck()
+    subcommands["getdosinfo"] = cmd_dosinfo_get()
 
index 53438d84bffbc088e3aa0d177b728a2797407c05..0eeb4977c12215247507736d1907b4d0e216ac46 100644 (file)
@@ -54,6 +54,14 @@ def checkset_backend(lp, backend, eadbfile):
     else:
         raise XattrBackendError("Invalid xattr backend choice %s"%backend)
 
+def getdosinfo(lp, file):
+    try:
+        attribute = samba.xattr_native.wrap_getxattr(file,
+                                                     xattr.XATTR_DOSATTRIB_NAME_S3)
+    except Exception:
+        return
+
+    return ndr_unpack(xattr.DOSATTRIB, attribute)
 
 def getntacl(lp, file, backend=None, eadbfile=None, direct_db_access=True, service=None):
     if direct_db_access: