pysss.c revision 40bb1ddf0a3f69922466b2b99bcdaf7746fc81ba
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2009 Red Hat
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 <structmember.h>
#include <talloc.h>
#include <pwd.h>
#include <grp.h>
#include "tools/tools_util.h"
#include "tools/sss_sync_ops.h"
while (!trs->transaction_done) { \
} \
if (retval) { \
goto fail; \
} \
} while(0)
/*
* function taken from samba sources tree as of Aug 20 2009,
*/
const char *paramname)
{
char **ret;
int i;
for (i = 0; i < PyList_Size(list); i++) {
if (!PyString_Check(item)) {
return NULL;
}
}
return ret;
}
/*
* The sss.local object
*/
typedef struct {
struct tevent_context *ev;
struct confdb_ctx *confdb;
struct sss_domain_info *local;
int lock;
int unlock;
/*
* The transaction object
*/
struct py_sss_transaction {
struct sysdb_handle *handle;
bool transaction_done;
int error;
};
/*
* Error reporting
*/
{
}
static void PyErr_SetSssError(int ret)
{
}
/*
* Common init of all methods
*/
{
return NULL;
}
/* tctx->nctx is NULL here, which is OK since we don't parse domains
* in the python bindings (yet?) */
return NULL;
}
return tctx;
}
/*
* Add a user
*/
"Add a user named ``username``.\n\n"
":param username: name of the user\n\n"
":param kwargs: Keyword arguments that customize the operation\n\n"
"* useradd can be customized further with keyword arguments:\n"
" * ``uid``: The UID of the user\n"
" * ``gid``: The GID of the user\n"
" * ``gecos``: The comment string\n"
" * ``homedir``: Home directory\n"
" * ``shell``: Login shell\n"
" * ``skel``: Specify an alternative skeleton directory\n"
" * ``create_home``: (bool) Force creation of home directory on or off\n"
" * ``groups``: List of groups the user is member of\n");
{
unsigned long uid = 0;
unsigned long gid = 0;
int ret;
"homedir", "shell", "skel",
int create_home = 0;
/* parse arguments */
discard_const_p(char, "s|kkssssO!O!"),
discard_const_p(char *, kwlist),
&username,
&uid,
&gid,
&gecos,
&home,
&shell,
&skel,
&py_groups)) {
goto fail;
}
if (!tctx) {
return NULL;
}
return NULL;
}
}
/* user-wise the parameter is only bool - do or don't,
* however we must have a third state - undecided, pick default */
if (py_create_home == Py_True) {
} else if (py_create_home == Py_False) {
}
/* fill in defaults */
skel);
goto fail;
}
/* Add the user within a transaction */
goto fail;
}
/* useradd */
/* cancel transaction */
goto fail;
}
goto fail;
}
/* We need to know the UID and GID of the user, if
* sysdb did assign it automatically, do a lookup */
goto fail;
}
}
goto fail;
}
/* failure here should not be fatal */
}
fail:
return NULL;
}
/*
* Delete a user
*/
"Remove the user named ``username``.\n\n"
":param username: Name of user being removed\n"
":param kwargs: Keyword arguments that customize the operation\n\n"
"* userdel can be customized further with keyword arguments:\n"
" * ``force``: (bool) Force removal of files not owned by the user\n"
" * ``remove``: (bool) Toggle removing home directory and mail spool\n");
{
int ret;
int remove_home = 0;
discard_const_p(char, "s|O!O!"),
discard_const_p(char *, kwlist),
&username,
&py_force)) {
goto fail;
}
if (!tctx) {
return NULL;
}
}
/*
* Fills in defaults for ops_ctx user did not specify.
*/
goto fail;
}
goto fail;
}
goto fail;
}
}
/* Delete the user */
goto fail;
}
goto fail;
}
}
fail:
return NULL;
}
/*
* Modify a user
*/
"Modify a user.\n\n"
":param username: Name of user being modified\n\n"
":param kwargs: Keyword arguments that customize the operation\n\n"
"* usermod can be customized further with keyword arguments:\n"
" * ``uid``: The UID of the user\n"
" * ``gid``: The GID of the user\n"
" * ``gecos``: The comment string\n"
" * ``homedir``: Home directory\n"
" * ``shell``: Login shell\n"
" * ``addgroups``: List of groups to add the user to\n"
" * ``rmgroups``: List of groups to remove the user from\n"
" * ``lock``: Lock or unlock the account\n");
{
unsigned long uid = 0;
unsigned long gid = 0;
unsigned long lock = 0;
"gecos", "homedir", "shell",
/* parse arguments */
discard_const_p(char, "s|kkksssO!O!"),
discard_const_p(char *, kwlist),
&username,
&uid,
&gid,
&lock,
&gecos,
&home,
&shell,
&py_rmgroups)) {
goto fail;
}
if (!tctx) {
return NULL;
}
"Unkown value for lock parameter");
goto fail;
}
if (py_addgroups != Py_None) {
"addgroups");
return NULL;
}
}
if (py_rmgroups != Py_None) {
"rmgroups");
return NULL;
}
}
/* Modify the user within a transaction */
goto fail;
}
/* usermod */
/* cancel transaction */
goto fail;
}
goto fail;
}
fail:
return NULL;
}
/*
* Add a group
*/
"Add a group.\n\n"
":param groupname: Name of group being added\n\n"
":param kwargs: Keyword arguments ro customize the operation\n\n"
"* groupmod can be customized further with keyword arguments:\n"
" * ``gid``: The GID of the group\n");
{
char *groupname;
unsigned long gid = 0;
/* parse arguments */
discard_const_p(char, "s|k"),
discard_const_p(char *, kwlist),
&gid)) {
goto fail;
}
if (!tctx) {
return NULL;
}
/* Add the group within a transaction */
goto fail;
}
/* groupadd */
/* cancel transaction */
goto fail;
}
goto fail;
}
fail:
return NULL;
}
/*
* Delete a group
*/
"Remove a group.\n\n"
":param groupname: Name of group being removed\n");
{
int ret;
goto fail;
}
if (!tctx) {
return NULL;
}
/* Remove the group */
goto fail;
}
fail:
return NULL;
}
/*
* Modify a group
*/
"Modify a group.\n\n"
":param groupname: Name of group being modified\n\n"
":param kwargs: Keyword arguments ro customize the operation\n\n"
"* groupmod can be customized further with keyword arguments:\n"
" * ``gid``: The GID of the group\n\n"
" * ``addgroups``: Groups to add the group to\n\n"
" * ``rmgroups``: Groups to remove the group from\n\n");
{
unsigned long gid = 0;
"rmgroups", NULL };
/* parse arguments */
discard_const_p(char, "s|kO!O!"),
discard_const_p(char *, kwlist),
&gid,
&py_rmgroups)) {
goto fail;
}
if (!tctx) {
return NULL;
}
if (py_addgroups != Py_None) {
"addgroups");
return NULL;
}
}
if (py_rmgroups != Py_None) {
"rmgroups");
return NULL;
}
}
/* Modify the group within a transaction */
goto fail;
}
/* groupmod */
/* cancel transaction */
goto fail;
}
goto fail;
}
fail:
return NULL;
}
/*** python plumbing begins here ***/
/*
* The sss.local destructor
*/
{
}
/*
* The sss.local constructor
*/
{
char *confdb_path;
int ret;
return NULL;
}
return NULL;
}
return NULL;
}
if (confdb_path == NULL) {
return NULL;
}
/* Connect to the conf db */
"Could not initialize connection to the confdb\n");
return NULL;
}
return NULL;
}
/* open 'local' sysdb at default path */
"Could not initialize connection to the sysdb\n");
return NULL;
}
}
/*
* sss.local object methods
*/
static PyMethodDef sss_local_methods[] = {
},
},
},
},
},
},
};
static PyMemberDef sss_members[] = {
};
/*
* sss.local object properties
*/
static PyTypeObject pysss_local_type = {
.tp_name = "sss.local",
.tp_basicsize = sizeof(PySssLocalObject),
.tp_doc = "SSS DB manipulation",
};
/*
* Module methods
*/
static PyMethodDef module_methods[] = {
};
/*
* Module initialization
*/
initpysss(void)
{
PyObject *m;
if (PyType_Ready(&pysss_local_type) < 0)
return;
if (m == NULL)
return;
}