Re: rlm_python import error undefinde symbol

2009-03-01 Thread Alexander Yu. Solodukhin
Alexander Yu. Solodukhin  писал(а) в своём письме Sat,  
28 Feb 2009 22:40:35 +0200:



Hi all.
I try to use rlm_python and got import error on importing any module  
that relevant on shared object.

Here an rlm_python configuration:

## cut
python {
 mod_instantiate = account
 func_instantiate = instantiate

 mod_authorize = account
 func_authorize = authorize

 mod_accounting = account
 func_accounting = accounting

 mod_preproxy = account
 func_preproxy = preproxy

 mod_postproxy = account
 func_postproxy = postproxy

 mod_postauth = account
 func_postauth = postauth

 mod_detach = account
 func_detach = detach
}
## end cut

account.py is radiusd_test.py from src/modules/rlm_python with one line  
added on top of file:

import time

'time' is not plain python module, it is shared object found at  
/usr/lib/python2.5/lib-dynload/time.so


After starting radius i got this error:

rlm_python:python_load_function: module 'account' is not found
rlm_python:EXCEPT::  
/usr/lib/python2.5/lib-dynload/time.so: undefined symbol:  
PyExc_ValueError


I was examine rlm_python code, and example 'C' code from python  
documentation on how to embedd python into 'C', and don't found major  
differences.


This code works fine:

#include 

int
main(int argc, char *argv[])
{
 PyObject *pName, *pModule, *pDict, *pFunc;
 PyObject *pArgs, *pValue;
 int i;

 if (argc < 3) {
 fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
 return 1;
 }

 Py_Initialize();
 pName = PyString_FromString(argv[1]);
 /* Error checking of pName left out */
 Py_INCREF(pName);

 pModule = PyImport_Import(pName);
 Py_DECREF(pName);

 if (pModule != NULL) {
 pFunc = PyObject_GetAttrString(pModule, argv[2]);
 /* pFunc is a new reference */

 if (pFunc && PyCallable_Check(pFunc)) {
 pArgs = PyTuple_New(argc - 3);
 for (i = 0; i < argc - 3; ++i) {
 pValue = PyInt_FromLong(atoi(argv[i + 3]));
 if (!pValue) {
 Py_DECREF(pArgs);
 Py_DECREF(pModule);
 fprintf(stderr, "Cannot convert argument\n");
 return 1;
 }
 /* pValue reference stolen here: */
 PyTuple_SetItem(pArgs, i, pValue);
 }
 pValue = PyObject_CallObject(pFunc, pArgs);
 Py_DECREF(pArgs);
 if (pValue != NULL) {
 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
 Py_DECREF(pValue);
 }
 else {
 Py_DECREF(pFunc);
 Py_DECREF(pModule);
 PyErr_Print();
 fprintf(stderr,"Call failed\n");
 return 1;
 }
 }
 else {
 if (PyErr_Occurred())
 PyErr_Print();
 fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
 }
 Py_XDECREF(pFunc);
 Py_DECREF(pModule);
 }
 else {
 PyErr_Print();
 fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
 return 1;
 }
 Py_Finalize();
 return 0;
}

Compiled with:
gcc call.c -o call -I/usr/include/python2.5 -L/usr/lib/python2.5/config  
-lpython2.5


Why this code does not through 'undefined symbol' error and rlm_python  
does?


PS: I read mailing list before posting this question and saw that this  
problem was found in 2007. I try newst freeradius 2.1.3 and problem  
still exists.


Any feedback will be great.




gcc -shared  .libs/rlm_python.o  -Wl,--rpath  
-Wl,/root/freeradius-server-2.1.3/src/lib/.libs -Wl,--rpath  
-Wl,/usr/lib/freeradius  
/root/freeradius-server-2.1.3/src/lib/.libs/libfreeradius-radius.so  
-L/usr/lib/python2.5/config -ldl -lutil -lpython2.5 -lm -lnsl -lresolv  
-lpthread  -Wl,-export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  
-Wl,-soname -Wl,rlm_python-2.1.3.so -o .libs/rlm_python-2.1.3.so  
/usr/lib/python2.5/lib-dynload/*.so  
/usr/lib/python-support/python-mysqldb/python2.5/_mysql.so


solves the problem (/usr/lib/python2.5/lib-dynload/*.so  
/usr/lib/python-support/python-mysqldb/python2.5/_mysql.so), but it's not  
right way to fix this problem :)



--
ISP CrIS, Softwarium
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

rlm_python import error undefinde symbol

2009-02-28 Thread Alexander Yu. Solodukhin

Hi all.
I try to use rlm_python and got import error on importing any module that  
relevant on shared object.

Here an rlm_python configuration:

## cut
python {
mod_instantiate = account
func_instantiate = instantiate

mod_authorize = account
func_authorize = authorize

mod_accounting = account
func_accounting = accounting

mod_preproxy = account
func_preproxy = preproxy

mod_postproxy = account
func_postproxy = postproxy

mod_postauth = account
func_postauth = postauth

mod_detach = account
func_detach = detach
}
## end cut

account.py is radiusd_test.py from src/modules/rlm_python with one line  
added on top of file:

import time

'time' is not plain python module, it is shared object found at  
/usr/lib/python2.5/lib-dynload/time.so


After starting radius i got this error:

rlm_python:python_load_function: module 'account' is not found
rlm_python:EXCEPT::  
/usr/lib/python2.5/lib-dynload/time.so: undefined symbol: PyExc_ValueError


I was examine rlm_python code, and example 'C' code from python  
documentation on how to embedd python into 'C', and don't found major  
differences.


This code works fine:

#include 

int
main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pFunc;
PyObject *pArgs, *pValue;
int i;

if (argc < 3) {
fprintf(stderr,"Usage: call pythonfile funcname [args]\n");
return 1;
}

Py_Initialize();
pName = PyString_FromString(argv[1]);
/* Error checking of pName left out */
Py_INCREF(pName);

pModule = PyImport_Import(pName);
Py_DECREF(pName);

if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, argv[2]);
/* pFunc is a new reference */

if (pFunc && PyCallable_Check(pFunc)) {
pArgs = PyTuple_New(argc - 3);
for (i = 0; i < argc - 3; ++i) {
pValue = PyInt_FromLong(atoi(argv[i + 3]));
if (!pValue) {
Py_DECREF(pArgs);
Py_DECREF(pModule);
fprintf(stderr, "Cannot convert argument\n");
return 1;
}
/* pValue reference stolen here: */
PyTuple_SetItem(pArgs, i, pValue);
}
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL) {
printf("Result of call: %ld\n", PyInt_AsLong(pValue));
Py_DECREF(pValue);
}
else {
Py_DECREF(pFunc);
Py_DECREF(pModule);
PyErr_Print();
fprintf(stderr,"Call failed\n");
return 1;
}
}
else {
if (PyErr_Occurred())
PyErr_Print();
fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]);
}
Py_XDECREF(pFunc);
Py_DECREF(pModule);
}
else {
PyErr_Print();
fprintf(stderr, "Failed to load \"%s\"\n", argv[1]);
return 1;
}
Py_Finalize();
return 0;
}

Compiled with:
gcc call.c -o call -I/usr/include/python2.5 -L/usr/lib/python2.5/config  
-lpython2.5


Why this code does not through 'undefined symbol' error and rlm_python  
does?


PS: I read mailing list before posting this question and saw that this  
problem was found in 2007. I try newst freeradius 2.1.3 and problem still  
exists.


Any feedback will be great.


--
ISP CrIS, Softwarium
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html