From: Arran Cudbard-Bell Date: Thu, 17 Dec 2020 03:14:15 +0000 (-0600) Subject: Nuke the cext tests (no longer supported) and change the module name to freeradius X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dfeb5cc117920eb2bf80838d56eb4d1c28ccb69;p=thirdparty%2Ffreeradius-server.git Nuke the cext tests (no longer supported) and change the module name to freeradius --- diff --git a/src/modules/rlm_python/example.py b/src/modules/rlm_python/example.py index abcd966c488..0dfb93fe4fd 100644 --- a/src/modules/rlm_python/example.py +++ b/src/modules/rlm_python/example.py @@ -5,7 +5,7 @@ # # $Id$ -import radiusd +import freeradius def instantiate(p): print("*** instantiate ***") @@ -15,51 +15,51 @@ def instantiate(p): def authorize(p): print("*** authorize ***") print("") - radiusd.log(radiusd.L_INFO, '*** log call in authorize ***') + freeradius.log(freeradius.L_INFO, '*** log call in authorize ***') print("") print(p) print("") - print(radiusd.config) + print(freeradius.config) print("") - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def preacct(p): print("*** preacct ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def accounting(p): print("*** accounting ***") - radiusd.log(radiusd.L_INFO, '*** log call in accounting (0) ***') + freeradius.log(freeradius.L_INFO, '*** log call in accounting (0) ***') print("") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def pre_proxy(p): print("*** pre_proxy ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def post_proxy(p): print("*** post_proxy ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def post_auth(p): print("*** post_auth ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def recv_coa(p): print("*** recv_coa ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def send_coa(p): print("*** send_coa ***") print(p) - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def detach(): print("*** goodbye from example.py ***") - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK diff --git a/src/modules/rlm_python/prepaid.py b/src/modules/rlm_python/prepaid.py index 56a09dfe8eb..84c4fe5b91f 100644 --- a/src/modules/rlm_python/prepaid.py +++ b/src/modules/rlm_python/prepaid.py @@ -19,7 +19,7 @@ # # $Id$ -import radiusd +import freeradius import MySQLdb # Configuration @@ -35,7 +35,7 @@ dbHandle = None def log(level, s): """Log function.""" - radiusd.radlog(level, 'prepaid.py: ' + s) + freeradius.radlog(level, 'prepaid.py: ' + s) def instantiate(p): """Module Instantiation. 0 for success, -1 for failure. @@ -49,10 +49,10 @@ def instantiate(p): except MySQLdb.OperationalError, e: # Report the error and return -1 for failure. # xxx A more advanced module would retry the database. - log(radiusd.L_ERR, str(e)) + log(freeradius.L_ERR, str(e)) return -1 - log(radiusd.L_INFO, 'db connection: ' + str(dbHandle)) + log(freeradius.L_INFO, 'db connection: ' + str(dbHandle)) return 0 @@ -71,41 +71,41 @@ def authorize(authData): userPasswd = t[1] # Build and log the SQL statement - # radiusd puts double quotes (") around the string representation of + # freeradius puts double quotes (") around the string representation of # the RADIUS packet. sql = 'select passwd, maxseconds from users where username = ' + userName - log(radiusd.L_DBG, sql) + log(freeradius.L_DBG, sql) # Get a cursor # xxx Or should this be one cursor all throughout? try: dbCursor = dbHandle.cursor() except MySQLdb.OperationalError, e: - log(radiusd.L_ERR, str(e)) - return radiusd.RLM_MODULE_FAIL + log(freeradius.L_ERR, str(e)) + return freeradius.RLM_MODULE_FAIL # Execute the SQL statement try: dbCursor.execute(sql) except MySQLdb.OperationalError, e: - log(radiusd.L_ERR, str(e)) + log(freeradius.L_ERR, str(e)) dbCursor.close() - return radiusd.RLM_MODULE_FAIL + return freeradius.RLM_MODULE_FAIL # Get the result. (passwd, maxseconds) result = dbCursor.fetchone() if not result: # User not found - log(radiusd.L_INFO, 'user not found: ' + userName) + log(freeradius.L_INFO, 'user not found: ' + userName) dbCursor.close() - return radiusd.RLM_MODULE_NOTFOUND + return freeradius.RLM_MODULE_NOTFOUND # Compare passwords # Ignore the quotes around userPasswd. if result[0] != userPasswd[1:-1]: - log(radiusd.L_DBG, 'user password mismatch: ' + userName) - return radiusd.RLM_MODULE_REJECT + log(freeradius.L_DBG, 'user password mismatch: ' + userName) + return freeradius.RLM_MODULE_REJECT maxSeconds = result[1] @@ -114,15 +114,15 @@ def authorize(authData): # Build and log the SQL statement sql = 'select sum(seconds) from sessions where username = ' + userName - log(radiusd.L_DBG, sql) + log(freeradius.L_DBG, sql) # Execute the SQL statement try: dbCursor.execute(sql) except MySQLdb.OperationalError, e: - log(radiusd.L_ERR, str(e)) + log(freeradius.L_ERR, str(e)) dbCursor.close() - return radiusd.RLM_MODULE_FAIL + return freeradius.RLM_MODULE_FAIL # Get the result. (sum,) result = dbCursor.fetchone() @@ -140,23 +140,23 @@ def authorize(authData): if sessionTimeout <= 0: # No more time, reject outright - log(radiusd.L_INFO, 'user out of time: ' + userName) - return radiusd.RLM_MODULE_REJECT + log(freeradius.L_INFO, 'user out of time: ' + userName) + return freeradius.RLM_MODULE_REJECT # Log the success - log(radiusd.L_DBG, 'user accepted: %s, %d seconds' % + log(freeradius.L_DBG, 'user accepted: %s, %d seconds' % (userName, sessionTimeout)) # We are adding to the RADIUS packet # Note that the session timeout integer must be converted to string. # We need to set an Auth-Type. - return (radiusd.RLM_MODULE_UPDATED, + return (freeradius.RLM_MODULE_UPDATED, (('Session-Timeout', str(sessionTimeout)),), (('Auth-Type', 'python'),)) # If you want to use different operators # you can do - # return (radiusd.RLM_MODULE_UPDATED, + # return (freeradius.RLM_MODULE_UPDATED, # ( # ('Session-Timeout', ':=', str(sessionTimeout)), # ('Some-other-option', '-=', Value'), @@ -167,11 +167,11 @@ def authorize(authData): # ) def authenticate(p): - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def preacct(p): - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def accounting(acctData): @@ -194,10 +194,10 @@ def accounting(acctData): # We will not deal with Start for now. # We may later, for simultaneous checks and the like. if acctStatusType == 'Start': - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK # Build and log the SQL statement - # radiusd puts double quotes (") around the string representation of + # freeradius puts double quotes (") around the string representation of # the RADIUS packet. # # xxx This is simplistic as it does not record the time, etc. @@ -205,36 +205,36 @@ def accounting(acctData): sql = 'insert into sessions (username, seconds) values (%s, %d)' % \ (userName, int(acctSessionTime)) - log(radiusd.L_DBG, sql) + log(freeradius.L_DBG, sql) # Get a cursor # xxx Or should this be one cursor all throughout? try: dbCursor = dbHandle.cursor() except MySQLdb.OperationalError, e: - log(radiusd.L_ERR, str(e)) - return radiusd.RLM_MODULE_FAIL + log(freeradius.L_ERR, str(e)) + return freeradius.RLM_MODULE_FAIL # Execute the SQL statement try: dbCursor.execute(sql) except MySQLdb.OperationalError, e: - log(radiusd.L_ERR, str(e)) + log(freeradius.L_ERR, str(e)) dbCursor.close() - return radiusd.RLM_MODULE_FAIL + return freeradius.RLM_MODULE_FAIL - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK def detach(): """Detach and clean up.""" # Shut down the database connection. global dbHandle - log(radiusd.L_DBG, 'closing database handle: ' + str(dbHandle)) + log(freeradius.L_DBG, 'closing database handle: ' + str(dbHandle)) dbHandle.close() - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index ad59d4b6408..63e76b537f4 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -192,7 +192,7 @@ static PyObject *mod_log(UNUSED PyObject *module, PyObject *args) static PyMethodDef module_methods[] = { { "log", &mod_log, METH_VARARGS, - "radiusd.log(level, msg)\n\n" \ + "freeradius.log(level, msg)\n\n" \ "Print a message using radiusd logging system. level should be one of the\n" \ "constants L_DBG, L_AUTH, L_INFO, L_ERR\n" }, @@ -851,8 +851,8 @@ static PyObject *python_module_init(void) static struct PyModuleDef py_module_def = { PyModuleDef_HEAD_INIT, - "radiusd", /* m_name */ - "FreeRADIUS python module", /* m_doc */ + "freeradius", /* m_name */ + "freeRADIUS python module", /* m_doc */ -1, /* m_size */ module_methods, /* m_methods */ NULL, /* m_reload */ @@ -911,9 +911,9 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf) * own copy which it can mutate as much as * it wants. */ - module = PyImport_ImportModule("radiusd"); + module = PyImport_ImportModule("freeradius"); if (!module) { - ERROR("Failed importing \"radiusd\" module into interpreter %p", inst->interpreter); + ERROR("Failed importing \"freeradius\" module into interpreter %p", inst->interpreter); return -1; } if ((python_module_import_config(inst, conf, module) < 0) || @@ -1113,7 +1113,7 @@ static int mod_load(void) * are automatically created when the first * interpreter is spawned. */ - PyImport_AppendInittab("radiusd", python_module_init); + PyImport_AppendInittab("freeradius", python_module_init); LSAN_DISABLE(Py_InitializeEx(0)); /* Don't override signal handlers - noop on subs calls */ /* diff --git a/src/tests/modules/python/auth_cext_compat.attrs b/src/tests/modules/python/auth_cext_compat.attrs deleted file mode 100644 index 8b7914eed69..00000000000 --- a/src/tests/modules/python/auth_cext_compat.attrs +++ /dev/null @@ -1,10 +0,0 @@ -# -# Input packet -# -User-Name = "bob" -User-Password = "hello" - -# -# Expected answer -# -Packet-Type == Access-Accept \ No newline at end of file diff --git a/src/tests/modules/python/auth_cext_compat.unlang b/src/tests/modules/python/auth_cext_compat.unlang deleted file mode 100644 index 5396ef9735e..00000000000 --- a/src/tests/modules/python/auth_cext_compat.unlang +++ /dev/null @@ -1,36 +0,0 @@ -if ("%{config:version.python}" =~ /^3/) { - test_pass - return -} - -# This module is cext_compat and should work -pmod4_cextcompat -if (!noop) { - test_fail -} else { - test_pass -} - -# This module share the main interpreter with pmod4_cextcompat. shared_attribute should be defined -pmod5_cextcompat -if (!ok) { - test_fail -} else { - test_pass -} - -# This module has it's own SubInterpreter. shared_attribute shouldn't be defined -pmod4_not_cextcompat -if (!noop) { - test_fail -} else { - test_pass -} - -# This module has it's own SubInterpreter. shared_attribute shouldn't be defined -pmod5_not_cextcompat -if (!noop) { - test_fail -} else { - test_pass -} diff --git a/src/tests/modules/python/auth_with_shared_storage.unlang b/src/tests/modules/python/auth_with_shared_storage.unlang index 9e55880a82a..54ba761ec7c 100644 --- a/src/tests/modules/python/auth_with_shared_storage.unlang +++ b/src/tests/modules/python/auth_with_shared_storage.unlang @@ -1,5 +1,5 @@ # Should return noop (no shared variable set) -pmod_shared_storage +pmod7_shared_storage if (noop) { test_pass } else { @@ -7,7 +7,7 @@ if (noop) { } # Should return ok (shared variable set) -pmod_shared_storage +pmod7_shared_storage if (ok) { test_pass } else { diff --git a/src/tests/modules/python/mod_return_ok.py b/src/tests/modules/python/mod_return_ok.py index 9089d1aa7fb..8879e10b2bc 100644 --- a/src/tests/modules/python/mod_return_ok.py +++ b/src/tests/modules/python/mod_return_ok.py @@ -1,4 +1,4 @@ -import radiusd +import freeradius -def authorize(p): - return radiusd.RLM_MODULE_OK \ No newline at end of file +def authorize(p): + return freeradius.RLM_MODULE_OK diff --git a/src/tests/modules/python/mod_shared_storage.py b/src/tests/modules/python/mod_shared_storage.py index b2f3e84c88e..4b0e13975a1 100644 --- a/src/tests/modules/python/mod_shared_storage.py +++ b/src/tests/modules/python/mod_shared_storage.py @@ -1,10 +1,10 @@ -import radiusd +import freeradius import shared def authorize(p): - radiusd.log(radiusd.L_DBG, 'Python - shared_attribute=' + str(hasattr(shared, 'shared_attribute'))) + freeradius.log(freeradius.L_DBG, 'Python - shared_attribute=' + str(hasattr(shared, 'shared_attribute'))) if not hasattr(shared, 'shared_attribute'): setattr(shared, 'shared_attribute', True) - return radiusd.RLM_MODULE_NOOP + return freeradius.RLM_MODULE_NOOP else: - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK diff --git a/src/tests/modules/python/mod_thread_local_storage.py b/src/tests/modules/python/mod_thread_local_storage.py index f2897dc29ec..3018e870c8c 100644 --- a/src/tests/modules/python/mod_thread_local_storage.py +++ b/src/tests/modules/python/mod_thread_local_storage.py @@ -1,13 +1,13 @@ -import radiusd +import freeradius import threading local = threading.local() def authorize(p): global local - radiusd.log(radiusd.L_DBG, 'Python - threading.local.tls()=' + str(hasattr(local, 'tls'))) + freeradius.log(freeradius.L_DBG, 'Python - threading.local.tls()=' + str(hasattr(local, 'tls'))) if hasattr(local, 'tls'): - return radiusd.RLM_MODULE_OK + return freeradius.RLM_MODULE_OK else: local.tls = True - return radiusd.RLM_MODULE_NOOP + return freeradius.RLM_MODULE_NOOP diff --git a/src/tests/modules/python/mod_with_config.py b/src/tests/modules/python/mod_with_config.py index e95e6cfa34a..91571f4366d 100644 --- a/src/tests/modules/python/mod_with_config.py +++ b/src/tests/modules/python/mod_with_config.py @@ -1,7 +1,7 @@ -import radiusd +import freeradius def authorize(p): - if radiusd.config.get('a_param'): - return radiusd.RLM_MODULE_OK + if freeradius.config.get('a_param'): + return freeradius.RLM_MODULE_OK - return radiusd.RLM_MODULE_NOOP \ No newline at end of file + return freeradius.RLM_MODULE_NOOP diff --git a/src/tests/modules/python/module.conf b/src/tests/modules/python/module.conf index 5d7072e71fc..c184d2ebd6d 100644 --- a/src/tests/modules/python/module.conf +++ b/src/tests/modules/python/module.conf @@ -25,40 +25,18 @@ python pmod3_withmod1 { func_authorize = authorize } -python pmod4_cextcompat { +python pmod4 { module = 'mod_shared_storage' mod_authorize = ${.module} func_authorize = authorize - - cext_compat = true -} - -python pmod5_cextcompat { - module = 'mod_shared_storage' - - mod_authorize = ${.module} - func_authorize = authorize - - cext_compat = true } -python pmod4_not_cextcompat { +python pmod5 { module = 'mod_shared_storage' mod_authorize = ${.module} func_authorize = authorize - - cext_compat = false -} - -python pmod5_not_cextcompat { - module = 'mod_shared_storage' - - mod_authorize = ${.module} - func_authorize = authorize - - cext_compat = false } python pmod6_configured { @@ -72,7 +50,7 @@ python pmod6_configured { } } -python pmod_shared_storage { +python pmod7_shared_storage { module = 'mod_shared_storage' mod_authorize = ${.module}