Changeset 137


Ignore:
Timestamp:
05/19/09 01:05:41 (15 years ago)
Author:
nanardon
Message:
  • manage default value
Location:
LATMOS-Accounts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts.pm

    r78 r137  
    4949    my ($self, $section) = @_; 
    5050    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    ); 
    5255    my $base = LATMOS::Accounts::Bases->new($type, %params, label => $section); 
    5356    $base->load or return; 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r122 r137  
    4242    $base->{_type} = lc($pclass); 
    4343    $base->{_label} = $options{label}; 
     44    $base->{defattr} = $options{defattr}; 
    4445    $base 
    4546} 
     
    177178    my ($self, $otype, $id, %cdata) = @_; 
    178179 
     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    } 
    179193    my %data; 
    180194    foreach my $cfield (keys %cdata) { 
     
    320334} 
    321335 
     336sub 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 
    3223421; 
    323343 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r122 r137  
    265265} 
    266266 
     267sub 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 
    2672871; 
    268288 
  • LATMOS-Accounts/sample/latmos-account.ini

    r24 r137  
    55# The master base, if unset the first one 
    66base = latmosc 
     7# Default synchro to apply 
     8sync = 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 
    717 
    818# An accounts base: 
     
    1727[unix] 
    1828type=unix 
     29 
     30# A synchronisation definition 
     31[sync:name] 
     32# source 
     33from = base1 
     34# destination, can be multiple 
     35to = unix 
     36#to = others 
Note: See TracChangeset for help on using the changeset viewer.