-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpamauth.php
71 lines (61 loc) · 1.93 KB
/
pamauth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
//error_reporting( -1 );
//ini_set( 'display_errors', 1 );
/** PWAuth-Driver */
class PWAuth{
private $pwauthPath = '/usr/sbin/pwauth';
/** Performs authentication and returns an array with user data if positive, or false if not
*
* @param string $external_uid
* @param string $external_passwd
*/
public function Authenticate($external_uid, $external_passwd) {
// Start
$handle = popen($this->pwauthPath, 'w');
if($handle === FALSE) {
die("Errore di apertura pwauth");
return false;
}
if(fwrite($handle, "$external_uid\n$external_passwd\n") === FALSE) {
die("Errore di comunicazione con pwauth");
return false;
}
$result = pclose($handle);
if($result==0) {// Login OK
$etcPasswd = file('/etc/passwd');
foreach($etcPasswd as $singleLine) {
if(substr($singleLine, 0, strlen($external_uid ) + 1) == $external_uid.':') {
$explodedLine = explode(':', $singleLine);
$return = array();
$return['user'] = $explodedLine[0];
$return['uid'] = $explodedLine[2];
$return['gid'] = $explodedLine[3];
$return['comment'] = $explodedLine[4];
$return['dir'] = $explodedLine[5];
$return['shell'] = $explodedLine[6];
// GECOS field (comment)
$userData = explode(',', $return['comment']);
$name = $userData[0];
$building = $userData[1];
$phone = $userData[2];
$other = $userData[3];
$return['name'] = $name;
$return['building'] = $building;
$return['phone'] = $phone;
$return['other'] = $other;
return $return;
}
}
}
return false;
}
}
//$pwauth = new PWAuth;
//$login = $pwauth->Authenticate('kodif', 'kodi');
// Test
//$pwauth = new PWAuth;
//$login = $pwauth->Authenticate('user', 'password');
//echo '<pre>';
//print_r($login);
//echo '</pre>';
?>