From 384eabdff355b835bf937e1814e6c54a2303b3c7 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Fri, 28 Oct 2011 14:30:55 +1300 Subject: [PATCH] Allow LDAP sync to work if the date is reasonable and no 'format_updated' is set. --- inc/drivers_ldap.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index a044e9ba..c769ca97 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -542,13 +542,21 @@ function sync_LDAP(){ $valid = $ldap_users_info[$username]; $ldap_timestamp = $valid[$mapping['modified']]; - /** - * This splits the LDAP timestamp apart and assigns values to $Y $m $d $H $M and $S - */ - foreach($c->authenticate_hook['config']['format_updated'] as $k => $v) - $$k = substr($ldap_timestamp,$v[0],$v[1]); - $ldap_timestamp = $Y.$m.$d.$H.$M.$S; - $valid[$mapping['modified']] = "$Y-$m-$d $H:$M:$S"; + if ( !empty($c->authenticate_hook['config']['format_updated']) ) { + /** + * This splits the LDAP timestamp apart and assigns values to $Y $m $d $H $M and $S + */ + foreach($c->authenticate_hook['config']['format_updated'] as $k => $v) + $$k = substr($ldap_timestamp,$v[0],$v[1]); + $ldap_timestamp = $Y.$m.$d.$H.$M.$S; + } + else if ( preg_match('{^(\d{8})(\d{6})(Z)?$', $ldap_timestamp, $matches ) { + $ldap_timestamp = $matches[1].'T'.$matches[2].$matches[3] + } + else if ( empty($ldap_timestamp) ) { + $ldap_timestamp = date('c'); + } + $valid[$mapping['modified']] = $ldap_timestamp; sync_user_from_LDAP( $principal, $mapping, $valid ); }