Bug Summary

File:tptserver/./../ptserver/ptprocs.c
Location:line 2145, column 7
Description:Value stored to 'code' is never read

Annotated Source Code

1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10/*
11 * (3) function addToGroup
12 *
13 * 1. Eliminate the code that tests for adding groups
14 * to groups. This is an error in normal AFS.
15 * 2. If adding a group to a group call AddToSGEntry
16 * to add the id of the group it's a member of.
17 *
18 * (4) function Delete
19 *
20 * 1. Print a messsage if an error is returned from
21 * FindByID() and PTDEBUG is defined.
22 * 2. If removing a group from a group call
23 * RemoveFromSGEntry to remove the id of the
24 * group it's a member of.
25 * 3. Remove supergroup continuation records.
26 *
27 * (5) function RemoveFromGroup
28 *
29 * 1. Eliminate the code that tests for adding groups
30 * to groups. This is an error in normal AFS.
31 * 2. If removing a group from a group call
32 * RemoveFromSGEntry to remove the id of the
33 * group it's a member of.
34 *
35 * (6) Add new functions PR_ListSuperGroups and
36 * listSuperGroups.
37 *
38 * (7) function isAMemberOf
39 *
40 * 1. Allow groups to be members of groups.
41 *
42 * Transarc does not currently use opcodes past 520, but
43 * they *could* decide at any time to use more opcodes.
44 * If they did, then one part of our local mods,
45 * ListSupergroups, would break. I've therefore
46 * renumbered it to 530, and put logic in to enable the
47 * old opcode to work (for now).
48 */
49
50#include <afsconfig.h>
51#include <afs/param.h>
52#include <afs/stds.h>
53
54#include <roken.h>
55
56#include <ctype.h>
57
58#include <lock.h>
59#include <afs/afsutil.h>
60#include <ubik.h>
61#include <rx/xdr.h>
62#include <rx/rx.h>
63#include <rx/rxkad.h>
64#include <afs/auth.h>
65
66#include "ptserver.h"
67#include "pterror.h"
68#include "ptprototypes.h"
69#include "afs/audit.h"
70
71#ifdef AFS_ATHENA_STDENV
72#include <krb.h>
73#endif
74
75extern int restricted;
76extern struct ubik_dbase *dbase;
77extern int pr_noAuth;
78extern char *pr_realmName;
79extern int prp_group_default;
80extern int prp_user_default;
81
82static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid,
83 afs_int32 oid, afs_int32 *cid);
84static afs_int32 newEntry(struct rx_call *call, char aname[], afs_int32 flag,
85 afs_int32 oid, afs_int32 *aid, afs_int32 *cid);
86static afs_int32 whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos,
87 afs_int32 *cid);
88static afs_int32 dumpEntry(struct rx_call *call, afs_int32 apos,
89 struct prdebugentry *aentry, afs_int32 *cid);
90static afs_int32 addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
91 afs_int32 *cid);
92static afs_int32 nameToID(struct rx_call *call, namelist *aname, idlist *aid);
93static afs_int32 idToName(struct rx_call *call, idlist *aid, namelist *aname);
94static afs_int32 Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid);
95static afs_int32 UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
96 struct PrUpdateEntry *uentry, afs_int32 *cid);
97static afs_int32 removeFromGroup(struct rx_call *call, afs_int32 aid,
98 afs_int32 gid, afs_int32 *cid);
99static afs_int32 getCPS(struct rx_call *call, afs_int32 aid, prlist *alist,
100 afs_int32 *over, afs_int32 *cid);
101static afs_int32 getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost,
102 prlist *alist, afs_int32 *over, afs_int32 *cid);
103static afs_int32 getHostCPS(struct rx_call *call, afs_uint32 ahost,
104 prlist *alist, afs_int32 *over);
105static afs_int32 listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid);
106static afs_int32 setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag,
107 afs_int32 *cid);
108static afs_int32 listEntry(struct rx_call *call, afs_int32 aid,
109 struct prcheckentry *aentry, afs_int32 *cid);
110static afs_int32 listEntries(struct rx_call *call, afs_int32 flag,
111 afs_int32 startindex, prentries *bulkentries,
112 afs_int32 *nextstartindex, afs_int32 *cid);
113static afs_int32 put_prentries(struct prentry *tentry, prentries *bulkentries);
114static afs_int32 changeEntry(struct rx_call *call, afs_int32 aid, char *name,
115 afs_int32 oid, afs_int32 newid, afs_int32 *cid);
116static afs_int32 setFieldsEntry(struct rx_call *call, afs_int32 id,
117 afs_int32 mask, afs_int32 flags,
118 afs_int32 ngroups, afs_int32 nusers,
119 afs_int32 spare1, afs_int32 spare2,
120 afs_int32 *cid);
121static afs_int32 listElements(struct rx_call *call, afs_int32 aid,
122 prlist *alist, afs_int32 *over, afs_int32 *cid);
123#if defined(SUPERGROUPS1)
124static afs_int32 listSuperGroups(struct rx_call *call, afs_int32 aid,
125 prlist *alist, afs_int32 *over,
126 afs_int32 *cid);
127#endif
128static afs_int32 listOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
129 afs_int32 *lastP, afs_int32 *cid);
130static afs_int32 isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
131 afs_int32 *flag, afs_int32 *cid);
132static afs_int32 addWildCards(struct ubik_trans *tt, prlist *alist,
133 afs_uint32 host);
134static afs_int32 WhoIsThisWithName(struct rx_call *acall,
135 struct ubik_trans *at, afs_int32 *aid,
136 char *aname);
137
138/* when we abort, the ubik cachedVersion will be reset, so we'll read in the
139 * header on the next call.
140 * Abort the transaction and return the code.
141 */
142#define ABORT_WITH(tt,code)return(ubik_AbortTrans(tt),code) return(ubik_AbortTrans(tt),code)
143
144static int
145CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag,
146 int admin)
147{
148 if (restricted && !admin)
149 return 0;
150
151 if (flag & PRFOREIGN16) {
152 /* Foreign users are recognized by the '@' sign and
153 * not by the PRFOREIGN flag.
154 */
155 return 0;
156 } else if (flag & PRGRP2) {
157 /* Allow anonymous group creation only if owner specified
158 * and running noAuth.
159 */
160 if (cid == ANONYMOUSID32766) {
161 if ((oid == 0) || !pr_noAuth)
162 return 0;
163 }
164 } else { /* creating a user */
165 if (!admin && !pr_noAuth)
166 return 0;
167 }
168 return 1; /* OK! */
169}
170
171afs_int32
172WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid)
173{
174 int code = WhoIsThisWithName(acall, at, aid, NULL((void *)0));
175 if (code == 2 && *aid == ANONYMOUSID32766)
176 return PRNOENT(267268L);
177 return code;
178}
179
180afs_int32
181SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
182{
183 afs_int32 code;
184 afs_int32 cid = ANONYMOUSID32766;
185
186 code = iNewEntry(call, aname, aid, oid, &cid);
187 osi_auditU(call, PTS_INewEntEvent"AFS_PTS_INewEnt", code, AUD_ID10, aid, AUD_STR1, aname,
188 AUD_ID10, oid, AUD_END0);
189 ViceLog(5, ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, aid, aname, oid))do { if ((5) <= LogLevel) (FSLog ("PTS_INewEntry: code %d cid %d aid %d aname %s oid %d\n"
, code, cid, aid, aname, oid)); } while (0)
;
190 return code;
191}
192
193static afs_int32
194iNewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid,
195 afs_int32 *cid)
196{
197 /* used primarily for conversion - not intended to be used as usual means
198 * of entering people into the database. */
199 struct ubik_trans *tt;
200 afs_int32 code;
201 afs_int32 gflag = 0;
202 int admin;
203
204 stolower(aname);
205 code = Initdb();
206 if (code != PRSUCCESS0)
207 return code;
208 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
209 if (code)
210 return code;
211 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
212 if (code)
213 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
214 code = read_DbHeader(tt);
215 if (code)
216 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
217
218 code = WhoIsThis(call, tt, cid);
219 if (code)
220 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
221 admin = IsAMemberOf(tt, *cid, SYSADMINID-204);
222
223 /* first verify the id is good */
224 if (aid == 0)
225 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
226 if (aid < 0) {
227 gflag |= PRGRP2;
228 /* only sysadmin can reuse a group id */
229 if (!admin && !pr_noAuth && (aid != ntohl(cheader.maxGroup)(__builtin_constant_p(cheader.maxGroup) ? ((((__uint32_t)(cheader
.maxGroup)) >> 24) | ((((__uint32_t)(cheader.maxGroup))
& (0xff << 16)) >> 8) | ((((__uint32_t)(cheader
.maxGroup)) & (0xff << 8)) << 8) | (((__uint32_t
)(cheader.maxGroup)) << 24)) : __bswap32_var(cheader.maxGroup
))
- 1))
230 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
231 }
232 if (FindByID(tt, aid))
233 ABORT_WITH(tt, PRIDEXIST)return(ubik_AbortTrans(tt),(267265L));
234
235 /* check a few other things */
236 if (!CreateOK(tt, *cid, oid, gflag, admin))
237 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
238
239 code = CreateEntry(tt, aname, &aid, 1, gflag, oid, *cid);
240 if (code != PRSUCCESS0)
241 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
242
243 /* finally, commit transaction */
244 code = ubik_EndTrans(tt);
245 if (code)
246 return code;
247 return PRSUCCESS0;
248}
249
250
251afs_int32
252SPR_NewEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
253 afs_int32 *aid)
254{
255 afs_int32 code;
256 afs_int32 cid = ANONYMOUSID32766;
257
258 code = newEntry(call, aname, flag, oid, aid, &cid);
259 osi_auditU(call, PTS_NewEntEvent"AFS_PTS_NewEnt", code, AUD_ID10, *aid, AUD_STR1, aname,
260 AUD_ID10, oid, AUD_END0);
261 ViceLog(5, ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n", code, cid, *aid, aname, oid))do { if ((5) <= LogLevel) (FSLog ("PTS_NewEntry: code %d cid %d aid %d aname %s oid %d\n"
, code, cid, *aid, aname, oid)); } while (0)
;
262 return code;
263}
264
265static afs_int32
266newEntry(struct rx_call *call, char aname[], afs_int32 flag, afs_int32 oid,
267 afs_int32 *aid, afs_int32 *cid)
268{
269 afs_int32 code;
270 struct ubik_trans *tt;
271 int admin;
272 char cname[PR_MAXNAMELEN64];
273 stolower(aname);
274 code = Initdb();
275 if (code)
276 return code;
277 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
278 if (code)
279 return code;
280 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
281 if (code)
282 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
283 code = read_DbHeader(tt);
284 if (code)
285 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
286
287 /* this is for cross-cell self registration. It is not added in the
288 * SPR_INewEntry because we want self-registration to only do
289 * automatic id assignment.
290 */
291 code = WhoIsThisWithName(call, tt, cid, cname);
292 if (code != 2) { /* 2 specifies that this is a foreign cell request */
293 if (code)
294 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
295 admin = IsAMemberOf(tt, *cid, SYSADMINID-204);
296 } else {
297 admin = ((!restricted && !strcmp(aname, cname))) || IsAMemberOf(tt, *cid, SYSADMINID-204);
298 oid = *cid = SYSADMINID-204;
299 }
300 if (!CreateOK(tt, *cid, oid, flag, admin))
301 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
302
303 code = CreateEntry(tt, aname, aid, 0, flag, oid, *cid);
304 if (code != PRSUCCESS0)
305 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
306
307 code = ubik_EndTrans(tt);
308 if (code)
309 return code;
310 return PRSUCCESS0;
311}
312
313
314
315afs_int32
316SPR_WhereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos)
317{
318 afs_int32 code;
319 afs_int32 cid = ANONYMOUSID32766;
320
321 code = whereIsIt(call, aid, apos, &cid);
322 osi_auditU(call, PTS_WheIsItEvent"AFS_PTS_WheIsIt", code, AUD_ID10, aid, AUD_LONG5, *apos,
323 AUD_END0);
324 ViceLog(125, ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n", code, cid, aid, *apos))do { if ((125) <= LogLevel) (FSLog ("PTS_WhereIsIt: code %d cid %d aid %d apos %d\n"
, code, cid, aid, *apos)); } while (0)
;
325 return code;
326}
327
328static afs_int32
329whereIsIt(struct rx_call *call, afs_int32 aid, afs_int32 *apos, afs_int32 *cid)
330{
331 afs_int32 code;
332 struct ubik_trans *tt;
333 afs_int32 temp;
334
335 code = Initdb();
336 if (code != PRSUCCESS0)
337 return code;
338 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
339 if (code)
340 return code;
341 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
342 if (code)
343 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
344 code = read_DbHeader(tt);
345 if (code)
346 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
347
348 code = WhoIsThis(call, tt, cid);
349 if (code)
350 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
351
352 temp = FindByID(tt, aid);
353 if (!temp)
354 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
355 *apos = temp;
356 code = ubik_EndTrans(tt);
357 if (code)
358 return code;
359 return PRSUCCESS0;
360}
361
362
363afs_int32
364SPR_DumpEntry(struct rx_call *call, afs_int32 apos,
365 struct prdebugentry *aentry)
366{
367 afs_int32 code;
368 afs_int32 cid = ANONYMOUSID32766;
369
370 code = dumpEntry(call, apos, aentry, &cid);
371 osi_auditU(call, PTS_DmpEntEvent"AFS_PTS_DmpEnt", code, AUD_LONG5, apos, AUD_END0);
372 ViceLog(125, ("PTS_DumpEntry: code %d cid %d apos %d\n", code, cid, apos))do { if ((125) <= LogLevel) (FSLog ("PTS_DumpEntry: code %d cid %d apos %d\n"
, code, cid, apos)); } while (0)
;
373 return code;
374}
375
376static afs_int32
377dumpEntry(struct rx_call *call, afs_int32 apos, struct prdebugentry *aentry,
378 afs_int32 *cid)
379{
380 afs_int32 code;
381 struct ubik_trans *tt;
382
383 code = Initdb();
384 if (code != PRSUCCESS0)
385 return code;
386 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
387 if (code)
388 return code;
389 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
390 if (code)
391 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
392 code = read_DbHeader(tt);
393 if (code)
394 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
395
396 code = WhoIsThis(call, tt, cid);
397 if (code)
398 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
399 code = pr_ReadEntry(tt, 0, apos, (struct prentry *)aentry);
400 if (code)
401 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
402
403 if (!AccessOK(tt, *cid, 0, PRP_STATUS_MEM(0x40 << 16), 0))
404 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
405
406 /* Since prdebugentry is in the form of a prentry not a coentry, we will
407 * return the coentry slots in network order where the string is. */
408#if 0
409 if (aentry->flags & PRCONT4) { /* wrong type, get coentry instead */
410 code = pr_ReadCoEntry(tt, 0, apos, aentry);
411 if (code)
412 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
413 }
414#endif
415 code = ubik_EndTrans(tt);
416 if (code)
417 return code;
418 return PRSUCCESS0;
419}
420
421afs_int32
422SPR_AddToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
423{
424 afs_int32 code;
425 afs_int32 cid = ANONYMOUSID32766;
426
427 code = addToGroup(call, aid, gid, &cid);
428 osi_auditU(call, PTS_AdToGrpEvent"AFS_PTS_AdToGrp", code, AUD_ID10, gid, AUD_ID10, aid,
429 AUD_END0);
430 ViceLog(5, ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid))do { if ((5) <= LogLevel) (FSLog ("PTS_AddToGroup: code %d cid %d gid %d aid %d\n"
, code, cid, gid, aid)); } while (0)
;
431 return code;
432}
433
434static afs_int32
435addToGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid, afs_int32 *cid)
436{
437 afs_int32 code;
438 struct ubik_trans *tt;
439 afs_int32 tempu;
440 afs_int32 tempg;
441 struct prentry tentry;
442 struct prentry uentry;
443
444 code = Initdb();
445 if (code != PRSUCCESS0)
446 return code;
447 if (gid == ANYUSERID-101 || gid == AUTHUSERID-102)
448 return PRPERM(267269L);
449 if (aid == ANONYMOUSID32766)
450 return PRPERM(267269L);
451 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
452 if (code)
453 return code;
454 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
455 if (code)
456 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
457 code = read_DbHeader(tt);
458 if (code)
459 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
460
461 code = WhoIsThis(call, tt, cid);
462 if (code)
463 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
464 tempu = FindByID(tt, aid);
465 if (!tempu)
466 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
467 memset(&uentry, 0, sizeof(uentry));
468 code = pr_ReadEntry(tt, 0, tempu, &uentry);
469 if (code != 0)
470 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
471
472#if !defined(SUPERGROUPS1)
473 /* we don't allow groups as members of groups at present */
474 if (uentry.flags & PRGRP2)
475 ABORT_WITH(tt, PRNOTUSER)return(ubik_AbortTrans(tt),(267271L));
476#endif
477
478 tempg = FindByID(tt, gid);
479 if (!tempg)
480 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
481 code = pr_ReadEntry(tt, 0, tempg, &tentry);
482 if (code != 0)
483 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
484 /* make sure that this is a group */
485 if (!(tentry.flags & PRGRP2))
486 ABORT_WITH(tt, PRNOTGROUP)return(ubik_AbortTrans(tt),(267270L));
487 if (!AccessOK(tt, *cid, &tentry, PRP_ADD_MEM(0x02 << 16), PRP_ADD_ANY(0x04 << 16)))
488 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
489
490 code = AddToEntry(tt, &tentry, tempg, aid);
491 if (code != PRSUCCESS0)
492 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
493
494#if defined(SUPERGROUPS1)
495 if (uentry.flags & PRGRP2)
496 code = AddToSGEntry(tt, &uentry, tempu, gid); /* mod group to be in sg */
497 else
498#endif
499 /* now, modify the user's entry as well */
500 code = AddToEntry(tt, &uentry, tempu, gid);
501 if (code != PRSUCCESS0)
502 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
503 code = ubik_EndTrans(tt);
504 if (code)
505 return code;
506 return PRSUCCESS0;
507}
508
509afs_int32
510SPR_NameToID(struct rx_call *call, namelist *aname, idlist *aid)
511{
512 afs_int32 code;
513
514 code = nameToID(call, aname, aid);
515 osi_auditU(call, PTS_NmToIdEvent"AFS_PTS_NmToId", code, AUD_END0);
516 ViceLog(125, ("PTS_NameToID: code %d\n", code))do { if ((125) <= LogLevel) (FSLog ("PTS_NameToID: code %d\n"
, code)); } while (0)
;
517 return code;
518}
519
520static afs_int32
521nameToID(struct rx_call *call, namelist *aname, idlist *aid)
522{
523 afs_int32 code;
524 struct ubik_trans *tt;
525 afs_int32 i;
526 int size;
527 int count = 0;
528
529 /* Initialize return struct */
530 aid->idlist_len = 0;
531 aid->idlist_val = NULL((void *)0);
532
533 size = aname->namelist_len;
534 if (size == 0)
535 return 0;
536 if (size < 0)
537 return PRTOOMANY(267279L);
538
539 aid->idlist_val = (afs_int32 *) malloc(size * sizeof(afs_int32));
540 if (!aid->idlist_val)
541 return PRNOMEM(267280L);
542
543 code = Initdb();
544 if (code != PRSUCCESS0)
545 return code;
546 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
547 if (code)
548 return code;
549 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
550 if (code)
551 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
552 code = read_DbHeader(tt);
553 if (code)
554 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
555
556 for (i = 0; i < aname->namelist_len; i++) {
557 char vname[256];
558 char *nameinst, *cell;
559
560 strncpy(vname, aname->namelist_val[i], sizeof(vname));
561 vname[sizeof(vname)-1] ='\0';
562
563 nameinst = vname;
564 cell = strchr(vname, '@');
565 if (cell) {
566 *cell = '\0';
567 cell++;
568 }
569
570 if (cell && afs_is_foreign_ticket_name(nameinst,NULL((void *)0),cell,pr_realmName))
571 code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
572 else
573 code = NameToID(tt, nameinst, &aid->idlist_val[i]);
574
575 if (code != PRSUCCESS0)
576 aid->idlist_val[i] = ANONYMOUSID32766;
577 osi_audit(PTS_NmToIdEvent"AFS_PTS_NmToId", code, AUD_STR1,
578 aname->namelist_val[i], AUD_ID10, aid->idlist_val[i],
579 AUD_END0);
580 ViceLog(125, ("PTS_NameToID: code %d aname %s aid %d\n", code,do { if ((125) <= LogLevel) (FSLog ("PTS_NameToID: code %d aname %s aid %d\n"
, code, aname->namelist_val[i], aid->idlist_val[i])); }
while (0)
581 aname->namelist_val[i], aid->idlist_val[i]))do { if ((125) <= LogLevel) (FSLog ("PTS_NameToID: code %d aname %s aid %d\n"
, code, aname->namelist_val[i], aid->idlist_val[i])); }
while (0)
;
582 if (count++ > 50) {
583#ifndef AFS_PTHREAD_ENV1
584 IOMGR_Poll();
585#endif
586 count = 0;
587 }
588 }
589 aid->idlist_len = aname->namelist_len;
590
591 code = ubik_EndTrans(tt);
592 if (code)
593 return code;
594 return PRSUCCESS0;
595}
596
597/*
598 * SPR_IDToName
599 * Given an array of ids, find the name for each of them.
600 * The array of ids and names is unlimited.
601 */
602afs_int32
603SPR_IDToName(struct rx_call *call, idlist *aid, namelist *aname)
604{
605 afs_int32 code;
606
607 code = idToName(call, aid, aname);
608 osi_auditU(call, PTS_IdToNmEvent"AFS_PTS_IdToNm", code, AUD_END0);
609 ViceLog(125, ("PTS_IDToName: code %d\n", code))do { if ((125) <= LogLevel) (FSLog ("PTS_IDToName: code %d\n"
, code)); } while (0)
;
610 return code;
611}
612
613static afs_int32
614idToName(struct rx_call *call, idlist *aid, namelist *aname)
615{
616 afs_int32 code;
617 struct ubik_trans *tt;
618 afs_int32 i;
619 int size;
620 int count = 0;
621
622 /* leave this first for rpc stub */
623 size = aid->idlist_len;
624 if (size == 0)
625 return 0;
626 if (size < 0)
627 return PRTOOMANY(267279L);
628 aname->namelist_val = (prname *) malloc(size * PR_MAXNAMELEN64);
629 aname->namelist_len = 0;
630 if (aname->namelist_val == 0)
631 return PRNOMEM(267280L);
632 if (aid->idlist_len == 0)
633 return 0;
634 if (size == 0)
635 return PRTOOMANY(267279L); /* rxgen will probably handle this */
636
637 code = Initdb();
638 if (code != PRSUCCESS0)
639 return code;
640 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
641 if (code)
642 return code;
643 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
644 if (code)
645 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
646 code = read_DbHeader(tt);
647 if (code)
648 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
649
650 for (i = 0; i < aid->idlist_len; i++) {
651 code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
652 if (code != PRSUCCESS0)
653 sprintf(aname->namelist_val[i], "%d", aid->idlist_val[i]);
654 osi_audit(PTS_IdToNmEvent"AFS_PTS_IdToNm", code, AUD_ID10, aid->idlist_val[i],
655 AUD_STR1, aname->namelist_val[i], AUD_END0);
656 ViceLog(125, ("PTS_idToName: code %d aid %d aname %s\n", code,do { if ((125) <= LogLevel) (FSLog ("PTS_idToName: code %d aid %d aname %s\n"
, code, aid->idlist_val[i], aname->namelist_val[i])); }
while (0)
657 aid->idlist_val[i], aname->namelist_val[i]))do { if ((125) <= LogLevel) (FSLog ("PTS_idToName: code %d aid %d aname %s\n"
, code, aid->idlist_val[i], aname->namelist_val[i])); }
while (0)
;
658 if (count++ > 50) {
659#ifndef AFS_PTHREAD_ENV1
660 IOMGR_Poll();
661#endif
662 count = 0;
663 }
664 }
665 aname->namelist_len = aid->idlist_len;
666
667 code = ubik_EndTrans(tt);
668 if (code)
669 return code;
670 return PRSUCCESS0;
671}
672
673afs_int32
674SPR_Delete(struct rx_call *call, afs_int32 aid)
675{
676 afs_int32 code;
677 afs_int32 cid = ANONYMOUSID32766;
678
679 code = Delete(call, aid, &cid);
680 osi_auditU(call, PTS_DelEvent"AFS_PTS_Del", code, AUD_ID10, aid, AUD_END0);
681 ViceLog(5, ("PTS_Delete: code %d cid %d aid %d\n", code, cid, aid))do { if ((5) <= LogLevel) (FSLog ("PTS_Delete: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
682 return code;
683}
684
685static afs_int32
686Delete(struct rx_call *call, afs_int32 aid, afs_int32 *cid)
687{
688 afs_int32 code;
689 struct ubik_trans *tt;
690 struct prentry tentry;
691 afs_int32 loc, nptr;
692 int count;
693
694 code = Initdb();
695 if (code)
696 return code;
697 if (code != PRSUCCESS0)
698 return code;
699 if (aid == SYSADMINID-204 || aid == ANYUSERID-101 || aid == AUTHUSERID-102
700 || aid == ANONYMOUSID32766)
701 return PRPERM(267269L);
702 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
703 if (code)
704 return code;
705 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
706 if (code)
707 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
708 code = read_DbHeader(tt);
709 if (code)
710 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
711
712 code = WhoIsThis(call, tt, cid);
713 if (code)
714 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
715
716 /* Read in entry to be deleted */
717 loc = FindByID(tt, aid);
718 if (loc == 0)
719 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
720 code = pr_ReadEntry(tt, 0, loc, &tentry);
721 if (code)
722 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
723
724 /* Do some access checking */
725 if (tentry.owner != *cid && !IsAMemberOf(tt, *cid, SYSADMINID-204)
726 && !IsAMemberOf(tt, *cid, tentry.owner) && !pr_noAuth)
727 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
728
729 /* Delete each continuation block as a separate transaction so that no one
730 * transaction become to large to complete. */
731 nptr = tentry.next;
732 while (nptr != 0) {
733 struct contentry centry;
734 int i;
735
736 code = pr_ReadCoEntry(tt, 0, nptr, &centry);
737 if (code != 0)
738 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
739 for (i = 0; i < COSIZE39; i++) {
740 if (centry.entries[i] == PRBADID0x80000000)
741 continue;
742 if (centry.entries[i] == 0)
743 break;
744#if defined(SUPERGROUPS1)
745 if (aid < 0 && centry.entries[i] < 0) /* Supergroup */
746 code = RemoveFromSGEntry(tt, aid, centry.entries[i]);
747 else
748#endif
749 code = RemoveFromEntry(tt, aid, centry.entries[i]);
750 if (code)
751 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
752 tentry.count--; /* maintain count */
753#ifndef AFS_PTHREAD_ENV1
754 if ((i & 3) == 0)
755 IOMGR_Poll();
756#endif
757 }
758 tentry.next = centry.next; /* thread out this block */
759 code = FreeBlock(tt, nptr); /* free continuation block */
760 if (code)
761 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
762 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
763 if (code)
764 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
765
766 /* end this trans and start a new one */
767 code = ubik_EndTrans(tt);
768 if (code)
769 return code;
770#ifndef AFS_PTHREAD_ENV1
771 IOMGR_Poll(); /* just to keep the connection alive */
772#endif
773 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
774 if (code)
775 return code;
776 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
777 if (code)
778 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
779
780 /* re-read entry to get consistent uptodate info */
781 loc = FindByID(tt, aid);
782 if (loc == 0)
783 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
784 code = pr_ReadEntry(tt, 0, loc, &tentry);
785 if (code)
786 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
787
788 nptr = tentry.next;
789 }
790
791#if defined(SUPERGROUPS1)
792 /* Delete each continuation block as a separate transaction
793 * so that no one transaction become too large to complete. */
794 {
795 struct prentryg *tentryg = (struct prentryg *)&tentry;
796 nptr = tentryg->nextsg;
797 while (nptr != 0) {
798 struct contentry centry;
799 int i;
800
801 code = pr_ReadCoEntry(tt, 0, nptr, &centry);
802 if (code != 0)
803 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
804 for (i = 0; i < COSIZE39; i++) {
805 if (centry.entries[i] == PRBADID0x80000000)
806 continue;
807 if (centry.entries[i] == 0)
808 break;
809 code = RemoveFromEntry(tt, aid, centry.entries[i]);
810 if (code)
811 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
812 tentryg->countsg--; /* maintain count */
813#ifndef AFS_PTHREAD_ENV1
814 if ((i & 3) == 0)
815 IOMGR_Poll();
816#endif
817 }
818 tentryg->nextsg = centry.next; /* thread out this block */
819 code = FreeBlock(tt, nptr); /* free continuation block */
820 if (code)
821 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
822 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
823 if (code)
824 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
825
826 /* end this trans and start a new one */
827 code = ubik_EndTrans(tt);
828 if (code)
829 return code;
830#ifndef AFS_PTHREAD_ENV1
831 IOMGR_Poll(); /* just to keep the connection alive */
832#endif
833
834 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
835 if (code)
836 return code;
837 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
838 if (code)
839 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
840
841 /* re-read entry to get consistent uptodate info */
842 loc = FindByID(tt, aid);
843 if (loc == 0)
844 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
845 code = pr_ReadEntry(tt, 0, loc, &tentry);
846 if (code)
847 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
848
849 nptr = tentryg->nextsg;
850 }
851 }
852
853#endif /* SUPERGROUPS */
854
855 /* Then move the owned chain, except possibly ourself to the orphan list.
856 * Because this list can be very long and so exceed the size of a ubik
857 * transaction, we start a new transaction every 50 entries. */
858 count = 0;
859 nptr = tentry.owned;
860 while (nptr != 0) {
861 struct prentry nentry;
862
863 code = pr_ReadEntry(tt, 0, nptr, &nentry);
864 if (code)
865 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
866 nptr = tentry.owned = nentry.nextOwned; /* thread out */
867
868 if (nentry.id != tentry.id) { /* don't add us to orphan chain! */
869 code = AddToOrphan(tt, nentry.id);
870 if (code)
871 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
872 count++;
873#ifndef AFS_PTHREAD_ENV1
874 if ((count & 3) == 0)
875 IOMGR_Poll();
876#endif
877 }
878 if (count < 50)
879 continue;
880 code = pr_WriteEntry(tt, 0, loc, &tentry); /* update main entry */
881 if (code)
882 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
883
884 /* end this trans and start a new one */
885 code = ubik_EndTrans(tt);
886 if (code)
887 return code;
888#ifndef AFS_PTHREAD_ENV1
889 IOMGR_Poll(); /* just to keep the connection alive */
890#endif
891 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
892 if (code)
893 return code;
894 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
895 if (code)
896 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
897
898 /* re-read entry to get consistent uptodate info */
899 loc = FindByID(tt, aid);
900 if (loc == 0)
901 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
902 code = pr_ReadEntry(tt, 0, loc, &tentry);
903 if (code)
904 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
905
906 nptr = tentry.owned;
907 }
908
909 /* now do what's left of the deletion stuff */
910 code = DeleteEntry(tt, &tentry, loc);
911 if (code != PRSUCCESS0)
912 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
913
914 code = ubik_EndTrans(tt);
915 if (code)
916 return code;
917 return PRSUCCESS0;
918}
919
920afs_int32
921SPR_UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
922 struct PrUpdateEntry *uentry)
923{
924 afs_int32 code;
925 afs_int32 cid = ANONYMOUSID32766;
926
927 code = UpdateEntry(call, aid, name, uentry, &cid);
928 osi_auditU(call, PTS_UpdEntEvent"AFS_PTS_UpdEnt", code, AUD_ID10, aid, AUD_STR1, name, AUD_END0);
929 ViceLog(5, ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n", code, cid, aid, name))do { if ((5) <= LogLevel) (FSLog ("PTS_UpdateEntry: code %d cid %d aid %d name %s\n"
, code, cid, aid, name)); } while (0)
;
930 return code;
931}
932
933afs_int32
934UpdateEntry(struct rx_call *call, afs_int32 aid, char *name,
935 struct PrUpdateEntry *uentry, afs_int32 *cid)
936{
937 afs_int32 code;
938 struct ubik_trans *tt;
939 struct prentry tentry;
940 afs_int32 loc;
941 int id = 0;
942
943 code = Initdb();
944 if (code)
945 return code;
946 if (code != PRSUCCESS0)
947 return code;
948 if (aid) {
949 id = aid;
950 if (aid == SYSADMINID-204 || aid == ANYUSERID-101 || aid == AUTHUSERID-102
951 || aid == ANONYMOUSID32766)
952 return PRPERM(267269L);
953 }
954 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
955 if (code)
956 return code;
957 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
958 if (code)
959 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
960 code = read_DbHeader(tt);
961 if (code)
962 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
963
964 code = WhoIsThis(call, tt, cid);
965 if (code)
966 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
967 code = IsAMemberOf(tt, *cid, SYSADMINID-204);
968 if (!code && !pr_noAuth)
969 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
970
971 /* Read in entry to be deleted */
972 if (id) {
973 loc = FindByID(tt, aid);
974 } else {
975 loc = FindByName(tt, name, &tentry);
976 }
977 if (loc == 0)
978 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
979 code = pr_ReadEntry(tt, 0, loc, &tentry);
980 if (code)
981 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
982
983 if (uentry->Mask & PRUPDATE_NAMEHASH0x0008) {
984 int tloc;
985 code = RemoveFromNameHash(tt, tentry.name, &tloc);
986 if (code != PRSUCCESS0)
987 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
988 code = AddToNameHash(tt, tentry.name, loc);
989 if (code)
990 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
991 }
992
993 if (uentry->Mask & PRUPDATE_IDHASH0x0010) {
994 int tloc;
995 if (!id)
996 id = tentry.id;
997 code = RemoveFromIDHash(tt, id, &tloc);
998 if (code != PRSUCCESS0)
999 ABORT_WITH(tt, PRDBFAIL)return(ubik_AbortTrans(tt),(267267L));
1000 code = AddToIDHash(tt, id, loc);
1001 if (code)
1002 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1003 }
1004
1005 code = ubik_EndTrans(tt);
1006 if (code)
1007 return code;
1008 return PRSUCCESS0;
1009}
1010
1011afs_int32
1012SPR_RemoveFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid)
1013{
1014 afs_int32 code;
1015 afs_int32 cid = ANONYMOUSID32766;
1016
1017 code = removeFromGroup(call, aid, gid, &cid);
1018 osi_auditU(call, PTS_RmFmGrpEvent"AFS_PTS_RmFmGrp", code, AUD_ID10, gid, AUD_ID10, aid,
1019 AUD_END0);
1020 ViceLog(5, ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n", code, cid, gid, aid))do { if ((5) <= LogLevel) (FSLog ("PTS_RemoveFromGroup: code %d cid %d gid %d aid %d\n"
, code, cid, gid, aid)); } while (0)
;
1021 return code;
1022}
1023
1024static afs_int32
1025removeFromGroup(struct rx_call *call, afs_int32 aid, afs_int32 gid,
1026 afs_int32 *cid)
1027{
1028 afs_int32 code;
1029 struct ubik_trans *tt;
1030 afs_int32 tempu;
1031 afs_int32 tempg;
1032 struct prentry uentry;
1033 struct prentry gentry;
1034
1035 code = Initdb();
1036 if (code != PRSUCCESS0)
1037 return code;
1038 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
1039 if (code)
1040 return code;
1041 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
1042 if (code)
1043 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1044 code = read_DbHeader(tt);
1045 if (code)
1046 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1047
1048 code = WhoIsThis(call, tt, cid);
1049 if (code)
1050 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1051 tempu = FindByID(tt, aid);
1052 if (!tempu)
1053 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1054 tempg = FindByID(tt, gid);
1055 if (!tempg)
1056 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1057 memset(&uentry, 0, sizeof(uentry));
1058 memset(&gentry, 0, sizeof(gentry));
1059 code = pr_ReadEntry(tt, 0, tempu, &uentry);
1060 if (code != 0)
1061 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1062 code = pr_ReadEntry(tt, 0, tempg, &gentry);
1063 if (code != 0)
1064 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1065 if (!(gentry.flags & PRGRP2))
1066 ABORT_WITH(tt, PRNOTGROUP)return(ubik_AbortTrans(tt),(267270L));
1067#if !defined(SUPERGROUPS1)
1068 if (uentry.flags & PRGRP2)
1069 ABORT_WITH(tt, PRNOTUSER)return(ubik_AbortTrans(tt),(267271L));
1070#endif
1071 if (!AccessOK(tt, *cid, &gentry, PRP_REMOVE_MEM(0x01 << 16), 0))
1072 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1073 code = RemoveFromEntry(tt, aid, gid);
1074 if (code != PRSUCCESS0)
1075 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1076#if defined(SUPERGROUPS1)
1077 if (!(uentry.flags & PRGRP2))
1078#endif
1079 code = RemoveFromEntry(tt, gid, aid);
1080#if defined(SUPERGROUPS1)
1081 else
1082 code = RemoveFromSGEntry(tt, gid, aid);
1083#endif
1084 if (code != PRSUCCESS0)
1085 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1086
1087 code = ubik_EndTrans(tt);
1088 if (code)
1089 return code;
1090 return PRSUCCESS0;
1091}
1092
1093
1094afs_int32
1095SPR_GetCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over)
1096{
1097 afs_int32 code;
1098 afs_int32 cid = ANONYMOUSID32766;
1099
1100 code = getCPS(call, aid, alist, over, &cid);
1101 osi_auditU(call, PTS_GetCPSEvent"AFS_PTS_GetCPS", code, AUD_ID10, aid, AUD_END0);
1102 ViceLog(125, ("PTS_GetCPS: code %d cid %d aid %d\n", code, cid, aid))do { if ((125) <= LogLevel) (FSLog ("PTS_GetCPS: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
1103 return code;
1104}
1105
1106static afs_int32
1107getCPS(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *over,
1108 afs_int32 *cid)
1109{
1110 afs_int32 code;
1111 struct ubik_trans *tt;
1112 afs_int32 temp;
1113 struct prentry tentry;
1114
1115 *over = 0;
1116 alist->prlist_len = 0;
1117 alist->prlist_val = NULL((void *)0);
1118 code = Initdb();
1119 if (code != PRSUCCESS0)
1120 return code;
1121 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1122 if (code)
1123 return code;
1124 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1125 if (code)
1126 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1127 code = read_DbHeader(tt);
1128 if (code)
1129 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1130
1131 temp = FindByID(tt, aid);
1132 if (!temp)
1133 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1134 code = pr_ReadEntry(tt, 0, temp, &tentry);
1135 if (code)
1136 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1137
1138 /* afs does authenticate now */
1139 code = WhoIsThis(call, tt, cid);
1140 if (code || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM(0x08 << 16), PRP_MEMBER_ANY(0x10 << 16)))
1141 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1142
1143 code = GetList(tt, &tentry, alist, 1);
1144 if (code != PRSUCCESS0)
1145 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1146
1147 code = ubik_EndTrans(tt);
1148 return code;
1149}
1150
1151
1152int
1153inCPS(prlist CPS, afs_int32 id)
1154{
1155 int i;
1156
1157 for (i = (CPS.prlist_len - 1); i >= 0; i--) {
1158 if (CPS.prlist_val[i] == id)
1159 return (1);
1160 }
1161 return (0);
1162}
1163
1164
1165afs_int32
1166SPR_GetCPS2(struct rx_call *call, afs_int32 aid, afs_int32 ahost,
1167 prlist *alist, afs_int32 *over)
1168{
1169 afs_int32 code;
1170 afs_int32 cid = ANONYMOUSID32766;
1171
1172 code = getCPS2(call, aid, ahost, alist, over, &cid);
1173 osi_auditU(call, PTS_GetCPS2Event"AFS_PTS_GetCPS2", code, AUD_ID10, aid, AUD_HOST4, htonl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
,
1174 AUD_END0);
1175 ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost))do { if ((125) <= LogLevel) (FSLog ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n"
, code, cid, aid, ahost)); } while (0)
;
1176 return code;
1177}
1178
1179static afs_int32
1180getCPS2(struct rx_call *call, afs_int32 aid, afs_uint32 ahost, prlist *alist,
1181 afs_int32 *over, afs_int32 *cid)
1182{
1183 afs_int32 code;
1184 struct ubik_trans *tt;
1185 afs_int32 temp;
1186 struct prentry tentry;
1187 struct prentry host_tentry;
1188 afs_int32 hostid;
1189 int host_list = 0;
1190 struct in_addr iaddr;
1191
1192 *over = 0;
1193 iaddr.s_addr = ntohl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
;
1194 alist->prlist_len = 0;
1195 alist->prlist_val = NULL((void *)0);
1196 code = Initdb();
1197 if (code != PRSUCCESS0)
1198 return code;
1199 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1200 if (code)
1201 return code;
1202 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1203 if (code)
1204 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1205 code = read_DbHeader(tt);
1206 if (code)
1207 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1208
1209 if (aid != PRBADID0x80000000) {
1210 temp = FindByID(tt, aid);
1211 if (!temp)
1212 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1213 code = pr_ReadEntry(tt, 0, temp, &tentry);
1214 if (code)
1215 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1216
1217 /* afs does authenticate now */
1218 code = WhoIsThis(call, tt, cid);
1219 if (code
1220 || !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM(0x08 << 16), PRP_MEMBER_ANY(0x10 << 16)))
1221 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1222 }
1223 code = NameToID(tt, inet_ntoa__inet_ntoa(iaddr), &hostid);
1224 if (code == PRSUCCESS0 && hostid != 0) {
1225 temp = FindByID(tt, hostid);
1226 if (temp) {
1227 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1228 if (code == PRSUCCESS0)
1229 host_list = 1;
1230 else
1231 fprintf(stderr__stderrp, "pr_ReadEntry returned %d\n", code);
1232 } else
1233 fprintf(stderr__stderrp, "FindByID Failed -- Not found\n");
1234 }
1235 if (host_list)
1236 code = GetList2(tt, &tentry, &host_tentry, alist, 1);
1237 else
1238 code = GetList(tt, &tentry, alist, 1);
1239 if (!code)
1240 code = addWildCards(tt, alist, ntohl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
);
1241 if (code != PRSUCCESS0)
1242 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1243
1244 code = ubik_EndTrans(tt);
1245 return code;
1246}
1247
1248
1249afs_int32
1250SPR_GetHostCPS(struct rx_call *call, afs_int32 ahost, prlist *alist,
1251 afs_int32 *over)
1252{
1253 afs_int32 code;
1254
1255 code = getHostCPS(call, ahost, alist, over);
1256 osi_auditU(call, PTS_GetHCPSEvent"AFS_PTS_GetHCPS", code, AUD_HOST4, htonl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
, AUD_END0);
1257 ViceLog(125, ("PTS_GetHostCPS: code %d ahost %d\n", code, ahost))do { if ((125) <= LogLevel) (FSLog ("PTS_GetHostCPS: code %d ahost %d\n"
, code, ahost)); } while (0)
;
1258 return code;
1259}
1260
1261afs_int32
1262getHostCPS(struct rx_call *call, afs_uint32 ahost, prlist *alist,
1263 afs_int32 *over)
1264{
1265 afs_int32 code, temp;
1266 struct ubik_trans *tt;
1267 struct prentry host_tentry;
1268 afs_int32 hostid;
1269 struct in_addr iaddr;
1270
1271 *over = 0;
1272 iaddr.s_addr = ntohl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
;
1273 alist->prlist_len = 0;
1274 alist->prlist_val = NULL((void *)0);
1275 code = Initdb();
1276 if (code != PRSUCCESS0)
1277 return code;
1278 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1279 if (code)
1280 return code;
1281 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1282 if (code)
1283 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1284 code = read_DbHeader(tt);
1285 if (code)
1286 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1287
1288 code = NameToID(tt, inet_ntoa__inet_ntoa(iaddr), &hostid);
1289 if (code == PRSUCCESS0 && hostid != 0) {
1290 temp = FindByID(tt, hostid);
1291 if (temp) {
1292 code = pr_ReadEntry(tt, 0, temp, &host_tentry);
1293 if (code == PRSUCCESS0) {
1294 code = GetList(tt, &host_tentry, alist, 0);
1295 if (code)
1296 goto bad;
1297 } else
1298 fprintf(stderr__stderrp, "pr_ReadEntry returned %d\n", code);
1299 } else
1300 fprintf(stderr__stderrp, "FindByID Failed -- Not found\n");
1301 }
1302 code = addWildCards(tt, alist, ntohl(ahost)(__builtin_constant_p(ahost) ? ((((__uint32_t)(ahost)) >>
24) | ((((__uint32_t)(ahost)) & (0xff << 16)) >>
8) | ((((__uint32_t)(ahost)) & (0xff << 8)) <<
8) | (((__uint32_t)(ahost)) << 24)) : __bswap32_var(ahost
))
);
1303 bad:
1304 if (code != PRSUCCESS0)
1305 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1306
1307 code = ubik_EndTrans(tt);
1308 return code;
1309}
1310
1311
1312afs_int32
1313SPR_ListMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
1314{
1315 afs_int32 code;
1316
1317 code = listMax(call, uid, gid);
1318 osi_auditU(call, PTS_LstMaxEvent"AFS_PTS_LstMax", code, AUD_END0);
1319 ViceLog(125, ("PTS_ListMax: code %d\n", code))do { if ((125) <= LogLevel) (FSLog ("PTS_ListMax: code %d\n"
, code)); } while (0)
;
1320 return code;
1321}
1322
1323afs_int32
1324listMax(struct rx_call *call, afs_int32 *uid, afs_int32 *gid)
1325{
1326 afs_int32 code;
1327 struct ubik_trans *tt;
1328
1329 code = Initdb();
1330 if (code != PRSUCCESS0)
1331 return code;
1332 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1333 if (code)
1334 return code;
1335 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1336 if (code)
1337 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1338 code = read_DbHeader(tt);
1339 if (code)
1340 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1341
1342 code = GetMax(tt, uid, gid);
1343 if (code != PRSUCCESS0)
1344 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1345
1346 code = ubik_EndTrans(tt);
1347 if (code)
1348 return code;
1349 return PRSUCCESS0;
1350}
1351
1352afs_int32
1353SPR_SetMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag)
1354{
1355 afs_int32 code;
1356 afs_int32 cid = ANONYMOUSID32766;
1357
1358 code = setMax(call, aid, gflag, &cid);
1359 osi_auditU(call, PTS_SetMaxEvent"AFS_PTS_SetMax", code, AUD_ID10, aid, AUD_LONG5, gflag,
1360 AUD_END0);
1361 ViceLog(125, ("PTS_SetMax: code %d cid %d aid %d gflag %d\n", code, cid, aid, gflag))do { if ((125) <= LogLevel) (FSLog ("PTS_SetMax: code %d cid %d aid %d gflag %d\n"
, code, cid, aid, gflag)); } while (0)
;
1362 return code;
1363}
1364
1365static afs_int32
1366setMax(struct rx_call *call, afs_int32 aid, afs_int32 gflag, afs_int32 *cid)
1367{
1368 afs_int32 code;
1369 struct ubik_trans *tt;
1370
1371 code = Initdb();
1372 if (code != PRSUCCESS0)
1373 return code;
1374 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
1375 if (code)
1376 return code;
1377 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
1378 if (code)
1379 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1380 code = read_DbHeader(tt);
1381 if (code)
1382 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1383
1384 code = WhoIsThis(call, tt, cid);
1385 if (code)
1386 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1387 if (!AccessOK(tt, *cid, 0, 0, 0))
1388 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1389 if (((gflag & PRGRP2) && (aid > 0)) || (!(gflag & PRGRP2) && (aid < 0)))
1390 ABORT_WITH(tt, PRBADARG)return(ubik_AbortTrans(tt),(267273L));
1391
1392 code = SetMax(tt, aid, gflag);
1393 if (code != PRSUCCESS0)
1394 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1395
1396 code = ubik_EndTrans(tt);
1397 if (code)
1398 return code;
1399 return PRSUCCESS0;
1400}
1401
1402afs_int32
1403SPR_ListEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry)
1404{
1405 afs_int32 code;
1406 afs_int32 cid = ANONYMOUSID32766;
1407
1408 code = listEntry(call, aid, aentry, &cid);
1409 osi_auditU(call, PTS_LstEntEvent"AFS_PTS_LstEnt", code, AUD_ID10, aid, AUD_END0);
1410 ViceLog(125, ("PTS_ListEntry: code %d cid %d aid %d\n", code, cid, aid))do { if ((125) <= LogLevel) (FSLog ("PTS_ListEntry: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
1411 return code;
1412}
1413
1414static afs_int32
1415listEntry(struct rx_call *call, afs_int32 aid, struct prcheckentry *aentry,
1416 afs_int32 *cid)
1417{
1418 afs_int32 code;
1419 struct ubik_trans *tt;
1420 afs_int32 temp;
1421 struct prentry tentry;
1422
1423 code = Initdb();
1424 if (code != PRSUCCESS0)
1425 return code;
1426 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1427 if (code)
1428 return code;
1429 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1430 if (code)
1431 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1432 code = read_DbHeader(tt);
1433 if (code)
1434 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1435
1436 code = WhoIsThis(call, tt, cid);
1437 if (code)
1438 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1439 temp = FindByID(tt, aid);
1440 if (!temp)
1441 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1442 code = pr_ReadEntry(tt, 0, temp, &tentry);
1443 if (code != 0)
1444 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1445 if (!AccessOK(tt, *cid, &tentry, PRP_STATUS_MEM(0x40 << 16), PRP_STATUS_ANY(0x80 << 16)))
1446 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1447
1448 aentry->flags = tentry.flags >> PRIVATE_SHIFT16;
1449 if (aentry->flags == 0) {
1450 if (tentry.flags & PRGRP2)
1451 aentry->flags = prp_group_default >> PRIVATE_SHIFT16;
1452 else
1453 aentry->flags = prp_user_default >> PRIVATE_SHIFT16;
1454 }
1455 aentry->owner = tentry.owner;
1456 aentry->id = tentry.id;
1457 strncpy(aentry->name, tentry.name, PR_MAXNAMELEN64);
1458 aentry->creator = tentry.creator;
1459 aentry->ngroups = tentry.ngroups;
1460 aentry->nusers = tentry.nusers;
1461 aentry->count = tentry.count;
1462 memset(aentry->reserved, 0, sizeof(aentry->reserved));
1463 code = ubik_EndTrans(tt);
1464 if (code)
1465 return code;
1466 return PRSUCCESS0;
1467}
1468
1469afs_int32
1470SPR_ListEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1471 prentries *bulkentries, afs_int32 *nextstartindex)
1472{
1473 afs_int32 code;
1474 afs_int32 cid = ANONYMOUSID32766;
1475
1476 code = listEntries(call, flag, startindex, bulkentries, nextstartindex, &cid);
1477 osi_auditU(call, PTS_LstEntsEvent"AFS_PTS_LstEnts", code, AUD_LONG5, flag, AUD_END0);
1478 ViceLog(125, ("PTS_ListEntries: code %d cid %d flag %d\n", code, cid, flag))do { if ((125) <= LogLevel) (FSLog ("PTS_ListEntries: code %d cid %d flag %d\n"
, code, cid, flag)); } while (0)
;
1479 return code;
1480}
1481
1482static afs_int32
1483listEntries(struct rx_call *call, afs_int32 flag, afs_int32 startindex,
1484 prentries *bulkentries, afs_int32 *nextstartindex, afs_int32 *cid)
1485{
1486 afs_int32 code;
1487 struct ubik_trans *tt;
1488 afs_int32 i, eof, pos, maxentries, f;
1489 struct prentry tentry;
1490 afs_int32 pollcount = 0;
1491
1492 *nextstartindex = -1;
1493 bulkentries->prentries_val = 0;
1494 bulkentries->prentries_len = 0;
1495
1496 code = Initdb();
1497 if (code != PRSUCCESS0)
1498 return code;
1499 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1500 if (code)
1501 return code;
1502 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1503 if (code)
1504 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1505 code = read_DbHeader(tt);
1506 if (code)
1507 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1508
1509 /* Make sure we are an authenticated caller and that we are on the
1510 * SYSADMIN list.
1511 */
1512 code = WhoIsThis(call, tt, cid);
1513 if (code)
1514 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1515 code = IsAMemberOf(tt, *cid, SYSADMINID-204);
1516 if (!code && !pr_noAuth)
1517 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1518
1519 eof = ntohl(cheader.eofPtr)(__builtin_constant_p(cheader.eofPtr) ? ((((__uint32_t)(cheader
.eofPtr)) >> 24) | ((((__uint32_t)(cheader.eofPtr)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(cheader.eofPtr
)) & (0xff << 8)) << 8) | (((__uint32_t)(cheader
.eofPtr)) << 24)) : __bswap32_var(cheader.eofPtr))
- sizeof(cheader);
1520 maxentries = eof / sizeof(struct prentry);
1521 for (i = startindex; i < maxentries; i++) {
1522 pos = i * sizeof(struct prentry) + sizeof(cheader);
1523 code = pr_ReadEntry(tt, 0, pos, &tentry);
1524 if (code)
1525 goto done;
1526
1527 if (++pollcount > 50) {
1528#ifndef AFS_PTHREAD_ENV1
1529 IOMGR_Poll();
1530#endif
1531 pollcount = 0;
1532 }
1533
1534 f = (tentry.flags & PRTYPE0x3f);
1535 if (((flag & PRUSERS0x1) && (f == 0)) || /* User entry */
1536 ((flag & PRGROUPS0x2) && (f & PRGRP2))) { /* Group entry */
1537 code = put_prentries(&tentry, bulkentries);
1538 if (code == -1)
1539 break; /* Filled return array */
1540 if (code)
1541 goto done;
1542 }
1543 }
1544 code = 0;
1545 if (i < maxentries)
1546 *nextstartindex = i;
1547
1548 done:
1549 if (code) {
1550 if (bulkentries->prentries_val)
1551 free(bulkentries->prentries_val);
1552 bulkentries->prentries_val = 0;
1553 bulkentries->prentries_len = 0;
1554 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1555 } else {
1556 code = ubik_EndTrans(tt);
1557 }
1558 if (code)
1559 return code;
1560 return PRSUCCESS0;
1561}
1562
1563#define PR_MAXENTRIES500 500
1564static afs_int32
1565put_prentries(struct prentry *tentry, prentries *bulkentries)
1566{
1567 struct prlistentries *entry;
1568
1569 if (bulkentries->prentries_val == 0) {
1570 bulkentries->prentries_len = 0;
1571 bulkentries->prentries_val =
1572 (struct prlistentries *)malloc(PR_MAXENTRIES500 *
1573 sizeof(struct prentry));
1574 if (!bulkentries->prentries_val) {
1575 return (PRNOMEM(267280L));
1576 }
1577 }
1578
1579 if (bulkentries->prentries_len >= PR_MAXENTRIES500) {
1580 return (-1);
1581 }
1582
1583 entry = (struct prlistentries *)bulkentries->prentries_val;
1584 entry += bulkentries->prentries_len;
1585
1586 entry->flags = tentry->flags >> PRIVATE_SHIFT16;
1587 if (entry->flags == 0) {
1588 entry->flags =
1589 ((tentry->
1590 flags & PRGRP2) ? prp_group_default : prp_user_default) >>
1591 PRIVATE_SHIFT16;
1592 }
1593 entry->owner = tentry->owner;
1594 entry->id = tentry->id;
1595 entry->creator = tentry->creator;
1596 entry->ngroups = tentry->ngroups;
1597 entry->nusers = tentry->nusers;
1598 entry->count = tentry->count;
1599 strncpy(entry->name, tentry->name, PR_MAXNAMELEN64);
1600 memset(entry->reserved, 0, sizeof(entry->reserved));
1601 bulkentries->prentries_len++;
1602 return 0;
1603}
1604
1605afs_int32
1606SPR_ChangeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1607 afs_int32 newid)
1608{
1609 afs_int32 code;
1610 afs_int32 cid = ANONYMOUSID32766;
1611
1612 code = changeEntry(call, aid, name, oid, newid, &cid);
1613 osi_auditU(call, PTS_ChgEntEvent"AFS_PTS_ChgEnt", code, AUD_ID10, aid, AUD_STR1, name,
1614 AUD_LONG5, oid, AUD_LONG5, newid, AUD_END0);
1615 ViceLog(5, ("PTS_ChangeEntry: code %d cid %d aid %d name %s oid %d newid %d\n", code, cid, aid, name, oid, newid))do { if ((5) <= LogLevel) (FSLog ("PTS_ChangeEntry: code %d cid %d aid %d name %s oid %d newid %d\n"
, code, cid, aid, name, oid, newid)); } while (0)
;
1616 return code;
1617}
1618
1619static afs_int32
1620changeEntry(struct rx_call *call, afs_int32 aid, char *name, afs_int32 oid,
1621 afs_int32 newid, afs_int32 *cid)
1622{
1623 afs_int32 code;
1624 struct ubik_trans *tt;
1625 afs_int32 pos;
1626
1627 if (!name)
1628 return PRPERM(267269L);
1629 stolower(name);
1630
1631 code = Initdb();
1632 if (code)
1633 return code;
1634 if (aid == ANYUSERID-101 || aid == AUTHUSERID-102 || aid == ANONYMOUSID32766
1635 || aid == SYSADMINID-204)
1636 return PRPERM(267269L);
1637 if (code != PRSUCCESS0)
1638 return code;
1639 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
1640 if (code)
1641 return code;
1642 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
1643 if (code)
1644 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1645 code = read_DbHeader(tt);
1646 if (code)
1647 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1648
1649 code = WhoIsThis(call, tt, cid);
1650 if (code)
1651 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1652 pos = FindByID(tt, aid);
1653 if (!pos)
1654 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1655 /* protection check in changeentry */
1656 code = ChangeEntry(tt, aid, *cid, name, oid, newid);
1657 if (code != PRSUCCESS0)
1658 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1659
1660 code = ubik_EndTrans(tt);
1661 return code;
1662}
1663
1664afs_int32
1665SPR_SetFieldsEntry(struct rx_call *call,
1666 afs_int32 id,
1667 afs_int32 mask, /* specify which fields to update */
1668 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1669 afs_int32 spare1, afs_int32 spare2)
1670{
1671 afs_int32 code;
1672 afs_int32 cid = ANONYMOUSID32766;
1673
1674 code =
1675 setFieldsEntry(call, id, mask, flags, ngroups, nusers, spare1,
1676 spare2, &cid);
1677 osi_auditU(call, PTS_SetFldEntEvent"AFS_PTS_SetFEnt", code, AUD_ID10, id, AUD_END0);
1678 ViceLog(5, ("PTS_SetFieldsEntry: code %d cid %d id %d\n", code, cid, id))do { if ((5) <= LogLevel) (FSLog ("PTS_SetFieldsEntry: code %d cid %d id %d\n"
, code, cid, id)); } while (0)
;
1679 return code;
1680}
1681
1682static afs_int32
1683setFieldsEntry(struct rx_call *call,
1684 afs_int32 id,
1685 afs_int32 mask, /* specify which fields to update */
1686 afs_int32 flags, afs_int32 ngroups, afs_int32 nusers,
1687 afs_int32 spare1, afs_int32 spare2, afs_int32 *cid)
1688{
1689 afs_int32 code;
1690 struct ubik_trans *tt;
1691 afs_int32 pos;
1692 struct prentry tentry;
1693 afs_int32 tflags;
1694
1695 if (mask == 0)
1696 return 0; /* no-op */
1697 code = Initdb();
1698 if (code)
1699 return code;
1700 if (id == ANYUSERID-101 || id == AUTHUSERID-102 || id == ANONYMOUSID32766)
1701 return PRPERM(267269L);
1702 if (code != PRSUCCESS0)
1703 return code;
1704 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS1, &tt);
1705 if (code)
1706 return code;
1707 code = ubik_SetLock(tt, 1, 1, LOCKWRITE2);
1708 if (code)
1709 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1710 code = read_DbHeader(tt);
1711 if (code)
1712 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1713
1714 code = WhoIsThis(call, tt, cid);
1715 if (code)
1716 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1717 pos = FindByID(tt, id);
1718 if (!pos)
1719 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1720 code = pr_ReadEntry(tt, 0, pos, &tentry);
1721 if (code)
1722 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1723 tflags = tentry.flags;
1724
1725 if (mask & (PR_SF_NGROUPS(1<<31) | PR_SF_NUSERS(1<<30))) {
1726 if (!AccessOK(tt, *cid, 0, 0, 0))
1727 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1728 if ((tflags & PRQUOTA(1<<7)) == 0) { /* default if only setting one */
1729 tentry.ngroups = tentry.nusers = 20;
1730 }
1731 } else {
1732 if (!AccessOK(tt, *cid, &tentry, 0, 0))
1733 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1734 }
1735
1736 if (mask & 0xffff) { /* if setting flag bits */
1737 afs_int32 flagsMask = mask & 0xffff;
1738 tflags &= ~(flagsMask << PRIVATE_SHIFT16);
1739 tflags |= (flags & flagsMask) << PRIVATE_SHIFT16;
1740 tflags |= PRACCESS(1<<6);
1741 }
1742
1743 if (mask & PR_SF_NGROUPS(1<<31)) { /* setting group limit */
1744 if (ngroups < 0)
1745 ABORT_WITH(tt, PRBADARG)return(ubik_AbortTrans(tt),(267273L));
1746 tentry.ngroups = ngroups;
1747 tflags |= PRQUOTA(1<<7);
1748 }
1749
1750 if (mask & PR_SF_NUSERS(1<<30)) { /* setting foreign user limit */
1751 if (nusers < 0)
1752 ABORT_WITH(tt, PRBADARG)return(ubik_AbortTrans(tt),(267273L));
1753 tentry.nusers = nusers;
1754 tflags |= PRQUOTA(1<<7);
1755 }
1756 tentry.flags = tflags;
1757
1758 code = pr_WriteEntry(tt, 0, pos, &tentry);
1759 if (code)
1760 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1761
1762 code = ubik_EndTrans(tt);
1763 return code;
1764}
1765
1766afs_int32
1767SPR_ListElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1768 afs_int32 *over)
1769{
1770 afs_int32 code;
1771 afs_int32 cid = ANONYMOUSID32766;
1772
1773 code = listElements(call, aid, alist, over, &cid);
1774 osi_auditU(call, PTS_LstEleEvent"AFS_PTS_LstEle", code, AUD_ID10, aid, AUD_END0);
1775 ViceLog(125, ("PTS_ListElements: code %d cid %d aid %d\n", code, cid, aid))do { if ((125) <= LogLevel) (FSLog ("PTS_ListElements: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
1776 return code;
1777}
1778
1779static afs_int32
1780listElements(struct rx_call *call, afs_int32 aid, prlist *alist,
1781 afs_int32 *over, afs_int32 *cid)
1782{
1783 afs_int32 code;
1784 struct ubik_trans *tt;
1785 afs_int32 temp;
1786 struct prentry tentry;
1787
1788 *over = 0;
1789 alist->prlist_len = 0;
1790 alist->prlist_val = NULL((void *)0);
1791
1792 code = Initdb();
1793 if (code != PRSUCCESS0)
1794 return code;
1795 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1796 if (code)
1797 return code;
1798 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1799 if (code)
1800 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1801 code = read_DbHeader(tt);
1802 if (code)
1803 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1804
1805 code = WhoIsThis(call, tt, cid);
1806 if (code)
1807 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1808
1809 temp = FindByID(tt, aid);
1810 if (!temp)
1811 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1812 code = pr_ReadEntry(tt, 0, temp, &tentry);
1813 if (code)
1814 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1815 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM(0x08 << 16), PRP_MEMBER_ANY(0x10 << 16)))
1816 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1817
1818 code = GetList(tt, &tentry, alist, 0);
1819 if (code != PRSUCCESS0)
1820 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1821
1822 code = ubik_EndTrans(tt);
1823 return code;
1824}
1825
1826
1827afs_int32
1828SPR_ListSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1829 afs_int32 *over)
1830{
1831#if defined(SUPERGROUPS1)
1832 afs_int32 code;
1833 afs_int32 cid = ANONYMOUSID32766;
1834
1835 code = listSuperGroups(call, aid, alist, over, &cid);
1836 osi_auditU(call, PTS_LstSGrps"AFS_PTS_LstSGrps", code, AUD_ID10, aid, AUD_END0);
1837 ViceLog(125, ("PTS_ListSuperGroups: code %d cid %d aid %d\n", code, cid, aid))do { if ((125) <= LogLevel) (FSLog ("PTS_ListSuperGroups: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
1838 return code;
1839#else
1840 return RXGEN_OPCODE-455;
1841#endif
1842}
1843
1844#if defined(SUPERGROUPS1)
1845static afs_int32
1846listSuperGroups(struct rx_call *call, afs_int32 aid, prlist *alist,
1847 afs_int32 *over, afs_int32 *cid)
1848{
1849 afs_int32 code;
1850 struct ubik_trans *tt;
1851 afs_int32 temp;
1852 struct prentry tentry;
1853
1854 alist->prlist_len = 0;
1855 alist->prlist_val = (afs_int32 *) 0;
1856
1857 code = Initdb();
1858 if (code != PRSUCCESS0)
1859 goto done;
1860 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1861 if (code)
1862 goto done;
1863 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1864 if (code)
1865 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1866 code = WhoIsThis(call, tt, cid);
1867 if (code)
1868 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1869
1870 temp = FindByID(tt, aid);
1871 if (!temp)
1872 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1873 code = pr_ReadEntry(tt, 0, temp, &tentry);
1874 if (code)
1875 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1876 if (!AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM(0x08 << 16), PRP_MEMBER_ANY(0x10 << 16)))
1877 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1878
1879 code = GetSGList(tt, &tentry, alist);
1880 *over = 0;
1881 if (code == PRTOOMANY(267279L))
1882 *over = 1;
1883 else if (code != PRSUCCESS0)
1884 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1885
1886 code = ubik_EndTrans(tt);
1887
1888 done:
1889 return code;
1890}
1891
1892#endif /* SUPERGROUPS */
1893
1894/*
1895 * SPR_ListOwned
1896 * List the entries owned by this id. If the id is zero,
1897 * return the orphans list. This will return up to PR_MAXGROUPS
1898 * at a time with the lastP available to get the rest. The
1899 * maximum value is enforced in GetOwnedChain().
1900 */
1901afs_int32
1902SPR_ListOwned(struct rx_call *call, afs_int32 aid, prlist *alist,
1903 afs_int32 *lastP)
1904{
1905 afs_int32 code;
1906 afs_int32 cid = ANONYMOUSID32766;
1907
1908 code = listOwned(call, aid, alist, lastP, &cid);
1909 osi_auditU(call, PTS_LstOwnEvent"AFS_PTS_LstOwn", code, AUD_ID10, aid, AUD_END0);
1910 ViceLog(125, ("PTS_ListOwned: code %d cid %d aid %d\n", code, cid, aid))do { if ((125) <= LogLevel) (FSLog ("PTS_ListOwned: code %d cid %d aid %d\n"
, code, cid, aid)); } while (0)
;
1911 return code;
1912}
1913
1914afs_int32
1915listOwned(struct rx_call *call, afs_int32 aid, prlist *alist, afs_int32 *lastP,
1916 afs_int32 *cid)
1917{
1918 afs_int32 code;
1919 struct ubik_trans *tt;
1920 struct prentry tentry;
1921 afs_int32 head = 0;
1922 afs_int32 start;
1923
1924 alist->prlist_len = 0;
1925 alist->prlist_val = NULL((void *)0);
1926
1927 if (!lastP)
1928 return PRBADARG(267273L);
1929 start = *lastP;
1930 *lastP = 0;
1931
1932 code = Initdb();
1933 if (code != PRSUCCESS0)
1934 return code;
1935 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
1936 if (code)
1937 return code;
1938 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
1939 if (code)
1940 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1941 code = read_DbHeader(tt);
1942 if (code)
1943 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1944
1945 code = WhoIsThis(call, tt, cid);
1946 if (code)
1947 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1948
1949 if (start) {
1950 code = pr_ReadEntry(tt, 0, start, &tentry);
1951 if (!code && (tentry.owner == aid))
1952 head = start; /* pick up where we left off */
1953 }
1954
1955 if (!head) {
1956 if (aid) {
1957 afs_int32 loc = FindByID(tt, aid);
1958 if (loc == 0)
1959 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
1960 code = pr_ReadEntry(tt, 0, loc, &tentry);
1961 if (code)
1962 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1963
1964 if (!AccessOK(tt, *cid, &tentry, -1, PRP_OWNED_ANY(0x20 << 16)))
1965 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1966 head = tentry.owned;
1967 } else {
1968 if (!AccessOK(tt, *cid, 0, 0, 0))
1969 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
1970 head = ntohl(cheader.orphan)(__builtin_constant_p(cheader.orphan) ? ((((__uint32_t)(cheader
.orphan)) >> 24) | ((((__uint32_t)(cheader.orphan)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(cheader.orphan
)) & (0xff << 8)) << 8) | (((__uint32_t)(cheader
.orphan)) << 24)) : __bswap32_var(cheader.orphan))
;
1971 }
1972 }
1973
1974 code = GetOwnedChain(tt, &head, alist);
1975 if (code) {
1976 if (code == PRTOOMANY(267279L))
1977 *lastP = head;
1978 else
1979 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
1980 }
1981
1982 code = ubik_EndTrans(tt);
1983 return code;
1984}
1985
1986afs_int32
1987SPR_IsAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid,
1988 afs_int32 *flag)
1989{
1990 afs_int32 code;
1991 afs_int32 cid = ANONYMOUSID32766;
1992
1993 code = isAMemberOf(call, uid, gid, flag, &cid);
1994 osi_auditU(call, PTS_IsMemOfEvent"AFS_PTS_IsMemOf", code, AUD_LONG5, uid, AUD_LONG5, gid,
1995 AUD_END0);
1996 ViceLog(125, ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n", code, cid, uid, gid))do { if ((125) <= LogLevel) (FSLog ("PTS_IsAMemberOf: code %d cid %d uid %d gid %d\n"
, code, cid, uid, gid)); } while (0)
;
1997 return code;
1998}
1999
2000static afs_int32
2001isAMemberOf(struct rx_call *call, afs_int32 uid, afs_int32 gid, afs_int32 *flag,
2002 afs_int32 *cid)
2003{
2004 afs_int32 code;
2005 struct ubik_trans *tt;
2006
2007 code = Initdb();
2008 if (code != PRSUCCESS0)
2009 return code;
2010 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS0, &tt);
2011 if (code)
2012 return code;
2013 code = ubik_SetLock(tt, 1, 1, LOCKREAD1);
2014 if (code)
2015 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
2016 code = read_DbHeader(tt);
2017 if (code)
2018 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
2019
2020 {
2021 afs_int32 uloc = FindByID(tt, uid);
2022 afs_int32 gloc = FindByID(tt, gid);
2023 struct prentry uentry, gentry;
2024
2025 if (!uloc || !gloc)
2026 ABORT_WITH(tt, PRNOENT)return(ubik_AbortTrans(tt),(267268L));
2027 code = WhoIsThis(call, tt, cid);
2028 if (code)
2029 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
2030 code = pr_ReadEntry(tt, 0, uloc, &uentry);
2031 if (code)
2032 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
2033 code = pr_ReadEntry(tt, 0, gloc, &gentry);
2034 if (code)
2035 ABORT_WITH(tt, code)return(ubik_AbortTrans(tt),code);
2036#if !defined(SUPERGROUPS1)
2037 if ((uentry.flags & PRGRP2) || !(gentry.flags & PRGRP2))
2038 ABORT_WITH(tt, PRBADARG)return(ubik_AbortTrans(tt),(267273L));
2039#else
2040 if (!(gentry.flags & PRGRP2))
2041 ABORT_WITH(tt, PRBADARG)return(ubik_AbortTrans(tt),(267273L));
2042#endif
2043 if (!AccessOK(tt, *cid, &uentry, 0, PRP_MEMBER_ANY(0x10 << 16))
2044 && !AccessOK(tt, *cid, &gentry, PRP_MEMBER_MEM(0x08 << 16), PRP_MEMBER_ANY(0x10 << 16)))
2045 ABORT_WITH(tt, PRPERM)return(ubik_AbortTrans(tt),(267269L));
2046 }
2047
2048 *flag = IsAMemberOf(tt, uid, gid);
2049 code = ubik_EndTrans(tt);
2050 return code;
2051}
2052
2053static afs_int32
2054addWildCards(struct ubik_trans *tt, prlist *alist, afs_uint32 host)
2055{
2056 afs_int32 temp;
2057 struct prentry tentry;
2058 prlist wlist;
2059 unsigned wild = htonl(0xffffff00)(__builtin_constant_p(0xffffff00) ? ((((__uint32_t)(0xffffff00
)) >> 24) | ((((__uint32_t)(0xffffff00)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(0xffffff00)) & (0xff <<
8)) << 8) | (((__uint32_t)(0xffffff00)) << 24)) :
__bswap32_var(0xffffff00))
;
2060 struct in_addr iaddr;
2061 afs_int32 hostid;
2062 int size = 0, i, code;
2063 int added = 0;
2064
2065 while ((host = (host & wild))) {
2066 wild = htonl(ntohl(wild) << 8)(__builtin_constant_p((__builtin_constant_p(wild) ? ((((__uint32_t
)(wild)) >> 24) | ((((__uint32_t)(wild)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(wild)) & (0xff <<
8)) << 8) | (((__uint32_t)(wild)) << 24)) : __bswap32_var
(wild)) << 8) ? ((((__uint32_t)((__builtin_constant_p(wild
) ? ((((__uint32_t)(wild)) >> 24) | ((((__uint32_t)(wild
)) & (0xff << 16)) >> 8) | ((((__uint32_t)(wild
)) & (0xff << 8)) << 8) | (((__uint32_t)(wild
)) << 24)) : __bswap32_var(wild)) << 8)) >>
24) | ((((__uint32_t)((__builtin_constant_p(wild) ? ((((__uint32_t
)(wild)) >> 24) | ((((__uint32_t)(wild)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(wild)) & (0xff <<
8)) << 8) | (((__uint32_t)(wild)) << 24)) : __bswap32_var
(wild)) << 8)) & (0xff << 16)) >> 8) | (
(((__uint32_t)((__builtin_constant_p(wild) ? ((((__uint32_t)(
wild)) >> 24) | ((((__uint32_t)(wild)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(wild)) & (0xff <<
8)) << 8) | (((__uint32_t)(wild)) << 24)) : __bswap32_var
(wild)) << 8)) & (0xff << 8)) << 8) | (
((__uint32_t)((__builtin_constant_p(wild) ? ((((__uint32_t)(wild
)) >> 24) | ((((__uint32_t)(wild)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(wild)) & (0xff <<
8)) << 8) | (((__uint32_t)(wild)) << 24)) : __bswap32_var
(wild)) << 8)) << 24)) : __bswap32_var((__builtin_constant_p
(wild) ? ((((__uint32_t)(wild)) >> 24) | ((((__uint32_t
)(wild)) & (0xff << 16)) >> 8) | ((((__uint32_t
)(wild)) & (0xff << 8)) << 8) | (((__uint32_t
)(wild)) << 24)) : __bswap32_var(wild)) << 8))
;
2067 iaddr.s_addr = host;
2068 code = NameToID(tt, inet_ntoa__inet_ntoa(iaddr), &hostid);
2069 if (code == PRSUCCESS0 && hostid != 0) {
2070 temp = FindByID(tt, hostid);
2071 if (temp) {
2072 code = pr_ReadEntry(tt, 0, temp, &tentry);
2073 if (code != PRSUCCESS0)
2074 continue;
2075 } else
2076 continue;
2077 } else
2078 continue;
2079 wlist.prlist_len = 0;
2080 wlist.prlist_val = NULL((void *)0);
2081
2082 code = GetList(tt, &tentry, &wlist, 0);
2083 if (code)
2084 return code;
2085 added += wlist.prlist_len;
2086 for (i = 0; i < wlist.prlist_len; i++) {
2087 if (!inCPS(*alist, wlist.prlist_val[i]))
2088 if ((code = AddToPRList(alist, &size, wlist.prlist_val[i]))) {
2089 free(wlist.prlist_val);
2090 return (code);
2091 }
2092 }
2093 if (wlist.prlist_val)
2094 free(wlist.prlist_val);
2095 }
2096 if (added)
2097 qsort(alist->prlist_val, alist->prlist_len, sizeof(afs_int32), IDCmp);
2098 return 0;
2099}
2100
2101static afs_int32
2102WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
2103 char *aname)
2104{
2105 int foreign = 0;
2106 /* aid is set to the identity of the caller, if known, else ANONYMOUSID */
2107 /* returns -1 and sets aid to ANONYMOUSID on any failure */
2108 struct rx_connection *tconn;
2109 afs_int32 code;
2110 char tcell[MAXKTCREALMLEN64];
2111 char name[MAXKTCNAMELEN64];
2112 char inst[MAXKTCNAMELEN64];
2113 int ilen;
2114 char vname[256];
2115
2116 *aid = ANONYMOUSID32766;
2117 tconn = rx_ConnectionOf(acall)((acall)->conn);
2118 code = rx_SecurityClassOf(tconn)((tconn)->securityIndex);
2119 if (code == 0)
2120 return 0;
2121 else if (code == 1) { /* vab class */
2122 goto done; /* no longer supported */
2123 } else if (code == 2) { /* kad class */
2124 if ((code = rxkad_GetServerInfo(acall->conn, NULL((void *)0), NULL((void *)0),
2125 name, inst, tcell, NULL((void *)0))))
2126 goto done;
2127
2128 if (tcell[0])
2129 foreign = afs_is_foreign_ticket_name(name, inst, tcell,
2130 pr_realmName);
2131
2132 strncpy(vname, name, sizeof(vname));
2133 if ((ilen = strlen(inst))) {
2134 if (strlen(vname) + 1 + ilen >= sizeof(vname))
2135 goto done;
2136 strcat(vname, ".");
2137 strcat(vname, inst);
2138 }
2139 if (foreign) {
2140 if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
2141 goto done;
2142 strcat(vname, "@");
2143 strcat(vname, tcell);
2144 lcstring(vname, vname, sizeof(vname));
2145 code = NameToID(at, vname, aid);
Value stored to 'code' is never read
2146 if (aname)
2147 strcpy(aname, vname);
2148 return 2;
2149 }
2150
2151 if (strcmp(AUTH_SUPERUSER"afs", vname) == 0)
2152 *aid = SYSADMINID-204; /* special case for the fileserver */
2153 else {
2154 lcstring(vname, vname, sizeof(vname));
2155 code = NameToID(at, vname, aid);
2156 }
2157 }
2158 done:
2159 if (code && !pr_noAuth)
2160 return -1;
2161 return 0;
2162}