Bug Summary

File:ptserver/pt_util.c
Location:line 272, column 7
Description:The left operand of '==' is a garbage value

Annotated Source Code

1/* $Id$ */
2
3/*
4 *
5 * pt_util: Program to dump the AFS protection server database
6 * into an ascii file.
7 *
8 * Assumptions: We *cheat* here and read the datafile directly, ie.
9 * not going through the ubik distributed data manager.
10 * therefore the database must be quiescent for the
11 * output of this program to be valid.
12 */
13
14#include <afsconfig.h>
15#include <afs/param.h>
16
17#include <roken.h>
18
19#ifndef _WIN32
20#include <sys/file.h>
21#else
22#define L_SET0 SEEK_SET0
23#endif
24#include <ctype.h>
25
26#include <afs/com_err.h>
27#include <afs/cmd.h> /*Command line parsing */
28#include <afs/afsutil.h>
29#include <lock.h>
30#define UBIK_INTERNALS
31#include <ubik.h>
32#include <rx/xdr.h>
33#include <rx/rx.h>
34
35#include "ptint.h"
36#include "ptserver.h"
37#include "pterror.h"
38#include "ptprototypes.h"
39
40#define IDHash(x)(abs(x) % 8191) (abs(x) % HASHSIZE8191)
41#define print_id(x)( ((flags&8)==0 && (x<-32767 || x>97536)) ||
((flags&16)==0 && (x>-32768 && x<97537
)))
( ((flags&DO_SYS8)==0 && (x<-32767 || x>97536)) || \
42 ((flags&DO_OTR16)==0 && (x>-32768 && x<97537)))
43
44extern char *optarg;
45extern int optind;
46
47int restricted = 0;
48
49static int display_entry(int);
50static void add_group(long);
51static void display_groups(void);
52static void display_group(int);
53static void fix_pre(struct prentry *);
54static char *id_to_name(int);
55static char *checkin(struct prentry *);
56static char *check_core(int);
57static int CommandProc(struct cmd_syndesc *, void *);
58
59struct hash_entry {
60 char h_name[PR_MAXNAMELEN64];
61 int h_id;
62 struct hash_entry *next;
63};
64struct hash_entry *hat[HASHSIZE8191];
65
66static struct contentry prco;
67static struct prentry pre;
68static struct prheader prh;
69static struct ubik_version uv;
70
71struct grp_list {
72 struct grp_list *next;
73 long groups[1024];
74};
75static struct grp_list *grp_head = 0;
76static long grp_count = 0;
77
78struct usr_list {
79 struct usr_list *next;
80 char name[PR_MAXNAMELEN64];
81 long uid;
82};
83static struct usr_list *usr_head = 0;
84
85char buffer[1024];
86int dbase_fd;
87FILE *dfp;
88
89#define FMT_BASE"%-10s %d/%d %d %d %d\n" "%-10s %d/%d %d %d %d\n"
90#define FMT_MEM" %-8s %d\n" " %-8s %d\n"
91
92#define DO_USR1 1
93#define DO_GRP2 2
94#define DO_MEM4 4
95#define DO_SYS8 8
96#define DO_OTR16 16
97
98int nflag = 0;
99int wflag = 0;
100int flags = 0;
101
102int
103main(int argc, char **argv)
104{
105
106 struct cmd_syndesc *cs; /*Command line syntax descriptor */
107 afs_int32 code; /*Return code */
108
109 cs = cmd_CreateSyntax(NULL((void *)0), CommandProc, NULL((void *)0),
110 "access protection database");
111 cmd_AddParm(cs, "-w", CMD_FLAG1, CMD_OPTIONAL1,
112 "update prdb with contents of data file");
113 cmd_AddParm(cs, "-user", CMD_FLAG1, CMD_OPTIONAL1, "display users");
114 cmd_AddParm(cs, "-group", CMD_FLAG1, CMD_OPTIONAL1, "display groups");
115 cmd_AddParm(cs, "-members", CMD_FLAG1, CMD_OPTIONAL1,
116 "display group members");
117 cmd_AddParm(cs, "-name", CMD_FLAG1, CMD_OPTIONAL1,
118 "follow name hash chains (not id hashes)");
119 cmd_AddParm(cs, "-system", CMD_FLAG1, CMD_OPTIONAL1,
120 "display only system data");
121 cmd_AddParm(cs, "-xtra", CMD_FLAG1, CMD_OPTIONAL1,
122 "display extra users/groups");
123 cmd_AddParm(cs, "-prdb", CMD_SINGLE2, CMD_OPTIONAL1, "prdb file");
124 cmd_AddParm(cs, "-datafile", CMD_SINGLE2, CMD_OPTIONAL1, "data file");
125 code = cmd_Dispatch(argc, argv);
126
127 exit(code);
128
129}
130
131static int
132CommandProc(struct cmd_syndesc *a_as, void *arock)
133{
134 int i;
135 long code = 0;
136 long upos;
137 long gpos = 0;
138 struct prentry uentry, gentry;
139 struct ubik_hdr *uh;
140 char *dfile = 0;
141 const char *pbase = AFSDIR_SERVER_PRDB_FILEPATHgetDirPath(AFSDIR_SERVER_PRDB_FILEPATH_ID);
142 char *pfile = NULL((void *)0);
143 char pbuffer[1028];
144 struct cmd_parmdesc *tparm;
145
146 tparm = a_as->parms;
147
148 if (tparm[0].items) {
1
Taking false branch
149 wflag++;
150 }
151 if (tparm[1].items) {
2
Taking false branch
152 flags |= DO_USR1;
153 }
154 if (tparm[2].items) {
3
Taking false branch
155 flags |= DO_GRP2;
156 }
157 if (tparm[3].items) {
4
Taking false branch
158 flags |= (DO_GRP2 | DO_MEM4);
159 }
160 if (tparm[4].items) {
5
Taking false branch
161 nflag++;
162 }
163 if (tparm[5].items) {
6
Taking false branch
164 flags |= DO_SYS8;
165 }
166 if (tparm[6].items) {
7
Taking false branch
167 flags |= DO_OTR16;
168 }
169 if (tparm[7].items) {
8
Taking false branch
170 pfile = tparm[7].items->data;
171 }
172 if (tparm[8].items) {
9
Taking false branch
173 dfile = tparm[8].items->data;
174 }
175
176 if (pfile == NULL((void *)0)) {
10
Taking true branch
177 snprintf(pbuffer, sizeof(pbuffer), "%s.DB0", pbase);
178 pfile = pbuffer;
179 }
180 if ((dbase_fd = open(pfile, (wflag ? O_RDWR0x0002 : O_RDONLY0x0000) | O_CREAT0x0200, 0600))
11
'?' condition is false
12
Taking false branch
181 < 0) {
182 fprintf(stderr__stderrp, "pt_util: cannot open %s: %s\n", pfile,
183 strerror(errno(* __error())));
184 exit(1);
185 }
186 if (read(dbase_fd, buffer, HDRSIZE64) < 0) {
13
Taking false branch
187 fprintf(stderr__stderrp, "pt_util: error reading %s: %s\n", pfile,
188 strerror(errno(* __error())));
189 exit(1);
190 }
191
192 if (dfile) {
14
Taking false branch
193 if ((dfp = fopen(dfile, wflag ? "r" : "w")) == 0) {
194 fprintf(stderr__stderrp, "pt_util: error opening %s: %s\n", dfile,
195 strerror(errno(* __error())));
196 exit(1);
197 }
198 } else
199 dfp = (wflag ? stdin__stdinp : stdout__stdoutp);
15
'?' condition is false
200
201 uh = (struct ubik_hdr *)buffer;
202 if (ntohl(uh->magic)(__builtin_constant_p(uh->magic) ? ((((__uint32_t)(uh->
magic)) >> 24) | ((((__uint32_t)(uh->magic)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(uh->magic
)) & (0xff << 8)) << 8) | (((__uint32_t)(uh->
magic)) << 24)) : __bswap32_var(uh->magic))
!= UBIK_MAGIC0x354545)
16
Taking false branch
203 fprintf(stderr__stderrp, "pt_util: %s: Bad UBIK_MAGIC. Is %x should be %x\n",
204 pfile, ntohl(uh->magic)(__builtin_constant_p(uh->magic) ? ((((__uint32_t)(uh->
magic)) >> 24) | ((((__uint32_t)(uh->magic)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(uh->magic
)) & (0xff << 8)) << 8) | (((__uint32_t)(uh->
magic)) << 24)) : __bswap32_var(uh->magic))
, UBIK_MAGIC0x354545);
205 memcpy(&uv, &uh->version, sizeof(struct ubik_version));
206
207 if (wflag && ntohl(uv.epoch)(__builtin_constant_p(uv.epoch) ? ((((__uint32_t)(uv.epoch)) >>
24) | ((((__uint32_t)(uv.epoch)) & (0xff << 16)) >>
8) | ((((__uint32_t)(uv.epoch)) & (0xff << 8)) <<
8) | (((__uint32_t)(uv.epoch)) << 24)) : __bswap32_var
(uv.epoch))
== 0 && ntohl(uv.counter)(__builtin_constant_p(uv.counter) ? ((((__uint32_t)(uv.counter
)) >> 24) | ((((__uint32_t)(uv.counter)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(uv.counter)) & (0xff <<
8)) << 8) | (((__uint32_t)(uv.counter)) << 24)) :
__bswap32_var(uv.counter))
== 0) {
17
Taking false branch
208 uv.epoch = htonl(2)(__builtin_constant_p(2) ? ((((__uint32_t)(2)) >> 24) |
((((__uint32_t)(2)) & (0xff << 16)) >> 8) | (
(((__uint32_t)(2)) & (0xff << 8)) << 8) | (((
__uint32_t)(2)) << 24)) : __bswap32_var(2))
; /* a ubik version of 0 or 1 has special meaning */
209 memcpy(&uh->version, &uv, sizeof(struct ubik_version));
210 lseek(dbase_fd, 0, SEEK_SET0);
211 if (write(dbase_fd, buffer, HDRSIZE64) < 0) {
212 fprintf(stderr__stderrp, "pt_util: error writing ubik version to %s: %s\n",
213 pfile, strerror(errno(* __error())));
214 exit(1);
215 }
216 }
217
218 /* Now that any writeback is done, swap these */
219 uv.epoch = ntohl(uv.epoch)(__builtin_constant_p(uv.epoch) ? ((((__uint32_t)(uv.epoch)) >>
24) | ((((__uint32_t)(uv.epoch)) & (0xff << 16)) >>
8) | ((((__uint32_t)(uv.epoch)) & (0xff << 8)) <<
8) | (((__uint32_t)(uv.epoch)) << 24)) : __bswap32_var
(uv.epoch))
;
220 uv.counter = ntohl(uv.counter)(__builtin_constant_p(uv.counter) ? ((((__uint32_t)(uv.counter
)) >> 24) | ((((__uint32_t)(uv.counter)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(uv.counter)) & (0xff <<
8)) << 8) | (((__uint32_t)(uv.counter)) << 24)) :
__bswap32_var(uv.counter))
;
221
222 fprintf(stderr__stderrp, "Ubik Version is: %d.%d\n", uv.epoch, uv.counter);
223 if (read(dbase_fd, &prh, sizeof(struct prheader)) < 0) {
18
Taking false branch
224 fprintf(stderr__stderrp, "pt_util: error reading %s: %s\n", pfile,
225 strerror(errno(* __error())));
226 exit(1);
227 }
228
229 Initdb();
230 initialize_PT_error_table();
231
232 if (wflag) {
19
Taking true branch
233 struct usr_list *u;
234
235 while (fgets(buffer, sizeof(buffer), dfp)) {
20
Loop condition is true. Entering loop body
236 int id, oid, cid, flags, quota, uid;
21
Variable 'id' declared without an initial value
237 char name[PR_MAXNAMELEN64], mem[PR_MAXNAMELEN64];
238
239 if (isspace(*buffer)__sbistype((*buffer), 0x00004000L)) {
22
Taking true branch
240 sscanf(buffer, "%s %d", mem, &uid);
241
242 for (u = usr_head; u; u = u->next)
23
Loop condition is false. Execution continues on line 245
243 if (u->uid && u->uid == uid)
244 break;
245 if (u) {
24
Taking false branch
246 /* Add user - deferred because it is probably foreign */
247 u->uid = 0;
248 if (FindByID(0, uid))
249 code = PRIDEXIST(267265L);
250 else {
251 if (!code
252 && (flags & (PRGRP2 | PRQUOTA(1<<7))) ==
253 (PRGRP2 | PRQUOTA(1<<7))) {
254 gentry.ngroups++;
255 code = pr_WriteEntry(0, 0, gpos, &gentry);
256 if (code)
257 fprintf(stderr__stderrp,
258 "Error setting group count on %s: %s\n",
259 name, afs_error_message(code));
260 }
261 code = CreateEntry(0, u->name, &uid, 1 /*idflag */ ,
262 1 /*gflag */ ,
263 SYSADMINID-204 /*oid */ ,
264 SYSADMINID-204 /*cid */ );
265 }
266 if (code)
267 fprintf(stderr__stderrp, "Error while creating %s: %s\n",
268 u->name, afs_error_message(code));
269 continue;
270 }
271 /* Add user to group */
272 if (id == ANYUSERID-101 || id == AUTHUSERID-102 || uid == ANONYMOUSID32766) {
25
The left operand of '==' is a garbage value
273 code = PRPERM(267269L);
274 } else if ((upos = FindByID(0, uid))
275 && (gpos = FindByID(0, id))) {
276 code = pr_ReadEntry(0, 0, upos, &uentry);
277 if (!code)
278 code = pr_ReadEntry(0, 0, gpos, &gentry);
279 if (!code)
280 code = AddToEntry(0, &gentry, gpos, uid);
281 if (!code)
282 code = AddToEntry(0, &uentry, upos, id);
283 } else
284 code = PRNOENT(267268L);
285
286 if (code)
287 fprintf(stderr__stderrp, "Error while adding %s to %s: %s\n", mem,
288 name, afs_error_message(code));
289 } else {
290 sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, &quota, &id,
291 &oid, &cid);
292
293 if (FindByID(0, id))
294 code = PRIDEXIST(267265L);
295 else
296 code = CreateEntry(0, name, &id, 1 /*idflag */ ,
297 flags & PRGRP2, oid, cid);
298 if (code == PRBADNAM(267272L)) {
299 u = (struct usr_list *)malloc(sizeof(struct usr_list));
300 u->next = usr_head;
301 u->uid = id;
302 strcpy(u->name, name);
303 usr_head = u;
304 } else if (code) {
305 fprintf(stderr__stderrp, "Error while creating %s: %s\n", name,
306 afs_error_message(code));
307 } else if ((flags & PRACCESS(1<<6))
308 || (flags & (PRGRP2 | PRQUOTA(1<<7))) ==
309 (PRGRP2 | PRQUOTA(1<<7))) {
310 gpos = FindByID(0, id);
311 code = pr_ReadEntry(0, 0, gpos, &gentry);
312 if (!code) {
313 gentry.flags = flags;
314 gentry.ngroups = quota;
315 code = pr_WriteEntry(0, 0, gpos, &gentry);
316 }
317 if (code)
318 fprintf(stderr__stderrp,
319 "Error while setting flags on %s: %s\n", name,
320 afs_error_message(code));
321 }
322 }
323 }
324 for (u = usr_head; u; u = u->next)
325 if (u->uid)
326 fprintf(stderr__stderrp, "Error while creating %s: %s\n", u->name,
327 afs_error_message(PRBADNAM(267272L)));
328 } else {
329 for (i = 0; i < HASHSIZE8191; i++) {
330 upos = nflag ? ntohl(prh.nameHash[i])(__builtin_constant_p(prh.nameHash[i]) ? ((((__uint32_t)(prh.
nameHash[i])) >> 24) | ((((__uint32_t)(prh.nameHash[i])
) & (0xff << 16)) >> 8) | ((((__uint32_t)(prh
.nameHash[i])) & (0xff << 8)) << 8) | (((__uint32_t
)(prh.nameHash[i])) << 24)) : __bswap32_var(prh.nameHash
[i]))
: ntohl(prh.idHash[i])(__builtin_constant_p(prh.idHash[i]) ? ((((__uint32_t)(prh.idHash
[i])) >> 24) | ((((__uint32_t)(prh.idHash[i])) & (0xff
<< 16)) >> 8) | ((((__uint32_t)(prh.idHash[i])) &
(0xff << 8)) << 8) | (((__uint32_t)(prh.idHash[i
])) << 24)) : __bswap32_var(prh.idHash[i]))
;
331 while (upos) {
332 long newpos;
333 newpos = display_entry(upos);
334 if (newpos == upos) {
335 fprintf(stderr__stderrp, "pt_util: hash error in %s chain %d\n",
336 nflag ? "name":"id", i);
337 exit(1);
338 } else
339 upos = newpos;
340 }
341 }
342 if (flags & DO_GRP2)
343 display_groups();
344 }
345
346 lseek(dbase_fd, 0, L_SET0); /* rewind to beginning of file */
347 if (read(dbase_fd, buffer, HDRSIZE64) < 0) {
348 fprintf(stderr__stderrp, "pt_util: error reading %s: %s\n", pfile,
349 strerror(errno(* __error())));
350 exit(1);
351 }
352 uh = (struct ubik_hdr *)buffer;
353
354 uh->version.epoch = ntohl(uh->version.epoch)(__builtin_constant_p(uh->version.epoch) ? ((((__uint32_t)
(uh->version.epoch)) >> 24) | ((((__uint32_t)(uh->
version.epoch)) & (0xff << 16)) >> 8) | ((((__uint32_t
)(uh->version.epoch)) & (0xff << 8)) << 8)
| (((__uint32_t)(uh->version.epoch)) << 24)) : __bswap32_var
(uh->version.epoch))
;
355 uh->version.counter = ntohl(uh->version.counter)(__builtin_constant_p(uh->version.counter) ? ((((__uint32_t
)(uh->version.counter)) >> 24) | ((((__uint32_t)(uh->
version.counter)) & (0xff << 16)) >> 8) | (((
(__uint32_t)(uh->version.counter)) & (0xff << 8)
) << 8) | (((__uint32_t)(uh->version.counter)) <<
24)) : __bswap32_var(uh->version.counter))
;
356
357 if ((uh->version.epoch != uv.epoch)
358 || (uh->version.counter != uv.counter)) {
359 fprintf(stderr__stderrp,
360 "pt_util: Ubik Version number changed during execution.\n");
361 fprintf(stderr__stderrp, "Old Version = %d.%d, new version = %d.%d\n",
362 uv.epoch, uv.counter, uh->version.epoch, uh->version.counter);
363 }
364 close(dbase_fd);
365 exit(0);
366}
367
368static int
369display_entry(int offset)
370{
371 lseek(dbase_fd, offset + HDRSIZE64, L_SET0);
372 read(dbase_fd, &pre, sizeof(struct prentry));
373
374 fix_pre(&pre);
375
376 if ((pre.flags & PRFREE1) == 0) {
377 if (pre.flags & PRGRP2) {
378 if (flags & DO_GRP2)
379 add_group(pre.id);
380 } else {
381 if (print_id(pre.id)( ((flags&8)==0 && (pre.id<-32767 || pre.id>
97536)) || ((flags&16)==0 && (pre.id>-32768 &&
pre.id<97537)))
&& (flags & DO_USR1))
382 fprintf(dfp, FMT_BASE"%-10s %d/%d %d %d %d\n", pre.name, pre.flags, pre.ngroups,
383 pre.id, pre.owner, pre.creator);
384 checkin(&pre);
385 }
386 }
387 return (nflag ? pre.nextName : pre.nextID);
388}
389
390static void
391add_group(long id)
392{
393 struct grp_list *g;
394 long i;
395
396 i = grp_count++ % 1024;
397 if (i == 0) {
398 g = (struct grp_list *)malloc(sizeof(struct grp_list));
399 g->next = grp_head;
400 grp_head = g;
401 }
402 g = grp_head;
403 g->groups[i] = id;
404}
405
406static void
407display_groups(void)
408{
409 int i, id;
410 struct grp_list *g;
411
412 g = grp_head;
413 while (grp_count--) {
414 i = grp_count % 1024;
415 id = g->groups[i];
416 display_group(id);
417 if (i == 0) {
418 grp_head = g->next;
419 free(g);
420 g = grp_head;
421 }
422 }
423}
424
425static void
426display_group(int id)
427{
428 int i, offset;
429 int print_grp = 0;
430
431 offset = ntohl(prh.idHash[IDHash(id)])(__builtin_constant_p(prh.idHash[(abs(id) % 8191)]) ? ((((__uint32_t
)(prh.idHash[(abs(id) % 8191)])) >> 24) | ((((__uint32_t
)(prh.idHash[(abs(id) % 8191)])) & (0xff << 16)) >>
8) | ((((__uint32_t)(prh.idHash[(abs(id) % 8191)])) & (0xff
<< 8)) << 8) | (((__uint32_t)(prh.idHash[(abs(id
) % 8191)])) << 24)) : __bswap32_var(prh.idHash[(abs(id
) % 8191)]))
;
432 while (offset) {
433 lseek(dbase_fd, offset + HDRSIZE64, L_SET0);
434 if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) {
435 fprintf(stderr__stderrp, "pt_util: read i/o error: %s\n", strerror(errno(* __error())));
436 exit(1);
437 }
438 fix_pre(&pre);
439 if (pre.id == id)
440 break;
441 offset = pre.nextID;
442 }
443
444 if (print_id(id)( ((flags&8)==0 && (id<-32767 || id>97536))
|| ((flags&16)==0 && (id>-32768 && id
<97537)))
) {
445 fprintf(dfp, FMT_BASE"%-10s %d/%d %d %d %d\n", pre.name, pre.flags, pre.ngroups, pre.id,
446 pre.owner, pre.creator);
447 print_grp = 1;
448 }
449
450 if ((flags & DO_MEM4) == 0)
451 return;
452
453 for (i = 0; i < PRSIZE10; i++) {
454 if ((id = pre.entries[i]) == 0)
455 break;
456 if (id == PRBADID0x80000000)
457 continue;
458 if (print_id(id)( ((flags&8)==0 && (id<-32767 || id>97536))
|| ((flags&16)==0 && (id>-32768 && id
<97537)))
|| print_grp == 1) {
459 if (print_grp == 0) {
460 fprintf(dfp, FMT_BASE"%-10s %d/%d %d %d %d\n", pre.name, pre.flags, pre.ngroups,
461 pre.id, pre.owner, pre.creator);
462 print_grp = 2;
463 }
464 fprintf(dfp, FMT_MEM" %-8s %d\n", id_to_name(id), id);
465 }
466 }
467 if (i == PRSIZE10) {
468 offset = pre.next;
469 while (offset) {
470 lseek(dbase_fd, offset + HDRSIZE64, L_SET0);
471 read(dbase_fd, &prco, sizeof(struct contentry));
472 prco.next = ntohl(prco.next)(__builtin_constant_p(prco.next) ? ((((__uint32_t)(prco.next)
) >> 24) | ((((__uint32_t)(prco.next)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(prco.next)) & (0xff <<
8)) << 8) | (((__uint32_t)(prco.next)) << 24)) :
__bswap32_var(prco.next))
;
473 for (i = 0; i < COSIZE39; i++) {
474 prco.entries[i] = ntohl(prco.entries[i])(__builtin_constant_p(prco.entries[i]) ? ((((__uint32_t)(prco
.entries[i])) >> 24) | ((((__uint32_t)(prco.entries[i])
) & (0xff << 16)) >> 8) | ((((__uint32_t)(prco
.entries[i])) & (0xff << 8)) << 8) | (((__uint32_t
)(prco.entries[i])) << 24)) : __bswap32_var(prco.entries
[i]))
;
475 if ((id = prco.entries[i]) == 0)
476 break;
477 if (id == PRBADID0x80000000)
478 continue;
479 if (print_id(id)( ((flags&8)==0 && (id<-32767 || id>97536))
|| ((flags&16)==0 && (id>-32768 && id
<97537)))
|| print_grp == 1) {
480 if (print_grp == 0) {
481 fprintf(dfp, FMT_BASE"%-10s %d/%d %d %d %d\n", pre.name, pre.flags,
482 pre.ngroups, pre.id, pre.owner, pre.creator);
483 print_grp = 2;
484 }
485 fprintf(dfp, FMT_MEM" %-8s %d\n", id_to_name(id), id);
486 }
487 }
488 if ((i == COSIZE39) && prco.next)
489 offset = prco.next;
490 else
491 offset = 0;
492 }
493 }
494}
495
496static void
497fix_pre(struct prentry *pre)
498{
499 int i;
500
501 pre->flags = ntohl(pre->flags)(__builtin_constant_p(pre->flags) ? ((((__uint32_t)(pre->
flags)) >> 24) | ((((__uint32_t)(pre->flags)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(pre->flags
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
flags)) << 24)) : __bswap32_var(pre->flags))
;
502 pre->id = ntohl(pre->id)(__builtin_constant_p(pre->id) ? ((((__uint32_t)(pre->id
)) >> 24) | ((((__uint32_t)(pre->id)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(pre->id)) & (0xff <<
8)) << 8) | (((__uint32_t)(pre->id)) << 24)) :
__bswap32_var(pre->id))
;
503 pre->cellid = ntohl(pre->cellid)(__builtin_constant_p(pre->cellid) ? ((((__uint32_t)(pre->
cellid)) >> 24) | ((((__uint32_t)(pre->cellid)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->cellid
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
cellid)) << 24)) : __bswap32_var(pre->cellid))
;
504 pre->next = ntohl(pre->next)(__builtin_constant_p(pre->next) ? ((((__uint32_t)(pre->
next)) >> 24) | ((((__uint32_t)(pre->next)) & (0xff
<< 16)) >> 8) | ((((__uint32_t)(pre->next)) &
(0xff << 8)) << 8) | (((__uint32_t)(pre->next
)) << 24)) : __bswap32_var(pre->next))
;
505 pre->nextID = ntohl(pre->nextID)(__builtin_constant_p(pre->nextID) ? ((((__uint32_t)(pre->
nextID)) >> 24) | ((((__uint32_t)(pre->nextID)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->nextID
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
nextID)) << 24)) : __bswap32_var(pre->nextID))
;
506 pre->nextName = ntohl(pre->nextName)(__builtin_constant_p(pre->nextName) ? ((((__uint32_t)(pre
->nextName)) >> 24) | ((((__uint32_t)(pre->nextName
)) & (0xff << 16)) >> 8) | ((((__uint32_t)(pre
->nextName)) & (0xff << 8)) << 8) | (((__uint32_t
)(pre->nextName)) << 24)) : __bswap32_var(pre->nextName
))
;
507 pre->owner = ntohl(pre->owner)(__builtin_constant_p(pre->owner) ? ((((__uint32_t)(pre->
owner)) >> 24) | ((((__uint32_t)(pre->owner)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(pre->owner
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
owner)) << 24)) : __bswap32_var(pre->owner))
;
508 pre->creator = ntohl(pre->creator)(__builtin_constant_p(pre->creator) ? ((((__uint32_t)(pre->
creator)) >> 24) | ((((__uint32_t)(pre->creator)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->creator
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
creator)) << 24)) : __bswap32_var(pre->creator))
;
509 pre->ngroups = ntohl(pre->ngroups)(__builtin_constant_p(pre->ngroups) ? ((((__uint32_t)(pre->
ngroups)) >> 24) | ((((__uint32_t)(pre->ngroups)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->ngroups
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
ngroups)) << 24)) : __bswap32_var(pre->ngroups))
;
510 pre->nusers = ntohl(pre->nusers)(__builtin_constant_p(pre->nusers) ? ((((__uint32_t)(pre->
nusers)) >> 24) | ((((__uint32_t)(pre->nusers)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->nusers
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
nusers)) << 24)) : __bswap32_var(pre->nusers))
;
511 pre->count = ntohl(pre->count)(__builtin_constant_p(pre->count) ? ((((__uint32_t)(pre->
count)) >> 24) | ((((__uint32_t)(pre->count)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(pre->count
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
count)) << 24)) : __bswap32_var(pre->count))
;
512 pre->instance = ntohl(pre->instance)(__builtin_constant_p(pre->instance) ? ((((__uint32_t)(pre
->instance)) >> 24) | ((((__uint32_t)(pre->instance
)) & (0xff << 16)) >> 8) | ((((__uint32_t)(pre
->instance)) & (0xff << 8)) << 8) | (((__uint32_t
)(pre->instance)) << 24)) : __bswap32_var(pre->instance
))
;
513 pre->owned = ntohl(pre->owned)(__builtin_constant_p(pre->owned) ? ((((__uint32_t)(pre->
owned)) >> 24) | ((((__uint32_t)(pre->owned)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(pre->owned
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
owned)) << 24)) : __bswap32_var(pre->owned))
;
514 pre->nextOwned = ntohl(pre->nextOwned)(__builtin_constant_p(pre->nextOwned) ? ((((__uint32_t)(pre
->nextOwned)) >> 24) | ((((__uint32_t)(pre->nextOwned
)) & (0xff << 16)) >> 8) | ((((__uint32_t)(pre
->nextOwned)) & (0xff << 8)) << 8) | (((__uint32_t
)(pre->nextOwned)) << 24)) : __bswap32_var(pre->nextOwned
))
;
515 pre->parent = ntohl(pre->parent)(__builtin_constant_p(pre->parent) ? ((((__uint32_t)(pre->
parent)) >> 24) | ((((__uint32_t)(pre->parent)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->parent
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
parent)) << 24)) : __bswap32_var(pre->parent))
;
516 pre->sibling = ntohl(pre->sibling)(__builtin_constant_p(pre->sibling) ? ((((__uint32_t)(pre->
sibling)) >> 24) | ((((__uint32_t)(pre->sibling)) &
(0xff << 16)) >> 8) | ((((__uint32_t)(pre->sibling
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
sibling)) << 24)) : __bswap32_var(pre->sibling))
;
517 pre->child = ntohl(pre->child)(__builtin_constant_p(pre->child) ? ((((__uint32_t)(pre->
child)) >> 24) | ((((__uint32_t)(pre->child)) & (
0xff << 16)) >> 8) | ((((__uint32_t)(pre->child
)) & (0xff << 8)) << 8) | (((__uint32_t)(pre->
child)) << 24)) : __bswap32_var(pre->child))
;
518 for (i = 0; i < PRSIZE10; i++) {
519 pre->entries[i] = ntohl(pre->entries[i])(__builtin_constant_p(pre->entries[i]) ? ((((__uint32_t)(pre
->entries[i])) >> 24) | ((((__uint32_t)(pre->entries
[i])) & (0xff << 16)) >> 8) | ((((__uint32_t)
(pre->entries[i])) & (0xff << 8)) << 8) | (
((__uint32_t)(pre->entries[i])) << 24)) : __bswap32_var
(pre->entries[i]))
;
520 }
521}
522
523static char *
524id_to_name(int id)
525{
526 int offset;
527 static struct prentry pre;
528 char *name;
529
530 name = check_core(id);
531 if (name)
532 return (name);
533 offset = ntohl(prh.idHash[IDHash(id)])(__builtin_constant_p(prh.idHash[(abs(id) % 8191)]) ? ((((__uint32_t
)(prh.idHash[(abs(id) % 8191)])) >> 24) | ((((__uint32_t
)(prh.idHash[(abs(id) % 8191)])) & (0xff << 16)) >>
8) | ((((__uint32_t)(prh.idHash[(abs(id) % 8191)])) & (0xff
<< 8)) << 8) | (((__uint32_t)(prh.idHash[(abs(id
) % 8191)])) << 24)) : __bswap32_var(prh.idHash[(abs(id
) % 8191)]))
;
534 while (offset) {
535 lseek(dbase_fd, offset + HDRSIZE64, L_SET0);
536 if (read(dbase_fd, &pre, sizeof(struct prentry)) < 0) {
537 fprintf(stderr__stderrp, "pt_util: read i/o error: %s\n", strerror(errno(* __error())));
538 exit(1);
539 }
540 pre.id = ntohl(pre.id)(__builtin_constant_p(pre.id) ? ((((__uint32_t)(pre.id)) >>
24) | ((((__uint32_t)(pre.id)) & (0xff << 16)) >>
8) | ((((__uint32_t)(pre.id)) & (0xff << 8)) <<
8) | (((__uint32_t)(pre.id)) << 24)) : __bswap32_var(pre
.id))
;
541 if (pre.id == id) {
542 name = checkin(&pre);
543 return (name);
544 }
545 offset = ntohl(pre.nextID)(__builtin_constant_p(pre.nextID) ? ((((__uint32_t)(pre.nextID
)) >> 24) | ((((__uint32_t)(pre.nextID)) & (0xff <<
16)) >> 8) | ((((__uint32_t)(pre.nextID)) & (0xff <<
8)) << 8) | (((__uint32_t)(pre.nextID)) << 24)) :
__bswap32_var(pre.nextID))
;
546 }
547 return 0;
548}
549
550static char *
551checkin(struct prentry *pre)
552{
553 struct hash_entry *he, *last;
554 int id;
555
556 id = pre->id;
557 last = (struct hash_entry *)0;
558 he = hat[IDHash(id)(abs(id) % 8191)];
559 while (he) {
560 if (id == he->h_id)
561 return (he->h_name);
562 last = he;
563 he = he->next;
564 }
565 he = (struct hash_entry *)malloc(sizeof(struct hash_entry));
566 if (he == 0) {
567 fprintf(stderr__stderrp, "pt_util: No Memory for internal hash table.\n");
568 exit(1);
569 }
570 he->h_id = id;
571 he->next = (struct hash_entry *)0;
572 strncpy(he->h_name, pre->name, PR_MAXNAMELEN64);
573 if (last == (struct hash_entry *)0)
574 hat[IDHash(id)(abs(id) % 8191)] = he;
575 else
576 last->next = he;
577 return (he->h_name);
578}
579
580static char *
581check_core(int id)
582{
583 struct hash_entry *he;
584 he = hat[IDHash(id)(abs(id) % 8191)];
585 while (he) {
586 if (id == he->h_id)
587 return (he->h_name);
588 he = he->next;
589 }
590 return 0;
591}