line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
############################################################################### |
3
|
|
|
|
|
|
|
## ## |
4
|
|
|
|
|
|
|
## Copyright (c) 2003 by Steffen Beyer & Gerhard Albers. ## |
5
|
|
|
|
|
|
|
## All rights reserved. ## |
6
|
|
|
|
|
|
|
## ## |
7
|
|
|
|
|
|
|
## This package is free software; you can redistribute it ## |
8
|
|
|
|
|
|
|
## and/or modify it under the same terms as Perl itself. ## |
9
|
|
|
|
|
|
|
## ## |
10
|
|
|
|
|
|
|
############################################################################### |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Config::Manager::User; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1902
|
use strict; |
|
2
|
|
|
|
|
72
|
|
|
2
|
|
|
|
|
84
|
|
15
|
2
|
|
|
2
|
|
12
|
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
274
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require Exporter; |
18
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@EXPORT = qw(); |
21
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
22
|
|
|
|
|
|
|
user_id |
23
|
|
|
|
|
|
|
user_name |
24
|
|
|
|
|
|
|
user_conf |
25
|
|
|
|
|
|
|
host_id |
26
|
|
|
|
|
|
|
host_pw |
27
|
|
|
|
|
|
|
machine_id |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => [@EXPORT_OK]); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$VERSION = '1.7'; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
2
|
|
11
|
use Config::Manager::Conf qw( whoami ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
95
|
|
35
|
2
|
|
|
2
|
|
10
|
use Config::Manager::Report qw(:all); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
2848
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
############################## |
38
|
|
|
|
|
|
|
## Configuration constants: ## |
39
|
|
|
|
|
|
|
############################## |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @FULLNAME = ('Person', 'Name'); |
42
|
|
|
|
|
|
|
my @HOST_ID = ('Host', 'HOST-ID'); |
43
|
|
|
|
|
|
|
my @HOST_PW = ('Host', 'HOST-PW'); |
44
|
|
|
|
|
|
|
my @MACHINE = ('DEFAULT', 'MACHINE'); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
####################### |
47
|
|
|
|
|
|
|
## Global variables: ## |
48
|
|
|
|
|
|
|
####################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my %ConfCache = (); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
######################## |
53
|
|
|
|
|
|
|
## Private Functions: ## |
54
|
|
|
|
|
|
|
######################## |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _get_user_conf |
57
|
|
|
|
|
|
|
{ |
58
|
1
|
|
|
1
|
|
2
|
my($userid) = @_; # User-Kennung |
59
|
1
|
|
|
|
|
2
|
my($ownerid,$varname,$scope,$confobj,$error); |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
1
|
local($@); |
62
|
1
|
0
|
33
|
|
|
3
|
if ((exists $ConfCache{$userid}) && |
|
|
|
33
|
|
|
|
|
63
|
|
|
|
|
|
|
(defined $ConfCache{$userid}) && |
64
|
|
|
|
|
|
|
(ref $ConfCache{$userid})) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
|
|
0
|
return $ConfCache{$userid}; |
67
|
|
|
|
|
|
|
} |
68
|
1
|
50
|
|
|
|
3
|
unless (($ownerid,$varname) = &whoami()) # defined in Conf.pm |
69
|
|
|
|
|
|
|
{ |
70
|
1
|
|
|
|
|
3
|
Config::Manager::Report->report |
71
|
|
|
|
|
|
|
( |
72
|
|
|
|
|
|
|
@ERROR, |
73
|
|
|
|
|
|
|
"Couldn't find user login in %ENV!" |
74
|
|
|
|
|
|
|
); |
75
|
1
|
|
|
|
|
3
|
return undef; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
0
|
|
|
|
0
|
if ($userid eq $ownerid) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
$confobj = Config::Manager::Conf->default(); |
80
|
0
|
|
|
|
|
0
|
$ConfCache{$userid} = $confobj; |
81
|
0
|
|
|
|
|
0
|
return $confobj; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
$error = ''; |
84
|
0
|
|
|
|
|
0
|
$ENV{$varname} = $userid; |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
0
|
local($SIG{'__DIE__'}) = 'DEFAULT'; |
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
eval |
88
|
0
|
|
|
|
|
0
|
{ |
89
|
0
|
0
|
|
|
|
0
|
if (defined ($scope = Config::Manager::Conf->scope())) |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
0
|
|
|
|
0
|
if (defined ($confobj = Config::Manager::Conf->new())) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
0
|
|
|
|
0
|
unless (defined ($confobj->init( $scope ))) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
0
|
$error = $confobj->error(); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
|
|
0
|
$error = Config::Manager::Conf->error(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
$error = Config::Manager::Conf->error(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
0
|
$ENV{$varname} = $ownerid; |
110
|
0
|
0
|
0
|
|
|
0
|
if (($@ ne '') || ($error ne '')) |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
|
|
0
|
$@ =~ s!\s+$!!; |
113
|
0
|
|
|
|
|
0
|
$error =~ s!\s+$!!; |
114
|
0
|
0
|
0
|
|
|
0
|
if (($@ ne '') && ($error ne '')) { $error = join("\n", $@, $error); } |
|
0
|
|
|
|
|
0
|
|
115
|
0
|
|
|
|
|
0
|
else { $error = $@ . $error; } |
116
|
0
|
|
|
|
|
0
|
Config::Manager::Report->report |
117
|
|
|
|
|
|
|
( |
118
|
|
|
|
|
|
|
@ERROR, |
119
|
|
|
|
|
|
|
"Error reading the configuration data for user '$userid':", |
120
|
|
|
|
|
|
|
$error |
121
|
|
|
|
|
|
|
); |
122
|
0
|
|
|
|
|
0
|
return undef; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
0
|
$ConfCache{$userid} = $confobj; |
125
|
0
|
|
|
|
|
0
|
return $confobj; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
####################### |
129
|
|
|
|
|
|
|
## Public functions: ## |
130
|
|
|
|
|
|
|
####################### |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub user_id |
133
|
|
|
|
|
|
|
{ |
134
|
1
|
|
|
1
|
0
|
50
|
my($user_id); |
135
|
|
|
|
|
|
|
|
136
|
1
|
50
|
|
|
|
3
|
if (($user_id) = &whoami()) # defined in Conf.pm |
137
|
|
|
|
|
|
|
{ |
138
|
0
|
|
|
|
|
0
|
return $user_id; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
Config::Manager::Report->report |
141
|
|
|
|
|
|
|
( |
142
|
1
|
|
|
|
|
4
|
@ERROR, |
143
|
|
|
|
|
|
|
"Couldn't find user login in %ENV!" |
144
|
|
|
|
|
|
|
); |
145
|
1
|
|
|
|
|
3
|
return undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub user_name |
149
|
|
|
|
|
|
|
{ |
150
|
0
|
|
|
0
|
0
|
0
|
my($conf,$user_name,$error); |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
0
|
if (@_ > 0) |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
return undef |
155
|
0
|
0
|
|
|
|
0
|
unless (defined ($conf = &_get_user_conf($_[0]))); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
|
|
0
|
$conf = Config::Manager::Conf->default(); |
160
|
|
|
|
|
|
|
} |
161
|
0
|
0
|
|
|
|
0
|
if (defined ($user_name = $conf->get(@FULLNAME))) |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
|
|
0
|
return $user_name; |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
0
|
$error = $conf->error(); |
166
|
0
|
|
|
|
|
0
|
$error =~ s!\s+$!!; |
167
|
0
|
|
|
|
|
0
|
Config::Manager::Report->report |
168
|
|
|
|
|
|
|
( |
169
|
|
|
|
|
|
|
@ERROR, |
170
|
|
|
|
|
|
|
"Couldn't find user's name in configuration data:", |
171
|
|
|
|
|
|
|
$error |
172
|
|
|
|
|
|
|
); |
173
|
0
|
|
|
|
|
0
|
return undef; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub user_conf |
177
|
|
|
|
|
|
|
{ |
178
|
1
|
50
|
|
1
|
0
|
9
|
if (@_ > 0) |
179
|
|
|
|
|
|
|
{ |
180
|
1
|
|
|
|
|
17
|
return &_get_user_conf($_[0]); |
181
|
|
|
|
|
|
|
} |
182
|
0
|
|
|
|
|
|
Config::Manager::Report->report(@FATAL, "No user specified!"); |
183
|
0
|
|
|
|
|
|
return undef; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub host_id |
187
|
|
|
|
|
|
|
{ |
188
|
0
|
|
|
0
|
0
|
|
my($conf,$host_id,$error); |
189
|
|
|
|
|
|
|
|
190
|
0
|
0
|
|
|
|
|
if (@_ > 0) |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
return undef |
193
|
0
|
0
|
|
|
|
|
unless (defined ($conf = &_get_user_conf($_[0]))); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
else |
196
|
|
|
|
|
|
|
{ |
197
|
0
|
|
|
|
|
|
$conf = Config::Manager::Conf->default(); |
198
|
|
|
|
|
|
|
} |
199
|
0
|
0
|
|
|
|
|
if (defined ($host_id = $conf->get(@HOST_ID))) |
200
|
|
|
|
|
|
|
{ |
201
|
0
|
|
|
|
|
|
return $host_id; |
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
$error = $conf->error(); |
204
|
0
|
|
|
|
|
|
$error =~ s!\s+$!!; |
205
|
0
|
|
|
|
|
|
Config::Manager::Report->report |
206
|
|
|
|
|
|
|
( |
207
|
|
|
|
|
|
|
@ERROR, |
208
|
|
|
|
|
|
|
"Couldn't find user's HOST-ID in configuration data:", |
209
|
|
|
|
|
|
|
$error |
210
|
|
|
|
|
|
|
); |
211
|
0
|
|
|
|
|
|
return undef; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub host_pw |
215
|
|
|
|
|
|
|
{ |
216
|
0
|
|
|
0
|
0
|
|
my($conf,$host_pw,$error); |
217
|
|
|
|
|
|
|
|
218
|
0
|
0
|
|
|
|
|
if (@_ > 0) |
219
|
|
|
|
|
|
|
{ |
220
|
|
|
|
|
|
|
return undef |
221
|
0
|
0
|
|
|
|
|
unless (defined ($conf = &_get_user_conf($_[0]))); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
else |
224
|
|
|
|
|
|
|
{ |
225
|
0
|
|
|
|
|
|
$conf = Config::Manager::Conf->default(); |
226
|
|
|
|
|
|
|
} |
227
|
0
|
0
|
|
|
|
|
if (defined ($host_pw = $conf->get(@HOST_PW))) |
228
|
|
|
|
|
|
|
{ |
229
|
0
|
|
|
|
|
|
return $host_pw; |
230
|
|
|
|
|
|
|
} |
231
|
0
|
|
|
|
|
|
$error = $conf->error(); |
232
|
0
|
|
|
|
|
|
$error =~ s!\s+$!!; |
233
|
0
|
|
|
|
|
|
Config::Manager::Report->report |
234
|
|
|
|
|
|
|
( |
235
|
|
|
|
|
|
|
@ERROR, |
236
|
|
|
|
|
|
|
"Couldn't find user's HOST-PW in configuration data:", |
237
|
|
|
|
|
|
|
$error |
238
|
|
|
|
|
|
|
); |
239
|
0
|
|
|
|
|
|
return undef; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub machine_id |
243
|
|
|
|
|
|
|
{ |
244
|
0
|
|
|
0
|
0
|
|
my($machine,$error); |
245
|
|
|
|
|
|
|
|
246
|
0
|
0
|
|
|
|
|
if (defined ($machine = Config::Manager::Conf->get(@MACHINE))) |
247
|
|
|
|
|
|
|
{ |
248
|
0
|
|
|
|
|
|
return $machine; |
249
|
|
|
|
|
|
|
} |
250
|
0
|
|
|
|
|
|
$error = Config::Manager::Conf->error(); |
251
|
0
|
|
|
|
|
|
$error =~ s!\s+$!!; |
252
|
0
|
|
|
|
|
|
Config::Manager::Report->report |
253
|
|
|
|
|
|
|
( |
254
|
|
|
|
|
|
|
@ERROR, |
255
|
|
|
|
|
|
|
"Couldn't find MACHINE-ID in configuration data:", |
256
|
|
|
|
|
|
|
$error |
257
|
|
|
|
|
|
|
); |
258
|
0
|
|
|
|
|
|
return undef; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
1; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
__END__ |