#
# $Id$
-import radiusd
+import freeradius
def instantiate(p):
print("*** instantiate ***")
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
#
# $Id$
-import radiusd
+import freeradius
import MySQLdb
# Configuration
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.
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
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]
# 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()
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'),
# )
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):
# 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.
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
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"
},
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 */
* 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) ||
* 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 */
/*