Some mods to samba.smb.SMB to support test cases for File System ACLs and privs

Richard Sharpe realrichardsharpe at gmail.com
Fri Mar 30 22:45:15 MDT 2012


On Thu, Mar 29, 2012 at 9:41 PM, Richard Sharpe
<realrichardsharpe at gmail.com> wrote:
>>>> Hi Richard,
>>>>
>>>> Instead of adding specific open_close_file(), can you add open() and
>>>> close() as separate calls? That paves a way for adding read/write
>>>> stuff at a later date.

OK, is this what you had in mind (plus a py_close_file)?

+/*
+ * 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 *
+{
+       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:get_acl",
+                               &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);
+}

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


More information about the samba-technical mailing list