From 86e75949ef6c3be9760fa92852cb67e38ed216ae Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 15 Oct 2009 12:10:42 -0400 Subject: [PATCH 1/3] Clean up warnings in pysss.c On older versions of the python headers, some arguments used 'char *' instead of 'const char *', which means that assigning a constant string such as "adduser" threw a warning about discarding qualifiers. This patch cleans up most of these warnings in this file. There remain several warnings in the sss_local_methods initialization that I do not know how to fix. --- server/python/pysss.c | 141 +++++++++++++++++++++++++++++++++++-------------- 1 files changed, 101 insertions(+), 40 deletions(-) diff --git a/server/python/pysss.c b/server/python/pysss.c index 9ce082b..de4a575 100644 --- a/server/python/pysss.c +++ b/server/python/pysss.c @@ -169,14 +169,27 @@ static PyObject *py_sss_useradd(PySssLocalObject *self, const char *gecos = NULL; const char *home = NULL; const char *shell = NULL; + char *format = NULL; char *username = NULL; int ret; const char * const kwlist[] = { "username", "uid", "gid", "gecos", "homedir", "shell", "groups", NULL }; PyObject *py_groups = Py_None; + tctx = init_ctx(self->mem_ctx, self); + if (!tctx) { + PyErr_NoMemory(); + return NULL; + } + /* parse arguments */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|kksssO!", + format = talloc_strdup(tctx, "s|kksssO!"); + if(!format) { + PyErr_NoMemory(); + goto fail; + } + + if (!PyArg_ParseTupleAndKeywords(args, kwds, format, discard_const_p(char *, kwlist), &username, &uid, @@ -189,12 +202,6 @@ static PyObject *py_sss_useradd(PySssLocalObject *self, goto fail; } - tctx = init_ctx(self->mem_ctx, self); - if (!tctx) { - PyErr_NoMemory(); - return NULL; - } - if (py_groups != Py_None) { tctx->octx->addgroups = PyList_AsStringList(tctx, py_groups, "groups"); if (!tctx->octx->addgroups) { @@ -263,10 +270,7 @@ static PyObject *py_sss_userdel(PySssLocalObject *self, struct tools_ctx *tctx = NULL; char *username = NULL; int ret; - - if(!PyArg_ParseTuple(args, "s", &username)) { - goto fail; - } + char *format = NULL; tctx = init_ctx(self->mem_ctx, self); if (!tctx) { @@ -274,6 +278,16 @@ static PyObject *py_sss_userdel(PySssLocalObject *self, return NULL; } + format = talloc_strdup(init_ctx, "s"); + if (!format) { + PyErr_NoMemory(); + goto fail; + } + + if(!PyArg_ParseTuple(args, format, &username)) { + goto fail; + } + tctx->octx->name = username; /* Delete the user within a transaction */ @@ -339,13 +353,26 @@ static PyObject *py_sss_usermod(PySssLocalObject *self, char *home = NULL; char *shell = NULL; char *username = NULL; + char *format = NULL; unsigned long lock = 0; const char * const kwlist[] = { "username", "uid", "gid", "lock", "gecos", "homedir", "shell", "addgroups", "rmgroups", NULL }; + tctx = init_ctx(self->mem_ctx, self); + if (!tctx) { + PyErr_NoMemory(); + return NULL; + } + + format = talloc_strdup(init_ctx, "s|kkksssO!O!"); + if (!format) { + PyErr_NoMemory(); + goto fail; + } + /* parse arguments */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|kkksssO!O!", + if (!PyArg_ParseTupleAndKeywords(args, kwds, format, discard_const_p(char *, kwlist), &username, &uid, @@ -361,12 +388,6 @@ static PyObject *py_sss_usermod(PySssLocalObject *self, goto fail; } - tctx = init_ctx(self->mem_ctx, self); - if (!tctx) { - PyErr_NoMemory(); - return NULL; - } - if (lock && lock != DO_LOCK && lock != DO_UNLOCK) { PyErr_SetString(PyExc_ValueError, "Unkown value for lock parameter"); @@ -449,23 +470,30 @@ static PyObject *py_sss_groupadd(PySssLocalObject *self, struct tools_ctx *tctx = NULL; char *groupname; unsigned long gid = 0; + char *format = NULL; int ret; const char * const kwlist[] = { "groupname", "gid", NULL }; + tctx = init_ctx(self->mem_ctx, self); + if (!tctx) { + PyErr_NoMemory(); + return NULL; + } + + format = talloc_strdup(init_ctx, "s|k"); + if (!format) { + PyErr_NoMemory(); + goto fail; + } + /* parse arguments */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|k", + if (!PyArg_ParseTupleAndKeywords(args, kwds, format, discard_const_p(char *, kwlist), &groupname, &gid)) { goto fail; } - tctx = init_ctx(self->mem_ctx, self); - if (!tctx) { - PyErr_NoMemory(); - return NULL; - } - tctx->octx->name = groupname; tctx->octx->gid = gid; @@ -515,18 +543,25 @@ static PyObject *py_sss_groupdel(PySssLocalObject *self, { struct tools_ctx *tctx = NULL; char *groupname = NULL; + char *format = NULL; int ret; - if(!PyArg_ParseTuple(args, "s", &groupname)) { - goto fail; - } - tctx = init_ctx(self->mem_ctx, self); if (!tctx) { PyErr_NoMemory(); return NULL; } + format = talloc_strdup(init_ctx, "s"); + if (!format) { + PyErr_NoMemory(); + goto fail; + } + + if(!PyArg_ParseTuple(args, format, &groupname)) { + goto fail; + } + tctx->octx->name = groupname; /* Remove the group within a transaction */ @@ -584,11 +619,25 @@ static PyObject *py_sss_groupmod(PySssLocalObject *self, PyObject *py_rmgroups = Py_None; unsigned long gid = 0; char *groupname = NULL; + char *format = NULL; const char * const kwlist[] = { "groupname", "gid", "addgroups", "rmgroups", NULL }; + + tctx = init_ctx(self->mem_ctx, self); + if (!tctx) { + PyErr_NoMemory(); + return NULL; + } + + format = talloc_strdup(init_ctx, "s|kO!O!"); + if (!format) { + PyErr_NoMemory(); + goto fail; + } + /* parse arguments */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|kO!O!", + if (!PyArg_ParseTupleAndKeywords(args, kwds, format, discard_const_p(char *, kwlist), &groupname, &gid, @@ -599,12 +648,6 @@ static PyObject *py_sss_groupmod(PySssLocalObject *self, goto fail; } - tctx = init_ctx(self->mem_ctx, self); - if (!tctx) { - PyErr_NoMemory(); - return NULL; - } - if (py_addgroups != Py_None) { tctx->octx->addgroups = PyList_AsStringList(tctx, py_addgroups, @@ -804,15 +847,33 @@ PyMODINIT_FUNC initpysss(void) { PyObject *m; + char *module_name = NULL; + char *object_name = NULL; - if (PyType_Ready(&pysss_local_type) < 0) + module_name = talloc_strdup(NULL, "pysss"); + if (!module_name) { return; + } - m = Py_InitModule("pysss", module_methods); - if (m == NULL) + if (PyType_Ready(&pysss_local_type) < 0) { + talloc_free(module_name); return; + } + m = Py_InitModule(module_name, module_methods); + if (m == NULL) { + talloc_free(module_name); + return; + } + + object_name = talloc_strdup(module_name, "local"); + if (!object_name) { + talloc_free(module_name); + return; + } Py_INCREF(&pysss_local_type); - PyModule_AddObject(m, "local", (PyObject *)&pysss_local_type); + PyModule_AddObject(m, object_name, (PyObject *)&pysss_local_type); + + talloc_free(module_name); } -- 1.6.2.5