[PATCH 1/10] rlm_python: 01---sanitize-rlm-python-t.patch
- Sanitize rlm_python_t - Remove typedef - Introduce global PyObject radiusd_module (anyway we have only one interpreter) --- commit 20b0202331f6bc26c46d3c91caf3c209a5958e01 tree 11c4bc223c448c60c4adce48e3fa56840be53e6d parent fef24dfbd7872636bc466bb28637578b1f8604ca author <stingray@boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300 committer <stingray@boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300 src/modules/rlm_python/rlm_python.c | 128 ++++++++++++++++------------------- 1 files changed, 60 insertions(+), 68 deletions(-) diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -42,55 +42,43 @@ static const char rcsid[] = "$Id: rlm_py * a lot cleaner to do so, and a pointer to the structure can * be used as the instance handle. */ -typedef struct rlm_python_t { - /* Config section */ - /* Names of modules */ - char - *mod_instantiate, - *mod_authorize, - *mod_authenticate, - *mod_preacct, - *mod_accounting, - *mod_checksimul, - *mod_detach, - - /* Names of functions */ - *func_instantiate, - *func_authorize, - *func_authenticate, - *func_preacct, - *func_accounting, - *func_checksimul, - *func_detach; - - - /* End Config section */ - - - /* Python objects for modules */ - PyObject - *pModule_builtin, - *pModule_instantiate, - *pModule_authorize, - *pModule_authenticate, - *pModule_preacct, - *pModule_accounting, - *pModule_checksimul, - *pModule_detach, - - - /* Functions */ - - *pFunc_instantiate, - *pFunc_authorize, - *pFunc_authenticate, - *pFunc_preacct, - *pFunc_accounting, - *pFunc_checksimul, - *pFunc_detach; +struct rlm_python_t { + char *mod_instantiate; + char *mod_authorize; + char *mod_authenticate; + char *mod_preacct; + char *mod_accounting; + char *mod_checksimul; + char *mod_detach; + + /* Names of functions */ + char *func_instantiate; + char *func_authorize; + char *func_authenticate; + char *func_preacct; + char *func_accounting; + char *func_checksimul; + char *func_detach; + + PyObject *pModule_instantiate; + PyObject *pModule_authorize; + PyObject *pModule_authenticate; + PyObject *pModule_preacct; + PyObject *pModule_accounting; + PyObject *pModule_checksimul; + PyObject *pModule_detach; + + /* Functions */ + PyObject *pFunc_instantiate; + PyObject *pFunc_authorize; + PyObject *pFunc_authenticate; + PyObject *pFunc_preacct; + PyObject *pFunc_accounting; + PyObject *pFunc_checksimul; + PyObject *pFunc_detach; +}; -} rlm_python_t; /* * A mapping of configuration file names to internal variables. @@ -103,44 +91,49 @@ typedef struct rlm_python_t { */ static CONF_PARSER module_config[] = { { "mod_instantiate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_instantiate), NULL, NULL}, + offsetof(struct rlm_python_t, mod_instantiate), NULL, NULL}, { "func_instantiate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_instantiate), NULL, NULL}, + offsetof(struct rlm_python_t, func_instantiate), NULL, NULL}, { "mod_authorize", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_authorize), NULL, NULL}, + offsetof(struct rlm_python_t, mod_authorize), NULL, NULL}, { "func_authorize", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_authorize), NULL, NULL}, + offsetof(struct rlm_python_t, func_authorize), NULL, NULL}, { "mod_authenticate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_authenticate), NULL, NULL}, + offsetof(struct rlm_python_t, mod_authenticate), NULL, NULL}, { "func_authenticate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_authenticate), NULL, NULL}, + offsetof(struct rlm_python_t, func_authenticate), NULL, NULL}, { "mod_preacct", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_preacct), NULL, NULL}, + offsetof(struct rlm_python_t, mod_preacct), NULL, NULL}, { "func_preacct", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_preacct), NULL, NULL}, + offsetof(struct rlm_python_t, func_preacct), NULL, NULL}, { "mod_accounting", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_accounting), NULL, NULL}, + offsetof(struct rlm_python_t, mod_accounting), NULL, NULL}, { "func_accounting", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_accounting), NULL, NULL}, + offsetof(struct rlm_python_t, func_accounting), NULL, NULL}, { "mod_checksimul", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_checksimul), NULL, NULL}, + offsetof(struct rlm_python_t, mod_checksimul), NULL, NULL}, { "func_checksimul", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_checksimul), NULL, NULL}, + offsetof(struct rlm_python_t, func_checksimul), NULL, NULL}, { "mod_detach", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_detach), NULL, NULL}, + offsetof(struct rlm_python_t, mod_detach), NULL, NULL}, { "func_detach", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_detach), NULL, NULL}, + offsetof(struct rlm_python_t, func_detach), NULL, NULL}, { NULL, -1, 0, NULL, NULL } /* end the list */ }; + +/* Let assume that radiusd module is only one since we have only one intepreter */ + +static PyObject *radiusd_module = NULL; + /* * radiusd Python functions */ @@ -570,8 +563,7 @@ static int load_python_function(const ch */ static int python_instantiate(CONF_SECTION *conf, void **instance) { - rlm_python_t *data; - PyObject *module; + struct rlm_python_t *data; int idx; /* @@ -598,7 +590,7 @@ static int python_instantiate(CONF_SECTI */ /* Code */ - if ((module = data->pModule_builtin = + if ((radiusd_module = Py_InitModule3("radiusd", radiusd_methods, "FreeRADIUS Module.")) == NULL) { @@ -611,7 +603,7 @@ static int python_instantiate(CONF_SECTI * Load constants into module */ for (idx=0; constants[idx].name; idx++) - if ((PyModule_AddIntConstant(module, constants[idx].name, constants[idx].value)) == -1) { + if ((PyModule_AddIntConstant(radiusd_module, constants[idx].name, constants[idx].value)) == -1) { radlog(L_ERR, "Python AddIntConstant failed"); } @@ -717,15 +709,15 @@ static int python_detach(void *instance) /* Default return value is failure */ return_value = -1; - if (((rlm_python_t *)instance)->pFunc_detach && - PyCallable_Check(((rlm_python_t *)instance)->pFunc_detach)) { + if (((struct rlm_python_t *)instance)->pFunc_detach && + PyCallable_Check(((struct rlm_python_t *)instance)->pFunc_detach)) { PyObject *pArgs, *pValue; /* call the function with an empty tuple */ pArgs = PyTuple_New(0); - pValue = PyObject_CallObject(((rlm_python_t *)instance)->pFunc_detach, + pValue = PyObject_CallObject(((struct rlm_python_t *)instance)->pFunc_detach, pArgs); if (pValue == NULL) { -- Paul P 'Stingray' Komkoff Jr // http://stingr.net/key <- my pgp key This message represents the official view of the voices in my head
Please post patches to bugs.freeradius.org. --Mike Paul P Komkoff Jr wrote:
- Sanitize rlm_python_t - Remove typedef - Introduce global PyObject radiusd_module (anyway we have only one interpreter)
--- commit 20b0202331f6bc26c46d3c91caf3c209a5958e01 tree 11c4bc223c448c60c4adce48e3fa56840be53e6d parent fef24dfbd7872636bc466bb28637578b1f8604ca author <stingray@boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300 committer <stingray@boxster64.stingr.net> Sun, 29 Jan 2006 14:44:46 +0300
src/modules/rlm_python/rlm_python.c | 128 ++++++++++++++++------------------- 1 files changed, 60 insertions(+), 68 deletions(-)
diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -42,55 +42,43 @@ static const char rcsid[] = "$Id: rlm_py * a lot cleaner to do so, and a pointer to the structure can * be used as the instance handle. */ -typedef struct rlm_python_t { - /* Config section */
- /* Names of modules */ - char - *mod_instantiate, - *mod_authorize, - *mod_authenticate, - *mod_preacct, - *mod_accounting, - *mod_checksimul, - *mod_detach, - - /* Names of functions */ - *func_instantiate, - *func_authorize, - *func_authenticate, - *func_preacct, - *func_accounting, - *func_checksimul, - *func_detach; - - - /* End Config section */ - - - /* Python objects for modules */ - PyObject - *pModule_builtin, - *pModule_instantiate, - *pModule_authorize, - *pModule_authenticate, - *pModule_preacct, - *pModule_accounting, - *pModule_checksimul, - *pModule_detach, - - - /* Functions */ - - *pFunc_instantiate, - *pFunc_authorize, - *pFunc_authenticate, - *pFunc_preacct, - *pFunc_accounting, - *pFunc_checksimul, - *pFunc_detach; +struct rlm_python_t { + char *mod_instantiate; + char *mod_authorize; + char *mod_authenticate; + char *mod_preacct; + char *mod_accounting; + char *mod_checksimul; + char *mod_detach; + + /* Names of functions */ + char *func_instantiate; + char *func_authorize; + char *func_authenticate; + char *func_preacct; + char *func_accounting; + char *func_checksimul; + char *func_detach; + + PyObject *pModule_instantiate; + PyObject *pModule_authorize; + PyObject *pModule_authenticate; + PyObject *pModule_preacct; + PyObject *pModule_accounting; + PyObject *pModule_checksimul; + PyObject *pModule_detach; + + /* Functions */ + PyObject *pFunc_instantiate; + PyObject *pFunc_authorize; + PyObject *pFunc_authenticate; + PyObject *pFunc_preacct; + PyObject *pFunc_accounting; + PyObject *pFunc_checksimul; + PyObject *pFunc_detach; +};
-} rlm_python_t;
/* * A mapping of configuration file names to internal variables. @@ -103,44 +91,49 @@ typedef struct rlm_python_t { */ static CONF_PARSER module_config[] = { { "mod_instantiate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_instantiate), NULL, NULL}, + offsetof(struct rlm_python_t, mod_instantiate), NULL, NULL}, { "func_instantiate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_instantiate), NULL, NULL}, + offsetof(struct rlm_python_t, func_instantiate), NULL, NULL},
{ "mod_authorize", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_authorize), NULL, NULL}, + offsetof(struct rlm_python_t, mod_authorize), NULL, NULL}, { "func_authorize", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_authorize), NULL, NULL}, + offsetof(struct rlm_python_t, func_authorize), NULL, NULL},
{ "mod_authenticate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_authenticate), NULL, NULL}, + offsetof(struct rlm_python_t, mod_authenticate), NULL, NULL}, { "func_authenticate", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_authenticate), NULL, NULL}, + offsetof(struct rlm_python_t, func_authenticate), NULL, NULL},
{ "mod_preacct", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_preacct), NULL, NULL}, + offsetof(struct rlm_python_t, mod_preacct), NULL, NULL}, { "func_preacct", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_preacct), NULL, NULL}, + offsetof(struct rlm_python_t, func_preacct), NULL, NULL},
{ "mod_accounting", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_accounting), NULL, NULL}, + offsetof(struct rlm_python_t, mod_accounting), NULL, NULL}, { "func_accounting", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_accounting), NULL, NULL}, + offsetof(struct rlm_python_t, func_accounting), NULL, NULL},
{ "mod_checksimul", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_checksimul), NULL, NULL}, + offsetof(struct rlm_python_t, mod_checksimul), NULL, NULL}, { "func_checksimul", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_checksimul), NULL, NULL}, + offsetof(struct rlm_python_t, func_checksimul), NULL, NULL},
{ "mod_detach", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, mod_detach), NULL, NULL}, + offsetof(struct rlm_python_t, mod_detach), NULL, NULL}, { "func_detach", PW_TYPE_STRING_PTR, - offsetof(rlm_python_t, func_detach), NULL, NULL}, + offsetof(struct rlm_python_t, func_detach), NULL, NULL},
{ NULL, -1, 0, NULL, NULL } /* end the list */ };
+ +/* Let assume that radiusd module is only one since we have only one intepreter */ + +static PyObject *radiusd_module = NULL; + /* * radiusd Python functions */ @@ -570,8 +563,7 @@ static int load_python_function(const ch */ static int python_instantiate(CONF_SECTION *conf, void **instance) { - rlm_python_t *data; - PyObject *module; + struct rlm_python_t *data; int idx;
/* @@ -598,7 +590,7 @@ static int python_instantiate(CONF_SECTI */
/* Code */ - if ((module = data->pModule_builtin = + if ((radiusd_module = Py_InitModule3("radiusd", radiusd_methods, "FreeRADIUS Module.")) == NULL) {
@@ -611,7 +603,7 @@ static int python_instantiate(CONF_SECTI * Load constants into module */ for (idx=0; constants[idx].name; idx++) - if ((PyModule_AddIntConstant(module, constants[idx].name, constants[idx].value)) == -1) { + if ((PyModule_AddIntConstant(radiusd_module, constants[idx].name, constants[idx].value)) == -1) {
radlog(L_ERR, "Python AddIntConstant failed"); } @@ -717,15 +709,15 @@ static int python_detach(void *instance) /* Default return value is failure */ return_value = -1;
- if (((rlm_python_t *)instance)->pFunc_detach && - PyCallable_Check(((rlm_python_t *)instance)->pFunc_detach)) { + if (((struct rlm_python_t *)instance)->pFunc_detach && + PyCallable_Check(((struct rlm_python_t *)instance)->pFunc_detach)) {
PyObject *pArgs, *pValue;
/* call the function with an empty tuple */
pArgs = PyTuple_New(0); - pValue = PyObject_CallObject(((rlm_python_t *)instance)->pFunc_detach, + pValue = PyObject_CallObject(((struct rlm_python_t *)instance)->pFunc_detach, pArgs);
if (pValue == NULL) {
Paul P Komkoff Jr wrote:
- Sanitize rlm_python_t - Remove typedef - Introduce global PyObject radiusd_module (anyway we have only one interpreter)
[...] It looks like nobody on this mailing list is using rlm_python, so we have no feedback about the patches. Since the submitter of bug #227 and Paul P Komkoff are using the patches in prod environment, perhaps we could just commit the set of patches in CVS. (it's an experimental module anyway) Alan, do you agree? -- Nicolas Baradakis
I am using rlm_python Of course, not the original one :) The patched version runs good for me (also in production environment). Valts. Nicolas Baradakis wrote:
Paul P Komkoff Jr wrote:
- Sanitize rlm_python_t - Remove typedef - Introduce global PyObject radiusd_module (anyway we have only one interpreter)
[...]
It looks like nobody on this mailing list is using rlm_python, so we have no feedback about the patches. Since the submitter of bug #227 and Paul P Komkoff are using the patches in prod environment, perhaps we could just commit the set of patches in CVS. (it's an experimental module anyway) Alan, do you agree?
Replying to Valts Mazurs:
I am using rlm_python Of course, not the original one :) The patched version runs good for me (also in production environment).
My latest patches or previous by Vladimir Yu. Stepanov? Despite of mainline maintainers development of this stuff continues here in 2 different directions but we'll choose one if SOMETHING will happen to mainline (either Vladimir's or my patches will be integrated). -- Paul P 'Stingray' Komkoff Jr // http://stingr.net/key <- my pgp key This message represents the official view of the voices in my head
Paul P Komkoff Jr wrote:
Replying to Valts Mazurs:
I am using rlm_python Of course, not the original one :) The patched version runs good for me (also in production environment).
My latest patches or previous by Vladimir Yu. Stepanov?
Despite of mainline maintainers development of this stuff continues here in 2 different directions but we'll choose one if SOMETHING will happen to mainline (either Vladimir's or my patches will be integrated).
I use the previous ones by Vladimir Yu. Stepanov They were rejected because Alan couldn't understand what exact changes were made in the rlm_python module. I suppose that it would be better to replace existing or make new module than leaving old crap untouched. Valdimir's code looked readable and good working for me. Thank you for the patches. I haven't tested them yet but I suppose that you fixed the same bugs what Vladimir did. I hope that rlm_python will become usable without custom patching after each release. Valts.
Nicolas Baradakis <nbk@sitadelle.com> wrote:
It looks like nobody on this mailing list is using rlm_python, so we have no feedback about the patches. Since the submitter of bug #227 and Paul P Komkoff are using the patches in prod environment, perhaps we could just commit the set of patches in CVS. (it's an experimental module anyway) Alan, do you agree?
I'm inclined to agree. My concerns are: a) one person sending a patch and saying "it works" is OK for tiny patches, but not for large ones. b) large patches should be read and audited before being applied. So far, few people have piped up for (a), and I haven't had time to do (b). Alan DeKok.
Alan DeKok wrote:
a) one person sending a patch and saying "it works" is OK for tiny patches, but not for large ones.
b) large patches should be read and audited before being applied.
So far, few people have piped up for (a), and I haven't had time to do (b).
I agree: thanks to your advices, the quality of the server can keep up. I was asking the question because rlm_python is an experimental module, therefore I was thinking it's less important. (moreover the users are saying it's almost unusable in its current state) Since I'm not using rlm_python, I can't really say anything about the changes. That's why I'll leave the CVS unchanged until you say the patch is good to go. -- Nicolas Baradakis
Nicolas Baradakis <nbk@sitadelle.com> wrote:
Since I'm not using rlm_python, I can't really say anything about the changes. That's why I'll leave the CVS unchanged until you say the patch is good to go.
I just want *someone* to look at it and see if it's OK. If 3-4 people try the module and it works, then it's a higher priority for me to go look at it, too. If almost no one is interested in the module, it's a low priority for me to go look at it. Alan DeKok.
participants (5)
-
Alan DeKok -
Michael Griego -
Nicolas Baradakis -
Paul P Komkoff Jr -
Valts Mazurs