[PATCH 15/18] s4: reimplement set/getntacl in python
Matthieu Patou
mat at matws.net
Sun Jan 10 16:24:49 MST 2010
---
source4/scripting/python/samba/netcmd/__init__.py | 2 +
source4/scripting/python/samba/netcmd/ntacl.py | 97 +++++++++++++
source4/utils/config.mk | 34 -----
source4/utils/getntacl.c | 159 ---------------------
source4/utils/setntacl.c | 122 ----------------
5 files changed, 99 insertions(+), 315 deletions(-)
create mode 100644 source4/scripting/python/samba/netcmd/ntacl.py
delete mode 100644 source4/utils/getntacl.c
delete mode 100644 source4/utils/setntacl.c
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index a204ab8..d6a130c 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -143,3 +143,5 @@ from samba.netcmd.enableaccount import cmd_enableaccount
commands["enableaccount"] = cmd_enableaccount()
from samba.netcmd.newuser import cmd_newuser
commands["newuser"] = cmd_newuser()
+from samba.netcmd.ntacl import cmd_acl
+commands["acl"] = cmd_acl()
diff --git a/source4/scripting/python/samba/netcmd/ntacl.py b/source4/scripting/python/samba/netcmd/ntacl.py
new file mode 100644
index 0000000..b5a4acf
--- /dev/null
+++ b/source4/scripting/python/samba/netcmd/ntacl.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+#
+# Manipulate file NT ACLs
+#
+# Copyright Matthieu Patou 2010 <mat at matws.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import samba.getopt as options
+from samba.dcerpc import security
+from samba.ntacls import setntacl, getntacl
+import ldb
+
+from samba.auth import system_session
+from samba.netcmd import (
+ Command,
+ SuperCommand,
+ CommandError,
+ Option,
+ )
+
+class cmd_acl_set(Command):
+ """Set ACLs on a file"""
+ synopsis = "%prog set <acl> <file> [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
+
+ takes_optiongroups = {
+ "sambaopts": options.SambaOptions,
+ "credopts": options.CredentialsOptions,
+ "versionopts": options.VersionOptions,
+ }
+
+ takes_options = [
+ Option("--quiet", help="Be quiet", action="store_true"),
+ Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
+ choices=["native","tdb"]),
+ Option("--eadb-file", help="Name of the tdb file where attributes are stored", type="string"),
+ ]
+
+ takes_args = ["acl","file"]
+
+ def run(self, acl, file, quiet=False,xattr_backend=None,eadb_file=None,
+ credopts=None, sambaopts=None, versionopts=None):
+ lp = sambaopts.get_loadparm()
+ creds = credopts.get_credentials(lp)
+ setntacl(lp,file,acl,xattr_backend,eadb_file)
+
+class cmd_acl_get(Command):
+ """Set ACLs on a file"""
+ synopsis = "%prog get <file> [--as-sddl] [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
+
+ takes_optiongroups = {
+ "sambaopts": options.SambaOptions,
+ "credopts": options.CredentialsOptions,
+ "versionopts": options.VersionOptions,
+ }
+
+ takes_options = [
+ Option("--as-sddl", help="Output ACL in the SDDL format", action="store_true"),
+ Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
+ choices=["native","tdb"]),
+ Option("--eadb-file", help="Name of the tdb file where attributes are stored", type="string"),
+ ]
+
+ takes_args = ["file"]
+
+ def run(self, file, as_sddl=False,xattr_backend=None,eadb_file=None,
+ credopts=None, sambaopts=None, versionopts=None):
+ lp = sambaopts.get_loadparm()
+ creds = credopts.get_credentials(lp)
+ acl = getntacl(lp,file,xattr_backend,eadb_file)
+ if as_sddl:
+ anysid=security.dom_sid(security.SID_NT_SELF)
+ print acl.info.as_sddl(anysid)
+ else:
+ acl.dump()
+
+
+class cmd_acl(SuperCommand):
+ """NT ACLs manipulation"""
+
+ subcommands = {}
+ subcommands["set"] = cmd_acl_set()
+ subcommands["get"] = cmd_acl_get()
+
diff --git a/source4/utils/config.mk b/source4/utils/config.mk
index 9b6a2f1..c420ae4 100644
--- a/source4/utils/config.mk
+++ b/source4/utils/config.mk
@@ -23,41 +23,7 @@ ntlm_auth_OBJ_FILES = $(utilssrcdir)/ntlm_auth.o
MANPAGES += $(utilssrcdir)/man/ntlm_auth.1
-#################################
-# Start BINARY getntacl
-[BINARY::getntacl]
-INSTALLDIR = BINDIR
-PRIVATE_DEPENDENCIES = \
- LIBSAMBA-HOSTCONFIG \
- LIBSAMBA-UTIL \
- POPT_SAMBA \
- NDR_XATTR \
- WRAP_XATTR \
- LIBSAMBA-ERRORS
-
-getntacl_OBJ_FILES = $(utilssrcdir)/getntacl.o
-
-# End BINARY getntacl
-#################################
-
-MANPAGES += $(utilssrcdir)/man/getntacl.1
-#################################
-# Start BINARY setntacl
-[BINARY::setntacl]
-INSTALLDIR = BINDIR
-PRIVATE_DEPENDENCIES = \
- LIBSAMBA-HOSTCONFIG \
- LIBSAMBA-UTIL \
- POPT_SAMBA \
- NDR_XATTR \
- WRAP_XATTR \
- LIBSAMBA-ERRORS
-
-setntacl_OBJ_FILES = $(utilssrcdir)/setntacl.o
-
-# End BINARY getntacl
-#################################
#################################
# Start BINARY generateblob
diff --git a/source4/utils/getntacl.c b/source4/utils/getntacl.c
deleted file mode 100644
index f75920c..0000000
--- a/source4/utils/getntacl.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Get NT ACLs from UNIX files.
-
- Copyright (C) Tim Potter <tpot at samba.org> 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "libcli/security/security.h"
-#include "system/filesys.h"
-#include "librpc/gen_ndr/ndr_xattr.h"
-#include "lib/cmdline/popt_common.h"
-#include "param/param.h"
-#include "param/loadparm.h"
-
-
-static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
-
-static void ntacl_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
-{
- va_list ap;
- char *s = NULL;
- int i;
-
- va_start(ap, format);
- vasprintf(&s, format, ap);
- va_end(ap);
-
- for (i=0;i<ndr->depth;i++) {
- printf(" ");
- }
-
- printf("%s\n", s);
- free(s);
-}
-
-static NTSTATUS get_ntacl(TALLOC_CTX *mem_ctx,
- char *filename,
- struct xattr_NTACL **ntacl,
- ssize_t *ntacl_len)
-{
- DATA_BLOB blob;
- ssize_t size;
- enum ndr_err_code ndr_err;
- struct ndr_pull *ndr;
-
- *ntacl = talloc(mem_ctx, struct xattr_NTACL);
-
- size = wrap_getxattr(filename, XATTR_NTACL_NAME, NULL, 0);
-
- if (size < 0) {
- fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- blob.data = talloc_array(*ntacl, uint8_t, size);
- size = wrap_getxattr(filename, XATTR_NTACL_NAME, blob.data, size);
- if (size < 0) {
- fprintf(stderr, "get_ntacl: %s\n", strerror(errno));
- return NT_STATUS_INTERNAL_ERROR;
- }
- blob.length = size;
-
- ndr = ndr_pull_init_blob(&blob, NULL, NULL);
-
- ndr_err = ndr_pull_xattr_NTACL(ndr, NDR_SCALARS|NDR_BUFFERS, *ntacl);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- return ndr_map_error2ntstatus(ndr_err);
- }
-
- return NT_STATUS_OK;
-}
-
-static void print_ntacl_sddl(TALLOC_CTX *mem_ctx,
- struct xattr_NTACL *ntacl)
-{
- const char *sddl;
- sddl = sddl_encode(mem_ctx,ntacl->info.sd,NULL);
- printf("%s\n",sddl);
-}
-static void print_ntacl(TALLOC_CTX *mem_ctx,
- const char *fname,
- struct xattr_NTACL *ntacl)
-{
- struct ndr_print *pr;
-
- pr = talloc_zero(mem_ctx, struct ndr_print);
- if (!pr) return;
- pr->print = ntacl_print_debug_helper;
-
- ndr_print_xattr_NTACL(pr, fname, ntacl);
- talloc_free(pr);
-}
-
-int main(int argc, const char *argv[])
-{
- int ret = 0;
- NTSTATUS status;
- struct xattr_NTACL *ntacl;
- ssize_t ntacl_len;
- int print_as_sddl = 0;
- char *readfile = NULL;
- poptContext pc;
- struct loadparm_context *lp_ctx;
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- {"as-sddl", '\0', POPT_ARG_NONE, &print_as_sddl, true, "Print NT ACL as SDDL"},
- POPT_COMMON_SAMBA
- POPT_COMMON_VERSION
- { NULL }
- };
-
- setup_logging(NULL, DEBUG_STDERR);
-
- pc = poptGetContext(NULL, argc, argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
- poptSetOtherOptionHelp(pc, "[OPTION(S)...] file");
-
- while(poptGetNextOpt(pc) != -1);
- // Skip programe name
- poptGetArg(pc);
- if(poptPeekArg(pc)) {
- readfile = strdup(poptGetArg(pc));
- }
-
-
- lp_ctx = cmdline_lp_ctx;
-
- status = get_ntacl(NULL, readfile, &ntacl, &ntacl_len);
-
- if (!NT_STATUS_IS_OK(status)) {
- fprintf(stderr, "get_ntacl failed: %s\n", nt_errstr(status));
- return 1;
- }
-
- if( print_as_sddl ) {
- print_ntacl_sddl(ntacl, ntacl);
- } else {
- print_ntacl(ntacl, readfile, ntacl);
- }
-
- talloc_free(ntacl);
-
- return 0;
-}
diff --git a/source4/utils/setntacl.c b/source4/utils/setntacl.c
deleted file mode 100644
index 4db608c..0000000
--- a/source4/utils/setntacl.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Get NT ACLs from UNIX files.
-
- Copyright (C) Tim Potter <tpot at samba.org> 2005
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "libcli/security/security.h"
-#include "librpc/gen_ndr/ndr_xattr.h"
-#include "param/param.h"
-#include "lib/cmdline/popt_common.h"
-#include "param/param.h"
-#include "param/loadparm.h"
-
-static NTSTATUS build_acl(TALLOC_CTX *mem_ctx, char* acls, struct xattr_NTACL **ntacl)
-{
- struct xattr_NTACL *acl = talloc(mem_ctx, struct xattr_NTACL);
- struct security_descriptor *sd;
- NTSTATUS status;
- sd = sddl_decode(mem_ctx,acls,NULL);
- if( !sd )
- {
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- acl->version = 1;
- acl->info.sd = sd;
-
- *ntacl = acl;
- return NT_STATUS_OK;
-}
-
-static NTSTATUS set_ntacl(TALLOC_CTX *mem_ctx,
- char *filename,
- void *ntacl)
-{
- enum ndr_err_code ndr_err;
- int ret;
- DATA_BLOB blob;
-
- ndr_err = ndr_push_struct_blob(&blob, mem_ctx, lp_iconv_convenience(NULL), ntacl ,(ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
- if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
- return ndr_map_error2ntstatus(ndr_err);
- }
- ret = wrap_setxattr(filename, XATTR_NTACL_NAME, blob.data,blob.length, 0);
-
- if (ret != 0) {
- fprintf(stderr, "set_ntacl: %s\n", strerror(errno));
- return NT_STATUS_INTERNAL_ERROR;
- }
- return NT_STATUS_OK;
-}
-
-int main(int argc, const char *argv[])
-{
- NTSTATUS status;
- char *acl = NULL;
- char *writtenfile = NULL;
- struct xattr_NTACL *ntacl;
- poptContext pc;
- struct loadparm_context *lp_ctx;
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- POPT_COMMON_SAMBA
- POPT_COMMON_VERSION
- { NULL }
- };
-
- setup_logging(NULL, DEBUG_STDERR);
-
- pc = poptGetContext(NULL, argc, argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
- poptSetOtherOptionHelp(pc, "[OPTION(S)...] acl file\nacl must be in SDDL format check documentation for more information");
-
- while(poptGetNextOpt(pc) != -1);
- // Skip program name
- poptGetArg(pc);
- if(poptPeekArg(pc)) {
- acl = strdup(poptGetArg(pc));
- }
-
- if(poptPeekArg(pc)) {
- writtenfile = strdup(poptGetArg(pc));
- }
-
- if ( !acl || !writtenfile ) {
- fprintf(stderr,"ACL and/or file to be written are missing !\nThese parameters are mandatory\n");
- exit(1);
- }
-
- lp_ctx = cmdline_lp_ctx;
-
- status = build_acl(NULL, acl, &ntacl);
- if (!NT_STATUS_IS_OK(status)) {
- fprintf(stderr, "build_acl failed: %s\n", nt_errstr(status));
- return 1;
- }
- status = set_ntacl(NULL, writtenfile, ntacl);
- if (!NT_STATUS_IS_OK(status)) {
- fprintf(stderr, "set_ntacl failed: %s\n", nt_errstr(status));
- return 1;
- }
-
- talloc_free(ntacl);
-
- return 0;
-}
--
1.6.3.3
--------------080603070205020905060303
Content-Type: text/x-patch;
name="0016-upgradeprovision-never-use-xattr-it-s-pointless-in-t.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0016-upgradeprovision-never-use-xattr-it-s-pointless-in-t.pa";
filename*1="tch"
More information about the samba-technical
mailing list