source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix/Group.pm @ 984

Last change on this file since 984 was 965, checked in by nanardon, 12 years ago
  • avoid undef value
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1package LATMOS::Accounts::Bases::Unix::Group;
2
3use 5.010000;
4use strict;
5use warnings;
6
7use base qw(LATMOS::Accounts::Bases::Objects);
8use LATMOS::Accounts::Log;
9
10our $VERSION = (q$Rev: 205 $ =~ /^Rev: (\d+) /)[0];
11
12=head1 NAME
13
14LATMOS::Ad - Perl extension for blah blah blah
15
16=head1 SYNOPSIS
17
18  use LATMOS::Accounts::Bases;
19  my $base = LATMOS::Accounts::Bases->new('unix');
20  ...
21
22=head1 DESCRIPTION
23
24Account base access over standard unix file format.
25
26=head1 FUNCTIONS
27
28=cut
29
30sub _get_attr_schema {
31    my ($class, $base) = @_;
32    {
33        sAMAccountName => {
34            iname => 'group_name',
35            ro => 1,
36        },
37        gidNumber => {
38            iname => 'gid',
39        },
40        memberUID => {
41            iname => 'user_list',
42            multiple => 1,
43            delayed => 1,
44        },
45    };
46}
47
48=head2 new(%options)
49
50Create a new LATMOS::Ad object for windows AD $domain.
51
52domain / server: either the Ad domain or directly the server
53
54ldap_args is an optionnal list of arguments to pass to L<Net::LDAP>.
55
56=cut
57
58sub new {
59    my ($class, $base, $id, @args) = @_;
60    # we profit of ref, quite easy
61    if (exists($base->{groups}{$id}) && $base->{groups}{$id}) {
62        if ($base->{groups}{$id}{gid} < ($base->{min_gid} || 0)) {
63            return;
64        }
65        return bless($base->{groups}{$id}, $class);
66    } else { return }
67}
68
69sub id {
70    $_[0]->{group_name}
71}
72
73sub get_field {
74    my ($self, $field) = @_;
75    if ($field eq 'user_list') {
76        return [ keys %{ $self->{'users'} || {} } ];
77    } elsif ($field eq 'goup_name') {
78        return $self->id;
79    }
80
81    $self->{$field}
82}
83
84sub set_fields {
85    my ($self, %data) = @_;
86    foreach my $field (keys %data) {
87        $field eq 'gid' and do {
88            if (!(defined($data{$field}) && $data{$field} =~ /^\d+$/)) {
89                $self->base->log(LA_ERR,
90                    "Invalid data for $field: " . ($data{$field} || ''));
91                return;
92            }
93        };
94    }
95    foreach my $field (keys %data) {
96        # TODO check fields exists !
97        if ($field eq 'user_list') {
98            $self->{'users'} = {};
99            foreach (ref $data{$field} ? (@{ $data{$field} || [] }) : ($data{$field})) {
100                $self->{'users'}{$_} = 1;
101            }
102        } else {
103            $self->{$field} = $data{$field};
104        }
105    }
106    1;
107}
108
1091;
110
111__END__
112
113=head1 SEE ALSO
114
115=head1 AUTHOR
116
117Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
118
119=head1 COPYRIGHT AND LICENSE
120
121Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
122
123This library is free software; you can redistribute it and/or modify
124it under the same terms as Perl itself, either Perl version 5.10.0 or,
125at your option, any later version of Perl 5 you may have available.
126
127
128=cut
Note: See TracBrowser for help on using the repository browser.