|
|
@@ -2,6 +2,41 @@
|
|
|
|
|
|
namespace UserModel;
|
|
|
|
|
|
+function get_user_infos($id) {
|
|
|
+ $ini = parse_ini_file('../includes/config.ini');
|
|
|
+ try {
|
|
|
+ $ldapconn = ldap_connect($ini['hostname'], $ini['port']);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ die ('ERROR: ' . $e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$ldapconn) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ldapbind = @ldap_bind($ldapconn, $ini["binddn"], $ini["bindpw"]);
|
|
|
+ if (!$ldapbind) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check if user can store ssh keys
|
|
|
+ $filter = "(&(uid=" . $id . ")(objectClass=ldapPublicKey))";
|
|
|
+ $attributes = array("ldapPublicKey");
|
|
|
+
|
|
|
+ $res = ldap_search($ldapconn, $ini["basedn"], $filter, $attributes);
|
|
|
+ $info = ldap_get_entries($ldapconn, $res);
|
|
|
+
|
|
|
+ if ($info["count"] > 0) {
|
|
|
+ $ssh_keys = true;
|
|
|
+ } else {
|
|
|
+ $ssh_keys = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return array("SSH_KEYS" => $ssh_keys);
|
|
|
+}
|
|
|
+
|
|
|
function auth($id, $passwd) {
|
|
|
$ini = parse_ini_file('../includes/config.ini');
|
|
|
try {
|
|
|
@@ -13,12 +48,18 @@ function auth($id, $passwd) {
|
|
|
}
|
|
|
|
|
|
if ($ldapconn) {
|
|
|
+
|
|
|
$ldapbind = @ldap_bind($ldapconn, "uid=" . ldap_escape($id) . ',' . $ini["basedn"], $passwd);
|
|
|
- if ($ldapbind) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
+
|
|
|
+ $user_infos = get_user_infos($id);
|
|
|
+ if (!$user_infos) {
|
|
|
+ return array(false, "A problem occured getting your account informations, contact admins");
|
|
|
}
|
|
|
+ if (!$ldapbind) {
|
|
|
+ return array(false, "Wrong username or password");
|
|
|
+ }
|
|
|
+
|
|
|
+ return array(true, $user_infos);
|
|
|
}
|
|
|
}
|
|
|
|