backend: last batch of audits for &config_read_array() use

This commit is contained in:
Franco Fichtner 2026-02-18 10:16:14 +01:00
parent 39dc18d580
commit b7166dc7ae
6 changed files with 16 additions and 20 deletions

View file

@ -34,7 +34,7 @@ require_once("util.inc");
$subsystem = !empty($argv[1]) ? $argv[1] : '';
$type = !empty($argv[2]) ? $argv[2] : '';
$a_hasync = &config_read_array('hasync');
$a_hasync = config_read_array('hasync', false);
if (!empty($a_hasync['disconnectppps'])) {
if ($type != 'MASTER' && $type != 'BACKUP' && $type != 'INIT') {
log_msg("Carp '$type' event unknown from source '{$subsystem}'");
@ -45,8 +45,8 @@ if (!empty($a_hasync['disconnectppps'])) {
}
list ($vhid, $iface) = explode('@', $subsystem);
$a_ppps = &config_read_array('ppps', 'ppp');
foreach ($a_ppps as $ppp) {
foreach ($config_read_array('ppps', 'ppp', false) as $ppp) {
if ($ppp['ports'] == $iface) {
foreach($config['interfaces'] as $ifkey => $interface) {
if ($ppp['if'] == $interface['if']) {

View file

@ -39,7 +39,6 @@ if (isset($opts['h']) || empty($opts['g'])) {
exit(-1);
} else {
$groupname = $opts['g'];
$a_group = &config_read_array('system', 'group');
$localgroups = [];
foreach (shell_safe('/usr/sbin/pw %s -a', 'groupshow', true) as $record) {
@ -53,7 +52,8 @@ if (isset($opts['h']) || empty($opts['g'])) {
$update_group = null;
$groupdb = [];
foreach ($a_group as $groupent) {
foreach (config_read_array('system', 'group', false) as $groupent) {
$groupdb[] = $groupent['name'];
if ($groupent['name'] == $groupname) {
$update_group = $groupent;

View file

@ -39,7 +39,6 @@ if (isset($opts['h']) || empty($opts['u'])) {
exit(-1);
} else {
$username = $opts['u'];
$a_user = &config_read_array('system', 'user');
/**
* XXX: If performance will be challenging at some point in time, we can cut some of the local user handling,
@ -57,7 +56,8 @@ if (isset($opts['h']) || empty($opts['u'])) {
$update_user = null;
$userdb = [];
foreach ($a_user as $userent) {
foreach (config_read_array('system', 'user', false) as $userent) {
if (!empty($userent['shell']) || $userent['uid'] == 0) {
/* only users with a shell account are allowed to have a local entry */
$userdb[] = $userent['name'];

View file

@ -31,8 +31,8 @@ require_once('config.inc');
require_once('util.inc');
$carpcount = 0;
$a_vip = &config_read_array('virtualip', 'vip');
foreach ($a_vip as $carp) {
foreach (config_read_array('virtualip', 'vip', false) as $carp) {
if ($carp['mode'] == "carp") {
$carpcount++;
break;
@ -43,7 +43,7 @@ $response = [
'demotion' => get_single_sysctl('net.inet.carp.demotion'),
'allow' => get_single_sysctl('net.inet.carp.allow'),
'maintenancemode' => !empty($config["virtualip_carp_maintenancemode"]),
'status_msg' => ''
'status_msg' => '',
];
if (empty($response['maintenancemode']) && !empty($response['demotion'])) {

View file

@ -33,7 +33,6 @@ require_once('system.inc');
require_once('util.inc');
$action = strtolower($argv[1] ?? '');
$a_vip = &config_read_array('virtualip', 'vip');
if ($action == 'maintenance') {
if (isset($config["virtualip_carp_maintenancemode"])) {
@ -57,7 +56,7 @@ if ($action == 'maintenance') {
}
} elseif ($action == 'disable') {
set_single_sysctl('net.inet.carp.allow', '0');
foreach ($a_vip as $vip) {
foreach (config_read_array('virtualip', 'vip', false) as $vip) {
if (!empty($vip['vhid'])) {
interface_vip_bring_down($vip);
}
@ -66,7 +65,7 @@ if ($action == 'maintenance') {
} elseif ($action == 'enable') {
interfaces_pfsync_configure();
set_single_sysctl('net.inet.carp.allow', '1');
foreach ($a_vip as $vip) {
foreach (config_read_array('virtualip', 'vip', false) as $vip) {
if (!empty($vip['vhid'])) {
if ($vip['mode'] == 'carp') {
interface_carp_configure($vip);

View file

@ -65,10 +65,9 @@ if (isset($argv[2]) && isset($argv[3]) && $argv[2] === '-h' && $argv[3] === '0')
} elseif (isset($argv[2]) && isset($argv[3]) && $argv[2] === '-x' && $argv[3] === '0') {
$admin_user = &getUserEntryByUID(0);
if (!$admin_user) {
$admin_user = array();
$admin_user = [];
$admin_user['uid'] = 0;
$a_users = &config_read_array('system', 'user');
$a_users[] = $admin_user;
config_write_array('system', 'user', $admin_user);
}
$admin_user['scope'] = 'system';
@ -118,11 +117,9 @@ if (isset($config['system']['webgui']['authmode']) && $config['system']['webgui'
$admin_user = &getUserEntryByUID(0);
if (!$admin_user) {
$admin_user = array();
$admin_user = [];
$admin_user['uid'] = 0;
$a_users = &config_read_array('system', 'user');
$a_users[] = $admin_user;
echo "\nRestored missing root user.\n";
config_write_array('system', 'user', $admin_user);
}
$admin_user['scope'] = 'system';