| 1 | package Net::LDAP::posixGroup; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Net::LDAP::Entry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Net::LDAP::posixGroup - Creates new Net::LDAP::Entry objects for a posixGroup entry. | ||||||||||
| 10 | |||||||||||
| 11 | =head1 VERSION | ||||||||||
| 12 | |||||||||||
| 13 | Version 0.0.2 | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | 2 | our $VERSION = '0.0.2'; | |||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | use Net::LDAP::posixGroup; | ||||||||||
| 23 | |||||||||||
| 24 | my $foo = Net::LDAP::posixGroup->new({baseDN=>'ou=group,dc=foo'}); | ||||||||||
| 25 | |||||||||||
| 26 | #creates a new entry with the minimum requirements | ||||||||||
| 27 | my $entry = $foo->create({name=>'vvelox', gid=>'404'}, ['user1', 'user2']); | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | =head1 FUNCTIONS | ||||||||||
| 31 | |||||||||||
| 32 | =head2 new | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | sub new { | ||||||||||
| 37 | 0 | ▶ | my %args; | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 38 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | %args= %{$_[1]}; | |||||||||
| 40 | }; | ||||||||||
| 41 | |||||||||||
| 42 | #returns undef if the baseDN is not set | ||||||||||
| 43 | 0 | ▶ | if (!defined($args{baseDN})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | warn('Net-LDAP-postixGroup new:0: "baseDN" is not defined'); | |||||||||
| 45 | 0 | return undef; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | my $self={error=>undef, set=>undef, baseDN=>$args{baseDN}}; | |||||||||
| 49 | 0 | bless $self; | |||||||||
| 50 | |||||||||||
| 51 | #if it is defined it sets the topless setting to what ever it is | ||||||||||
| 52 | 0 | ▶ | if (defined($args{topless})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | $self->{topless}=$args{topless}; | |||||||||
| 54 | }else { | ||||||||||
| 55 | 0 | $self->{topless}=undef; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | return $self; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | =head2 create | ||||||||||
| 62 | |||||||||||
| 63 | Creates a new Net::LDAP::Entry object. The first value is a | ||||||||||
| 64 | hash. See the below for avialble values. The second is a array | ||||||||||
| 65 | with the group members. | ||||||||||
| 66 | |||||||||||
| 67 | =head3 name | ||||||||||
| 68 | |||||||||||
| 69 | The group name. This is required. | ||||||||||
| 70 | |||||||||||
| 71 | =head3 gid | ||||||||||
| 72 | |||||||||||
| 73 | The numeric GID of a group. This is required. | ||||||||||
| 74 | |||||||||||
| 75 | =head3 description | ||||||||||
| 76 | |||||||||||
| 77 | A optional LDAP desciption. This is optional. | ||||||||||
| 78 | |||||||||||
| 79 | =head3 primary | ||||||||||
| 80 | |||||||||||
| 81 | The accepted values are 'cn' and 'gidNumber'. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | sub create{ | ||||||||||
| 86 | 0 | ▶ | my $self=$_[0]; | ||||||||
|
Subroutine
create: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||
| 87 | 0 | my %args; | |||||||||
| 88 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | %args= %{$_[1]}; | |||||||||
| 90 | }; | ||||||||||
| 91 | 0 | my @members; | |||||||||
| 92 | 0 | ▶ | if (defined($_[2])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 0 | @members=@{$_[2]}; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | #error if name is not defined | ||||||||||
| 97 | 0 | ▶ | if (!defined($args{name})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | warn('Net-LDAP-posixGroup create:1: name not defined'); | |||||||||
| 99 | 0 | $self->{error}=1; | |||||||||
| 100 | 0 | $self->{errorString}='name not defined'; | |||||||||
| 101 | 0 | return undef; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | #error if name is not defined | ||||||||||
| 105 | 0 | ▶ | if (!defined($args{name})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | warn('Net-LDAP-posixGroup create:2: gid not defined'); | |||||||||
| 107 | 0 | $self->{error}=2; | |||||||||
| 108 | 0 | $self->{errorString}='gid not defined'; | |||||||||
| 109 | 0 | return undef; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | #sets the primary if it is not defined | ||||||||||
| 113 | 0 | ▶ | if (!defined($args{primary})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | $args{primary}='cn'; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | #verifies the primary | ||||||||||
| 118 | 0 | my @primary=('gid', 'cn'); | |||||||||
| 119 | 0 | my $dn=undef; | |||||||||
| 120 | 0 | my $primaryInt=0; | |||||||||
| 121 | 0 | ▶ | while (defined($primary[$primaryInt])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | #when a match is found, use it to begin forming the the DN | ||||||||||
| 123 | 0 | ▶ | if ($args{primary} eq $primary[$primaryInt]) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | $dn=$args{primary}.'='; | |||||||||
| 125 | } | ||||||||||
| 126 | 0 | $primaryInt++; | |||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | #error if none is matched | ||||||||||
| 130 | 0 | ▶ | if (!defined($dn)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | warn('Net-LDAP-posixGroup create:3: primary is a invalid value'); | |||||||||
| 132 | 0 | $self->{error}=3; | |||||||||
| 133 | 0 | $self->{errorString}='primary is a invalid value'; | |||||||||
| 134 | 0 | return undef; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | #forms the DN if it is using the gidNumber | ||||||||||
| 138 | 0 | ▶ | if ($args{primary} eq 'gidNumber') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | 0 | $dn=$dn.$args{uid}; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | #forms the DN if it is using the CN | ||||||||||
| 143 | 0 | ▶ | if ($args{primary} eq 'cn') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | 0 | $dn=$dn.$args{name}; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | #full forms the DN | ||||||||||
| 148 | 0 | $dn=$dn.','.$self->{baseDN}; | |||||||||
| 149 | |||||||||||
| 150 | #creates a new object | ||||||||||
| 151 | 0 | my $entry = Net::LDAP::Entry->new; | |||||||||
| 152 | |||||||||||
| 153 | #sets the dn | ||||||||||
| 154 | 0 | $entry->dn($dn); | |||||||||
| 155 | |||||||||||
| 156 | #adds the various attributes | ||||||||||
| 157 | $entry->add(objectClass=>['posixGroup', 'top'], | ||||||||||
| 158 | 0 | gidNumber=>[$args{gid}], cn=>[$args{name}]); | |||||||||
| 159 | |||||||||||
| 160 | #adds the description if needed | ||||||||||
| 161 | 0 | ▶ | if (defined($args{description})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | 0 | $entry->add(description=>[$args{description}]); | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | 0 | my $membersInt=0; | |||||||||
| 166 | 0 | ▶ | while (defined($members[$membersInt])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 167 | 0 | $entry->add(memberUid=>[$members[$membersInt]]); | |||||||||
| 168 | |||||||||||
| 169 | 0 | $membersInt++; | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 0 | return $entry; | |||||||||
| 173 | |||||||||||
| 174 | } | ||||||||||
| 175 | |||||||||||
| 176 | =head2 errorBlank | ||||||||||
| 177 | |||||||||||
| 178 | A internal function user for clearing an error. | ||||||||||
| 179 | |||||||||||
| 180 | =cut | ||||||||||
| 181 | |||||||||||
| 182 | #blanks the error flags | ||||||||||
| 183 | sub errorBlank{ | ||||||||||
| 184 | 0 | ▶ | my $self=$_[0]; | ||||||||
|
Subroutine
errorBlank: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 185 | |||||||||||
| 186 | #error handling | ||||||||||
| 187 | 0 | $self->{error}=undef; | |||||||||
| 188 | 0 | $self->{errorString}=""; | |||||||||
| 189 | |||||||||||
| 190 | 0 | return 1; | |||||||||
| 191 | }; | ||||||||||
| 192 | |||||||||||
| 193 | =head1 Error Codes | ||||||||||
| 194 | |||||||||||
| 195 | =head2 0 | ||||||||||
| 196 | |||||||||||
| 197 | Missing baseDN. | ||||||||||
| 198 | |||||||||||
| 199 | =head2 1 | ||||||||||
| 200 | |||||||||||
| 201 | No group name specified. | ||||||||||
| 202 | |||||||||||
| 203 | =head2 2 | ||||||||||
| 204 | |||||||||||
| 205 | No GID specified. | ||||||||||
| 206 | |||||||||||
| 207 | =head2 3 | ||||||||||
| 208 | |||||||||||
| 209 | The primary is a invalid value. | ||||||||||
| 210 | |||||||||||
| 211 | =head1 AUTHOR | ||||||||||
| 212 | |||||||||||
| 213 | Zane C. Bowers, C<< <vvelox at vvelox.net> >> | ||||||||||
| 214 | |||||||||||
| 215 | =head1 BUGS | ||||||||||
| 216 | |||||||||||
| 217 | Please report any bugs or feature requests to C<bug-net-ldap-posixgroup at rt.cpan.org>, or through | ||||||||||
| 218 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-LDAP-posixGroup>. I will be notified, and then you'll | ||||||||||
| 219 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 220 | |||||||||||
| 221 | |||||||||||
| 222 | |||||||||||
| 223 | |||||||||||
| 224 | =head1 SUPPORT | ||||||||||
| 225 | |||||||||||
| 226 | You can find documentation for this module with the perldoc command. | ||||||||||
| 227 | |||||||||||
| 228 | perldoc Net::LDAP::posixGroup | ||||||||||
| 229 | |||||||||||
| 230 | |||||||||||
| 231 | You can also look for information at: | ||||||||||
| 232 | |||||||||||
| 233 | =over 4 | ||||||||||
| 234 | |||||||||||
| 235 | =item * RT: CPAN's request tracker | ||||||||||
| 236 | |||||||||||
| 237 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-LDAP-posixGroup> | ||||||||||
| 238 | |||||||||||
| 239 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 240 | |||||||||||
| 241 | L<http://annocpan.org/dist/Net-LDAP-posixGroup> | ||||||||||
| 242 | |||||||||||
| 243 | =item * CPAN Ratings | ||||||||||
| 244 | |||||||||||
| 245 | L<http://cpanratings.perl.org/d/Net-LDAP-posixGroup> | ||||||||||
| 246 | |||||||||||
| 247 | =item * Search CPAN | ||||||||||
| 248 | |||||||||||
| 249 | L<http://search.cpan.org/dist/Net-LDAP-posixGroup> | ||||||||||
| 250 | |||||||||||
| 251 | =back | ||||||||||
| 252 | |||||||||||
| 253 | |||||||||||
| 254 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 255 | |||||||||||
| 256 | |||||||||||
| 257 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 258 | |||||||||||
| 259 | Copyright 2008 Zane C. Bowers, all rights reserved. | ||||||||||
| 260 | |||||||||||
| 261 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 262 | under the same terms as Perl itself. | ||||||||||
| 263 | |||||||||||
| 264 | |||||||||||
| 265 | =cut | ||||||||||
| 266 | |||||||||||
| 267 | 2 | 1; # End of Net::LDAP::posixGroup | |||||||||