source: branches/2.2/preferences/changepassword.php @ 3279

Revision 3279, 5.0 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1299 - Corrige a gravação da senha criptografada com certificado digital no LDAP.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * phpGroupWare - preferences                                               *
4        * http://www.phpgroupware.org                                              *
5        * Written by Joseph Engo <jengo@phpgroupware.org>                          *
6        * --------------------------------------------                             *
7        *  This program is free software; you can redistribute it and/or modify it *
8        *  under the terms of the GNU General Public License as published by the   *
9        *  Free Software Foundation; either version 2 of the License, or (at your  *
10        *  option) any later version.                                              *
11        \**************************************************************************/
12
13
14        $GLOBALS['phpgw_info']['flags'] = array(
15                'noheader'   => True,
16                'nonavbar'   => True,
17                'currentapp' => 'preferences'
18        );
19
20        include('../header.inc.php');
21
22/*
23function path_template_include($app,$prefix)
24    {
25        $file_include = PHPGW_SERVER_ROOT . '/' . $app . '/templates/' . $GLOBALS['phpgw_info']['login_template_set'] . '/' . $prefix . '_' . $GLOBALS['phpgw_info']['login_template_set'] . '.php';
26
27        if(!$file_include || !file_exists($file_include))
28            {
29                $file_include = PHPGW_SERVER_ROOT . '/' . $app . '/templates/default/' . $prefix .'_default.php';
30            }
31
32        return $file_include;
33    }
34*/
35
36function grava_senha_criptografada_com_certificado_no_ldap($aux_uid,$aux_senha)
37   {
38        require_once('/var/www/expresso/security/classes/CertificadoB.php');
39        $ldap_context = $GLOBALS['phpgw_info']['server']['ldap_context'];
40        $ldap_servidor = $GLOBALS['phpgw_info']['server']['ldap_host'];
41        $ldap_dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
42        $ldap_passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
43
44        $cc=ldap_connect($ldap_servidor);
45
46        if($GLOBALS['phpgw_info']['server']['ldap_version3'])
47        {
48                ldap_set_option($cc, LDAP_OPT_PROTOCOL_VERSION, 3);
49        }
50
51        //  bind ..
52        $sr=ldap_bind($cc,$ldap_dn,$ldap_passwd);
53
54        $filtro = 'uidNumber='.$aux_uid;
55
56        // Pesquisa uidNumber no LDAP
57        $sr=ldap_search($cc, $ldap_context,$filtro);
58
59        // Pega resultado ....
60        $info = ldap_get_entries($cc, $sr);
61
62        // Tem de achar só uma entrada.....ao menos uma....
63        if($info["count"]!=1)
64            {        if($GLOBALS['phpgw_info']['server']['ldap_version3'])
65        {
66                ldap_set_option($cc, LDAP_OPT_PROTOCOL_VERSION, 3);
67        }
68                ldap_close($cc);
69                return false;
70            }
71
72        if(!$info[0]["usercertificate"][0])
73            {
74                //Usuario sem certificado cadastrado
75                ldap_close($cc);
76                return false;
77            }
78
79        $a = new certificadoB();
80        $R = $a->encriptar_senha($aux_senha,$info[0]["usercertificate"][0]);
81        if(!$R)
82            {
83                return false;
84            }
85        $user_info = array();
86        $aux1 = $info[0]["dn"];
87        $user_info['cryptpassword'] = $R;
88        ldap_modify($cc,$aux1,$user_info);
89
90        ldap_close($cc);
91
92        return true;
93   }
94        $a_passwd   = $_POST['a_passwd'];
95        $n_passwd   = $_POST['n_passwd'];
96        $n_passwd_2 = $_POST['n_passwd_2'];
97
98        if(!$GLOBALS['phpgw']->acl->check('changepassword', 1) || $_POST['cancel'])
99        {
100                if(($GLOBALS['phpgw_info']['user']['lastpasswd_change'] == '0') && (!$_POST['cancel']))
101                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=6'));
102
103                if ($GLOBALS['phpgw_info']['server']['use_https'] == 1)
104                        Header('Location: http://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . '/preferences/index.php');
105                else
106                        $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
107
108                $GLOBALS['phpgw']->common->phpgw_exit();
109        }
110
111        $GLOBALS['phpgw']->template->set_file(array(
112                'form' => 'changepassword.tpl'
113        ));
114        $GLOBALS['phpgw']->template->set_var('lang_enter_actual_password',lang('Enter your actual password'));
115        $GLOBALS['phpgw']->template->set_var('lang_enter_password',lang('Enter your new password'));
116        $GLOBALS['phpgw']->template->set_var('lang_reenter_password',lang('Re-enter your password'));
117        $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change'));
118        $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
119        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepassword.php'));
120
121        if ($_GET['cd'] == 1)
122        {
123                $lang1 = lang('Your password has expired');
124                $lang2 = lang('You must register a new password');
125                $GLOBALS['phpgw']->template->set_var('messages',"<font color=red><h1>$lang1.<br>$lang2.</h1></font>");
126        }
127
128        if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap')
129        {
130                $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature does *not* change your email password. This will '
131                        . 'need to be done manually.'));
132        }
133
134        if ($_POST['change'])
135            {
136                include(personalize_include_path('preferences','changepassword'));
137            }
138        else
139        {
140                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your password');
141                $GLOBALS['phpgw']->common->phpgw_header();
142                echo parse_navbar();
143
144                $GLOBALS['phpgw']->template->pfp('out','form');
145                $GLOBALS['phpgw']->common->phpgw_footer();
146        }
147?>
Note: See TracBrowser for help on using the repository browser.