[1493] | 1 | package LATMOS::Accounts::Bases::Ldap::Aliases; |
---|
| 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::LDAPS; |
---|
| 10 | use Net::LDAP::Entry; |
---|
| 11 | use Net::LDAP::Control::Paged; |
---|
| 12 | use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); |
---|
| 13 | use Net::LDAP::Util qw( escape_filter_value ); |
---|
| 14 | use LATMOS::Accounts::Log; |
---|
| 15 | |
---|
| 16 | our $VERSION = (q$Rev: 649 $ =~ /^Rev: (\d+) /)[0]; |
---|
| 17 | |
---|
| 18 | =head1 NAME |
---|
| 19 | |
---|
| 20 | LATMOS::Ldap - Perl extension for blah blah blah |
---|
| 21 | |
---|
| 22 | =head1 SYNOPSIS |
---|
| 23 | |
---|
| 24 | use LATMOS::Ldap; |
---|
| 25 | blah blah blah |
---|
| 26 | |
---|
| 27 | =head1 DESCRIPTION |
---|
| 28 | |
---|
| 29 | Stub documentation for LATMOS::Ldap, created by h2xs. It looks like the |
---|
| 30 | author of the extension was negligent enough to leave the stub |
---|
| 31 | unedited. |
---|
| 32 | |
---|
| 33 | Blah blah blah. |
---|
| 34 | |
---|
| 35 | =head1 FUNCTIONS |
---|
| 36 | |
---|
| 37 | =cut |
---|
| 38 | |
---|
| 39 | sub _class_filter { '(&(ObjectClass=nisMailAlias))' } |
---|
| 40 | |
---|
| 41 | sub _key_attr { 'cn' } |
---|
| 42 | |
---|
| 43 | sub _my_ldap_classes { qw( |
---|
| 44 | top |
---|
| 45 | nisMailAlias |
---|
| 46 | ) } |
---|
| 47 | |
---|
| 48 | sub _get_attr_schema { |
---|
| 49 | my ($class, $base) = @_; |
---|
| 50 | my $info = { |
---|
| 51 | cn => { ro => 1 }, |
---|
| 52 | dn => { ro => 1 }, |
---|
| 53 | objectClass => { ro => 1 }, |
---|
| 54 | rfc822MailMember => { |
---|
| 55 | multiple => 1, |
---|
| 56 | }, |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | $info->{$class->_key_attribute($base)}{ro} = 1; |
---|
| 60 | $info->{$class->_dn_attribute($base)}{ro} = 1; |
---|
| 61 | |
---|
| 62 | $info |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | sub is_supported { |
---|
| 66 | my ($class, $base) = @_; |
---|
| 67 | return $base->config('aliases_container') ? 1 : 0; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | sub _create { |
---|
| 71 | my ($class, $base, $id, %data) = @_; |
---|
| 72 | |
---|
| 73 | my $entry = Net::LDAP::Entry->new(); |
---|
| 74 | |
---|
| 75 | $entry->dn(join(',', |
---|
| 76 | sprintf('%s=%s', |
---|
| 77 | $class->_dn_attribute($base), |
---|
| 78 | escape_filter_value($id)), |
---|
| 79 | $base->object_base_dn($class->type), |
---|
| 80 | )); |
---|
| 81 | $entry->replace(objectClass => |
---|
| 82 | [ $class->_my_ldap_classes ],); |
---|
| 83 | $data{$class->_key_attribute($base)} = $id; |
---|
| 84 | foreach (keys %data) { |
---|
| 85 | $class->_populate_entry($entry, |
---|
| 86 | $_, $data{$_}, $base); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | my $msg = $base->ldap->add($entry); |
---|
| 90 | if ($msg->code) { |
---|
| 91 | $base->log(LA_ERR, "Cannot create aliases: %s", $msg->error); |
---|
| 92 | return 0; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | return 1; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | 1; |
---|
| 99 | |
---|
| 100 | __END__ |
---|
| 101 | |
---|
| 102 | =head1 SEE ALSO |
---|
| 103 | |
---|
| 104 | =head1 AUTHOR |
---|
| 105 | |
---|
| 106 | Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
| 107 | |
---|
| 108 | =head1 COPYRIGHT AND LICENSE |
---|
| 109 | |
---|
| 110 | Copyright (C) 2015 CNRS LATMOS |
---|
| 111 | |
---|
| 112 | This library is free software; you can redistribute it and/or modify |
---|
| 113 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
| 114 | at your option, any later version of Perl 5 you may have available. |
---|
| 115 | |
---|
| 116 | =cut |
---|