[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Tue Aug 2 23:50:02 MDT 2011


The branch, master has been updated
       via  f854209 s4-libcli: Fix the fd leak. Close open file descriptor before return.
       via  cff7adb samba-tool: Rename samba-tool command gpo2 --> gpo
       via  e2af384 samba-tool: Remove C version of samba-tool
       via  7d137f8 samba-tool: Add implementation of gpo create command
       via  fb798d3 samba-tool: Add functions to create directories and copy files over SMB share
       via  65dcf82 s4-libcli: get_acl and set_acl require raw_open to set security descriptor
       via  52d6023 s4-libcli: Check if short_name is not null, before converting to python string
       via  38b8d38 s4-libcli: Replace smb_composite_connect() with smb_full_connection()
       via  6cce5fd s4-policy: Use the correct local directory for stat.
       via  c670465 samba-tool: Rename copy_directory_recurse to copy_directory_remote_to_local
       via  1e36679 samba-tool: Addd functions to print GPO flags and GPlink options
       via  463ab48 s4-policy: Add python wrapper for ads_to_dir_access_mask() function
       via  0c8d742 s4-policy: Expose gp_ads_to_dir_access_mask() function
       via  2d90caf s4-libcli: Added python SMB methods for mkdir(), rmdir(), chkpath()
       via  a7f3545 pyldb: return a copy of key constant DNs via python interface
      from  785c65e We don't need check_name() here. All possible paths to dptr_create() have already called check_name.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f854209996491b34b7326c956d512f3d77db600e
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Wed Aug 3 10:50:31 2011 +1000

    s4-libcli: Fix the fd leak. Close open file descriptor before return.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User: Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date: Wed Aug  3 07:49:12 CEST 2011 on sn-devel-104

commit cff7adb7ec79feecff73415b2ef4602c2fd4b2ae
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Wed Aug 3 09:37:04 2011 +1000

    samba-tool: Rename samba-tool command gpo2 --> gpo
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit e2af38415163f248e3dbd5a2abc156761e74b87c
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Wed Aug 3 09:21:21 2011 +1000

    samba-tool: Remove C version of samba-tool
    
    Python version of samba-tool has now implemented all the commands
    from C version and more.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 7d137f8bda1cc245762f53e6e8e562dda0336bdb
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 16:13:43 2011 +1000

    samba-tool: Add implementation of gpo create command
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit fb798d35df570d7cd9ad6386595dff9c5b0321e5
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 16:13:01 2011 +1000

    samba-tool: Add functions to create directories and copy files over SMB share
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 65dcf82e644e8b57d3e09ad428a63a4708057311
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 16:10:21 2011 +1000

    s4-libcli: get_acl and set_acl require raw_open to set security descriptor
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 52d602335be1826e6a99a6470c03062ba908d373
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 16:07:43 2011 +1000

    s4-libcli: Check if short_name is not null, before converting to python string
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 38b8d38b30370bf930a647bceceed7fd407b649b
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 16:04:52 2011 +1000

    s4-libcli: Replace smb_composite_connect() with smb_full_connection()
    
    Python smb connection now uses smb_full_connection method.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 6cce5fd43e9036d2d57bb3cd9aef905463acdcce
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 2 15:13:36 2011 +1000

    s4-policy: Use the correct local directory for stat.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit c670465c23765bade0d248215cbdddafbd8468ee
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Aug 1 15:47:10 2011 +1000

    samba-tool: Rename copy_directory_recurse to copy_directory_remote_to_local
    
    gpo fetch is remote->local and gpo create is local->remote
    local is local filesystem and remote is smb share.
    Need two functions to copy local->remote and remote->local.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 1e3667934b777034d6460f938ba5093f3c913144
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Aug 1 15:41:19 2011 +1000

    samba-tool: Addd functions to print GPO flags and GPlink options
    
    Use methods from python wrapper to convert gpo flags and gplink
    options to string.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 463ab48868e917b1ccad22bfb5c3c101b6c44e7b
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Aug 1 15:35:32 2011 +1000

    s4-policy: Add python wrapper for ads_to_dir_access_mask() function
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 0c8d74299234b50c8705d7700da325146cf9a5fe
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Aug 1 14:51:25 2011 +1000

    s4-policy: Expose gp_ads_to_dir_access_mask() function
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit 2d90cafa1013204d664c94e89c6745eb546ee254
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Jul 29 16:17:49 2011 +1000

    s4-libcli: Added python SMB methods for mkdir(), rmdir(), chkpath()
    
    Updated docstrings for all methods.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

commit a7f3545b825de86f7b551d8b517031998327a92d
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 1 12:39:48 2011 +1000

    pyldb: return a copy of key constant DNs via python interface
    
    this prevents an easy coding error where the caller modifies one of
    the key DNs for the database, by using an add_child function or
    similar
    
    Pair-Programmed-With: Amitay Isaacs <amitay at gmail.com>
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/ldb/pyldb.c                                   |   25 +-
 source4/lib/policy/gp_filesys.c                   |    2 +-
 source4/lib/policy/gp_manage.c                    |    2 +-
 source4/lib/policy/policy.h                       |    1 +
 source4/lib/policy/pypolicy.c                     |   19 +-
 source4/libcli/pysmb.c                            |  253 +++++++--
 source4/samba_tool/gpo.c                          |  609 ---------------------
 source4/samba_tool/samba_tool.c                   |  385 -------------
 source4/samba_tool/samba_tool.h                   |   39 --
 source4/samba_tool/vampire.c                      |  130 -----
 source4/samba_tool/wscript_build                  |    9 -
 source4/scripting/python/samba/netcmd/__init__.py |    2 +-
 source4/scripting/python/samba/netcmd/gpo.py      |  289 +++++++++--
 wscript_build                                     |    1 -
 14 files changed, 493 insertions(+), 1273 deletions(-)
 delete mode 100644 source4/samba_tool/gpo.c
 delete mode 100644 source4/samba_tool/samba_tool.c
 delete mode 100644 source4/samba_tool/samba_tool.h
 delete mode 100644 source4/samba_tool/vampire.c
 delete mode 100644 source4/samba_tool/wscript_build


Changeset truncated at 500 lines:

diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index c92d64d..e9af227 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -589,6 +589,23 @@ static Py_ssize_t py_ldb_dn_len(PyLdbDnObject *self)
 	return ldb_dn_get_comp_num(PyLdbDn_AsDn((PyObject *)self));
 }
 
