summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/util.inc
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2017-01-02 09:34:55 -0500
committerjim-p <jimp@pfsense.org>2017-01-02 09:34:55 -0500
commita5d56253d87abeeb76ef480edced9a7a512ad908 (patch)
treee21433d2c67b338ef08f3311d0a6d75b5fed658d /src/etc/inc/util.inc
parent80d3effa960ab23112233d2dfb50c35161bd7e03 (diff)
parent416322ee7d7db1fe9d8d416017e4546162bbb766 (diff)
downloadpfsense-a5d56253d87abeeb76ef480edced9a7a512ad908.zip
pfsense-a5d56253d87abeeb76ef480edced9a7a512ad908.tar.gz
Merge pull request #3304 from marjohn56/master
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r--src/etc/inc/util.inc63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 78bf1b6..df5cdd0 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -2546,4 +2546,67 @@ function validateipaddr(&$addr, $type, $label, &$err_msg, $alias=false) {
return false;
}
+
+/* returns true if $dhcp6duid is a valid duid entrry */
+function is_duid($dhcp6duid) {
+ $values = explode(":", $dhcp6duid);
+ if (count($values) != 16 || strlen($dhcp6duid) != 47) {
+ return false;
+ }
+ for ($i = 0; $i < 16; $i++) {
+ if (ctype_xdigit($values[$i]) == false)
+ return false;
+ if (hexdec($values[$i]) < 0 || hexdec($values[$i]) > 255)
+ return false;
+ }
+ return true;
+}
+
+/* Write the DHCP6 DUID file */
+function write_dhcp6_duid($duidstring) {
+ // Create the hex array from the dhcp6duid config entry and write to file
+ global $g;
+
+ if(!is_duid($duidstring)) {
+ log_error(gettext("Error: attempting to write DUID file - Invalid DUID detected"));
+ return false;
+ }
+ $temp = str_replace(":","",$duidstring);
+ $duid_binstring = pack("H*",$temp);
+ if ($fd = fopen("{$g['vardb_path']}/dhcp6c_duid", "wb")) {
+ fwrite($fd, $duid_binstring);
+ fclose($fd);
+ return true;
+ }
+ log_error(gettext("Error: attempting to write DUID file - File write error"));
+ return false;
+}
+
+/* returns duid string from 'vardb_path']}/dhcp6c_duid' */
+function get_duid_from_file()
+{
+ global $g;
+
+ $duid_ASCII = "";
+ $count = 0;
+
+ if ($fd = fopen("{$g['vardb_path']}/dhcp6c_duid", "r")) {
+ if(filesize("{$g['vardb_path']}/dhcp6c_duid")==16) {
+ $buffer = fread($fd,16);
+ while($count < 16) {
+ $duid_ASCII .= bin2hex($buffer[$count]);
+ $count++;
+ if($count < 16) {
+ $duid_ASCII .= ":";
+ }
+ }
+ }
+ fclose($fd);
+ }
+ //if no file or error with read then the string returns blanked DUID string
+ if(!is_duid($duid_ASCII)) {
+ return "--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--";
+ }
+ return($duid_ASCII);
+}
?>
OpenPOWER on IntegriCloud