diff options
author | Sumit Bose <sbose@redhat.com> | 2013-04-22 17:57:53 +0200 |
---|---|---|
committer | Sumit Bose <sbose@redhat.com> | 2013-04-23 12:35:38 +0200 |
commit | d7e2c673f04d994c4447191a3c4e53db07026748 (patch) | |
tree | a20138a1793b704e4d8f79ef2c3db16d91b94686 | |
parent | e0d43857c7d6fda0c71be84e4eb9f4bee63fa186 (diff) | |
download | sssd-python_api.tar.gz sssd-python_api.tar.xz sssd-python_api.zip |
Add python interface to nss_idmappython_api
-rw-r--r-- | Makefile.am | 15 | ||||
-rw-r--r-- | contrib/sssd.spec.in | 1 | ||||
-rw-r--r-- | src/python/pysss_nss_idmap.c | 169 |
3 files changed, 184 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 59024e0e5..0aa5b5b23 100644 --- a/Makefile.am +++ b/Makefile.am @@ -229,7 +229,8 @@ if BUILD_PYTHON_BINDINGS pyexec_LTLIBRARIES = \ pysss.la \ pyhbac.la \ - pysss_murmur.la + pysss_murmur.la \ + pysss_nss_idmap.la endif dist_noinst_SCRIPTS = \ @@ -1736,6 +1737,18 @@ pysss_murmur_la_LIBADD = \ pysss_murmur_la_LDFLAGS = \ -avoid-version \ -module + +pysss_nss_idmap_la_SOURCES = \ + src/python/pysss_nss_idmap.c +pysss_nss_idmap_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(PYTHON_CFLAGS) +pysss_nss_idmap_la_LIBADD = \ + $(PYTHON_LIBS) \ + libsss_nss_idmap.la +pysss_nss_idmap_la_LDFLAGS = \ + -avoid-version \ + -module endif ################ diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in index e4c550d99..1213a2acf 100644 --- a/contrib/sssd.spec.in +++ b/contrib/sssd.spec.in @@ -446,6 +446,7 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man1/sss_ssh_knownhostsproxy.1* %{python_sitearch}/pysss.so %{python_sitearch}/pysss_murmur.so +%{python_sitearch}/pysss_nss_idmap.so %{_includedir}/sss_nss_idmap.h %{_libdir}/libsss_nss_idmap.so diff --git a/src/python/pysss_nss_idmap.c b/src/python/pysss_nss_idmap.c new file mode 100644 index 000000000..cf68a68a8 --- /dev/null +++ b/src/python/pysss_nss_idmap.c @@ -0,0 +1,169 @@ +/* + Authors: + Sumit Bose <sbose@redhat.com> + + Copyright (C) 2012 Red Hat + + 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 <http://www.gnu.org/licenses/>. +*/ + +#include <Python.h> +#include "util/sss_python.h" + +#include "sss_client/idmap/sss_nss_idmap.h" + +PyDoc_STRVAR(getsidbyname_doc, +"getsidbyname(name) -> SID string\n\ +\n\ +Returns the SID of the object with the given name." +); + +static PyObject * py_getsidbyname(PyObject *module, PyObject *args) +{ + const char *name; + char *sid; + int ret; + PyObject *py_sid; + + if (!PyArg_ParseTuple(args, sss_py_const_p(char, "s"), &name)) { + PyErr_Format(PyExc_ValueError, "Invalid argument\n"); + return NULL; + } + + ret = sss_nss_getsidbyname(name, &sid); + if (ret != 0) { + PyErr_Format(PyExc_IOError, "Operation not supported."); + return NULL; + } + + py_sid = PyString_FromString(sid); + + free(sid); + + return py_sid; +} + +PyDoc_STRVAR(getsidbyid_doc, +"getsidbyid(id) -> SID string\n\ +\n\ +Returns the SID of the object with the given POSIX ID." +); + +static PyObject * py_getsidbyid(PyObject *module, PyObject *args) +{ + long long id; + char *sid; + int ret; + PyObject *py_sid; + + if (!PyArg_ParseTuple(args, sss_py_const_p(char, "L"), &id)) { + PyErr_Format(PyExc_ValueError, "Invalid argument\n"); + return NULL; + } + + if (id < 0 || id > UINT32_MAX) { + PyErr_Format(PyExc_ValueError, "Invalid value\n"); + return NULL; + } + + ret = sss_nss_getsidbyid((uint32_t) id, &sid); + if (ret != 0) { + PyErr_Format(PyExc_IOError, "Operation not supported."); + return NULL; + } + + py_sid = PyString_FromString(sid); + + free(sid); + + return py_sid; +} + +PyDoc_STRVAR(getnamebysid_doc, +"getnamebysid(sid) -> Name\n\ +\n\ +Returns the name of the object with the given SID." +); + +static PyObject * py_getnamebysid(PyObject *module, PyObject *args) +{ + const char *sid; + char *name; + int ret; + PyObject *py_name; + + if (!PyArg_ParseTuple(args, sss_py_const_p(char, "s"), &sid)) { + PyErr_Format(PyExc_ValueError, "Invalid argument\n"); + return NULL; + } + + ret = sss_nss_getnamebysid(sid, &name); + if (ret != 0) { + PyErr_Format(PyExc_IOError, "Operation not supported."); + return NULL; + } + + py_name = PyString_FromString(name); + + free(name); + + return py_name; +} + +PyDoc_STRVAR(getidbysid_doc, +"getidbysid(sid) -> POSIX ID\n\ +\n\ +Returns the POSIX ID of the object with the given SID." +); + +static PyObject * py_getidbysid(PyObject *module, PyObject *args) +{ + const char *sid; + uint32_t id; + enum sss_id_type id_type; + int ret; + + if (!PyArg_ParseTuple(args, sss_py_const_p(char, "s"), &sid)) { + PyErr_Format(PyExc_ValueError, "Invalid argument\n"); + return NULL; + } + + ret = sss_nss_getidbysid(sid, &id, &id_type); + if (ret != 0) { + PyErr_Format(PyExc_IOError, "Operation not supported."); + return NULL; + } + + return PyInt_FromLong((long) id); +} + +static PyMethodDef methods[] = { + { sss_py_const_p(char, "getsidbyname"), (PyCFunction) py_getsidbyname, + METH_VARARGS, getsidbyname_doc }, + { sss_py_const_p(char, "getsidbyid"), (PyCFunction) py_getsidbyid, + METH_VARARGS, getsidbyid_doc }, + { sss_py_const_p(char, "getnamebysid"), (PyCFunction) py_getnamebysid, + METH_VARARGS, getnamebysid_doc }, + { sss_py_const_p(char, "getidbysid"), (PyCFunction) py_getidbysid, + METH_VARARGS, getidbysid_doc }, + { NULL,NULL, 0, NULL } +}; + + +PyMODINIT_FUNC +initpysss_nss_idmap(void) +{ + Py_InitModule3(sss_py_const_p(char, "pysss_nss_idmap"), + methods, sss_py_const_p(char, "SSSD ID-mapping functions")); +} |