c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose Sumit Bose <sbose@redhat.com>
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose Alexander Bokovoy <abokovoy@redhat.com>
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose Copyright (C) 2013 Red Hat
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose This program is free software; you can redistribute it and/or modify
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose it under the terms of the GNU General Public License as published by
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose the Free Software Foundation; either version 3 of the License, or
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose (at your option) any later version.
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose This program is distributed in the hope that it will be useful,
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose GNU General Public License for more details.
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose You should have received a copy of the GNU General Public License
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int add_dict(PyObject *py_result, PyObject *key, PyObject *res_type,
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda ret = PyDict_SetItem(py_dict, PyBytes_FromString(SSS_TYPE_KEY), id_type);
e1a9780b5c75602618773b1510e076897e129b36Sumit Bosestatic char *py_string_or_unicode_as_string(PyObject *inp)
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose PyErr_Format(PyExc_TypeError, "input must be unicode or a string");
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int do_getsidbyname(PyObject *py_result, PyObject *py_name)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose ret = sss_nss_getsidbyname(name, &sid, &id_type);
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda ret = add_dict(py_result, py_name, PyBytes_FromString(SSS_SID_KEY),
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda PyUnicode_FromString(sid), PYNUMBER_FROMLONG(id_type));
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int do_getnamebysid(PyObject *py_result, PyObject *py_sid)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose ret = sss_nss_getnamebysid(sid, &name, &id_type);
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda ret = add_dict(py_result, py_sid, PyBytes_FromString(SSS_NAME_KEY),
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda PyUnicode_FromString(name), PYNUMBER_FROMLONG(id_type));
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int do_getsidbyid(PyObject *py_result, PyObject *py_id)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose ret = sss_nss_getsidbyid((uint32_t) id, &sid, &id_type);
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda ret = add_dict(py_result, py_id, PyBytes_FromString(SSS_SID_KEY),
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda PyUnicode_FromString(sid), PYNUMBER_FROMLONG(id_type));
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bosestatic int do_getnamebycert(PyObject *py_result, PyObject *py_cert)
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose ret = sss_nss_getnamebycert(cert, &name, &id_type);
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose ret = add_dict(py_result, py_cert, PyBytes_FromString(SSS_NAME_KEY),
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose PyUnicode_FromString(name), PYNUMBER_FROMLONG(id_type));
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int do_getidbysid(PyObject *py_result, PyObject *py_sid)
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda ret = add_dict(py_result, py_sid, PyBytes_FromString(SSS_ID_KEY),
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda PYNUMBER_FROMLONG(id), PYNUMBER_FROMLONG(id_type));
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic int do_lookup(enum lookup_type type, PyObject *py_result,
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic PyObject *check_args(enum lookup_type type, PyObject *args)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose if (!PyArg_ParseTuple(args, sss_py_const_p(char, "O"), &obj)) {
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyErr_Format(PyExc_ValueError, "Unable to retrieve argument\n");
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda PyBytes_Check(obj) || PyUnicode_Check(obj) ||
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda (type == SIDBYID && (PYNUMBER_CHECK(obj))))) {
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose "Only string, long or list or tuples of them " \
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose "are accepted\n");
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose "Unable to allocate resulting dictionary\n");
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose for(i=0; i < len; i++) {
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda (PyBytes_Check(py_value) || PyUnicode_Check(py_value) ||
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda (type == SIDBYID && PYNUMBER_CHECK(py_value)))) {
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose /* Skip this name */
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose case ENOENT: /* nothing found, return empty dict */
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose PyErr_Format(PyExc_ValueError, "Unable to retrieve result\n");
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyErr_Format(PyExc_IOError, "Operation not supported\n");
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose"getsidbyname(name or list/tuple of names) -> dict(name => dict(results))\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseReturns a dictionary with a dictonary of results for each given name.\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseThe result dictonary contain the SID and the type of the object which can be\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Boseaccessed with the key constants SID_KEY and TYPE_KEY, respectively.\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseThe return type can be one of the following constants:\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose- ID_NOT_SPECIFIED\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose- ID_GROUP\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic PyObject * py_getsidbyname(PyObject *module, PyObject *args)
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose"getsidbyid(id or list/tuple of id) -> dict(id => dict(results))\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseReturns a dictionary with a dictonary of results for each given POSIX ID.\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseThe result dictonary contain the SID and the type of the object which can be\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Boseaccessed with the key constants SID_KEY and TYPE_KEY, respectively."
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic PyObject * py_getsidbyid(PyObject *module, PyObject *args)
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose"getnamebysid(sid or list/tuple of sid) -> dict(sid => dict(results))\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseReturns a dictionary with a dictonary of results for each given SID.\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseThe result dictonary contain the name and the type of the object which can be\n\
fed544f8c960bf346679870843854bf43e83c453Ondrej Kosaccessed with the key constants NAME_KEY and TYPE_KEY, respectively.\n\
fed544f8c960bf346679870843854bf43e83c453Ondrej KosNOTE: getnamebysid currently works only with id_provider set as \"ad\" or \"ipa\""
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic PyObject * py_getnamebysid(PyObject *module, PyObject *args)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose"getidbysid(sid) -> POSIX ID\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseReturns the POSIX ID of the object with the given SID."
e1a9780b5c75602618773b1510e076897e129b36Sumit Bose"getidbysid(sid or list/tuple of sid) -> dict(sid => dict(results))\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseReturns a dictionary with a dictonary of results for each given SID.\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit BoseThe result dictonary contain the POSIX ID and the type of the object which\n\
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosecan be accessed with the key constants ID_KEY and TYPE_KEY, respectively."
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bosestatic PyObject * py_getidbysid(PyObject *module, PyObject *args)
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose"getnamebycert(sid or list/tuple of certificates) -> dict(sid => dict(results))\n\
9c88f837ffacf6548c13825589b327de1a5525f3Sumit BoseReturns a dictionary with a dictonary of results for each given certificates.\n\
9c88f837ffacf6548c13825589b327de1a5525f3Sumit BoseThe result dictonary contain the name and the type of the object which can be\n\
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Boseaccessed with the key constants NAME_KEY and TYPE_KEY, respectively.\n\
9c88f837ffacf6548c13825589b327de1a5525f3Sumit BoseNOTE: getnamebycert currently works only with id_provider set as \"ad\" or \"ipa\""
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bosestatic PyObject * py_getnamebycert(PyObject *module, PyObject *args)
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose { sss_py_const_p(char, "getsidbyname"), (PyCFunction) py_getsidbyname,
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose { sss_py_const_p(char, "getsidbyid"), (PyCFunction) py_getsidbyid,
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose { sss_py_const_p(char, "getnamebysid"), (PyCFunction) py_getnamebysid,
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose { sss_py_const_p(char, "getidbysid"), (PyCFunction) py_getidbysid,
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose { sss_py_const_p(char, "getnamebycert"), (PyCFunction) py_getnamebycert,
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrdastatic struct PyModuleDef pysss_nss_idmap_def = {
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda "pysss_nss_idmap",
341a00311680a440d7f979f06c34c70d86c9367aBohuslav Kabrda module = PyModule_Create(&pysss_nss_idmap_def);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose module = Py_InitModule3(sss_py_const_p(char, "pysss_nss_idmap"),
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose sss_py_const_p(char, "SSSD ID-mapping functions"));
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddIntConstant(module, "ID_NOT_SPECIFIED",
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddIntConstant(module, "ID_USER", SSS_ID_TYPE_UID);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddIntConstant(module, "ID_GROUP", SSS_ID_TYPE_GID);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddIntConstant(module, "ID_BOTH", SSS_ID_TYPE_BOTH);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddStringConstant(module, "SID_KEY", SSS_SID_KEY);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddStringConstant(module, "NAME_KEY", SSS_NAME_KEY);
c080a11e9e88f35e40aff4e476cabbd971833019Sumit Bose PyModule_AddStringConstant(module, "ID_KEY", SSS_ID_KEY);