2 # Copyright (c) 1996, Carnegie Mellon University
5 # See CMU_copyright.ph for use and distribution information
7 #: * pts.pm - Wrappers around PTS commands (user/group maintenance)
8 #: * This module provides wrappers around the various PTS commands, giving
9 #: * them a nice perl-based interface. Someday, they might talk to the
10 #: * ptserver directly instead of using 'pts', but not anytime soon.
14 use OpenAFS
::CMU_copyright
;
15 use OpenAFS
::util
qw(:DEFAULT :afs_internal);
22 @EXPORT = qw(&AFS_pts_createuser &AFS_pts_listmax
23 &AFS_pts_creategroup &AFS_pts_setmax
24 &AFS_pts_delete &AFS_pts_add
25 &AFS_pts_rename &AFS_pts_remove
26 &AFS_pts_examine &AFS_pts_members
27 &AFS_pts_chown &AFS_pts_listown
31 #: AFS_pts_createuser($user, [$id], [$cell])
32 #: Create a PTS user with $user as its name.
33 #: If specified, use $id as the PTS id; otherwise, AFS picks one.
34 #: If specified, operate in cell $cell instead of the default cell.
35 #: On success, return the PTS id of the newly-created user.
37 $AFS_Help{pts_createuser
} = '$user, [$id], [$cell] => $uid';
38 sub AFS_pts_createuser
{
39 my($user, $id, $cell) = @_;
42 @args = ('createuser', '-name', $user);
43 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
44 push(@args, '-id', $id) if ($id);
45 &wrapper
('pts', \
@args, [[ '^User .* has id (\d+)', \
$uid ]]);
50 #: AFS_pts_creategroup($group, [$id], [$owner], [$cell])
51 #: Create a PTS group with $group as its name.
52 #: If specified, use $id as the PTS id; otherwise, AFS picks one.
53 #: If specified, use $owner as the owner, instead of the current user.
54 #: If specified, operate in cell $cell instead of the default cell.
55 #: On success, return the PTS id of the newly-created group.
57 $AFS_Help{pts_creategroup
} = '$group, [$id], [$owner], [$cell] => $gid';
58 sub AFS_pts_creategroup
{
59 my($group, $id, $owner, $cell) = @_;
62 @args = ('creategroup', '-name', $group);
63 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
64 push(@args, '-id', $id) if ($id);
65 push(@args, '-owner', $owner) if ($owner);
66 &wrapper
('pts', \
@args, [[ '^group .* has id (\-\d+)', \
$uid ]]);
71 #: AFS_pts_delete(\@objs, [$cell])
72 #: Attempt to destroy PTS objects listed in @objs.
73 #: If specified, operate in cell $cell instead of the default cell.
74 #: On success, return 1.
75 #: If multiple objects are specified and only some are destroyed, some
76 #: operations may be left untried.
78 $AFS_Help{pts_delete
} = '\@objs, [$cell] => Success?';
80 my($objs, $cell) = @_;
83 @args = ('delete', '-nameorid', @
$objs);
84 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
85 &wrapper
('pts', \
@args);
90 #: AFS_pts_rename($old, $new, [$cell])
91 #: Rename the PTS object $old to have the name $new.
92 #: If specified, operate in cell $cell instead of the default cell.
93 #: On success, return 1.
95 $AFS_Help{pts_rename
} = '$old, $new, [$cell] => Success?';
97 my($old, $new, $cell) = @_;
100 @args = ('rename', '-oldname', $old, '-newname', $new);
101 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
102 &wrapper
('pts', \
@args);
107 #: AFS_pts_examine($obj, [$cell])
108 #: Examine the PTS object $obj, and return information about it.
109 #: If specified, operate in cell $cell instead of the default cell.
110 #: On success, return an associative array with some or all of the following:
111 #: - name Name of this object
112 #: - id ID of this object
113 #: - owner Name or ID of owner
114 #: - creator Name or ID of creator
115 #: - mem_count Number of members (group) or memberships (user)
116 #: - flags Privacy/access flags (as a string)
117 #: - group_quota Remaining group quota
119 $AFS_Help{pts_examine
} = '$obj, [$cell] => %info';
120 sub AFS_pts_examine
{
121 my($obj, $cell) = @_;
124 @args = ('examine', '-nameorid', $obj);
125 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
126 &wrapper
('pts', \
@args,
127 [[ '^Name\: (.*)\, id\: ([\-0-9]+)\, owner\: (.*)\, creator\: (.*)\,$', #',
128 'name', 'id', 'owner', 'creator' ],
129 [ '^ membership\: (\d+)\, flags\: (.....)\, group quota\: (\d+)\.$', #',
130 'mem_count', 'flags', 'group_quota' ]
135 #: AFS_pts_chown($obj, $owner, [$cell])
136 #: Change the owner of the PTS object $obj to be $owner.
137 #: If specified, operate in cell $cell instead of the default cell.
138 #: On success, return 1.
140 $AFS_Help{pts_chown
} = '$obj, $owner, [$cell] => Success?';
142 my($obj, $owner, $cell) = @_;
145 @args = ('chown', '-name', $obj, '-owner', $owner);
146 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
147 &wrapper
('pts', \
@args);
152 #: AFS_pts_setf($obj, [$access], [$gquota], [$cell])
153 #: Change the access flags and/or group quota for the PTS object $obj.
154 #: If specified, $access specifies the new access flags in the standard 'SOMAR'
155 #: format; individual flags may be specified as '.' to keep the current value.
156 #: If specified, $gquota specifies the new group quota.
157 #: If specified, operate in cell $cell instead of the default cell.
158 #: On success, return 1.
160 $AFS_Help{pts_setf
} = '$obj, [$access], [$gquota], [$cell] => Success?';
162 my($obj, $access, $gquota, $cell) = @_;
165 @args = ('setfields', '-nameorid', $obj);
166 push(@args, '-groupquota', $gquota) if ($gquota ne '');
169 # Ensure access is 5 characters
170 if (length($access) < 5) {
171 $access .= ('.' x
(5 - length($access)));
172 } elsif (length($access) > 5) {
173 substr($access, 5) = '';
176 %result = &AFS_pts_examine
($obj, $cell);
178 @old = split(//, $result{'flags'});
179 @new = split(//, $access);
180 foreach $i (0 .. 4) {
181 $new[$i] = $old[$i] if ($new[$i] eq '.');
183 $access = join('', @new);
184 if ($access ne $result{'flags'}) {
185 push(@args, '-access', $access);
188 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
189 &wrapper
('pts', \
@args);
194 #: AFS_pts_listmax([$cell])
195 #: Fetch the maximum assigned group and user ID.
196 #: If specified, operate in cell $cell instead of the default cell.
197 #: On success, returns (maxuid, maxgid)
199 $AFS_Help{pts_listmax
} = '[$cell] => ($maxuid, $maxgid)';
200 sub AFS_pts_listmax
{
202 my(@args, $uid, $gid);
205 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
206 &wrapper
('pts', \
@args,
207 [[ '^Max user id is (\d+) and max group id is (\-\d+).',
213 #: AFS_pts_setmax([$maxuser], [$maxgroup], [$cell])
214 #: Set the maximum assigned group and/or user ID.
215 #: If specified, $maxuser is the new maximum user ID
216 #: If specified, $maxgroup is the new maximum group ID
217 #: If specified, operate in cell $cell instead of the default cell.
218 #: On success, return 1.
220 $AFS_Help{pts_setmax
} = '[$maxuser], [$maxgroup], [$cell] => Success?';
222 my($maxuser, $maxgroup, $cell) = @_;
226 push(@args, '-group', $maxgroup) if ($maxgroup);
227 push(@args, '-user', $maxuser) if ($maxuser);
228 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
229 &wrapper
('pts', \
@args);
233 #: AFS_pts_add(\@users, \@groups, [$cell])
234 #: Add users specified in @users to groups specified in @groups.
235 #: If specified, operate in cell $cell instead of the default cell.
236 #: On success, return 1.
237 #: If multiple users and/or groups are specified and only some memberships
238 #: are added, some operations may be left untried.
240 $AFS_Help{pts_add
} = '\@users, \@groups, [$cell] => Success?';
242 my($users, $groups, $cell) = @_;
245 @args = ('adduser', '-user', @
$users, '-group', @
$groups);
246 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
247 &wrapper
('pts', \
@args);
252 #: AFS_pts_remove(\@users, \@groups, [$cell])
253 #: Remove users specified in @users from groups specified in @groups.
254 #: If specified, operate in cell $cell instead of the default cell.
255 #: On success, return 1.
256 #: If multiple users and/or groups are specified and only some memberships
257 #: are removed, some operations may be left untried.
259 $AFS_Help{pts_remove
} = '\@users, \@groups, [$cell] => Success?';
261 my($users, $groups, $cell) = @_;
264 @args = ('removeuser', '-user', @
$users, '-group', @
$groups);
265 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
266 &wrapper
('pts', \
@args);
271 #: AFS_pts_members($obj, [$cell])
272 #: If $obj specifies a group, retrieve a list of its members.
273 #: If $obj specifies a user, retrieve a list of groups to which it belongs.
274 #: If specified, operate in cell $cell instead of the default cell.
275 #: On success, return the resulting list.
277 $AFS_Help{pts_members
} = '$obj, [$cell] => @members';
278 sub AFS_pts_members
{
279 my($obj, $cell) = @_;
280 my(@args, @grouplist);
282 @args = ('membership', '-nameorid', $obj);
283 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
284 &wrapper
('pts', \
@args, [[ '^ (.*)', \
@grouplist ]]);
289 #: AFS_pts_listown($owner, [$cell])
290 #: Retrieve a list of PTS groups owned by the PTS object $obj.
291 #: If specified, operate in cell $cell instead of the default cell.
292 #: On success, return the resulting list.
294 $AFS_Help{pts_listown
} = '$owner, [$cell] => @owned';
295 sub AFS_pts_listown
{
296 my($owner, $cell) = @_;
297 my(@args, @grouplist);
299 @args = ('listowned', '-nameorid', $owner);
300 push(@args, '-cell', $cell ?
$cell : $AFS_Parms{'cell'});
301 &wrapper
('pts', \
@args, [[ '^ (.*)', \
@grouplist ]]);