File: chguserpw.php

package info (click to toggle)
lwat 0.17-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 860 kB
  • ctags: 945
  • sloc: php: 3,151; sh: 212; makefile: 148
file content (125 lines) | stat: -rwxr-xr-x 4,302 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
    LWAT, LDAP Webbased Administration Tool
    Copyright (C) 2007  Finn-Arne Johansen <faj@bzz.no>, Bzzware AS, Norway

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once ('functions.php') ;
loadConfig () ; 
require_once ('/etc/lwat/config.php') ;
require('/usr/share/php/smarty/libs/Smarty.class.php') ; 
loadLocale () ; 
ob_start () ; 

$smarty = new Smarty();
$smarty->template_dir = $smarty_templ ; 
$smarty->compile_dir = $smarty_compile ; 

$want= array ("objectClass", "cn", "uid");
if (!($connect = ldap_connect ($ldaphost))) 
    die ("Could not connect to ldap server") ; 
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_start_tls ($connect) ; 

$name=trim($_GET['username']) ; 

if (empty($name))
    $action=readKey('Action') ; 
else 
    $action="searchFor" ; 

switch ($action) {
    case "searchFor":
	if ($bind = ldap_bind ($connect)) { 
	    if (empty ($name)) {
	        $name=readKey ('name') ;
	        $filter="(&(objectClass=posixAccount)" . 
	                "(|(uid=$name*)(cn=$name*)))" ; 
	    } else
	        $filter="(&(objectClass=posixAccount)(uid=$name))" ; 
	    $result= ldap_search ($connect, $base, $filter, $want);
	    $entries = ldap_get_entries ($connect, $result);
	    switch ($entries["count"]) {
		case 0:
		    $smarty->assign('filter', $filter) ; 
		    $smarty->display('chguserpw_none.tpl');
		    break ;
		case 1:
		    $smarty->assign('userdn', $entries[0]['dn']) ; 
		    $smarty->assign('username', $entries[0]['uid'][0]) ; 
		    $smarty->assign('fullname', $entries[0]['cn'][0]) ; 
		    if (in_array("sambaSamAccount", $entries[0]["objectclass"]) === false)
		        $smarty->assign('sambaAccount', 0) ; 
		    else
		        $smarty->assign('sambaAccount', 1) ; 
		    $smarty->display('chguserpw_change.tpl');
		    break ;
		default:
		    for ($i = 1 ; $i < $entries['count']; $i++) {
		        $display[] = $entries[$i]['cn'][0] . "(" . $entries[$i]['uid'][0] . ")" ; 
		        $username[] = $entries[$i]['uid'][0] ; 
		    }
		    $smarty->assign ('display', $display) ; 
		    $smarty->assign ('username', $username) ; 
		    $smarty->display ('chguserpw_select.tpl') ; 
		    break ;
	    }
	}
        break ;
    case "setpw":
	$newpw = readKey('userpw') ; 
	$oldpw = readKey('oldpw') ; 
	$chkpw = readKey('chkpw') ; 
	if (strlen ($newpw) < $minPwLength )
	    printf (_("Sorry. The password is too short") . "<br>" );
	elseif ($newpw <> $chkpw) 
	    printf (_("Sorry. The passwords must be the same") . "<br>" );
	else {
	    $userdn = readKey('userdn') ; 
	    $cryptpw = cryptgen ($newpw); 
	    $sambahash = new smbHash ; 
	    $info = array ();
	    $info["userPassword"][] = $cryptpw ;
	    if (readkey("sambaAccount") == 1) {
	        $info["sambaLMPassword"][] = $sambahash->lmhash($newpw) ; 
	        $info["sambaNTPassword"][] = $sambahash->nthash($newpw);
            }
	    if ($bind = ldap_bind ($connect)) {
		$result= ldap_search ($connect, $base, $filter, $want);
		$entries = ldap_get_entries ($connect, $result);
		if ($entries[count] == 1) {
		    $entry = $entries[0];
		    $admindn = $entry["dn"];
		}
		$bind = ldap_bind ($connect,$userdn,$oldpw) ;
	    }
	    if (! $bind)
		printf (_("Sorry. I'm not able to connect as  %s.") . "<br>" , $userdn );
	    else {
		$result = ldap_modify ($connect,$userdn,$info) ;
		if ($result)
		    printf (_("Changed password for  %s") . "<br>" , $userdn);
		else
		    printf (_("Failed to change password for  %s.") . "<br>" ,$userdn);
	    }
	}
	break ;
    default:
        $smarty->display('chguserpw_search.tpl');
	break ;
}
    ldap_close ($connect) ; 
?>