- Timestamp:
- 07/24/12 22:56:06 (12 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/MANIFEST
r1048 r1071 123 123 sqldata/attributes.csv 124 124 sqldata/base.sql 125 man/man8/latmos-accounts-base-sql.pod 125 126 t/05_utils.t 126 127 t/06_cli.t -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts.pm
r1058 r1071 137 137 my ($self, $section) = @_; 138 138 my $type = $self->val($section, 'type') or return; 139 my %params = ( 140 map { $_ => ($self->val($section, $_)) } $self->Parameters($section), 141 defattr => { map { $_ => ($self->val('_defattr_', $_)) } $self->Parameters('_defattr_') }, 142 ); 139 140 my %params = 141 map { $_ => ($self->val($section, $_)) } 142 $self->Parameters($section); 143 144 my %defattr = 145 map { $_ => ($self->val('_defattr_', $_)) } 146 $self->Parameters('_defattr_'); 147 143 148 my $base = LATMOS::Accounts::Bases->new( 144 149 $type, 145 %params, 146 label => $section, 147 acls => $self->{_acls}, 148 allowed_values => $self->{_allowed_values}, 149 configdir => $self->_configdir, 150 _la => $self, 150 { 151 params => \%params, 152 label => $section, 153 acls => $self->{_acls}, 154 allowed_values => $self->{_allowed_values}, 155 configdir => $self->_configdir, 156 la => $self, 157 defattr => { %defattr }, 158 }, 151 159 ) or do { 152 160 la_log(LA_WARN, "Cannot instanciate base $section ($type)"); -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r1070 r1071 37 37 38 38 sub new { 39 my ($class, $type, %options) = @_;39 my ($class, $type, $options) = @_; 40 40 41 41 my $pclass = ucfirst(lc($type)); 42 42 eval "require LATMOS::Accounts::Bases::$pclass;"; 43 43 if ($@) { return } # error message ? 44 my $base = "LATMOS::Accounts::Bases::$pclass"->new(% options)44 my $base = "LATMOS::Accounts::Bases::$pclass"->new(%{$options->{params}}) 45 45 or return; 46 46 $base->{_type} = lc($pclass); 47 $base->{_label} = $options {label};48 $base->{_options} = { %options};47 $base->{_label} = $options->{label}; 48 $base->{_options} = $options->{params}; 49 49 $base->{wexported} = 0; 50 $base->{defattr} = $options {defattr};51 $base->{_acls} = $options {acls};52 $base->{_allowed_values} = $options {allowed_values};53 $base->{_la} = $options {_la};54 la_log(LA_DEBUG, 'Instanciate base %s (%s)', ($ options{label}|| 'N/A'), $pclass);50 $base->{defattr} = $options->{defattr}; 51 $base->{_acls} = $options->{acls}; 52 $base->{_allowed_values} = $options->{allowed_values}; 53 $base->{_la} = $options->{la}; 54 la_log(LA_DEBUG, 'Instanciate base %s (%s)', ($base->label || 'N/A'), $pclass); 55 55 $base 56 56 } … … 121 121 sub la { $_[0]->{_la} }; 122 122 123 =head2 options($opt)123 =head2 config ($opt) 124 124 125 125 Return options from config … … 127 127 =cut 128 128 129 sub options{129 sub config { 130 130 my ($self, $opt) = @_; 131 131 return $self->{_options}{$opt}; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad.pm
r1038 r1071 38 38 =cut 39 39 40 =head2 new(% options)40 =head2 new(%config) 41 41 42 42 Create a new LATMOS::Ad object for windows AD $domain. 43 43 44 options:44 config: 45 45 46 46 =over 4 … … 69 69 70 70 sub new { 71 my ($class, % options) = @_;71 my ($class, %config) = @_; 72 72 73 $ options{domain} or do {73 $config{domain} or do { 74 74 la_log(LA_ERR, 75 75 "Cannot instanciate base %s w/o domain name", 76 $ options{label} || '(unknown label)'76 $config{label} || '(unknown label)' 77 77 ); 78 78 return; … … 80 80 81 81 my $self = { 82 _server => $options{server}, 83 _ad_domain => $options{domain}, 84 _top_dn => join(',', map { "dc=$_" } split('\.', $options{domain})), 85 _login => $options{login}, 86 _password => $options{password}, 87 _ssl => $options{ssl}, 82 _top_dn => join(',', map { "dc=$_" } split('\.', $config{domain})), 88 83 }; 89 84 … … 100 95 101 96 my $ldap; 102 my @ldapservers = ($self-> {_server}103 ? ($self->_ldap_url($self-> {_server}))97 my @ldapservers = ($self->config('server') 98 ? ($self->_ldap_url($self->config('server'))) 104 99 : ($self->_query_zone_ads)) or do { 105 100 la_log(LA_ERR, … … 121 116 }; 122 117 123 my $login = $self-> {_login};118 my $login = $self->config('login'); 124 119 $login =~ m/@/ or $login .= '@' . $self->ad_domain; 125 120 126 my $msg = $ldap->bind($login, password => $self-> {_password});121 my $msg = $ldap->bind($login, password => $self->config('password')); 127 122 $msg->code and do { 128 123 $self->log(LA_ERR, "Cannot bind ldap: %s", $msg->error); … … 158 153 159 154 sub ad_domain { 160 return $_[0]-> {_ad_domain}155 return $_[0]->config('ad_domain') 161 156 } 162 157 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Dummy.pm
r1023 r1071 18 18 19 19 sub new { 20 my ($class, % options) = @_;20 my ($class, %config) = @_; 21 21 bless {}, $class; 22 22 } -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Heimdal.pm
r1037 r1071 32 32 =cut 33 33 34 =head2 new(% options)34 =head2 new(%config) 35 35 36 36 Create a new LATMOS::Ldap object for windows AD $domain. 37 37 38 options:38 config: 39 39 40 40 =over 4 … … 73 73 74 74 sub new { 75 my ($class, % options) = @_;75 my ($class, %config) = @_; 76 76 77 77 bless({}, $class); … … 84 84 $self->{_heimdal} and return 1; 85 85 86 if (!$self-> options('realm')) {87 if ($self-> options('domain')) {88 $self->{_ options}{realm} = $self->_domain2realm or do {86 if (!$self->config('realm')) { 87 if ($self->config('domain')) { 88 $self->{_config}{realm} = $self->_domain2realm or do { 89 89 $self->log(LA_ERR, 90 90 'Cannot find kerberos TXT record for domain `%s\'', 91 $self-> options('domain'),91 $self->config('domain'), 92 92 ); 93 93 return; 94 94 }; 95 $self->log(LA_DEBUG, 'kerberos REALM is %s', $self-> options('realm'));95 $self->log(LA_DEBUG, 'kerberos REALM is %s', $self->config('realm')); 96 96 } else { 97 97 # No way to find realm … … 99 99 } 100 100 } 101 my @servers = $self-> options('server')102 ? ($self-> options('server'))103 : $self-> options('domain')101 my @servers = $self->config('server') 102 ? ($self->config('server')) 103 : $self->config('domain') 104 104 ? $self->_domain2server 105 105 : (); … … 118 118 # Port => '8899', 119 119 # Required: 120 Principal => $self-> options('login'),121 Realm => $self-> options('realm'),120 Principal => $self->config('login'), 121 Realm => $self->config('realm'), 122 122 # --- Either --- 123 Password => $self-> options('password'),123 Password => $self->config('password'), 124 124 # --- Or --- 125 # Keytab => $self-> options('keytab'),125 # Keytab => $self->config('keytab'), 126 126 ); 127 127 … … 150 150 151 151 my $resolver = Net::DNS::Resolver->new; 152 my $query = $resolver->query("_kerberos-adm._tcp." . $self-> options('domain'),152 my $query = $resolver->query("_kerberos-adm._tcp." . $self->config('domain'), 153 153 "SRV") or return; 154 154 foreach my $rr ( … … 166 166 my $resolver = Net::DNS::Resolver->new; 167 167 my $query = $resolver->query( 168 "_kerberos." . $self-> options('domain'),168 "_kerberos." . $self->config('domain'), 169 169 "TXT") or return; 170 170 foreach my $rr ($query->answer) { -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Heimdal/User.pm
r1037 r1071 58 58 59 59 $uid eq 'default' and return 1; 60 grep { $uid eq $_ } split(/ *, */, $base-> options('ignoredusers'))60 grep { $uid eq $_ } split(/ *, */, $base->config('ignoredusers')) 61 61 and return 1; 62 62 … … 67 67 my ($class, $base) = @_; 68 68 69 my $realm = $base-> options('realm');69 my $realm = $base->config('realm'); 70 70 my @uids; 71 71 foreach ($base->heimdal->getPrincipals('*@' . $realm)) { … … 90 90 my $ba = $base || $self->base; 91 91 $uid ||= $self->id; 92 return $uid . '@' . $ba-> options('realm');92 return $uid . '@' . $ba->config('realm'); 93 93 } 94 94 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap.pm
r1037 r1071 38 38 =cut 39 39 40 =head2 new(% options)40 =head2 new(%config) 41 41 42 42 Create a new LATMOS::Ldap object for windows AD $domain. 43 43 44 options:44 config: 45 45 46 46 =over 4 … … 69 69 70 70 sub new { 71 my ($class, % options) = @_;71 my ($class, %config) = @_; 72 72 73 73 my $self = { 74 _server => $options{server}, 75 _top_dn => $options{topdn}, 76 _login => $options{login}, 77 _password => $options{password}, 78 _ssl => $options{ssl}, 74 _top_dn => $config{topdn}, 79 75 }; 80 76 … … 91 87 my ($self, $otype) = @_; 92 88 return join(',', 93 ($self-> options($otype . '_container') || 'cn=Users'),89 ($self->config($otype . '_container') || 'cn=Users'), 94 90 $self->top_dn, 95 91 ); … … 102 98 $self->{_ldap} and return 1; 103 99 104 my $ldapurl = $self->_ldap_url($self-> {_server});100 my $ldapurl = $self->_ldap_url($self->config('server')); 105 101 my $ldap = Net::LDAP->new($ldapurl); 106 102 … … 114 110 115 111 116 my $msg = $ldap->bind($self-> {_login}, password => $self->{_password});112 my $msg = $ldap->bind($self->config('login'), password => $self->config('password')); 117 113 $msg->code and do { 118 114 $self->log(LA_ERR, "Cannot bind ldap: %s", $msg->error); … … 129 125 sprintf( 130 126 '%s://%s%s/', 131 $self-> {_ssl}? 'ldaps' : 'ldap',127 $self->config('ssl') ? 'ldaps' : 'ldap', 132 128 $host, 133 129 $port ? ":$port" : '', -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap/Onlyaddress.pm
r1037 r1071 79 79 sub is_supported { 80 80 my ($class, $base) = @_; 81 return $base-> options('onlyaddress_container') ? 1 : 0;81 return $base->config('onlyaddress_container') ? 1 : 0; 82 82 } 83 83 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Mail.pm
r1023 r1071 24 24 25 25 sub new { 26 my ($class, % options) = @_;26 my ($class, %config) = @_; 27 27 28 28 my $base = { … … 33 33 34 34 foreach (qw(aliases revaliases)) { 35 if ($ options{$_}) {36 $base->{file}{$_} = $ options{$_};37 } elsif ($ options{directory}) {38 $base->{file}{$_} = $ options{directory} . '/' . $_;35 if ($config{$_}) { 36 $base->{file}{$_} = $config{$_}; 37 } elsif ($config{directory}) { 38 $base->{file}{$_} = $config{directory} . '/' . $_; 39 39 } else { 40 40 $base->{file}{$_} = "/etc/$_"; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r1023 r1071 550 550 } 551 551 552 =head2 text_dump ($handle, $ options, $base)552 =head2 text_dump ($handle, $config, $base) 553 553 554 554 Dump object into C<$handle> … … 557 557 558 558 sub text_dump { 559 my ($self, $handle, $ options, $base) = @_;560 print $handle $self->dump($ options, $base);559 my ($self, $handle, $config, $base) = @_; 560 print $handle $self->dump($config, $base); 561 561 return 1; 562 562 } … … 569 569 570 570 sub dump { 571 my ($self, $ options, $base) = @_;571 my ($self, $config, $base) = @_; 572 572 573 573 my $otype = $self->type; … … 581 581 582 582 foreach my $attr (sort { $a cmp $b } $base->list_canonical_fields($otype, 583 $ options->{only_rw} ? 'rw' : 'r')) {583 $config->{only_rw} ? 'rw' : 'r')) { 584 584 my $oattr = $base->attribute($otype, $attr); 585 585 if (ref $self) { 586 586 my $val = $self->get_c_field($attr); 587 if ($val || $ options->{empty_attr}) {587 if ($val || $config->{empty_attr}) { 588 588 if (my @allowed = $base->obj_attr_allowed_values($otype, $attr)) { 589 589 $dump .= sprintf("# %s must be%s: %s\n", -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r1023 r1071 36 36 =cut 37 37 38 =head2 new(% options)38 =head2 new(%config) 39 39 40 40 Create a new LATMOS::Ad object for windows AD $domain. … … 47 47 48 48 sub new { 49 my ($class, % options) = @_;49 my ($class, %config) = @_; 50 50 51 51 my $base = { 52 db_conn => $ options{db_conn},52 db_conn => $config{db_conn}, 53 53 }; 54 54 … … 324 324 } 325 325 326 =head2 rename_nethost ($nethostname, $to, % options)326 =head2 rename_nethost ($nethostname, $to, %config) 327 327 328 328 Facility function to rename computer to new name … … 331 331 332 332 sub rename_nethost { 333 my ($self, $nethostname, $to, % options) = @_;333 my ($self, $nethostname, $to, %config) = @_; 334 334 { 335 335 my $obj = $self->get_object('nethost', $nethostname); … … 339 339 } 340 340 $self->rename_object('nethost', $nethostname, $to) or return; 341 if ($ options{'addcname'}) {341 if ($config{'addcname'}) { 342 342 my $obj = $self->get_object('nethost', $to); 343 343 my @cname = grep { $_ } $obj->get_attributes('cname'); -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/DataRequest.pm
r1023 r1071 222 222 } 223 223 224 =head2 register ($ options, %info)224 =head2 register ($config, %info) 225 225 226 226 Register the form. C<%info> must contains submitted informations. 227 227 228 C<$ options> is a hashref where228 C<$config> is a hashref where 229 229 230 230 =over 4 … … 247 247 248 248 sub register { 249 my ($self, $ options, %param) = @_;250 251 my $user = $ options->{user};252 my $apply = $ options->{apply};253 my $auto = $ options->{auto};249 my ($self, $config, %param) = @_; 250 251 my $user = $config->{user}; 252 my $apply = $config->{apply}; 253 my $auto = $config->{auto}; 254 254 255 255 my $rev; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Revaliases.pm
r1023 r1071 28 28 =cut 29 29 30 =head2 new(% options)30 =head2 new(%config) 31 31 32 32 Create a new LATMOS::Ad object for windows AD $domain. -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r1014 r1071 23 23 =cut 24 24 25 =head2 new(% options)25 =head2 new(%config) 26 26 27 27 Create a new LATMOS::Ad object for windows AD $domain. -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm
r861 r1071 29 29 =cut 30 30 31 =head2 new(% options)31 =head2 new(%config) 32 32 33 33 Create a new LATMOS::Ad object for windows AD $domain. … … 40 40 41 41 sub new { 42 my ($class, % options) = @_;42 my ($class, %config) = @_; 43 43 44 44 my $base = { 45 45 # are we using shadow, default to yes 46 use_shadow => (defined($ options{use_shadow}) ? $options{use_shadow} : 1),47 min_gid => $ options{min_gid},48 min_uid => $ options{min_uid},49 nis_overflow => ($ options{nis_overflow} || ''),46 use_shadow => (defined($config{use_shadow}) ? $config{use_shadow} : 1), 47 min_gid => $config{min_gid}, 48 min_uid => $config{min_uid}, 49 nis_overflow => ($config{nis_overflow} || ''), 50 50 users => {}, 51 51 groups => {}, … … 53 53 54 54 foreach (qw(passwd shadow group gshadow)) { 55 if ($ options{$_}) {56 $base->{$_} = $ options{$_};57 } elsif ($ options{directory}) {58 $base->{$_} = $ options{directory} . '/' . $_;55 if ($config{$_}) { 56 $base->{$_} = $config{$_}; 57 } elsif ($config{directory}) { 58 $base->{$_} = $config{directory} . '/' . $_; 59 59 } else { 60 60 $base->{$_} = "/etc/$_"; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix/Group.pm
r1014 r1071 46 46 } 47 47 48 =head2 new(% options)48 =head2 new(%config) 49 49 50 50 Create a new LATMOS::Ad object for windows AD $domain. -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix/User.pm
r1023 r1071 67 67 } 68 68 69 =head2 new(% options)69 =head2 new(%config) 70 70 71 71 =cut -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm
r1023 r1071 405 405 406 406 foreach my $base ($self->to) { 407 if ($base-> options('presynchro')) {407 if ($base->config('presynchro')) { 408 408 la_log LA_DEBUG, "Executing base pre synchro `%s' for %s", 409 $base-> options('presynchro'), $base->label;409 $base->config('presynchro'), $base->label; 410 410 exec_command( 411 $base-> options('presynchro'),411 $base->config('presynchro'), 412 412 { 413 413 BASE => $base->label, … … 439 439 440 440 foreach my $base ($self->to) { 441 if ($base-> options('postsynchro')) {441 if ($base->config('postsynchro')) { 442 442 la_log LA_DEBUG, "Executing base post synchro `%s' for %s", 443 $base-> options('postsynchro'), $base->label;443 $base->config('postsynchro'), $base->label; 444 444 exec_command( 445 $base-> options('postsynchro'),445 $base->config('postsynchro'), 446 446 { 447 447 BASE => $base->label, -
trunk/LATMOS-Accounts/t/11_bases_unix.t
r861 r1071 18 18 ok(my $unixb = LATMOS::Accounts::Bases->new( 19 19 'unix', 20 passwd => "$dir/passwd", 21 shadow => "$dir/shadow", 22 group => "$dir/group", 23 gshadow => "$dir/gshadow", 20 { params => { 21 passwd => "$dir/passwd", 22 shadow => "$dir/shadow", 23 group => "$dir/group", 24 gshadow => "$dir/gshadow", 25 } } 24 26 ), "Can get unix base"); 25 27 isa_ok($unixb, 'LATMOS::Accounts::Bases'); … … 52 54 ok(my $unixbmod = LATMOS::Accounts::Bases->new( 53 55 'unix', 56 { params => { 54 57 passwd => "$dir/passwd", 55 58 shadow => "$dir/shadow", 56 59 group => "$dir/group", 57 60 gshadow => "$dir/gshadow", 61 } } 58 62 ), "Can get unix base"); 59 63 ok($unixbmod->load, "Can load saved db"); -
trunk/LATMOS-Accounts/t/15_bases_mail.t
r861 r1071 18 18 ok(my $mailb = LATMOS::Accounts::Bases->new( 19 19 'mail', 20 aliases => "$dir/aliases", 21 revaliases => "$dir/revaliases", 20 { 21 params => { 22 aliases => "$dir/aliases", 23 revaliases => "$dir/revaliases", 24 }} 22 25 ), "Can get mail base"); 23 26 … … 41 44 ok(my $mailbmod = LATMOS::Accounts::Bases->new( 42 45 'mail', 46 { params => { 43 47 aliases => "$dir/aliases", 44 48 revaliases => "$dir/revaliases", 49 }} 45 50 ), "Can get mail base"); 46 51 -
trunk/LATMOS-Accounts/t/25_la_synchro.t
r861 r1071 49 49 ok(my $unixb = LATMOS::Accounts::Bases->new( 50 50 'unix', 51 passwd => "$workdir/passwd", 52 shadow => "$workdir/shadow", 53 group => "$workdir/group", 54 gshadow => "$workdir/gshadow", 51 { 52 params => { 53 passwd => "$workdir/passwd", 54 shadow => "$workdir/shadow", 55 group => "$workdir/group", 56 gshadow => "$workdir/gshadow", 57 } 58 } 55 59 ), "Can get unix base"); 56 60 isa_ok($unixb, 'LATMOS::Accounts::Bases::Unix');
Note: See TracChangeset
for help on using the changeset viewer.