/** * The callout function that invokes the optionUsage function. * * @param[in] pOptions the AutoOpts option description structure * @param[in] pOptDesc the descriptor for the "help" (usage) option. * @noreturn */ static void doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) { optionUsage(&gnutls_cli_debugOptions, GNUTLS_CLI_DEBUG_EXIT_SUCCESS); /* NOTREACHED */ (void)pOptDesc; (void)pOptions; }
/** * The callout function that invokes the optionUsage function. * * @param pOptions the AutoOpts option description structure * @param pOptDesc the descriptor for the "help" (usage) option. * @noreturn */ static void doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) { optionUsage(&ocsptoolOptions, OCSPTOOL_EXIT_SUCCESS); /* NOTREACHED */ (void)pOptDesc; (void)pOptions; }
/** * The callout function that invokes the optionUsage function. * * @param pOptions the AutoOpts option description structure * @param pOptDesc the descriptor for the "help" (usage) option. * @noreturn */ static void doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) { optionUsage(&danetoolOptions, DANETOOL_EXIT_SUCCESS); /* NOTREACHED */ (void)pOptDesc; (void)pOptions; }
/** * The callout function that invokes the optionUsage function. * * @param[in] opts the AutoOpts option description structure * @param[in] od the descriptor for the "help" (usage) option. * @noreturn */ static void doUsageOpt(tOptions * opts, tOptDesc * od) { int ex_code; ex_code = NTPQ_EXIT_SUCCESS; optionUsage(&ntpqOptions, ex_code); /* NOTREACHED */ exit(1); (void)opts; (void)od; }
/** * The callout function that invokes the optionUsage function. * * @param[in] opts the AutoOpts option description structure * @param[in] od the descriptor for the "help" (usage) option. * @noreturn */ static void doUsageOpt(tOptions * opts, tOptDesc * od) { int ex_code; ex_code = TCPCAPINFO_EXIT_SUCCESS; optionUsage(&tcpcapinfoOptions, ex_code); /* NOTREACHED */ exit(1); (void)opts; (void)od; }
/* * getCmdOpts - get command line options */ void getCmdOpts( int argc, char *argv[] ) { extern const char *config_file; int errflg; tOptions *myOptions = &OPTSTRUCT; /* * Initialize, initialize */ errflg = 0; switch (WHICH_IDX_IPV4) { case INDEX_OPT_IPV4: default_ai_family = AF_INET; break; case INDEX_OPT_IPV6: default_ai_family = AF_INET6; break; default: /* ai_fam_templ = ai_fam_default; */ break; } if (HAVE_OPT( AUTHREQ )) proto_config(PROTO_AUTHENTICATE, 1, 0., NULL); if (HAVE_OPT( AUTHNOREQ )) proto_config(PROTO_AUTHENTICATE, 0, 0., NULL); if (HAVE_OPT( BCASTSYNC )) proto_config(PROTO_BROADCLIENT, 1, 0., NULL); if (HAVE_OPT( CONFIGFILE )) { config_file = OPT_ARG( CONFIGFILE ); #ifdef HAVE_NETINFO check_netinfo = 0; #endif } if (HAVE_OPT( DRIFTFILE )) stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE )); if (HAVE_OPT( PANICGATE )) allow_panic = TRUE; if (HAVE_OPT( JAILDIR )) { #ifdef HAVE_DROPROOT droproot = 1; chrootdir = OPT_ARG( JAILDIR ); #else fprintf(stderr, "command line -i option (jaildir) is not supported by this binary" # ifndef SYS_WINNT ",\n" "can not drop root privileges. See configure options\n" "--enable-clockctl and --enable-linuxcaps.\n"); # else ".\n"); # endif msyslog(LOG_ERR, "command line -i option (jaildir) is not supported by this binary."); errflg++; #endif } if (HAVE_OPT( KEYFILE )) getauthkeys(OPT_ARG( KEYFILE )); if (HAVE_OPT( PIDFILE )) stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE )); if (HAVE_OPT( QUIT )) mode_ntpdate = TRUE; if (HAVE_OPT( PROPAGATIONDELAY )) do { double tmp; const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY ); if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) { msyslog(LOG_ERR, "command line broadcast delay value %s undecodable", my_ntp_optarg); } else { proto_config(PROTO_BROADDELAY, 0, tmp, NULL); } } while (0); if (HAVE_OPT( STATSDIR )) stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR )); if (HAVE_OPT( TRUSTEDKEY )) { int ct = STACKCT_OPT( TRUSTEDKEY ); const char** pp = STACKLST_OPT( TRUSTEDKEY ); do { u_long tkey; const char* p = *pp++; tkey = (int)atol(p); if (tkey == 0 || tkey > NTP_MAXKEY) { msyslog(LOG_ERR, "command line trusted key %s is invalid", p); } else { authtrust(tkey, 1); } } while (--ct > 0); } if (HAVE_OPT( USER )) { #ifdef HAVE_DROPROOT char *ntp_optarg = OPT_ARG( USER ); droproot = 1; user = emalloc(strlen(ntp_optarg) + 1); (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1); group = rindex(user, ':'); if (group) *group++ = '\0'; /* get rid of the ':' */ #else fprintf(stderr, "command line -u/--user option is not supported by this binary" # ifndef SYS_WINNT ",\n" "can not drop root privileges. See configure options\n" "--enable-clockctl and --enable-linuxcaps.\n"); # else ".\n"); # endif msyslog(LOG_ERR, "command line -u/--user option is not supported by this binary."); errflg++; #endif } if (HAVE_OPT( VAR )) { int ct = STACKCT_OPT( VAR ); const char** pp = STACKLST_OPT( VAR ); do { const char* my_ntp_optarg = *pp++; set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1, (u_short) (RW)); } while (--ct > 0); } if (HAVE_OPT( DVAR )) { int ct = STACKCT_OPT( DVAR ); const char** pp = STACKLST_OPT( DVAR ); do { const char* my_ntp_optarg = *pp++; set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1, (u_short) (RW | DEF)); } while (--ct > 0); } if (HAVE_OPT( SLEW )) clock_max = 600; if (HAVE_OPT( UPDATEINTERVAL )) { long val = OPT_VALUE_UPDATEINTERVAL; if (val >= 0) interface_interval = val; else { fprintf(stderr, "command line interface update interval %ld must not be negative\n", val); msyslog(LOG_ERR, "command line interface update interval %ld must not be negative", val); errflg++; } } #ifdef SIM if (HAVE_OPT( SIMBROADCASTDELAY )) sscanf(OPT_ARG( SIMBROADCASTDELAY ), "%lf", &ntp_node.bdly); if (HAVE_OPT( PHASENOISE )) sscanf(OPT_ARG( PHASENOISE ), "%lf", &ntp_node.snse); if (HAVE_OPT( SIMSLEW )) sscanf(OPT_ARG( SIMSLEW ), "%lf", &ntp_node.slew); if (HAVE_OPT( SERVERTIME )) sscanf(OPT_ARG( SERVERTIME ), "%lf", &ntp_node.clk_time); if (HAVE_OPT( ENDSIMTIME )) sscanf(OPT_ARG( ENDSIMTIME ), "%lf", &ntp_node.sim_time); if (HAVE_OPT( FREQERR )) sscanf(OPT_ARG( FREQERR ), "%lf", &ntp_node.ferr); if (HAVE_OPT( WALKNOISE )) sscanf(OPT_ARG( WALKNOISE ), "%lf", &ntp_node.fnse); if (HAVE_OPT( NDELAY )) sscanf(OPT_ARG( NDELAY ), "%lf", &ntp_node.ndly); if (HAVE_OPT( PDELAY )) sscanf(OPT_ARG( PDELAY ), "%lf", &ntp_node.pdly); #endif /* SIM */ if (errflg || argc) { if (argc) fprintf(stderr, "argc after processing is <%d>\n", argc); optionUsage(myOptions, 2); } return; }
/*=export_func genshelloptUsage * private: * what: The usage function for the genshellopt generated program * * arg: + tOptions * + opts + program options descriptor + * arg: + int + exit_cd + usage text type to produce + * * doc: * This function is used to create the usage strings for the option * processing shell script code. Two child processes are spawned * each emitting the usage text in either the short (error exit) * style or the long style. The generated program will capture this * and create shell script variables containing the two types of text. =*/ void genshelloptUsage(tOptions * opts, int exit_cd) { #if ! defined(HAVE_WORKING_FORK) optionUsage(opts, exit_cd); #else /* * IF not EXIT_SUCCESS, * THEN emit the short form of usage. */ if (exit_cd != EXIT_SUCCESS) optionUsage(opts, exit_cd); fflush(stderr); fflush(stdout); if (ferror(stdout) || ferror(stderr)) option_exits(EXIT_FAILURE); option_usage_fp = stdout; /* * First, print our usage */ switch (fork()) { case -1: optionUsage(opts, EXIT_FAILURE); /* NOTREACHED */ case 0: pagerState = PAGER_STATE_CHILD; optionUsage(opts, EXIT_SUCCESS); /* NOTREACHED */ _exit(EXIT_FAILURE); default: { int sts; wait(&sts); } } /* * Generate the pzProgName, since optionProcess() normally * gets it from the command line */ { char * pz; char ** pp = VOIDP(&(optionParseShellOptions->pzProgName)); AGDUPSTR(pz, optionParseShellOptions->pzPROGNAME, "prog name"); *pp = pz; while (*pz != NUL) { *pz = (char)LOWER(*pz); pz++; } } /* * Separate the makeshell usage from the client usage */ fprintf(option_usage_fp, zGenshell, optionParseShellOptions->pzProgName); fflush(option_usage_fp); /* * Now, print the client usage. */ switch (fork()) { case 0: pagerState = PAGER_STATE_CHILD; /*FALLTHROUGH*/ case -1: optionUsage(optionParseShellOptions, EXIT_FAILURE); default: { int sts; wait(&sts); } } fflush(stdout); if (ferror(stdout)) fserr_exit(opts->pzProgName, zwriting, zstdout_name); option_exits(EXIT_SUCCESS); #endif }
/* * getCmdOpts - get command line options */ void getCmdOpts( int argc, char *argv[] ) { extern const char *config_file; int errflg; tOptions *myOptions = &ntpdOptions; /* * Initialize, initialize */ errflg = 0; if (HAVE_OPT( IPV4 )) default_ai_family = AF_INET; else if (HAVE_OPT( IPV6 )) default_ai_family = AF_INET6; if (HAVE_OPT( AUTHREQ )) proto_config(PROTO_AUTHENTICATE, 1, 0., NULL); else if (HAVE_OPT( AUTHNOREQ )) proto_config(PROTO_AUTHENTICATE, 0, 0., NULL); if (HAVE_OPT( BCASTSYNC )) proto_config(PROTO_BROADCLIENT, 1, 0., NULL); if (HAVE_OPT( CONFIGFILE )) { config_file = OPT_ARG( CONFIGFILE ); #ifdef HAVE_NETINFO check_netinfo = 0; #endif } if (HAVE_OPT( DRIFTFILE )) stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE )); if (HAVE_OPT( PANICGATE )) allow_panic = TRUE; #ifdef HAVE_DROPROOT if (HAVE_OPT( JAILDIR )) { droproot = 1; chrootdir = OPT_ARG( JAILDIR ); } #endif if (HAVE_OPT( KEYFILE )) getauthkeys(OPT_ARG( KEYFILE )); if (HAVE_OPT( PIDFILE )) stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE )); if (HAVE_OPT( QUIT )) mode_ntpdate = TRUE; if (HAVE_OPT( PROPAGATIONDELAY )) do { double tmp; const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY ); if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) { msyslog(LOG_ERR, "command line broadcast delay value %s undecodable", my_ntp_optarg); } else { proto_config(PROTO_BROADDELAY, 0, tmp, NULL); } } while (0); if (HAVE_OPT( STATSDIR )) stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR )); if (HAVE_OPT( TRUSTEDKEY )) { int ct = STACKCT_OPT( TRUSTEDKEY ); const char** pp = STACKLST_OPT( TRUSTEDKEY ); do { u_long tkey; const char* p = *pp++; tkey = (int)atol(p); if (tkey == 0 || tkey > NTP_MAXKEY) { msyslog(LOG_ERR, "command line trusted key %s is invalid", p); } else { authtrust(tkey, 1); } } while (--ct > 0); } #ifdef HAVE_DROPROOT if (HAVE_OPT( USER )) { droproot = 1; user = estrdup(OPT_ARG( USER )); group = rindex(user, ':'); if (group) *group++ = '\0'; /* get rid of the ':' */ } #endif if (HAVE_OPT( VAR )) { int ct = STACKCT_OPT( VAR ); const char** pp = STACKLST_OPT( VAR ); do { const char* my_ntp_optarg = *pp++; set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1, (u_short) (RW)); } while (--ct > 0); } if (HAVE_OPT( DVAR )) { int ct = STACKCT_OPT( DVAR ); const char** pp = STACKLST_OPT( DVAR ); do { const char* my_ntp_optarg = *pp++; set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1, (u_short) (RW | DEF)); } while (--ct > 0); } if (HAVE_OPT( SLEW )) { clock_max = 600; kern_enable = 0; } if (HAVE_OPT( UPDATEINTERVAL )) { long val = OPT_VALUE_UPDATEINTERVAL; if (val >= 0) interface_interval = val; else { fprintf(stderr, "command line interface update interval %ld must not be negative\n", val); msyslog(LOG_ERR, "command line interface update interval %ld must not be negative", val); errflg++; } } #ifdef SIM /* SK: * The simulator no longer takes any command line arguments. Hence, * all the code that was here has been removed. */ #endif /* SIM */ if (errflg || argc) { if (argc) fprintf(stderr, "argc after processing is <%d>\n", argc); optionUsage(myOptions, 2); } return; }
/*=export_func genshelloptUsage * private: * what: The usage function for the genshellopt generated program * * arg: + tOptions* + pOpts + program options descriptor + * arg: + int + exitCode + usage text type to produce + * * doc: * This function is used to create the usage strings for the option * processing shell script code. Two child processes are spawned * each emitting the usage text in either the short (error exit) * style or the long style. The generated program will capture this * and create shell script variables containing the two types of text. =*/ void genshelloptUsage( tOptions* pOpts, int exitCode ) { #if ! defined(HAVE_WORKING_FORK) optionUsage( pOpts, exitCode ); #else /* * IF not EXIT_SUCCESS, * THEN emit the short form of usage. */ if (exitCode != EXIT_SUCCESS) optionUsage( pOpts, exitCode ); fflush( stderr ); fflush( stdout ); option_usage_fp = stdout; /* * First, print our usage */ switch (fork()) { case -1: optionUsage( pOpts, EXIT_FAILURE ); /* NOTREACHED */ _exit( EXIT_FAILURE ); case 0: pagerState = PAGER_STATE_CHILD; optionUsage( pOpts, EXIT_SUCCESS ); /* NOTREACHED */ _exit( EXIT_FAILURE ); default: { int sts; wait( &sts ); } } /* * Generate the pzProgName, since optionProcess() normally * gets it from the command line */ { char* pz; AGDUPSTR( pz, pShellParseOptions->pzPROGNAME, "program name" ); pShellParseOptions->pzProgName = pz; while (*pz != NUL) { *pz = tolower( *pz ); pz++; } } /* * Separate the makeshell usage from the client usage */ fprintf( option_usage_fp, zGenshell, pShellParseOptions->pzProgName ); fflush( option_usage_fp ); /* * Now, print the client usage. */ switch (fork()) { case 0: pagerState = PAGER_STATE_CHILD; /*FALLTHROUGH*/ case -1: optionUsage( pShellParseOptions, EXIT_FAILURE ); default: { int sts; wait( &sts ); } } exit( EXIT_SUCCESS ); #endif }
/** * The callout function that invokes the optionUsage() function, but first * makes sure "endwin()" gets called. * * @param opts the AutoOpts option description structure * @param ex the program exit code. */ void pcopy_usage(tOptions * opts, int ex) { if (curses_active) endwin(); optionUsage(opts, ex); }
/* * getCmdOpts - apply most command line options * * A few options are examined earlier in ntpd.c ntpdmain() and * ports/winnt/ntpd/ntservice.c main(). */ void getCmdOpts( int argc, char ** argv ) { extern const char *config_file; int errflg; /* * Initialize, initialize */ errflg = 0; if (ipv4_works && ipv6_works) { if (HAVE_OPT( IPV4 )) ipv6_works = 0; else if (HAVE_OPT( IPV6 )) ipv4_works = 0; } else if (!ipv4_works && !ipv6_works) { msyslog(LOG_ERR, "Neither IPv4 nor IPv6 networking detected, fatal."); exit(1); } else if (HAVE_OPT( IPV4 ) && !ipv4_works) msyslog(LOG_WARNING, "-4/--ipv4 ignored, IPv4 networking not found."); else if (HAVE_OPT( IPV6 ) && !ipv6_works) msyslog(LOG_WARNING, "-6/--ipv6 ignored, IPv6 networking not found."); if (HAVE_OPT( AUTHREQ )) proto_config(PROTO_AUTHENTICATE, 1, 0., NULL); else if (HAVE_OPT( AUTHNOREQ )) proto_config(PROTO_AUTHENTICATE, 0, 0., NULL); if (HAVE_OPT( BCASTSYNC )) proto_config(PROTO_BROADCLIENT, 1, 0., NULL); if (HAVE_OPT( CONFIGFILE )) { config_file = OPT_ARG( CONFIGFILE ); #ifdef HAVE_NETINFO check_netinfo = 0; #endif } if (HAVE_OPT( DRIFTFILE )) stats_config(STATS_FREQ_FILE, OPT_ARG( DRIFTFILE )); if (HAVE_OPT( PANICGATE )) allow_panic = TRUE; if (HAVE_OPT( FORCE_STEP_ONCE )) force_step_once = TRUE; #ifdef HAVE_DROPROOT if (HAVE_OPT( JAILDIR )) { droproot = 1; chrootdir = OPT_ARG( JAILDIR ); } #endif if (HAVE_OPT( KEYFILE )) getauthkeys(OPT_ARG( KEYFILE )); if (HAVE_OPT( PIDFILE )) stats_config(STATS_PID_FILE, OPT_ARG( PIDFILE )); if (HAVE_OPT( QUIT )) mode_ntpdate = TRUE; if (HAVE_OPT( PROPAGATIONDELAY )) do { double tmp; const char *my_ntp_optarg = OPT_ARG( PROPAGATIONDELAY ); if (sscanf(my_ntp_optarg, "%lf", &tmp) != 1) { msyslog(LOG_ERR, "command line broadcast delay value %s undecodable", my_ntp_optarg); } else { proto_config(PROTO_BROADDELAY, 0, tmp, NULL); } } while (0); if (HAVE_OPT( STATSDIR )) stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR )); if (HAVE_OPT( TRUSTEDKEY )) { int ct = STACKCT_OPT( TRUSTEDKEY ); const char** pp = STACKLST_OPT( TRUSTEDKEY ); do { u_long tkey; const char* p = *pp++; tkey = (int)atol(p); if (tkey == 0 || tkey > NTP_MAXKEY) { msyslog(LOG_ERR, "command line trusted key %s is invalid", p); } else { authtrust(tkey, 1); } } while (--ct > 0); } #ifdef HAVE_DROPROOT if (HAVE_OPT( USER )) { droproot = 1; user = estrdup(OPT_ARG( USER )); group = strrchr(user, ':'); if (group != NULL) { size_t len; *group++ = '\0'; /* get rid of the ':' */ len = group - user; group = estrdup(group); user = erealloc(user, len); } } #endif if (HAVE_OPT( VAR )) { int ct; const char ** pp; const char * v_assign; ct = STACKCT_OPT( VAR ); pp = STACKLST_OPT( VAR ); do { v_assign = *pp++; set_sys_var(v_assign, strlen(v_assign) + 1, RW); } while (--ct > 0); } if (HAVE_OPT( DVAR )) { int ct = STACKCT_OPT( DVAR ); const char** pp = STACKLST_OPT( DVAR ); do { const char* my_ntp_optarg = *pp++; set_sys_var(my_ntp_optarg, strlen(my_ntp_optarg)+1, (u_short) (RW | DEF)); } while (--ct > 0); } if (HAVE_OPT( SLEW )) loop_config(LOOP_MAX, 600); if (HAVE_OPT( UPDATEINTERVAL )) { long val = OPT_VALUE_UPDATEINTERVAL; if (val >= 0) interface_interval = val; else { fprintf(stderr, "command line interface update interval %ld must not be negative\n", val); msyslog(LOG_ERR, "command line interface update interval %ld must not be negative", val); errflg++; } } /* save list of servers from cmd line for config_peers() use */ if (argc > 0) { cmdline_server_count = argc; cmdline_servers = argv; } /* display usage & exit with any option processing errors */ if (errflg) optionUsage(&ntpdOptions, 2); /* does not return */ }