From 530758dc2a6dd6dce083789b328e16e51ba6573d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 16 Dec 2008 00:16:02 +0100 Subject: [PATCH] Add python extensions for dom_sid. --- librpc/idl/security.idl | 3 +-- source4/librpc/ndr/py_security.c | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 source4/librpc/ndr/py_security.c diff --git a/librpc/idl/security.idl b/librpc/idl/security.idl index d88931fc699..4c6aa235d76 100644 --- a/librpc/idl/security.idl +++ b/librpc/idl/security.idl @@ -26,10 +26,9 @@ cpp_quote("#define dom_sid28 dom_sid") /* same struct as dom_sid but in a variable byte buffer, which is maybe empty in NDR */ cpp_quote("#define dom_sid0 dom_sid") - - [ helper("librpc/gen_ndr/ndr_dom_sid.h"), + pyhelper("librpc/ndr/py_security.c"), pointer_default(unique) ] interface security diff --git a/source4/librpc/ndr/py_security.c b/source4/librpc/ndr/py_security.c new file mode 100644 index 00000000000..6888f143756 --- /dev/null +++ b/source4/librpc/ndr/py_security.c @@ -0,0 +1,58 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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, see . +*/ +#include "libcli/security/security.h" + +static PyObject *py_dom_sid_eq(PyObject *self, PyObject *args) +{ + struct dom_sid *this = py_talloc_get_ptr(self), *other; + PyObject *py_other; + + if (!PyArg_ParseTuple(args, "O", &py_other)) + return NULL; + + other = py_talloc_get_type(py_other, struct dom_sid); + if (other == NULL) + return Py_False; + + return dom_sid_equal(this, other)?Py_True:Py_False; +} + +static PyObject *py_dom_sid_str(PyObject *self) +{ + struct dom_sid *this = py_talloc_get_ptr(self); + char *str = dom_sid_string(NULL, this); + PyObject *ret = PyString_FromString(str); + talloc_free(str); + return ret; +} + +static PyObject *py_dom_sid_repr(PyObject *self) +{ + struct dom_sid *this = py_talloc_get_ptr(self); + char *str = dom_sid_string(NULL, this); + PyObject *ret = PyString_FromFormat("dom_sid('%s')", str); + talloc_free(str); + return ret; +} + +#define PY_DOM_SID_REPR py_dom_sid_repr + +#define PY_DOM_SID_EXTRA_METHODS \ + { "__eq__", (PyCFunction)py_dom_sid_eq, METH_VARARGS, "S.__eq__(x) -> S == x" }, \ + { "__str__", (PyCFunction)py_dom_sid_str, METH_NOARGS, "S.__str__() -> str(S)" }, \ -- 2.11.4.GIT