int main(int argc, char *argv[]) { int optct, rcode; init(); /* call autoopts to process arguments */ optct = optionProcess(&tcpbridgeOptions, argc, argv); argc -= optct; argv += optct; post_args(argc, argv); /* init tcpedit context */ if (tcpedit_init(&tcpedit, pcap_datalink(options.pcap1)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(&tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } #ifdef ENABLE_VERBOSE if (options.verbose) { options.tcpdump = (tcpdump_t*)safe_malloc(sizeof(tcpdump_t)); tcpdump_open(options.tcpdump, options.pcap1); } #endif if (gettimeofday(&begin, NULL) < 0) err(-1, "gettimeofday() failed"); /* process packets */ do_bridge(&options, tcpedit); /* clean up after ourselves */ pcap_close(options.pcap1); if (options.unidir) { pcap_close(options.pcap2); } #ifdef ENABLE_VERBOSE tcpdump_close(options.tcpdump); #endif return 0; }
static void cmd_parser(int argc, char **argv) { const char *rest = NULL; int optct = optionProcess(&gnutls_cli_debugOptions, argc, argv); argc -= optct; argv += optct; if (rest == NULL && argc > 0) rest = argv[0]; if (HAVE_OPT(PORT)) port = OPT_VALUE_PORT; else { if (HAVE_OPT(STARTTLS_PROTO)) port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO)); else port = 443; } if (rest == NULL) hostname = "localhost"; else hostname = rest; if (HAVE_OPT(DEBUG)) debug = OPT_VALUE_DEBUG; if (HAVE_OPT(VERBOSE)) verbose++; }
/* * ntpOptionProcess() was a clone of libopts' optionProcess which * overrode the --version output, appending detail from version.c * which was not available at Autogen time. This is now done via * AutoOpts' version-proc = override in copyright.def, so this * routine is a straightforward wrapper of optionProcess(). */ int ntpOptionProcess( tOptions * pOpts, int argc, char ** argv ) { return optionProcess(pOpts, argc, argv); }
/** * Generated main procedure. This will emit text that a Bourne shell can * process to handle its command line arguments. * * @param[in] argc argument count * @param[in] argv argument vector * @returns program exit code */ int main(int argc, char ** argv) { int res = NTPQ_EXIT_SUCCESS; (void)optionProcess(&ntpqOptions, argc, argv); optionPutShell(&ntpqOptions); res = ferror(stdout); if (res != 0) fputs("output error writing to stdout\n", stderr); return res; }
int main(int argc, char **argv) { int ret; if ((ret = gnutls_global_init()) < 0) { fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret)); exit(1); } optionProcess(&ocsptoolOptions, argc, argv); gnutls_global_set_log_function(tls_log_func); gnutls_global_set_log_level(OPT_VALUE_DEBUG); if (HAVE_OPT(OUTFILE)) { outfile = fopen(OPT_ARG(OUTFILE), "wb"); if (outfile == NULL) { fprintf(stderr, "%s\n", OPT_ARG(OUTFILE)); exit(1); } } else outfile = stdout; if (HAVE_OPT(INFILE)) { infile = fopen(OPT_ARG(INFILE), "rb"); if (infile == NULL) { fprintf(stderr, "%s\n", OPT_ARG(INFILE)); exit(1); } } else infile = stdin; if (ENABLED_OPT(INDER)) encoding = GNUTLS_X509_FMT_DER; else encoding = GNUTLS_X509_FMT_PEM; if (HAVE_OPT(REQUEST_INFO)) request_info(); else if (HAVE_OPT(RESPONSE_INFO)) response_info(); else if (HAVE_OPT(GENERATE_REQUEST)) generate_request(NULL); else if (HAVE_OPT(VERIFY_RESPONSE)) verify_response(NULL); else if (HAVE_OPT(ASK)) ask_server(OPT_ARG(ASK)); else { USAGE(1); } return 0; }
static void process_commandline_opts( int *pargc, char ***pargv ) { int optct; optct = optionProcess(&ntpdOptions, *pargc, *pargv); *pargc -= optct; *pargv += optct; }
int main (int argc, char *argv[]) { int arg_ct; time_t arg; int c, idx=0; char number[40]; arg_ct = optionProcess( &progOptions, argc, argv ); argc -= arg_ct; argv += arg_ct; if (argc > 0) { arg = atoi(*argv); printf("%s", ctime(&arg)); exit(0); } memset(number, 0, sizeof(number)); while ((c = getc(stdin)) != EOF) { if (!isdigit(c)) { if (idx) { fputs(number, stdout); memset(number, 0, sizeof(number)); idx = 0; } putc(c, stdout); continue; } number[idx++] = c; if (atoi(number) > 1262300400) { // Jan 1st 2010 fputs(number, stdout); memset(number, 0, sizeof(number)); idx = 0; continue; } if (atoi(number) < 1009839600) { continue; } fputs(number, stdout); arg = atoi(number); sprintf(number, "%s", ctime(&arg)); number[strlen(number)-1] = 0; putc('(', stdout); fputs(number, stdout); putc(')', stdout); memset(number, 0, sizeof(number)); idx = 0; } return 0; }
void ActivateOption(const char* option, const char* argument) { const int ARGV_SIZE = 4; char* opts[ARGV_SIZE]; opts[0] = estrdup("sntpopts"); opts[1] = estrdup(option); opts[2] = estrdup(argument); opts[3] = estrdup("127.0.0.1"); optionProcess(&sntpOptions, ARGV_SIZE, opts); }
int main(int argc, char *argv[]) { int optct, rcode; pcap_t *dlt_pcap; #ifdef ENABLE_FRAGROUTE char ebuf[FRAGROUTE_ERRBUF_LEN]; #endif tcprewrite_init(); /* call autoopts to process arguments */ optct = optionProcess(&tcprewriteOptions, argc, argv); argc -= optct; argv += optct; /* parse the tcprewrite args */ post_args(argc, argv); /* init tcpedit context */ if (tcpedit_init(&tcpedit, pcap_datalink(options.pin)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(&tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } /* open up the output file */ options.outfile = safe_strdup(OPT_ARG(OUTFILE)); dbgx(1, "Rewriting DLT to %s", pcap_datalink_val_to_name(tcpedit_get_output_dlt(tcpedit))); if ((dlt_pcap = pcap_open_dead(tcpedit_get_output_dlt(tcpedit), 65535)) == NULL) err(-1, "Unable to open dead pcap handle."); dbgx(1, "DLT of dlt_pcap is %s", pcap_datalink_val_to_name(pcap_datalink(dlt_pcap))); #ifdef ENABLE_FRAGROUTE if (options.fragroute_args) { if ((options.frag_ctx = fragroute_init(65535, pcap_datalink(dlt_pcap), options.fragroute_args, ebuf)) == NULL) errx(-1, "%s", ebuf); } #endif #ifdef ENABLE_VERBOSE if (options.verbose) { tcpdump_open(&tcpdump, dlt_pcap); } #endif if ((options.pout = pcap_dump_open(dlt_pcap, options.outfile)) == NULL) errx(-1, "Unable to open output pcap file: %s", pcap_geterr(dlt_pcap)); pcap_close(dlt_pcap); /* rewrite packets */ if (rewrite_packets(tcpedit, options.pin, options.pout) != 0) errx(-1, "Error rewriting packets: %s", tcpedit_geterr(tcpedit)); /* clean up after ourselves */ pcap_dump_close(options.pout); pcap_close(options.pin); #ifdef ENABLE_VERBOSE tcpdump_close(&tcpdump); #endif #ifdef ENABLE_DMALLOC dmalloc_shutdown(); #endif return 0; }
static void cmd_parser(int argc, char **argv) { int ret, privkey_op = 0; common_info_st cinfo; const char *proto = "tcp"; unsigned int port = 443; optionProcess(&danetoolOptions, argc, argv); if (HAVE_OPT(OUTFILE)) { outfile = safe_open_rw(OPT_ARG(OUTFILE), privkey_op); if (outfile == NULL) { fprintf(stderr, "%s", OPT_ARG(OUTFILE)); exit(1); } } else outfile = stdout; default_dig = GNUTLS_DIG_UNKNOWN; if (HAVE_OPT(HASH)) { if (strcasecmp(OPT_ARG(HASH), "md5") == 0) { fprintf(stderr, "Warning: MD5 is broken, and should not be used any more for digital signatures.\n"); default_dig = GNUTLS_DIG_MD5; } else if (strcasecmp(OPT_ARG(HASH), "sha1") == 0) default_dig = GNUTLS_DIG_SHA1; else if (strcasecmp(OPT_ARG(HASH), "sha256") == 0) default_dig = GNUTLS_DIG_SHA256; else if (strcasecmp(OPT_ARG(HASH), "sha224") == 0) default_dig = GNUTLS_DIG_SHA224; else if (strcasecmp(OPT_ARG(HASH), "sha384") == 0) default_dig = GNUTLS_DIG_SHA384; else if (strcasecmp(OPT_ARG(HASH), "sha512") == 0) default_dig = GNUTLS_DIG_SHA512; else if (strcasecmp(OPT_ARG(HASH), "rmd160") == 0) default_dig = GNUTLS_DIG_RMD160; else { fprintf(stderr, "invalid hash: %s", OPT_ARG(HASH)); exit(1); } } gnutls_global_set_log_function(tls_log_func); if (HAVE_OPT(DEBUG)) { gnutls_global_set_log_level(OPT_VALUE_DEBUG); printf("Setting log level to %d\n", (int) OPT_VALUE_DEBUG); } if ((ret = gnutls_global_init()) < 0) { fprintf(stderr, "global_init: %s", gnutls_strerror(ret)); exit(1); } #ifdef ENABLE_PKCS11 pkcs11_common(NULL); #endif memset(&cinfo, 0, sizeof(cinfo)); if (HAVE_OPT(INDER) || HAVE_OPT(INRAW)) cinfo.incert_format = GNUTLS_X509_FMT_DER; else cinfo.incert_format = GNUTLS_X509_FMT_PEM; if (HAVE_OPT(VERBOSE)) cinfo.verbose = 1; if (HAVE_OPT(LOAD_PUBKEY)) cinfo.pubkey = OPT_ARG(LOAD_PUBKEY); if (HAVE_OPT(LOAD_CERTIFICATE)) cinfo.cert = OPT_ARG(LOAD_CERTIFICATE); if (HAVE_OPT(PORT)) { port = OPT_VALUE_PORT; } else { if (HAVE_OPT(STARTTLS_PROTO)) port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO)); } if (HAVE_OPT(PROTO)) proto = OPT_ARG(PROTO); if (HAVE_OPT(TLSA_RR)) dane_info(OPT_ARG(HOST), proto, port, HAVE_OPT(CA), ENABLED_OPT(DOMAIN), &cinfo); else if (HAVE_OPT(CHECK)) dane_check(OPT_ARG(CHECK), proto, port, &cinfo); else USAGE(1); fclose(outfile); #ifdef ENABLE_PKCS11 gnutls_pkcs11_deinit(); #endif gnutls_global_deinit(); }
static void cmd_parser (int argc, char **argv) { int ret, debug = 0; common_info_st cinfo; unsigned int pkcs11_type = -1, key_type = GNUTLS_PK_UNKNOWN; const char* url = NULL; unsigned int detailed_url = 0, optct; unsigned int login = 0, bits = 0; const char* label = NULL, *sec_param = NULL; optct = optionProcess( &p11toolOptions, argc, argv); argc += optct; argv += optct; if (url == NULL && argc > 0) url = argv[0]; else url = "pkcs11:"; if (HAVE_OPT(DEBUG)) debug = OPT_VALUE_DEBUG; gnutls_global_set_log_function (tls_log_func); gnutls_global_set_log_level (debug); if (debug > 1) printf ("Setting log level to %d\n", debug); if ((ret = gnutls_global_init ()) < 0) error (EXIT_FAILURE, 0, "global_init: %s", gnutls_strerror (ret)); if (HAVE_OPT(PROVIDER)) { ret = gnutls_pkcs11_init (GNUTLS_PKCS11_FLAG_MANUAL, NULL); if (ret < 0) fprintf (stderr, "pkcs11_init: %s", gnutls_strerror (ret)); else { ret = gnutls_pkcs11_add_provider (OPT_ARG(PROVIDER), NULL); if (ret < 0) error (EXIT_FAILURE, 0, "pkcs11_add_provider: %s", gnutls_strerror (ret)); } } else { ret = gnutls_pkcs11_init (GNUTLS_PKCS11_FLAG_AUTO, NULL); if (ret < 0) fprintf (stderr, "pkcs11_init: %s", gnutls_strerror (ret)); } if (HAVE_OPT(OUTFILE)) { outfile = safe_open_rw (OPT_ARG(OUTFILE), 0); if (outfile == NULL) error (EXIT_FAILURE, errno, "%s", OPT_ARG(OUTFILE)); } else outfile = stdout; memset (&cinfo, 0, sizeof (cinfo)); if (HAVE_OPT(SECRET_KEY)) cinfo.secret_key = OPT_ARG(SECRET_KEY); if (HAVE_OPT(LOAD_PRIVKEY)) cinfo.privkey = OPT_ARG(LOAD_PRIVKEY); if (HAVE_OPT(PKCS8)) cinfo.pkcs8 = 1; if (ENABLED_OPT(INDER) || ENABLED_OPT(INRAW)) cinfo.incert_format = GNUTLS_X509_FMT_DER; else cinfo.incert_format = GNUTLS_X509_FMT_PEM; if (HAVE_OPT(LOAD_CERTIFICATE)) cinfo.cert = OPT_ARG(LOAD_CERTIFICATE); if (HAVE_OPT(LOAD_PUBKEY)) cinfo.pubkey = OPT_ARG(LOAD_PUBKEY); if (ENABLED_OPT(DETAILED_URL)) detailed_url = 1; if (ENABLED_OPT(LOGIN)) login = 1; if (HAVE_OPT(LABEL)) { label = OPT_ARG(LABEL); } if (HAVE_OPT(BITS)) { bits = OPT_VALUE_BITS; } if (HAVE_OPT(SEC_PARAM)) { sec_param = OPT_ARG(SEC_PARAM); } if (debug > 0) { if (HAVE_OPT(PRIVATE)) fprintf(stderr, "Private: %s\n", ENABLED_OPT(PRIVATE)?"yes":"no"); fprintf(stderr, "Trusted: %s\n", ENABLED_OPT(TRUSTED)?"yes":"no"); fprintf(stderr, "Login: %s\n", ENABLED_OPT(LOGIN)?"yes":"no"); fprintf(stderr, "Detailed URLs: %s\n", ENABLED_OPT(DETAILED_URL)?"yes":"no"); fprintf(stderr, "\n"); } /* handle actions */ if (HAVE_OPT(LIST_TOKENS)) pkcs11_token_list (outfile, detailed_url, &cinfo); else if (HAVE_OPT(LIST_MECHANISMS)) pkcs11_mechanism_list (outfile, url, login, &cinfo); else if (HAVE_OPT(LIST_ALL)) { pkcs11_type = PKCS11_TYPE_ALL; pkcs11_list (outfile, url, pkcs11_type, login, detailed_url, &cinfo); } else if (HAVE_OPT(LIST_ALL_CERTS)) { pkcs11_type = PKCS11_TYPE_CRT_ALL; pkcs11_list (outfile, url, pkcs11_type, login, detailed_url, &cinfo); } else if (HAVE_OPT(LIST_CERTS)) { pkcs11_type = PKCS11_TYPE_PK; pkcs11_list (outfile, url, pkcs11_type, login, detailed_url, &cinfo); } else if (HAVE_OPT(LIST_ALL_PRIVKEYS)) { pkcs11_type = PKCS11_TYPE_PRIVKEY; pkcs11_list (outfile, url, pkcs11_type, login, detailed_url, &cinfo); } else if (HAVE_OPT(LIST_ALL_TRUSTED)) { pkcs11_type = PKCS11_TYPE_TRUSTED; pkcs11_list (outfile, url, pkcs11_type, login, detailed_url, &cinfo); } else if (HAVE_OPT(EXPORT)) { pkcs11_export (outfile, url, login, &cinfo); } else if (HAVE_OPT(WRITE)) { int priv; if (HAVE_OPT(PRIVATE)) priv = ENABLED_OPT(PRIVATE); else priv = -1; pkcs11_write (outfile, url, label, ENABLED_OPT(TRUSTED), priv, login, &cinfo); } else if (HAVE_OPT(INITIALIZE)) pkcs11_init (outfile, url, label, &cinfo); else if (HAVE_OPT(DELETE)) pkcs11_delete (outfile, url, 0, login, &cinfo); else if (HAVE_OPT(GENERATE_ECC)) { key_type = GNUTLS_PK_EC; pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param), label, ENABLED_OPT(PRIVATE), detailed_url, login, &cinfo); } else if (HAVE_OPT(GENERATE_RSA)) { key_type = GNUTLS_PK_RSA; pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param), label, ENABLED_OPT(PRIVATE), detailed_url, login, &cinfo); } else if (HAVE_OPT(GENERATE_DSA)) { key_type = GNUTLS_PK_DSA; pkcs11_generate (outfile, url, key_type, get_bits(key_type, bits, sec_param), label, ENABLED_OPT(PRIVATE), detailed_url, login, &cinfo); } else { USAGE(1); } fclose (outfile); #ifdef ENABLE_PKCS11 gnutls_pkcs11_deinit (); #endif gnutls_global_deinit (); }
/* * main - parse arguments and handle options */ int ntpdcmain( int argc, char *argv[] ) { extern int ntp_optind; delay_time.l_ui = 0; delay_time.l_uf = DEFDELAY; #ifdef SYS_VXWORKS clear_globals(); taskPrioritySet(taskIdSelf(), 100 ); #endif init_lib(); /* sets up ipv4_works, ipv6_works */ ssl_applink(); /* Check to see if we have IPv6. Otherwise default to IPv4 */ if (!ipv6_works) ai_fam_default = AF_INET; progname = argv[0]; { int optct = optionProcess(&ntpdcOptions, argc, argv); argc -= optct; argv += optct; } if (HAVE_OPT(IPV4)) ai_fam_templ = AF_INET; else if (HAVE_OPT(IPV6)) ai_fam_templ = AF_INET6; else ai_fam_templ = ai_fam_default; if (HAVE_OPT(COMMAND)) { int cmdct = STACKCT_OPT( COMMAND ); const char** cmds = STACKLST_OPT( COMMAND ); while (cmdct-- > 0) { ADDCMD(*cmds++); } } debug = DESC(DEBUG_LEVEL).optOccCt; if (HAVE_OPT(INTERACTIVE)) { interactive = 1; } if (HAVE_OPT(NUMERIC)) { showhostnames = 0; } if (HAVE_OPT(LISTPEERS)) { ADDCMD("listpeers"); } if (HAVE_OPT(PEERS)) { ADDCMD("peers"); } if (HAVE_OPT(SHOWPEERS)) { ADDCMD("dmpeers"); } if (ntp_optind == argc) { ADDHOST(DEFHOST); } else { for (; ntp_optind < argc; ntp_optind++) ADDHOST(argv[ntp_optind]); } if (numcmds == 0 && interactive == 0 && isatty(fileno(stdin)) && isatty(fileno(stderr))) { interactive = 1; } #if 0 ai_fam_templ = ai_fam_default; while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF) switch (c) { case '4': ai_fam_templ = AF_INET; break; case '6': ai_fam_templ = AF_INET6; break; case 'c': ADDCMD(ntp_optarg); break; case 'd': ++debug; break; case 'i': interactive = 1; break; case 'l': ADDCMD("listpeers"); break; case 'n': showhostnames = 0; break; case 'p': ADDCMD("peers"); break; case 's': ADDCMD("dmpeers"); break; default: errflg++; break; } if (errflg) { (void) fprintf(stderr, "usage: %s [-46dilnps] [-c cmd] host ...\n", progname); exit(2); } if (ntp_optind == argc) { ADDHOST(DEFHOST); } else { for (; ntp_optind < argc; ntp_optind++) ADDHOST(argv[ntp_optind]); } if (numcmds == 0 && interactive == 0 && isatty(fileno(stdin)) && isatty(fileno(stderr))) { interactive = 1; } #endif #ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */ if (interactive) (void) signal_no_reset(SIGINT, abortcmd); #endif /* SYS_WINNT */ /* * Initialize the packet data buffer */ pktdatasize = INITDATASIZE; pktdata = emalloc(INITDATASIZE); if (numcmds == 0) { (void) openhost(chosts[0]); getcmds(); } else { int ihost; int icmd; for (ihost = 0; ihost < numhosts; ihost++) { if (openhost(chosts[ihost])) for (icmd = 0; icmd < numcmds; icmd++) { if (numhosts > 1) printf ("--- %s ---\n",chosts[ihost]); docmd(ccmds[icmd]); } } } #ifdef SYS_WINNT WSACleanup(); #endif return(0); } /* main end */
/** * This is the main function of the program that handles calling other * functions to implemented the needed operations of the replay functionaily. */ int main(int argc, char **argv) { unsigned int k; unsigned int num_packets=0; char port_mode[10]; /* does user specify random port generation?*/ char random_strg[7] = "random"; char* iface = argv[1]; char* new_rmac_ptr; char* new_rip_ptr; in_addr new_remoteip; struct mac_addr new_remotemac; in_addr myip; struct mac_addr mymac; /*temporary packet buffers*/ unsigned int new_src_port = 0; unsigned int retransmissions = 0; pcap_t *local_handle; char errbuf[PCAP_ERRBUF_SIZE]; char ebuf[SENDPACKET_ERRBUF_SIZE]; optionProcess(&tcpliveplayOptions, argc, argv); /*Process AutoOpts for manpage options*/ if((argc < 5) || (argv[1]==NULL) || (argv[2]==NULL) || (argv[3]==NULL) || (argv[4]==NULL) || (argv[5]==NULL)) { printf("ERROR: Incorrect Usage!\n"); printf("Usage: tcpliveplay <eth0/eth1> <file.pcap> <Destinatin IP [1.2.3.4]> <Destination mac [0a:1b:2c:3d:4e:5f]> <specify 'random' or specific port#>\n"); printf("Example:\n yhsiam@yhsiam-VirtualBox:~$ sudo tcpliveplay eth0 test1.pcap 192.168.1.4 52:57:01:11:31:92 random\n\n"); exit(0); } iface_addrs(iface, &myip, &mymac); /* Extract MAC of interface replay is being request on */ /* open send function socket*/ if ((sp = sendpacket_open(iface, ebuf, TCPR_DIR_C2S, SP_TYPE_NONE)) == NULL) errx(-1, "Can't open %s: %s", argv[1], ebuf); /* random dport vs. specified dport operation*/ strcpy(port_mode, argv[5]); /*for(int i = 0; i<10; i++) tolower(port_mode[i]);*/ if(strcmp(port_mode, random_strg)==0) { new_src_port = random_port(); } else new_src_port = atoi(argv[5]); /*else { printf("Port specification error. Please specify 'random' for random source port generation between 49152 and 65535 OR specifiy a specific source port number.\n"); return; }*/ printf("new source port:: %d\n", new_src_port); /* Establish a handler for SIGALRM signals. */ /* This is used as timeout for unresponsive remote hosts */ signal (SIGALRM, catch_alarm); /* Extract new Remote MAC & IP inputted at command line */ new_rmac_ptr= argv[4]; new_rip_ptr = argv[3]; /* These function setup the MAC & IP addresses in the mac_addr & in_addr structs */ extmac(new_rmac_ptr, &new_remotemac); extip(new_rip_ptr, &new_remoteip); /* Rewrites the given "*.pcap" file with all the new parameters and returns the number of packets */ /* that need to be replayed */ num_packets = rewrite(&new_remoteip, &new_remotemac, &myip, &mymac, argv[2], new_src_port); /* create schedule & set it up */ sched = (struct tcp_sched*) malloc(num_packets*sizeof(struct tcp_sched)); pkts_scheduled = setup_sched(sched); /* Returns number of packets in schedule*/ /* Set up the schedule struct to be relative numbers rather than absolute*/ relative_sched(sched, sched[1].exp_rseq, num_packets); printf("Packets Scheduled %d\n", pkts_scheduled); /* Open socket for savedfile traffic to be sent*/ local_handle = pcap_open_offline("newfile.pcap", errbuf); /*call pcap library function*/ if (local_handle == NULL) { fprintf(stderr,"Couldn't open pcap file %s: %s\n", "newfile.pcap", errbuf); return(2); } /* Open socket for live traffic to be listed to*/ live_handle = set_live_filter(iface, &myip, new_src_port); /* returns a pcap_t that filters out traffic other than TCP*/ if (live_handle == NULL) { fprintf(stderr,"Error occured while listing on traffic: %s\n", errbuf); return(2); } /* Printout when no packets are scheduled */ if(pkts_scheduled==0) { printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ ERROR:: There are no TCP packets to sent +\n"); printf("+ Closing replay... +\n"); printf("+ Thank you for Playing, Play again! +\n"); printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); return ERROR; } /* Start replay by sending the first packet, the SYN, from the schedule */ else if(sched[0].local) { /* Send first packet*/ sendpacket(sp, sched[sched_index].packet_ptr, sched[sched_index].pkthdr.len, &sched[sched_index].pkthdr); printf("Sending Local Packet............... [%d]\n",sched_index+1); sched_index++; /* Proceed in the schedule */ } /* Main while loop that handles the decision making and the replay oprations */ while(sched_index<pkts_scheduled) { if(!keep_going) { /*Check the timeout variable */ printf("\n======================================================================\n"); printf("= TIMEOUT:: Remote host is not responding. You may have crashed =\n"); printf("= the host you replayed these packets against OR the packet sequence =\n"); printf("= changed since the capture was taken resulting in differing =\n"); printf("= expectations. Closing replay... =\n"); printf("======================================================================\n\n"); break; } /* tcphdr_rprev carries the last remote tcp header */ if(tcphdr_rprev == NULL) { //printf("FIRST PASS!\n"); } /* Check if received RST or RST-ACK flagged packets*/ else if((tcphdr_rprev->th_flags==TH_RST) || (tcphdr_rprev->th_flags==(TH_RST|TH_ACK))) { printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ ERROR:: Remote host has requested to RESET the connection. +\n"); printf("+ Closing replay... +\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); break; } /*Check if received earlier FIN-ACK than expected else if((sched_index-1 < finack_rindex) && (tcphdr_rprev->th_flags==(TH_FIN|TH_ACK))){ printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ ERROR:: Remote host sent an earlier FIN-ACK than expected. +\n"); printf("+ Closing replay... +\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); return; } */ /* Do the following if we receive a packet that ACKs for the same ACKing of next packet */ else if((tcphdr_rprev->th_seq==htonl(sched[sched_index].exp_rseq)) && (tcphdr_rprev->th_ack==htonl(sched[sched_index].exp_rack)) && (size_payload_prev>0)) { printf("Received Remote Packet............... [%d]\n",sched_index+1); printf("Skipping Packet...................... [%d] to Packet [%d]\n",sched_index+1, sched_index+2); printf("Next Remote Packet Expectation met.\nProceeding in replay...\n"); sched_index++; } /* Do the following if payload does not meet expectation and re-attempt with the remote host for 3 tries*/ else if(different_payload) { printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ WARNING: Remote host is not meeting packet size expectations. +\n"); printf("+ for packet %-d. Application layer data differs from capture being replayed. +\n", diff_payload_index+1); printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); printf("Requesting retransmission.\n Proceeding...\n"); different_payload = false; } /* Local Packets */ if(sched[sched_index].local) { /*Reset alarm timeout*/ alarm (ALARM_TIMEOUT); printf("Sending Local Packet............... [%d]\n",sched_index+1); /* edit each packet tcphdr before sending based on the schedule*/ if(sched_index>0) { sched[sched_index].tcphdr->th_ack = htonl(sched[sched_index].curr_lack); fix_all_checksum_liveplay(sched[sched_index].iphdr); } /* If 3 attempts of resending was made, then error out to the user */ if(sched[sched_index].sent_counter==3) { printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("+ ERROR: Re-sent packet [%-d] 3 times, but remote host is not +\n", sched_index+1); printf("+ responding as expected. 3 resend attempts are a maximum. +\n"); printf("+ Closing replay... +\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); break; } /* If nothing goes wrong, then send the packet scheduled to be sent, then proceed in the schedule */ sendpacket(sp, sched[sched_index].packet_ptr, sched[sched_index].pkthdr.len, &sched[sched_index].pkthdr); sched[sched_index].sent_counter++; /* Keep track of how many times this specific packet was attempted */ sched_index++; /* proceed */ } /* Remote Packets */ else if(sched[sched_index].remote) { alarm (ALARM_TIMEOUT); printf("Receiving Packets from remote host...\n"); pcap_dispatch(live_handle, 1, got_packet, NULL); /* Listen in on NIC for tcp packets */ //printf("pcap_loop returned\n"); } } /* end of main while loop*/ pcap_breakloop(live_handle); pcap_close(live_handle); sendpacket_close(sp); /* Close Send socket*/ remove("newfile.pcap"); /* Remote the rewritten file that was created*/ for(k=0; k<pkts_scheduled; k++) { retransmissions+=sched[k].sent_counter; } /* User Debug Result Printouts*/ if(sched_index==pkts_scheduled) { printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("~ CONGRATS!!! You have successfully Replayed your pcap file '%s' \n", argv[2]); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); } else { printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("~ Unfortunately an error has occurred halting the replay of \n"); printf("~ the pcap file '%s'. Please see error above for details... \n", argv[2]); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); } printf("----------------TCP Live Play Summary----------------\n"); printf("- Packets Scheduled to be Sent & Received: %-d \n", pkts_scheduled); printf("- Actual Packets Sent & Received: %-d \n", sched_index); printf("- Total Local Packet Re-Transmissions due to packet \n"); printf("- loss and/or differing payload size than expected: %-d \n", retransmissions); printf("- Thank you for Playing, Play again! \n"); printf("----------------------------------------------------------\n\n"); return 0; }
static void cmd_parser (int argc, char **argv) { const char* rest = NULL; int optct = optionProcess( &gnutls_cliOptions, argc, argv); argc -= optct; argv += optct; if (rest == NULL && argc > 0) rest = argv[0]; if (HAVE_OPT(BENCHMARK_CIPHERS)) { benchmark_cipher(1, OPT_VALUE_DEBUG); exit(0); } if (HAVE_OPT(BENCHMARK_SOFT_CIPHERS)) { benchmark_cipher(0, OPT_VALUE_DEBUG); exit(0); } if (HAVE_OPT(BENCHMARK_TLS)) { benchmark_tls(OPT_VALUE_DEBUG); exit(0); } if (HAVE_OPT(PRIORITY)) { priorities = OPT_ARG(PRIORITY); } verbose = HAVE_OPT( VERBOSE); if (verbose) print_cert = 1; else print_cert = HAVE_OPT( PRINT_CERT); if (HAVE_OPT(LIST)) { print_list(priorities, verbose); exit(0); } disable_extensions = HAVE_OPT( DISABLE_EXTENSIONS); starttls = HAVE_OPT(STARTTLS); resume = HAVE_OPT(RESUME); rehandshake = HAVE_OPT(REHANDSHAKE); insecure = HAVE_OPT(INSECURE); udp = HAVE_OPT(UDP); mtu = OPT_VALUE_MTU; if (HAVE_OPT(PORT)) { service = OPT_ARG(PORT); } else { service = "443"; } record_max_size = OPT_VALUE_RECORDSIZE; fingerprint = HAVE_OPT(FINGERPRINT); if (HAVE_OPT(X509FMTDER)) x509ctype = GNUTLS_X509_FMT_DER; else x509ctype = GNUTLS_X509_FMT_PEM; if (HAVE_OPT(SRPUSERNAME)) srp_username = OPT_ARG(SRPUSERNAME); if (HAVE_OPT(SRPPASSWD)) srp_passwd = OPT_ARG(SRPPASSWD); if (HAVE_OPT(X509CAFILE)) x509_cafile = OPT_ARG(X509CAFILE); else { if (access(DEFAULT_CA_FILE, R_OK) == 0) x509_cafile = DEFAULT_CA_FILE; } if (HAVE_OPT(X509CRLFILE)) x509_crlfile = OPT_ARG(X509CRLFILE); if (HAVE_OPT(X509KEYFILE)) x509_keyfile = OPT_ARG(X509KEYFILE); if (HAVE_OPT(X509CERTFILE)) x509_certfile = OPT_ARG(X509CERTFILE); if (HAVE_OPT(PGPKEYFILE)) pgp_keyfile = OPT_ARG(PGPKEYFILE); if (HAVE_OPT(PGPCERTFILE)) pgp_certfile = OPT_ARG(PGPCERTFILE); if (HAVE_OPT(PSKUSERNAME)) psk_username = OPT_ARG(PSKUSERNAME); if (HAVE_OPT(PSKKEY)) { psk_key.data = (unsigned char *) OPT_ARG(PSKKEY); psk_key.size = strlen (OPT_ARG(PSKKEY)); } else psk_key.size = 0; if (HAVE_OPT(PGPKEYRING)) pgp_keyring = OPT_ARG(PGPKEYRING); crlf = HAVE_OPT(CRLF); if (rest != NULL) hostname = rest; if (hostname == NULL) { fprintf(stderr, "No hostname specified\n"); exit(1); } }
/* * The actual main function. */ int sntp_main ( int argc, char **argv ) { register int c; struct kod_entry *reason = NULL; int optct; /* boolean, u_int quiets gcc4 signed overflow warning */ u_int sync_data_suc; struct addrinfo **bcastaddr = NULL; struct addrinfo **resh = NULL; struct addrinfo *ai; int resc; int kodc; int ow_ret; int bcast = 0; char *hostname; optct = optionProcess(&sntpOptions, argc, argv); argc -= optct; argv += optct; /* Initialize logging system */ init_logging(); if (HAVE_OPT(LOGFILE)) open_logfile(OPT_ARG(LOGFILE)); msyslog(LOG_NOTICE, "Started sntp"); /* IPv6 available? */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_pref = AF_INET; #ifdef DEBUG printf("No ipv6 support available, forcing ipv4\n"); #endif } else { /* Check for options -4 and -6 */ if (HAVE_OPT(IPV4)) ai_fam_pref = AF_INET; else if (HAVE_OPT(IPV6)) ai_fam_pref = AF_INET6; } /* Parse config file if declared TODO */ /* * If there's a specified KOD file init KOD system. If not use * default file. For embedded systems with no writable * filesystem, -K /dev/null can be used to disable KoD storage. */ if (HAVE_OPT(KOD)) kod_init_kod_db(OPT_ARG(KOD)); else kod_init_kod_db("/var/db/ntp-kod"); if (HAVE_OPT(KEYFILE)) auth_init(OPT_ARG(KEYFILE), &keys); #ifdef EXERCISE_KOD_DB add_entry("192.168.169.170", "DENY"); add_entry("192.168.169.171", "DENY"); add_entry("192.168.169.172", "DENY"); add_entry("192.168.169.173", "DENY"); add_entry("192.168.169.174", "DENY"); delete_entry("192.168.169.174", "DENY"); delete_entry("192.168.169.172", "DENY"); delete_entry("192.168.169.170", "DENY"); if ((kodc = search_entry("192.168.169.173", &reason)) == 0) printf("entry for 192.168.169.173 not found but should have been!\n"); else free(reason); #endif /* Considering employing a variable that prevents functions of doing anything until * everything is initialized properly */ resc = resolve_hosts((void *)argv, argc, &resh, ai_fam_pref); if (resc < 1) { printf("Unable to resolve hostname(s)\n"); return -1; } bcast = ENABLED_OPT(BROADCAST); if (bcast) { const char * myargv[2]; myargv[0] = OPT_ARG(BROADCAST); myargv[1] = NULL; bcast = resolve_hosts(myargv, 1, &bcastaddr, ai_fam_pref); } /* Select a certain ntp server according to simple criteria? For now * let's just pay attention to previous KoDs. */ sync_data_suc = FALSE; for (c = 0; c < resc && !sync_data_suc; c++) { ai = resh[c]; do { hostname = addrinfo_to_str(ai); if ((kodc = search_entry(hostname, &reason)) == 0) { if (is_reachable(ai)) { ow_ret = on_wire(ai, bcast ? bcastaddr[0] : NULL); if (0 == ow_ret) sync_data_suc = TRUE; } } else { printf("%d prior KoD%s for %s, skipping.\n", kodc, (kodc > 1) ? "s" : "", hostname); free(reason); } free(hostname); ai = ai->ai_next; } while (NULL != ai); freeaddrinfo(resh[c]); } free(resh); if (!sync_data_suc) return 1; return 0; }
static void cmd_parser(int argc, char **argv) { unsigned int optct; /* Note that the default sec-param is legacy because several TPMs * cannot handle larger keys. */ optct = optionProcess(&systemkey_toolOptions, argc, argv); argc += optct; argv += optct; gnutls_global_set_log_function(tls_log_func); if (HAVE_OPT(DEBUG)) { gnutls_global_set_log_level(OPT_VALUE_DEBUG); printf("Setting log level to %d\n", (int) OPT_VALUE_DEBUG); } if (HAVE_OPT(INDER)) { incert_format = GNUTLS_X509_FMT_DER; inkey_format = GNUTLS_TPMKEY_FMT_DER; } else { incert_format = GNUTLS_X509_FMT_PEM; inkey_format = GNUTLS_TPMKEY_FMT_CTK_PEM; } if (HAVE_OPT(OUTDER)) { outcert_format = GNUTLS_X509_FMT_DER; outkey_format = GNUTLS_TPMKEY_FMT_DER; } else { outcert_format = GNUTLS_X509_FMT_PEM; outkey_format = GNUTLS_TPMKEY_FMT_CTK_PEM; } if (HAVE_OPT(OUTFILE)) { outfile = safe_open_rw(OPT_ARG(OUTFILE), 0); if (outfile == NULL) { fprintf(stderr, "%s", OPT_ARG(OUTFILE)); exit(1); } } else outfile = stdout; if (HAVE_OPT(INFILE)) { infile = fopen(OPT_ARG(INFILE), "rb"); if (infile == NULL) { fprintf(stderr, "%s", OPT_ARG(INFILE)); exit(1); } } else infile = stdin; if (HAVE_OPT(DELETE)) { systemkey_delete(OPT_ARG(DELETE), outfile); } else if (HAVE_OPT(LIST)) { systemkey_list(outfile); } else { USAGE(1); } fclose(outfile); gnutls_global_deinit(); }
/* * main - parse arguments and handle options */ int main( int argc, char *argv[] ) { int fd; struct sgttyb ttyb; struct itimerval itimer; #ifdef STREAM magic[0] = 0; #endif { int ct = optionProcess( &clktestOptions, argc, argv ); if (HAVE_OPT(COMMAND) && (strlen(OPT_ARG(COMMAND)) == 0)) { fputs( "The command option string must not be empty\n", stderr ); USAGE( EXIT_FAILURE ); } if ((argc -= ct) != 1) { fputs( "Missing tty device name\n", stderr ); USAGE( EXIT_FAILURE ); } argv += ct; } #ifdef STREAM if (!strlen(magic)) strcpy(magic,DEFMAGIC); #endif fd = open(*argv, HAVE_OPT(TIMEOUT) ? O_RDWR : O_RDONLY, 0777); if (fd == -1) { fprintf(stderr, "%s: open(%s): ", progname, *argv); perror(""); exit(1); } if (ioctl(fd, TIOCEXCL, (char *)0) < 0) { (void) fprintf(stderr, "%s: ioctl(TIOCEXCL): ", progname); perror(""); exit(1); } /* * If we have the clock discipline, set the port to raw. Otherwise * we run cooked. */ ttyb.sg_ispeed = ttyb.sg_ospeed = speed; #ifdef CLKLDISC ttyb.sg_erase = (char)magic1; ttyb.sg_kill = (char)magic2; #endif ttyb.sg_flags = (short)ttflags; if (ioctl(fd, TIOCSETP, (char *)&ttyb) < 0) { (void) fprintf(stderr, "%s: ioctl(TIOCSETP): ", progname); perror(""); exit(1); } if (fcntl(fd, F_SETOWN, getpid()) == -1) { (void) fprintf(stderr, "%s: fcntl(F_SETOWN): ", progname); perror(""); exit(1); } #ifdef CLKLDISC { int ldisc; ldisc = CLKLDISC; if (ioctl(fd, TIOCSETD, (char *)&ldisc) < 0) { (void) fprintf(stderr, "%s: ioctl(TIOCSETD): ", progname); perror(""); exit(1); } } #endif #ifdef STREAM if (ioctl(fd, I_POP, 0) >=0 ) ; if (ioctl(fd, I_PUSH, "clk") < 0) { (void) fprintf(stderr, "%s: ioctl(I_PUSH): ", progname); perror(""); exit(1); } if (ioctl(fd, CLK_SETSTR, magic) < 0) { (void) fprintf(stderr, "%s: ioctl(CLK_SETSTR): ", progname); perror(""); exit(1); } #endif (void) gettimeofday(&lasttv, (struct timezone *)0); if (HAVE_OPT(TIMEOUT)) { /* * set non-blocking, async I/O on the descriptor */ iosig = 0; (void) signal(SIGIO, ioready); if (fcntl(fd, F_SETFL, FNDELAY|FASYNC) < 0) { (void) fprintf(stderr, "%s: fcntl(F_SETFL): ", progname); perror(""); exit(1); } /* * Set up the alarm interrupt. */ wasalarmed = 0; (void) signal(SIGALRM, alarming); timeout.tv_sec = OPT_VALUE_TIMEOUT; itimer.it_interval = itimer.it_value = timeout; setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0); doboth(fd); } doioonly(fd); }
int main(int argc, char **argv) { int ret; #ifndef _WIN32 struct passwd *pwd; #endif unsigned char key[MAX_KEY_SIZE]; char hex_key[MAX_KEY_SIZE * 2 + 1]; int optct, key_size; gnutls_datum_t dkey; const char *passwd, *username; size_t hex_key_size = sizeof(hex_key); if ((ret = gnutls_global_init()) < 0) { fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret)); exit(1); } umask(066); optct = optionProcess(&psktoolOptions, argc, argv); argc -= optct; argv += optct; if (!HAVE_OPT(PASSWD)) passwd = (char *) KPASSWD; else passwd = OPT_ARG(PASSWD); if (!HAVE_OPT(USERNAME)) { #ifndef _WIN32 pwd = getpwuid(getuid()); if (pwd == NULL) { fprintf(stderr, "No such user\n"); return -1; } username = pwd->pw_name; #else fprintf(stderr, "Please specify a user\n"); return -1; #endif } else username = OPT_ARG(USERNAME); if (HAVE_OPT(KEYSIZE) && OPT_VALUE_KEYSIZE > MAX_KEY_SIZE) { fprintf(stderr, "Key size is too long\n"); exit(1); } if (!HAVE_OPT(KEYSIZE) || OPT_VALUE_KEYSIZE < 1) key_size = 16; else key_size = OPT_VALUE_KEYSIZE; printf("Generating a random key for user '%s'\n", username); ret = gnutls_rnd(GNUTLS_RND_RANDOM, (char *) key, key_size); if (ret < 0) { fprintf(stderr, "Not enough randomness\n"); exit(1); } dkey.data = key; dkey.size = key_size; ret = gnutls_hex_encode(&dkey, hex_key, &hex_key_size); if (ret < 0) { fprintf(stderr, "HEX encoding error\n"); exit(1); } ret = write_key(username, hex_key, hex_key_size, passwd); if (ret == 0) printf("Key stored to %s\n", passwd); return ret; }
int main( int argc, char** argv ) { xmlDocPtr pDoc; char const* pzFile = NULL; { int ct = optionProcess( &xml2agOptions, argc, argv ); argc -= ct; argv += ct; switch (argc) { case 1: if (strcmp( *argv, "-" ) != 0) { if (HAVE_OPT( DEFINITIONS )) { fprintf( stderr, zConflict ); USAGE( EXIT_FAILURE ); } pzFile = *argv; break; } case 0: if ( HAVE_OPT( DEFINITIONS ) && (strcmp( OPT_ARG( DEFINITIONS ), "-" ) != 0) ) pzFile = OPT_ARG( DEFINITIONS ); break; default: fprintf( stderr, "only one argument allowed\n" ); return EXIT_FAILURE; } } if (! HAVE_OPT( OUTPUT )) forkAutogen( pzFile ); else outFp = stdout; if (pzFile != NULL) { fprintf( outFp, "/* Parsing file %s */\n", pzFile ); pDoc = xmlParseFile( pzFile ); } else { size_t sz; char* pz = loadFile( stdin, &sz ); pDoc = xmlParseMemory( pz, (int)sz ); fprintf( outFp, "/* Parsed from stdin */\n" ); } { static char const z_not_doc[] = "/* type %d doc is not DOCUMENT or HTML_DOCUMENT */\n"; xmlNodePtr pRoot = printHeader( pDoc ); printAttrs( pRoot->properties ); switch (pDoc->type) { case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: printChildren( pRoot->children ); break; default: fprintf( outFp, z_not_doc, pDoc->type ); } } xmlCleanupParser(); return 0; }
/* * Main program. Initialize us, disconnect us from the tty if necessary, * and loop waiting for I/O and/or timer expiries. */ int ntpdmain( int argc, char *argv[] ) { l_fp now; struct recvbuf *rbuf; #ifdef _AIX /* HMS: ifdef SIGDANGER? */ struct sigaction sa; #endif progname = argv[0]; initializing = 1; /* mark that we are initializing */ { int optct = optionProcess( #ifdef SIM &ntpdsimOptions #else &ntpdOptions #endif , argc, argv); argc -= optct; argv += optct; } /* HMS: is this lame? Should we process -l first? */ init_logging(progname); /* Open the log file */ #ifdef HAVE_UMASK { mode_t uv; uv = umask(0); if(uv) (void) umask(uv); else (void) umask(022); } #endif #if defined(HAVE_GETUID) && !defined(MPE) /* MPE lacks the concept of root */ { uid_t uid; uid = getuid(); if (uid) { msyslog(LOG_ERR, "ntpd: must be run as root, not uid %ld", (long)uid); printf("must be run as root, not uid %ld", (long)uid); exit(1); } } #endif #ifdef OPENSSL if ((SSLeay() ^ OPENSSL_VERSION_NUMBER) & ~0xff0L) { msyslog(LOG_ERR, "ntpd: OpenSSL version mismatch. Built against %lx, you have %lx\n", OPENSSL_VERSION_NUMBER, SSLeay()); exit(1); } #endif /* getstartup(argc, argv); / * startup configuration, may set debug */ #ifdef DEBUG debug = DESC(DEBUG_LEVEL).optOccCt; if (debug) printf("%s\n", Version); #endif /* * Enable the Multi-Media Timer for Windows? */ #ifdef SYS_WINNT if (HAVE_OPT( MODIFYMMTIMER )) set_mm_timer(MM_TIMER_HIRES); #endif if (HAVE_OPT( NOFORK ) || HAVE_OPT( QUIT )) nofork = 1; if (HAVE_OPT( NOVIRTUALIPS )) listen_to_virtual_ips = 0; if (HAVE_OPT( INTERFACE )) { #if 0 int ifacect = STACKCT_OPT( INTERFACE ); char** ifaces = STACKLST_OPT( INTERFACE ); /* malloc space for the array of names */ while (ifacect-- > 0) { next_iface = *ifaces++; } #else specific_interface = OPT_ARG( INTERFACE ); #endif } if (HAVE_OPT( NICE )) priority_done = 0; #if defined(HAVE_SCHED_SETSCHEDULER) if (HAVE_OPT( PRIORITY )) { config_priority = OPT_VALUE_PRIORITY; config_priority_override = 1; priority_done = 0; } #endif #ifdef SYS_WINNT /* * Initialize the time structures and variables */ init_winnt_time(); #endif setup_logfile(); /* * Initialize random generator and public key pair */ get_systime(&now); ntp_srandom((int)(now.l_i * now.l_uf)); #ifdef HAVE_DNSREGISTRATION /* HMS: does this have to happen this early? */ msyslog(LOG_INFO, "Attemping to register mDNS"); if ( DNSServiceRegister (&mdns, 0, 0, NULL, "_ntp._udp", NULL, NULL, htons(NTP_PORT), 0, NULL, NULL, NULL) != kDNSServiceErr_NoError ) { msyslog(LOG_ERR, "Unable to register mDNS"); } #endif #if !defined(VMS) # ifndef NODETACH /* * Detach us from the terminal. May need an #ifndef GIZMO. */ if ( # ifdef DEBUG !debug && # endif /* DEBUG */ !nofork) { # ifndef SYS_WINNT # ifdef HAVE_DAEMON daemon(0, 0); # else /* not HAVE_DAEMON */ if (fork()) /* HMS: What about a -1? */ exit(0); { #if !defined(F_CLOSEM) u_long s; int max_fd; #endif /* not F_CLOSEM */ #if defined(F_CLOSEM) /* * From 'Writing Reliable AIX Daemons,' SG24-4946-00, * by Eric Agar (saves us from doing 32767 system * calls) */ if (fcntl(0, F_CLOSEM, 0) == -1) msyslog(LOG_ERR, "ntpd: failed to close open files(): %m"); #else /* not F_CLOSEM */ # if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX) max_fd = sysconf(_SC_OPEN_MAX); # else /* HAVE_SYSCONF && _SC_OPEN_MAX */ max_fd = getdtablesize(); # endif /* HAVE_SYSCONF && _SC_OPEN_MAX */ for (s = 0; s < max_fd; s++) (void) close((int)s); #endif /* not F_CLOSEM */ (void) open("/", 0); (void) dup2(0, 1); (void) dup2(0, 2); #ifdef SYS_DOMAINOS { uid_$t puid; status_$t st; proc2_$who_am_i(&puid); proc2_$make_server(&puid, &st); } #endif /* SYS_DOMAINOS */ #if defined(HAVE_SETPGID) || defined(HAVE_SETSID) # ifdef HAVE_SETSID if (setsid() == (pid_t)-1) msyslog(LOG_ERR, "ntpd: setsid(): %m"); # else if (setpgid(0, 0) == -1) msyslog(LOG_ERR, "ntpd: setpgid(): %m"); # endif #else /* HAVE_SETPGID || HAVE_SETSID */ { # if defined(TIOCNOTTY) int fid; fid = open("/dev/tty", 2); if (fid >= 0) { (void) ioctl(fid, (u_long) TIOCNOTTY, (char *) 0); (void) close(fid); } # endif /* defined(TIOCNOTTY) */ # ifdef HAVE_SETPGRP_0 (void) setpgrp(); # else /* HAVE_SETPGRP_0 */ (void) setpgrp(0, getpid()); # endif /* HAVE_SETPGRP_0 */ } #endif /* HAVE_SETPGID || HAVE_SETSID */ #ifdef _AIX /* Don't get killed by low-on-memory signal. */ sa.sa_handler = catch_danger; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; (void) sigaction(SIGDANGER, &sa, NULL); #endif /* _AIX */ } # endif /* not HAVE_DAEMON */ # endif /* SYS_WINNT */ } # endif /* NODETACH */ #endif /* VMS */ setup_logfile(); /* We lost any redirect when we daemonized */ #ifdef SCO5_CLOCK /* * SCO OpenServer's system clock offers much more precise timekeeping * on the base CPU than the other CPUs (for multiprocessor systems), * so we must lock to the base CPU. */ { int fd = open("/dev/at1", O_RDONLY); if (fd >= 0) { int zero = 0; if (ioctl(fd, ACPU_LOCK, &zero) < 0) msyslog(LOG_ERR, "cannot lock to base CPU: %m"); close( fd ); } /* else ... * If we can't open the device, this probably just isn't * a multiprocessor system, so we're A-OK. */ } #endif #if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) && defined(MCL_FUTURE) # ifdef HAVE_SETRLIMIT /* * Set the stack limit to something smaller, so that we don't lock a lot * of unused stack memory. */ { struct rlimit rl; /* HMS: must make the rlim_cur amount configurable */ if (getrlimit(RLIMIT_STACK, &rl) != -1 && (rl.rlim_cur = 50 * 4096) < rl.rlim_max) { if (setrlimit(RLIMIT_STACK, &rl) == -1) { msyslog(LOG_ERR, "Cannot adjust stack limit for mlockall: %m"); } } # ifdef RLIMIT_MEMLOCK /* * The default RLIMIT_MEMLOCK is very low on Linux systems. * Unless we increase this limit malloc calls are likely to * fail if we drop root privlege. To be useful the value * has to be larger than the largest ntpd resident set size. */ rl.rlim_cur = rl.rlim_max = 32*1024*1024; if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) { msyslog(LOG_ERR, "Cannot set RLIMIT_MEMLOCK: %m"); } # endif /* RLIMIT_MEMLOCK */ } # endif /* HAVE_SETRLIMIT */ /* * lock the process into memory */ if (mlockall(MCL_CURRENT|MCL_FUTURE) < 0) msyslog(LOG_ERR, "mlockall(): %m"); #else /* not (HAVE_MLOCKALL && MCL_CURRENT && MCL_FUTURE) */ # ifdef HAVE_PLOCK # ifdef PROCLOCK # ifdef _AIX /* * set the stack limit for AIX for plock(). * see get_aix_stack() for more info. */ if (ulimit(SET_STACKLIM, (get_aix_stack() - 8*4096)) < 0) { msyslog(LOG_ERR,"Cannot adjust stack limit for plock on AIX: %m"); } # endif /* _AIX */ /* * lock the process into memory */ if (plock(PROCLOCK) < 0) msyslog(LOG_ERR, "plock(PROCLOCK): %m"); # else /* not PROCLOCK */ # ifdef TXTLOCK /* * Lock text into ram */ if (plock(TXTLOCK) < 0) msyslog(LOG_ERR, "plock(TXTLOCK) error: %m"); # else /* not TXTLOCK */ msyslog(LOG_ERR, "plock() - don't know what to lock!"); # endif /* not TXTLOCK */ # endif /* not PROCLOCK */ # endif /* HAVE_PLOCK */ #endif /* not (HAVE_MLOCKALL && MCL_CURRENT && MCL_FUTURE) */ /* * Set up signals we pay attention to locally. */ #ifdef SIGDIE1 (void) signal_no_reset(SIGDIE1, finish); #endif /* SIGDIE1 */ #ifdef SIGDIE2 (void) signal_no_reset(SIGDIE2, finish); #endif /* SIGDIE2 */ #ifdef SIGDIE3 (void) signal_no_reset(SIGDIE3, finish); #endif /* SIGDIE3 */ #ifdef SIGDIE4 (void) signal_no_reset(SIGDIE4, finish); #endif /* SIGDIE4 */ #ifdef SIGBUS (void) signal_no_reset(SIGBUS, finish); #endif /* SIGBUS */ #if !defined(SYS_WINNT) && !defined(VMS) # ifdef DEBUG (void) signal_no_reset(MOREDEBUGSIG, moredebug); (void) signal_no_reset(LESSDEBUGSIG, lessdebug); # else (void) signal_no_reset(MOREDEBUGSIG, no_debug); (void) signal_no_reset(LESSDEBUGSIG, no_debug); # endif /* DEBUG */ #endif /* !SYS_WINNT && !VMS */ /* * Set up signals we should never pay attention to. */ #if defined SIGPIPE (void) signal_no_reset(SIGPIPE, SIG_IGN); #endif /* SIGPIPE */ /* * Call the init_ routines to initialize the data structures. * * Exactly what command-line options are we expecting here? */ init_auth(); init_util(); init_restrict(); init_mon(); init_timer(); #if defined (HAVE_IO_COMPLETION_PORT) init_io_completion_port(); #endif init_lib(); init_request(); init_control(); init_peer(); #ifdef REFCLOCK init_refclock(); #endif set_process_priority(); init_proto(); /* Call at high priority */ init_io(); init_loopfilter(); mon_start(MON_ON); /* monitor on by default now */ /* turn off in config if unwanted */ /* * Get the configuration. This is done in a separate module * since this will definitely be different for the gizmo board. */ getconfig(argc, argv); loop_config(LOOP_DRIFTCOMP, old_drift / 1e6); #ifdef OPENSSL crypto_setup(); #endif /* OPENSSL */ initializing = 0; #ifdef HAVE_DROPROOT if( droproot ) { /* Drop super-user privileges and chroot now if the OS supports this */ #ifdef HAVE_LINUX_CAPABILITIES /* set flag: keep privileges accross setuid() call (we only really need cap_sys_time): */ if( prctl( PR_SET_KEEPCAPS, 1L, 0L, 0L, 0L ) == -1 ) { msyslog( LOG_ERR, "prctl( PR_SET_KEEPCAPS, 1L ) failed: %m" ); exit(-1); } #else /* we need a user to switch to */ if( user == NULL ) { msyslog(LOG_ERR, "Need user name to drop root privileges (see -u flag!)" ); exit(-1); } #endif /* HAVE_LINUX_CAPABILITIES */ if (user != NULL) { if (isdigit((unsigned char)*user)) { sw_uid = (uid_t)strtoul(user, &endp, 0); if (*endp != '\0') goto getuser; } else { getuser: if ((pw = getpwnam(user)) != NULL) { sw_uid = pw->pw_uid; } else { errno = 0; msyslog(LOG_ERR, "Cannot find user `%s'", user); exit (-1); } } } if (group != NULL) { if (isdigit((unsigned char)*group)) { sw_gid = (gid_t)strtoul(group, &endp, 0); if (*endp != '\0') goto getgroup; } else { getgroup: if ((gr = getgrnam(group)) != NULL) { sw_gid = gr->gr_gid; } else { errno = 0; msyslog(LOG_ERR, "Cannot find group `%s'", group); exit (-1); } } } if( chrootdir ) { /* make sure cwd is inside the jail: */ if( chdir(chrootdir) ) { msyslog(LOG_ERR, "Cannot chdir() to `%s': %m", chrootdir); exit (-1); } if( chroot(chrootdir) ) { msyslog(LOG_ERR, "Cannot chroot() to `%s': %m", chrootdir); exit (-1); } } if (group && setgid(sw_gid)) { msyslog(LOG_ERR, "Cannot setgid() to group `%s': %m", group); exit (-1); } if (group && setegid(sw_gid)) { msyslog(LOG_ERR, "Cannot setegid() to group `%s': %m", group); exit (-1); } if (user && setuid(sw_uid)) { msyslog(LOG_ERR, "Cannot setuid() to user `%s': %m", user); exit (-1); } if (user && seteuid(sw_uid)) { msyslog(LOG_ERR, "Cannot seteuid() to user `%s': %m", user); exit (-1); } #ifndef HAVE_LINUX_CAPABILITIES /* * for now assume that the privilege to bind to privileged ports * is associated with running with uid 0 - should be refined on * ports that allow binding to NTP_PORT with uid != 0 */ disable_dynamic_updates |= (sw_uid != 0); /* also notifies routing message listener */ #endif if (disable_dynamic_updates && interface_interval) { interface_interval = 0; msyslog(LOG_INFO, "running in unprivileged mode disables dynamic interface tracking"); } #ifdef HAVE_LINUX_CAPABILITIES do { /* * We may be running under non-root uid now, but we still hold full root privileges! * We drop all of them, except for the crucial one or two: cap_sys_time and * cap_net_bind_service if doing dynamic interface tracking. */ cap_t caps; char *captext = interface_interval ? "cap_sys_time,cap_net_bind_service=ipe" : "cap_sys_time=ipe"; if( ! ( caps = cap_from_text( captext ) ) ) { msyslog( LOG_ERR, "cap_from_text() failed: %m" ); exit(-1); } if( cap_set_proc( caps ) == -1 ) { msyslog( LOG_ERR, "cap_set_proc() failed to drop root privileges: %m" ); exit(-1); } cap_free( caps ); } while(0); #endif /* HAVE_LINUX_CAPABILITIES */ } /* if( droproot ) */ #endif /* HAVE_DROPROOT */ /* * Report that we're up to any trappers */ report_event(EVNT_SYSRESTART, (struct peer *)0); /* * Use select() on all on all input fd's for unlimited * time. select() will terminate on SIGALARM or on the * reception of input. Using select() means we can't do * robust signal handling and we get a potential race * between checking for alarms and doing the select(). * Mostly harmless, I think. */ /* On VMS, I suspect that select() can't be interrupted * by a "signal" either, so I take the easy way out and * have select() time out after one second. * System clock updates really aren't time-critical, * and - lacking a hardware reference clock - I have * yet to learn about anything else that is. */ #if defined(HAVE_IO_COMPLETION_PORT) for (;;) { int tot_full_recvbufs = GetReceivedBuffers(); #else /* normal I/O */ BLOCK_IO_AND_ALARM(); was_alarmed = 0; for (;;) { # if !defined(HAVE_SIGNALED_IO) extern fd_set activefds; extern int maxactivefd; fd_set rdfdes; int nfound; # endif if (alarm_flag) /* alarmed? */ { was_alarmed = 1; alarm_flag = 0; } if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE) { /* * Nothing to do. Wait for something. */ # ifndef HAVE_SIGNALED_IO rdfdes = activefds; # if defined(VMS) || defined(SYS_VXWORKS) /* make select() wake up after one second */ { struct timeval t1; t1.tv_sec = 1; t1.tv_usec = 0; nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0, (fd_set *)0, &t1); } # else nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0, (fd_set *)0, (struct timeval *)0); # endif /* VMS */ if (nfound > 0) { l_fp ts; get_systime(&ts); (void)input_handler(&ts); } else if (nfound == -1 && errno != EINTR) netsyslog(LOG_ERR, "select() error: %m"); # ifdef DEBUG else if (debug > 5) netsyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound); # endif /* DEBUG */ # else /* HAVE_SIGNALED_IO */ wait_for_signal(); # endif /* HAVE_SIGNALED_IO */ if (alarm_flag) /* alarmed? */ { was_alarmed = 1; alarm_flag = 0; } } if (was_alarmed) { UNBLOCK_IO_AND_ALARM(); /* * Out here, signals are unblocked. Call timer routine * to process expiry. */ timer(); was_alarmed = 0; BLOCK_IO_AND_ALARM(); } #endif /* HAVE_IO_COMPLETION_PORT */ #ifdef DEBUG_TIMING { l_fp pts; l_fp tsa, tsb; int bufcount = 0; get_systime(&pts); tsa = pts; #endif rbuf = get_full_recv_buffer(); while (rbuf != NULL) { if (alarm_flag) { was_alarmed = 1; alarm_flag = 0; } UNBLOCK_IO_AND_ALARM(); if (was_alarmed) { /* avoid timer starvation during lengthy I/O handling */ timer(); was_alarmed = 0; } /* * Call the data procedure to handle each received * packet. */ if (rbuf->receiver != NULL) /* This should always be true */ { #ifdef DEBUG_TIMING l_fp dts = pts; L_SUB(&dts, &rbuf->recv_time); DPRINTF(2, ("processing timestamp delta %s (with prec. fuzz)\n", lfptoa(&dts, 9))); collect_timing(rbuf, "buffer processing delay", 1, &dts); bufcount++; #endif (rbuf->receiver)(rbuf); } else { msyslog(LOG_ERR, "receive buffer corruption - receiver found to be NULL - ABORTING"); abort(); } BLOCK_IO_AND_ALARM(); freerecvbuf(rbuf); rbuf = get_full_recv_buffer(); } #ifdef DEBUG_TIMING get_systime(&tsb); L_SUB(&tsb, &tsa); if (bufcount) { collect_timing(NULL, "processing", bufcount, &tsb); DPRINTF(2, ("processing time for %d buffers %s\n", bufcount, lfptoa(&tsb, 9))); } } #endif /* * Go around again */ } UNBLOCK_IO_AND_ALARM(); return 1; } #ifdef SIGDIE2 /* * finish - exit gracefully */ static RETSIGTYPE finish( int sig ) { msyslog(LOG_NOTICE, "ntpd exiting on signal %d", sig); write_stats(); #ifdef HAVE_DNSREGISTRATION if (mdns != NULL) DNSServiceRefDeallocate(mdns); #endif switch (sig) { # ifdef SIGBUS case SIGBUS: printf("\nfinish(SIGBUS)\n"); exit(0); # endif case 0: /* Should never happen... */ return; default: exit(0); } }
int main(int argc, char *argv[]) { int i, optct = 0; int rcode; ctx = tcpreplay_init(); #ifdef TCPREPLAY optct = optionProcess(&tcpreplayOptions, argc, argv); #elif defined TCPREPLAY_EDIT optct = optionProcess(&tcpreplay_editOptions, argc, argv); #endif argc -= optct; argv += optct; rcode = tcpreplay_post_args(ctx, argc); if (rcode <= -2) { warnx("%s", tcpreplay_getwarn(ctx)); } else if (rcode == -1) { errx(-1, "Unable to parse args: %s", tcpreplay_geterr(ctx)); } #ifdef TCPREPLAY_EDIT /* init tcpedit context */ if (tcpedit_init(&tcpedit, sendpacket_get_dlt(ctx->intf1)) < 0) { errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit)); } /* parse the tcpedit args */ rcode = tcpedit_post_args(tcpedit); if (rcode < 0) { errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit)); } else if (rcode == 1) { warnx("%s", tcpedit_geterr(tcpedit)); } if (tcpedit_validate(tcpedit) < 0) { errx(-1, "Unable to edit packets given options:\n%s", tcpedit_geterr(tcpedit)); } #endif if ((ctx->options->enable_file_cache || ctx->options->preload_pcap) && ! HAVE_OPT(QUIET)) { notice("File Cache is enabled"); } /* * Setup up the file cache, if required */ if (ctx->options->enable_file_cache || ctx->options->preload_pcap) { /* Initialise each of the file cache structures */ for (i = 0; i < argc; i++) { ctx->options->file_cache[i].index = i; ctx->options->file_cache[i].cached = FALSE; ctx->options->file_cache[i].packet_cache = NULL; } } for (i = 0; i < argc; i++) { tcpreplay_add_pcapfile(ctx, argv[i]); /* preload our pcap file? */ if (ctx->options->preload_pcap) { preload_pcap_file(ctx, i); } } /* init the signal handlers */ init_signal_handlers(); if (gettimeofday(&ctx->stats.start_time, NULL) < 0) errx(-1, "gettimeofday() failed: %s", strerror(errno)); /* main loop, when not looping forever */ if (ctx->options->loop > 0) { while (ctx->options->loop--) { /* limited loop */ if (ctx->options->dualfile) { /* process two files at a time for network taps */ for (i = 0; i < argc; i += 2) { tcpr_replay_index(ctx, i); } } else { /* process each pcap file in order */ for (i = 0; i < argc; i++) { /* reset cache markers for each iteration */ ctx->cache_byte = 0; ctx->cache_bit = 0; tcpr_replay_index(ctx, i); } } } } else { /* loop forever */ while (1) { if (ctx->options->dualfile) { /* process two files at a time for network taps */ for (i = 0; i < argc; i += 2) { tcpr_replay_index(ctx, i); } } else { /* process each pcap file in order */ for (i = 0; i < argc; i++) { /* reset cache markers for each iteration */ ctx->cache_byte = 0; ctx->cache_bit = 0; tcpr_replay_index(ctx, i); } } } } if (ctx->stats.bytes_sent > 0) { if (gettimeofday(&ctx->stats.end_time, NULL) < 0) errx(-1, "gettimeofday() failed: %s", strerror(errno)); packet_stats(&ctx->stats); printf("%s", sendpacket_getstat(ctx->intf1)); if (ctx->intf2 != NULL) printf("%s", sendpacket_getstat(ctx->intf2)); } tcpreplay_close(ctx); return 0; } /* main() */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * MAIN */ int main(int argc, char ** argv) { FILE* outFp; optionProcess(&getdefsOptions, argc, argv); validateOptions(); outFp = startAutogen(); doPreamble(outFp); /* * Process each input file */ { int ct = STACKCT_OPT(INPUT); char const ** ppz = STACKLST_OPT(INPUT); do { processFile(*ppz++); } while (--ct > 0); } /* * IF we don't have an ordering file, but we do have a "first index", * THEN alphabetize by definition name. */ if ((pzIndexText == NULL) && HAVE_OPT(FIRST_INDEX)) { qsort((void*)papzBlocks, blkUseCt, sizeof(char*), compar_defname); set_first_idx(); } else if (ENABLED_OPT(ORDERING) && (blkUseCt > 1)) qsort((void*)papzBlocks, blkUseCt, sizeof(char*), &compar_text); printEntries(outFp); fclose(outFp); /* * IF output is to a file * THEN set the permissions and modification times */ if ( (WHICH_IDX_AUTOGEN == INDEX_OPT_OUTPUT) && (outFp != stdout) ) { struct utimbuf tbuf; tbuf.actime = time((time_t*)NULL); tbuf.modtime = modtime + 1; utime(OPT_ARG(OUTPUT), &tbuf); chmod(OPT_ARG(OUTPUT), S_IRUSR|S_IRGRP|S_IROTH); } /* * IF we are keeping a database of indexes * AND we have augmented the contents, * THEN append the new entries to the file. */ if ((pzIndexText != NULL) && (pzEndIndex != pzIndexEOF)) updateDatabase(); if (agPid != -1) return awaitAutogen(); return EXIT_SUCCESS; }
int main (int argc, char **argv) { const char *passwd; int salt_size, ret; int optct; const char* fpasswd, *fpasswd_conf; const char* username; #ifndef _WIN32 struct passwd *pwd; #endif set_program_name (argv[0]); if ((ret = gnutls_global_init ()) < 0) { fprintf (stderr, "global_init: %s\n", gnutls_strerror (ret)); exit (1); } umask (066); optct = optionProcess( &srptoolOptions, argc, argv); argc -= optct; argv += optct; gnutls_global_set_log_function (tls_log_func); gnutls_global_set_log_level (OPT_VALUE_DEBUG); if (HAVE_OPT(CREATE_CONF)) { return generate_create_conf (OPT_ARG(CREATE_CONF)); } if (HAVE_OPT(PASSWD)) fpasswd = OPT_ARG(PASSWD); else fpasswd = (char *) KPASSWD; if (HAVE_OPT(PASSWD_CONF)) fpasswd_conf = OPT_ARG(PASSWD_CONF); else fpasswd_conf = (char *) KPASSWD_CONF; if (HAVE_OPT(USERNAME)) username = OPT_ARG(USERNAME); else { #ifndef _WIN32 pwd = getpwuid (getuid ()); if (pwd == NULL) { fprintf (stderr, "No such user\n"); return -1; } username = pwd->pw_name; #else fprintf (stderr, "Please specify a user\n"); return -1; #endif } salt_size = 16; passwd = getpass ("Enter password: "******"Please specify a password\n"); return -1; } /* not ready yet */ if (HAVE_OPT(VERIFY)) { return verify_passwd (fpasswd_conf, fpasswd, username, passwd); } return crypt_int (username, passwd, salt_size, fpasswd_conf, fpasswd, VALUE_OPT_INDEX); }
int main(int argc, char **argv) { ATerm bos, term; ATermTable opcodes; AIL_Definition def; AIL_Program prg; ABFBuffer buffer; ABF abf; PT_Tree tree; int size; /* Option processing */ int arg_ct = optionProcess(&ailcOptions, argc, argv); argc -= arg_ct; argv += arg_ct; if (HAVE_OPT(INPUT)) ailc_input = open_file(OPT_ARG(INPUT), "r"); else ailc_input = stdin; if (HAVE_OPT(OUTPUT)) ailc_output = open_file(OPT_ARG(OUTPUT), "w"); else ailc_output = stdout; if (HAVE_OPT(GENERATE_API)) { ailc_generate_api = 1; ailc_name = OPT_ARG(NAME); /* if (HAVE_OPT(PREFIX)) */ /* ailc_prefix = OPT_ARG(PREFIX); */ /* else */ /* ailc_prefix = default_ail_prefix; */ } if (HAVE_OPT(AIL_LIST)) ailc_def = OPT_ARG(AIL_LIST); else ailc_def = default_ail_def; if (HAVE_OPT(VERBOSE)) ail2abf_set_verbose(1); /* end option processing. */ ATinit(argc, argv, &bos); AIL_initAILApi(); PT_initMEPTApi(); abf_init_buffer(&buffer); /* Read definition. */ term = ATreadFromNamedFile(ailc_def); tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term)); def = AIL_DefinitionFromTerm(PT_TreeToTerm(tree)); /* Save api if needed. */ if (ailc_generate_api) save_opcode_api(ailc_name, def); else { AIL_ByteCode bc; term = ATreadFromBinaryFile(ailc_input); tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term)); prg = AIL_ProgramFromTerm(PT_TreeToTerm(tree)); bc = compile_ail(&buffer, def, prg); AIL_writeToFile(ailc_output, bc); } return 0; }