]>
git.proxmox.com Git - pmg-api.git/blob - PMG/LDAPSet.pm
11 sub new_from_ldap_cfg
{
12 my ($self, $ldap_cfg, $syncmode, $serverid) = @_;
13 my $type = ref($self) || $self;
20 $ids = [ keys %{$ldap_cfg->{ids
}} ];
23 $self = bless {}, $type;
25 foreach my $id (@$ids) {
27 # fixme: does it work?
28 my $data = $ldap_cfg->{ids
}->{$id};
30 next if $data->{disable
};
32 $data->{syncmode
} = $syncmode;
35 $self->{$id} = PMG
::LDAPCache-
>new(%$data);
42 my ($ldap_cfg, $tostderr) = @_;
44 my $ldap = __PACKAGE__-
>new_from_ldap_cfg($ldap_cfg, 1);
46 foreach my $p (@{$ldap->ids()}) {
47 my $server = $ldap->{$p}->{server1
};
49 my $msg = "start syncing ldap profile '${p}' (${server})";
51 print STDERR
"$msg\n" if $tostderr;
53 $ldap->{$p}->update(2);
55 my $errors = $ldap->{$p}->{errors
};
56 print STDERR
$errors if $tostderr && $errors;
58 my $gcount = $ldap->{$p}->{gcount
};
59 my $ucount = $ldap->{$p}->{ucount
};
60 my $mcount = $ldap->{$p}->{mcount
};
63 $msg = "aborted syncing ldap profile '${p}' (${server}): " .
64 "keep old data, $ucount accounts, $mcount addresses, $gcount groups";
66 $msg = "finished syncing ldap profile '${p}' (${server}): " .
67 "found $ucount accounts, $mcount addresses, $gcount groups";
70 print STDERR
"$msg\n" if $tostderr;
79 foreach my $id (keys %$self) {
80 next if ref($self->{$id}) ne 'PMG::LDAPCache';
88 my ($self, $syncmode) = @_;
89 foreach my $id (@{$self->ids()}) {
90 $self->{$id}->update($syncmode);
97 if (!($self->{$id} && ref($self->{$id}) eq 'PMG::LDAPCache')) {
98 syslog
('warning', "WARNING: trying to query non-existent ldap profile '$id'");
102 return $self->{$id}->groups();
106 my ($self, $mail, $id) = @_;
109 if (!($self->{$id} && ref($self->{$id}) eq 'PMG::LDAPCache')) {
110 syslog
('warning', "WARNING: trying to query non-existent ldap profile '$id'");
113 return $self->{$id}->mail_exists($mail);
116 foreach $id (@{$self->ids()}) {
117 my $res = $self->{$id}->mail_exists($mail);
125 my ($self, $account, $id) = @_;
127 if (!($self->{$id} && ref($self->{$id}) eq 'PMG::LDAPCache')) {
128 syslog
('warning', "WARNING: trying to query non-existent ldap profile '$id'");
132 return $self->{$id}->account_exists($account);
135 sub account_has_address
{
136 my ($self, $account, $mail, $id) = @_;
138 if (!($self->{$id} && ref($self->{$id}) eq 'PMG::LDAPCache')) {
139 syslog
('warning', "WARNING: trying to query non-existent ldap profile '$id'");
143 return $self->{$id}->account_has_address($account, $mail);
147 my ($self, $mail, $group, $id) = @_;
149 if (!($self->{$id} && ref($self->{$id}) eq 'PMG::LDAPCache')) {
150 syslog
('warning', "WARNING: trying to query non-existent ldap profile '$id'");
154 return $self->{$id}->user_in_group($mail, $group);
158 my ($self, $mail, $password) = @_;
160 foreach my $id (@{$self->ids()}) {
161 if ($self->{$id}->mail_exists($mail)) {
162 if (my $res = $self->{$id}->account_info($mail)) {
163 $res->{profile
} = $id;
165 if (defined($password)) {
166 if (my $ldap = $self->{$id}->ldap_connect()) {
167 my $mesg = $ldap->bind($res->{dn
}, password
=> $password);
168 return undef if ($mesg->code);