+/*
+  copy a DN as a python object
+ */
+static PyObject *py_ldb_dn_copy(struct ldb_dn *dn)
+{
+	PyLdbDnObject *py_ret;
+
+	py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0);
+	if (py_ret == NULL) {
+		PyErr_NoMemory();
+		return NULL;
+	}
+	py_ret->mem_ctx = talloc_new(NULL);
+	py_ret->dn = ldb_dn_copy(py_ret->mem_ctx, dn);
+	return (PyObject *)py_ret;
+}
+
 static PyObject *py_ldb_dn_concat(PyLdbDnObject *self, PyObject *py_other)
 {
 	struct ldb_dn *dn = PyLdbDn_AsDn((PyObject *)self), 
@@ -759,7 +776,7 @@ static PyObject *py_ldb_get_root_basedn(PyLdbObject *self)
 	struct ldb_dn *dn = ldb_get_root_basedn(PyLdb_AsLdbContext(self));
 	if (dn == NULL)
 		Py_RETURN_NONE;
-	return PyLdbDn_FromDn(dn);
+	return py_ldb_dn_copy(dn);
 }
 
 
@@ -768,7 +785,7 @@ static PyObject *py_ldb_get_schema_basedn(PyLdbObject *self)
 	struct ldb_dn *dn = ldb_get_schema_basedn(PyLdb_AsLdbContext(self));
 	if (dn == NULL)
 		Py_RETURN_NONE;
