diff options
author | Steve Langasek <vorlon@debian.org> | 2009-01-07 21:36:50 -0800 |
---|---|---|
committer | Steve Langasek <steve.langasek@ubuntu.com> | 2019-01-03 17:28:29 -0800 |
commit | b4334959bfb64067fe1c9ed5ae143df05e66a001 (patch) | |
tree | 6c92a9fa1d3bee4c0b6b885e19d1b3e156a3c223 /debian/local | |
parent | 4456ce6011a0b5551c8577a837475b369ce56d86 (diff) | |
download | pam-b4334959bfb64067fe1c9ed5ae143df05e66a001.tar.gz pam-b4334959bfb64067fe1c9ed5ae143df05e66a001.tar.bz2 pam-b4334959bfb64067fe1c9ed5ae143df05e66a001.zip |
factor out the duplicate code used for returning the lines for a given module
Diffstat (limited to 'debian/local')
-rwxr-xr-x | debian/local/pam-auth-update | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/debian/local/pam-auth-update b/debian/local/pam-auth-update index 760e9aa5..4a3bd9f8 100755 --- a/debian/local/pam-auth-update +++ b/debian/local/pam-auth-update @@ -254,6 +254,16 @@ sub merge_one_line return $modline . " " . join(' ',@opts,keys(%{$adds})) . "\n"; } +# return the lines for a given config name, type, and position in the stack +sub lines_for_module_and_type +{ + my ($profiles, $mod, $type, $modpos) = @_; + if ($modpos == 0 && $profiles->{$mod}{$type . '-Initial'}) { + return $profiles->{$mod}{$type . '-Initial'}; + } + return $profiles->{$mod}{$type}; +} + # create a single PAM config from the indicated template and selections, # writing to a new file sub create_from_template @@ -303,13 +313,7 @@ sub create_from_template my $output; next if (!$profiles->{$mod}{$uctype . '-Type'}); next if $profiles->{$mod}{$uctype . '-Type'} ne $val; - if ($i++ == 0 - && $profiles->{$mod}{$uctype . '-Initial'}) - { - $output = $profiles->{$mod}{$uctype . '-Initial'}; - } else { - $output = $profiles->{$mod}{$uctype}; - } + $output = lines_for_module_and_type($profiles, $mod, $uctype, $i++); # bypasses a perl warning about @_, sigh my @tmparr = split("\n+",$output); $count += @tmparr; @@ -332,13 +336,7 @@ sub create_from_template my @output; next if (!$profiles->{$mod}{$uctype . '-Type'}); next if $profiles->{$mod}{$uctype . '-Type'} ne $val; - if ($i++ == 0 - && $profiles->{$mod}{$uctype . '-Initial'}) - { - $output = $profiles->{$mod}{$uctype . '-Initial'}; - } else { - $output = $profiles->{$mod}{$uctype}; - } + $output = lines_for_module_and_type($profiles, $mod, $uctype, $i++); for my $line (split("\n",$output)) { $line = merge_one_line($line,$diff, $count); @@ -474,12 +472,7 @@ sub write_profiles next if (!$profiles->{$mod}{$uctype . '-Type'}); next if ($profiles->{$mod}{$uctype . '-Type'} eq 'Additional'); - if ($i++ == 0 && $profiles->{$mod}{$uctype . '-Initial'}) - { - $output = $profiles->{$mod}{$uctype . '-Initial'}; - } else { - $output = $profiles->{$mod}{$uctype}; - } + $output = lines_for_module_and_type($profiles, $mod, $uctype, $i++); if ($output) { print OUTPUT "Module: $mod\n"; print OUTPUT $output . "\n"; @@ -499,12 +492,7 @@ sub write_profiles next if (!$profiles->{$mod}{$uctype . '-Type'}); next if ($profiles->{$mod}{$uctype . '-Type'} eq 'Primary'); - if ($i++ == 0 && $profiles->{$mod}{$uctype . '-Initial'}) - { - $output = $profiles->{$mod}{$uctype . '-Initial'}; - } else { - $output = $profiles->{$mod}{$uctype}; - } + $output = lines_for_module_and_type($profiles, $mod, $uctype, $i++); if ($output) { print OUTPUT "Module: $mod\n"; print OUTPUT $output . "\n"; |