[OpenAFS-devel] patch for src/ptserver/pt_util.c
Matthew A. Bacchi
mbacchi@btv.ibm.com
Mon, 27 Jan 2003 13:38:22 -0500
I modified the pt_util tool to use libcmd, but one issue remains
regarding whether to rename the command line args. In this patch I
simply kept the flags as they were, but since I don't know how to
get libcmd to output the help _description_ in addition to the flags
themselves, I lengthened the name of the arguments. For example the
-n argument is now -name. I think because libcmd seems better suited
to handle command _suites_ such as backup and vos, and the
cmd_AddParm() call wants to add sub-command help descriptions, I was
confused. So basically, I didn't know how to get the help output to
display the long help description in the "Where:" section. If you have
suggestions, I'll fix and resubmit the patch, or if you want to make a
change go ahead.
Also, is there any documentation of the libcmd library, especially the
cmd_Seek() call? I used it here, but just made sure I did a seek
beyond the largest arg # I had created with cmd_AddParm().
Thanks,
-Matt
These diffs were taken relative to the openafs-1.2.9-rc1 version. This
was tested on AIX 4.3.3 only at this point.
*** orig/src/ptserver/Makefile.in Wed Sep 19 18:40:37 2001
--- src/ptserver/Makefile.in Mon Jan 27 13:07:40 2003
***************
*** 141,147 ****
testpt.o: testpt.c ${INCLS} ${TOP_INCDIR}/afs/cmd.h AFS_component_version_number.c
pt_util: pt_util.o ptutils.o ubik.o utils.o libprot.a $(LIBS)
! $(CC) ${CFLAGS} -o pt_util pt_util.o ptutils.o ubik.o utils.o libprot.a $(LIBS) ${XLIBS}
ubik.o: ubik.c ${INCLS}
--- 141,148 ----
testpt.o: testpt.c ${INCLS} ${TOP_INCDIR}/afs/cmd.h AFS_component_version_number.c
pt_util: pt_util.o ptutils.o ubik.o utils.o libprot.a $(LIBS)
! $(CC) ${CFLAGS} -o pt_util pt_util.o ptutils.o ubik.o utils.o libprot.a \
! ${TOP_LIBDIR}/libcmd.a $(LIBS) ${XLIBS}
ubik.o: ubik.c ${INCLS}
*** orig/src/ptserver/pt_util.c Mon Jan 27 09:59:37 2003
--- src/ptserver/pt_util.c Mon Jan 27 13:09:01 2003
***************
*** 24,29 ****
--- 24,30 ----
RCSID("$Header: /cvs/openafs/src/ptserver/pt_util.c,v 1.3.4.4 2003/01/11 07:53:30 shadow Exp $");
+ #include <afs/cmd.h> /*Command line parsing*/
#include <errno.h>
#include <lock.h>
#include <netinet/in.h>
***************
*** 50,55 ****
--- 51,57 ----
char *checkin();
char *check_core();
char *id_to_name();
+ int CommandProc(struct cmd_syndesc*);
struct hash_entry {
char h_name[PR_MAXNAMELEN];
***************
*** 98,103 ****
--- 100,129 ----
int argc;
char **argv;
{
+
+ register struct cmd_syndesc *cs; /*Command line syntax descriptor*/
+ register afs_int32 code; /*Return code*/
+
+ cs = cmd_CreateSyntax((char *) 0, CommandProc, 0, "access protection database");
+ cmd_AddParm(cs, "-w", CMD_FLAG, CMD_OPTIONAL, "update prdb with contents of data file");
+ cmd_AddParm(cs, "-user", CMD_FLAG, CMD_OPTIONAL, "display users");
+ cmd_AddParm(cs, "-group", CMD_FLAG, CMD_OPTIONAL, "display groups");
+ cmd_AddParm(cs, "-members", CMD_FLAG, CMD_OPTIONAL, "display group members");
+ cmd_AddParm(cs, "-name", CMD_FLAG, CMD_OPTIONAL, "follow name hash chains (not id hashes)");
+ cmd_AddParm(cs, "-system", CMD_FLAG, CMD_OPTIONAL, "display only system data");
+ cmd_AddParm(cs, "-xtra", CMD_FLAG, CMD_OPTIONAL, "display extra users/groups");
+ cmd_Seek(cs, 10);
+ cmd_AddParm(cs, "-prdb", CMD_SINGLE, CMD_OPTIONAL, "prdb file");
+ cmd_AddParm(cs, "-datafile", CMD_SINGLE, CMD_OPTIONAL, "data file");
+ code = cmd_Dispatch(argc, argv);
+
+ exit(code);
+
+ }
+
+ int CommandProc(a_as)
+ register struct cmd_syndesc *a_as;
+ {
register int i;
register long code;
long cc, upos, gpos;
***************
*** 105,154 ****
struct ubik_hdr *uh;
char *dfile = 0;
char *pfile = "/usr/afs/db/prdb.DB0";
!
! while ((cc = getopt(argc, argv, "wugmxsnp:d:")) != EOF) {
! switch (cc) {
! case 'p':
! pfile = optarg;
! break;
! case 'd':
! dfile = optarg;
! break;
! case 'n':
! nflag++;
! break;
! case 'w':
! wflag++;
! break;
! case 'u':
! flags |= DO_USR;
! break;
! case 'm':
! flags |= (DO_GRP|DO_MEM);
! break;
! case 'g':
! flags |= DO_GRP;
! break;
! case 's':
! flags |= DO_SYS;
! break;
! case 'x':
! flags |= DO_OTR;
! break;
! default:
! fprintf(stderr,
! "Usage: pt_util [options] [-d data] [-p prdb]\n");
! fputs(" Options:\n", stderr);
! fputs(" -w Update prdb with contents of data file\n", stderr);
! fputs(" -u Display users\n", stderr);
! fputs(" -g Display groups\n", stderr);
! fputs(" -m Display group members\n", stderr);
! fputs(" -n Follow name hash chains (not id hashes)\n", stderr);
! fputs(" -s Display only system data\n", stderr);
! fputs(" -x Display extra users/groups\n", stderr);
! exit(1);
! }
}
if ((dbase_fd = open(pfile, (wflag ? O_RDWR : O_RDONLY)|O_CREAT, 0600))
< 0) {
fprintf(stderr, "pt_util: cannot open %s: %s\n",
--- 131,169 ----
struct ubik_hdr *uh;
char *dfile = 0;
char *pfile = "/usr/afs/db/prdb.DB0";
! struct cmd_parmdesc *tparm;
!
! tparm = a_as->parms;
!
! if ( tparm[0].items ) {
! wflag++;
}
+ if ( tparm[1].items ) {
+ flags |= DO_USR;
+ }
+ if ( tparm[2].items ) {
+ flags |= DO_GRP;
+ }
+ if ( tparm[3].items ) {
+ flags |= (DO_GRP|DO_MEM);
+ }
+ if ( tparm[4].items ) {
+ nflag++;
+ }
+ if ( tparm[5].items ) {
+ flags |= DO_SYS;
+ }
+ if ( tparm[6].items ) {
+ flags |= DO_OTR;
+ }
+ if ( tparm[7].items ) {
+ pfile = tparm[7].items->data;
+ }
+ if ( tparm[8].items ) {
+ dfile = tparm[8].items->data;
+ }
+
+
if ((dbase_fd = open(pfile, (wflag ? O_RDWR : O_RDONLY)|O_CREAT, 0600))
< 0) {
fprintf(stderr, "pt_util: cannot open %s: %s\n",