mirror of
https://github.com/samba-team/samba.git
synced 2025-07-31 20:22:15 +03:00
ntacl: Use existing infrastructure.
This commit is contained in:
@ -18,7 +18,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
from samba import getopt as options, Ldb
|
from samba import getopt as options
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,15 +26,13 @@ from samba import Ldb
|
|||||||
from samba.ndr import ndr_unpack
|
from samba.ndr import ndr_unpack
|
||||||
|
|
||||||
from ldb import SCOPE_BASE
|
from ldb import SCOPE_BASE
|
||||||
import ldb
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from samba.auth import system_session
|
from samba.auth import system_session
|
||||||
from samba.netcmd import (
|
from samba.netcmd import (
|
||||||
Command,
|
Command,
|
||||||
SuperCommand,
|
|
||||||
CommandError,
|
CommandError,
|
||||||
|
SuperCommand,
|
||||||
Option,
|
Option,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,31 +51,33 @@ class cmd_acl_set(Command):
|
|||||||
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
|
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
|
||||||
choices=["native","tdb"]),
|
choices=["native","tdb"]),
|
||||||
Option("--eadb-file", help="Name of the tdb file where attributes are stored", type="string"),
|
Option("--eadb-file", help="Name of the tdb file where attributes are stored", type="string"),
|
||||||
]
|
]
|
||||||
|
|
||||||
takes_args = ["acl","file"]
|
takes_args = ["acl","file"]
|
||||||
|
|
||||||
def run(self, acl, file, quiet=False,xattr_backend=None,eadb_file=None,
|
def run(self, acl, file, quiet=False,xattr_backend=None,eadb_file=None,
|
||||||
credopts=None, sambaopts=None, versionopts=None):
|
credopts=None, sambaopts=None, versionopts=None):
|
||||||
lp = sambaopts.get_loadparm()
|
lp = sambaopts.get_loadparm()
|
||||||
creds = credopts.get_credentials(lp)
|
creds = credopts.get_credentials(lp)
|
||||||
path = os.path.join(lp.get("private dir"), lp.get("secrets database") or "secrets.ldb")
|
path = os.path.join(lp.get("private dir"), lp.get("secrets database") or "secrets.ldb")
|
||||||
creds = credopts.get_credentials(lp)
|
creds = credopts.get_credentials(lp)
|
||||||
creds.set_kerberos_state(DONT_USE_KERBEROS)
|
creds.set_kerberos_state(DONT_USE_KERBEROS)
|
||||||
try:
|
try:
|
||||||
ldb = Ldb(path, session_info=system_session(), credentials=creds,lp=lp)
|
ldb = Ldb(path, session_info=system_session(), credentials=creds,lp=lp)
|
||||||
except:
|
except:
|
||||||
print "Unable to read domain SID from configuration files"
|
# XXX: Should catch a particular exception type
|
||||||
sys.exit(1)
|
raise CommandError("Unable to read domain SID from configuration files")
|
||||||
attrs = ["objectSid"]
|
attrs = ["objectSid"]
|
||||||
print lp.get("realm")
|
print lp.get("realm")
|
||||||
res = ldb.search(expression="(objectClass=*)",base="flatname=%s,cn=Primary Domains"%lp.get("workgroup"), scope=SCOPE_BASE, attrs=attrs)
|
res = ldb.search(expression="(objectClass=*)",
|
||||||
if len(res) !=0:
|
base="flatname=%s,cn=Primary Domains" % lp.get("workgroup"),
|
||||||
domainsid = ndr_unpack( security.dom_sid,res[0]["objectSid"][0])
|
scope=SCOPE_BASE, attrs=attrs)
|
||||||
setntacl(lp,file,acl,str(domainsid),xattr_backend,eadb_file)
|
if len(res) !=0:
|
||||||
else:
|
domainsid = ndr_unpack(security.dom_sid, res[0]["objectSid"][0])
|
||||||
print "Unable to read domain SID from configuration files"
|
setntacl(lp, file, acl, str(domainsid), xattr_backend, eadb_file)
|
||||||
sys.exit(1)
|
else:
|
||||||
|
raise CommandError("Unable to read domain SID from configuration files")
|
||||||
|
|
||||||
|
|
||||||
class cmd_acl_get(Command):
|
class cmd_acl_get(Command):
|
||||||
"""Set ACLs on a file"""
|
"""Set ACLs on a file"""
|
||||||
@ -98,13 +98,13 @@ class cmd_acl_get(Command):
|
|||||||
|
|
||||||
takes_args = ["file"]
|
takes_args = ["file"]
|
||||||
|
|
||||||
def run(self, file, as_sddl=False,xattr_backend=None,eadb_file=None,
|
def run(self, file, as_sddl=False, xattr_backend=None, eadb_file=None,
|
||||||
credopts=None, sambaopts=None, versionopts=None):
|
credopts=None, sambaopts=None, versionopts=None):
|
||||||
lp = sambaopts.get_loadparm()
|
lp = sambaopts.get_loadparm()
|
||||||
creds = credopts.get_credentials(lp)
|
creds = credopts.get_credentials(lp)
|
||||||
acl = getntacl(lp,file,xattr_backend,eadb_file)
|
acl = getntacl(lp, file, xattr_backend, eadb_file)
|
||||||
if as_sddl:
|
if as_sddl:
|
||||||
anysid=security.dom_sid(security.SID_NT_SELF)
|
anysid = security.dom_sid(security.SID_NT_SELF)
|
||||||
print acl.info.as_sddl(anysid)
|
print acl.info.as_sddl(anysid)
|
||||||
else:
|
else:
|
||||||
acl.dump()
|
acl.dump()
|
||||||
|
Reference in New Issue
Block a user