pysss.c revision 758ce3f01b4ed73c3bc35cd7039fac26fdf16386
8c294c1cd4d721818a59684cf7f2b36123f79163Stephen Gallagher Jakub Hrozek <jhrozek@redhat.com>
8c294c1cd4d721818a59684cf7f2b36123f79163Stephen Gallagher Copyright (C) 2009 Red Hat
9542512d7be40f2000298c86d3d2b728f4f0f65aStephen Gallagher This program is free software; you can redistribute it and/or modify
9542512d7be40f2000298c86d3d2b728f4f0f65aStephen Gallagher it under the terms of the GNU General Public License as published by
9542512d7be40f2000298c86d3d2b728f4f0f65aStephen Gallagher the Free Software Foundation; either version 3 of the License, or
c6e39e15178675d0779e0ae855245774a09b4eb5Nikolai Kondrashov (at your option) any later version.
c6e39e15178675d0779e0ae855245774a09b4eb5Nikolai Kondrashov This program is distributed in the hope that it will be useful,
c6e39e15178675d0779e0ae855245774a09b4eb5Nikolai Kondrashov but WITHOUT ANY WARRANTY; without even the implied warranty of
c6e39e15178675d0779e0ae855245774a09b4eb5Nikolai Kondrashov MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fd5a4eacd56700ffb08a73121aeacdc806cb0132Sumit Bose GNU General Public License for more details.
8b1f525acd20f36c836e827de3c251088961c5d9Stephen Gallagher You should have received a copy of the GNU General Public License
8b1f525acd20f36c836e827de3c251088961c5d9Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * function taken from samba sources tree as of Aug 20 2009,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list,
90fd1bbd6035cdab46faa3a695a2fb2be6508b17Sumit Bose ret = talloc_array(mem_ctx, char *, PyList_Size(list)+1);
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke PyErr_Format(PyExc_TypeError, "%s should be strings", paramname);
f3c85d900c4663854cc7bbae7d9f77867ed1f69bSumit Bose ret[i] = talloc_strndup(ret, PyString_AsString(item),
d921c1eba437662437847279f251a0a5d8f70127Maxim/* ======================= sysdb python wrappers ==========================*/
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * The sss.password object
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallaghertypedef struct {
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher * The transaction object
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Error reporting
054b5d4bb98973698f74d66b14ccd14394b53f10Lukas Slebodnikstatic void PyErr_SetSssErrorWithMessage(int ret, const char *message)
a3d176d116ceccd6a7547c128fab5df5cdd2c2b6Michal Zidek PyObject *exc = Py_BuildValue(discard_const_p(char, "(is)"),
9a3e40dc49c1e38bf58e45be5adff37615f3910bJan Cholasta PyErr_SetSssErrorWithMessage(ret, strerror(ret));
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Common init of all methods
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic struct tools_ctx *init_ctx(PySssLocalObject *self)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx = talloc_zero(self->mem_ctx, struct tools_ctx);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* tctx->nctx is NULL here, which is OK since we don't parse domains
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * in the python bindings (yet?) */
e7311aec8d691e5427317442387af1bc8fff3742Jan Cholasta * Add a user
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "Add a user named ``username``.\n\n"
19d3aba12c70528708be9440aca66038a291f29eYassir Elley ":param username: name of the user\n\n"
19d3aba12c70528708be9440aca66038a291f29eYassir Elley ":param kwargs: Keyword arguments that customize the operation\n\n"
19d3aba12c70528708be9440aca66038a291f29eYassir Elley "* useradd can be customized further with keyword arguments:\n"
f3a25949de81f80c136bb073e4a8f504b080c20cJakub Hrozek " * ``uid``: The UID of the user\n"
f3a25949de81f80c136bb073e4a8f504b080c20cJakub Hrozek " * ``gid``: The GID of the user\n"
f3a25949de81f80c136bb073e4a8f504b080c20cJakub Hrozek " * ``gecos``: The comment string\n"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek " * ``homedir``: Home directory\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``shell``: Login shell\n"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose " * ``skel``: Specify an alternative skeleton directory\n"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose " * ``create_home``: (bool) Force creation of home directory on or off\n"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose " * ``groups``: List of groups the user is member of\n");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic PyObject *py_sss_useradd(PySssLocalObject *self,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher unsigned long uid = 0;
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher unsigned long gid = 0;
effcbdb12c7ef892f1fd92a745cb33a08ca4ba30Stephen Gallagher const char * const kwlist[] = { "username", "uid", "gid", "gecos",
4bd20c075f0f187db0181dc53d00ab6cd47fdb4dJakub Hrozek /* parse arguments */
d00ffd2cb4e2f17c75b466178bb645b5c9317909Pallavi Jha tctx->octx->addgroups = PyList_AsStringList(tctx, py_groups, "groups");
f69f3581658351003a6d9245045e41d0efb85022Sumit Bose /* user-wise the parameter is only bool - do or don't,
1ce58f139699dd26b8888f4131c996263b6a80a5Jakub Hrozek * however we must have a third state - undecided, pick default */
802385896dc1c4e7b8bbd40dcfe3cd131f68e696Sumit Bose /* fill in defaults */
99f8be128274eba264ea1434a7eb2800bced5902Lukas Slebodnik /* Add the user within a transaction */
a2e417f38c57ed87c956ddcecf4dafca93842b65Lukas Slebodnik tctx->error = sysdb_transaction_start(tctx->sysdb);
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek /* useradd */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = useradd(tctx, tctx->sysdb, tctx->octx);
bf5a808fa92007c325c3996e79694badfab201d4Stephen Gallagher tctx->error = sysdb_transaction_commit(tctx->sysdb);
bf5a808fa92007c325c3996e79694badfab201d4Stephen Gallagher /* Create user's home directory and/or mail spool */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* We need to know the UID and GID of the user, if
bf5a808fa92007c325c3996e79694badfab201d4Stephen Gallagher * sysdb did assign it automatically, do a lookup */
150b76e13b7c4f3ccf1d709bf517ca2af6b2c9a2Jakub Hrozek if (tctx->octx->uid == 0 || tctx->octx->gid == 0) {
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* failure here should not be fatal */
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke /* We do not handle return value of sysdb_transaction_cancel()
af4ffe1001adcc0a96897e426d26444f07af9aa1Benjamin Franzke * because we don't want to overwrite previous error code.
c7919a4fe41133cc466aa3d9431bfceee5784e7bJan Cholasta * Delete a user
69aaef8719c5cf33ed1c4090fa313ba281bf8a02Jakub Hrozek "Remove the user named ``username``.\n\n"
3b08dec5ee634f83ee18e1753d5ffe0ac5e3c458Jakub Hrozek ":param username: Name of user being removed\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ":param kwargs: Keyword arguments that customize the operation\n\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "* userdel can be customized further with keyword arguments:\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``force``: (bool) Force removal of files not owned by the user\n"
c7919a4fe41133cc466aa3d9431bfceee5784e7bJan Cholasta " * ``remove``: (bool) Toggle removing home directory and mail spool\n");
c7919a4fe41133cc466aa3d9431bfceee5784e7bJan Cholastastatic PyObject *py_sss_userdel(PySssLocalObject *self,
3b1df539835367cb81cd5ff0f9959947d5642e55Stephen Gallagher const char * const kwlist[] = { "username", "remove", "force", NULL };
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher if(!PyArg_ParseTupleAndKeywords(args, kwds,
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov * Fills in defaults for ops_ctx user did not specify.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* Delete the user */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ret = userdel(tctx, self->sysdb, tctx->octx);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Modify a user
e7311aec8d691e5427317442387af1bc8fff3742Jan Cholasta "Modify a user.\n\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ":param username: Name of user being modified\n\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ":param kwargs: Keyword arguments that customize the operation\n\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "* usermod can be customized further with keyword arguments:\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``uid``: The UID of the user\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``gid``: The GID of the user\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``gecos``: The comment string\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``homedir``: Home directory\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``shell``: Login shell\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``addgroups``: List of groups to add the user to\n"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny " * ``rmgroups``: List of groups to remove the user from\n"
769347ad4d35d43488eb98f980143495b0db415dStef Walter " * ``lock``: Lock or unlock the account\n");
769347ad4d35d43488eb98f980143495b0db415dStef Walterstatic PyObject *py_sss_usermod(PySssLocalObject *self,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher unsigned long uid = 0;
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher unsigned long gid = 0;
543676afec3c08fdc0a5a794976adc8dfdca974bJakub Hrozek unsigned long lock = 0;
543676afec3c08fdc0a5a794976adc8dfdca974bJakub Hrozek const char * const kwlist[] = { "username", "uid", "gid", "lock",
ca261795ce61c41d7e62217ccb2ee913923040ffPavel Březina /* parse arguments */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher if (!PyArg_ParseTupleAndKeywords(args, kwds,
fe2091327ff44f80d6681c261494e4432404e9baStephen Gallagher if (lock && lock != DO_LOCK && lock != DO_UNLOCK) {
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "Unkown value for lock parameter");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->octx->addgroups = PyList_AsStringList(tctx,
2e6087c6cc903d5164b9a1d5e3d791fd046001d9Jakub Hrozek "addgroups");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->octx->rmgroups = PyList_AsStringList(tctx,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* Modify the user within a transaction */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = sysdb_transaction_start(tctx->sysdb);
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter /* usermod */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = usermod(tctx, tctx->sysdb, tctx->octx);
823a5b3f4375f12b6edae4dd5169ee01771baebeJan Zeleny tctx->error = sysdb_transaction_commit(tctx->sysdb);
7452f1b637276ce582b120f8f5482ae7f3b6bd47Jakub Hrozek /* We do not handle return value of sysdb_transaction_cancel()
918b2a5a91f1c551d48f4bffed2a28c36fdb4be1Simo Sorce * because we don't want to overwrite previous error code.
ef39c0adcb61b16f9edc7beb4cdc8f3b0d5a8f15Stephen Gallagher "Add a group.\n\n"
8c3a4809b3420657289b42f028a1c9019b112991Stephen Gallagher ":param groupname: Name of group being added\n\n"
eb2e21b764d03544d8161e9956d7f70b07b75f77Simo Sorce ":param kwargs: Keyword arguments ro customize the operation\n\n"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose "* groupmod can be customized further with keyword arguments:\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher " * ``gid``: The GID of the group\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic PyObject *py_sss_groupadd(PySssLocalObject *self,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher unsigned long gid = 0;
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter const char * const kwlist[] = { "groupname", "gid", NULL };
3f98cdc011bb4e8cd22c088f288b0bcdb6452492Jakub Hrozek /* parse arguments */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* Add the group within a transaction */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = sysdb_transaction_start(tctx->sysdb);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* groupadd */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = groupadd(tctx->sysdb, tctx->octx);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher tctx->error = sysdb_transaction_commit(tctx->sysdb);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* We do not handle return value of sysdb_transaction_cancel()
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * because we don't want to overwrite previous error code.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Delete a group
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "Remove a group.\n\n"
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ":param groupname: Name of group being removed\n");
4139a7a731f2831963a42b26aac111422be28792Jakub Hrozekstatic PyObject *py_sss_groupdel(PySssLocalObject *self,
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose if(!PyArg_ParseTuple(args, discard_const_p(char, "s"), &groupname)) {
3b08dec5ee634f83ee18e1753d5ffe0ac5e3c458Jakub Hrozek /* Remove the group */
eaa723b4d06b4c1e588df67bef44a84bbfaebf1aLukas Slebodnik * Modify a group
eaa723b4d06b4c1e588df67bef44a84bbfaebf1aLukas Slebodnik"Modify a group.\n\n"
86b61156743b7ebdc049450a6f88452890fd9a61Jakub Hrozek":param groupname: Name of group being modified\n\n"
86b61156743b7ebdc049450a6f88452890fd9a61Jakub Hrozek":param kwargs: Keyword arguments ro customize the operation\n\n"
77c0d1f6074059dafd2293f9c42ea0f9d60f8aadJakub Hrozek"* groupmod can be customized further with keyword arguments:\n"
77c0d1f6074059dafd2293f9c42ea0f9d60f8aadJakub Hrozek" * ``gid``: The GID of the group\n\n"
77c0d1f6074059dafd2293f9c42ea0f9d60f8aadJakub Hrozek" * ``addgroups``: Groups to add the group to\n\n"
77c0d1f6074059dafd2293f9c42ea0f9d60f8aadJakub Hrozek" * ``rmgroups``: Groups to remove the group from\n\n");
fe2091327ff44f80d6681c261494e4432404e9baStephen Gallagherstatic PyObject *py_sss_groupmod(PySssLocalObject *self,
654757bcead49427baaeb1b368c0e3433b67c51aJan Engelhardt unsigned long gid = 0;
96453f402831275a39d5fb89c33c9776e148d03fStephen Gallagher const char * const kwlist[] = { "groupname", "gid", "addgroups",
96453f402831275a39d5fb89c33c9776e148d03fStephen Gallagher /* parse arguments */
87c07559af5cfcd2752295ef7c425bd3205f426fStephen Gallagher if (!PyArg_ParseTupleAndKeywords(args, kwds,
fe2091327ff44f80d6681c261494e4432404e9baStephen Gallagher tctx->octx->addgroups = PyList_AsStringList(tctx,
fe2091327ff44f80d6681c261494e4432404e9baStephen Gallagher tctx->octx->rmgroups = PyList_AsStringList(tctx,
b9d8c6172e48a2633ebe196b2e88bebdf9523c20Stef Walter "rmgroups");
dbea04f585a30d001b574317c068cd03a4fa332bJakub Hrozek /* Modify the group within a transaction */
5a70b84cb66fb8c7a3fce0e3f2e4b61e0b2ea9d4Simo Sorce tctx->error = sysdb_transaction_start(tctx->sysdb);
22d381367c27910fe82f476a76b9f4ede555e35aLukas Slebodnik /* groupmod */
12805da52a93c268290cec7b8fbbdbd4ea8abc3eLukas Slebodnik tctx->error = groupmod(tctx, tctx->sysdb, tctx->octx);
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek tctx->error = sysdb_transaction_commit(tctx->sysdb);
3f98cdc011bb4e8cd22c088f288b0bcdb6452492Jakub Hrozek /* We do not handle return value of sysdb_transaction_cancel()
3f98cdc011bb4e8cd22c088f288b0bcdb6452492Jakub Hrozek * because we don't want to overwrite previous error code.
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek * Get list of groups user belongs to
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek "Get list of groups user belongs to.\n\n"
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek "NOTE: The interface uses the system NSS calls and is not limited to "
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek "users served by the SSSD!\n"
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidek ":param username: name of user to get list for\n");
42ec8af02ecf1937e4db9b1ecc6216022634f0f9Michal Zidekstatic PyObject *py_sss_getgrouplist(PyObject *self, PyObject *args)
577ba99b3150404533bd3d859522a2c994b17e76Lukas Slebodnik if(!PyArg_ParseTuple(args, discard_const_p(char, "s"), &username)) {
bbaba8b3ef9bc101863b8687f234f4ee956caacdPavel Březina ret = getgrouplist(username, pw->pw_gid, groups, &ngroups);
3fc158e59eebbc2f538fe0076a03928d0d4eab9fPavel Březina groups = realloc(groups, ngroups * sizeof(gid_t));
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose groups_tuple = PyTuple_New((Py_ssize_t) ngroups);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher for (i = 0; i < ngroups; i++) {
654757bcead49427baaeb1b368c0e3433b67c51aJan Engelhardt PyTuple_SetItem(groups_tuple, i, PyString_FromString(gr->gr_name));
a6098862048d4bb469130b9ff21be3020d6f2c54Sumit Bose/*** python plumbing begins here ***/
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek * The sss.local destructor
f28b09f887870c10c8c611beee3c17eaa9ef74f3Lukas Slebodnikstatic void PySssLocalObject_dealloc(PySssLocalObject *self)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose * The sss.local constructor
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bosestatic PyObject *PySssLocalObject_new(PyTypeObject *type,
a9c287bda3fc2a1e12cef2135ade96945f11ad01Sumit Bose self = (PySssLocalObject *) type->tp_alloc(type, 0);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose confdb_path = talloc_asprintf(self->mem_ctx, "%s/%s", DB_PATH, CONFDB_FILE);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose /* Connect to the conf db */
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ret = confdb_init(self->mem_ctx, &self->confdb, confdb_path);
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose "Could not initialize connection to the confdb\n");
885386b7e3f1c3e74b354576b98a092b0835d64eSumit Bose ret = sssd_domain_init(self->mem_ctx, self->confdb, "local",
f3c85d900c4663854cc7bbae7d9f77867ed1f69bSumit Bose "Could not initialize connection to the sysdb\n");
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina * sss.local object methods
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina { sss_py_const_p(char, "useradd"), (PyCFunction) py_sss_useradd,
efa6c1f75c4c18bcc148d6e7efd429c2d56499adPavel Březina { sss_py_const_p(char, "userdel"), (PyCFunction) py_sss_userdel,
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina { sss_py_const_p(char, "usermod"), (PyCFunction) py_sss_usermod,
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina { sss_py_const_p(char, "groupadd"), (PyCFunction) py_sss_groupadd,
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina { sss_py_const_p(char, "groupdel"), (PyCFunction) py_sss_groupdel,
a7e27c11866a48742bb70564b88e15bf15e9367dPavel Březina { sss_py_const_p(char, "groupmod"), (PyCFunction) py_sss_groupmod,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * sss.local object properties
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter .tp_dealloc = (destructor) PySssLocalObject_dealloc,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter .tp_doc = sss_py_const_p(char, "SSS DB manipulation"),
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter/* ==================== obfuscation python wrappers ========================*/
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Walter * The sss.local object
b699c4d7f85a5404be1d1ee9450331aea869b886Stef Waltertypedef struct {
574a1c20f114851071ae74112b34488c3d1aeeb3Ondrej Kos"Obfuscate a password\n\n"
769347ad4d35d43488eb98f980143495b0db415dStef Walter":param password: The password to obfuscate\n\n"
769347ad4d35d43488eb98f980143495b0db415dStef Walter":param method: The obfuscation method\n\n");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic PyObject *py_sss_encrypt(PySssPasswordObject *self,
eb2e21b764d03544d8161e9956d7f70b07b75f77Simo Sorce /* parse arguments */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher if (!PyArg_ParseTuple(args, discard_const_p(char, "s#i"),
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ret = sss_password_encrypt(tctx, password, plen+1,
577ba99b3150404533bd3d859522a2c994b17e76Lukas Slebodnik retval = Py_BuildValue(sss_py_const_p(char, "s"), obfpwd);
577ba99b3150404533bd3d859522a2c994b17e76Lukas Slebodnik"Deobfuscate a password\n\n"
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina":param obfpwd: The password to convert back to clear text\n\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic PyObject *py_sss_decrypt(PySssPasswordObject *self,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* parse arguments */
e7311aec8d691e5427317442387af1bc8fff3742Jan Cholasta if (!PyArg_ParseTuple(args, discard_const_p(char, "s"),
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose ret = sss_password_decrypt(tctx, obfpwd, &password);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek * The sss.password destructor
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozekstatic void PySssPasswordObject_dealloc(PySssPasswordObject *self)
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek * The sss.password constructor
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekstatic PyObject *PySssPasswordObject_new(PyTypeObject *type,
1a59af8245f183f22d87d067a90197d8e2ea958dJakub Hrozek self = (PySssPasswordObject *) type->tp_alloc(type, 0);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * sss.password object methods
ac47e8854f3bc404f2a35c6682faf621673d6b32Pavel Březina { sss_py_const_p(char, "encrypt"), (PyCFunction) py_sss_encrypt,
b79e0e50a935d108173ca3062f2afe16103fcb1dPavel Březina METH_VARARGS | METH_STATIC, py_sss_encrypt__doc__
769347ad4d35d43488eb98f980143495b0db415dStef Walter METH_VARARGS | METH_STATIC, py_sss_decrypt__doc__
577ba99b3150404533bd3d859522a2c994b17e76Lukas Slebodnik * sss.password object members
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic PyMemberDef sss_password_members[] = {
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher offsetof(PySssPasswordObject, aes_256), RO, NULL},
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek * sss.password object properties
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher .tp_name = sss_py_const_p(char, "sss.password"),
8a07521b413a3b5879f824e1872c5770c92ee5c0Stephen Gallagher .tp_basicsize = sizeof(PySssPasswordObject),
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher .tp_dealloc = (destructor) PySssPasswordObject_dealloc,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher .tp_doc = sss_py_const_p(char, "SSS password obfuscation"),
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher/* ==================== the sss module initialization =======================*/
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Module methods
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher {"getgrouplist", py_sss_getgrouplist, METH_VARARGS, py_sss_getgrouplist__doc__},
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher * Module initialization
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher m = Py_InitModule(discard_const_p(char, "pysss"), module_methods);
577ba99b3150404533bd3d859522a2c994b17e76Lukas Slebodnik PyModule_AddObject(m, discard_const_p(char, "local"), (PyObject *)&pysss_local_type);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher PyModule_AddObject(m, discard_const_p(char, "password"), (PyObject *)&pysss_password_type);