public static function getUserRecord($uid, $checkSU = TRUE) { // -- If no $uid, return data for authenticated user if (!isset($uid) && self::isAuthenticated()) { return array("name" => isset($_SESSION["nwAuth"]["username"]) ? $_SESSION["nwAuth"]["username"] : "", "uid" => isset($_SESSION["nwAuth"]["uid"]) ? $_SESSION["nwAuth"]["uid"] : "", "gecos" => isset($_SESSION["nwAuth"]["gecos"]) ? $_SESSION["nwAuth"]["gecos"] : ""); } if (!isset($uid) || empty($uid)) { return FALSE; } // -- Cleanup $uid = (int) $uid; // -- This UID may have been processed earlier and stored in auth::$userAccounts if (isset(self::$userAccounts[$uid]) && ($au = self::$userAccounts[$uid])) { return $au; } // -- Is this the special robot UID? if (self::isRobot($uid)) { return array("name" => "nobody", "uid" => $uid, "gecos" => "WebRobot"); } // -- Then check if a translation exists in the special accounts DB table (negative UIDs): if (preg_match("/^-\\d+/", $uid)) { // if (preg_match("/^-?\d+/",$uid)) { // -- Fetch user data for UID from DB if (!class_exists("fromdb_accounts", FALSE)) { require_once PATH_CLASSES . "/fromdb/accounts.php"; } if (!isset($GLOBALS["accountClass"])) { $GLOBALS["accountClass"] = new fromdb_accounts(); } $record = $GLOBALS["accountClass"]->getSpecialUserRecord($uid); if (!empty($record)) { $au = array("name" => $record["username"], "uid" => $record["id"], "gecos" => functions::utf8encode($record["full_name"])); self::$userAccounts[$uid] = $au; return $au; } // -- Negative UIDs are special UIDs // if (preg_match("/^-\d+/",$uid)) return FALSE; } // -- Then check if $uid is an account on the local machine if ($localAccount = posix_getpwuid((int) $uid)) { $localAccount["gecos"] = functions::utf8encode($localAccount["gecos"]); return $localAccount; } // -- Then optionally check SU accounts via locally kept password files // [probably obsolete] if ($checkSU) { $commonPasswdFile = array("/afs/physto.se/common/uadmin/passwd/su.se/passwd.common", "/afs/kth.se/admin/passwd/passwd.full"); foreach ($commonPasswdFile as $pwfile) { if (file_exists($pwfile) && is_file($pwfile) && ($l = shell_exec("grep '^.*:.*:" . $uid . ":' " . $pwfile))) { $u = split(":", $l); $su = core2posix($u); if (!empty($su["gecos"])) { return $su; } } } } // end if ($checkSU) // -- Did not find a translation for $uid return FALSE; }
function core_getpwnam($login, $appsDB = False) { global $core_commonPW, $classAuth; if (!$login) { return False; } if (!preg_match("/\\w/", $login)) { return False; } if (isset($classAuth) && get_class($classAuth) == 'auth') { list($g, $l, $u) = $classAuth->whoAmI(); if ($l == $login) { $a["name"] = $login; $a["gecos"] = $g; $a["uid"] = $u; core_dbg('core_getpwnam', $login, "uid={$u} {$g} (authenticated login)"); return $a; } } if ($localAccount = posix_getpwnam($login)) { $localAccount["gecos"] = core_utf8_encode($localAccount["gecos"]); core_dbg('core_getpwnam', $login, $localAccount["uid"] . ' (local)'); return $localAccount; } if (get_class($appsDB)) { if (!$_SESSION["core_auth_SQL"]["table"]) { core_db2auth(); } if ($appsDB->tableExists($_SESSION["core_auth_SQL"]["table"])) { $res = $appsDB->query("SELECT * FROM " . $_SESSION["core_auth_SQL"]["table"] . " WHERE " . $_SESSION["core_auth_SQL"]["username"] . "='{$login}'"); if ($row = $appsDB->next_record($res)) { $au["name"] = $row[$_SESSION["core_auth_SQL"]["username"]]; $au["uid"] = $row[$_SESSION["core_auth_SQL"]["id"]]; $au["gecos"] = core_utf8_encode($row[$_SESSION["core_auth_SQL"]["name"]]); core_dbg('core_getpwnam', $uid, $au["gecos"] . ' (sql account)'); return $au; } } core_dbg('core_getpwuid SQL unknown', $uid); } foreach ($core_commonPW as $pwfile) { if (file_exists($pwfile) && is_file($pwfile) && ($l = `grep ^{$login}: {$pwfile}`)) { $u = split(':', $l); $su = core2posix($u); core_dbg('core_getpwnam', $login, "uid={$su['uid']} {$su['gecos']} ({$pwfile})"); if ($su["gecos"]) { return $su; } } } //core_dbg('core_getpwnam',$login,'?????????'); return False; }