-	return PyLdbDn_FromDn(dn);
+	return py_ldb_dn_copy(dn);
 }
 
 static PyObject *py_ldb_get_config_basedn(PyLdbObject *self)
@@ -776,7 +793,7 @@ static PyObject *py_ldb_get_config_basedn(PyLdbObject *self)
 	struct ldb_dn *dn = ldb_get_config_basedn(PyLdb_AsLdbContext(self));
 	if (dn == NULL)
 		Py_RETURN_NONE;
-	return PyLdbDn_FromDn(dn);
+	return py_ldb_dn_copy(dn);
 }
 
 static PyObject *py_ldb_get_default_basedn(PyLdbObject *self)
@@ -784,7 +801,7 @@ static PyObject *py_ldb_get_default_basedn(PyLdbObject *self)
 	struct ldb_dn *dn = ldb_get_default_basedn(PyLdb_AsLdbContext(self));
 	if (dn == NULL)
 		Py_RETURN_NONE;
-	return PyLdbDn_FromDn(dn);
+	return py_ldb_dn_copy(dn);
 }
 
 static const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list, 
diff --git a/source4/lib/policy/gp_filesys.c b/source4/lib/policy/gp_filesys.c
index 00d04d5..6e0cbed 100644
--- a/source4/lib/policy/gp_filesys.c
+++ b/source4/lib/policy/gp_filesys.c
@@ -417,7 +417,7 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat
 		                                    remote_path, dirent->d_name);
 		NT_STATUS_HAVE_NO_MEMORY(entry_remote_path);
 
