summaryrefslogtreecommitdiff
path: root/debian/local/pam-auth-update
diff options
context:
space:
mode:
authorSteve Langasek <vorlon@debian.org>2008-08-03 22:44:23 -0700
committerSteve Langasek <steve.langasek@ubuntu.com>2019-01-03 17:28:23 -0800
commitaaedf7c7f0cc87f3a4ed8c65d437747e52b20512 (patch)
tree5bdfc9bce0a9578ed7a579792511d44597db8dce /debian/local/pam-auth-update
parent1b6b036a2730bb85d633d474263916a387a20e6f (diff)
first attempt at handling conflicts among the selected profiles
Diffstat (limited to 'debian/local/pam-auth-update')
-rwxr-xr-xdebian/local/pam-auth-update42
1 files changed, 37 insertions, 5 deletions
diff --git a/debian/local/pam-auth-update b/debian/local/pam-auth-update
index bbb1a876..ddb6cfbd 100755
--- a/debian/local/pam-auth-update
+++ b/debian/local/pam-auth-update
@@ -32,7 +32,8 @@ my $capb=capb('backup');
my $inputdir = '/usr/share/pam-configs';
my $template = 'libpam-runtime/profiles';
-my (%profiles, @sorted, @enabled);
+my $errtemplate = 'libpam-runtime/conflicts';
+my (%profiles, @sorted, @enabled, @conflicts);
opendir(DIR, $inputdir) || die "could not open config directory: $!";
while (my $profile = readdir(DIR)) {
@@ -42,6 +43,9 @@ while (my $profile = readdir(DIR)) {
closedir DIR;
x_loadtemplatefile('/var/lib/dpkg/info/libpam-runtime.templates','libpam-runtime');
+
+# always sort by priority, so we have consistency and don't have to
+# shuffle later
@sorted = sort { $profiles{$b}->{'Priority'} <=> $profiles{$a}->{'Priority'} }
keys(%profiles);
subst($template, 'profile_names', join(', ',@sorted));
@@ -53,10 +57,36 @@ subst($template, 'profiles',
fset($template,'seen','false');
set($template,
join(', ', grep { $profiles{$_}->{'Default'} eq 'yes' } @sorted));
-input('high',$template);
-go();
-@enabled = split(/, /, get($template));
+do {
+ @conflicts = ();
+ input('high',$template);
+ go();
+
+ @enabled = split(/, /, get($template));
+
+ # in case of conflicts, automatically unset the lower priority
+ # item of each pair
+ foreach my $elem (@enabled)
+ {
+ for (my $i=$#enabled; $i >= 0; $i--)
+ {
+ my $conflict = $enabled[$i];
+ if ($profiles{$elem}->{'Conflicts'}->{$conflict}) {
+ splice(@enabled,$i,1);
+ my $desc = $profiles{$elem}->{'Name'}
+ . ', ' . $profiles{$conflict}->{'Name'};
+ push(@conflicts,$desc);
+ }
+ }
+ }
+ if (@conflicts) {
+ subst($errtemplate, 'conflicts', join("\n", @conflicts));
+ input('high',$errtemplate);
+ }
+ fset($template,'seen','false');
+ set($template, join(', ', @enabled));
+} while (@conflicts);
# simple function to parse a provided config file, in pseudo-RFC822
# format,
@@ -70,7 +100,9 @@ sub parse_pam_profile
if (/^(\S+):\s+(.*)$/) {
$fieldname = $1;
if ($fieldname eq 'Conflicts') {
- @{$profile{1}} = split(/, /, $2);
+ foreach my $elem (split(/, /, $2)) {
+ $profile{'Conflicts'}->{$elem} = 1;
+ }
} else {
$profile{$1} = $2;
}