/** * volinfo program entry */ int main(int argc, char **argv) { afs_int32 code; struct cmd_syndesc *ts; ts = cmd_CreateSyntax(NULL, VolInfo, NULL, 0, "Dump volume's internal state"); cmd_AddParmAtOffset(ts, P_CHECKOUT, "-checkout", CMD_FLAG, CMD_OPTIONAL, "Checkout volumes from running fileserver"); cmd_AddParmAtOffset(ts, P_VNODE, "-vnode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode info"); cmd_AddParmAtOffset(ts, P_DATE, "-date", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's mod date"); cmd_AddParmAtOffset(ts, P_INODE, "-inode", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's inode number"); cmd_AddParmAtOffset(ts, P_ITIME, "-itime", CMD_FLAG, CMD_OPTIONAL, "Dump special inode's mod times"); cmd_AddParmAtOffset(ts, P_PART, "-part", CMD_LIST, CMD_OPTIONAL, "AFS partition name or id (default current partition)"); cmd_AddParmAtOffset(ts, P_VOLUMEID, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id"); cmd_AddParmAtOffset(ts, P_HEADER, "-header", CMD_FLAG, CMD_OPTIONAL, "Dump volume's header info"); cmd_AddParmAtOffset(ts, P_SIZEONLY, "-sizeonly", CMD_FLAG, CMD_OPTIONAL, "Dump volume's size"); cmd_AddParmAtOffset(ts, P_FIXHEADER, "-fixheader", CMD_FLAG, CMD_OPTIONAL, "Try to fix header"); cmd_AddParmAtOffset(ts, P_SAVEINODES, "-saveinodes", CMD_FLAG, CMD_OPTIONAL, "Try to save all inodes"); cmd_AddParmAtOffset(ts, P_ORPHANED, "-orphaned", CMD_FLAG, CMD_OPTIONAL, "List all dir/files without a parent"); #if defined(AFS_NAMEI_ENV) cmd_AddParmAtOffset(ts, P_FILENAMES, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's namei filename"); #endif /* For compatibility with older versions. */ cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly"); code = cmd_Dispatch(argc, argv); return code; }
int main(int argc, char **argv) { afs_int32 code; afs_uint32 myHost; struct rx_service *tservice; struct rx_securityClass **securityClasses; afs_int32 numClasses; struct afsconf_dir *tdir; struct ktc_encryptionKey tkey; struct afsconf_cell info; struct hostent *th; char hostname[VL_MAXNAMELEN]; int noAuth = 0; char clones[MAXHOSTSPERCELL]; afs_uint32 host = ntohl(INADDR_ANY); struct cmd_syndesc *opts; char *vl_dbaseName; char *configDir; char *logFile; char *auditFileName = NULL; char *interface = NULL; char *optstring = NULL; #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; rx_extraPackets = 100; /* should be a switch, I guess... */ sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGABRT, &nsa, NULL); sigaction(SIGSEGV, &nsa, NULL); #endif osi_audit_init(); /* Initialize dirpaths */ 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); } vl_dbaseName = strdup(AFSDIR_SERVER_VLDB_FILEPATH); configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH); logFile = strdup(AFSDIR_SERVER_VLOG_FILEPATH); cmd_DisableAbbreviations(); cmd_DisablePositionalCommands(); opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL); /* vlserver specific options */ cmd_AddParmAtOffset(opts, OPT_noauth, "-noauth", CMD_FLAG, CMD_OPTIONAL, "disable authentication"); cmd_AddParmAtOffset(opts, OPT_smallmem, "-smallmem", CMD_FLAG, CMD_OPTIONAL, "optimise for small memory systems"); /* general server options */ cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE, CMD_OPTIONAL, "location of audit log"); cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging"); cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL, "configuration location"); cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL, "debug level"); cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE, CMD_OPTIONAL, "database file"); cmd_AddParmAlias(opts, OPT_database, "-db"); cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE, CMD_OPTIONAL, "location of logfile"); cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL, "number of threads"); #if !defined(AFS_NT40_ENV) cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG, CMD_OPTIONAL, "log to syslog"); #endif /* rx options */ cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX transport statistics"); cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX RPC statistics"); cmd_AddParmAtOffset(opts, OPT_nojumbo, "-nojumbo", CMD_FLAG, CMD_OPTIONAL, "disable jumbograms"); cmd_AddParmAtOffset(opts, OPT_jumbo, "-jumbo", CMD_FLAG, CMD_OPTIONAL, "enable jumbograms"); cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL, "bind only to the primary interface"); cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "maximum MTU for RX"); cmd_AddParmAtOffset(opts, OPT_trace, "-trace", CMD_SINGLE, CMD_OPTIONAL, "rx trace file"); /* rxkad options */ cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL, "permit Kerberos 5 principals with dots"); code = cmd_Parse(argc, argv, &opts); if (code) return -1; cmd_OptionAsString(opts, OPT_config, &configDir); cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH); cmd_SetCommandName("vlserver"); /* vlserver options */ cmd_OptionAsFlag(opts, OPT_noauth, &noAuth); cmd_OptionAsFlag(opts, OPT_smallmem, &smallMem); if (cmd_OptionAsString(opts, OPT_trace, &optstring) == 0) { extern char rxi_tracename[80]; strcpy(rxi_tracename, optstring); free(optstring); optstring = NULL; } /* general server options */ cmd_OptionAsString(opts, OPT_auditlog, &auditFileName); if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) { if (osi_audit_interface(interface)) { printf("Invalid audit interface '%s'\n", interface); return -1; } free(interface); } cmd_OptionAsInt(opts, OPT_debug, &LogLevel); cmd_OptionAsString(opts, OPT_database, &vl_dbaseName); cmd_OptionAsString(opts, OPT_logfile, &logFile); if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) { if (lwps > MAXLWP) { printf("Warning: '-p %d' is too big; using %d instead\n", lwps, MAXLWP); lwps = MAXLWP; } } #ifndef AFS_NT40_ENV if (cmd_OptionPresent(opts, OPT_syslog)) { serverLogSyslog = 1; cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility); } #endif /* rx options */ if (cmd_OptionPresent(opts, OPT_peer)) rx_enablePeerRPCStats(); if (cmd_OptionPresent(opts, OPT_process)) rx_enableProcessRPCStats(); if (cmd_OptionPresent(opts, OPT_nojumbo)) rxJumbograms = 0; if (cmd_OptionPresent(opts, OPT_jumbo)) rxJumbograms = 1; cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind); cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU); /* rxkad options */ cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck); if (auditFileName) { osi_audit_file(auditFileName); } #ifndef AFS_NT40_ENV serverLogSyslogTag = "vlserver"; #endif OpenLog(logFile); /* set up logging */ SetupLogSignals(); tdir = afsconf_Open(configDir); if (!tdir) { VLog(0, ("vlserver: can't open configuration files in dir %s, giving up.\n", configDir)); exit(1); } /* initialize audit user check */ osi_audit_set_user_check(tdir, vldb_IsLocalRealmMatch); #ifdef AFS_NT40_ENV /* initialize winsock */ if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); VLog(0, ("vlserver: couldn't initialize winsock. \n")); exit(1); } #endif /* get this host */ gethostname(hostname, sizeof(hostname)); th = gethostbyname(hostname); if (!th) { VLog(0, ("vlserver: couldn't get address of this host (%s).\n", hostname)); exit(1); } memcpy(&myHost, th->h_addr, sizeof(afs_uint32)); #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) signal(SIGXCPU, CheckSignal_Signal); #endif /* get list of servers */ code = afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info, clones); if (code) { printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n"); exit(2); } vldb_confdir = tdir; /* Preserve our configuration dir */ /* rxvab no longer supported */ memset(&tkey, 0, sizeof(tkey)); if (noAuth) afsconf_SetNoAuthFlag(tdir, 1); if (rxBind) { afs_int32 ccode; #ifndef AFS_NT40_ENV if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL, ADDRSPERSITE, reason, AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else #endif { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } if (ccode == 1) { host = SHostAddrs[0]; rx_InitHost(host, htons(AFSCONF_VLDBPORT)); } } if (!rxJumbograms) { rx_SetNoJumbo(); } if (rxMaxMTU != -1) { if (rx_SetMaxMTU(rxMaxMTU) != 0) { VLog(0, ("rxMaxMTU %d invalid\n", rxMaxMTU)); return -1; } } ubik_nBuffers = 512; ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir); ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects, afsconf_CheckAuth, tdir); ubik_SyncWriterCacheProc = vlsynccache; code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones, vl_dbaseName, &VL_dbase); if (code) { VLog(0, ("vlserver: Ubik init failed: %s\n", afs_error_message(code))); exit(2); } rx_SetRxDeadTime(50); memset(rd_HostAddress, 0, sizeof(rd_HostAddress)); memset(wr_HostAddress, 0, sizeof(wr_HostAddress)); initialize_dstats(); afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses); tservice = rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", securityClasses, numClasses, VL_ExecuteRequest); if (tservice == (struct rx_service *)0) { VLog(0, ("vlserver: Could not create VLDB_SERVICE rx service\n")); exit(3); } rx_SetMinProcs(tservice, 2); if (lwps < 4) lwps = 4; rx_SetMaxProcs(tservice, lwps); if (rxkadDisableDotCheck) { rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS, (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK); } tservice = rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses, numClasses, RXSTATS_ExecuteRequest); if (tservice == (struct rx_service *)0) { VLog(0, ("vlserver: Could not create rpc stats rx service\n")); exit(3); } rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, 4); LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog); VLog(0, ("%s\n", cml_version_number)); /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(vldb_rxstat_userok); rx_StartServer(1); /* Why waste this idle process?? */ return 0; /* not reachable */ }
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) { afs_int32 code; afs_uint32 myHost; struct hostent *th; char hostname[64]; struct rx_service *tservice; struct rx_securityClass **securityClasses; afs_int32 numClasses; int lwps = 3; char clones[MAXHOSTSPERCELL]; afs_uint32 host = htonl(INADDR_ANY); struct cmd_syndesc *opts; struct cmd_item *list; char *pr_dbaseName; char *configDir; char *logFile; char *whoami = "ptserver"; char *auditFileName = NULL; char *interface = NULL; #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 osi_audit_init(); osi_audit(PTS_StartEvent, 0, AUD_END); /* Initialize dirpaths */ 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); } pr_dbaseName = strdup(AFSDIR_SERVER_PRDB_FILEPATH); configDir = strdup(AFSDIR_SERVER_ETC_DIRPATH); logFile = strdup(AFSDIR_SERVER_PTLOG_FILEPATH); #if defined(SUPERGROUPS) /* make sure the structures for database records are the same size */ if ((sizeof(struct prentry) != ENTRYSIZE) || (sizeof(struct prentryg) != ENTRYSIZE)) { fprintf(stderr, "The structures for the database records are different" " sizes\n" "struct prentry = %" AFS_SIZET_FMT "\n" "struct prentryg = %" AFS_SIZET_FMT "\n" "ENTRYSIZE = %d\n", sizeof(struct prentry), sizeof(struct prentryg), ENTRYSIZE); PT_EXIT(1); } #endif cmd_DisableAbbreviations(); cmd_DisablePositionalCommands(); opts = cmd_CreateSyntax(NULL, NULL, NULL, NULL); /* ptserver specific options */ cmd_AddParmAtOffset(opts, OPT_database, "-database", CMD_SINGLE, CMD_OPTIONAL, "database file"); cmd_AddParmAlias(opts, OPT_database, "db"); cmd_AddParmAtOffset(opts, OPT_access, "-default_access", CMD_SINGLE, CMD_OPTIONAL, "default access flags for new entries"); #if defined(SUPERGROUPS) cmd_AddParmAtOffset(opts, OPT_groupdepth, "-groupdepth", CMD_SINGLE, CMD_OPTIONAL, "max search depth for supergroups"); cmd_AddParmAlias(opts, OPT_groupdepth, "depth"); #endif cmd_AddParmAtOffset(opts, OPT_restricted, "-restricted", CMD_FLAG, CMD_OPTIONAL, "enable restricted mode"); /* general server options */ cmd_AddParmAtOffset(opts, OPT_auditlog, "-auditlog", CMD_SINGLE, CMD_OPTIONAL, "location of audit log"); cmd_AddParmAtOffset(opts, OPT_auditiface, "-audit-interface", CMD_SINGLE, CMD_OPTIONAL, "interface to use for audit logging"); cmd_AddParmAtOffset(opts, OPT_config, "-config", CMD_SINGLE, CMD_OPTIONAL, "configuration location"); cmd_AddParmAtOffset(opts, OPT_debug, "-d", CMD_SINGLE, CMD_OPTIONAL, "debug level"); cmd_AddParmAtOffset(opts, OPT_logfile, "-logfile", CMD_SINGLE, CMD_OPTIONAL, "location of logfile"); cmd_AddParmAtOffset(opts, OPT_threads, "-p", CMD_SINGLE, CMD_OPTIONAL, "number of threads"); #if !defined(AFS_NT40_ENV) cmd_AddParmAtOffset(opts, OPT_syslog, "-syslog", CMD_SINGLE_OR_FLAG, CMD_OPTIONAL, "log to syslog"); #endif /* rx options */ cmd_AddParmAtOffset(opts, OPT_peer, "-enable_peer_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX transport statistics"); cmd_AddParmAtOffset(opts, OPT_process, "-enable_process_stats", CMD_FLAG, CMD_OPTIONAL, "enable RX RPC statistics"); cmd_AddParmAtOffset(opts, OPT_rxbind, "-rxbind", CMD_FLAG, CMD_OPTIONAL, "bind only to the primary interface"); cmd_AddParmAtOffset(opts, OPT_rxmaxmtu, "-rxmaxmtu", CMD_SINGLE, CMD_OPTIONAL, "maximum MTU for RX"); /* rxkad options */ cmd_AddParmAtOffset(opts, OPT_dotted, "-allow-dotted-principals", CMD_FLAG, CMD_OPTIONAL, "permit Kerberos 5 principals with dots"); code = cmd_Parse(argc, argv, &opts); if (code) PT_EXIT(1); cmd_OptionAsString(opts, OPT_config, &configDir); cmd_OpenConfigFile(AFSDIR_SERVER_CONFIG_FILE_FILEPATH); cmd_SetCommandName("ptserver"); if (cmd_OptionAsList(opts, OPT_access, &list) == 0) { prp_user_default = prp_access_mask(list->data); if (list->next == NULL || list->next->data == NULL) { fprintf(stderr, "Missing second argument for -default_access\n"); PT_EXIT(1); } prp_group_default = prp_access_mask(list->next->data); } #if defined(SUPERGROUPS) cmd_OptionAsInt(opts, OPT_groupdepth, &depthsg); #endif cmd_OptionAsFlag(opts, OPT_restricted, &restricted); /* general server options */ cmd_OptionAsString(opts, OPT_auditlog, &auditFileName); if (cmd_OptionAsString(opts, OPT_auditiface, &interface) == 0) { if (osi_audit_interface(interface)) { printf("Invalid audit interface '%s'\n", interface); PT_EXIT(1); } free(interface); } cmd_OptionAsInt(opts, OPT_debug, &LogLevel); cmd_OptionAsString(opts, OPT_database, &pr_dbaseName); cmd_OptionAsString(opts, OPT_logfile, &logFile); if (cmd_OptionAsInt(opts, OPT_threads, &lwps) == 0) { if (lwps > 64) { /* maximum of 64 */ printf("Warning: '-p %d' is too big; using %d instead\n", lwps, 64); lwps = 64; } else if (lwps < 3) { /* minimum of 3 */ printf("Warning: '-p %d' is too small; using %d instead\n", lwps, 3); lwps = 3; } } #ifndef AFS_NT40_ENV if (cmd_OptionPresent(opts, OPT_syslog)) { serverLogSyslog = 1; cmd_OptionAsInt(opts, OPT_syslog, &serverLogSyslogFacility); } #endif /* rx options */ if (cmd_OptionPresent(opts, OPT_peer)) rx_enablePeerRPCStats(); if (cmd_OptionPresent(opts, OPT_process)) rx_enableProcessRPCStats(); cmd_OptionAsFlag(opts, OPT_rxbind, &rxBind); cmd_OptionAsInt(opts, OPT_rxmaxmtu, &rxMaxMTU); /* rxkad options */ cmd_OptionAsFlag(opts, OPT_dotted, &rxkadDisableDotCheck); cmd_FreeOptions(&opts); if (auditFileName) { osi_audit_file(auditFileName); osi_audit(PTS_StartEvent, 0, AUD_END); } #ifndef AFS_NT40_ENV serverLogSyslogTag = "ptserver"; #endif OpenLog(logFile); /* set up logging */ SetupLogSignals(); prdir = afsconf_Open(configDir); if (!prdir) { fprintf(stderr, "ptserver: can't open configuration directory.\n"); PT_EXIT(1); } if (afsconf_GetNoAuthFlag(prdir)) printf("ptserver: running unauthenticated\n"); #ifdef AFS_NT40_ENV /* initialize winsock */ if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); fprintf(stderr, "ptserver: couldn't initialize winsock. \n"); PT_EXIT(1); } #endif /* get this host */ gethostname(hostname, sizeof(hostname)); th = gethostbyname(hostname); if (!th) { fprintf(stderr, "ptserver: couldn't get address of this host.\n"); PT_EXIT(1); } memcpy(&myHost, th->h_addr, sizeof(afs_uint32)); /* get list of servers */ code = afsconf_GetExtendedCellInfo(prdir, NULL, "afsprot", &info, clones); if (code) { afs_com_err(whoami, code, "Couldn't get server list"); PT_EXIT(2); } /* initialize audit user check */ osi_audit_set_user_check(prdir, pr_IsLocalRealmMatch); /* initialize ubik */ ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, prdir); ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects, afsconf_CheckAuth, prdir); /* The max needed is when deleting an entry. A full CoEntry deletion * required removal from 39 entries. Each of which may refers to the entry * being deleted in one of its CoEntries. If a CoEntry is freed its * predecessor CoEntry will be modified as well. Any freed blocks also * modifies the database header. Counting the entry being deleted and its * CoEntry this adds up to as much as 1+1+39*3 = 119. If all these entries * and the header are in separate Ubik buffers then 120 buffers may be * required. */ ubik_nBuffers = 120 + /*fudge */ 40; if (rxBind) { afs_int32 ccode; if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL, ADDRSPERSITE, reason, AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } if (ccode == 1) { host = SHostAddrs[0]; /* the following call is idempotent so if/when it gets called * again by the ubik init stuff, it doesn't really matter * -- klm */ rx_InitHost(host, htons(AFSCONF_PROTPORT)); } } /* Disable jumbograms */ rx_SetNoJumbo(); if (rxMaxMTU != -1) { if (rx_SetMaxMTU(rxMaxMTU) != 0) { printf("rxMaxMTU %d is invalid\n", rxMaxMTU); PT_EXIT(1); } } code = ubik_ServerInitByInfo(myHost, htons(AFSCONF_PROTPORT), &info, clones, pr_dbaseName, &dbase); if (code) { afs_com_err(whoami, code, "Ubik init failed"); PT_EXIT(2); } #if defined(SUPERGROUPS) pt_hook_write(); #endif afsconf_BuildServerSecurityObjects(prdir, &securityClasses, &numClasses); tservice = rx_NewServiceHost(host, 0, PRSRV, "Protection Server", securityClasses, numClasses, PR_ExecuteRequest); if (tservice == (struct rx_service *)0) { fprintf(stderr, "ptserver: Could not create new rx service.\n"); PT_EXIT(3); } rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, lwps); if (rxkadDisableDotCheck) { rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS, (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK); } tservice = rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", securityClasses, numClasses, RXSTATS_ExecuteRequest); if (tservice == (struct rx_service *)0) { fprintf(stderr, "ptserver: Could not create new rx service.\n"); PT_EXIT(3); } rx_SetMinProcs(tservice, 2); rx_SetMaxProcs(tservice, 4); /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(pr_rxstat_userok); LogCommandLine(argc, argv, "ptserver", #if defined(SUPERGROUPS) "1.1", #else "1.0", #endif "Starting AFS", FSLog); rx_StartServer(1); osi_audit(PTS_FinishEvent, -1, AUD_END); exit(0); }