-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
freeradius service handling fixes (Bug #6404), fix chown handling and various bugs #267
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c984f27
Remove unwanted freeradius restart on install/upgrade (Bug #6404)
doktornotor 7be36fd
Add an argument to skip service restart
doktornotor b388104
Do not restart service twice on resync
doktornotor 6519bef
Bump port version
doktornotor 0f9126f
Fix XMLRPC sync madness that was restarting the service 4 times
doktornotor 57204cc
Do not restart when booting either
doktornotor 98597de
Remove an evil recursive chown call on /var/log
doktornotor 22fe452
Stop creating a symlink to itself instead of /usr/local/etc/raddb dir…
doktornotor 1775136
Use safe_mkdir() and PHP functions here, fix a broken check
doktornotor eb54fa8
Sanitize and fix recursive chown usage
doktornotor bca4075
Use safe_mkdir() and PHP functions here to match freeradius_settings_…
doktornotor 960e97a
Prevent install failure if unlink() fails here
doktornotor de8f640
Use boolean for $via_rpc
doktornotor af938f7
Add $restart_svc argument to more functions
doktornotor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,16 +39,17 @@ define('FREERADIUS_LIB', FREERADIUS_BASE . '/lib'); | |
define('FREERADIUS_ETC', FREERADIUS_BASE . '/etc'); | ||
|
||
// Check freeradius lib version | ||
$frlib=""; | ||
if (file_exists(FREERADIUS_LIB)) { | ||
$frlib = ""; | ||
if (is_dir(FREERADIUS_LIB)) { | ||
$libfiles = scandir(FREERADIUS_LIB); | ||
foreach ($libfiles as $libfile){ | ||
if (preg_match("/freeradius-/",$libfile)) | ||
$frlib=FREERADIUS_LIB . '/' . $libfile; | ||
foreach ($libfiles as $libfile) { | ||
if (preg_match("/freeradius-/", $libfile)) { | ||
$frlib = FREERADIUS_LIB . '/' . $libfile; | ||
} | ||
} | ||
} | ||
if ($frlib == ""){ | ||
log_error("freeRADIUS - No freeradius lib found on ".FREERADIUS_LIB); | ||
if ($frlib == "") { | ||
log_error("freeRADIUS - No freeradius libs found on " . FREERADIUS_LIB); | ||
} | ||
|
||
function freeradius_deinstall_command() { | ||
|
@@ -64,24 +65,54 @@ function freeradius_deinstall_command() { | |
return; | ||
} | ||
|
||
function freeradius_chown_recursive($dir, $user = "root", $group = "wheel") { | ||
if (empty($dir) || ($dir == '/') || ($dir == '/usr/local') || ($dir == '/usr/local/etc') || ($dir == '/usr/local/lib') || ($dir == '/var/log') || !is_dir($dir)) { | ||
log_error(gettext("[freeradius] Attempted to recursively chown an invalid directory: '{$dir}'")); | ||
return; | ||
} | ||
chown($dir, $user); | ||
chgrp($dir, $group); | ||
$handle = opendir($dir); | ||
if ($handle) { | ||
while (($item = readdir($handle)) !== false) { | ||
if (!empty($item) && ($item != ".") && ($item != "..")) { | ||
$path = "{$dir}/{$item}"; | ||
if (is_file($path)) { | ||
chown($path, $user); | ||
chgrp($path, $group); | ||
} | ||
} | ||
} | ||
} else { | ||
log_error(gettext("[freedarius] freeradius_chown_recursive() call failed; permissions not set for directory: '{$dir}'")); | ||
} | ||
} | ||
|
||
function freeradius_install_command() { | ||
global $config, $frlib; | ||
|
||
// We create here different folders for different counters. | ||
@mkdir("/var/log/radacct/datacounter/daily", 0755, true); | ||
@mkdir("/var/log/radacct/datacounter/weekly", 0755, true); | ||
@mkdir("/var/log/radacct/datacounter/monthly", 0755, true); | ||
@mkdir("/var/log/radacct/datacounter/forever", 0755, true); | ||
@mkdir("/var/log/radacct/timecounter", 0755, true); | ||
@mkdir(FREERADIUS_ETC . "/raddb/scripts", 0755, true); | ||
|
||
unlink_if_exists("/usr/local/etc/raddb"); | ||
@symlink(FREERADIUS_ETC . "/raddb", "/usr/local/etc/raddb"); | ||
if (!file_exists("/var/log/radutmp")) { exec("touch /var/log/radutmp"); } | ||
if (!file_exists("/var/log/radwtmp")) { exec("touch /var/log/radwtmp"); } | ||
exec("chown -R root:wheel " . FREERADIUS_ETC . "/raddb /var/log/radacct"); | ||
if (file_exists($frlib)) { | ||
exec("chown -R root:wheel {$frlib}"); | ||
safe_mkdir("/var/log/radacct/datacounter/daily"); | ||
safe_mkdir("/var/log/radacct/datacounter/weekly"); | ||
safe_mkdir("/var/log/radacct/datacounter/monthly"); | ||
safe_mkdir("/var/log/radacct/datacounter/forever"); | ||
safe_mkdir("/var/log/radacct/timecounter"); | ||
if (!file_exists("/var/log/radutmp")) { | ||
touch("/var/log/radutmp"); | ||
} | ||
if (!file_exists("/var/log/radwtmp")) { | ||
touch("/var/log/radwtmp"); | ||
} | ||
|
||
// Previous package versions were creating a symlink targeting itself here | ||
if (is_link(FREERADIUS_ETC . "/raddb")) { | ||
@unlink(FREERADIUS_ETC . "/raddb"); | ||
} | ||
safe_mkdir(FREERADIUS_ETC . "/raddb/scripts"); | ||
freeradius_chown_recursive(FREERADIUS_ETC . "/raddb"); | ||
freeradius_chown_recursive("/var/log/radacct"); | ||
if (is_dir($frlib)) { | ||
freeradius_chown_recursive($frlib); | ||
} | ||
|
||
// creating a backup file of the original policy.conf no matter if user checked this or not | ||
|
@@ -163,23 +194,27 @@ SERVICENAME="radiusd" | |
EOD; | ||
$rcfile['stop'] = FREERADIUS_ETC . '/rc.d/radiusd onestop'; | ||
write_rcfile($rcfile); | ||
start_service("radiusd"); | ||
} | ||
|
||
function freeradius_settings_resync() { | ||
function freeradius_settings_resync($restart_svc = true) { | ||
global $config; | ||
$conf = ''; | ||
|
||
// put the constant to a variable | ||
$varFREERADIUS_BASE = FREERADIUS_BASE; | ||
|
||
// We do some checks of some folders which will be deleted after reboot on nanobsd systems | ||
if (!file_exists("/var/log/radacct/")) { exec("mkdir /var/log/radacct"); } | ||
if (!file_exists("/var/log/radacct/datacounter/")) { exec("mkdir /var/log/radacct/datacounter && mkdir /var/log/radacct/datacounter/daily && mkdir /var/log/radacct/datacounter/weekly && mkdir /var/log/radacct/datacounter/monthly && mkdir /var/log/radacct/datacounter/forever"); } | ||
if (!file_exists("/var/log/radacct/timecounter/")) { exec("mkdir /var/log/radacct/timecounter"); } | ||
if (!file_exists("/var/log/radutmp")) { exec("touch /var/log/radutmp"); } | ||
if (!file_exists("/var/log/radwtmp")) { exec("touch /var/log/radwtmp"); } | ||
if (!file_exists("/var/log/radacct/")) { exec("chown -R root:wheel /var/log/radacct"); } | ||
safe_mkdir("/var/log/radacct/datacounter/daily"); | ||
safe_mkdir("/var/log/radacct/datacounter/weekly"); | ||
safe_mkdir("/var/log/radacct/datacounter/monthly"); | ||
safe_mkdir("/var/log/radacct/datacounter/forever"); | ||
safe_mkdir("/var/log/radacct/timecounter"); | ||
if (!file_exists("/var/log/radutmp")) { | ||
touch("/var/log/radutmp"); | ||
} | ||
if (!file_exists("/var/log/radwtmp")) { | ||
touch("/var/log/radwtmp"); | ||
} | ||
|
||
$varsettings = $config['installedpackages']['freeradiussettings']['config'][0]; | ||
|
||
|
@@ -409,11 +444,16 @@ EOD; | |
// This is to fix the mysqlclient.so which gets lost after reboot | ||
exec("ldconfig -m /usr/local/lib/mysql"); | ||
// Change owner of freeradius created files | ||
exec("chown -R root:wheel /var/log"); | ||
restart_service("radiusd"); | ||
if (is_dir("/var/log/radacct/")) { | ||
freeradius_chown_recursive("/var/log/radacct"); | ||
} | ||
|
||
if ($restart_svc) { | ||
restart_service("radiusd"); | ||
} | ||
} | ||
|
||
function freeradius_users_resync() { | ||
function freeradius_users_resync($via_rpc = "no") { | ||
global $config; | ||
|
||
$conf = ''; | ||
|
@@ -634,11 +674,15 @@ EOD; | |
conf_mount_ro(); | ||
|
||
freeradius_sync_on_changes(); | ||
restart_service('radiusd'); | ||
// Do not restart on boot | ||
// Will get restarted later by freeradius_clients_resync() if called via XMLRPC sync | ||
if ($via_rpc == "no" && !platform_booting()) { | ||
restart_service('radiusd'); | ||
} | ||
} | ||
|
||
|
||
function freeradius_authorizedmacs_resync() { | ||
function freeradius_authorizedmacs_resync($via_rpc = "no") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use boolean type for $via_rpc |
||
global $config; | ||
|
||
$conf = ''; | ||
|
@@ -828,7 +872,9 @@ EOD; | |
conf_mount_ro(); | ||
|
||
freeradius_sync_on_changes(); | ||
restart_service('radiusd'); | ||
if ($via_rpc == "no") { | ||
restart_service('radiusd'); | ||
} | ||
} | ||
|
||
function freeradius_clients_resync() { | ||
|
@@ -2758,14 +2804,12 @@ function freeradius_do_xmlrpc_sync($sync_to_ip, $username, $password, $varsyncpo | |
// This function restarts all other needed functions after XMLRPC so that the content of .XML + .INC will be written in the files (clients.conf, users) | ||
// Adding more functions will increase the to sync | ||
function freeradius_all_after_XMLRPC_resync() { | ||
|
||
freeradius_users_resync(); | ||
freeradius_authorizedmacs_resync(); | ||
// Only (re)start the service once by passing $via_rpc = 'yes' to the below function calls | ||
freeradius_users_resync('yes'); | ||
freeradius_authorizedmacs_resync('yes'); | ||
freeradius_clients_resync(); | ||
|
||
log_error("[FreeRADIUS]: Finished XMLRPC process. It should be OK. For more information look at the host which started sync."); | ||
|
||
exec(FREERADIUS_ETC . "/rc.d/radiusd onerestart"); | ||
} | ||
|
||
function freeradius_modulescounter_resync() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use boolean type for $via_rpc