Project

General

Profile

Defect #879 » Redmine.pm.diff

Diff with original version (0.6.4) - Liwiusz Ociepa, 2008-03-17 16:04

View differences:

Redmine.pm 2008-03-17 15:34:52.789384031 +0100
90 90

  
91 91
use DBI;
92 92
use Digest::SHA1;
93
use Net::LDAP;
93 94

  
94 95
use Apache2::Module;
95 96
use Apache2::Access;
......
140 141

  
141 142
    my $dbh = connect_database($r);
142 143
    my $sth = $dbh->prepare(
143
	"SELECT * FROM projects WHERE projects.identifier=? and projects.is_public=true;"
144
        "SELECT * FROM projects WHERE projects.identifier=? and projects.is_public=true;"
144 145
    );
145 146

  
146 147
    $sth->execute($project_id);
......
176 177
  my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass);
177 178

  
178 179
  my $sth = $dbh->prepare(
179
      "SELECT hashed_password FROM members, projects, users WHERE projects.id=members.project_id AND users.id=members.user_id AND users.status=1 AND login=? AND identifier=?;"
180
      "SELECT hashed_password,coalesce(auth_source_id,0) FROM members, projects, users WHERE projects.id=members.project_id AND users.id=members.user_id AND users.status=1 AND login=? AND identifier=?;"
180 181
  );
181 182
  $sth->execute($redmine_user, $project_id);
182 183

  
183 184
  my $ret;
184 185
  while (my @row = $sth->fetchrow_array) {
185
      if ($row[0] eq $pass_digest) {
186
	  $ret = 1;
187
	  last;
186
      if ($row[1] eq 0) {
187
          if ($row[0] eq $pass_digest) {
188
              $ret = 1;
189
              last;
190
          }
191
      } else {
192
          my $sthldap = $dbh->prepare(
193
              "SELECT host,port,account,account_password,base_dn,attr_login from auth_sources WHERE id = ?;"
194
          );
195
          $sthldap->execute($row[1]);
196
          while (my @rowldap = $sthldap->fetchrow_array) {
197
              my $ldap = Net::LDAP->new($rowldap[0], port => $rowldap[1]);
198
              my $res = $rowldap[2] ? $ldap->bind($rowldap[2], password => $rowldap[3]) : $ldap->bind();
199
 
200
              unless ($res->code) {
201
                  my $res = $ldap->search(
202
                      base => $rowldap[4],
203
                      filter => "(".$rowldap[5]."=".$redmine_user.")",
204
                      attrs => ['dn']
205
                  );
206
                  unless ($res->code) { 
207
                      foreach my $entry ($res->entries) { 
208
                          my $mesg = $ldap->bind($entry->dn, password => $redmine_pass);
209
                          $ret = 1 and last unless $mesg->code;
210
                      }
211
                  }
212
              }
213
              $res = $ldap->unbind();
214
              $ldap->disconnect();
215
          }
216
          $sthldap->finish();
188 217
      }
189 218
  }
219
  $sth->finish();
190 220
  $dbh->disconnect();
191 221

  
192 222
  $ret;
(2-2/6)