| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Grips::Gripsrc.pm |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Copyright (c) 2002 DIMDI . All rights reserved. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or modify it under |
|
6
|
|
|
|
|
|
|
# the same terms as Perl itself, i.e. under the terms of either the GNU General |
|
7
|
|
|
|
|
|
|
# Public License or the Artistic License, as specified in the F file. |
|
8
|
|
|
|
|
|
|
package Grips::Gripsrc; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7803
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
56
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
12
|
1
|
|
|
1
|
|
1167
|
use FileHandle; |
|
|
1
|
|
|
|
|
14178
|
|
|
|
1
|
|
|
|
|
6
|
|
|
13
|
1
|
|
|
1
|
|
387
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1008
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$VERSION = "0.01"; # $Id: Gripsrc.pm,v 1.2 2003-02-04 12:19:08 ahmed Exp $ |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %gripsrc = (); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _readrc |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
0
|
|
|
0
|
|
|
my $host = shift; |
|
22
|
0
|
|
|
|
|
|
my($home,$file); |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if($^O eq "MacOS") { |
|
25
|
0
|
|
0
|
|
|
|
$home = $ENV{HOME} || `pwd`; |
|
26
|
0
|
|
|
|
|
|
chomp($home); |
|
27
|
0
|
0
|
|
|
|
|
$file = ($home =~ /:$/ ? $home . "gripsrc" : $home . ":gripsrc"); |
|
28
|
|
|
|
|
|
|
} else { |
|
29
|
|
|
|
|
|
|
# Some OS's don't have `getpwuid', so we default to $ENV{HOME} |
|
30
|
0
|
|
0
|
|
|
|
$home = eval { (getpwuid($>))[7] } || $ENV{HOME}; |
|
31
|
0
|
|
|
|
|
|
$file = $home . "/.gripsrc"; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $fh; |
|
35
|
0
|
|
|
|
|
|
local $_; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$gripsrc{default} = undef; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# OS/2 and Win32 do not handle stat in a way compatable with this check :-( |
|
40
|
0
|
0
|
0
|
|
|
|
unless($^O eq 'os2' |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|| $^O eq 'MSWin32' |
|
42
|
|
|
|
|
|
|
|| $^O eq 'MacOS' |
|
43
|
|
|
|
|
|
|
|| $^O =~ /^cygwin/) |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
0
|
|
|
|
|
|
my @stat = stat($file); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if(@stat) |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
0
|
0
|
|
|
|
|
if($stat[2] & 077) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
|
|
|
carp "Bad permissions: $file"; |
|
52
|
0
|
|
|
|
|
|
return; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
0
|
0
|
|
|
|
|
if($stat[4] != $<) |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
0
|
|
|
|
|
|
carp "Not owner: $file"; |
|
57
|
0
|
|
|
|
|
|
return; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if($fh = FileHandle->new($file,"r")) |
|
63
|
|
|
|
|
|
|
{ |
|
64
|
0
|
|
|
|
|
|
my($mach,$macdef,$tok,@tok) = (0,0); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
while(<$fh>) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
0
|
|
|
|
|
undef $macdef if /\A\n\Z/; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if($macdef) |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
|
|
|
|
|
push(@$macdef,$_); |
|
73
|
0
|
|
|
|
|
|
next; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
s/^\s*//; |
|
77
|
0
|
|
|
|
|
|
chomp; |
|
78
|
0
|
|
0
|
|
|
|
push(@tok, $+) |
|
79
|
|
|
|
|
|
|
while(length && s/^("([^"]*)"|(\S+))\s*//); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
TOKEN: |
|
82
|
0
|
|
|
|
|
|
while(@tok) |
|
83
|
|
|
|
|
|
|
{ |
|
84
|
0
|
0
|
|
|
|
|
if($tok[0] eq "default") |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
|
|
|
shift(@tok); |
|
87
|
0
|
|
|
|
|
|
$mach = bless {}; |
|
88
|
0
|
|
|
|
|
|
$gripsrc{default} = [$mach]; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
next TOKEN; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
last TOKEN |
|
94
|
0
|
0
|
|
|
|
|
unless @tok > 1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$tok = shift(@tok); |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if($tok eq "host") |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
{ |
|
100
|
0
|
|
|
|
|
|
my $host = shift @tok; |
|
101
|
0
|
|
|
|
|
|
$mach = bless {host => $host}; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$gripsrc{$host} = [] |
|
104
|
0
|
0
|
|
|
|
|
unless exists($gripsrc{$host}); |
|
105
|
0
|
|
|
|
|
|
push(@{$gripsrc{$host}}, $mach); |
|
|
0
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
elsif($tok =~ /^(id|user|pwd)$/) |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
0
|
0
|
|
|
|
|
next TOKEN unless $mach; |
|
110
|
0
|
|
|
|
|
|
my $value = shift @tok; |
|
111
|
|
|
|
|
|
|
# Following line added by rmerrell to remove '/' escape char in .gripsrc |
|
112
|
0
|
|
|
|
|
|
$value =~ s/\/\\/\\/g; |
|
113
|
0
|
|
|
|
|
|
$mach->{$1} = $value; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
elsif($tok eq "macdef") |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
0
|
0
|
|
|
|
|
next TOKEN unless $mach; |
|
118
|
0
|
|
|
|
|
|
my $value = shift @tok; |
|
119
|
|
|
|
|
|
|
$mach->{macdef} = {} |
|
120
|
0
|
0
|
|
|
|
|
unless exists $mach->{macdef}; |
|
121
|
0
|
|
|
|
|
|
$macdef = $mach->{machdef}{$value} = []; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
0
|
|
|
|
|
|
$fh->close(); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub lookup |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
0
|
|
|
0
|
1
|
|
my($pkg,$mach,$id) = @_; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
_readrc() |
|
134
|
0
|
0
|
|
|
|
|
unless exists $gripsrc{default}; |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
0
|
|
|
|
$mach ||= 'default'; |
|
137
|
0
|
0
|
|
|
|
|
undef $id |
|
138
|
|
|
|
|
|
|
if $mach eq 'default'; |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if(exists $gripsrc{$mach}) |
|
141
|
|
|
|
|
|
|
{ |
|
142
|
0
|
0
|
|
|
|
|
if(defined $id) |
|
143
|
|
|
|
|
|
|
{ |
|
144
|
0
|
|
|
|
|
|
my $m; |
|
145
|
0
|
|
|
|
|
|
foreach $m (@{$gripsrc{$mach}}) |
|
|
0
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
{ |
|
147
|
|
|
|
|
|
|
return $m |
|
148
|
0
|
0
|
0
|
|
|
|
if(exists $m->{id} && $m->{id} eq $id); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
0
|
|
|
|
|
|
return undef; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
0
|
|
|
|
|
|
return $gripsrc{$mach}->[0] |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return $gripsrc{default}->[0] |
|
156
|
0
|
0
|
|
|
|
|
if defined $gripsrc{default}; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return undef; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub id |
|
162
|
|
|
|
|
|
|
{ |
|
163
|
0
|
|
|
0
|
1
|
|
my $me = shift; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
exists $me->{id} |
|
166
|
|
|
|
|
|
|
? $me->{id} |
|
167
|
0
|
0
|
|
|
|
|
: undef; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub pwd |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
0
|
|
|
0
|
1
|
|
my $me = shift; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
exists $me->{pwd} |
|
175
|
|
|
|
|
|
|
? $me->{pwd} |
|
176
|
0
|
0
|
|
|
|
|
: undef; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub user |
|
180
|
|
|
|
|
|
|
{ |
|
181
|
0
|
|
|
0
|
1
|
|
my $me = shift; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
exists $me->{user} |
|
184
|
|
|
|
|
|
|
? $me->{user} |
|
185
|
0
|
0
|
|
|
|
|
: undef; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub iup |
|
189
|
|
|
|
|
|
|
{ |
|
190
|
0
|
|
|
0
|
1
|
|
my $me = shift; |
|
191
|
0
|
|
|
|
|
|
($me->id, $me->user, $me->pwd); |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__ |