Index: branches/2.2.0.1/setup/manageheader.php
===================================================================
--- branches/2.2.0.1/setup/manageheader.php	(revision 3304)
+++ branches/2.2.0.1/setup/manageheader.php	(revision 3991)
@@ -596,4 +596,5 @@
 					$setup_tpl->set_var('use_https_0',' checked');
 					$setup_tpl->set_var('div_cert',' style="display:none" ');
+                                        $setup_tpl->set_var('div_atributo_cpf',' style="display:none" ');
                                         $setup_tpl->set_var('div_criptox',' style="display:none" ');
 					
@@ -614,4 +615,5 @@
 				default:
 					$setup_tpl->set_var('certificado_0',' checked');
+                                        $setup_tpl->set_var('div_atributo_cpf',' style="display:none" ');
 					$setup_tpl->set_var('div_cripto',' style="display:none" ');
                                         $setup_tpl->set_var('div_criptox',' style="display:none" ');
@@ -623,5 +625,10 @@
 					break;
 			}
-			
+
+			if($GLOBALS['phpgw_info']['server']['certificado_atributo_cpf'])
+			{
+				$setup_tpl->set_var('certificado_atributo_cpf',$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']);
+			}
+
 			switch($GLOBALS['phpgw_info']['server']['captcha'])
 			{
Index: branches/2.2.0.1/setup/templates/default/manageheader.tpl
===================================================================
--- branches/2.2.0.1/setup/templates/default/manageheader.tpl	(revision 3304)
+++ branches/2.2.0.1/setup/templates/default/manageheader.tpl	(revision 3991)
@@ -22,7 +22,11 @@
 		document.getElementById('cert_0').checked = true;
 	}
+	if(xdiv.id == "criptografiax") {
+		document.getElementById("atributo_cpf").style.display='none';
+	}
 	if( xdiv.id == "certificado" || xdiv.id == "criptografia") {
 		var xdiv = document.getElementById('criptografia');
 		document.getElementById('cripto_0').checked = true;
+                document.getElementById("atributo_cpf").style.display='none';
 	}
 	if(xdiv.id == "certificado" || xdiv.id == "criptografia" ) {
@@ -41,4 +45,7 @@
   {
 	var xdiv = document.getElementById(zdiv);
+	if(zdiv == "criptografiax") {
+		document.getElementById("atributo_cpf").style.display='';
+	}
 	if(xdiv.id == "cripto_options") {
 		document.getElementById('maxcerttxt').value = '10';
@@ -183,8 +190,12 @@
 	<tr><td colspan="2"><b>Usar Certificado Digital (para identificar o usuario no processo de login)?</b></td></tr>
   	<tr><td colspan="2">
-	          <font color='red'>Obs.: Para habilitar este item o uso do HTTPS deve ter sido habilitado.</font><br>
+	        <font color='red'>Obs.: Para habilitar este item o uso do HTTPS deve ter sido habilitado.</font><br>
 		<INPUT id="cert_0" type="radio" {certificado_0} name="setting[certificado]" onclick="javascript:ocultar('criptografiax')" value="0" >N&Atilde;O Usar Certificado Digital.<BR>
 		
 		<INPUT id="cert_1" type="radio" {certificado_1} name="setting[certificado]" onclick="javascript:exibir('criptografiax')" value="1">Usar Certificado Digital.<BR>
+               <div id="atributo_cpf" {div_atributo_cpf}>
+                <b>Nome do atributo , no ldap, para identificar CPF do proprietario do certificado digital</b><BR>
+                <INPUT type="text" maxlength="50" size="40" name="setting[certificado_atributo_cpf]" id="certificado_atributo_cpf" value="{certificado_atributo_cpf}" ><BR>
+               </div>
   	</td></tr>
 	</table>
Index: branches/2.2.0.1/preferences/handlecertificate.php
===================================================================
--- branches/2.2.0.1/preferences/handlecertificate.php	(revision 3991)
+++ branches/2.2.0.1/preferences/handlecertificate.php	(revision 3991)
@@ -0,0 +1,203 @@
+<?php
+$GLOBALS['phpgw_info']['flags'] = array(
+        'noheader'   => True,
+        'nonavbar'   => True,
+        'currentapp' => 'preferences'
+);
+if(file_exists('../header.inc.php'))
+    {
+        include('../header.inc.php');
+    }
+else
+    {
+        echo '1'.chr(0x0D).chr(0x0A).lang('Error. header.inc.php not found');
+        exit();
+    }
+if($_POST['certificado'])
+    {
+        require_once('../security/classes/CertificadoB.php');
+        require_once('../security/classes/Verifica_Certificado.php');
+        include('../security/classes/Verifica_Certificado_conf.php');
+        $cert =str_replace(chr(0x0A).chr(0x0A),chr(0x0A),$_POST['certificado']);
+        $cert = troca_espaco_por_mais($cert);
+        $c = new certificadoB();
+        $c->certificado($cert);
+        if (!$c->apresentado)
+            {
+               echo '2'.chr(0x0D).chr(0x0A).lang('Fail to get certificate');
+               exit();
+            }
+        $b = new Verifica_Certificado($c->dados,$cert);
+        // Testa se Certificado OK.
+        if(!$b->status)
+            {
+               $msg = '3'.chr(0x0D).chr(0x0A).$b->msgerro;
+               foreach($b->erros_ssl  as $linha)
+                   {
+                        $msg .= "\n" . $linha;
+                   }
+               echo $msg;
+               exit();
+            }
+        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
+                (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
+                (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
+            {
+                $ds = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
+                $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
+                $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
+            }
+        else
+            {
+                $ds = $GLOBALS['phpgw']->common->ldapConnect();
+            }
+        if (!$ds)
+             {
+                echo '4'.chr(0x0D).chr(0x0A).lang('Failure when get user data to login');
+                exit();
+             }
+        $cert_atrib_cpf = isset($GLOBALS['phpgw_info']['server']['certificado_atributo_cpf'])&&$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']!=''?$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']:"uid";
+        // CPF he valor obrigatório no certificado ICP-BRASIL.
+        $filtro = $cert_atrib_cpf .'='. $c->dados['2.16.76.1.3.1']['CPF'];
+        $atributos = array();
+        if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']) && $GLOBALS['phpgw_info']['server']['atributoexpiracao'])
+            {
+                $atributos[] = $GLOBALS['phpgw_info']['server']['atributoexpiracao'];
+            }
+        else
+            {
+                $atributos[] = 'phpgwlastpasswdchange';
+            }
+         $atributos[] = "userCertificate";
+         $atributos[] = "uid";
+        $sr=ldap_search($ds, $GLOBALS['phpgw_info']['server']['ldap_context'],$filtro,$atributos);
+        // Pega resultado ....
+        $info = ldap_get_entries($ds, $sr);
+        // Tem de achar só uma entrada.....ao menos uma....
+        if($info["count"]!=1)
+            {
+                echo '5'.chr(0x0D).chr(0x0A).lang('Invalid data from users directory').'('.$cert_atrib_cpf.' = ' . $c->dados['2.16.76.1.3.1']['CPF'] . ')';
+                ldap_close($ds);
+                exit();
+            }
+        if($info[0]["userCertificate"][0] && $cert == $info[0]["userCertificate"][0] )
+            {
+                //echo '0'.chr(0x0D).chr(0x0A).$info[0]["uid"][0].chr(0x0D).chr(0x0A).$info[0]["cryptpassword"][0];
+                echo '6'.chr(0x0D).chr(0x0A).lang('Certificate already registered');
+                ldap_close($ds);
+                exit();
+            }
+        $user_info = array();
+        $aux1 = $info[0]["dn"];
+        $user_info['userCertificate'] = $cert;
+        if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']) && $GLOBALS['phpgw_info']['server']['atributoexpiracao'])
+            {
+                if(substr($info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0],-1,1)=="Z")
+                    {
+                        $user_info[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = '19800101000000Z';
+                    }
+                else
+                    {
+                        $user_info[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = '0';
+                    }
+            }
+        else
+            {
+                $user_info['phpgwlastpasswdchange'] = '0';
+            }
+        if(!ldap_modify($ds,$aux1,$user_info))
+            {
+                echo '7'.chr(0x0D).chr(0x0A).lang('Error in Certificate registration'). '  -  ' . $aux1;
+            }
+        else
+            {
+                echo '0'.chr(0x0D).chr(0x0A).lang('To conclude your Certificate registration change your password');
+            }
+        ldap_close($ds);
+        exit();
+    }
+else
+    {
+        $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Digital Certificate Registration');
+        $GLOBALS['phpgw']->common->phpgw_header();
+        echo parse_navbar();
+        if ($GLOBALS['phpgw_info']['server']['certificado']==1)
+            {
+                    $var_tokens = '';
+                    for($ii = 1; $ii < 11; $ii++)
+                    {
+                            if($GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'])
+                                    $var_tokens .= $GLOBALS['phpgw_info']['server']['test_token' . $ii . '1'] . ',';
+                    }
+                    if(!$var_tokens)
+                    {
+                            $var_tokens = 'ePass2000Lx;/usr/lib/libepsng_p11.so,ePass2000Win;c:/windows/system32/ngp11v211.dll';
+                    }
+                    $param1 = "
+                                                                                            '<param name=\"token\" value=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\"> ' +
+                                                                                       ";
+                    $param2 = "
+                                                                                            'token=\"" . substr($var_tokens,0,strlen($var_tokens)) . "\" ' +
+                                                                                       ";
+                    $cod_applet =
+        /*    // com debug ativado
+                '<script type="text/javascript">
+                                            if (navigator.userAgent.match(\'MSIE\')){
+                                                    document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
+                                                    \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
+                                                    \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
+                                                    \'<param name="code" value="LoginApplet.class"> \' +
+                                                    \'<param name="locale" value="' . $lang . '"> \' +
+                                                    \'<param name="mayscript" value="true"> \' + '
+                                                    . $param1
+                                                    . ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
+                            \'<param name="debug" value="true"> \' +
+                                                    \'</object>\');
+                                            }
+                                            else {
+                                                    document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" code="LoginApplet.class" locale="' . $lang . '"\' +
+                                                    \'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
+                                                    . $param2
+                                                    . ' \'type="application/x-java-applet;version=1.5" debug= "true" mayscript > \' +
+                                                    \'<noembed> \' +
+                                                    \'No Java Support. \' +
+                                                    \'</noembed> \' +
+                                                    \'</embed> \');
+                                            }
+                                    </script>';
+        */
+                // sem debug ativado
+                '<script type="text/javascript">
+                                            if (navigator.userAgent.match(\'MSIE\')){
+                                                    document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
+                                                    \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
+                                                    \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
+                                                    \'<param name="codebase" value="/security/">\' +
+                                                    \'<param name="code" value="LoginApplet.class"> \' +
+                                                    \'<param name="locale" value="' . $lang . '"> \' +
+                                                    \'<param name="mayscript" value="true"> \' + '
+                                                    . $param1
+                                                    . ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
+                                                    \'</object>\');
+                                            }
+                                            else {
+                                                    document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $lang . '"\' +
+                                                    \'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
+                                                    . $param2
+                                                    . ' \'type="application/x-java-applet;version=1.5" mayscript > \' +
+                                                    \'<noembed> \' +
+                                                    \'No Java Support. \' +
+                                                    \'</noembed> \' +
+                                                    \'</embed> \');
+                                            }
+                                    </script>';
+                  echo $cod_applet;
+                  echo '<form method="POST" action="preferences" >';
+                  echo '<BR/><BR/><BR/>';
+                  echo '<div align="center"><h2>'.lang('Getting your Certificate').'</h2>';
+                  echo '<h2><img style="border:0px;margin:31px 0px 58px 0px;" src="../phpgwapi/templates/default/images/acao.gif" /></h2>';
+                  echo '<input type="submit" name="cancel" value="' . lang('cancel') . '" ></div>';
+                  $GLOBALS['phpgw']->common->phpgw_footer();
+        }
+    }
+?>
Index: branches/2.2.0.1/preferences/inc/hook_preferences.inc.php
===================================================================
--- branches/2.2.0.1/preferences/inc/hook_preferences.inc.php	(revision 2)
+++ branches/2.2.0.1/preferences/inc/hook_preferences.inc.php	(revision 3991)
@@ -16,4 +16,11 @@
 		$file['Change your Password'] = $GLOBALS['phpgw']->link('/preferences/changepassword.php');
 	}
+        if (isset($GLOBALS['phpgw_info']['server']['certificado']))
+            {
+                if ($GLOBALS['phpgw_info']['server']['certificado'])
+                {
+                        $file['Register Digital Certificate'] = $GLOBALS['phpgw']->link('/preferences/handlecertificate.php');
+                }
+            }
 	$file['change your settings'] = $GLOBALS['phpgw']->link('/preferences/preferences.php','appname=preferences');
 	
Index: branches/2.2.0.1/security/classes/funcoes_auxiliares.php
===================================================================
--- branches/2.2.0.1/security/classes/funcoes_auxiliares.php	(revision 3563)
+++ branches/2.2.0.1/security/classes/funcoes_auxiliares.php	(revision 3991)
@@ -151,5 +151,14 @@
 	}
 
-
+        function troca_espaco_por_mais($pem_data)
+        {
+            $begin = "CERTIFICATE-----";
+            $end   = "-----END";
+            $aux = substr($pem_data, strpos($pem_data, $begin)+strlen($begin));
+            $aux = substr($aux, 0, strpos($aux, $end));
+            $aux = strtr($aux,' ','+');
+            $aux = '-----BEGIN CERTIFICATE-----'.$aux.'-----END CERTIFICATE-----';
+            return $aux;
+        }
        	function verificaopenssl()
 	{
Index: branches/2.2.0.1/security/vercert.php
===================================================================
--- branches/2.2.0.1/security/vercert.php	(revision 3232)
+++ branches/2.2.0.1/security/vercert.php	(revision 3991)
@@ -1,95 +1,3 @@
 <?php
-function item_para_uid($dados_do_certificado)
-	{
-/*
-// Exemplo do Array $dados_do_certificado padrao ICP-BRASIL
-// O conteudo do array pode variar conforme a AC emissora.
-Array
-(
-    [SERIALNUMBER] => 2009031816232802
-    [EMISSOR_CAMINHO_COMPLETO] => Array
-        (
-            [C] => BR
-            [O] => ICP-Brasil
-            [OU] => CSPB-1
-            [CN] => HOMAutoridade Certificadora do SERPRO Final v2
-        )
-
-    [EMISSOR] => HOMAutoridade Certificadora do SERPRO Final v2
-    [INICIO_VALIDADE] => 20090318205216
-    [FIM_VALIDADE] => 20120317205216
-    [EXPIRADO] =>
-    [SUBJECT] => Array
-        (
-            [C] => BR
-            [O] => ICP-Brasil
-            [OU] => Pessoa Fisica A3
-            [CN] => CESAR VIANNA
-        )
-
-    [NOME] => CESAR VIANNA
-    [AUTHORITYKEYIDENTIFIER] => AE34F397BB05B1AA6CC3FD6C4F0E9129BBB61BE2
-    [KEYUSAGE] => Array
-        (
-            [digitalSignature] => 1
-            [nonRepudiation] => 1
-            [keyEncipherment] => 1
-        )
-
-    [EXTKEYUSAGE] => Array
-        (
-            [clientAuth] => 1.3.6.1.5.5.7.3.2
-            [emailProtection] => 1.3.6.1.5.5.7.3.4
-        )
-
-    [CA] =>
-    [CRLDISTRIBUTIONPOINTS] => Array
-        (
-            [0] => http://ccdhom.serpro.gov.br/lcr/serproacfv2.crl
-            [1] => http://ccdhom.serpro.gov.br/lcr/serproacfv3.crl
-            [2] => http://ccdhom.serpro.gov.br/lcr/serproacfv4.crl
-        )
-
-    [2.16.76.1.3.6] => Array
-        (
-            [CADINSS] => 000000000000
-        )
-
-    [CADINSS] => 000000000000
-    [2.16.76.1.3.5] => Array
-        (
-            [TITULO] => 000000000000
-            [ZONA] => 000
-            [SECAO] => 0000
-            [TITULO_CIDADE_UF] =>
-        )
-
-    [TITULO] => 000000000000
-    [ZONA] => 000
-    [SECAO] => 0000
-    [TITULO_CIDADE_UF] =>
-    [2.16.76.1.3.1] => Array
-        (
-            [NASCIMENTO] => 19081981
-            [CPF] => 12345678902
-            [NIS] => 12345678901
-            [RG] => 000201075150953
-            [ORGAOUF] => SSPRS
-        )
-
-    [NASCIMENTO] => 19081981
-    [CPF] =>  12345678902
-    [NIS] => 12345678901
-    [RG] => 000201075150953
-    [ORGAOUF] => SSPRS
-    [EMAIL] => cesar.vianna@pr.planalto.gov.br
-)
-*/
-
-		// Retorna o CPF para usar como uid.
-		return $dados_do_certificado['2.16.76.1.3.1']['CPF'];
-	}
-
-
 $GLOBALS['phpgw_info']['flags'] = array(
 		'disable_Template_class' => True,
@@ -98,126 +6,79 @@
 		'noheader'               => True
 	);
-
-if(!$_REQUEST['certificado'])
-{
-   echo '2'.chr(0x0D).chr(0x0A).'Certificado não foi apresentado.';
-   exit();
-}
-
 if(file_exists('../header.inc.php'))
-	{
-		include('../header.inc.php');
-	}
+    {
+        include('../header.inc.php');
+    }
 else
-	{
-	        echo '1'.chr(0x0D).chr(0x0A).'Arquivo header.inc.php n&atilde;o foi localizado.';
-		exit();
-	}
-
+    {
+        echo '1'.chr(0x0D).chr(0x0A).lang('Error. header.inc.php not found');
+        exit();
+    }
+if(!$_POST['certificado'])
+    {
+        echo '2'.chr(0x0D).chr(0x0A).lang('Fail to get certificate');
+        exit();
+    }
 require_once('classes/CertificadoB.php');
 require_once('classes/Verifica_Certificado.php');
 include('classes/Verifica_Certificado_conf.php');
-
-  # Transforma o certificado do formato PEM para o formato DER ...
-  function troca_espaco_por_mais($pem_data)
-  {
-    $begin = "CERTIFICATE-----";
-    $end   = "-----END";
-    $aux = substr($pem_data, strpos($pem_data, $begin)+strlen($begin));
-    $aux = substr($aux, 0, strpos($aux, $end));
-    $aux = strtr($aux,' ','+');
-    $aux = '-----BEGIN CERTIFICATE-----'.$aux.'-----END CERTIFICATE-----';
-    return $aux;
-  }
-
-$cert =str_replace(chr(0x0A).chr(0x0A),chr(0x0A),$_REQUEST['certificado']);
+$cert =str_replace(chr(0x0A).chr(0x0A),chr(0x0A),$_POST['certificado']);
 $cert = troca_espaco_por_mais($cert);
-
 $c = new certificadoB();
 $c->certificado($cert);
-
 if (!$c->apresentado)
-{
-   echo '2'.chr(0x0D).chr(0x0A).'Certificado não foi apresentado.';
-   exit();
-}
-
-if (!$c->dados['CPF'])
-{
-   echo '2'.chr(0x0D).chr(0x0A).'Não foi possível obter o CPF do certificado apresentado.';
-   exit();
-}
-
+    {
+       echo '3'.chr(0x0D).chr(0x0A).lang('Fail to get certificate');
+       exit();
+    }
 $b = new Verifica_Certificado($c->dados,$cert);
-
-// Testa se Certificado OK.
 if(!$b->status)
-{
-   $msg = '3'.chr(0x0D).chr(0x0A).$b->msgerro;
-
-   foreach($b->erros_ssl  as $linha)
-   {
-	$msg .= "\n" . $linha;
-   }
-
-   echo $msg;
-   exit();
-}
-
+    {
+       $msg = '4'.chr(0x0D).chr(0x0A).$b->msgerro;
+       foreach($b->erros_ssl  as $linha)
+           {
+                $msg .= "\n" . $linha;
+           }
+       echo $msg;
+       exit();
+    }
 if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
-	            (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
-	            (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
-        {
-                $ds = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
-			$GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
-			$GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
-        }
+        (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
+	(!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
+    {
+        $ds = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
+        $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
+        $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
+    }
 else
-        {
-                $ds = $GLOBALS['phpgw']->common->ldapConnect();
-        }
-
+    {
+        $ds = $GLOBALS['phpgw']->common->ldapConnect();
+    }
 if (!$ds)
      {
-	echo '8'.chr(0x0D).chr(0x0A).'Não foi possível obter dados do usuario para login.';
+	echo '5'.chr(0x0D).chr(0x0A).lang('Failure when get user data to login');
 	exit();
      }
-     
-    $filtro = 'uid='. item_para_uid($c->dados);
-    $atributos = array();
-    //$atributos[] = 'phpgwaccountexpires';
-    $atributos[] = 'phpgwlastpasswdchange';
-
-    if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
-		{
-		    $atributos[] = $GLOBALS['phpgw_info']['server']['atributoexpiracao'];
-		}
-
-     $atributos[] = "usercertificate";
-     $atributos[] = "phpgwaccountstatus";
-     $atributos[] = "cryptpassword";
-     $atributos[] = "uid";
-
-    $sr=ldap_search($ds, $GLOBALS['phpgw_info']['server']['ldap_context'],$filtro,$atributos);
-
-    // Pega resultado ....
-    $info = ldap_get_entries($ds, $sr);
-
-    // Tem de achar só uma entrada.....ao menos uma....
-    if($info["count"]!=1)
+$cert_atrib_cpf = isset($GLOBALS['phpgw_info']['server']['certificado_atributo_cpf'])&&$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']!=''?$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']:"uid";
+$filtro = $cert_atrib_cpf .'='. $c->dados['2.16.76.1.3.1']['CPF'];
+$atributos = array();
+$atributos[] = "usercertificate";
+$atributos[] = "phpgwaccountstatus";
+$atributos[] = "cryptpassword";
+$atributos[] = "uid";
+$sr=ldap_search($ds, $GLOBALS['phpgw_info']['server']['ldap_context'],$filtro,$atributos);
+$info = ldap_get_entries($ds, $sr);
+if($info["count"]!=1)
+{
+    echo '6'.chr(0x0D).chr(0x0A).lang('Invalid data from users directory');
+    ldap_close($ds);
+    exit();
+}
+if($info[0]['phpgwaccountstatus'][0]!='A')
     {
-	echo '4'.chr(0x0D).chr(0x0A).'Dados inválidos no diretório de usuários';
+	echo '7'.chr(0x0D).chr(0x0A).lang('User account is inactive in Expresso');
 	ldap_close($ds);
 	exit();
     }
-
-// A conta expresso tem de estar ativa....
-if($info[0]['phpgwaccountstatus'][0]!='A')
-    {
-	echo '5'.chr(0x0D).chr(0x0A).'Conta do usuario nao esta ativa no Expresso.';
-	ldap_close($ds);
-	exit();
-    }
-
 if($info[0]["cryptpassword"][0] && $info[0]["usercertificate"][0] && $cert == $info[0]["usercertificate"][0] )
     {
@@ -226,38 +87,5 @@
 else
     {
-        if(!$info[0]["usercertificate"][0] || $cert != $info[0]["usercertificate"][0])
-		{
-			$user_info = array();
-			$aux1 = $info[0]["dn"];
-			$user_info['usercertificate'] = $cert;
-			if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao']))
-				{
-					if(substr($info[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0],-1,1)=="Z")
-						{
-							$user_info[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = '19800101000000Z';
-						}
-					else
-						{
-							$user_info[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = '0';
-						}
-				}
-			else
-				{
-                                        $user_info['phpgwlastpasswdchange'] = '0';
-				}
-
-			if(!ldap_modify($ds,$aux1,$user_info))
-                            {
-                                echo '7'.chr(0x0D).chr(0x0A).'Ocorreu um erro no acolhimento do certificado.',$aux1;
-                            }
-                        else
-                            {
-                                echo '6'.chr(0x0D).chr(0x0A).'Seu Certificado foi cadastrado. Sua senha foi expirada. Altere sua senha para concluir o processo.';
-                            }
-		}
-	else
-		{
-			echo '6'.chr(0x0D).chr(0x0A).'Sua senha foi expirada. Altere sua senha para acessar o Expresso usando certificado digital.';
-		}
+        echo '8'.chr(0x0D).chr(0x0A).lang('The current certificate not registered to login');
     }
 ldap_close($ds);
