fix selfservice password change with ldap encoding, #16810
[freeside.git] / FS / FS / svc_acct.pm
index 6596354..e67db43 100644 (file)
@@ -1163,6 +1163,7 @@ sub check {
 
   my $cust_pkg;
   local $username_letter = $username_letter;
+  local $username_uppercase = $username_uppercase;
   if ($self->svcnum) {
     my $cust_svc = $self->cust_svc
       or return "no cust_svc record found for svcnum ". $self->svcnum;
@@ -1174,6 +1175,8 @@ sub check {
   if ($cust_pkg) {
     $username_letter =
       $conf->exists('username-letter', $cust_pkg->cust_main->agentnum);
+    $username_uppercase =
+      $conf->exists('username-uppercase', $cust_pkg->cust_main->agentnum);
   }
 
   my $ulen = $usernamemax || $self->dbdef_table->column('username')->length;
@@ -1464,7 +1467,7 @@ sub set_password {
   if ( !$encoding ) {
     # set encoding to system default
     ($encoding, $encryption) =
-      split(/-/, lc($conf->config('default-password-encoding')));
+      split(/-/, lc($conf->config('default-password-encoding') || ''));
     $encoding ||= 'legacy';
     $self->_password_encoding($encoding);
   }
@@ -2521,7 +2524,8 @@ sub check_password {
 
   if ( $self->_password_encoding eq 'ldap' ) {
 
-    my $auth = from_rfc2307 Authen::Passphrase $self->_password;
+    $password =~ s/^{PLAIN}/{CLEARTEXT}/;
+    my $auth = from_rfc2307 Authen::Passphrase $password;
     return $auth->match($check_password);
 
   } elsif ( $self->_password_encoding eq 'crypt' ) {
@@ -2848,6 +2852,9 @@ sub search {
     push @where, "svcpart = $1";
   }
 
+  # sector and tower
+  my @where_sector = $class->tower_sector_sql($params);
+  push @where, @where_sector if @where_sector;
 
   # here is the agent virtualization
   #if ($params->{CurrentUser}) {
@@ -2875,6 +2882,9 @@ sub search {
                   ' LEFT JOIN cust_pkg  USING ( pkgnum  ) '.
                   ' LEFT JOIN cust_main USING ( custnum ) ';
 
+  $addl_from .= ' LEFT JOIN tower_sector USING ( sectornum )'
+    if @where_sector;
+
   my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
   #if ( keys %svc_acct ) {
   #  $count_query .= ' WHERE '.