[SCM] Samba Shared Repository - branch master updated

Jelmer Vernooij jelmer at samba.org
Sun Apr 1 08:40:12 MDT 2012


-----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.
>
> +
> + 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.
>
> +
> + 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.

Cheers,

Jelmer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJPeGjLAAoJEACAbyvXKaRXfYEP/RtlXOZAEvra4LCrxY2W8Sih
tlH/0qSfn7mNiRThGZtroCTh5+swr2IxHyG290uLVWWrhug6STCMdjOsmKLL0U6o
eyVrG3iapjA5dGlFBtIjvq7zEddRuMhPDUsIwbzMPiyxD63aSKaWmZ0c5oO9vPH2
w9FKO45YEQ6ocIstYSq70g/qHd/am9TG2IO1y0ISwQu+6FY0gzpLVYQ0WKr5OLVe
pzsfGtrMjsOxW1njcVdhmBF4U/7/GpeNIL5fPiSCEqd49L8aAGiy+2sYvTIVFVba
RSAwzqVQ1Qb3+kFNl5WyNCTx09yUEViEltQBMpPenzSVqpehqjOnH3+lVnVxrnmU
GUGgXuep80s5lYw4BOBIKxzDOsUA3kwAJ1uJF13DTwk5WXnymd6Y3Ozsdx1SM8JF
L1UBiMlbEAbTWVjxKRNUpbSAKU46OdP9iLuQunNAkAgZgPHsy5ekfvX/CPQZLIb6
+CrEIXRsRr9DMkrPVVlh35PGVYgHDzq8n/ZpyfTyBFS3OyHWtvix1jvLPmtxYQ6M
8QdqOxnfYQbsVGWyZMtEeoxJcKPWKkNmWOJd0VOv0PNvczURWmt4t6MOUJF44BOf
lJKBZs4/j3Hr1zjwVsDgJOZQsey55teRq7o9NwUsiYzNMBPpcjHE3LLd9/u6nG6Y
mH2irnvlLFIhqXYMQxTu
=KZh1
-----END PGP SIGNATURE-----



More information about the samba-technical mailing list