Changeset 683
- Timestamp:
- 01/21/10 01:06:46 (14 years ago)
- Location:
- LATMOS-Accounts
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts.pm
r623 r683 48 48 }; 49 49 $self->{_acls} = $acls; 50 } 51 52 if ($self->val('_default_', 'allowed_values')) { 53 $self->{_allowed_values} = Config::IniFiles->new( 54 -file => $self->val('_default_', 'allowed_values'), 55 -allowempty => 1, 56 ) or do { 57 return; 58 }; 59 } else { 60 $self->{_allowed_values} = Config::IniFiles->new(); 50 61 } 51 62 … … 143 154 label => $section, 144 155 acls => $self->{_acls}, 156 allowed_values => $self->{_allowed_values}, 145 157 ) or do { 146 158 la_log(LA_WARN, "Cannot instanciate base $section ($type)"); -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r679 r683 48 48 $base->{defattr} = $options{defattr}; 49 49 $base->{_acls} = $options{acls}; 50 $base->{_allowed_values} = $options{allowed_values}; 50 51 la_log(LA_DEBUG, 'Instanciate base %s (%s)', ($options{label} || 'N/A'), $pclass); 51 52 $base … … 75 76 sub type { 76 77 $_[0]->{_type}; 78 } 79 80 sub allowed_values { 81 $_[0]->{_allowed_values} 82 } 83 84 sub check_allowed_values { 85 my ($self, $otype, $attr, $attrvalues) = @_; 86 my @values = ref $attrvalues ? @{ $attrvalues } : $attrvalues; 87 foreach my $value (@values) { 88 $value or next; 89 if (my @allowed = $self->allowed_values->val("$otype.$attr", 'allowed')) { 90 grep { $value eq $_ } @allowed or do { 91 $self->log(LA_ERR, 92 "value `%s' is not allow for %s.%s per configuration (allowed_values)", 93 $value, $otype, $attr 94 ); 95 return; 96 }; 97 } 98 } 99 return 1; 77 100 } 78 101 … … 237 260 return; 238 261 } 262 foreach my $cfield (keys %cdata) { 263 $self->check_allowed_values($otype, $cfield, $cdata{$cfield}) or do { 264 $self->log(LA_ERR, "Cannot create $otype, wrong value"); 265 return; 266 }; 267 } 268 239 269 $self->_create_c_object($otype, $id, %cdata); 240 270 } -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r675 r683 253 253 =cut 254 254 255 sub check_allowed_values { 256 my ($self, $attr, $values) = @_; 257 $self->base->check_allowed_values($self->type, $attr, $values); 258 } 259 255 260 =head2 set_c_fields(%data) 256 261 … … 262 267 sub set_c_fields { 263 268 my ($self, %cdata) = @_; 264 my %data;265 269 eval { 266 270 foreach my $cfield (keys %cdata) { 267 271 $self->base->check_acl($self, $cfield, 'w') or 268 die "permission denied"; 272 die "permission denied\n"; 273 } 274 275 foreach my $cfield (keys %cdata) { 276 $self->check_allowed_values($cfield, $cdata{$cfield}) or 277 die "incorrect attribute\n"; 269 278 } 270 279 }; 271 return if($@); 280 if($@) { 281 $self->base->log(LA_ERR, "Cannot modified %s/%s: %s", 282 $self->type, $self->id, $@ 283 ); 284 return; 285 } 272 286 $self->_set_c_fields(%cdata); 273 287 } -
LATMOS-Accounts/sample/latmos-account.ini
r562 r683 9 9 # The acls file to use to limit access 10 10 #acls = 11 # An inifile containing per attributes values restriction 12 # allowed_values = 11 13 # smtp: the server used to send mail 12 14 smtp = localhost
Note: See TracChangeset
for help on using the changeset viewer.