From: <ssm...@us...> - 2007-09-10 19:24:50
|
Revision: 2553 http://selinux.svn.sourceforge.net/selinux/?rev=2553&view=rev Author: ssmalley Date: 2007-09-10 12:24:47 -0700 (Mon, 10 Sep 2007) Log Message: ----------- Author: James Athey Email: ja...@tr... Subject: libselinux: fix rpm_execcon in SWIG bindings Date: Wed, 05 Sep 2007 15:35:22 -0400 On Tue, 2007-09-04 at 10:23 -0400, Daniel J Walsh wrote: > https://bugzilla.redhat.com/show_bug.cgi?id=276121 > > Bug in refactored SWIG Bindings. > > > #!/usr/bin/python > > import selinux > args = [ "/bin/bash", "--version" ] > selinux.rpm_execcon(0, args[0], args, [ ]) > > Produces: > > Traceback (most recent call last): > File "test.py", line 5, in <module> > selinux.rpm_execcon(0, args[0], args, [ ]) > TypeError: in method 'rpm_execcon', argument 3 of type 'char *const []' > > Version-Release number of selected component (if applicable): > libselinux-2.0.31-3.fc8 > > James do you have a nice quick fix for this? It's nice, it's quick, and I think it's a fix, but I'll let you be the judge of that. Modified Paths: -------------- trunk/libselinux/src/selinux.py trunk/libselinux/src/selinuxswig_python.i trunk/libselinux/src/selinuxswig_wrap.c Modified: trunk/libselinux/src/selinux.py =================================================================== --- trunk/libselinux/src/selinux.py 2007-09-10 19:23:04 UTC (rev 2552) +++ trunk/libselinux/src/selinux.py 2007-09-10 19:24:47 UTC (rev 2553) @@ -277,6 +277,7 @@ selinux_file_context_local_path = _selinux.selinux_file_context_local_path selinux_homedir_context_path = _selinux.selinux_homedir_context_path selinux_media_context_path = _selinux.selinux_media_context_path +selinux_x_context_path = _selinux.selinux_x_context_path selinux_contexts_path = _selinux.selinux_contexts_path selinux_securetty_types_path = _selinux.selinux_securetty_types_path selinux_booleans_path = _selinux.selinux_booleans_path Modified: trunk/libselinux/src/selinuxswig_python.i =================================================================== --- trunk/libselinux/src/selinuxswig_python.i 2007-09-10 19:23:04 UTC (rev 2552) +++ trunk/libselinux/src/selinuxswig_python.i 2007-09-10 19:24:47 UTC (rev 2553) @@ -98,4 +98,41 @@ } } +%typemap(in) char * const [] { + int i, size; + PyObject * s; + + if (!PySequence_Check($input)) { + PyErr_SetString(PyExc_ValueError, "Expected a sequence"); + return NULL; + } + + size = PySequence_Size($input); + + $1 = (char**) malloc(size + 1); + + for(i = 0; i < size; i++) { + if (!PyString_Check(PySequence_GetItem($input, i))) { + PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings"); + return NULL; + } + } + + for(i = 0; i < size; i++) { + s = PySequence_GetItem($input, i); + $1[i] = (char*) malloc(PyString_Size(s) + 1); + strcpy($1[i], PyString_AsString(s)); + } + $1[size] = NULL; +} + +%typemap(freearg,match="in") char * const [] { + int i = 0; + while($1[i]) { + free($1[i]); + i++; + } + free($1); +} + %include "selinuxswig.i" Modified: trunk/libselinux/src/selinuxswig_wrap.c =================================================================== --- trunk/libselinux/src/selinuxswig_wrap.c 2007-09-10 19:23:04 UTC (rev 2552) +++ trunk/libselinux/src/selinuxswig_wrap.c 2007-09-10 19:24:47 UTC (rev 2553) @@ -6856,6 +6856,19 @@ } +SWIGINTERN PyObject *_wrap_selinux_x_context_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + char *result = 0 ; + + if (!PyArg_ParseTuple(args,(char *)":selinux_x_context_path")) SWIG_fail; + result = (char *)selinux_x_context_path(); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + SWIGINTERN PyObject *_wrap_selinux_contexts_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; char *result = 0 ; @@ -7078,10 +7091,6 @@ int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; - void *argp3 = 0 ; - int res3 = 0 ; - void *argp4 = 0 ; - int res4 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; @@ -7098,22 +7107,98 @@ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "rpm_execcon" "', argument " "2"" of type '" "char const *""'"); } arg2 = (char *)(buf2); - res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_p_char, 0 | 0 ); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "rpm_execcon" "', argument " "3"" of type '" "char *const []""'"); - } - arg3 = (char **)(argp3); - res4 = SWIG_ConvertPtr(obj3, &argp4,SWIGTYPE_p_p_char, 0 | 0 ); - if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "rpm_execcon" "', argument " "4"" of type '" "char *const []""'"); - } - arg4 = (char **)(argp4); + { + int i, size; + PyObject * s; + + if (!PySequence_Check(obj2)) { + PyErr_SetString(PyExc_ValueError, "Expected a sequence"); + return NULL; + } + + size = PySequence_Size(obj2); + + arg3 = (char**) malloc(size + 1); + + for(i = 0; i < size; i++) { + if (!PyString_Check(PySequence_GetItem(obj2, i))) { + PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings"); + return NULL; + } + } + + for(i = 0; i < size; i++) { + s = PySequence_GetItem(obj2, i); + arg3[i] = (char*) malloc(PyString_Size(s) + 1); + strcpy(arg3[i], PyString_AsString(s)); + } + arg3[size] = NULL; + } + { + int i, size; + PyObject * s; + + if (!PySequence_Check(obj3)) { + PyErr_SetString(PyExc_ValueError, "Expected a sequence"); + return NULL; + } + + size = PySequence_Size(obj3); + + arg4 = (char**) malloc(size + 1); + + for(i = 0; i < size; i++) { + if (!PyString_Check(PySequence_GetItem(obj3, i))) { + PyErr_SetString(PyExc_ValueError, "Sequence must contain only strings"); + return NULL; + } + } + + for(i = 0; i < size; i++) { + s = PySequence_GetItem(obj3, i); + arg4[i] = (char*) malloc(PyString_Size(s) + 1); + strcpy(arg4[i], PyString_AsString(s)); + } + arg4[size] = NULL; + } result = (int)rpm_execcon(arg1,(char const *)arg2,(char *const (*))arg3,(char *const (*))arg4); resultobj = SWIG_From_int((int)(result)); if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + { + int i = 0; + while(arg3[i]) { + free(arg3[i]); + i++; + } + free(arg3); + } + { + int i = 0; + while(arg4[i]) { + free(arg4[i]); + i++; + } + free(arg4); + } return resultobj; fail: if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); + { + int i = 0; + while(arg3[i]) { + free(arg3[i]); + i++; + } + free(arg3); + } + { + int i = 0; + while(arg4[i]) { + free(arg4[i]); + i++; + } + free(arg4); + } return NULL; } @@ -8002,6 +8087,7 @@ { (char *)"selinux_file_context_local_path", _wrap_selinux_file_context_local_path, METH_VARARGS, NULL}, { (char *)"selinux_homedir_context_path", _wrap_selinux_homedir_context_path, METH_VARARGS, NULL}, { (char *)"selinux_media_context_path", _wrap_selinux_media_context_path, METH_VARARGS, NULL}, + { (char *)"selinux_x_context_path", _wrap_selinux_x_context_path, METH_VARARGS, NULL}, { (char *)"selinux_contexts_path", _wrap_selinux_contexts_path, METH_VARARGS, NULL}, { (char *)"selinux_securetty_types_path", _wrap_selinux_securetty_types_path, METH_VARARGS, NULL}, { (char *)"selinux_booleans_path", _wrap_selinux_booleans_path, METH_VARARGS, NULL}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |