diff options
-rw-r--r-- | source3/python/py_lsa.c | 82 | ||||
-rw-r--r-- | source3/python/py_spoolss.c | 70 | ||||
-rw-r--r-- | source3/python/py_spoolss.h | 7 | ||||
-rw-r--r-- | source3/python/py_spoolss_proto.h | 3 |
4 files changed, 68 insertions, 94 deletions
diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index dfb9b642ed..5e805a91ad 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -1,19 +1,12 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_lsa.h" static void py_policy_hnd_dealloc(PyObject* self) { PyObject_Del(self); } -typedef struct { - PyObject_HEAD - struct cli_state *cli; - TALLOC_CTX *mem_ctx; - POLICY_HND pol; -} lsa_policy_hnd_object; - PyTypeObject lsa_policy_hnd_type = { PyObject_HEAD_INIT(NULL) 0, @@ -32,6 +25,20 @@ PyTypeObject lsa_policy_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + lsa_policy_hnd_object *o; + + o = PyObject_New(lsa_policy_hnd_object, &lsa_policy_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + /* * Exceptions raised by this module */ @@ -52,23 +59,70 @@ static PyObject *lsa_openpolicy(PyObject *self, PyObject *args, { static char *kwlist[] = { "servername", "creds", "access", NULL }; char *server_name; - PyObject *creds = NULL; + PyObject *creds = NULL, *result; uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; + struct cli_state *cli; + NTSTATUS ntstatus; + TALLOC_CTX *mem_ctx; + POLICY_HND hnd; if (!PyArg_ParseTupleAndKeywords( args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, - &creds, &desired_access)) { + &creds, &desired_access)) + return NULL; - goto done; + if (!(cli = open_pipe_creds(server_name, creds, cli_lsa_initialise, + NULL))) { + fprintf(stderr, "could not initialise cli state\n"); + return NULL; } - done: - return NULL; + if (!(mem_ctx = talloc_init())) { + fprintf(stderr, "unable to initialise talloc context\n"); + return NULL; + } + + ntstatus = cli_lsa_open_policy(cli, mem_ctx, True, + SEC_RIGHTS_MAXIMUM_ALLOWED, &hnd); + + if (!NT_STATUS_IS_OK(ntstatus)) { + cli_shutdown(cli); + SAFE_FREE(cli); + PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); + return NULL; + } + + result = new_lsa_policy_hnd_object(cli, mem_ctx, &hnd); + + return result; } static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw) { - return NULL; + PyObject *po; + lsa_policy_hnd_object *hnd; + NTSTATUS result; + + /* Parse parameters */ + + if (!PyArg_ParseTuple(args, "O!", &lsa_policy_hnd_type, &po)) + return NULL; + + hnd = (lsa_policy_hnd_object *)po; + + /* Call rpc function */ + + result = cli_lsa_close(hnd->cli, hnd->mem_ctx, &hnd->pol); + + /* Cleanup samba stuf */ + + cli_shutdown(hnd->cli); + talloc_destroy(hnd->mem_ctx); + + /* Return value */ + + Py_INCREF(Py_None); + return Py_None; } static PyObject *lsa_lookupnames(PyObject *self, PyObject *args, diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index ead54febda..450abbd6dc 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -28,76 +28,6 @@ PyObject *spoolss_error, *spoolss_werror; * Routines to convert from python hashes to Samba structures */ -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli) -{ - struct ntuser_creds nt_creds; - - if (!cli) { - cli = (struct cli_state *)malloc(sizeof(struct cli_state)); - if (!cli) - return NULL; - } - - ZERO_STRUCTP(cli); - - /* Extract credentials from the python dictionary and initialise - the ntuser_creds struct from them. */ - - ZERO_STRUCT(nt_creds); - nt_creds.pwd.null_pwd = True; - - if (creds && PyDict_Size(creds) > 0) { - char *username, *password, *domain; - PyObject *username_obj, *password_obj, *domain_obj; - - /* Check credentials passed are valid. This means the - username, domain and password keys must exist and be - string objects. */ - - username_obj = PyDict_GetItemString(creds, "username"); - domain_obj = PyDict_GetItemString(creds, "domain"); - password_obj = PyDict_GetItemString(creds, "password"); - - if (!username_obj || !domain_obj || !password_obj) { - error: - PyErr_SetString(spoolss_error, "invalid credentials"); - return NULL; - } - - if (!PyString_Check(username_obj) || - !PyString_Check(domain_obj) || - !PyString_Check(password_obj)) - goto error; - - username = PyString_AsString(username_obj); - domain = PyString_AsString(domain_obj); - password = PyString_AsString(password_obj); - - if (!username || !domain || !password) - goto error; - - /* Initialise nt_creds structure with passed creds */ - - fstrcpy(nt_creds.user_name, username); - fstrcpy(nt_creds.domain, domain); - - if (lp_encrypted_passwords()) - pwd_make_lm_nt_16(&nt_creds.pwd, password); - else - pwd_set_cleartext(&nt_creds.pwd, password); - - nt_creds.pwd.null_pwd = False; - } - - /* Now try to connect */ - - connect_fn(cli, system_name, &nt_creds); - - return cli; -} - PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol) { diff --git a/source3/python/py_spoolss.h b/source3/python/py_spoolss.h index 7c7669c752..777a2b5991 100644 --- a/source3/python/py_spoolss.h +++ b/source3/python/py_spoolss.h @@ -41,13 +41,6 @@ extern PyTypeObject spoolss_policy_hnd_type; extern PyObject *spoolss_error, *spoolss_werror; -/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials - are passed use them. */ - -typedef struct cli_state *(cli_pipe_fn)( - struct cli_state *cli, char *system_name, - struct ntuser_creds *creds); - #include "python/py_spoolss_proto.h" #endif /* _PY_SPOOLSS_H */ diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 6788dcccd1..3e3e5ef6ee 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -6,9 +6,6 @@ /* The following definitions come from python/py_spoolss.c */ -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli); PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol); void initspoolss(void); |