source: LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad/User.pm @ 91

Last change on this file since 91 was 91, checked in by nanardon, 15 years ago
  • AD support of memberOf (eq user in group)
  • Property svn:keywords set to Id Rev
File size: 2.5 KB
Line 
1package LATMOS::Accounts::Bases::Ad::User;
2
3use 5.010000;
4use strict;
5use warnings;
6
7use base qw(LATMOS::Accounts::Bases::Ad::objects);
8use Net::LDAP;
9use Net::LDAP::Entry;
10use Net::LDAP::Control::Paged;
11use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); 
12use Net::LDAP::Util     qw( escape_filter_value );
13
14our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
15
16=head1 NAME
17
18LATMOS::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
27Stub documentation for LATMOS::Ad, created by h2xs. It looks like the
28author of the extension was negligent enough to leave the stub
29unedited.
30
31Blah blah blah.
32
33=head1 FUNCTIONS
34
35=cut
36
37sub _class_filter { '(&(ObjectClass=user) (!(ObjectClass=computer)))' }
38
39sub _key_attr { 'cn' } 
40
41sub _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
65sub _populate_entry {
66    my ($self, $entry, $field, $value) = @_;
67    for ($field) {
68    }
69    $entry->replace($field, $value);
70}
71
72
73sub _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
941;
95
96__END__
97
98=head1 SEE ALSO
99
100=head1 AUTHOR
101
102Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt>
103
104=head1 COPYRIGHT AND LICENSE
105
106Copyright (C) 2008 CNRS SA/CETP/LATMOS
107
108This library is free software; you can redistribute it and/or modify
109it under the same terms as Perl itself, either Perl version 5.10.0 or,
110at your option, any later version of Perl 5 you may have available.
111
112
113=cut
Note: See TracBrowser for help on using the repository browser.