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