Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
smradius
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shail
smradius
Commits
ef746b6c
Commit
ef746b6c
authored
16 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
* More work on the userdb sql module
parent
a86baf9b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smradius/modules/userdb/mod_userdb_sql.pm
+86
-15
86 additions, 15 deletions
smradius/modules/userdb/mod_userdb_sql.pm
with
86 additions
and
15 deletions
smradius/modules/userdb/mod_userdb_sql.pm
+
86
−
15
View file @
ef746b6c
...
...
@@ -26,6 +26,7 @@ use smradius::constants;
use
smradius::
logging
;
use
smradius::
dblayer
;
use
smradius::
util
;
use
smradius::
attributes
;
# Exporter stuff
require
Exporter
;
...
...
@@ -65,8 +66,8 @@ sub init
$server
->
{'
smradius
'}
->
{'
database
'}
->
{'
enabled
'}
=
1
;
}
#Default configs...
$config
->
{'
userdb_
select
_query
'}
=
'
#
Default configs...
$config
->
{'
userdb_
find
_query
'}
=
'
SELECT
ID
FROM
...
...
@@ -75,13 +76,32 @@ sub init
UserName = %{authentication.User-Name}
';
$config
->
{'
userdb_get_group_attributes_query
'}
=
'
SELECT
group_attributes.Name, group_attributes.Operator, group_attributes.Value
FROM
@TP@group_attributes, @TP@users_to_groups
WHERE
users_to_groups.UserID = %{user.ID}
AND group_attributes.GroupID = users_to_groups.GroupID
';
$config
->
{'
userdb_get_user_attributes_query
'}
=
'
SELECT
Name, Operator, Value
FROM
@TP@users_attributes
WHERE
UserID = %{user.ID}
';
# Setup SQL queries
if
(
defined
(
$scfg
->
{'
mod_userdb_sql
'}))
{
# Pull in queries
if
(
defined
(
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
select
_query
'})
&&
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
select
_query
'}
ne
"")
{
$config
->
{'
userdb_
select
_query
'}
=
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
select
_query
'};
if
(
defined
(
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
find
_query
'})
&&
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
find
_query
'}
ne
"")
{
$config
->
{'
userdb_
find
_query
'}
=
$scfg
->
{'
mod_userdb_sql
'}
->
{'
userdb_
find
_query
'};
}
}
...
...
@@ -101,26 +121,36 @@ sub find
# Build template
my
$template
;
$server
->
log
(
LOG_DEBUG
,"
[MOD_USERDB_SQL] Find function called
");
foreach
my
$attr
(
$packet
->
attributes
)
{
$template
->
{'
authentication
'}
->
{
$attr
}
=
$packet
->
rawattr
(
$attr
)
}
$template
->
{'
user
'}
=
$user
;
# Replace template entries
my
@dbDoParams
=
templateReplace
(
$config
->
{'
userdb_
select
_query
'},
$template
);
my
@dbDoParams
=
templateReplace
(
$config
->
{'
userdb_
find
_query
'},
$template
);
my
$sth
=
DBSelect
(
@dbDoParams
);
if
(
!
$sth
)
{
$server
->
log
(
LOG_ERR
,"
Failed to find user data:
"
.
smradius::dblayer::
Error
());
return
-
1
;
$server
->
log
(
LOG_ERR
,"
[MOD_USERDB_SQL] Failed to find user data:
"
.
smradius::dblayer::
Error
());
return
MOD_RES_SKIP
;
}
# Check if we got a result, if we did not NACK
my
$rows
=
$sth
->
rows
();
if
(
$rows
>
1
)
{
$server
->
log
(
LOG_ERR
,"
[MOD_USERDB_SQL] More than one result returned for user '
"
.
$user
->
{'
Username
'}
.
"
'
");
return
MOD_RES_SKIP
;
}
elsif
(
$rows
<
1
)
{
$server
->
log
(
LOG_DEBUG
,"
[MOD_USERDB_SQL] User '
"
.
$user
->
{'
Username
'}
.
"
' not found in database
");
return
MOD_RES_SKIP
;
}
$server
->
log
(
LOG_NOTICE
,"
Number of rows :
"
.
$sth
->
rows
());
# Grab record data
my
$row
=
$sth
->
fetchrow_hashref
();
# TODO: Query database and see if this user exists
DBFreeRes
(
$sth
);
return
MOD_RES_
SKIP
;
return
(
MOD_RES_
ACK
,
$row
)
;
}
...
...
@@ -136,10 +166,51 @@ sub get
{
my
(
$server
,
$user
,
$packet
)
=
@_
;
my
$userDetails
;
# TODO: Query user and get attributes, return in $userDetails hash
# Build template
my
$template
;
foreach
my
$attr
(
$packet
->
attributes
)
{
$template
->
{'
authentication
'}
->
{
$attr
}
=
$packet
->
rawattr
(
$attr
)
}
$template
->
{'
user
'}
->
{'
Username
'}
=
$user
->
{'
Username
'};
$template
->
{'
user
'}
->
{'
ID
'}
=
$user
->
{'
_UserDB_Data
'}
->
{'
id
'};
# Replace template entries
my
@dbDoParams
=
templateReplace
(
$config
->
{'
userdb_get_group_attributes_query
'},
$template
);
# Query database
my
$sth
=
DBSelect
(
@dbDoParams
);
if
(
!
$sth
)
{
$server
->
log
(
LOG_ERR
,"
Failed to get group attributes:
"
.
smradius::dblayer::
Error
());
return
-
1
;
}
# Loop with group attributes
while
(
my
$row
=
$sth
->
fetchrow_hashref
())
{
addAttribute
(
$server
,
$user
->
{'
Attributes
'},
$row
);
}
$sth
->
DBFreeRes
();
# Replace template entries again
@dbDoParams
=
templateReplace
(
$config
->
{'
userdb_get_user_attributes_query
'},
$template
);
# Query database
$sth
=
DBSelect
(
@dbDoParams
);
if
(
!
$sth
)
{
$server
->
log
(
LOG_ERR
,"
Failed to get user attributes:
"
.
smradius::dblayer::
Error
());
return
-
1
;
}
# Loop with group attributes
while
(
my
$row
=
$sth
->
fetchrow_hashref
())
{
addAttribute
(
$server
,
$user
->
{'
Attributes
'},
$row
);
}
$sth
->
DBFreeRes
();
return
$userDetails
;
#
return $userDetails;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment