File: suid2stat

package info (click to toggle)
suidmanager 0.52
  • links: PTS
  • area: main
  • in suites: woody
  • size: 52 kB
  • sloc: sh: 47; perl: 34; makefile: 27
file content (45 lines) | stat: -rwxr-xr-x 1,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w
#
# Import suid.conf file into dpkg-statoverride database.
# Remove the file if the conversion is successful.
#
use strict;
my $file=shift || die "Usage: $0 suid.conf";

my $keepfile=0;
my @out;

open (IN, "<$file") or die "read $file: $!";
while (<IN>) {
	if (m/^\w*#/) {
		push @out, $_;
		next;
	}
	
	chomp;
	my ($sm_pkg,$sm_file,$sm_user,$sm_group, $sm_mode)=split;
	$sm_user="#$sm_user" if ($sm_user =~ m/^\d*$/);
	$sm_group="#$sm_group" if ($sm_group =~ m/^\d*$/);

	if ($sm_pkg eq 'user' or $sm_pkg eq 'local') {
		if (system('dpkg-statoverride', '--add',
		    $sm_user, $sm_group, $sm_mode, $sm_file) != 0) {
		    	# Don't remove from file; there is a conflict.
			push @out, $_."\n";
			$keepfile=1;
		}
	}
}

if ($keepfile && @out) {
	open (OUT, ">$file") or die "write $file: $!";
	foreach (@out) {
		print OUT $_;
	}
	close OUT;
	print STDERR "Error converting some entries in $file; those\n";
	print STDERR "entries remain in $file. Please deal with this by hand\n";
}
else {
	unlink $file or die "unlink $file: $!";
}