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;
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;
server += 2;
- if (!(cli = open_pipe_creds(server, creds, PIPE_LSARPC, &errstr))) {
+ if (!(cli = open_pipe_creds(server, creds, PI_LSARPC, &errstr))) {
PyErr_SetString(lsa_error, errstr);
free(errstr);
return NULL;
}
- if (!(mem_ctx = talloc_init())) {
+ if (!(mem_ctx = talloc_init("lsa_open_policy"))) {
PyErr_SetString(lsa_error, "unable to init talloc context\n");
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;
/* 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 */
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;
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 {
/* 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);
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;
}
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;
uint32 *types;
lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self;
+ TALLOC_CTX *mem_ctx = NULL;
DOM_SID *sids;
if (!PyArg_ParseTuple(args, "O", &py_sids))
return NULL;
}
+ if (!(mem_ctx = talloc_init("lsa_lookup_sids"))) {
+ PyErr_SetString(lsa_error, "unable to init talloc context\n");
+ goto done;
+ }
+
if (PyList_Check(py_sids)) {
/* Convert dictionary to char ** array */
num_sids = PyList_Size(py_sids);
- sids = (DOM_SID *)talloc(hnd->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));
for (i = 0; i < num_sids; i++) {
PyObject *obj = PyList_GetItem(py_sids, i);
- string_to_sid(&sids[i], PyString_AsString(obj));
+ if (!string_to_sid(&sids[i], PyString_AsString(obj))) {
+ PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
+ goto done;
+ }
}
} else {
/* Just a single element */
num_sids = 1;
- sids = (DOM_SID *)talloc(hnd->mem_ctx, sizeof(DOM_SID));
+ sids = (DOM_SID *)_talloc(mem_ctx, sizeof(DOM_SID));
- string_to_sid(&sids[0], PyString_AsString(py_sids));
+ if (!string_to_sid(&sids[0], PyString_AsString(py_sids))) {
+ PyErr_SetString(PyExc_ValueError, "string_to_sid failed");
+ goto done;
+ }
}
- ntstatus = cli_lsa_lookup_sids(hnd->cli, hnd->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));
- return NULL;
+ goto done;
}
result = PyList_New(num_sids);
PyList_SetItem(result, i, obj);
}
-
+
+ done:
+ talloc_destroy(mem_ctx);
+
return result;
}
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);
{ "setup_logging", (PyCFunction)py_setup_logging,
METH_VARARGS | METH_KEYWORDS,
- "Set up debug logging.
-
-Initialises Samba's debug logging system. One argument is expected which
-is a boolean specifying whether debugging is interactive and sent to stdout
-or logged to a file.
-
-Example:
-
->>> spoolss.setup_logging(interactive = 1)" },
+ "Set up debug logging.\n"
+"\n"
+"Initialises Samba's debug logging system. One argument is expected which\n"
+"is a boolean specifying whether debugging is interactive and sent to stdout\n"
+"or logged to a file.\n"
+"\n"
+"Example:\n"
+"\n"
+">>> lsa.setup_logging(interactive = 1)" },
{ "get_debuglevel", (PyCFunction)get_debuglevel,
METH_VARARGS,
- "Set the current debug level.
-
-Example:
-
->>> spoolss.get_debuglevel()
-0" },
+ "Set the current debug level.\n"
+"\n"
+"Example:\n"
+"\n"
+">>> lsa.get_debuglevel()\n"
+"0" },
{ "set_debuglevel", (PyCFunction)set_debuglevel,
METH_VARARGS,
- "Get the current debug level.
-
-Example:
-
->>> spoolss.set_debuglevel(10)" },
+ "Get the current debug level.\n"
+"\n"
+"Example:\n"
+"\n"
+">>> lsa.set_debuglevel(10)" },
{ NULL }
};