Changeset 861 for LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
- Timestamp:
- 12/02/11 11:42:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r818 r861 12 12 13 13 @ISA = qw(Exporter); 14 @EXPORT = qw(to_ascii exec_command );15 @EXPORT_OK = qw(to_ascii exec_command );14 @EXPORT = qw(to_ascii exec_command switch_user run_via_sudo); 15 @EXPORT_OK = qw(to_ascii exec_command switch_user run_via_sudo); 16 16 17 17 sub to_ascii { … … 21 21 $text =~ s/Å/oe/g; 22 22 $text =~ s/Ê/ae/g; 23 $text =~ tr {uà âÀÃÃÃçéÚêëÃÃÃÃïîÃÃÞöÎÃÃÌûÃà }24 {uaaaAAAceeeeEEEEiiIIoooOOuuUU };23 $text =~ tr {uà âÀÃÃÃçéÚêëÃÃÃÃïîÃÃÞöÎÃÃÌûÃÃÄ} 24 {uaaaAAAceeeeEEEEiiIIoooOOuuUUc}; 25 25 $text =~ s/([^[:ascii:]])/_/g; 26 26 $text … … 29 29 sub exec_command { 30 30 my ($command, $env) = @_; 31 my $rout = undef; 32 $rout = \$_[2] if(@_ > 2); 31 33 32 34 my @exec = ref $command … … 35 37 la_log(LA_DEBUG, 'running command `%s\'', join(' ', @exec)); 36 38 39 pipe(my $rh, my $wh); 37 40 my $pid = fork; 38 41 if (!defined($pid)) { … … 40 43 } elsif ($pid) { 41 44 # Father 45 close($wh); 46 my $header; 47 while (<$rh>) { 48 if ($rout) { 49 $$rout .= $_; 50 } else { 51 chomp; 52 if (!$header) { 53 $header = 1; 54 la_log(LA_NOTICE, "exec `%s'", join(' ', @exec)); 55 } 56 la_log(LA_NOTICE, "output: %s", $_); 57 } 58 } 42 59 waitpid($pid, 0); 43 60 if (my $exitstatus = $?) { … … 50 67 } else { 51 68 # Child 69 close($rh); 70 ( $ENV{LA_MODULE} ) = caller(); 52 71 foreach (keys %{ $env || {} }) { 53 72 $ENV{"LA_$_"} = $env->{$_}; 54 73 } 74 open(STDOUT, ">&=" . fileno($wh)); 75 open(STDERR, ">&=" . fileno($wh)); 55 76 exec(@exec); 56 77 exit($!); … … 78 99 } 79 100 } else { 80 $attributes{$attr} = $value || undef; 81 $attr eq 'exported' && !defined $attributes{$attr} and $attributes{$attr} = 1; 101 $attributes{$attr} = $value eq '' ? undef : $value; 102 # Don't remember why this is here 103 #$attr eq 'exported' && !defined $attributes{$attr} and $attributes{$attr} = 1; 82 104 } 83 105 } … … 129 151 if ($name !~ /^[a-z]/); 130 152 return "must contain only a-z,0-9" 131 if ($name !~ /^[a-z,0-9 ]+$/);153 if ($name !~ /^[a-z,0-9,_,-]+$/); 132 154 133 155 return check_oid_validity($name); 134 156 } 135 157 158 sub switch_user { 159 my ($runas) = @_; 160 161 if ($< == 0 || $> == 0) { 162 my @info = getpwnam($runas) or do { 163 warn "Can find user $runas"; 164 return; 165 }; 166 $> = $info[3]; 167 return; 168 } else { 169 warn "we are not root"; 170 } 171 } 172 173 sub run_via_sudo { 174 my ($runas) = @_; 175 176 my @info = getpwnam($runas) or do { 177 warn "Can find user $runas"; 178 return; 179 }; 180 if ($< != $info[3]) { 181 exec('sudo', '-u', $runas, $0, @ARGV) or "Can run $!"; 182 } 183 } 184 136 185 1;
Note: See TracChangeset
for help on using the changeset viewer.