r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / python / py_lsa.c
index 4204f43f7b9dbe0c9d31f4ca8b3cb69fab98d53a..6095fdfc677f0fa1ef0561ce59621521647cba4e 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "python/py_lsa.h"
 
-PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+PyObject *new_lsa_policy_hnd_object(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                    POLICY_HND *pol)
 {
        lsa_policy_hnd_object *o;
@@ -55,7 +54,7 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args,
        static char *kwlist[] = { "servername", "creds", "access", NULL };
        char *server, *errstr;
        PyObject *creds = NULL, *result = NULL;
-       uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
+       uint32 desired_access = GENERIC_EXECUTE_ACCESS;
        struct cli_state *cli = NULL;
        NTSTATUS ntstatus;
        TALLOC_CTX *mem_ctx = NULL;
@@ -89,23 +88,22 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args,
                goto done;
        }
 
-       ntstatus = cli_lsa_open_policy(cli, mem_ctx, True,
-                                      SEC_RIGHTS_MAXIMUM_ALLOWED, &hnd);
+       ntstatus = rpccli_lsa_open_policy(
+               cli->pipe_list, mem_ctx, True, desired_access, &hnd);
 
        if (!NT_STATUS_IS_OK(ntstatus)) {
                PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus));
                goto done;
        }
 
-       result = new_lsa_policy_hnd_object(cli, mem_ctx, &hnd);
+       result = new_lsa_policy_hnd_object(cli->pipe_list, mem_ctx, &hnd);
 
 done:
        if (!result) {
                if (cli)
                        cli_shutdown(cli);
 
-               if (mem_ctx)
-                       talloc_destroy(mem_ctx);
+               talloc_destroy(mem_ctx);
        }
 
        return result;
@@ -126,7 +124,7 @@ static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw)
 
        /* Call rpc function */
 
-       result = cli_lsa_close(hnd->cli, hnd->mem_ctx, &hnd->pol);
+       result = rpccli_lsa_Close(hnd->cli, hnd->mem_ctx, &hnd->pol);
 
        /* Cleanup samba stuff */
 
@@ -141,13 +139,14 @@ static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw)
 
 static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 {
-       PyObject *py_names, *result;
+       PyObject *py_names, *result = NULL;
        NTSTATUS ntstatus;
        lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self;
        int num_names, i;
        const char **names;
        DOM_SID *sids;
-       uint32 *name_types;
+       TALLOC_CTX *mem_ctx = NULL;
+       enum lsa_SidType *name_types;
 
        if (!PyArg_ParseTuple(args, "O", &py_names))
                return NULL;
@@ -157,18 +156,22 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
                return NULL;
        }
 
+       if (!(mem_ctx = talloc_init("lsa_lookup_names"))) {
+               PyErr_SetString(lsa_error, "unable to init talloc context\n");
+               goto done;
+       }
+
        if (PyList_Check(py_names)) {
 
                /* Convert list to char ** array */
 
                num_names = PyList_Size(py_names);
-               names = (const char **)talloc(
-                       hnd->mem_ctx, num_names * sizeof(char *));
+               names = (const char **)_talloc(mem_ctx, num_names * sizeof(char *));
                
                for (i = 0; i < num_names; i++) {
                        PyObject *obj = PyList_GetItem(py_names, i);
                        
-                       names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj));
+                       names[i] = talloc_strdup(mem_ctx, PyString_AsString(obj));
                }
 
        } else {
@@ -176,17 +179,18 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
                /* Just a single element */
 
                num_names = 1;
-               names = (const char **)talloc(hnd->mem_ctx, sizeof(char *));
+               names = (const char **)_talloc(mem_ctx, sizeof(char *));
 
                names[0] = PyString_AsString(py_names);
        }
 
-       ntstatus = cli_lsa_lookup_names(hnd->cli, hnd->mem_ctx, &hnd->pol,
-                                       num_names, names, &sids, &name_types);
+       ntstatus = rpccli_lsa_lookup_names(
+               hnd->cli, mem_ctx, &hnd->pol, num_names, names, 
+               NULL, 1, &sids, &name_types);
 
        if (!NT_STATUS_IS_OK(ntstatus) && NT_STATUS_V(ntstatus) != 0x107) {
                PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus));
