diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/python/py_samr.c | 241 |
1 files changed, 202 insertions, 39 deletions
diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 2271cb4464..9a19f9abd5 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -23,20 +23,6 @@ #include "python/py_samr.h" -PyObject *new_samr_connect_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_connect_hnd_object *o; - - o = PyObject_New(samr_connect_hnd_object, &samr_connect_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 */ @@ -48,20 +34,22 @@ PyObject *samr_ntstatus; /* This exception is raised when a RPC call returns a status code other than NT_STATUS_OK */ +/* SAMR connect handle object */ + static void py_samr_connect_hnd_dealloc(PyObject* self) { PyObject_Del(self); } -#if 0 +static PyMethodDef samr_connect_methods[] = { + { NULL } +}; static PyObject *py_samr_connect_hnd_getattr(PyObject *self, char *attrname) { return Py_FindMethod(samr_connect_methods, self, attrname); } -#endif - PyTypeObject samr_connect_hnd_type = { PyObject_HEAD_INIT(NULL) 0, @@ -70,7 +58,7 @@ PyTypeObject samr_connect_hnd_type = { 0, py_samr_connect_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_connect_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -80,15 +68,45 @@ PyTypeObject samr_connect_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_samr_connect_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + samr_connect_hnd_object *o; + + o = PyObject_New(samr_connect_hnd_object, &samr_connect_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* SAMR domain handle object */ + +static void py_samr_domain_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +static PyMethodDef samr_domain_methods[] = { + { NULL } +}; + +static PyObject *py_samr_domain_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(samr_domain_methods, self, attrname); +} + PyTypeObject samr_domain_hnd_type = { PyObject_HEAD_INIT(NULL) 0, "SAMR Domain Handle", - sizeof(samr_connect_hnd_object), + sizeof(samr_domain_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_domain_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_domain_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -98,15 +116,45 @@ PyTypeObject samr_domain_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_samr_domain_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + samr_domain_hnd_object *o; + + o = PyObject_New(samr_domain_hnd_object, &samr_domain_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* SAMR user handle object */ + +static void py_samr_user_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +static PyMethodDef samr_user_methods[] = { + { NULL } +}; + +static PyObject *py_samr_user_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(samr_user_methods, self, attrname); +} + PyTypeObject samr_user_hnd_type = { PyObject_HEAD_INIT(NULL) 0, "SAMR User Handle", - sizeof(samr_connect_hnd_object), + sizeof(samr_user_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_user_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_user_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -116,15 +164,45 @@ PyTypeObject samr_user_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_samr_user_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + samr_user_hnd_object *o; + + o = PyObject_New(samr_user_hnd_object, &samr_user_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* SAMR group handle object */ + +static void py_samr_group_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +static PyMethodDef samr_group_methods[] = { + { NULL } +}; + +static PyObject *py_samr_group_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(samr_group_methods, self, attrname); +} + PyTypeObject samr_group_hnd_type = { PyObject_HEAD_INIT(NULL) 0, "SAMR Group Handle", - sizeof(samr_connect_hnd_object), + sizeof(samr_group_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_group_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_group_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -134,15 +212,45 @@ PyTypeObject samr_group_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_samr_group_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + samr_group_hnd_object *o; + + o = PyObject_New(samr_group_hnd_object, &samr_group_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* Alias handle object */ + +static void py_samr_alias_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +static PyMethodDef samr_alias_methods[] = { + { NULL } +}; + +static PyObject *py_samr_alias_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(samr_alias_methods, self, attrname); +} + PyTypeObject samr_alias_hnd_type = { PyObject_HEAD_INIT(NULL) 0, "SAMR Alias Handle", - sizeof(samr_connect_hnd_object), + sizeof(samr_alias_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_alias_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_alias_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -152,24 +260,79 @@ PyTypeObject samr_alias_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_samr_alias_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + samr_alias_hnd_object *o; + + o = PyObject_New(samr_alias_hnd_object, &samr_alias_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) +{ + static char *kwlist[] = { "server", "creds", "access", NULL }; + uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; + char *server_name; + struct cli_state *cli; + POLICY_HND hnd; + TALLOC_CTX *mem_ctx; + PyObject *result = NULL, *creds = NULL; + NTSTATUS ntstatus; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, + &creds, &desired_access)) + return NULL; + + if (!(cli = open_pipe_creds(server_name, creds, cli_samr_initialise, + NULL))) { + + /* Error state set in open_pipe_creds() */ + + goto done; + } + + if (!(mem_ctx = talloc_init())) { + PyErr_SetString(samr_ntstatus, + "unable to initialise talloc context\n"); + goto done; + } + + ntstatus = cli_samr_connect(cli, mem_ctx, desired_access, &hnd); + + if (!NT_STATUS_IS_OK(ntstatus)) { + cli_shutdown(cli); + SAFE_FREE(cli); + PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus)); + goto done; + } + + result = new_samr_connect_hnd_object(cli, mem_ctx, &hnd); + +done: + return result; +} + +/* + * Module initialisation + */ + static PyMethodDef samr_methods[] = { /* Open/close samr connect handles */ -#if 0 - { "connect", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, + { "connect", samr_connect, METH_VARARGS | METH_KEYWORDS, "Open a connect handle" }, - { "close", lsa_close, METH_VARARGS, "Close a policy handle" }, -#endif - { NULL } }; -/* - * Module initialisation -*/ - void initsamr(void) { PyObject *module, *dict; |