Browse Source

+ LDV::LDAP->_uid_to_dn

master
Alex 'AdUser' Z 10 years ago
parent
commit
71c0b21258
  1. 11
      lib/LDV/LDAP.pm

11
lib/LDV/LDAP.pm

@ -37,6 +37,11 @@ sub _escape {
return $str; return $str;
} }
sub _uid_to_dn {
my ($self, $uid) = @_;
return sprintf "uid=%s,%s", $uid, $self->{userbase};
}
sub _filter_username { sub _filter_username {
my ($self, $uid) = @_; my ($self, $uid) = @_;
return bless({and => return bless({and =>
@ -55,7 +60,7 @@ sub create {
return "User already exists" return "User already exists"
if ($data); if ($data);
my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; my $dn = $self->_uid_to_dn($uid);
my $result = $conn->add($dn, attr => [ my $result = $conn->add($dn, attr => [
objectClass => ['inetOrgPerson'], objectClass => ['inetOrgPerson'],
uid => $uid, uid => $uid,
@ -71,7 +76,7 @@ sub delete {
my ($self, $uid) = @_; my ($self, $uid) = @_;
my $conn = $self->_connect(); my $conn = $self->_connect();
$uid = $self->_escape($uid); $uid = $self->_escape($uid);
my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; my $dn = $self->_uid_to_dn($uid);
my $result = $conn->delete($dn); my $result = $conn->delete($dn);
$conn->unbind; $conn->unbind;
return $result->error if ($result->code); return $result->error if ($result->code);
@ -110,7 +115,7 @@ sub update {
return "No such user" return "No such user"
unless ($data); unless ($data);
my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; my $dn = $self->_uid_to_dn($uid);
my %allowed = map { $_ => 1 } @{$self->{defattrs}}; my %allowed = map { $_ => 1 } @{$self->{defattrs}};
my @chg = (); my @chg = ();
while (my ($key, $value) = each(%$attrs)) { while (my ($key, $value) = each(%$attrs)) {

Loading…
Cancel
Save