From 4b592e1f48edb2654bc732fb2c27a741a5d5479c Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Thu, 12 Aug 2021 21:04:30 +0200 Subject: [PATCH 01/11] Fix regex (#2589) --- .../lib/Lemonldap/NG/Portal/Lib/LDAP.pm | 29 ++++++++++--------- .../Lemonldap/NG/Portal/Plugins/FindUser.pm | 25 +++++++++------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/LDAP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/LDAP.pm index 8258cab35..218ce3b43 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/LDAP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/LDAP.pm @@ -13,7 +13,7 @@ use Lemonldap::NG::Portal::Main::Constants qw( extends 'Lemonldap::NG::Common::Module'; -our $VERSION = '2.0.12'; +our $VERSION = '2.0.13'; # PROPERTIES @@ -76,8 +76,7 @@ has findUserFilter => ( is => 'ro', lazy => 1, builder => sub { - - # $_[0]->conf->{AuthLDAPFilter} || + $_[0]->conf->{AuthLDAPFilter} || $_[0]->conf->{LDAPFilter} || '(&(uid=$user)(objectClass=inetOrgPerson))'; } @@ -180,8 +179,10 @@ sub findUser { $self->validateLdap; return PE_LDAPCONNECTFAILED unless $self->ldap; - $self->findUserFilter =~ /\bobjectClass=(\w+)\b/; - my $filter = "(&(objectClass=$1)"; + my $filter = + $self->findUserFilter =~ /\bobjectClass=(\w+)\b/ + ? "(&(objectClass=$1)" + : '(&'; my $wildcard = $self->conf->{findUserWildcard}; $self->logger->info("LDAP UserDB with wildcard ($wildcard)") if $wildcard; foreach (@$searching) { @@ -199,11 +200,12 @@ sub findUser { $self->bind(); my $mesg = $self->ldap->search( - base => $self->conf->{ldapBase}, - scope => 'sub', - filter => $filter, - deref => $self->conf->{ldapSearchDeref} || 'find', - attrs => $self->attrs, + base => $self->conf->{ldapBase}, + scope => 'sub', + filter => $filter, + deref => $self->conf->{ldapSearchDeref} || 'find', + attrs => $self->attrs, + sizelimit => 50 ); if ( $mesg->code() != 0 ) { @@ -218,9 +220,10 @@ sub findUser { my $rank = int( rand( $mesg->count() ) ); $self->logger->debug("Demo UserDB random rank: $rank"); my $entry = - ( $mesg->entry($rank)->dn() =~ /\b(?:uid|sAMAccountName)=(\w+?)\b/ ) - [0]; - $self->userLogger->info("FindUser: LDAP UserDB returns $entry"); + ( $mesg->entry($rank)->dn() =~ /\b(?:uid|sAMAccountName)\x3d(.+?),/ ) + [0] || ''; + $self->userLogger->info("FindUser: LDAP UserDB returns $entry") + if $entry; $req->data->{findUser} = $entry; return PE_OK; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm index 15b109159..703bfde15 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FindUser.pm @@ -9,7 +9,7 @@ use Lemonldap::NG::Portal::Main::Constants qw( PE_TOKENEXPIRED ); -our $VERSION = '2.0.12'; +our $VERSION = '2.0.13'; extends qw( Lemonldap::NG::Portal::Main::Plugin @@ -32,8 +32,10 @@ sub init { my ($self) = @_; ( my $imp = grep /::Plugins::Impersonation$/, $self->p->enabledPlugins ) ? $self->addUnauthRoute( finduser => 'provideUser', ['POST'] ) - ->addAuthRoute( finduser => 'provideUser', - ['POST'] ) # Allow findUser with reAuth + ->addAuthRoute( + finduser => 'provideUser', + ['POST'] + ) # Allow findUser with reAuth : $self->logger->warn('FindUser plugin enabled without Impersonation'); $self->logger->warn('FindUser plugin enabled without searching attribute') unless keys %{ $self->conf->{findUserSearchingAttributes} }; @@ -87,19 +89,22 @@ sub retreiveFindUserParams { my $regex = '^(?:' . join( '|', keys %values ) . ')$'; my $checked = $select - ? $param =~ /$regex/o - : $param =~ /$self->{conf}->{findUserControl}/o; - push @required, $key if $select && !$null; + ? $param =~ /$regex/ + : $param =~ /$self->{conf}->{findUserControl}/; + push @required, $key unless $null; # For " name="" type="text" autocomplete="off" class="form-control" placeholder="" /> +
+ +
- diff --git a/lemonldap-ng-portal/site/templates/bootstrap/gpgform.tpl b/lemonldap-ng-portal/site/templates/bootstrap/gpgform.tpl index 41ef728d8..188b585d8 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/gpgform.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/gpgform.tpl @@ -37,10 +37,24 @@ + + ?skin=&=&url="> + + Reset my certificate + + + + + + + - ?skin=&=&url="> - - Create an account - + ?skin=&=&url="> + + Create an account + diff --git a/lemonldap-ng-portal/site/templates/bootstrap/login.tpl b/lemonldap-ng-portal/site/templates/bootstrap/login.tpl index 9f86b07ab..a4ce0cca1 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/login.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/login.tpl @@ -218,6 +218,14 @@ + +
+ +
+
diff --git a/lemonldap-ng-portal/site/templates/bootstrap/openidform.tpl b/lemonldap-ng-portal/site/templates/bootstrap/openidform.tpl index a8a15e50e..1ba89a976 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/openidform.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/openidform.tpl @@ -14,3 +14,12 @@ Connect + + +
+ +
+
\ No newline at end of file diff --git a/lemonldap-ng-portal/site/templates/bootstrap/sslform.tpl b/lemonldap-ng-portal/site/templates/bootstrap/sslform.tpl index 34ff09f07..29ae6aac8 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/sslform.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/sslform.tpl @@ -18,3 +18,12 @@ Connect + + +
+ +
+
diff --git a/lemonldap-ng-portal/site/templates/bootstrap/standardform.tpl b/lemonldap-ng-portal/site/templates/bootstrap/standardform.tpl index 63b33056c..3a6256e59 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/standardform.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/standardform.tpl @@ -59,7 +59,7 @@ Reset my certificate - +