ptserver-prototypes-20090316
[openafs.git] / src / ptserver / ptclient.c
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 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #ifdef  AFS_AIX32_ENV
17 #include <signal.h>
18 #endif
19 #include <sys/types.h>
20 #ifdef AFS_NT40_ENV
21 #include <winsock2.h>
22 #include <WINNT/afsevent.h>
23 #else
24 #include <netinet/in.h>
25 #include <netdb.h>
26 #endif
27 #include <stdio.h>
28 #include <rx/xdr.h>
29 #include <rx/rx.h>
30 #include <string.h>
31 #include <afs/stds.h>
32 #include <afs/com_err.h>
33 #include <afs/cellconfig.h>
34 #include "ptclient.h"
35 #include "pterror.h"
36 #include <afs/afsutil.h>
37
38
39 afs_int32 security = 0;
40 char confdir[AFSDIR_PATH_MAX];
41
42 char *whoami;
43
44 #ifndef AFS_PTHREAD_ENV
45 extern struct ubik_client *pruclient;
46 #endif
47
48 static int ignoreExist = 0;
49 static char line[256];
50 static char *lineProgress;
51
52 #define WHITESPACE " \t\n"
53
54 #ifndef AFS_PTHREAD_ENV
55 int
56 osi_audit()
57 {
58 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
59  * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
60  * anyway.  It's gonna give somebody fits to debug, I know, I know.
61  */
62     return 0;
63 }
64 #endif /* !AFS_PTHREAD_ENV */
65
66 int
67 GetToken(char *format, afs_int32 *l)
68 {
69     int c;
70
71     *l = 0;
72     if (lineProgress == 0)
73         lineProgress = line;
74     c = sscanf(lineProgress, format, l);
75     if (c != 1)
76         return -1;
77     /* skip the white space */
78     lineProgress += strspn(lineProgress, WHITESPACE);
79     /* skip to end of token */
80     lineProgress = strpbrk(lineProgress, WHITESPACE);
81     return 0;
82 }
83
84 #define GetInt32(l) GetToken ("%d", l)
85 #define GetXInt32(l) GetToken ("%x", l)
86
87 int
88 GetString(s, slen)
89      char *s;
90      int slen;
91 {
92     char *beg;
93     int l;
94     int code;
95
96     if (lineProgress == 0)
97         lineProgress = line;
98     /* skip the white space */
99     lineProgress += strspn(lineProgress, WHITESPACE);
100
101     /* check for quoted string and find end */
102     beg = lineProgress;
103     if (*beg == '"') {
104         l = strcspn(++beg, "\"");
105         if (l == strlen(beg))
106             return -1;          /* unbalanced quotes */
107         lineProgress = beg + l + 1;
108     } else {
109         l = strcspn(beg, WHITESPACE);
110         lineProgress += l;
111     }
112     if (l >= slen) {            /* don't return too much */
113         code = -1;
114         l = slen - 1;
115     } else
116         code = 0;
117
118     strncpy(s, beg, l);
119     s[l] = 0;                   /* null termination */
120     return code;
121 }
122
123 int
124 CodeOk(code)
125      afs_int32 code;
126 {
127     if (!ignoreExist)
128         return code;
129     return code && (code != PREXIST) && (code != PRIDEXIST);
130 }
131
132 int
133 PrintEntry(ea, e, indent)
134      afs_int32 ea;
135      struct prentry *e;
136      int indent;
137 {
138     /* handle screwed up versions of DumpEntry */
139     if (e->flags & PRCONT) {
140         afs_int32 id = *(afs_int32 *) (e->name);
141         if ((id != PRBADID) && ((id > (1 << 24)) || (id < -(1 << 24)))) {
142             /* assume server incorrectly swapped these bytes... */
143             int i = 0;
144             while (i < sizeof(e->name)) {
145                 char temp;
146                 temp = e->name[i];
147                 e->name[i] = e->name[i + 3];
148                 e->name[i + 3] = temp;
149                 temp = e->name[i + 1];
150                 e->name[i + 1] = e->name[i + 2];
151                 e->name[i + 2] = temp;
152                 i += 4;
153             }
154         }
155     }
156     return pr_PrintEntry(stdout, /*host order */ 1, ea, e, indent);
157 }
158
159 #ifndef AFS_PTHREAD_ENV
160
161 /* main program */
162
163 #include "AFS_component_version_number.c"
164
165 main(argc, argv)
166      int argc;
167      char **argv;
168 {
169     register afs_int32 code;
170     char op[8];
171     char name[PR_MAXNAMELEN];
172     afs_int32 id, oid = ANONYMOUSID, gid;
173     afs_int32 pos;
174     int i;
175     struct prentry entry;
176     prlist alist;
177     idlist lid;
178     namelist lnames;
179     struct hostent *hostinfo;
180     struct in_addr *hostaddr;
181     afs_int32 *ptr;
182     char *foo;
183     afs_int32 over;
184     char *cell;
185
186 #ifdef  AFS_AIX32_ENV
187     /*
188      * The following signal action for AIX is necessary so that in case of a 
189      * crash (i.e. core is generated) we can include the user's data section 
190      * in the core dump. Unfortunately, by default, only a partial core is
191      * generated which, in many cases, isn't too useful.
192      */
193     struct sigaction nsa;
194
195     sigemptyset(&nsa.sa_mask);
196     nsa.sa_handler = SIG_DFL;
197     nsa.sa_flags = SA_FULLDUMP;
198     sigaction(SIGSEGV, &nsa, NULL);
199 #endif
200     whoami = argv[0];
201
202     initialize_PT_error_table();
203
204     strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
205     cell = 0;
206     i = 1;
207     while (i < argc) {
208         int arglen = strlen(argv[i]);
209         char arg[256];
210         lcstring(arg, argv[i], sizeof(arg));
211 #define IsArg(a) (strncmp (arg,a, arglen) == 0)
212         if (IsArg("-testconfdir"))
213             strncpy(confdir, argv[++i], sizeof(confdir));
214         else if (IsArg("client"))
215             strncpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(confdir));
216         else if (IsArg("server"))
217             strncpy(confdir, AFSDIR_SERVER_ETC_DIRPATH, sizeof(confdir));
218         else if (IsArg("0") || IsArg("1") || IsArg("2"))
219             security = atoi(argv[i]);
220         else if (IsArg("-ignoreexist"))
221             ignoreExist++;
222         else if (IsArg("-cell"))
223             cell = argv[++i];
224         else {
225             printf
226                 ("Usage is: 'prclient [-testconfdir <dir> | server | client] [0 | 1 | 2] [-ignoreExist] [-cell <cellname>]\n");
227             exit(1);
228         }
229         i++;
230     }
231
232     printf("Using CellServDB file in %s\n", confdir);
233     if (security == 0)
234         printf("Making unauthenticated connection to prserver\n");
235
236     code = pr_Initialize(security, confdir, cell);
237     if (code) {
238         afs_com_err(whoami, code, "Couldn't initialize protection library");
239         exit(1);
240     }
241
242     while (1) {
243         char *s;
244
245         printf("pr> ");
246         s = fgets(line, sizeof(line), stdin);
247         if (s == NULL)
248             break;
249         lineProgress = 0;
250
251         code = GetString(op, sizeof(op));
252         if (code) {
253             afs_com_err(whoami, PRBADARG,
254                     "error reading opcode in line '%s', got '%.*s'", line,
255                     sizeof(op), op);
256             exit(1);
257         }
258         if (strlen(op) == 0)
259             continue;           /* no input */
260
261         if (!strcmp(op, "cr")) {
262             if (GetString(name, sizeof(name)) || GetInt32(&id)
263                 || GetInt32(&oid))
264                 code = PRBADARG;
265             /* use ubik_Call to do the work, finding an up server and handling
266              * the job of finding a sync site, if need be */
267             else
268                 code = ubik_PR_INewEntry(pruclient, 0, name, id, oid);
269             if (CodeOk(code))
270                 afs_com_err(whoami, code, "on %s %s %d %d", op, name, id, oid);
271         } else if (!strcmp(op, "sf")) {
272             afs_int32 mask, access, gq, uq;
273             if (GetInt32(&id) || GetXInt32(&mask) || GetXInt32(&access)
274                 || GetInt32(&gq) || GetInt32(&uq))
275                 code = PRBADARG;
276             else
277                 code =
278                     ubik_PR_SetFieldsEntry(pruclient, 0, id, mask,
279                               access, gq, uq, 0, 0);
280             if (CodeOk(code))
281                 afs_com_err(whoami, code, "on %s %d %x %x %d %d", op, id, mask,
282                         access, gq, uq);
283         } else if (!strcmp(op, "ce")) {
284             char newname[PR_MAXNAMELEN];
285             afs_int32 newid;
286             if (GetInt32(&id) || GetString(newname, sizeof(newname))
287                 || GetInt32(&oid) || GetInt32(&newid))
288                 code = PRBADARG;
289             else
290                 code =
291                     ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid,
292                               newid);
293             if (CodeOk(code))
294                 afs_com_err(whoami, code, "on %s %d %s %d %d", op, id, newname,
295                         oid, newid);
296         } else if (!strcmp(op, "wh")) {
297             /* scanf("%d",&id); */
298             if (GetInt32(&id))
299                 code = PRBADARG;
300             else
301                 code = ubik_PR_WhereIsIt(pruclient, 0, id, &pos);
302             if (CodeOk(code))
303                 printf("%s\n", pr_ErrorMsg(code));
304             else
305                 printf("location %d\n", pos);
306         } else if (!strcmp(op, "du")) {
307             memset(&entry, 0, sizeof(entry));
308             /* scanf("%d",&pos); */
309             if (GetInt32(&pos))
310                 code = PRBADARG;
311             else
312                 code = ubik_PR_DumpEntry(pruclient, 0, pos, &entry);
313             if (CodeOk(code))
314                 printf("%s\n", pr_ErrorMsg(code));
315             if (code == PRSUCCESS) {
316                 PrintEntry(pos, &entry, /*indent */ 0);
317 #if 0
318                 printf("The contents of the entry for %d are:\n", entry.id);
319                 printf("flags %d next %d\n", entry.flags, entry.next);
320                 printf("Groups (or members) \n");
321                 for (i = 0; i < PRSIZE; i++)
322                     printf("%d\n", entry.entries[i]);
323                 printf("nextID %d nextname %d name %s\n", entry.nextID,
324                        entry.nextName, entry.name);
325                 printf("owner %d creator %d\n", entry.owner, entry.creator);
326 #endif
327             }
328         } else if (!strcmp(op, "add") || !strcmp(op, "au")) {
329             /* scanf("%d %d",&id,&gid); */
330             if (GetInt32(&id) || GetInt32(&gid))
331                 code = PRBADARG;
332             else
333                 code = ubik_PR_AddToGroup(pruclient, 0, id, gid);
334             if (CodeOk(code))
335                 afs_com_err(whoami, code, "on %s %d %d", op, id, gid);
336         } else if (!strcmp(op, "iton")) {
337             lid.idlist_val = (afs_int32 *) malloc(20 * sizeof(afs_int32));
338             ptr = lid.idlist_val;
339             lid.idlist_len = 0;
340             foo = line;
341             skip(&foo);
342             while ((lid.idlist_len < 20) && (sscanf(foo, "%d", ptr) != EOF)) {
343                 lid.idlist_len++;
344                 skip(&foo);
345                 ptr++;
346             }
347             if (*foo) {
348                 fprintf(stderr, "too many values specified; max is %d\n", 20);
349             }
350             lnames.namelist_val = 0;
351             lnames.namelist_len = 0;
352             code = ubik_PR_IDToName(pruclient, 0, &lid, &lnames);
353             if (CodeOk(code))
354                 printf("%s\n", pr_ErrorMsg(code));
355             if (code == PRSUCCESS) {
356                 for (i = 0; i < lnames.namelist_len; i++) {
357                     printf("id %d name %s\n", lid.idlist_val[i],
358                            lnames.namelist_val[i]);
359                 }
360                 free(lnames.namelist_val);
361             }
362             free(lid.idlist_val);
363             lid.idlist_val = 0;
364             lid.idlist_len = 0;
365         } else if (!strcmp(op, "ntoi")) {
366             lnames.namelist_val =
367                 (prname *) malloc(PR_MAXLIST * PR_MAXNAMELEN);
368             lnames.namelist_len = 0;
369             foo = line;
370             skip(&foo);
371             for (i = 0; ((lnames.namelist_len < PR_MAXLIST)
372                          && (sscanf(foo, "%s", lnames.namelist_val[i]) !=
373                              EOF)); i++) {
374                 lnames.namelist_len++;
375                 skip(&foo);
376             }
377             if (*foo) {
378                 fprintf(stderr, "too many values specified; max is %d\n",
379                         PR_MAXLIST);
380             }
381             lid.idlist_val = 0;
382             lid.idlist_len = 0;
383             code = ubik_PR_NameToID(pruclient, 0, &lnames, &lid);
384             if (CodeOk(code))
385                 printf("%s\n", pr_ErrorMsg(code));
386             if (code == PRSUCCESS) {
387                 for (i = 0; i < lid.idlist_len; i++)
388                     printf("name %s id %d\n", lnames.namelist_val[i],
389                            lid.idlist_val[i]);
390                 free(lid.idlist_val);
391             }
392             free(lnames.namelist_val);
393             lnames.namelist_val = 0;
394             lnames.namelist_len = 0;
395         } else if (!strcmp(op, "del")) {
396             /* scanf("%d",&id); */
397             if (GetInt32(&id))
398                 code = PRBADARG;
399             else
400                 code = ubik_PR_Delete(pruclient, 0, id);
401             if (CodeOk(code))
402                 printf("%s\n", pr_ErrorMsg(code));
403         } else if (!strcmp(op, "dg")) {
404             /* scanf("%d",&id); */
405             if (GetInt32(&id))
406                 code = PRBADARG;
407             else
408                 code = ubik_PR_Delete(pruclient, 0, id);
409             if (CodeOk(code))
410                 printf("%s\n", pr_ErrorMsg(code));
411         } else if (!strcmp(op, "rm")) {
412             /* scanf("%d %d",&id,&gid); */
413             if (GetInt32(&id) || GetInt32(&gid))
414                 code = PRBADARG;
415             else
416                 code = ubik_PR_RemoveFromGroup(pruclient, 0, id, gid);
417             if (CodeOk(code))
418                 printf("%s\n", pr_ErrorMsg(code));
419         }
420 #if defined(SUPERGROUPS)
421         else if (!strcmp(op, "lsg")) {
422             alist.prlist_len = 0;
423             alist.prlist_val = 0;
424             /* scanf("%d",&id); */
425             if (GetInt32(&id))
426                 code = PRBADARG;
427             else
428                 code =
429                     ubik_PR_ListSuperGroups(pruclient, 0, id, &alist,
430                               &over);
431             if (CodeOk(code))
432                 printf("%s\n", pr_ErrorMsg(code));
433             if (code == PRSUCCESS) {
434                 ptr = alist.prlist_val;
435                 if (over) {
436                     printf("Number of groups greater than PR_MAXGROUPS!\n");
437                     printf("Excess of %d.\n", over);
438                 }
439                 for (i = 0; i < alist.prlist_len; i++, ptr++)
440                     printf("%d\n", *ptr);
441                 free(alist.prlist_val);
442                 alist.prlist_len = 0;
443                 alist.prlist_val = 0;
444             }
445         }
446 #endif /* SUPERGROUPS */
447         else if (!strcmp(op, "l")) {
448             alist.prlist_len = 0;
449             alist.prlist_val = 0;
450             /* scanf("%d",&id); */
451             if (GetInt32(&id))
452                 code = PRBADARG;
453             else
454                 code = ubik_PR_GetCPS(pruclient, 0, id, &alist, &over);
455             if (CodeOk(code))
456                 printf("%s\n", pr_ErrorMsg(code));
457             if (code == PRSUCCESS) {
458                 ptr = alist.prlist_val;
459                 if (over) {
460                     printf("Number of groups greater than PR_MAXGROUPS!\n");
461                     printf("Excess of %d.\n", over);
462                 }
463                 for (i = 0; i < alist.prlist_len; i++, ptr++)
464                     printf("%d\n", *ptr);
465                 free(alist.prlist_val);
466                 alist.prlist_len = 0;
467                 alist.prlist_val = 0;
468             }
469         } else if (!strcmp(op, "lh")) {
470             alist.prlist_len = 0;
471             alist.prlist_val = 0;
472             /* scanf("%d",&id); */
473             if (GetString(name, sizeof(name)))
474                 code = PRBADARG;
475             else if (!(hostinfo = gethostbyname(name)))
476                 code = PRBADARG;
477             else {
478                 hostaddr = hostinfo->h_addr_list[0];
479                 id = ntohl(hostaddr->s_addr);
480                 code =
481                     ubik_PR_GetHostCPS(pruclient, 0, id, &alist, &over);
482             }
483             if (CodeOk(code))
484                 printf("%s\n", pr_ErrorMsg(code));
485             if (code == PRSUCCESS) {
486                 ptr = alist.prlist_val;
487                 if (over) {
488                     printf("Number of groups greater than PR_MAXGROUPS!\n");
489                     printf("Excess of %d.\n", over);
490                 }
491                 for (i = 0; i < alist.prlist_len; i++, ptr++)
492                     printf("%d\n", *ptr);
493                 free(alist.prlist_val);
494                 alist.prlist_len = 0;
495                 alist.prlist_val = 0;
496             }
497         }
498 #if defined(SUPERGROUPS)
499         else if (!strcmp(op, "m")) {
500             alist.prlist_len = 0;
501             alist.prlist_val = 0;
502             /* scanf("%d",&id); */
503             if (GetInt32(&id))
504                 code = PRBADARG;
505             else
506                 code =
507                     ubik_PR_ListElements(pruclient, 0, id, &alist,
508                               &over);
509             if (CodeOk(code))
510                 printf("%s\n", pr_ErrorMsg(code));
511             if (code == PRSUCCESS) {
512                 ptr = alist.prlist_val;
513                 if (over) {
514                     printf("Number of groups greater than PR_MAXGROUPS!\n");
515                     printf("Excess of %d.\n", over);
516                 }
517                 for (i = 0; i < alist.prlist_len; i++, ptr++)
518                     printf("%d\n", *ptr);
519                 free(alist.prlist_val);
520                 alist.prlist_len = 0;
521                 alist.prlist_val = 0;
522             }
523         }
524 #endif /* SUPERGROUPS */
525         else if (!strcmp(op, "nu")) {
526             /* scanf("%s",name); */
527             if (GetString(name, sizeof(name)))
528                 code = PRBADARG;
529             else
530                 code = pr_CreateUser(name, &id);
531             if (CodeOk(code))
532                 printf("%s\n", pr_ErrorMsg(code));
533             if (code == PRSUCCESS)
534                 printf("Id is %d.\n", id);
535         } else if (!strcmp(op, "ng")) {
536             /* scanf("%s",name); */
537             if (GetString(name, sizeof(name)))
538                 code = PRBADARG;
539             else
540                 code = ubik_PR_NewEntry(pruclient, 0, name, 1, oid, &id);
541             if (CodeOk(code))
542                 printf("%s\n", pr_ErrorMsg(code));
543             if (code == PRSUCCESS)
544                 printf("Id is %d.\n", id);
545         } else if (!strcmp(op, "lm")) {
546             code = ubik_PR_ListMax(pruclient, 0, &id, &gid);
547             if (CodeOk(code))
548                 printf("%s\n", pr_ErrorMsg(code));
549             if (code == PRSUCCESS)
550                 printf("Max user id is %d, max (really min) group is %d.\n",
551                        id, gid);
552         } else if (!strcmp(op, "smu")) {
553             /* scanf("%d",&id); */
554             if (GetInt32(&id))
555                 code = PRBADARG;
556             else
557                 code = ubik_PR_SetMax(pruclient, 0, id, 0);
558             if (CodeOk(code))
559                 printf("%s\n", pr_ErrorMsg(code));
560         } else if (!strcmp(op, "smg")) {
561             /* scanf("%d",&id); */
562             if (GetInt32(&id))
563                 code = PRBADARG;
564             else
565                 code = ubik_PR_SetMax(pruclient, 0, id, 1);
566             if (CodeOk(code))
567                 printf("%s\n", pr_ErrorMsg(code));
568         } else if (!strcmp(op, "sin")) {
569             /* scanf("%d",&id); */
570             if (GetInt32(&id))
571                 code = PRBADARG;
572             else
573                 code = pr_SIdToName(id, name);
574             if (CodeOk(code))
575                 printf("%s\n", pr_ErrorMsg(code));
576             if (code == PRSUCCESS)
577                 printf("id %d name %s\n", id, name);
578         } else if (!strcmp(op, "sni")) {
579             /* scanf("%s",name); */
580             if (GetString(name, sizeof(name)))
581                 code = PRBADARG;
582             else
583                 code = pr_SNameToId(name, &id);
584             if (CodeOk(code))
585                 printf("%s\n", pr_ErrorMsg(code));
586             if (code == PRSUCCESS)
587                 printf("name %s id %d\n", name, id);
588         } else if (!strcmp(op, "fih")) {
589             char tname[128];
590             struct PrUpdateEntry uentry;
591             memset(&uentry, 0, sizeof(uentry));
592             /* scanf("%s",name); */
593             if (GetString(name, sizeof(name))) {
594                 code = PRBADARG;
595                 continue;
596             }
597             code = pr_SNameToId(name, &id);
598             if (CodeOk(code)) {
599                 printf("%s\n", pr_ErrorMsg(code));
600                 continue;
601             }
602             code = pr_SIdToName(id, tname);
603             if (code == PRSUCCESS) {
604                 printf
605                     ("Warning: Id hash for %s (id %d) seems correct at the db; rehashing it anyway\n",
606                      name, id);
607 /*              continue;*/
608             }
609             uentry.Mask = PRUPDATE_IDHASH;
610             code = ubik_PR_UpdateEntry(pruclient, 0, 0, name, &uentry);
611             if (code) {
612                 printf("Failed to update entry %s (err=%d)\n", name, code);
613                 continue;
614             }
615         } else if (!strcmp(op, "fnh")) {
616             int tid;
617             struct PrUpdateEntry uentry;
618             memset(&uentry, 0, sizeof(uentry));
619             /* scanf("%d", &id); */
620             if (GetInt32(&id)) {
621                 code = PRBADARG;
622                 continue;
623             }
624             code = pr_SIdToName(id, name);
625             if (CodeOk(code)) {
626                 printf("%s\n", pr_ErrorMsg(code));
627                 continue;
628             }
629             code = pr_SNameToId(name, &tid);
630             if (code == PRSUCCESS) {
631                 printf
632                     ("Name hash for %d (name is %s) seems correct at the db; rehashing it anyway\n",
633                      id, name);
634 /*              continue;*/
635             }
636             uentry.Mask = PRUPDATE_NAMEHASH;
637             code =
638                 ubik_PR_UpdateEntry(pruclient, 0, id, "_foo_", &uentry);
639             if (code) {
640                 printf("Failed to update entry with id %d (err=%d)\n", id,
641                        code);
642                 continue;
643             }
644         }
645 #if defined(SUPERGROUPS)
646         else if (!strcmp(op, "fih")) {
647             char tname[128];
648             struct PrUpdateEntry uentry;
649             memset(&uentry, 0, sizeof(uentry));
650             /* scanf("%s",name); */
651             if (GetString(name, sizeof(name))) {
652                 code = PRBADARG;
653                 continue;
654             }
655             code = pr_SNameToId(name, &id);
656             if (CodeOk(code)) {
657                 printf("%s\n", pr_ErrorMsg(code));
658                 continue;
659             }
660             code = pr_SIdToName(id, tname);
661             if (code == PRSUCCESS) {
662                 printf
663                     ("Warning: Id hash for %s (id %d) seems correct at the db; rehashing it anyway\n",
664                      name, id);
665 /*              continue;*/
666             }
667             uentry.Mask = PRUPDATE_IDHASH;
668             code = ubik_PR_UpdateEntry(pruclient, 0, 0, name, &uentry);
669             if (code) {
670                 printf("Failed to update entry %s (err=%d)\n", name, code);
671                 continue;
672             }
673         } else if (!strcmp(op, "fnh")) {
674             int tid;
675             struct PrUpdateEntry uentry;
676             memset(&uentry, 0, sizeof(uentry));
677             /* scanf("%d", &id); */
678             if (GetInt32(&id)) {
679                 code = PRBADARG;
680                 continue;
681             }
682             code = pr_SIdToName(id, name);
683             if (CodeOk(code)) {
684                 printf("%s\n", pr_ErrorMsg(code));
685                 continue;
686             }
687             code = pr_SNameToId(name, &tid);
688             if (code == PRSUCCESS) {
689                 printf
690                     ("Name hash for %d (name is %s) seems correct at the db; rehashing it anyway\n",
691                      id, name);
692 /*              continue;*/
693             }
694             uentry.Mask = PRUPDATE_NAMEHASH;
695             code =
696                 ubik_PR_UpdateEntry(pruclient, 0, id, "_foo_", &uentry);
697             if (code) {
698                 printf("Failed to update entry with id %d (err=%d)\n", id,
699                        code);
700                 continue;
701             }
702         }
703 #endif /* SUPERGROUPS */
704         else if (!strcmp(op, "?"))
705             PrintHelp();
706         else if (!strcmp(op, "q"))
707             exit(0);
708         else
709             printf("Unknown op: '%s'! ? for help\n", op);
710     }
711 }
712
713
714 PrintHelp()
715 {
716     printf("cr name id owner - create entry with name and id.\n");
717     printf("wh id  - what is the offset into database for id?\n");
718     printf("du offset - dump the contents of the entry at offset.\n");
719     printf("add uid gid - add user uid to group gid.\n");
720     printf("iton id* - translate the list of id's to names.\n");
721     printf("ntoi name* - translate the list of names to ids.\n");
722     printf("del id - delete the entry for id.\n");
723     printf("dg gid - delete the entry for group gid.\n");
724     printf("rm id gid - remove user id from group gid.\n");
725     printf("l id - get the CPS for id.\n");
726     printf("lh host - get the host CPS for host.\n");
727 #if defined(SUPERGROUPS)
728     printf("lsg id - get the supergroups for id.\n");
729     printf("m id - list elements for id.\n");
730 #endif
731     printf("nu name - create new user with name - returns an id.\n");
732     printf("ng name - create new group with name - returns an id.\n");
733     printf("lm  - list max user id and max (really min) group id.\n");
734     printf("smu - set max user id.\n");
735     printf("smg - set max group id.\n");
736     printf("sin id - single iton.\n");
737     printf("sni name - single ntoi.\n");
738     printf("fih name - fix id hash for <name>.\n");
739     printf("fnh id - fix name hash for <id>.\n");
740     printf("q - quit.\n?- this message.\n");
741 }
742
743
744 skip(s)
745      char **s;
746 {
747     while (**s != ' ' && **s != '\0')
748         (*s)++;
749     while (**s == ' ')
750         (*s)++;
751 }
752 #endif /* !AFS_PTHREAD_ENV */