1 | package LATMOS::Accounts::Bases::Ad::User; |
---|
2 | |
---|
3 | use 5.010000; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | |
---|
7 | use base qw(LATMOS::Accounts::Bases::Ad::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 | |
---|
14 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
15 | |
---|
16 | =head1 NAME |
---|
17 | |
---|
18 | LATMOS::Ad - Perl extension for blah blah blah |
---|
19 | |
---|
20 | =head1 SYNOPSIS |
---|
21 | |
---|
22 | use LATMOS::Ad; |
---|
23 | blah blah blah |
---|
24 | |
---|
25 | =head1 DESCRIPTION |
---|
26 | |
---|
27 | Stub documentation for LATMOS::Ad, created by h2xs. It looks like the |
---|
28 | author of the extension was negligent enough to leave the stub |
---|
29 | unedited. |
---|
30 | |
---|
31 | Blah blah blah. |
---|
32 | |
---|
33 | =head1 FUNCTIONS |
---|
34 | |
---|
35 | =cut |
---|
36 | |
---|
37 | sub _class_filter { '(&(ObjectClass=user) (!(ObjectClass=computer)))' } |
---|
38 | |
---|
39 | sub _key_attr { 'cn' } |
---|
40 | |
---|
41 | sub _canonical_fields { |
---|
42 | my ($self, $base, $mode) = @_; |
---|
43 | ( |
---|
44 | qw( |
---|
45 | sn name givenName |
---|
46 | sAMAccountName uid gecos |
---|
47 | homeDirectory loginShell |
---|
48 | uidNumber gidNumber gecos |
---|
49 | userPassword |
---|
50 | shadowLastChange shadowMin shadowMax |
---|
51 | shadowWarning shadowInactive shadowExpire |
---|
52 | shadowFlag |
---|
53 | description |
---|
54 | mail |
---|
55 | ipPhone otherTelephone department |
---|
56 | title modbile homePhone |
---|
57 | ), |
---|
58 | ($mode !~ /w/ |
---|
59 | ? qw(cn dn uSNCreated uSNChanged memberOf) |
---|
60 | : () |
---|
61 | ) |
---|
62 | ) |
---|
63 | } |
---|
64 | |
---|
65 | sub _populate_entry { |
---|
66 | my ($self, $entry, $field, $value) = @_; |
---|
67 | for ($field) { |
---|
68 | } |
---|
69 | $entry->replace($field, $value); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | sub _create { |
---|
74 | my ($class, $base, $id, %data) = @_; |
---|
75 | |
---|
76 | my $entry = Net::LDAP::Entry->new(); |
---|
77 | |
---|
78 | $entry->dn(join(',', |
---|
79 | sprintf('cn=%s', escape_filter_value($id)), |
---|
80 | $base->object_base_dn($class->type), |
---|
81 | )); |
---|
82 | $entry->replace('sAMAccountName', $id); |
---|
83 | $entry->replace(objectClass => [ qw(top person organizationalPerson user)],); |
---|
84 | $entry->replace(userAccountControl => 544); |
---|
85 | $entry->replace(accountExpires => '9223372036854775807'); # TODO hardcoded, burk |
---|
86 | $entry->replace(userPrincipalName => "$id\@" . $base->ad_domain); |
---|
87 | foreach (keys %data) { |
---|
88 | $class->_populate_entry($entry, $_, $data{$_}); |
---|
89 | } |
---|
90 | my $msg = $base->ldap->add($entry); |
---|
91 | return $msg->code ? 0 : 1; |
---|
92 | } |
---|
93 | |
---|
94 | 1; |
---|
95 | |
---|
96 | __END__ |
---|
97 | |
---|
98 | =head1 SEE ALSO |
---|
99 | |
---|
100 | =head1 AUTHOR |
---|
101 | |
---|
102 | Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt> |
---|
103 | |
---|
104 | =head1 COPYRIGHT AND LICENSE |
---|
105 | |
---|
106 | Copyright (C) 2008 CNRS SA/CETP/LATMOS |
---|
107 | |
---|
108 | This library is free software; you can redistribute it and/or modify |
---|
109 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
110 | at your option, any later version of Perl 5 you may have available. |
---|
111 | |
---|
112 | |
---|
113 | =cut |
---|