static void add_std_args(struct cmd_syndesc *ts) { cmd_Seek(ts, 14); cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL, "local authentication"); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); }
int main(int argc, char *argv[]) { struct cmd_syndesc *ts; afs_int32 code; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif zero_argc = argc; zero_argv = argv; ts = cmd_CreateSyntax(NULL, CommandProc, NULL, "obtain Kerberos authentication"); #define aXFLAG 0 #define aPRINCIPAL 1 #define aPASSWORD 2 #define aCELL 3 #define aSERVERS 4 #define aPIPE 5 #define aSILENT 6 #define aLIFETIME 7 #define aSETPAG 8 #define aTMP 9 cmd_AddParm(ts, "-x", CMD_FLAG, CMD_OPTIONAL, "(obsolete, noop)"); cmd_Seek(ts, aPRINCIPAL); cmd_AddParm(ts, "-principal", CMD_SINGLE, CMD_OPTIONAL, "user name"); cmd_AddParm(ts, "-password", CMD_SINGLE, CMD_OPTIONAL, "user's password"); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "explicit list of servers"); cmd_AddParm(ts, "-pipe", CMD_FLAG, CMD_OPTIONAL, "read password from stdin"); cmd_AddParm(ts, "-silent", CMD_FLAG, CMD_OPTIONAL, "silent operation"); cmd_AddParm(ts, "-lifetime", CMD_SINGLE, CMD_OPTIONAL, "ticket lifetime in hh[:mm[:ss]]"); cmd_AddParm(ts, "-setpag", CMD_FLAG, CMD_OPTIONAL, "Create a new setpag before authenticating"); cmd_AddParm(ts, "-tmp", CMD_FLAG, CMD_OPTIONAL, "write Kerberos-style ticket file in /tmp"); code = cmd_Dispatch(argc, argv); KLOGEXIT(code); }
struct cmd_syndesc * cmd_CreateSyntax(char *aname, int (*aproc) (struct cmd_syndesc * ts, void *arock), void *arock, char *ahelp) { struct cmd_syndesc *td; /* can't have two cmds in no opcode mode */ if (noOpcodes) return NULL; td = calloc(1, sizeof(struct cmd_syndesc)); assert(td); td->aliasOf = td; /* treat aliasOf as pointer to real command, no matter what */ /* copy in name, etc */ if (aname) { td->name = strdup(aname); assert(td->name); } else { td->name = NULL; noOpcodes = 1; } if (ahelp) { /* Piggy-back the hidden option onto the help string */ if (ahelp == (char *)CMD_HIDDEN) { td->flags |= CMD_HIDDEN; } else { td->help = strdup(ahelp); assert(td->help); } } else td->help = NULL; td->proc = aproc; td->rock = arock; SortSyntax(td); cmd_Seek(td, CMD_HELPPARM); cmd_AddParm(td, "-help", CMD_FLAG, CMD_OPTIONAL, "get detailed help"); cmd_Seek(td, 0); return td; }
int main(int argc, char **argv) { struct cmd_syndesc *ts; ts = cmd_CreateSyntax("apple", cproc1, NULL, 0, "describe apple"); cmd_CreateAlias(ts, "appl"); ts = cmd_CreateSyntax("pear", cproc2, NULL, 0, "describe pear"); cmd_AddParm(ts, "-num", CMD_LIST, 0, "number of pears"); cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate"); cmd_AddParm(ts, "-spotpos", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, 0); cmd_Seek(ts, 8); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_CreateAlias(ts, "alias"); return cmd_Dispatch(argc, argv); }
int main(int argc, char **argv) { struct cmd_syndesc *ts; char tline[1000]; afs_int32 tc; char *tp; long code; char *tv[100]; initialize_CMD_error_table(); ts = cmd_CreateSyntax("apple", cproc1, NULL, 0, "describe apple"); ts = cmd_CreateSyntax("pear", cproc2, NULL, 0, "describe pear"); cmd_AddParm(ts, "-num", CMD_LIST, 0, "number of pears"); cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL, "don't authenticate"); cmd_AddParm(ts, "-spotpos", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS, 0); cmd_Seek(ts, 8); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_CreateAlias(ts, "alias"); ts = cmd_CreateSyntax("quit", cproc3, 0, 0, "quit"); while (1) { printf("> "); tp = gets(tline); if (tp == NULL) break; code = cmd_ParseLine(tline, tv, &tc, 100); if (code) { printf("itest: parsing failure: %s\n", afs_error_message(code)); exit(1); } code = cmd_Dispatch(tc, tv); cmd_FreeArgv(tv); if (code) { printf("itest: execution failed: %s\n", afs_error_message(code)); } } return 0; }
int main(int argc, char **argv) { struct cmd_syndesc *ts; int err = 0; int i; extern char cml_version_number[]; /* Initialize directory paths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", argv[0]); exit(2); } ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "needvolume"); ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "cbk"); ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "ls"); ts = cmd_CreateSyntax("leaveoff", VolLeaveOff, 0, "leave volume offline (FSYNC_VOL_LEAVE_OFF opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("attach", VolForceAttach, 0, "force full attachment (FSYNC_VOL_ATTACH opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("error", VolForceError, 0, "force into hard error state (FSYNC_VOL_FORCE_ERROR opcode)"); VOLOP_PARMS_DECL(ts); ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "qry"); ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "hdr"); ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)"); VOLOP_PARMS_DECL(ts); cmd_CreateAlias(ts, "vop"); ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)"); cmd_Seek(ts, CUSTOM_PARMS_OFFSET); cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id"); cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier"); cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name"); COMMON_PARMS_DECL(ts); ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information"); cmd_Seek(ts, CUSTOM_PARMS_OFFSET); cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand"); cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1"); cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2"); COMMON_PARMS_DECL(ts); err = cmd_Dispatch(argc, argv); exit(err); }
int main(int argc, char **argv) { /*main */ char *targv[MAXV]; /*Ptr to parsed argv stuff */ afs_int32 targc; /*Num parsed arguments */ afs_int32 code; /*Return code */ struct cmd_syndesc *ts; /*Ptr to parsed command line */ int i; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif Lock_Init(&dispatchLock); InitErrTabs(); /* init all the error tables which may be used */ /* setup the default backup dir */ DefaultConfDir = AFSDIR_SERVER_BACKUP_DIRPATH; /* Get early warning if the command is interacive mode or not */ interact = (((argc < 2) || (argv[1][0] == '-')) ? 1 : 0); cmd_SetBeforeProc(MyBeforeProc, NULL); ts = cmd_CreateSyntax("dump", bc_DumpCmd, NULL, "start dump"); cmd_AddParm(ts, "-volumeset", CMD_SINGLE, CMD_OPTIONAL, "volume set name"); cmd_AddParm(ts, "-dump", CMD_SINGLE, CMD_OPTIONAL, "dump level name"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); cmd_AddParm(ts, "-at", CMD_LIST, CMD_OPTIONAL, "Date/time to start dump"); cmd_AddParm(ts, "-append", CMD_FLAG, CMD_OPTIONAL, "append to existing dump set"); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it"); cmd_AddParmAlias(ts, 5, "-n"); cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "load file"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("volrestore", bc_VolRestoreCmd, NULL, "restore volume"); cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "destination machine"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "destination partition"); cmd_AddParm(ts, "-volume", CMD_LIST, CMD_REQUIRED, "volume(s) to restore"); cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "new volume name extension"); cmd_AddParm(ts, "-date", CMD_LIST, CMD_OPTIONAL, "date from which to restore"); cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offsets"); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it"); cmd_AddParmAlias(ts, 6, "-n"); cmd_AddParm(ts, "-usedump", CMD_SINGLE, CMD_OPTIONAL, "specify the dumpID to restore from"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("diskrestore", bc_DiskRestoreCmd, NULL, "restore partition"); cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine to restore"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition to restore"); cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offset"); cmd_Seek(ts, 8); cmd_AddParm(ts, "-newserver", CMD_SINGLE, CMD_OPTIONAL, "destination machine"); cmd_AddParm(ts, "-newpartition", CMD_SINGLE, CMD_OPTIONAL, "destination partition"); cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "new volume name extension"); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it"); cmd_AddParmAlias(ts, 11, "-n"); if (!interact) add_std_args(ts); cmd_CreateSyntax("quit", bc_QuitCmd, NULL, "leave the program"); ts = cmd_CreateSyntax("volsetrestore", bc_VolsetRestoreCmd, NULL, "restore a set of volumes"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume set name"); cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "file name"); cmd_AddParm(ts, "-portoffset", CMD_LIST, CMD_OPTIONAL, "TC port offset"); cmd_AddParm(ts, "-extension", CMD_SINGLE, CMD_OPTIONAL, "new volume name extension"); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list what would be done, don't do it"); cmd_AddParmAlias(ts, 4, "-n"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("addhost", bc_AddHostCmd, NULL, "add host to config"); cmd_AddParm(ts, "-tapehost", CMD_SINGLE, CMD_REQUIRED, "tape machine name"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("delhost", bc_DeleteHostCmd, NULL, "delete host to config"); cmd_AddParm(ts, "-tapehost", CMD_SINGLE, CMD_REQUIRED, "tape machine name"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("listhosts", bc_ListHostsCmd, NULL, "list config hosts"); if (!interact) add_std_args(ts); cmd_CreateSyntax("jobs", bc_JobsCmd, NULL, "list running jobs"); ts = cmd_CreateSyntax("kill", bc_KillCmd, NULL, "kill running job"); cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED, "job ID or dump set name"); ts = cmd_CreateSyntax("listvolsets", bc_ListVolSetCmd, NULL, "list volume sets"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "volume set name"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("listdumps", bc_ListDumpScheduleCmd, NULL, "list dump schedules"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("addvolset", bc_AddVolSetCmd, NULL, "create a new volume set"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name"); cmd_AddParm(ts, "-temporary", CMD_FLAG, CMD_OPTIONAL, "temporary volume set"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("status", bc_GetTapeStatusCmd, NULL, "get tape coordinator status"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("delvolset", bc_DeleteVolSetCmd, NULL, "delete a volume set"); cmd_AddParm(ts, "-name", CMD_LIST, CMD_REQUIRED, "volume set name"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("addvolentry", bc_AddVolEntryCmd, NULL, "add a new volume entry"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name"); cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name"); cmd_AddParm(ts, "-volumes", CMD_SINGLE, CMD_REQUIRED, "volume name (regular expression)"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("delvolentry", bc_DeleteVolEntryCmd, NULL, "delete a volume set sub-entry"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_REQUIRED, "volume set name"); cmd_AddParm(ts, "-entry", CMD_SINGLE, CMD_REQUIRED, "volume set index"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("adddump", bc_AddDumpCmd, NULL, "add dump schedule"); cmd_AddParm(ts, "-dump", CMD_LIST, CMD_REQUIRED, "dump level name"); cmd_AddParm(ts, "-expires", CMD_LIST, CMD_OPTIONAL, "expiration date"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("deldump", bc_DeleteDumpCmd, NULL, "delete dump schedule"); cmd_AddParm(ts, "-dump", CMD_SINGLE, CMD_REQUIRED, "dump level name"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("labeltape", bc_LabelTapeCmd, NULL, "label a tape"); cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "AFS tape name, defaults to NULL"); cmd_AddParm(ts, "-size", CMD_SINGLE, CMD_OPTIONAL, "tape size in Kbytes, defaults to size in tapeconfig"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); cmd_AddParm(ts, "-pname", CMD_SINGLE, CMD_OPTIONAL, "permanent tape name"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("readlabel", bc_ReadLabelCmd, NULL, "read the label on tape"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("scantape", bc_ScanDumpsCmd, NULL, "dump information recovery from tape"); cmd_AddParm(ts, "-dbadd", CMD_FLAG, CMD_OPTIONAL, "add information to the database"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("volinfo", bc_dblookupCmd, NULL, "query the backup database"); cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_REQUIRED, "volume name"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("setexp", bc_SetExpCmd, NULL, "set/clear dump expiration dates"); cmd_AddParm(ts, "-dump", CMD_LIST, CMD_REQUIRED, "dump level name"); cmd_AddParm(ts, "-expires", CMD_LIST, CMD_OPTIONAL, "expiration date"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("savedb", bc_saveDbCmd, NULL, "save backup database"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); cmd_AddParm(ts, "-archive", CMD_LIST, CMD_OPTIONAL, "date time"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("restoredb", bc_restoreDbCmd, NULL, "restore backup database"); cmd_AddParm(ts, "-portoffset", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("dumpinfo", bc_dumpInfoCmd, NULL, "provide information about a dump in the database"); cmd_AddParm(ts, "-ndumps", CMD_SINGLE, CMD_OPTIONAL, "no. of dumps"); cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_OPTIONAL, "dump id"); cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "detailed description"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("dbverify", bc_dbVerifyCmd, NULL, "check ubik database integrity"); cmd_AddParm(ts, "-detail", CMD_FLAG, CMD_OPTIONAL, "additional details"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("deletedump", bc_deleteDumpCmd, NULL, "delete dumps from the database"); cmd_AddParm(ts, "-dumpid", CMD_LIST, CMD_OPTIONAL, "dump id"); cmd_AddParm(ts, "-from", CMD_LIST, CMD_OPTIONAL, "date time"); cmd_AddParm(ts, "-to", CMD_LIST, CMD_OPTIONAL, "date time"); cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "TC port offset"); cmd_AddParm(ts, "-groupid", CMD_SINGLE, CMD_OPTIONAL, "group ID"); cmd_AddParm(ts, "-dbonly", CMD_FLAG, CMD_OPTIONAL, "delete the dump from the backup database only"); cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "always delete from backup database"); cmd_AddParm(ts, "-noexecute", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, ""); cmd_AddParm(ts, "-dryrun", CMD_FLAG, CMD_OPTIONAL, "list the dumps, don't delete anything"); cmd_AddParmAlias(ts, 8, "-n"); if (!interact) add_std_args(ts); ts = cmd_CreateSyntax("interactive", bc_interactCmd, NULL, "enter interactive mode"); add_std_args(ts); /* * Now execute the command. */ targc = 0; targv[targc++] = argv[0]; if (interact) targv[targc++] = "interactive"; for (i = 1; i < argc; i++) targv[targc++] = argv[i]; code = doDispatch(targc, targv, 1); if (!interact || !bcInit) { /* Non-interactive mode */ if (code) exit(-1); if (bcInit) code = bc_WaitForNoJobs(); /* wait for any jobs to finish */ exit(code); /* and exit */ } /* Iterate on command lines, interpreting user commands (interactive mode) */ while (1) { int ret; printf("backup> "); fflush(stdout); while ((ret = LWP_GetLine(lineBuffer, sizeof(lineBuffer))) == 0) printf("%s: Command line too long\n", whoami); /* line too long */ if (ret == -1) return 0; /* Got EOF */ if (!LineIsBlank(lineBuffer)) { code = cmd_ParseLine(lineBuffer, targv, &targc, MAXV); if (code) afs_com_err(whoami, code, "; Can't parse line: '%s'", afs_error_message(code)); else { doDispatch(targc, targv, 1); cmd_FreeArgv(targv); } } } } /*main */
int main(int argc, char **argv) { struct CmdLine cmdline; struct cmd_syndesc *ts; int err = 0; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif /* Initialize directory paths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif fprintf(stderr, "%s: Unable to obtain AFS server directory.\n", argv[0]); exit(2); } #ifdef AFS_NT40_ENV /* Default to binary mode for fopen() */ _set_fmode(_O_BINARY); main_thread = pthread_self(); if (spawnDatap && spawnDataLen) { /* This is a child per partition salvager. Don't setup log or * try to lock the salvager lock. */ if (nt_SetupPartitionSalvage(spawnDatap, spawnDataLen) < 0) exit(3); } else { #endif #ifndef AFS_NT40_ENV if (geteuid() != 0) { printf("Salvager must be run as root.\n"); fflush(stdout); Exit(0); } #endif /* Get and hold a lock for the duration of the salvage to make sure * that no other salvage runs at the same time. The routine * VInitVolumePackage2 (called below) makes sure that a file server or * other volume utilities don't interfere with the salvage. */ get_salvage_lock = 1; #ifdef AFS_NT40_ENV } #endif cmdline.argc = argc; cmdline.argv = argv; ts = cmd_CreateSyntax("initcmd", handleit, &cmdline, 0, "initialize the program"); cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "Name of partition to salvage"); cmd_AddParm(ts, "-volumeid", CMD_SINGLE, CMD_OPTIONAL, "Volume Id to salvage"); cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL, "Run in Debugging mode"); cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL, "Run readonly/test mode"); cmd_AddParm(ts, "-inodes", CMD_FLAG, CMD_OPTIONAL, "Just list affected afs inodes - debugging flag"); cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL, "Force full salvaging"); cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL, "Give permission to destroy bogus inodes/volumes - debugging flag"); cmd_AddParm(ts, "-rootinodes", CMD_FLAG, CMD_OPTIONAL, "Show inodes owned by root - debugging flag"); cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL, "Force rebuild/salvage of all directories"); cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL, "Read smaller blocks to handle IO/bad blocks"); cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL, "# of max parallel partition salvaging"); cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL, "Name of dir to place tmp files "); cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "Show log file upon completion"); cmd_AddParm(ts, "-showsuid", CMD_FLAG, CMD_OPTIONAL, "Report on suid/sgid files"); cmd_AddParm(ts, "-showmounts", CMD_FLAG, CMD_OPTIONAL, "Report on mountpoints"); cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL, "ignore | remove | attach"); /* note - syslog isn't avail on NT, but if we make it conditional, have * to deal with screwy offsets for cmd params */ cmd_AddParm(ts, "-syslog", CMD_FLAG, CMD_OPTIONAL, "Write salvage log to syslogs"); cmd_AddParm(ts, "-syslogfacility", CMD_SINGLE, CMD_OPTIONAL, "Syslog facility number to use"); cmd_AddParm(ts, "-datelogs", CMD_FLAG, CMD_OPTIONAL, "Include timestamp in logfile filename"); #ifdef FAST_RESTART cmd_AddParm(ts, "-DontSalvage", CMD_FLAG, CMD_OPTIONAL, "Don't salvage. This my be set in BosConfig to let the fileserver restart immediately after a crash. Bad volumes will be taken offline"); #elif defined(AFS_DEMAND_ATTACH_FS) cmd_Seek(ts, 20); /* skip DontSalvage */ cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL, "For Demand Attach Fileserver, permit a manual volume salvage outside of the salvageserver"); #endif /* FAST_RESTART */ cmd_Seek(ts, 21); /* skip DontSalvage and forceDAFS if needed */ cmd_AddParm(ts, "-f", CMD_FLAG, CMD_OPTIONAL, "Alias for -force"); err = cmd_Dispatch(argc, argv); Exit(err); return 0; /* not reached */ }
int main(int argc, char *argv[]) { struct cmd_syndesc *ts; afs_int32 code; #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif zero_argc = argc; zero_argv = argv; ts = cmd_CreateSyntax(NULL, CommandProc, NULL, 0, "obtain Kerberos authentication"); #define aXFLAG 0 #define aPRINCIPAL 1 #define aPASSWORD 2 #define aCELL 3 #define aKRBREALM 4 #define aPIPE 5 #define aSILENT 6 #define aLIFETIME 7 #define aSETPAG 8 #define aTMP 9 #define aNOPRDB 10 #define aUNWRAP 11 #define aK5 12 #define aK4 13 cmd_AddParm(ts, "-x", CMD_FLAG, CMD_OPTIONAL, "obsolete, noop"); cmd_Seek(ts, aPRINCIPAL); cmd_AddParm(ts, "-principal", CMD_SINGLE, CMD_OPTIONAL, "user name"); cmd_AddParm(ts, "-password", CMD_SINGLE, CMD_OPTIONAL, "user's password"); cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name"); cmd_AddParm(ts, "-k", CMD_SINGLE, CMD_OPTIONAL, "krb5 realm"); cmd_AddParm(ts, "-pipe", CMD_FLAG, CMD_OPTIONAL, "read password from stdin"); cmd_AddParm(ts, "-silent", CMD_FLAG, CMD_OPTIONAL, "silent operation"); /* Note: -lifetime is not implemented in this version of klog. */ cmd_AddParm(ts, "-lifetime", CMD_SINGLE, CMD_OPTIONAL, "ticket lifetime in hh[:mm[:ss]]"); cmd_AddParm(ts, "-setpag", CMD_FLAG, CMD_OPTIONAL, "Create a new setpag before authenticating"); cmd_AddParm(ts, "-tmp", CMD_FLAG, CMD_OPTIONAL, "write Kerberos-style ticket file in /tmp"); cmd_AddParm(ts, "-noprdb", CMD_FLAG, CMD_OPTIONAL, "don't consult pt"); cmd_AddParm(ts, "-unwrap", CMD_FLAG, CMD_OPTIONAL, "perform 524d conversion"); #ifdef AFS_RXK5 cmd_AddParm(ts, "-k5", CMD_FLAG, CMD_OPTIONAL, "get rxk5 credentials"); cmd_AddParm(ts, "-k4", CMD_FLAG, CMD_OPTIONAL, "get rxkad credentials"); #else ++ts->nParms; /* skip -k5 */ cmd_AddParm(ts, "-k4", CMD_FLAG, CMD_OPTIONAL|CMD_HIDDEN, 0); #endif code = cmd_Dispatch(argc, argv); KLOGEXIT(code); }