line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (c) 2003-2004 Morgan Stanley and Co. |
5
|
|
|
|
|
|
|
# See ..../src/LICENSE for terms of distribution. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package AFS::Command::PTS; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require 5.6.0; |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
3033
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
116
|
|
13
|
3
|
|
|
3
|
|
13
|
use English; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
20
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
3563
|
use AFS::Command::Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use AFS::Object; |
17
|
|
|
|
|
|
|
use AFS::Object::PTServer; |
18
|
|
|
|
|
|
|
use AFS::Object::Principal; |
19
|
|
|
|
|
|
|
use AFS::Object::Group; |
20
|
|
|
|
|
|
|
use AFS::Object::User; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(AFS::Command::Base); |
23
|
|
|
|
|
|
|
our $VERSION = '1.99'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub creategroup { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my (%args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->{operation} = "creategroup"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return unless $self->_save_stderr(); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $errors = 0; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds(); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
43
|
|
|
|
|
|
|
next unless /group (\S+) has id (-\d+)/; |
44
|
|
|
|
|
|
|
my $group = AFS::Object::Group->new |
45
|
|
|
|
|
|
|
( |
46
|
|
|
|
|
|
|
name => $1, |
47
|
|
|
|
|
|
|
id => $2, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
$result->_addGroup($group); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
53
|
|
|
|
|
|
|
$errors++ unless $self->_restore_stderr(); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return if $errors; |
56
|
|
|
|
|
|
|
return $result; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub createuser { |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
my (%args) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$self->{operation} = "createuser"; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return unless $self->_save_stderr(); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $errors = 0; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
78
|
|
|
|
|
|
|
next unless /User (\S+) has id (\d+)/; |
79
|
|
|
|
|
|
|
my $user = AFS::Object::User->new |
80
|
|
|
|
|
|
|
( |
81
|
|
|
|
|
|
|
name => $1, |
82
|
|
|
|
|
|
|
id => $2, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
$result->_addUser($user); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
88
|
|
|
|
|
|
|
$errors++ unless $self->_restore_stderr(); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return if $errors; |
91
|
|
|
|
|
|
|
return $result; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub examine { |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
my (%args) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$self->{operation} = "examine"; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
return unless $self->_save_stderr(); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $errors = 0; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds(); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
chomp; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
while ( /,\s*$/ ) { |
117
|
|
|
|
|
|
|
$_ .= $self->{handle}->getline(); |
118
|
|
|
|
|
|
|
chomp; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my %data = (); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
foreach my $field ( split(/,\s*/) ) { |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my ($key,$value) = split(/:\s+/,$field,2); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$key =~ tr/A-Z/a-z/; |
128
|
|
|
|
|
|
|
$key =~ s/\s+//g; # group quota -> groupquota |
129
|
|
|
|
|
|
|
$value =~ s/\.$//; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$data{$key} = $value; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
unless ( $data{id} ) { |
136
|
|
|
|
|
|
|
$self->_Carp("pts examine: Unrecognized output: '$_'"); |
137
|
|
|
|
|
|
|
$errors++; |
138
|
|
|
|
|
|
|
next; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
if ( $data{id} > 0 ) { |
142
|
|
|
|
|
|
|
$result->_addUser( AFS::Object::User->new(%data) ); |
143
|
|
|
|
|
|
|
} else { |
144
|
|
|
|
|
|
|
$result->_addGroup( AFS::Object::Group->new(%data) ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
150
|
|
|
|
|
|
|
$errors++ unless $self->_restore_stderr(); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
return if $errors; |
153
|
|
|
|
|
|
|
return $result; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub listentries { |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $self = shift; |
160
|
|
|
|
|
|
|
my (%args) = @_; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$self->{operation} = "listentries"; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
return unless $self->_save_stderr(); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $errors = 0; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds(); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
next if /^Name/; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my ($name,$id,$owner,$creator) = split; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# |
181
|
|
|
|
|
|
|
# We seem to be getting this one bogus line of data, with no |
182
|
|
|
|
|
|
|
# name, and 0's for the IDs. Probably a bug in pts... |
183
|
|
|
|
|
|
|
# |
184
|
|
|
|
|
|
|
next if ( ! $name && ! $id && ! $owner && ! $creator ); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
if ( $id > 0 ) { |
187
|
|
|
|
|
|
|
my $user = AFS::Object::User->new |
188
|
|
|
|
|
|
|
( |
189
|
|
|
|
|
|
|
name => $name, |
190
|
|
|
|
|
|
|
id => $id, |
191
|
|
|
|
|
|
|
owner => $owner, |
192
|
|
|
|
|
|
|
creator => $creator, |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
$result->_addUser($user); |
195
|
|
|
|
|
|
|
} else { |
196
|
|
|
|
|
|
|
my $group = AFS::Object::Group->new |
197
|
|
|
|
|
|
|
( |
198
|
|
|
|
|
|
|
name => $name, |
199
|
|
|
|
|
|
|
id => $id, |
200
|
|
|
|
|
|
|
owner => $owner, |
201
|
|
|
|
|
|
|
creator => $creator, |
202
|
|
|
|
|
|
|
); |
203
|
|
|
|
|
|
|
$result->_addGroup($group); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
209
|
|
|
|
|
|
|
$errors++ unless $self->_restore_stderr(); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
return if $errors; |
212
|
|
|
|
|
|
|
return $result; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub listmax { |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $self = shift; |
219
|
|
|
|
|
|
|
my (%args) = @_; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
$self->{operation} = "listmax"; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
return unless $self->_save_stderr(); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $errors = 0; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds(); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
234
|
|
|
|
|
|
|
next unless /Max user id is (\d+) and max group id is (-\d+)/; |
235
|
|
|
|
|
|
|
$result->_setAttribute |
236
|
|
|
|
|
|
|
( |
237
|
|
|
|
|
|
|
maxuserid => $1, |
238
|
|
|
|
|
|
|
maxgroupid => $2, |
239
|
|
|
|
|
|
|
); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
243
|
|
|
|
|
|
|
$errors++ unless $self->_restore_stderr(); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
return if $errors; |
246
|
|
|
|
|
|
|
return $result; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub listowned { |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
my $self = shift; |
253
|
|
|
|
|
|
|
my (%args) = @_; |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
$self->{operation} = "listowned"; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
my $errors = 0; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds( stderr => 'stdout' ); |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my $user = undef; |
266
|
|
|
|
|
|
|
my $group = undef; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
if ( /Groups owned by (\S+) \(id: (-?\d+)\)/ ) { |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
$result->_addUser($user) if $user; |
273
|
|
|
|
|
|
|
$result->_addGroup($group) if $group; |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
my ($name,$id) = ($1,$2); |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
if ( $id > 0 ) { |
278
|
|
|
|
|
|
|
$user = AFS::Object::User->new |
279
|
|
|
|
|
|
|
( |
280
|
|
|
|
|
|
|
name => $name, |
281
|
|
|
|
|
|
|
id => $id, |
282
|
|
|
|
|
|
|
); |
283
|
|
|
|
|
|
|
$group = undef; |
284
|
|
|
|
|
|
|
} else { |
285
|
|
|
|
|
|
|
$group = AFS::Object::Group->new |
286
|
|
|
|
|
|
|
( |
287
|
|
|
|
|
|
|
name => $name, |
288
|
|
|
|
|
|
|
id => $id, |
289
|
|
|
|
|
|
|
); |
290
|
|
|
|
|
|
|
$user = undef; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
} elsif ( /^\s+(\S+)\s*/ ) { |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
if ( $user ) { |
296
|
|
|
|
|
|
|
$user->_addOwned($1); |
297
|
|
|
|
|
|
|
} else { |
298
|
|
|
|
|
|
|
$group->_addOwned($2); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
} elsif ( /unable to get owner list/ ) { |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# |
304
|
|
|
|
|
|
|
# pts still (as of OpenAFS 1.2.8) doesn't have proper exit codes. |
305
|
|
|
|
|
|
|
# If we see this string, then let the command fail, even |
306
|
|
|
|
|
|
|
# though we might have partial data. |
307
|
|
|
|
|
|
|
# |
308
|
|
|
|
|
|
|
$self->{errors} .= $_; |
309
|
|
|
|
|
|
|
$errors++; |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$result->_addUser($user) if $user; |
316
|
|
|
|
|
|
|
$result->_addGroup($group) if $group; |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
return if $errors; |
321
|
|
|
|
|
|
|
return $result; |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub membership { |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
my $self = shift; |
328
|
|
|
|
|
|
|
my (%args) = @_; |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
my $result = AFS::Object::PTServer->new(); |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
$self->{operation} = "membership"; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
return unless $self->_parse_arguments(%args); |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
my $errors = 0; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
$errors++ unless $self->_exec_cmds( stderr => 'stdout' ); |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
my $user = undef; |
341
|
|
|
|
|
|
|
my $group = undef; |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
while ( defined($_ = $self->{handle}->getline()) ) { |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
if ( /(\S+) \(id: (-?\d+)\)/ ) { |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$result->_addUser($user) if $user; |
348
|
|
|
|
|
|
|
$result->_addGroup($group) if $group; |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
my ($name,$id) = ($1,$2); |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
if ( $id > 0 ) { |
353
|
|
|
|
|
|
|
$user = AFS::Object::User->new |
354
|
|
|
|
|
|
|
( |
355
|
|
|
|
|
|
|
name => $name, |
356
|
|
|
|
|
|
|
id => $id, |
357
|
|
|
|
|
|
|
); |
358
|
|
|
|
|
|
|
$group = undef; |
359
|
|
|
|
|
|
|
} else { |
360
|
|
|
|
|
|
|
$group = AFS::Object::Group->new |
361
|
|
|
|
|
|
|
( |
362
|
|
|
|
|
|
|
name => $name, |
363
|
|
|
|
|
|
|
id => $id, |
364
|
|
|
|
|
|
|
); |
365
|
|
|
|
|
|
|
$user = undef; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
} elsif ( /^\s+(\S+)\s*/ ) { |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
if ( $user ) { |
371
|
|
|
|
|
|
|
$user->_addMembership($1); |
372
|
|
|
|
|
|
|
} else { |
373
|
|
|
|
|
|
|
$group->_addMembership($1); |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
} elsif ( /unable to get membership/ || |
377
|
|
|
|
|
|
|
/User or group doesn't exist/ || |
378
|
|
|
|
|
|
|
/membership list for id \d+ exceeds display limit/ ) { |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# |
381
|
|
|
|
|
|
|
# pts still (as of OpenAFS 1.2.8) doesn't have proper exit codes. |
382
|
|
|
|
|
|
|
# If we see this string, then let the command fail, even |
383
|
|
|
|
|
|
|
# though we might have partial data. |
384
|
|
|
|
|
|
|
# |
385
|
|
|
|
|
|
|
$self->{errors} .= $_; |
386
|
|
|
|
|
|
|
$errors++; |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
$result->_addUser($user) if $user; |
393
|
|
|
|
|
|
|
$result->_addGroup($group) if $group; |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
$errors++ unless $self->_reap_cmds(); |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
return if $errors; |
398
|
|
|
|
|
|
|
return $result; |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
1; |