[288] | 1 | package LATMOS::Accounts::Bases::Ldap::Group; |
---|
| 2 | |
---|
| 3 | use 5.010000; |
---|
| 4 | use strict; |
---|
| 5 | use warnings; |
---|
| 6 | |
---|
| 7 | use base qw(LATMOS::Accounts::Bases::Ldap::objects); |
---|
| 8 | use Net::LDAP; |
---|
| 9 | use Net::LDAP::Entry; |
---|
| 10 | use Net::LDAP::Control::Paged; |
---|
| 11 | use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); |
---|
| 12 | use Net::LDAP::Util qw( escape_filter_value ); |
---|
| 13 | use LATMOS::Accounts::Log; |
---|
| 14 | |
---|
| 15 | our $VERSION = (q$Rev: 649 $ =~ /^Rev: (\d+) /)[0]; |
---|
| 16 | |
---|
| 17 | =head1 NAME |
---|
| 18 | |
---|
| 19 | LATMOS::Ldap - Perl extension for blah blah blah |
---|
| 20 | |
---|
| 21 | =head1 SYNOPSIS |
---|
| 22 | |
---|
| 23 | use LATMOS::Ldap; |
---|
| 24 | blah blah blah |
---|
| 25 | |
---|
| 26 | =head1 DESCRIPTION |
---|
| 27 | |
---|
| 28 | Stub documentation for LATMOS::Ldap, created by h2xs. It looks like the |
---|
| 29 | author of the extension was negligent enough to leave the stub |
---|
| 30 | unedited. |
---|
| 31 | |
---|
| 32 | Blah blah blah. |
---|
| 33 | |
---|
| 34 | =head1 FUNCTIONS |
---|
| 35 | |
---|
| 36 | =cut |
---|
| 37 | |
---|
| 38 | sub _class_filter { '(ObjectClass=posixGroup)' } |
---|
| 39 | |
---|
| 40 | sub _key_attr { 'cn' } |
---|
| 41 | |
---|
[292] | 42 | sub _my_ldap_classes { qw(top posixGroup) } |
---|
| 43 | |
---|
[861] | 44 | sub _get_attr_schema { |
---|
| 45 | my ($class, $base) = @_; |
---|
| 46 | $class->SUPER::_get_attr_schema($base, |
---|
| 47 | { |
---|
| 48 | gidNumber => { uniq => 1, }, |
---|
| 49 | description => { }, |
---|
| 50 | memberUID => { multiple => 1, delayed => 1, }, |
---|
| 51 | cn => { ro => 1 }, |
---|
| 52 | dn => { ro => 1 }, |
---|
| 53 | objectClass => { ro => 1 }, |
---|
| 54 | } |
---|
| 55 | ); |
---|
[288] | 56 | } |
---|
| 57 | |
---|
| 58 | sub _create { |
---|
| 59 | my ($class, $base, $id, %data) = @_; |
---|
| 60 | |
---|
| 61 | my $entry = Net::LDAP::Entry->new(); |
---|
| 62 | |
---|
| 63 | $entry->dn(join(',', |
---|
[1115] | 64 | sprintf('%s=%s', |
---|
[1117] | 65 | $class->_dn_attribute($base), |
---|
[1115] | 66 | escape_filter_value($id)), |
---|
| 67 | $base->object_base_dn($class->type), |
---|
[288] | 68 | )); |
---|
[292] | 69 | $entry->replace(objectClass => [ $class->_my_ldap_classes ],); |
---|
[288] | 70 | my %delayed; |
---|
[1117] | 71 | $data{$class->_key_attribute($base)} = $id; |
---|
[288] | 72 | foreach (keys %data) { |
---|
| 73 | /^(memberUID)$/ and do { |
---|
[1120] | 74 | $delayed{memberUID} = $data{$_}; |
---|
[288] | 75 | next; |
---|
| 76 | }; |
---|
| 77 | $class->_populate_entry($entry, $_, $data{$_}); |
---|
| 78 | } |
---|
| 79 | my $msg = $base->ldap->add($entry); |
---|
| 80 | $base->log(LA_ERR, "Cannot create group: %s", $msg->error) if ($msg->code); |
---|
| 81 | return if ($msg->code); |
---|
| 82 | if (! keys %delayed) { return 1 }; |
---|
| 83 | my $res = $base->get_object('group', $id)->set_fields(%delayed); |
---|
| 84 | return defined($res) ? 1 : 0; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | sub get_field { |
---|
| 88 | my ($self, $field) = @_; |
---|
| 89 | |
---|
| 90 | $field eq 'memberUID' and do { |
---|
| 91 | my $val = $self->SUPER::get_field('memberUid'); |
---|
| 92 | return ref $val ? $val : [ grep { $_ } $val ]; |
---|
| 93 | }; |
---|
| 94 | $self->SUPER::get_field($field); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | sub set_fields { |
---|
| 98 | my ($self, %data) = @_; |
---|
| 99 | my %ndata; |
---|
| 100 | while (my ($f, $val) = each(%data)) { |
---|
| 101 | $f eq 'memberUID' and do { |
---|
| 102 | my %users; |
---|
| 103 | $users{$_}{e} = 1 foreach (@{ $self->get_field('memberUID') || []}); |
---|
| 104 | $users{$_}{n} = 1 foreach (@{ $val || []}); |
---|
| 105 | foreach (keys %users) { |
---|
| 106 | $users{$_}{e} && $users{$_}{n} and next; |
---|
| 107 | if ($users{$_}{e}) { |
---|
| 108 | $self->{entry}->delete(memberUid => $_); |
---|
[766] | 109 | } elsif ($users{$_}{n} && $self->base->get_object('user', $_)) { |
---|
[288] | 110 | $self->{entry}->add(memberUid => $_); |
---|
| 111 | } # else {} # can't happen |
---|
| 112 | my $mesg = $self->{entry}->update($self->base->ldap); |
---|
| 113 | } |
---|
| 114 | next; |
---|
| 115 | }; |
---|
| 116 | $ndata{$f} = $val; |
---|
| 117 | } |
---|
| 118 | $self->SUPER::set_fields(%ndata); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | 1; |
---|
| 122 | |
---|
| 123 | __END__ |
---|
| 124 | |
---|
| 125 | =head1 SEE ALSO |
---|
| 126 | |
---|
| 127 | =head1 AUTHOR |
---|
| 128 | |
---|
| 129 | Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt> |
---|
| 130 | |
---|
| 131 | =head1 COPYRIGHT AND LICENSE |
---|
| 132 | |
---|
| 133 | Copyright (C) 2008 CNRS SA/CETP/LATMOS |
---|
| 134 | |
---|
| 135 | This library is free software; you can redistribute it and/or modify |
---|
| 136 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
| 137 | at your option, any later version of Perl 5 you may have available. |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | =cut |
---|