function ApplySingleAcls($directory) { $unix = new unix(); $chmod_bin = $unix->find_program("chmod"); $setfacl_bin = $unix->find_program("setfacl"); $recursive = null; $chmod = null; $q = new mysql(); $dir = $unix->shellEscapeChars($directory); if (!is_dir($directory)) { echo "Starting......: acls {$directory} no such directory\n"; $q->QUERY_SQL("DELETE FROM acl_directories WHERE `directory`='{$directory}'"); if (!$q->ok) { echo $q->mysql_error . "\n"; } return; } $acls = new aclsdirs($directory); echo "Starting......: acls \"{$dir}\" directory\n"; if (!is_numeric($acls->chmod_octal)) { $events[] = "octal is not a numeric value..."; } if (is_numeric($acls->chmod_octal)) { $events[] = "octal \"{$acls->chmod_octal}\""; if (chmod_recursive == 1) { $events[] = "Recursive mode"; $recursive = " -R "; } $chmod = " " . $acls->chmod_octal; } if ($chmod != null) { $cmd = "{$chmod_bin}{$recursive}{$chmod} {$dir}"; $events[] = "{$cmd}"; exec("{$chmod_bin}{$recursive}{$chmod} {$dir} 2>&1", $events); } if (strlen($setfacl_bin) < 3) { $events[] = "ERROR: setfacl no such binary file"; $events_text = @implode("\n", $events); if ($GLOBALS["VERBOSE"]) { echo $events_text . "\n"; } $sql = "UPDATE acl_directories SET events='" . addslashes($events_text) . "' WHERE `md5`='{$acls->md5}'"; if ($GLOBALS["VERBOSE"]) { echo $sql . "\n"; } $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "{$q->mysql_error}\n"; } return; } $cmd = "{$setfacl_bin} -b {$dir} 2>&1"; $events[] = $cmd; exec("{$cmd}", $events); if ($GLOBALS["VERBOSE"]) { if (!is_array($acls->acls_array)) { echo "acls_array not an Array\n"; } } print_r($acls->acls_array); $gp = new groups(); if (is_array($acls->acls_array["GROUPS"])) { while (list($groupname, $array) = each($acls->acls_array["GROUPS"])) { $perms = array(); $perms_strings = null; $recurs = null; if ($array["r"] == 1) { $perms[] = "r"; } if ($array["w"] == 1) { $perms[] = "w"; } if ($array["x"] == 1) { $perms[] = "x"; } $perms_strings = @implode("", $perms); if ($perms_strings == null) { $events[] = "No permissions set for {$groupname}"; continue; } if ($acls->acls_array["recursive"] == 1) { $recurs = "-R "; } $gpid = $gp->GroupIDFromGetEnt($groupname); $groupname = utf8_encode($groupname); if ($GLOBALS["VERBOSE"]) { echo "`{$groupname}` as gidNumber `{$gpid}`\n"; } if (is_numeric($gpid)) { if ($gpid > 0) { $groupname = $gpid; } } $cmd = "{$setfacl_bin} {$recurs}-m g:\"{$groupname}\":{$perms_strings} {$dir} 2>&1"; $events[] = $cmd; exec("{$cmd}", $events); if ($acls->acls_array["default"] == 1) { $groupname = utf8_encode($groupname); $cmd = "{$setfacl_bin} {$recurs}-m d:g:\"{$groupname}\":{$perms_strings} {$dir} 2>&1"; $events[] = $cmd; exec("{$cmd}", $events); } } } else { $events[] = "Groups: No acls\n"; } if (is_array($acls->acls_array["MEMBERS"])) { while (list($member, $array) = each($acls->acls_array["MEMBERS"])) { $perms = array(); $perms_strings = null; $recurs = null; if ($array["r"] == 1) { $perms[] = "r"; } if ($array["w"] == 1) { $perms[] = "w"; } if ($array["x"] == 1) { $perms[] = "x"; } $perms_strings = @implode("", $perms); if ($perms_strings == null) { $events[] = "No permissions set for {$member}"; continue; } if ($acls->acls_array["recursive"] == 1) { $recurs = "R"; } $member = utf8_encode($member); $cmd = "{$setfacl_bin} -m{$recurs} u:\"{$member}\":{$perms_strings} {$dir} 2>&1"; $events[] = $cmd; exec("{$cmd}", $events); if ($acls->acls_array["default"] == 1) { $member = utf8_encode($member); $cmd = "{$setfacl_bin} -m{$recurs} d:u:\"{$member}\":{$perms_strings} {$dir} 2>&1"; $events[] = $cmd; exec("{$cmd}", $events); } } } else { $events[] = "Members: No acls\n"; } $events_text = @implode("\n", $events); if ($GLOBALS["VERBOSE"]) { echo $events_text . "\n"; } $sql = "UPDATE acl_directories SET events='" . addslashes($events_text) . "' WHERE `md5`='{$acls->md5}'"; $q->QUERY_SQL($sql, "artica_backup"); }