[SCM] Samba Shared Repository - branch master updated

Richard Sharpe realrichardsharpe at gmail.com
Sun Apr 1 08:57:57 MDT 2012


On Sun, Apr 1, 2012 at 7:40 AM, Jelmer Vernooij <jelmer at samba.org> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi Ricard,
>
> Thanks for extending the SMB module.
>
> On 04/01/2012 04:30 PM, Richard Sharpe wrote:
>> @@ -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;
> It seems a lot simpler to add these default values in the declaration.
> That way, it's still possible for API users to specify 0 as a value, and
> it's also a fair bit shorter.

You are correct. I will fix that.

>> +
>> + 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);
> Are you sure you want to use self->talloc_ctx in this case?
> self->talloc_ctx doesn't get destroyed until the SMB object is
> destroyed, which means that you keep allocating more memory even when
> files are closed, until the SMB object is garbage collected.

Sigh. Cut-n-paste. I will have to come up with a fix for that. What I
would prefer to do is to move to returning an object, so that I can
have a separate talloc context.

>> +
>> + 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;
>> +
>> + if (!PyArg_ParseTuple(args, "i:close_file", &fnum)) {
>> + return NULL;
>> + }
>> +
>> + spdata = self->ptr;
>> +
>> + /*
>> + * Should check the status ...
>> + */
>> + smbcli_close(spdata->tree, fnum);
>> +
>> + Py_RETURN_NONE;
>> +}
>>
>> static PyMethodDef py_smb_methods[] = {
>> { "loadfile", (PyCFunction)py_smb_loadfile, METH_VARARGS,
>> @@ -467,10 +539,15 @@ static PyMethodDef py_smb_methods[] = {
>> { "set_acl", (PyCFunction)py_smb_setacl, METH_VARARGS,
>> "set_acl(path, security_descriptor[, security_info=0]) -> None\n\n \
>> 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." },
> All code in Python throws exceptions :-) It's not very useful to
> explicitly mention this. :-) It might be useful in some cases to mention
> what exceptions are thrown when, though.

Heh. Thanks.

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list