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;
 }
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
#!/usr/bin/env php
<?php 
if (!extension_loaded('yp')) {
    error_log('yp extension not found');
    exit(1);
}
$opts = getopt('d:');
if (isset($opts['d'])) {
    $domain = $opts['d'];
} else {
    $domain = yp_get_default_domain();
}
if (empty($domain)) {
    error_log('domain should not be empty');
    exit(1);
}
$mapname = array_pop($argv);
if (empty($mapname)) {
    error_log('mapname is empty');
    exit(1);
}
$hosts = listgroup($domain, 'netgroup', $mapname);
echo implode(' ', $hosts) . PHP_EOL;
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) {