diff options
author | Renato Botelho <garga@FreeBSD.org> | 2014-02-03 14:55:01 -0200 |
---|---|---|
committer | Renato Botelho <garga@FreeBSD.org> | 2014-02-04 12:43:18 -0200 |
commit | 46b12609e51b9b3113abc9c22a1b0ad5a2b37d11 (patch) | |
tree | 0cadd8627871d2e8f159d093852e665a02e39777 /etc/inc | |
parent | 44f2ef9b486fc3e4e2a183ae157a86a9e8ac9018 (diff) | |
download | pfsense-46b12609e51b9b3113abc9c22a1b0ad5a2b37d11.zip pfsense-46b12609e51b9b3113abc9c22a1b0ad5a2b37d11.tar.gz |
Add escapeshellarg() calls on exec parameters. While I'm here, replace some exec() calls by php functions like symlink, copy, unlink, mkdir
Conflicts:
etc/inc/filter_log.inc
etc/inc/interfaces.inc
etc/inc/pfsense-utils.inc
etc/inc/pkg-utils.inc
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/filter_log.inc | 4 | ||||
-rw-r--r-- | etc/inc/interfaces.inc | 68 | ||||
-rw-r--r-- | etc/inc/ipsec.attributes.php | 2 | ||||
-rw-r--r-- | etc/inc/openvpn.attributes.php | 2 | ||||
-rw-r--r-- | etc/inc/openvpn.inc | 14 | ||||
-rw-r--r-- | etc/inc/pfsense-utils.inc | 20 | ||||
-rw-r--r-- | etc/inc/pkg-utils.inc | 14 | ||||
-rw-r--r-- | etc/inc/rrd.inc | 4 | ||||
-rw-r--r-- | etc/inc/service-utils.inc | 2 | ||||
-rw-r--r-- | etc/inc/shaper.inc | 2 | ||||
-rw-r--r-- | etc/inc/system.inc | 7 | ||||
-rw-r--r-- | etc/inc/upgrade_config.inc | 6 | ||||
-rw-r--r-- | etc/inc/util.inc | 12 |
13 files changed, 78 insertions, 79 deletions
diff --git a/etc/inc/filter_log.inc b/etc/inc/filter_log.inc index c0067fa..cb13b51 100644 --- a/etc/inc/filter_log.inc +++ b/etc/inc/filter_log.inc @@ -55,9 +55,9 @@ function conv_log_filter($logfile, $nentries, $tail = 50, $filtertext = "", $fil $logarr = ""; if(isset($config['system']['usefifolog'])) - exec("/usr/sbin/fifolog_reader {$logfile} | /usr/bin/tail -r -n {$tail}", $logarr); + exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . " | /usr/bin/tail -r -n {$tail}", $logarr); else - exec("/usr/sbin/clog {$logfile} | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail -r -n {$tail}", $logarr); + exec("/usr/sbin/clog " . escapeshellarg($logfile) . " | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail -r -n {$tail}", $logarr); $filterlog = array(); $counter = 0; diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 940915c..e842ffa 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -610,9 +610,9 @@ function interface_bridge_configure(&$bridge, $checkmember = 0) { } if ($bridge['maxaddr'] <> "") - mwexec("/sbin/ifconfig {$bridgeif} maxaddr {$bridge['maxaddr']}"); + mwexec("/sbin/ifconfig {$bridgeif} maxaddr " . escapeshellarg($bridge['maxaddr'])); if ($bridge['timeout'] <> "") - mwexec("/sbin/ifconfig {$bridgeif} timeout {$bridge['timeout']}"); + mwexec("/sbin/ifconfig {$bridgeif} timeout " . escapeshellarg($bridge['timeout'])); if ($bridge['span'] <> "") { $realif = get_real_interface($bridge['span']); mwexec("/sbin/ifconfig {$bridgeif} span {$realif}"); @@ -804,7 +804,7 @@ function interface_lagg_configure(&$lagg) { mwexec("/sbin/ifconfig {$laggif} laggport {$member}"); } - mwexec("/sbin/ifconfig {$laggif} laggproto {$lagg['proto']}"); + mwexec("/sbin/ifconfig {$laggif} laggproto " . escapeshellarg($lagg['proto'])); interfaces_bring_up($laggif); @@ -857,11 +857,11 @@ function interface_gre_configure(&$gre, $grekey = "") { $greif = pfSense_interface_create("gre"); /* Do not change the order here for more see gre(4) NOTES section. */ - mwexec("/sbin/ifconfig {$greif} tunnel {$realifip} {$gre['remote-addr']}"); + mwexec("/sbin/ifconfig {$greif} tunnel {$realifip} " . escapeshellarg($gre['remote-addr'])); if((is_ipaddrv6($gre['tunnel-local-addr'])) || (is_ipaddrv6($gre['tunnel-remote-addr']))) { - mwexec("/sbin/ifconfig {$greif} inet6 {$gre['tunnel-local-addr']} {$gre['tunnel-remote-addr']} prefixlen /{$gre['tunnel-remote-net']} "); + mwexec("/sbin/ifconfig {$greif} inet6 " . escapeshellarg($gre['tunnel-local-addr']) . " " . escapeshellarg($gre['tunnel-remote-addr']) . " prefixlen /" . escapeshellarg($gre['tunnel-remote-net'])); } else { - mwexec("/sbin/ifconfig {$greif} {$gre['tunnel-local-addr']} {$gre['tunnel-remote-addr']} netmask " . gen_subnet_mask($gre['tunnel-remote-net'])); + mwexec("/sbin/ifconfig {$greif} " . escapeshellarg($gre['tunnel-local-addr']) . " " . escapeshellarg($gre['tunnel-remote-addr']) . " netmask " . gen_subnet_mask($gre['tunnel-remote-net'])); } if (isset($gre['link0'])) pfSense_interface_flags($greif, IFF_LINK0); @@ -876,7 +876,7 @@ function interface_gre_configure(&$gre, $grekey = "") { log_error(gettext("Could not bring greif up -- variable not defined.")); if (isset($gre['link1']) && $gre['link1']) - mwexec("/sbin/route add {$gre['tunnel-remote-addr']}/{$gre['tunnel-remote-net']} {$gre['tunnel-local-addr']}"); + mwexec("/sbin/route add " . escapeshellarg($gre['tunnel-remote-addr']) . "/" . escapeshellarg($gre['tunnel-remote-net']) . " " . escapeshellarg($gre['tunnel-local-addr'])); if(is_ipaddrv4($gre['tunnel-remote-addr'])) file_put_contents("{$g['tmp_path']}/{$greif}_router", $gre['tunnel-remote-addr']); if(is_ipaddrv6($gre['tunnel-remote-addr'])) @@ -947,11 +947,11 @@ function interface_gif_configure(&$gif, $gifkey = "") { $gifif = pfSense_interface_create("gif"); /* Do not change the order here for more see gif(4) NOTES section. */ - mwexec("/sbin/ifconfig {$gifif} tunnel {$realifip} {$gif['remote-addr']}"); + mwexec("/sbin/ifconfig {$gifif} tunnel {$realifip} " . escapeshellarg($gif['remote-addr'])); if((is_ipaddrv6($gif['tunnel-local-addr'])) || (is_ipaddrv6($gif['tunnel-remote-addr']))) { - mwexec("/sbin/ifconfig {$gifif} inet6 {$gif['tunnel-local-addr']} {$gif['tunnel-remote-addr']} prefixlen /{$gif['tunnel-remote-net']} "); + mwexec("/sbin/ifconfig {$gifif} inet6 " . escapeshellarg($gif['tunnel-local-addr']) . " " . escapeshellarg($gif['tunnel-remote-addr']) . " prefixlen /" . escapeshellarg($gif['tunnel-remote-net'])); } else { - mwexec("/sbin/ifconfig {$gifif} {$gif['tunnel-local-addr']} {$gif['tunnel-remote-addr']} netmask " . gen_subnet_mask($gif['tunnel-remote-net'])); + mwexec("/sbin/ifconfig {$gifif} " . escapeshellarg($gif['tunnel-local-addr']) . " " . escapeshellarg($gif['tunnel-remote-addr']) . " netmask " . gen_subnet_mask($gif['tunnel-remote-net'])); } if (isset($gif['link0'])) pfSense_interface_flags($gifif, IFF_LINK0); @@ -983,10 +983,10 @@ function interface_gif_configure(&$gif, $gifkey = "") { file_put_contents("{$g['tmp_path']}/{$gifif}_routerv6", $gif['tunnel-remote-addr']); if (is_ipaddrv4($realifgw)) { - mwexec("/sbin/route change -host {$gif['remote-addr']} {$realifgw}"); + mwexec("/sbin/route change -host " . escapeshellarg($gif['remote-addr']) . " {$realifgw}"); } if (is_ipaddrv6($realifgw)) { - mwexec("/sbin/route change -host -inet6 {$gif['remote-addr']} {$realifgw}"); + mwexec("/sbin/route change -host -inet6 " . escapeshellarg($gif['remote-addr']) . " {$realifgw}"); } return $gifif; @@ -1152,7 +1152,7 @@ function interface_vip_bring_down($vip) { $vipif = get_real_interface($vip['interface']); if (does_interface_exist($vipif)) { if (is_ipaddrv6($vip['subnet'])) - mwexec("/sbin/ifconfig {$vipif} inet6 {$vip['subnet']} -alias"); + mwexec("/sbin/ifconfig {$vipif} inet6 " . escapeshellarg($vip['subnet']) . " -alias"); else pfSense_interface_deladdress($vipif, $vip['subnet']); } @@ -1235,7 +1235,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); if ($destroy == true) pfSense_interface_flags($realif, -IFF_UP); - mwexec("/usr/sbin/arp -d -i {$realif} -a"); + mwexec("/usr/sbin/arp -d -i " . escapeshellarg($realif) . " -a"); } break; default: @@ -1243,7 +1243,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); if ($destroy == true) pfSense_interface_flags($realif, -IFF_UP); - mwexec("/usr/sbin/arp -d -i {$realif} -a"); + mwexec("/usr/sbin/arp -d -i " . escapeshellarg($realif) . " -a"); } break; } @@ -1262,7 +1262,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = mwexec("/sbin/ifconfig " . escapeshellarg($realifv6) . " inet6 {$ip6} delete", true); if ($destroy == true) pfSense_interface_flags($realif, -IFF_UP); - mwexec("/usr/sbin/arp -d -i {$realif} -a"); + mwexec("/usr/sbin/arp -d -i " . escapeshellarg($realif) . " -a"); } break; case "6rd": @@ -1285,7 +1285,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$ifcfg['ipaddrv6']} delete", true); if ($destroy == true) pfSense_interface_flags($realif, -IFF_UP); - mwexec("/usr/sbin/arp -d -i {$realif} -a"); + mwexec("/usr/sbin/arp -d -i " . escapeshellarg($realif) . " -a"); } break; } @@ -1295,7 +1295,7 @@ function interface_bring_down($interface = "wan", $destroy = false, $ifacecfg = // log_error("Checking for old router states: {$g['tmp_path']}/{$realif}_router = {$old_router}"); if (!empty($old_router)) { log_error("Clearing states to old gateway {$old_router}."); - mwexec("/sbin/pfctl -i {$realif} -Fs -G {$old_router}"); + mwexec("/sbin/pfctl -i " . escapeshellarg($realif) . " -Fs -G {$old_router}"); } /* remove interface up file if it exists */ @@ -1450,12 +1450,11 @@ function interface_ppps_configure($interface) { // mpd5 requires a /var/spool/lock directory for PPP modem links. if(!is_dir("/var/spool/lock")) { - exec("/bin/mkdir -p /var/spool/lock"); - exec("/bin/chmod a+rw /var/spool/lock/."); + mkdir("/var/spool/lock", 0777, true); } // mpd5 modem chat script expected in the same directory as the mpd_xxx.conf files if (!file_exists("{$g['varetc_path']}/mpd.script")) - mwexec("/bin/ln -s /usr/local/sbin/mpd.script {$g['varetc_path']}/."); + symlink("/usr/local/sbin/mpd.script", "{$g['varetc_path']}/."); if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) { foreach ($config['ppps']['ppp'] as $pppid => $ppp) { @@ -1801,7 +1800,7 @@ EOD; /* Generate mpd.conf. If mpd_[interface].conf exists in the conf path, then link to it instead of generating a fresh conf file. */ if (file_exists("{$g['conf_path']}/mpd_{$interface}.conf")) - mwexec("/bin/ln -s {$g['conf_path']}/mpd_{$interface}.conf {$g['varetc_path']}/."); + symlink("{$g['conf_path']}/mpd_{$interface}.conf", "{$g['varetc_path']}/."); else { $fd = fopen("{$g['varetc_path']}/mpd_{$interface}.conf", "w"); if (!$fd) { @@ -1818,13 +1817,13 @@ EOD; if (isset($ppp['uptime'])) { if (!file_exists("/conf/{$pppif}.log")) { conf_mount_rw(); - mwexec("echo /dev/null > /conf/{$pppif}.log"); + file_put_contents("/conf/{$pppif}.log", ''); conf_mount_ro(); } } else { if (file_exists("/conf/{$pppif}.log")) { conf_mount_rw(); - mwexec("rm -f /conf/{$pppif}.log"); + unlink("/conf/{$pppif}.log"); conf_mount_ro(); } } @@ -1836,7 +1835,8 @@ EOD; } /* fire up mpd */ - mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/{$ppp['type']}_{$interface}.pid -s ppp {$ppp['type']}client"); + mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/" . + escapeshellarg($ppp['type']) . "_{$interface}.pid -s ppp " . escapeshellarg($ppp['type']) . "client"); // Check for PPPoE periodic reset request if ($type == "pppoe") { @@ -1848,7 +1848,7 @@ EOD; /* wait for upto 10 seconds for the interface to appear (ppp(oe)) */ $i = 0; while($i < 10) { - exec("/sbin/ifconfig {$ppp['if']} 2>&1", $out, $ret); + exec("/sbin/ifconfig " . escapeshellarg($ppp['if']) . " 2>&1", $out, $ret); if($ret == 0) break; sleep(1); @@ -2174,7 +2174,7 @@ function interface_carp_configure(&$vip) { $broadcast_address = gen_subnet_max($vip['subnet'], $vip['subnet_bits']); $advbase = ""; if (!empty($vip['advbase'])) - $advbase = "advbase {$vip['advbase']}"; + $advbase = "advbase " . escapeshellarg($vip['advbase']); if(is_ipaddrv4($vip['subnet'])) { $broadcast_address = gen_subnet_max($vip['subnet'], $vip['subnet_bits']); @@ -2213,7 +2213,7 @@ function interface_wireless_clone($realif, $wlcfg) { } $baseif = interface_get_wireless_base($wlcfg['if']); if(does_interface_exist($realif)) { - exec("/sbin/ifconfig {$realif}", $output, $ret); + exec("/sbin/ifconfig " . escapeshellarg($realif), $output, $ret); $ifconfig_str = implode($output); if(($wlcfg_mode == "hostap") && (! preg_match("/hostap/si", $ifconfig_str))) { log_error(sprintf(gettext("Interface %s changed to hostap mode"), $realif)); @@ -2715,7 +2715,7 @@ EOD; if ( !empty($friendly_if) && $config['interfaces'][$friendly_if]['wireless']['mode'] == "bss" && isset($config['interfaces'][$friendly_if]['wireless']['wpa']['enable']) ) { - mwexec("/bin/sh {$g['tmp_path']}/{$clone_if}_setup.sh"); + mwexec("/bin/sh {$g['tmp_path']}/" . escapeshellarg($clone_if) . "_setup.sh"); } } } @@ -2723,16 +2723,16 @@ EOD; /* The mode must be specified in a separate command before ifconfig * will allow the mode and channel at the same time in the next. */ - mwexec("/sbin/ifconfig {$if} mode " . escapeshellarg($standard)); + mwexec("/sbin/ifconfig " . escapeshellarg($if) . " mode " . escapeshellarg($standard)); /* configure wireless */ $wlcmd_args = implode(" ", $wlcmd); - mwexec("/sbin/ifconfig {$if} $wlcmd_args", false); + mwexec("/sbin/ifconfig " . escapeshellarg($if) . " " . $wlcmd_args, false); sleep(1); /* execute hostapd and wpa_supplicant if required in shell */ - mwexec("/bin/sh {$g['tmp_path']}/{$if}_setup.sh"); + mwexec("/bin/sh {$g['tmp_path']}/" . escapeshellarg($if) . "_setup.sh"); return 0; @@ -3009,7 +3009,7 @@ function interface_configure($interface = "wan", $reloadall = false, $linkupeven if (is_ipaddrv6($wancfg['ipaddrv6']) && $wancfg['subnetv6'] <> "") { //pfSense_interface_setaddress($realif, "{$wancfg['ipaddrv6']}/{$wancfg['subnetv6']}"); // FIXME: Add IPv6 Support to the pfSense module - mwexec("/sbin/ifconfig {$realif} inet6 {$wancfg['ipaddrv6']} prefixlen {$wancfg['subnetv6']} "); + mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$wancfg['ipaddrv6']} prefixlen " . escapeshellarg($wancfg['subnetv6'])); } break; } @@ -3663,7 +3663,7 @@ function is_interface_group($if) { function interface_group_add_member($interface, $groupname) { $interface = get_real_interface($interface); - mwexec("/sbin/ifconfig {$interface} group {$groupname}", true); + mwexec("/sbin/ifconfig {$interface} group " . escapeshellarg($groupname), true); } /* COMPAT Function */ diff --git a/etc/inc/ipsec.attributes.php b/etc/inc/ipsec.attributes.php index 7e7ce2e..e30fc4c 100644 --- a/etc/inc/ipsec.attributes.php +++ b/etc/inc/ipsec.attributes.php @@ -177,7 +177,7 @@ $rules = parse_cisco_acl($attributes); if (!empty($rules)) { $pid = posix_getpid(); @file_put_contents("/tmp/ipsec_{$pid}{$common_name}.rules", $rules); - mwexec("/sbin/pfctl -a \"ipsec/{$common_name}\" -f {$g['tmp_path']}/ipsec_{$pid}{$common_name}.rules"); + mwexec("/sbin/pfctl -a \"ipsec/" . escapeshellarg($common_name) . "\" -f {$g['tmp_path']}/ipsec_{$pid}" . escapeshellarg($common_name) . ".rules"); @unlink("{$g['tmp_path']}/ipsec_{$pid}{$common_name}.rules"); } diff --git a/etc/inc/openvpn.attributes.php b/etc/inc/openvpn.attributes.php index 2f7e121..31ec7f5 100644 --- a/etc/inc/openvpn.attributes.php +++ b/etc/inc/openvpn.attributes.php @@ -179,7 +179,7 @@ $rules = parse_cisco_acl($attributes); if (!empty($rules)) { $pid = posix_getpid(); @file_put_contents("/tmp/ovpn_{$pid}{$common_name}.rules", $rules); - mwexec("/sbin/pfctl -a \"openvpn/{$common_name}\" -f {$g['tmp_path']}/ovpn_{$pid}{$common_name}.rules"); + mwexec("/sbin/pfctl -a \"openvpn/" . escapeshellarg($common_name) . "\" -f {$g['tmp_path']}/ovpn_{$pid}" . escapeshellarg($common_name) . ".rules"); @unlink("{$g['tmp_path']}/ovpn_{$pid}{$common_name}.rules"); } diff --git a/etc/inc/openvpn.inc b/etc/inc/openvpn.inc index b680ce1..7ffb52d 100644 --- a/etc/inc/openvpn.inc +++ b/etc/inc/openvpn.inc @@ -399,13 +399,13 @@ function openvpn_reconfigure($mode, $settings) { /* create the tap device if required */ if (!file_exists("/dev/{$tunname}")) - exec("/sbin/ifconfig {$tunname} create"); + exec("/sbin/ifconfig " . escapeshellarg($tunname) . " create"); /* rename the device */ - mwexec("/sbin/ifconfig {$tunname} name {$devname}"); + mwexec("/sbin/ifconfig " . escapeshellarg($tunname) . " name " . escapeshellarg($devname)); /* add the device to the openvpn group */ - mwexec("/sbin/ifconfig {$devname} group openvpn"); + mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn"); } $pfile = $g['varrun_path'] . "/openvpn_{$mode_id}.pid"; @@ -801,7 +801,7 @@ function openvpn_restart($mode, $settings) { /* start the new process */ $fpath = $g['varetc_path']."/openvpn/{$mode_id}.conf"; openvpn_clear_route($mode, $settings); - mwexec_bg("/usr/local/sbin/openvpn --config {$fpath}"); + mwexec_bg("/usr/local/sbin/openvpn --config " . escapeshellarg($fpath)); if (!$g['booting']) send_event("filter reload"); @@ -837,13 +837,13 @@ function openvpn_delete($mode, & $settings) { } /* remove the device from the openvpn group */ - mwexec("/sbin/ifconfig {$devname} -group openvpn"); + mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " -group openvpn"); /* restore the original adapter name */ - mwexec("/sbin/ifconfig {$devname} name {$tunname}"); + mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " name " . escapeshellarg($tunname)); /* remove the configuration files */ - mwexec("/bin/rm {$g['varetc_path']}/openvpn/{$mode_id}.*"); + array_map('unlink', glob("{$g['varetc_path']}/openvpn/{$mode_id}.*")); } function openvpn_cleanup_csc($common_name) { diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 0b6507e..e7aaa2b 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -350,7 +350,7 @@ function get_pfsync_interface_status($pfsyncinterface) { * add_rule_to_anchor($anchor, $rule): adds the specified rule to an anchor */ function add_rule_to_anchor($anchor, $rule, $label) { - mwexec("echo " . $rule . " | /sbin/pfctl -a " . $anchor . ":" . $label . " -f -"); + mwexec("echo " . escapeshellarg($rule) . " | /sbin/pfctl -a " . escapeshellarg($anchor) . ":" . escapeshellarg($label) . " -f -"); } /* @@ -619,7 +619,7 @@ if (!function_exists('php_check_syntax')){ if (!function_exists('php_check_syntax')){ function php_check_syntax($code_to_check, &$errormessage){ return false; - $command = "/usr/local/bin/php -l " . $code_to_check; + $command = "/usr/local/bin/php -l " . escapeshellarg($code_to_check); $output = exec_command($command); if (stristr($output, "Errors parsing") == false) { echo "false\n"; @@ -1452,7 +1452,7 @@ function add_hostname_to_watch($hostname) { if((is_fqdn($hostname)) && (!is_ipaddr($hostname))) { $domrecords = array(); $domips = array(); - exec("host -t A $hostname", $domrecords, $rethost); + exec("host -t A " . escapeshellarg($hostname), $domrecords, $rethost); if($rethost == 0) { foreach($domrecords as $domr) { $doml = explode(" ", $domr); @@ -1526,7 +1526,7 @@ function compare_hostname_to_dnscache($hostname) { if((is_fqdn($hostname)) && (!is_ipaddr($hostname))) { $domrecords = array(); $domips = array(); - exec("host -t A $hostname", $domrecords, $rethost); + exec("host -t A " . escapeshellarg($hostname), $domrecords, $rethost); if($rethost == 0) { foreach($domrecords as $domr) { $doml = explode(" ", $domr); @@ -1876,7 +1876,7 @@ function update_alias_url_data() { function process_alias_unzip($temp_filename) { if(!file_exists("/usr/local/bin/unzip")) return; - mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.zip"); + rename("{$temp_filename}/aliases", "{$temp_filename}/aliases.zip"); mwexec("/usr/local/bin/unzip {$temp_filename}/aliases.tgz -d {$temp_filename}/aliases/"); unlink("{$temp_filename}/aliases.zip"); $files_to_process = return_dir_as_array("{$temp_filename}/"); @@ -1893,7 +1893,7 @@ function process_alias_unzip($temp_filename) { function process_alias_tgz($temp_filename) { if(!file_exists("/usr/bin/tar")) return; - mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz"); + rename("{$temp_filename}/aliases", "{$temp_filename}/aliases.tgz"); mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/"); unlink("{$temp_filename}/aliases.tgz"); $files_to_process = return_dir_as_array("{$temp_filename}/"); @@ -2026,7 +2026,7 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) { mwexec("/usr/bin/sed 's/\;.*//g' ". escapeshellarg($urltable_filename . ".tmp") . "| /usr/bin/egrep -v '^[[:space:]]*$|^#' > " . escapeshellarg($urltable_filename)); unlink_if_exists($urltable_filename . ".tmp"); } else - mwexec("/usr/bin/touch {$urltable_filename}"); + touch($urltable_filename); conf_mount_ro(); return true; } else { @@ -2119,10 +2119,10 @@ function nanobsd_update_fstab($gslice, $complete_path, $oldufs, $newufs) { $tmppath = "/tmp/{$gslice}"; $fstabpath = "/tmp/{$gslice}/etc/fstab"; - exec("/bin/mkdir {$tmppath}"); + mkdir($tmppath); exec("/sbin/fsck_ufs -y /dev/{$complete_path}"); exec("/sbin/mount /dev/ufs/{$gslice} {$tmppath}"); - exec("/bin/cp /etc/fstab {$fstabpath}"); + copy("/etc/fstab", $fstabpath); if (!file_exists($fstabpath)) { $fstab = <<<EOF @@ -2137,7 +2137,7 @@ EOF; $status = exec("sed -i \"\" \"s/pfsense{$oldufs}/pfsense{$newufs}/g\" {$fstabpath}"); } exec("/sbin/umount {$tmppath}"); - exec("/bin/rmdir {$tmppath}"); + rmdir($tmppath); return $status; } diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc index 9f3296a..b727abe 100644 --- a/etc/inc/pkg-utils.inc +++ b/etc/inc/pkg-utils.inc @@ -102,7 +102,7 @@ function remove_freebsd_package($packagestring) { // The packagestring passed in must be the full PBI package name, // as displayed by the pbi_info utility. e.g. "package-1.2.3_4-i386" // It must NOT have ".pbi" on the end. - exec("/usr/local/sbin/pbi_info {$packagestring} | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir); + exec("/usr/local/sbin/pbi_info " . escapeshellarg($packagestring) . " | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir); $pbidir = $pbidir[0]; if ($pbidir == "") { log_error("PBI dir for {$packagestring} was not found - cannot cleanup PBI files"); @@ -127,7 +127,7 @@ function remove_freebsd_package($packagestring) { } } - exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt"); + exec("/usr/local/sbin/pbi_delete " . escapeshellarg($packagestring) . " 2>>/tmp/pbi_delete_errors.txt"); } } @@ -279,7 +279,7 @@ function is_freebsd_pkg_installed($pkg) { if(!$pkg) return; $output = ""; - exec("/usr/local/sbin/pbi_info \"{$pkg}\"", $output, $retval); + exec("/usr/local/sbin/pbi_info \"" . escapeshellarg($pkg) . "\"", $output, $retval); return (intval($retval) == 0); } @@ -567,10 +567,10 @@ function pkg_fetch_recursive($pkgname, $filename, $dependlevel = 0, $base_url = $pkgaddout = ""; - exec("/usr/local/sbin/pbi_add {$pkgstaging} -f -v --no-checksig {$fetchto} 2>&1", $pkgaddout); + exec("/usr/local/sbin/pbi_add " . escapeshellarg($pkgstaging) . " -f -v --no-checksig " . escapeshellarg($fetchto) . " 2>&1", $pkgaddout); pkg_debug($pkgname . " " . print_r($pkgaddout, true) . "\npbi_add successfully completed.\n"); setup_library_paths(); - exec("/usr/local/sbin/pbi_info " . preg_replace('/\.pbi$/','',$filename) . " | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir); + exec("/usr/local/sbin/pbi_info " . escapeshellarg(preg_replace('/\.pbi$/','',$filename)) . " | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir); $pbidir = $pbidir[0]; $linkdirs = array('bin','sbin'); foreach($linkdirs as $dir) { @@ -803,7 +803,7 @@ function install_package_xml($pkg) { if(stristr($filename, ".tgz") <> "") { pkg_debug(gettext("Extracting tarball to -C for ") . $filename . "...\n"); $tarout = ""; - exec("/usr/bin/tar xvzf " . $prefix . $filename . " -C / 2>&1", $tarout); + exec("/usr/bin/tar xvzf " . escapeshellarg($prefix . $filename) . " -C / 2>&1", $tarout); pkg_debug(print_r($tarout, true) . "\n"); } if($pkg_chmod <> "") { @@ -861,7 +861,7 @@ function install_package_xml($pkg) { $pkg_name_for_pbi_match = strtolower($pkg) . "-"; exec("/usr/local/sbin/pbi_info | grep '^{$pkg_name_for_pbi_match}' | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray); $pbidir0 = $pbidirarray[0]; - exec("find /usr/local/etc/ -name *.conf | grep \"{$pkg}\"",$files); + exec("find /usr/local/etc/ -name *.conf | grep '" . escapeshellarg($pkg) . "'",$files); foreach($files as $f) { $pbiconf = str_replace('/usr/local',$pbidir0,$f); if(is_file($pbiconf) || is_link($pbiconf)) { diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc index d09ef82..a66120a 100644 --- a/etc/inc/rrd.inc +++ b/etc/inc/rrd.inc @@ -37,9 +37,9 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile) { $rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool"; if(file_exists($xmldumpfile)) - mwexec("rm {$xmldumpfile}"); + unlink($xmldumpfile); - exec("$rrdtool dump {$rrddatabase} {$xmldumpfile} 2>&1", $dumpout, $dumpret); + exec("$rrdtool dump " . escapeshellarg($rrddatabase) . " {$xmldumpfile} 2>&1", $dumpout, $dumpret); if ($dumpret <> 0) { $dumpout = implode(" ", $dumpout); log_error(sprintf(gettext('RRD dump failed exited with %1$s, the error is: %2$s'), $dumpret, $dumpout)); diff --git a/etc/inc/service-utils.inc b/etc/inc/service-utils.inc index a1dbf31..d52abd2 100644 --- a/etc/inc/service-utils.inc +++ b/etc/inc/service-utils.inc @@ -67,7 +67,7 @@ function write_rcfile($params) { $tokill =& $params['stop']; } else if(!empty($params['executable'])) { /* just nuke the executable */ - $tokill = "/usr/bin/killall {$params['executable']}"; + $tokill = "/usr/bin/killall " . escapeshellarg($params['executable']); } else { /* make an educated guess (bad) */ $tokill = array_pop(explode('/', array_shift(explode(' ', $params['start'])))); diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index ef49bc2..bcca750 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -4093,7 +4093,7 @@ function generate_layer7_files() { if (!is_module_loaded("ipdivert.ko")) mwexec("/sbin/kldload ipdivert.ko"); - mwexec("rm -f {$g['tmp_path']}/*.l7"); + array_map('unlink', glob("{$g['tmp_path']}/*.l7")); } foreach($layer7_rules_list as $l7rules) { diff --git a/etc/inc/system.inc b/etc/inc/system.inc index d213aa6..b2d7309 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -379,7 +379,7 @@ function system_routing_configure($interface = "") { $foundgwv6 = false; /* tack on all the hard defined gateways as well */ if (is_array($config['gateways']['gateway_item'])) { - mwexec("/bin/rm -f {$g['tmp_path']}/*_defaultgw {$g['tmp_path']}/*_defaultgwv6", true); + array_map('unlink', glob("{$g['tmp_path']}/*_defaultgw{,v6}", GLOB_BRACE)); foreach ($config['gateways']['gateway_item'] as $gateway) { if (isset($gateway['defaultgw'])) { if ($gateway['ipprotocol'] != "inet6" && (is_ipaddrv4($gateway['gateway']) || $gateway['gateway'] == "dynamic")) { @@ -875,8 +875,7 @@ function system_generate_lighty_config($filename, $captive_portal_mod_evasive = "evasive.max-conns-per-ip = {$maxprocperip}"; $server_upload_dirs = "server.upload-dirs = ( \"{$g['tmp_path']}/captiveportal/\" )\n"; - exec("mkdir -p {$g['tmp_path']}/captiveportal"); - exec("chmod a-w {$g['tmp_path']}/captiveportal"); + mkdir("{$g['tmp_path']}/captiveportal", 0555); $server_max_request_size = "server.max-request-size = 384"; $cgi_config = ""; } else { @@ -1354,7 +1353,7 @@ function system_ntp_configure($start_ntpd=true) { /* if /var/empty does not exist, create it */ if(!is_dir("/var/empty")) - exec("/bin/mkdir -p /var/empty && chmod ug+rw /var/empty/."); + mkdir("/var/empty", 0775, true); /* start opentpd, set time now and use /var/etc/ntpd.conf */ mwexec("/usr/local/sbin/ntpd -g -c {$g['varetc_path']}/ntpd.conf -p {$g['varrun_path']}/ntpd.pid", false, true); diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc index 901902c..cf25e1d 100644 --- a/etc/inc/upgrade_config.inc +++ b/etc/inc/upgrade_config.inc @@ -1991,7 +1991,7 @@ function upgrade_054_to_055() { /* restore the databases, if we have one */ if (restore_rrd()) { /* Make sure to move the rrd backup out of the way. We will make a new one after converting. */ - exec("/bin/mv {$g['cf_conf_path']}/rrd.tgz {$g['cf_conf_path']}/backup"); + rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup"); } } @@ -2657,7 +2657,7 @@ function upgrade_080_to_081() { /* restore the databases, if we have one */ if (restore_rrd()) { /* Make sure to move the rrd backup out of the way. We will make a new one after converting. */ - exec("/bin/mv {$g['cf_conf_path']}/rrd.tgz {$g['cf_conf_path']}/backup"); + rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup"); } } @@ -3107,7 +3107,7 @@ function upgrade_095_to_096() { /* restore the databases, if we have one */ if (restore_rrd()) { /* Make sure to move the rrd backup out of the way. We will make a new one after converting. */ - exec("/bin/mv {$g['cf_conf_path']}/rrd.tgz {$g['cf_conf_path']}/backup"); + rename("{$g['cf_conf_path']}/rrd.tgz", "{$g['cf_conf_path']}/backup"); } } diff --git a/etc/inc/util.inc b/etc/inc/util.inc index b23c5a3..8f57553 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -52,7 +52,7 @@ function isvalidpid($pidfile) { function is_process_running($process) { $output = ""; - exec("/bin/pgrep -anx {$process}", $output, $retval); + exec("/bin/pgrep -anx " . escapeshellarg($process), $output, $retval); return (intval($retval) == 0); } @@ -65,7 +65,7 @@ function isvalidproc($proc) { /* return 1 for success and 0 for a failure */ function sigkillbypid($pidfile, $sig) { if (file_exists($pidfile)) - return mwexec("/bin/pkill -{$sig} -F {$pidfile}", true); + return mwexec("/bin/pkill " . escapeshellarg("-{$sig}") . " -F {$pidfile}", true); return 0; } @@ -73,7 +73,7 @@ function sigkillbypid($pidfile, $sig) { /* kill a process by name */ function sigkillbyname($procname, $sig) { if(isvalidproc($procname)) - return mwexec("/usr/bin/killall -{$sig} " . escapeshellarg($procname), true); + return mwexec("/usr/bin/killall " . escapeshellarg("-{$sig}") . " " . escapeshellarg($procname), true); } /* kill a process by name */ @@ -1070,7 +1070,7 @@ function log_auth($error) { ******/ function exec_command($command) { $output = array(); - exec($command . ' 2>&1 ', $output); + exec($command . ' 2>&1', $output); return(implode("\n", $output)); } @@ -1296,9 +1296,9 @@ function verify_digital_signature($fname) { /* obtain MAC address given an IP address by looking at the ARP table */ function arp_get_mac_by_ip($ip) { - mwexec("/sbin/ping -c 1 -t 1 {$ip}", true); + mwexec("/sbin/ping -c 1 -t 1 " . escapeshellarg($ip), true); $arpoutput = ""; - exec("/usr/sbin/arp -n {$ip}", $arpoutput); + exec("/usr/sbin/arp -n " . escapeshellarg($ip), $arpoutput); if ($arpoutput[0]) { $arpi = explode(" ", $arpoutput[0]); |