blib/script/copy-links-from-users

filter: Statementstmt 29.7% 14 / 47 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod n/a totaltotal 19.5% 17 / 87 CC 4 SCAR 17.0
CC
4
Cov
18%
__ANON__
12.0
__ANON__
6.0
__ANON__
2.0
CRAP 5.5
« blib/lib/LWP/FastRobot.pm ↑ Summary blib/lib/LWP/Auth_UA.pm »
1 #!/usr/local/bin/perl
2  
3 =head1 NAME
4  
5 copy-links-from-users - get link files for use by link-controller
6  
7 =head1 SYNOPSIS
8  
9 copy-links-from-users [options] username.. destfile
10  
11 =head1 DESCRIPTION
12  
13 This program is designed to check through all of the user's
14 directories and get lists of links which can then used to build a
15 central link database using C<extract-links>
16  
17 B<--user>
18  
19 B<--group>
20  
21 =head1 NOTES
22  
23 This program has not been audited at all for security yet and isn't
24 safe to run as root. In the long term, the aim is that this should be
25 safe to run as root. However, even so, you should not do that!!! It
26 will work better if run as a normal user.
27  
28 =head1 SEE ALSO
29  
30 L<default-install>
31  
32 L<verify-link-control(1)>; L<extract-links(1)>; L<build-schedule>
33 L<link-report(1)>; L<fix-link(1)>; L<link-report.cgi(1)>; L<fix-link.cgi>
34 L<suggest(1)>; L<link-report.cgi(1)>; L<configure-link-control>
35  
36 The LinkController manual in the distribution in HTML, info, or
37 postscript formats, included in the distribution.
38  
39 http://scotclimb.org.uk/software/linkcont - the
40 LinkController homepage.
41  
42 =cut
43  
44 2 $::start_time = time();
45 2 $::earliest_modtime=0;
46 2 ▶use Getopt::Function; #don't need yet qw(maketrue makevalue);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 sub group;
49  
50 {
51 2 my $opened=0;
52 $::opthandler = new Getopt::Function
53 [ "version V>version",
54 "usage h>usage help>usage",
55 "help-opt=s",
56 "verbose:i v>verbose",
57 "group=s g>group",
58 "output-file=s",
59 ], {
60 #not used.. they should use @ARGV..
61 0 ▶ user => [ sub { $users{$::value}=1; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 "copy links from the given username",
63 "USERNAME"],
64 0 ▶ max-age => [ sub {$::earliest_modtime=$start_time
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 - $::value * 60*60*24; },
66 "Maximum age for files to be collected (0=disable)",
67 "DAYS"],
68 group => [
69 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
70 0 my ($name,$passwd,$gid,$members) = getgrnam($::value);
71 0 ▶ die "Unknown group $::value" unless defined($gid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gid 0 0 0
72 0 foreach my $user (split / /, ($members)) {
73 0 $users{$user}=1;
74 }
75 },
76 "copy links from the given group name.",
77 "GROUP",
78 ],
79 #currently inactive
80 0 ▶ "output-file" => [ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
81 0 ▶ die "Only one output file supported. Use tee."
Branch: 1 branch
BranchTrueFalseTotal
if $opened 0 0 0
82 if $opened;
83 #not portable
84 0 open STOUT, "> ./$::value";
85 2 }, "File into which to gather links.",
86 "FILENAME"
87 ]
88 };
89 }
90 2 $::opthandler->std_opts;
91  
92 2 $::opthandler->check_opts;
93  
94 1 ▶sub usage() {
Subroutine usage: called CC=1 SCAR=0.0
95 1 print <<EOF;
96 copy-links-from-users [options] username [...]
97  
98 EOF
99 1 $::opthandler->list_opts;
100 1 print <<EOF;
101  
102 Copy links files from user's directories.
103 EOF
104 }
105  
106 1 ▶sub version() {
Subroutine version: called CC=1 SCAR=0.0
107 1 print <<'EOF';
108 copy-links-from-users version
109 $Id: copy-links-from-users.pl,v 1.3 2001/11/22 15:30:29 mikedlr Exp $
110 EOF
111 }
112  
113 0 foreach my $user (@ARGV) {
114 0 $users{"$user"} = 1;
115 }
116  
117 0 ▶die "no users given" unless keys(%users) ;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %users 0 0 0
118  
119 0 USER: foreach my $user ( keys (%users) ) {
120 0 ▶ print STDERR "considering copying from user $user\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
121 0 my ($uname,$upasswd,$uuid,$ugid, $uquota,$ucomment,$ugcos,$udir,
122 $ushell,$uexpire)
123 = getpwnam($user);
124 0 ▶ die "Unknown user $user" unless defined($uuid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uuid 0 0 0
125 0 ▶ die "User $user has UID < 100" if $uuid < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $uuid < 100 0 0 0
126 #FIXME arbitrary parameter (100) which is often wrong, e.g. on redhat where
127 #500 would be correct!!
128 #FIXME maybe we should. Just delete this line.
129  
130 0 my $link_file=$udir . '/.link-control-links';
131 0 ▶ if ( -e $link_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $link_file) 0 0 0
132 0 ▶ sysopen (USR_LNK_FILE, $link_file, $rdonly) || do {
Branch: 1 branch
BranchTrueFalseTotal
sysopen USR_LNK_FILE, $link_file, $rdonly or do { warn "couldn't open users link file for $user"; next USER } 0 0 0
133 0 warn "couldn't open users link file for $user";
134 0 next USER;
135 };
136 0 my ($fdev,$fino,$fmode,$fnlink,$fuid,$fgid,$frdev,$fsize,
137 $fatime,$fmtime,$fctime,$fblksize,$fblocks) = stat(USR_LNK_FILE);
138  
139 0 ▶ next USER if $::earliest_modtime && $fmtime < $::earliest_modtime ;
Branch: 1 branch
BranchTrueFalseTotal
if $earliest_modtime and $fmtime < $earliest_modtime 0 0 0
Condition0%0/3
$earliest_modtime and $fmtime < $earliest_modtime
!ll&&!rl&&r
000
MC/DC0%0/2
$earliest_modtime and $fmtime < $earliest_modtime
$earliest_modtime $fmtime < $earliest_modtime
Truth table0%0/3
A and B
A= $earliest_modtimeB= $fmtime < $earliest_modtime
ABresult
0X0
100
111
140  
141 #the target user must own the file. Anything else is his responsibility
142 0 ▶ $uuid != $fuid and do {warn "File $link_file not owned by $user";
Branch: 1 branch
BranchTrueFalseTotal
$uuid != $fuid and do { warn "File $link_file not owned by $user"; next USER } 0 0 0
143 0 next USER;};
144 0 ▶ print STDERR "$link_file will be copied \n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
145 0 print "#####################################################################\n";
146 0 print "#links from user $uname from file $link_file\n";
147 0 print "#####################################################################\n";
148  
149 #FIXME statistics?
150 0 ▶ while (<USR_LNK_FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline USR_LNK_FILE)) 0 0 0
151 0 ▶ print || die "print failed $!";
Branch: 1 branch
BranchTrueFalseTotal
print $_ or die "print failed $!" 0 0 0
152 }
153  
154 }
155 # we should only allow ourselves to open a file iff
156 # we have access to it (easy)
157 # the current user has access to it.
158 # FIXME ?? no other user has modification rights.
159 }
160  
161 0 ▶close STDIN or die "couldn't close stdin $!";
Branch: 1 branch
BranchTrueFalseTotal
close STDIN or die "couldn't close stdin $!" 0 0 0
162  
163  
« blib/lib/LWP/FastRobot.pm ↑ Summary blib/lib/LWP/Auth_UA.pm »