-		if (stat(dirent->d_name, &s) != 0) {
+		if (stat(entry_local_path, &s) != 0) {
 			return NT_STATUS_UNSUCCESSFUL;
 		}
 		if (s.st_mode & S_IFDIR) {
diff --git a/source4/lib/policy/gp_manage.c b/source4/lib/policy/gp_manage.c
index f2d3243..e4321e5 100644
--- a/source4/lib/policy/gp_manage.c
+++ b/source4/lib/policy/gp_manage.c
@@ -24,7 +24,7 @@
 #include "param/param.h"
 #include "lib/policy/policy.h"
 
-static uint32_t gp_ads_to_dir_access_mask(uint32_t access_mask)
+uint32_t gp_ads_to_dir_access_mask(uint32_t access_mask)
 {
 	uint32_t fs_mask;
 
diff --git a/source4/lib/policy/policy.h b/source4/lib/policy/policy.h
index d22c3d6..e6ce15c 100644
--- a/source4/lib/policy/policy.h
+++ b/source4/lib/policy/policy.h
@@ -123,5 +123,6 @@ NTSTATUS gp_get_ini_uint(struct gp_ini_context *ini, const char *section, const
 NTSTATUS gp_create_gpo (struct gp_context *gp_ctx, const char *display_name, struct gp_object **ret);
 NTSTATUS gp_create_gpt_security_descriptor (TALLOC_CTX *mem_ctx, struct security_descriptor *ds_sd, struct security_descriptor **ret);
 NTSTATUS gp_set_acl (struct gp_context *gp_ctx, const char *dn_str, const struct security_descriptor *sd);
+uint32_t gp_ads_to_dir_access_mask(uint32_t access_mask);
 
 #endif
diff --git a/source4/lib/policy/pypolicy.c b/source4/lib/policy/pypolicy.c
index 3f302e6..8a9aa47 100644
--- a/source4/lib/policy/pypolicy.c
+++ b/source4/lib/policy/pypolicy.c
@@ -108,11 +108,26 @@ static PyObject *py_get_gplink_options(PyObject *self, PyObject *args)
 	return py_ret;
 }
 
+static PyObject *py_ads_to_dir_access_mask(PyObject *self, PyObject *args)
+{
+	uint32_t access_mask, dir_mask;
+
+	if (! PyArg_ParseTuple(args, "I", &access_mask))
+		return NULL;
+
+	dir_mask = gp_ads_to_dir_access_mask(access_mask);
+
+	return Py_BuildValue("I", dir_mask);
+}
+
+
 static PyMethodDef py_policy_methods[] = {
 	{ "get_gpo_flags", (PyCFunction)py_get_gpo_flags, METH_VARARGS,
 		"get_gpo_flags(flags) -> list" },
-    { "get_gplink_options", (PyCFunction)py_get_gplink_options, METH_VARARGS,
-        "get_gplink_options(options) -> list" },
+	{ "get_gplink_options", (PyCFunction)py_get_gplink_options, METH_VARARGS,
+		"get_gplink_options(options) -> list" },
+	{ "ads_to_dir_access_mask", (PyCFunction)py_ads_to_dir_access_mask, METH_VARARGS,
+		"ads_to_dir_access_mask(access_mask) -> dir_mask" },
 	{ NULL }
 };
 
diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c
index 52d0b10..afa85ab 100644
--- a/source4/libcli/pysmb.c
+++ b/source4/libcli/pysmb.c
@@ -24,6 +24,7 @@
 #include "param/param.h"
 #include "param/pyparam.h"
 #include "system/dir.h"
+#include "system/filesys.h"
 #include "lib/events/events.h"
 #include "auth/credentials/credentials.h"
 #include "auth/credentials/pycredentials.h"
@@ -60,43 +61,39 @@ static void dos_format(char *s)
 
 
 /*
- * Connect to SMB share using smb_composite_connect
+ * Connect to SMB share using smb_full_connection
  */
 static NTSTATUS do_smb_connect(TALLOC_CTX *mem_ctx, struct smb_private_data *spdata,
 			const char *hostname, const char *service, struct smbcli_tree **tree)
 {
-	struct smb_composite_connect io;
+	struct smbcli_state *smb_state;
 	NTSTATUS status;
-
-	gensec_init();
+	struct smbcli_options options;
+	struct smbcli_session_options session_options;
 
 	*tree = NULL;
 
-	ZERO_STRUCT(io);
-
-	io.in.dest_host = hostname;
-
-	io.in.dest_ports = lpcfg_smb_ports(spdata->lp_ctx);
-	io.in.socket_options = lpcfg_socket_options(spdata->lp_ctx);
-	io.in.gensec_settings = lpcfg_gensec_settings(mem_ctx, spdata->lp_ctx);
-
-	io.in.called_name = lpcfg_netbios_name(spdata->lp_ctx);
-	io.in.workgroup = lpcfg_workgroup(spdata->lp_ctx);
-
-	lpcfg_smbcli_options(spdata->lp_ctx, &io.in.options);
-	lpcfg_smbcli_session_options(spdata->lp_ctx, &io.in.session_options);
+	gensec_init();
 
-	io.in.service = service;
-	io.in.service_type = NULL;
+	smb_state = smbcli_state_init(mem_ctx);
 
-	io.in.credentials = spdata->creds;
-	io.in.fallback_to_anonymous = false;
+	lpcfg_smbcli_options(spdata->lp_ctx, &options);
+	lpcfg_smbcli_session_options(spdata->lp_ctx, &session_options);
 
-	status = smb_composite_connect(&io, mem_ctx,
+	status = smbcli_full_connection(mem_ctx, &smb_state, hostname, 
+					lpcfg_smb_ports(spdata->lp_ctx),
+					service, 
+					NULL,
+					lpcfg_socket_options(spdata->lp_ctx),
+					spdata->creds,
 					lpcfg_resolve_context(spdata->lp_ctx),
-					spdata->ev_ctx);
+					spdata->ev_ctx,
+					&options,
+					&session_options,
+					lpcfg_gensec_settings(mem_ctx, spdata->lp_ctx));
+
 	if (NT_STATUS_IS_OK(status)) {
-		*tree = io.out.tree;
+		*tree = smb_state->tree;
 	}
 
 	return status;
@@ -113,7 +110,7 @@ static PyObject * py_smb_loadfile(py_talloc_Object *self, PyObject *args)
 	NTSTATUS status;
 	struct smb_private_data *spdata;
 
-	if (!PyArg_ParseTuple(args, "s", &filename)) {
+	if (!PyArg_ParseTuple(args, "s:loadfile", &filename)) {
 		return NULL;
 	}
 
@@ -139,7 +136,7 @@ static PyObject * py_smb_savefile(py_talloc_Object *self, PyObject *args)
 	NTSTATUS status;
 	struct smb_private_data *spdata;
 
-	if (!PyArg_ParseTuple(args, "ss", &filename, &data)) {
+	if (!PyArg_ParseTuple(args, "ss:savefile", &filename, &data)) {
 		return NULL;
 	}
 
@@ -169,7 +166,14 @@ static void py_smb_list_callback(struct clilist_file_info *f, const char *mask,
 		dict = PyDict_New();
 		if(dict) {
 			PyDict_SetItemString(dict, "name", PyString_FromString(f->name));
-			PyDict_SetItemString(dict, "short_name", PyString_FromString(f->short_name));
+			
+			/* Windows does not always return short_name */
+			if (f->short_name) {
+				PyDict_SetItemString(dict, "short_name", PyString_FromString(f->short_name));
+			} else {
+				PyDict_SetItemString(dict, "short_name", Py_None);
+			}
+
 			PyDict_SetItemString(dict, "size", PyLong_FromUnsignedLongLong(f->size));
 			PyDict_SetItemString(dict, "attrib", PyInt_FromLong(f->attrib));
 			PyDict_SetItemString(dict, "mtime", PyInt_FromLong(f->mtime));
@@ -194,7 +198,7 @@ static PyObject *py_smb_list(py_talloc_Object *self, PyObject *args, PyObject *k
 	uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY
 				| FILE_ATTRIBUTE_ARCHIVE;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|sH",
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|sH:list",
 					discard_const_p(char *, kwnames),
 					&base_dir, &user_mask, &attribute)) {
 		return NULL;
@@ -223,32 +227,131 @@ static PyObject *py_smb_list(py_talloc_Object *self, PyObject *args, PyObject *k
 
 
 /*
+ * Create a directory
+ */
+static PyObject *py_smb_mkdir(py_talloc_Object *self, PyObject *args)
+{
+	NTSTATUS status;
+	const char *dirname;
+	struct smb_private_data *spdata;
+
+	if (!PyArg_ParseTuple(args, "s:mkdir", &dirname)) {
+		return NULL;
+	}
+
+	spdata = self->ptr;	
+	status = smbcli_mkdir(spdata->tree, dirname);
+	PyErr_NTSTATUS_IS_ERR_RAISE(status);
+
+	Py_RETURN_NONE;
+}
+
+
+/*
+ * Remove a directory
+ */
+static PyObject *py_smb_rmdir(py_talloc_Object *self, PyObject *args)
+{
+	NTSTATUS status;
+	const char *dirname;
+	struct smb_private_data *spdata;
+
+	if (!PyArg_ParseTuple(args, "s:rmdir", &dirname)) {
+		return NULL;
+	}
+
+	spdata = self->ptr;	
+	status = smbcli_rmdir(spdata->tree, dirname);
+	PyErr_NTSTATUS_IS_ERR_RAISE(status);
+
+	Py_RETURN_NONE;
+}
+
+
+/*
+ * Check existence of a path
+ */
+static PyObject *py_smb_chkpath(py_talloc_Object *self, PyObject *args)
+{
+	NTSTATUS status;
+	const char *path;
+	struct smb_private_data *spdata;
+
+	if (!PyArg_ParseTuple(args, "s:chkpath", &path)) {
+		return NULL;
+	}
+
+	spdata = self->ptr;	
+	status = smbcli_chkpath(spdata->tree, path);
+
+	if (NT_STATUS_IS_OK(status)) {
+		Py_RETURN_TRUE;
+	}
+
+	Py_RETURN_FALSE;
+}
+
+
+/*
  * Read ACL on a given file/directory as a security descriptor object
  */
 static PyObject *py_smb_getacl(py_talloc_Object *self, PyObject *args, PyObject *kwargs)
 {
 	NTSTATUS status;
-	union smb_fileinfo io;
+	union smb_open io;
+	union smb_fileinfo fio;
 	struct smb_private_data *spdata;
 	const char *filename;
+	int fnum;
 
-	if (!PyArg_ParseTuple(args, "s", &filename)) {
+	if (!PyArg_ParseTuple(args, "s:get_acl", &filename)) {
 		return NULL;
 	}
 
 	ZERO_STRUCT(io);
 
-	io.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
-	io.query_secdesc.in.file.path = filename;
-	io.query_secdesc.in.secinfo_flags = 0;
+	spdata = self->ptr;	
+
+	io.generic.level = RAW_OPEN_NTCREATEX;
+	io.ntcreatex.in.root_fid.fnum = 0;
+	io.ntcreatex.in.flags = 0;
+	io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+	io.ntcreatex.in.create_options = 0;
+	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | 
+					NTCREATEX_SHARE_ACCESS_WRITE;
+	io.ntcreatex.in.alloc_size = 0;
+	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+	io.ntcreatex.in.security_flags = 0;
+	io.ntcreatex.in.fname = filename;
+	
+	status = smb_raw_open(spdata->tree, self->talloc_ctx, &io);
+	PyErr_NTSTATUS_IS_ERR_RAISE(status);
 
-	spdata = self->ptr;
+	fnum = io.ntcreatex.out.file.fnum;
+
+	ZERO_STRUCT(fio);
+
+	fio.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+	fio.query_secdesc.in.file.fnum = fnum;
+	fio.query_secdesc.in.secinfo_flags = SECINFO_OWNER |
+						SECINFO_GROUP |
+						SECINFO_DACL |
+						SECINFO_PROTECTED_DACL |
+						SECINFO_UNPROTECTED_DACL |
+						SECINFO_DACL |
+						SECINFO_PROTECTED_SACL |
+						SECINFO_UNPROTECTED_SACL;
+
+
+	status = smb_raw_query_secdesc(spdata->tree, self->talloc_ctx, &fio);
+	smbcli_close(spdata->tree, fnum);
 
-	status = smb_raw_query_secdesc(spdata->tree, self->talloc_ctx, &io);
 	PyErr_NTSTATUS_IS_ERR_RAISE(status);
 
 	return py_return_ndr_struct("samba.dcerpc.security", "descriptor",
-				self->talloc_ctx, io.query_secdesc.out.sd);
+				self->talloc_ctx, fio.query_secdesc.out.sd);
 }
 
 
@@ -258,13 +361,15 @@ static PyObject *py_smb_getacl(py_talloc_Object *self, PyObject *args, PyObject
 static PyObject *py_smb_setacl(py_talloc_Object *self, PyObject *args, PyObject *kwargs)
 {
 	NTSTATUS status;
-	union smb_setfileinfo io;
+	union smb_open io;
+	union smb_setfileinfo fio;
 	struct smb_private_data *spdata;
 	const char *filename;
 	PyObject *py_sd;
 	struct security_descriptor *sd;
+	int fnum;
 
-	if (!PyArg_ParseTuple(args, "sO", &filename, &py_sd)) {
+	if (!PyArg_ParseTuple(args, "sO:set_acl", &filename, &py_sd)) {
 		return NULL;
 	}
 
@@ -272,19 +377,45 @@ static PyObject *py_smb_setacl(py_talloc_Object *self, PyObject *args, PyObject
 
 	sd = py_talloc_get_type(py_sd, struct security_descriptor);
 	if (!sd) {
-		PyErr_Format(PyExc_TypeError,
-				"Expected dcerpc.security.descriptor for security_descriptor argument, got %s", talloc_get_name(py_talloc_get_ptr(py_sd)));
+		PyErr_Format(PyExc_TypeError, 
+			"Expected dcerpc.security.descriptor as argument, got %s", 
+			talloc_get_name(py_talloc_get_ptr(py_sd)));
 		return NULL;
 	}
 
 	ZERO_STRUCT(io);
 
-	io.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
-	io.set_secdesc.in.file.path = filename;
-	io.set_secdesc.in.secinfo_flags = 0;
-	io.set_secdesc.in.sd = sd;
+	spdata = self->ptr;	
+
+	io.generic.level = RAW_OPEN_NTCREATEX;
+	io.ntcreatex.in.root_fid.fnum = 0;
+	io.ntcreatex.in.flags = 0;
+	io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+	io.ntcreatex.in.create_options = 0;
+	io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+	io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | 
+					NTCREATEX_SHARE_ACCESS_WRITE;
+	io.ntcreatex.in.alloc_size = 0;
+	io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+	io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+	io.ntcreatex.in.security_flags = 0;
+	io.ntcreatex.in.fname = filename;
+	
+	status = smb_raw_open(spdata->tree, self->talloc_ctx, &io);
+	PyErr_NTSTATUS_IS_ERR_RAISE(status);
+
+	fnum = io.ntcreatex.out.file.fnum;
+
+	ZERO_STRUCT(fio);
+
+	fio.set_secdesc.level = RAW_SFILEINFO_SEC_DESC;
+	fio.set_secdesc.in.file.fnum = fnum;
+	fio.set_secdesc.in.secinfo_flags = 0;
+	fio.set_secdesc.in.sd = sd;
+
+	status = smb_raw_set_secdesc(spdata->tree, &fio);
+	smbcli_close(spdata->tree, fnum);
 
-	status = smb_raw_set_secdesc(spdata->tree, &io);
 	PyErr_NTSTATUS_IS_ERR_RAISE(status);
 
 	Py_RETURN_NONE;
@@ -293,15 +424,34 @@ static PyObject *py_smb_setacl(py_talloc_Object *self, PyObject *args, PyObject
 
 static PyMethodDef py_smb_methods[] = {
 	{ "loadfile", (PyCFunction)py_smb_loadfile, METH_VARARGS,
-		"Read contents of a file" },
+		"loadfile(path) -> file contents as a string\n\n \
+		Read contents of a file." },
 	{ "savefile", (PyCFunction)py_smb_savefile, METH_VARARGS,
-		"Write contents to a file" },
+		"savefile(path, str) -> None\n\n \
+		Write string str to file." },
 	{ "list", (PyCFunction)py_smb_list, METH_VARARGS|METH_KEYWORDS,
-		"List contents of a directory" },
+		"list(path) -> directory contents as a dictionary\n\n \
+		List contents of a directory. The keys are, \n \
+		\tname: Long name of the directory item\n \
+		\tshort_name: Short name of the directory item\n \
+		\tsize: File size in bytes\n \
+		\tattrib: Attributes\n \
+		\tmtime: Modification time\n" },
+	{ "mkdir", (PyCFunction)py_smb_mkdir, METH_VARARGS,
+		"mkdir(path) -> None\n\n \
+		Create a directory." },
+	{ "rmdir", (PyCFunction)py_smb_rmdir, METH_VARARGS,
+		"rmdir(path) -> None\n\n \
+		Delete a directory." },
+	{ "chkpath", (PyCFunction)py_smb_chkpath, METH_VARARGS,
+		"chkpath(path) -> True or False\n\n \
+		Return true if path exists, false otherwise." },
 	{ "get_acl", (PyCFunction)py_smb_getacl, METH_VARARGS,
-		"Get security descriptor for a file" },
+		"get_acl(path) -> security_descriptor object\n\n \
+		Get security descriptor for file." },
 	{ "set_acl", (PyCFunction)py_smb_setacl, METH_VARARGS,
-		"Set security descriptor for a file" },
+		"set_acl(path, security_descriptor) -> None\n\n \


-- 
Samba Shared Repository


More information about the samba-cvs mailing list