function listgroup($domain, $mapname, $key) { $hosts = array(); $match_result = yp_match($domain, $mapname, $key); if (empty($match_result)) { return array(); } foreach (explode(' ', $match_result) as $match_item) { $match_item = trim($match_item); if (empty($match_item)) { continue; } $all_matches = array(); if (preg_match_all('/\\(.*\\)/U', $match_item, $all_matches, PREG_OFFSET_CAPTURE)) { foreach ($all_matches[0] as $match_capture) { list($host_line, $offset) = $match_capture; $host_line = substr($host_line, 1, -1); list($host, , ) = explode(',', $host_line); if (empty($host)) { continue; } $hosts[] = $host; } } else { $hosts = array_merge($hosts, listgroup($domain, $mapname, $match_item)); } } return array_unique($hosts); }
function authenticate($username, $passwd) { $domain = yp_get_default_domain(); if (!empty($GLOBALS['phpgw_info']['server']['nis_domain'])) { $domain = $GLOBALS['phpgw_info']['server']['nis_domain']; } $map = "passwd.byname"; if (!empty($GLOBALS['phpgw_info']['server']['nis_map'])) { $map = $GLOBALS['phpgw_info']['server']['nis_map']; } $entry = yp_match($domain, $map, $username); /* * we assume that the map is structured in the usual * unix passwd flavor */ $entry_array = explode(':', $entry); $stored_passwd = $entry_array[1]; $encrypted_passwd = crypt($passwd, $stored_passwd); return $encrypted_passwd == $stored_passwd; }
function user_valid_login($login, $password) { global $error, $user_external_group, $user_external_email; $ret = false; $data = @yp_match(yp_get_default_domain(), "passwd.byname", $login); if (strlen($data)) { $data = explode(":", $data); if ($user_external_group && $user_external_group != $data[3]) { $error = translate("Invalid login"); return $ret; } if ($data[1] == crypt($password, substr($data[1], 0, 2))) { if (count($data) >= 4) { $ret = true; // Check for user in webcal_user. // If in NIS and not in DB, then insert... $sql = "SELECT cal_login FROM webcal_user WHERE cal_login = '******'"; $res = dbi_query($sql); if (!$res || !dbi_fetch_row($res)) { // insert user $uname = explode(" ", $data[4]); $ufirstname = $uname[0]; $ulastname = $uname[count($uname) - 1]; $sql = "INSERT INTO webcal_user " . "( cal_login, cal_lastname, cal_firstname, " . "cal_is_admin, cal_email ) " . "VALUES ( '{$login}', '{$ulastname}', '{$ufirstname}', " . "'N', '{$login}" . "@" . "{$user_external_email}')"; if (!dbi_query($sql)) { $error = translate("Database error") . ": " . dbi_error(); $ret = false; } } } else { $error = translate("Invalid login") . ": " . translate("incorrect password"); $ret = false; } } } else { // no such user $error = translate("Invalid login") . ": " . translate("no such user"); $ret = false; } return $ret; }
function user_valid_login($login, $password) { global $error, $user_external_group, $user_external_email; $ret = false; $data = @yp_match(yp_get_default_domain(), 'passwd.byname', $login); if (strlen($data)) { $data = explode(':', $data); if ($user_external_group && $user_external_group != $data[3]) { $error = translate('Invalid login'); return $ret; } if ($data[1] == crypt($password, substr($data[1], 0, CRYPT_SALT_LENGTH))) { if (count($data) >= 4) { $ret = true; // Check for user in webcal_user. // If in NIS and not in DB, then insert... $sql = 'SELECT cal_login FROM webcal_user WHERE cal_login = ?'; $res = dbi_execute($sql, array($login)); if (!$res || !dbi_fetch_row($res)) { // insert user into webcal_user $uname = explode(' ', $data[4]); $ufirstname = $uname[0]; $ulastname = $uname[count($uname) - 1]; user_add_user($login, $password, $ufirstname, $ulastname, $login . '@' . $user_external_email, 'N'); } else { //refresh their password in webcal_user user_update_user_password($login, $password); } } else { $error = translate('Invalid login') . ': ' . translate('incorrect password'); $ret = false; } } } else { // no such user $error = translate('Invalid login') . ': ' . translate('no such user'); $ret = false; } return $ret; }