[SCM] Samba Shared Repository - branch master updated
The branch, master has been updated via 2c322ca Fix some of the issues that Jelmer identified in my first patch. This might be changed again, especially when I figure out how to return the file as an object. from 36101d3 Add an open and close method to samba.smb.SMB so we can open and close files. Also, fix up some documentation. http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log - commit 2c322ca95a7dc4fb8396b475d115f31837316267 Author: Richard Sharpe Date: Sun Apr 1 13:14:49 2012 -0700 Fix some of the issues that Jelmer identified in my first patch. This might be changed again, especially when I figure out how to return the file as an object. Autobuild-User: Richard Sharpe Autobuild-Date: Mon Apr 2 01:43:44 CEST 2012 on sn-devel-104 --- Summary of changes: source4/libcli/pysmb.c | 28 1 files changed, 12 insertions(+), 16 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c index a0021b9..3f2efe9 100644 --- a/source4/libcli/pysmb.c +++ b/source4/libcli/pysmb.c @@ -437,13 +437,15 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObject *args, PyObject *k union smb_open io; struct smb_private_data *spdata; const char *filename; - uint32_t access_mask = 0; - uint32_t share_access = 0; -uint32_t open_disposition = 0; + uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + uint32_t share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE; +uint32_t open_disposition = NTCREATEX_DISP_OPEN; uint32_t create_options = 0; + TALLOC_CTX *mem_ctx; int fnum; - if (!PyArg_ParseTuple(args, "si|iii:open_file", + if (!PyArg_ParseTuple(args, "s|:open_file", &filename, &access_mask, &share_access, @@ -452,20 +454,12 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObject *args, PyObject *k return NULL; } - if (!access_mask) - access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - - if (!share_access) - share_access = NTCREATEX_SHARE_ACCESS_READ | - NTCREATEX_SHARE_ACCESS_WRITE; - - if (!open_disposition) - open_disposition = NTCREATEX_DISP_OPEN; - ZERO_STRUCT(io); spdata = self->ptr; + mem_ctx = talloc_new(NULL); + io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.flags = 0; @@ -479,7 +473,9 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObject *args, PyObject *k io.ntcreatex.in.security_flags = 0; io.ntcreatex.in.fname = filename; - status = smb_raw_open(spdata->tree, self->talloc_ctx, &io); + status = smb_raw_open(spdata->tree, mem_ctx, &io); + talloc_free(mem_ctx); + PyErr_NTSTATUS_IS_ERR_RAISE(status); fnum = io.ntcreatex.out.file.fnum; @@ -541,7 +537,7 @@ static PyMethodDef py_smb_methods[] = { Set security descriptor for file." }, { "open_file", (PyCFunction)py_open_file, METH_VARARGS, "open_file(path, access_mask[, share_access[, open_disposition[, create_options]]] -> fnum\n\n \ - Open a file. Throws exceptions on errors." }, + Open a file. Throws NTSTATUS exceptions on errors." }, { "close_file", (PyCFunction)py_close_file, METH_VARARGS, "close_file(fnum) -> None\n\n \ Close the file based on fnum."}, -- Samba Shared Repository
[SCM] Samba Shared Repository - branch master updated
The branch, master has been updated via 36101d3 Add an open and close method to samba.smb.SMB so we can open and close files. Also, fix up some documentation. from 0aacdbf s3-aio-fork: Fix a segfault in vfs_aio_fork http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log - commit 36101d3fa45c0b583628862794054f60eb4e6ed3 Author: Richard Sharpe Date: Fri Mar 30 22:04:28 2012 -0700 Add an open and close method to samba.smb.SMB so we can open and close files. Also, fix up some documentation. Autobuild-User: Richard Sharpe Autobuild-Date: Sun Apr 1 16:29:52 CEST 2012 on sn-devel-104 --- Summary of changes: source4/libcli/pysmb.c | 96 +++- 1 files changed, 86 insertions(+), 10 deletions(-) Changeset truncated at 500 lines: diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c index b4eba14..a0021b9 100644 --- a/source4/libcli/pysmb.c +++ b/source4/libcli/pysmb.c @@ -53,7 +53,6 @@ struct smb_private_data { struct smbcli_tree *tree; }; - static void dos_format(char *s) { string_replace(s, '/', '\\'); @@ -151,7 +150,6 @@ static PyObject * py_smb_savefile(pytalloc_Object *self, PyObject *args) Py_RETURN_NONE; } - /* * Callback function to accumulate directory contents in a python list */ @@ -183,7 +181,6 @@ static void py_smb_list_callback(struct clilist_file_info *f, const char *mask, } } - /* * List the directory contents for specified directory (Ignore '.' and '..' dirs) */ @@ -225,7 +222,6 @@ static PyObject *py_smb_list(pytalloc_Object *self, PyObject *args, PyObject *kw return py_dirlist; } - /* * Create a directory */ @@ -246,7 +242,6 @@ static PyObject *py_smb_mkdir(pytalloc_Object *self, PyObject *args) Py_RETURN_NONE; } - /* * Remove a directory */ @@ -267,7 +262,6 @@ static PyObject *py_smb_rmdir(pytalloc_Object *self, PyObject *args) Py_RETURN_NONE; } - /* * Check existence of a path */ @@ -291,7 +285,6 @@ static PyObject *py_smb_chkpath(pytalloc_Object *self, PyObject *args) Py_RETURN_FALSE; } - /* * Read ACL on a given file/directory as a security descriptor object */ @@ -357,7 +350,6 @@ static PyObject *py_smb_getacl(pytalloc_Object *self, PyObject *args, PyObject * self->talloc_ctx, fio.query_secdesc.out.sd); } - /* * Set ACL on file/directory using given security descriptor object */ @@ -436,6 +428,86 @@ static PyObject *py_smb_setacl(pytalloc_Object *self, PyObject *args, PyObject * Py_RETURN_NONE; } +/* + * Open the file with the parameters passed in and return an object if OK + */ +static PyObject *py_open_file(pytalloc_Object *self, PyObject *args, PyObject *kwargs) +{ + NTSTATUS status; + union smb_open io; + struct smb_private_data *spdata; + const char *filename; + uint32_t access_mask = 0; + uint32_t share_access = 0; +uint32_t open_disposition = 0; +uint32_t create_options = 0; + int fnum; + + if (!PyArg_ParseTuple(args, "si|iii:open_file", + &filename, + &access_mask, + &share_access, + &open_disposition, + &create_options)) { + return NULL; + } + + if (!access_mask) + access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + + if (!share_access) + share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE; + + if (!open_disposition) + open_disposition = NTCREATEX_DISP_OPEN; + + ZERO_STRUCT(io); + + 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 = access_mask; + io.ntcreatex.in.create_options = create_options; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = share_access; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = open_disposition; + 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; + + return Py_BuildValue("i", fnum); +} + +/* + * Close the file based on the fnum passed in + */ +static PyObject *py_close_file(pytalloc_Object *self, PyObject *args, PyObject *kwargs) +{ + struct smb_private_data *spdata; + int fnum; + +
Re: wild use of strlcpy() broke ipv6 support
On 03/30/2012 09:21 PM, Jeremy Allison wrote: On Fri, Mar 30, 2012 at 08:53:21PM -0700, Jeremy Allison wrote: On Fri, Mar 30, 2012 at 08:52:09PM -0700, Jeremy Allison wrote: On Fri, Mar 30, 2012 at 06:02:06PM -0700, Matthieu Patou wrote: At least for this two changes you didn't get completely the sense of the strlcpy(), the idea is that if you have fe80::221:ccff:fe5f:7e51%eth0 to get the number of the interface and remove what is after '%'. so we should in this case always truncate and ihmo it's not a problem. Ok - I'm boilerplate fixing all strlcpy uses. If it truncates then by definition it's a problem, and we shouldn't be using strlcpy() - we should be correctly paying attention to the length we really want. I do (vaguely :-) remember writing this code (or something like it). I'll take a look and fix up asap. Ah yes - now I looked at it I did write this code originally :-). I'll fix. Here's the fix (attached). autobuilding now. Sorry for the breakage, but we really do need to correctly use strlcpy/strlcat to check if we ever get truncation (I'm at fault here, as I introduced them originally - and added the incorrect idiom when using them). I'll try and be a little more careful when adding the checks if we're doing anything sophisticated with the lengths. It's a very rare case where we're using truncation as a desired side effect (and is an *explicitly* incorrect use of the API :-). I'll just tested your patch it's working for local-link ipv6, was too busy today between homedepot and fry's and enjoying this beautifull bay area weather :-) And please can you recheck that you didn't introduced other regression. I'm thinking of having one instance of samba in make test with interface + bind interface only combo set so that we can catch this problem in the future. Matthieu. -- Matthieu Patou Samba Team http://samba.org