-               return NULL;
+               goto done;
        }
 
        result = PyList_New(num_names);
@@ -196,10 +200,13 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 
                py_from_SID(&sid_obj, &sids[i]);
 
-               obj = Py_BuildValue("(Oi)", sid_obj, name_types[i]);
+               obj = Py_BuildValue("(Ni)", sid_obj, name_types[i]);
 
                PyList_SetItem(result, i, obj);
        }
+
+ done:
+       talloc_destroy(mem_ctx);
        
        return result;
 }
@@ -207,7 +214,7 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args)
 static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, 
                                 PyObject *kw) 
 {
-       PyObject *py_sids, *result;
+       PyObject *py_sids, *result = NULL;
        NTSTATUS ntstatus;
        int num_sids, i;
        char **domains, **names;
@@ -224,7 +231,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                return NULL;
        }
 
-       if (!(mem_ctx = talloc_init("lsa_open_policy"))) {
+       if (!(mem_ctx = talloc_init("lsa_lookup_sids"))) {
                PyErr_SetString(lsa_error, "unable to init talloc context\n");
                goto done;
        }
@@ -234,7 +241,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                /* Convert dictionary to char ** array */
                
                num_sids = PyList_Size(py_sids);
-               sids = (DOM_SID *)talloc(mem_ctx, num_sids * sizeof(DOM_SID));
+               sids = (DOM_SID *)_talloc(mem_ctx, num_sids * sizeof(DOM_SID));
                
                memset(sids, 0, num_sids * sizeof(DOM_SID));
                
@@ -243,7 +250,6 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                        
                        if (!string_to_sid(&sids[i], PyString_AsString(obj))) {
                                PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
-                               result = NULL;
                                goto done;
                        }
                }
@@ -253,22 +259,20 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
                /* Just a single element */
 
                num_sids = 1;
-               sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID));
+               sids = (DOM_SID *)_talloc(mem_ctx, sizeof(DOM_SID));
 
                if (!string_to_sid(&sids[0], PyString_AsString(py_sids))) {
                        PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
-                       result = NULL;
                        goto done;
                }
        }
 
-       ntstatus = cli_lsa_lookup_sids(hnd->cli, mem_ctx, &hnd->pol,
-                                      num_sids, sids, &domains, &names, 
-                                      &types);
+       ntstatus = rpccli_lsa_lookup_sids(
+               hnd->cli, mem_ctx, &hnd->pol, num_sids, sids, &domains, 
+               &names, &types);
 
        if (!NT_STATUS_IS_OK(ntstatus)) {
                PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus));
-               result = NULL;
                goto done;
        }
 
@@ -285,8 +289,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args,
        }
 
  done:
-       if (mem_ctx)
-               talloc_destroy(mem_ctx);
+       talloc_destroy(mem_ctx);
 
        return result;
 }
@@ -303,7 +306,7 @@ static PyObject *lsa_enum_trust_dom(PyObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, ""))
                return NULL;
        
-       ntstatus = cli_lsa_enum_trust_dom(
+       ntstatus = rpccli_lsa_enum_trust_dom(
                hnd->cli, hnd->mem_ctx, &hnd->pol, &enum_ctx,
                &num_domains, &domain_names, &domain_sids);
 
@@ -404,7 +407,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.setup_logging(interactive = 1)" },
+">>> lsa.setup_logging(interactive = 1)" },
 
        { "get_debuglevel", (PyCFunction)get_debuglevel, 
          METH_VARARGS, 
@@ -412,7 +415,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.get_debuglevel()\n"
+">>> lsa.get_debuglevel()\n"
 "0" },
 
        { "set_debuglevel", (PyCFunction)set_debuglevel, 
@@ -421,7 +424,7 @@ static PyMethodDef lsa_methods[] = {
 "\n"
 "Example:\n"
 "\n"
-">>> spoolss.set_debuglevel(10)" },
+">>> lsa.set_debuglevel(10)" },
 
        { NULL }
 };