Changeset 137
- Timestamp:
- 05/19/09 01:05:41 (15 years ago)
- Location:
- LATMOS-Accounts
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts.pm
r78 r137 49 49 my ($self, $section) = @_; 50 50 my $type = $self->val($section, 'type') or return; 51 my %params = map { $_ => ($self->val($section, $_)) } $self->Parameters($section); 51 my %params = ( 52 map { $_ => ($self->val($section, $_)) } $self->Parameters($section), 53 defattr => { map { $_ => ($self->val('_defattr_', $_)) } $self->Parameters('_defattr_') }, 54 ); 52 55 my $base = LATMOS::Accounts::Bases->new($type, %params, label => $section); 53 56 $base->load or return; -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r122 r137 42 42 $base->{_type} = lc($pclass); 43 43 $base->{_label} = $options{label}; 44 $base->{defattr} = $options{defattr}; 44 45 $base 45 46 } … … 177 178 my ($self, $otype, $id, %cdata) = @_; 178 179 180 # populating default value 181 foreach my $def (%{ $self->{defattr} || {}}) { 182 if ($def =~ /^$otype\.(.*)$/) { 183 $cdata{$1} = $self->{defattr}{$def} if(!$cdata{$1}); 184 } 185 } 186 if ($otype eq 'user') { 187 $cdata{uidNumber} ||= $self->find_next_numeric_id('user', 'uidNumber', 188 $self->{defattr}{'user.min_uid'}, $self->{defattr}{'user.max_uid'}); 189 } elsif ($otype eq 'group') { 190 $cdata{gidNumber} ||= $self->find_next_numeric_id('group', 'gidNumber', 191 $self->{defattr}{'group.min_gid'}, $self->{defattr}{'group.max_gid'}); 192 } 179 193 my %data; 180 194 foreach my $cfield (keys %cdata) { … … 320 334 } 321 335 336 sub find_next_numeric_id { 337 my ($self, $otype, $field, $min, $max) = @_; 338 my $pclass = $self->_load_obj_class($otype) or return; 339 $pclass->find_next_numeric_id($self, $field, $min, $max); 340 } 341 322 342 1; 323 343 -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r122 r137 265 265 } 266 266 267 sub find_next_numeric_id { 268 my ($class, $base, $field, $min, $max) = @_; 269 $base->get_field_name($class->type, $field) or return; 270 $min ||= 271 $field eq 'uidNumber' ? 500 : 272 $field eq 'gidNumber' ? 500 : 273 1; 274 $max ||= 65635; 275 my %existsid; 276 foreach ($base->list_objects($class->type)) { 277 my $obj = $base->get_object($class->type, $_) or next; 278 my $id = $obj->get_c_field($field) or next; 279 $existsid{$id} = 1; 280 } 281 for(my $i = $min; $i <= $max; $i++) { 282 $existsid{$i} or return $i; 283 } 284 return; 285 } 286 267 287 1; 268 288 -
LATMOS-Accounts/sample/latmos-account.ini
r24 r137 5 5 # The master base, if unset the first one 6 6 base = latmosc 7 # Default synchro to apply 8 sync = name 9 10 [_defattr_] 11 # default attribute/value to set 12 # OBJECT.ATTR = value 13 # user.min_uid is min uid for automatic assigment 14 # user.max_uid is max uid for automatic assigment 15 # group.min_gid is min gid for automatic assigment 16 # group.max_gid is max gid for automatic assigment 7 17 8 18 # An accounts base: … … 17 27 [unix] 18 28 type=unix 29 30 # A synchronisation definition 31 [sync:name] 32 # source 33 from = base1 34 # destination, can be multiple 35 to = unix 36 #to = others
Note: See TracChangeset
for help on using the changeset viewer.