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

Last change on this file since 69 was 69, checked in by nanardon, 15 years ago
  • Ad::Group, allow create
  • escape CN=
  • Property svn:keywords set to Id Rev
File size: 2.4 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        ),
56        ($mode !~ /w/
57            ? qw(cn dn)
58            : ()
59        )
60    )
61}
62
63sub _populate_entry {
64    my ($self, $entry, $field, $value) = @_;
65    for ($field) {
66    }
67    $entry->replace($field, $value);
68}
69
70
71sub _create {
72    my ($class, $base, $id, %data) = @_;
73
74    my $entry = Net::LDAP::Entry->new();
75
76    $entry->dn(join(',',
77        sprintf('cn=%s', escape_filter_value($id)),
78        'cn=Users',
79        $base->top_dn
80    ));
81    $entry->replace('sAMAccountName', $id);
82    $entry->replace(objectClass => [ qw(top person organizationalPerson user)],);
83    $entry->replace(userAccountControl => 544);
84    $entry->replace(accountExpires => '9223372036854775807'); # TODO hardcoded, burk
85    $entry->replace(userPrincipalName => "$id\@" . $base->ad_domain);
86    foreach (keys %data) {
87        $class->_populate_entry($entry, $_, $data{$_});
88    }
89    my $msg = $base->ldap->add($entry);
90    return $msg->code ? 0 : 1;
91}
92
931;
94
95__END__
96
97=head1 SEE ALSO
98
99=head1 AUTHOR
100
101Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt>
102
103=head1 COPYRIGHT AND LICENSE
104
105Copyright (C) 2008 CNRS SA/CETP/LATMOS
106
107This library is free software; you can redistribute it and/or modify
108it under the same terms as Perl itself, either Perl version 5.10.0 or,
109at your option, any later version of Perl 5 you may have available.
110
111
112=cut
Note: See TracBrowser for help on using the repository browser.