pytalloc: Use consistent prefix for functions, add ABI file.
[ab/samba.git/.git] / source4 / libcli / pysmb.c
index 43478ea5a801185cc362f57fb0f90865e20cb72a..31d163cd3a9a77ed24f6610da97e1490d5f62b25 100644 (file)
@@ -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"
@@ -102,7 +103,7 @@ static NTSTATUS do_smb_connect(TALLOC_CTX *mem_ctx, struct smb_private_data *spd
 /*
  * Read SMB file and return the contents of the file as python string
  */
-static PyObject * py_smb_loadfile(py_talloc_Object *self, PyObject *args)
+static PyObject * py_smb_loadfile(pytalloc_Object *self, PyObject *args)
 {
        struct smb_composite_loadfile io;
        const char *filename;
@@ -127,7 +128,7 @@ static PyObject * py_smb_loadfile(py_talloc_Object *self, PyObject *args)
 /*
  * Create a SMB file with given string as the contents
  */
-static PyObject * py_smb_savefile(py_talloc_Object *self, PyObject *args)
+static PyObject * py_smb_savefile(pytalloc_Object *self, PyObject *args)
 {
        struct smb_composite_savefile io;
        const char *filename;
@@ -186,7 +187,7 @@ static void py_smb_list_callback(struct clilist_file_info *f, const char *mask,
 /*
  * List the directory contents for specified directory (Ignore '.' and '..' dirs)
  */
-static PyObject *py_smb_list(py_talloc_Object *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_smb_list(pytalloc_Object *self, PyObject *args, PyObject *kwargs)
 {
        struct smb_private_data *spdata;
        PyObject *py_dirlist;
@@ -228,7 +229,7 @@ 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)
+static PyObject *py_smb_mkdir(pytalloc_Object *self, PyObject *args)
 {
        NTSTATUS status;
        const char *dirname;
@@ -249,7 +250,7 @@ static PyObject *py_smb_mkdir(py_talloc_Object *self, PyObject *args)
 /*
  * Remove a directory
  */
-static PyObject *py_smb_rmdir(py_talloc_Object *self, PyObject *args)
+static PyObject *py_smb_rmdir(pytalloc_Object *self, PyObject *args)
 {
        NTSTATUS status;
        const char *dirname;
@@ -270,7 +271,7 @@ static PyObject *py_smb_rmdir(py_talloc_Object *self, PyObject *args)
 /*
  * Check existence of a path
  */
-static PyObject *py_smb_chkpath(py_talloc_Object *self, PyObject *args)
+static PyObject *py_smb_chkpath(pytalloc_Object *self, PyObject *args)
 {
        NTSTATUS status;
        const char *path;
@@ -294,12 +295,14 @@ static PyObject *py_smb_chkpath(py_talloc_Object *self, PyObject *args)
 /*
  * 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)
+static PyObject *py_smb_getacl(pytalloc_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:get_acl", &filename)) {
                return NULL;
@@ -307,31 +310,64 @@ static PyObject *py_smb_getacl(py_talloc_Object *self, PyObject *args, PyObject
 
        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;     
 
-       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.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);
 }
 
 
 /*
  * Set ACL on file/directory using given security descriptor object
  */
-static PyObject *py_smb_setacl(py_talloc_Object *self, PyObject *args, PyObject *kwargs)
+static PyObject *py_smb_setacl(pytalloc_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:set_acl", &filename, &py_sd)) {
                return NULL;
@@ -339,21 +375,47 @@ static PyObject *py_smb_setacl(py_talloc_Object *self, PyObject *args, PyObject
 
        spdata = self->ptr;
 
-       sd = py_talloc_get_type(py_sd, struct security_descriptor);
+       sd = pytalloc_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(pytalloc_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;
@@ -401,7 +463,7 @@ static PyObject *py_smb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
        const char *kwnames[] = { "hostname", "service", "creds", "lp", NULL };
        const char *hostname = NULL;
        const char *service = NULL;
-       py_talloc_Object *smb;
+       pytalloc_Object *smb;
        struct smb_private_data *spdata;
        NTSTATUS status;
 
@@ -411,7 +473,7 @@ static PyObject *py_smb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
                return NULL;
        }
 
-       smb = (py_talloc_Object *)type->tp_alloc(type, 0);
+       smb = (pytalloc_Object *)type->tp_alloc(type, 0);
        if (smb == NULL) {
                PyErr_NoMemory();
                return NULL;
@@ -456,7 +518,7 @@ static PyObject *py_smb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
 
 static PyTypeObject PySMB = {
        .tp_name = "smb.SMB",
-       .tp_basicsize = sizeof(py_talloc_Object),
+       .tp_basicsize = sizeof(pytalloc_Object),
        .tp_new = py_smb_new,
        .tp_flags = Py_TPFLAGS_DEFAULT,
        .tp_methods = py_smb_methods,
@@ -467,7 +529,7 @@ static PyTypeObject PySMB = {
 void initsmb(void)
 {
        PyObject *m;
-       PyTypeObject *talloc_type = PyTalloc_GetObjectType();
+       PyTypeObject *talloc_type = pytalloc_GetObjectType();
        if (talloc_type == NULL) {
                return;
        }