/********************************************************************** * * fast_dgrep * * Searches pattern from the whole buffer, and when a match is found, * makes a line from the match position. */ static int fast_dgrep(char* buf, REG3 char* bufend, int bufsize) { REG1 char* matchptr = buf; REG2 char* linebeg; /* beginning of current line */ for (;;) { if (regmust) matchptr = boyer_moore(matchptr,bufend,regmust,regmustlen); else matchptr = reg_exec(matchptr, bufend, linecount_ptr); if (matchptr == NULL) break; linebeg = get_linebeg(matchptr, buf); /* below matchptr points end of line */ matchptr = memchr(matchptr, EOL2, bufend-matchptr); if (matchptr == NULL) matchptr = bufend; if (regmust_only || !regmust /* match found or ...*/ || reg_exec(linebeg,matchptr,NULL) != NULL) /* verify ok */ if (check_flags(linebeg, matchptr, bufend) == STOP) return -1; matchptr++; if (matchptr > bufend) break; } return (buf+bufsize)-(bufend+NEOL(bufend)); }
kadm5_ret_t _kadm5_acl_check_permission(kadm5_server_context *context, unsigned op, krb5_const_principal princ) { kadm5_ret_t ret; unsigned princ_flags; ret = check_flags (op, context->acl_flags); if (ret == 0) return ret; ret = fetch_acl (context, princ, &princ_flags); if (ret) return ret; return check_flags (op, princ_flags); }
void distrib(t_precis *nb, t_flag *flag, char *format) { init(flag, nb); stop_convers(format, nb); check_flags(format, nb); check_precis(nb, format); }
/********************************************************************** * * normal_dgrep * * When use_normal is TRUE, use this. This version separates * lines from buffer and then searches pattern from that line. */ static int normal_dgrep(char* buf, char* bufend, REG4 int bufsize) { REG3 char* line = buf; /* current line */ REG2 char* le; /* line end */ REG1 char* match; while ((le = memchr(line, EOL2, bufsize)) != NULL) { if (regmust) { match = boyer_moore(line,le,regmust,regmustlen); if (match != NULL && !regmust_only) match = reg_exec(line, le, NULL); } else match = reg_exec(line, le, NULL); if ((match && !nonmatch) || (!match && nonmatch)) { if (check_flags(line, le, bufend) == STOP) return -1; } else linecount++; le++; if ((bufsize -= (le-line)) <= 0) return 0; line = le; } return bufsize; }
int dispvar(char **format, va_list ap) { int wr; t_args *arg; wr = 0; arg = (t_args*)malloc(sizeof(t_args)); *format += 1; if (**format != 0) { init_arg(&arg); while (is_flag(**format)) { check_flags(format, &arg); check_field(format, &arg, ap); check_prec(format, &arg, ap); check_length(format, &arg); } wr += print_char(format, &arg, ap); wr += print_hexa(format, &arg, ap); wr += print_decimal(format, &arg, ap); wr += print_octal(format, &arg, ap); } free(arg); return (wr); }
int main (int argc, char **argv) { int i; char *p; struct utsname utsname; /* first, drop privileges */ if (dotlock_init_privs () == -1) return DL_EX_ERROR; /* determine the system's host name */ uname (&utsname); if (!(Hostname = strdup (utsname.nodename))) return DL_EX_ERROR; if ((p = strchr (Hostname, '.'))) *p = '\0'; /* parse the command line options. */ DotlockFlags = 0; while ((i = getopt (argc, argv, "dtfupr:")) != EOF) { switch (i) { /* actions, mutually exclusive */ case 't': check_flags (DotlockFlags); DotlockFlags |= DL_FL_TRY; break; case 'd': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLINK; break; case 'u': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLOCK; break; /* other flags */ case 'f': DotlockFlags |= DL_FL_FORCE; break; case 'p': DotlockFlags |= DL_FL_USEPRIV; break; case 'r': DotlockFlags |= DL_FL_RETRY; Retry = atoi (optarg); break; default: usage (argv[0]); } } if (optind == argc || Retry < 0) usage (argv[0]); return dotlock_dispatch (argv[optind], -1); }
bool is_string(void) const { #if ENABLE_COMPILER_TYPE_INFO return must_be_nonnull() && raw_location()->class_id() == Universe::string_class()->class_id(); #else return check_flags(Value::F_IS_STRING); #endif }
bool is_object_array(void) const { #if ENABLE_COMPILER_TYPE_INFO return must_be_nonnull() && raw_location()->is_exact_type() && raw_location()->class_id() == Universe::object_array_class()->class_id(); #else return check_flags(Value::F_IS_OBJECT_ARRAY); #endif }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { int c; static struct option long_options[] = { {"crypt-method", required_argument, NULL, 'c'}, {"encrypted", no_argument, NULL, 'e'}, {"help", no_argument, NULL, 'h'}, {"md5", no_argument, NULL, 'm'}, {"root", required_argument, NULL, 'R'}, #ifdef USE_SHA_CRYPT {"sha-rounds", required_argument, NULL, 's'}, #endif {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, #ifdef USE_SHA_CRYPT "c:ehmR:s:", #else "c:ehmR:", #endif long_options, NULL)) != -1) { switch (c) { case 'c': crypt_method = optarg; break; case 'e': eflg = true; break; case 'h': usage (E_SUCCESS); /*@notreached@*/break; case 'm': md5flg = true; break; case 'R': /* no-op, handled in process_root_flag () */ break; #ifdef USE_SHA_CRYPT case 's': sflg = true; if (getlong(optarg, &sha_rounds) == 0) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (E_USAGE); } break; #endif default: usage (E_USAGE); /*@notreached@*/break; } } /* validate options */ check_flags (); }
bool is_string_array(void) const { #if ENABLE_COMPILER_TYPE_INFO return must_be_nonnull() && raw_location()->class_id() == JavaClass::Raw(Universe::string_class()->array_class())().class_id(); #else return check_flags(Value::F_IS_STRING_ARRAY); #endif }
int main(int argc, char *argv[]) { // Configuration string path; if(!check_flags(argc,argv,path)){ return 1; } read_input_file(path); // Algorithm //int iteration = 0; //int loop; int watch_best; int best_fitness; solutions_generation(sols); fitness_calculation(sols); solutions_improvement(sols); refset_build(); save_best_solution(refset); refset_tmp = refset; do { // number of new solutions in the RefSet loop = 0; while (get_difference(refset_tmp,refset) != 0) { refset_tmp = refset; solutions_combination(); fitness_calculation(new_set); new_set = solutions_improvement2(new_set); //solutions_improvement(new_set); refset_modification(new_set); loop++; } save_best_solution(refset); /* A: If we find the optimal, stop */ if(best.p == 100){ iteration = max_iter; } /* A: end */ refset_rebuild(); iteration++; print_one_solution(best); //print_strip(best); //print_tikz(best); } while (iteration < max_iter); //print_one_solution(best); //print_strip(best); print_tikz(best); return 0; }
int main(int argc, char **argv) { TDSRESULTINFO *info; char mymsg[256]; fprintf(stdout, "%s: Testing flags from server\n", __FILE__); if (try_tds_login(&login, &tds, __FILE__, 0) != TDS_SUCCESS) { fprintf(stderr, "try_tds_login() failed\n"); return 1; } if (run_query(tds, "create table #tmp1 (i numeric(10,0) identity primary key, b varchar(20) null, c int not null)") != TDS_SUCCESS) fatal_error("creating table error"); /* TDS 4.2 without FOR BROWSE clause seem to forget flags... */ if (!IS_TDS42(tds->conn)) { /* check select of all fields */ test_begin("select * from #tmp1"); info = tds->current_results; if (info->num_cols != 3) { sprintf(mymsg,"wrong number of columns returned expected 3 got %d", info->num_cols); fatal_error(mymsg); } check_flags(info->columns[0], 0, "identity"); check_flags(info->columns[1], 1, "nullable writable"); check_flags(info->columns[2], 2, "writable"); test_end(); } /* check select of 2 field */ test_begin("select c, b from #tmp1 for browse"); info = tds->current_results; if (info->num_cols != 3) fatal_error("wrong number of columns returned"); check_flags(info->columns[0], 0, "writable"); if (!IS_TDS42(tds->conn)) { check_flags(info->columns[1], 1, "nullable writable"); } else { check_flags(info->columns[1], 1, "writable-nullable writable"); } /* TDS5 return not identity information altough documented.. */ check_flags(info->columns[2], 2, "writable identity key hidden-writable key hidden"); test_end(); try_tds_logout(login, tds, 0); return 0; }
void check_opt(char *opt) { int i; i = 1; while (opt[i] != '\0') { if (check_flags(opt[i]) == 0) wrong_flag(opt[i]); else act_flag(opt[i]); i++; } }
std::string read_format_with_args(const std::string &fmt, size_t &index, bool &width_arg, bool &precision_arg, Format &format) { size_t start = index++, len = fmt.length(); while (index < len && check_flags(fmt[index])) { index++; } if (fmt[index] == '*' || isdigit(fmt[index])) { width_arg = has_arg(fmt, index); } if (fmt[index] == '.') { precision_arg = has_arg(fmt, ++index); } check_specifier(fmt, index); format = get_format(fmt, index); return fmt.substr(start, index - start); }
SEQ* seq_open_type(const char *fname, int type) { SEQ *s = ckallocz(sizeof(SEQ)); int r, flags = 0; r = parse_fname(fname, &(s->fname), &(s->from), &(s->slen), &(s->maskname)); if (r == -1) fatalf("improper positions specification: %s", fname); s->type = type; s->flags = check_flags(r|flags); s->fp = ckopen(s->fname, "rb"); s->count = 0; s->offset = 0; return s; }
static void init() { CoglError *error = NULL; CoglDisplay *display; CoglRenderer *renderer; CoglBool missing_requirement; //g_setenv ("COGL_X11_SYNC", "1", 0); test_ctx = cogl_context_new (NULL, &error); if (!test_ctx) { g_message ("Failed to create a CoglContext: %s", error->message); exit(1); } display = cogl_context_get_display (test_ctx); renderer = cogl_display_get_renderer (display); if (!check_flags (renderer)) { g_message ("WARNING: Missing required feature[s] for this test\n"); exit(1); } { //TODO: get all monitors size to test CoglOffscreen *offscreen; CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx, FB_WIDTH, FB_HEIGHT); offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); test_fb = COGL_FRAMEBUFFER (offscreen); } if (!cogl_framebuffer_allocate (test_fb, &error)) { g_message ("Failed to allocate framebuffer: %s", error->message); exit(1); } cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_DEPTH | COGL_BUFFER_BIT_STENCIL, 0, 0, 0, 1); }
void ft_echo(char **av, char **environ) { int i; int flag; flag = 0; i = 0; if (!av[1]) { ft_putchar('\n'); return ; } else i = check_flags(av, &flag); if (flag && !av[i]) return ; else if (flag && av[i]) print_string(av, environ, i, flag); else print_string(av, environ, 1, flag); }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { /* * Parse the command line options. */ char *cp; int c; static struct option long_options[] = { {"force", no_argument, NULL, 'f'}, {"gid", required_argument, NULL, 'g'}, {"help", no_argument, NULL, 'h'}, {"key", required_argument, NULL, 'K'}, {"non-unique", no_argument, NULL, 'o'}, {"password", required_argument, NULL, 'p'}, {"system", no_argument, NULL, 'r'}, {"root", required_argument, NULL, 'R'}, {"prefix", required_argument, NULL, 'P'}, {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, "fg:hK:op:rR:P:", long_options, NULL)) != -1) { switch (c) { case 'f': /* * "force" - do nothing, just exit(0), if the * specified group already exists. With -g, if * specified gid already exists, choose another * (unique) gid (turn off -g). Based on the RedHat's * patch from shadow-utils-970616-9. */ fflg = true; break; case 'g': gflg = true; if ( (get_gid (optarg, &group_id) == 0) || (group_id == (gid_t)-1)) { fprintf (stderr, _("%s: invalid group ID '%s'\n"), Prog, optarg); exit (E_BAD_ARG); } break; case 'h': usage (E_SUCCESS); /*@notreached@*/break; case 'K': /* * override login.defs defaults (-K name=value) * example: -K GID_MIN=100 -K GID_MAX=499 * note: -K GID_MIN=10,GID_MAX=499 doesn't work yet */ cp = strchr (optarg, '='); if (NULL == cp) { fprintf (stderr, _("%s: -K requires KEY=VALUE\n"), Prog); exit (E_BAD_ARG); } /* terminate name, point to value */ *cp++ = '\0'; if (putdef_str (optarg, cp) < 0) { exit (E_BAD_ARG); } break; case 'o': oflg = true; break; case 'p': pflg = true; group_passwd = optarg; break; case 'r': rflg = true; break; case 'R': /* no-op, handled in process_root_flag () */ break; case 'P': /* no-op, handled in process_prefix_flag () */ break; default: usage (E_USAGE); } } /* * Check the flags consistency */ if (optind != argc - 1) { usage (E_USAGE); } group_name = argv[optind]; check_flags (); }
void process_tcp(u_char * data, int skblen) { // printf("into process_tcp\n"); struct ip *this_iphdr = (struct ip *)data; struct tcphdr *this_tcphdr = (struct tcphdr *)(data + 4 * this_iphdr->ip_hl); int datalen, iplen; int from_client = 1; unsigned int tmp_ts; struct tcp_stream *a_tcp; struct half_stream *snd, *rcv; ugly_iphdr = this_iphdr; iplen = ntohs(this_iphdr->ip_len); if ((unsigned)iplen < 4 * this_iphdr->ip_hl + sizeof(struct tcphdr)) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } // ktos sie bawi datalen = iplen - 4 * this_iphdr->ip_hl - 4 * this_tcphdr->th_off; if (datalen < 0) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } // ktos sie bawi if ((this_iphdr->ip_src.s_addr | this_iphdr->ip_dst.s_addr) == 0) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } /* if (!(this_tcphdr->th_flags & TH_ACK)) detect_scan(this_iphdr); */ if (!nids_params.n_tcp_streams) return; if (my_tcp_check(this_tcphdr, iplen - 4 * this_iphdr->ip_hl, this_iphdr->ip_src.s_addr, this_iphdr->ip_dst.s_addr)) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); //return; } #if 0 check_flags(this_iphdr, this_tcphdr); //ECN #endif if (!(a_tcp = find_stream(this_tcphdr, this_iphdr, &from_client))) { if ((this_tcphdr->th_flags & TH_SYN) && !(this_tcphdr->th_flags & TH_ACK) && !(this_tcphdr->th_flags & TH_RST)) add_new_tcp(this_tcphdr, this_iphdr); // printf("add new\n"); return; } // printf("tcp exist\n"); if (from_client) { snd = &a_tcp->client; rcv = &a_tcp->server; } else { rcv = &a_tcp->client; snd = &a_tcp->server; } if ((this_tcphdr->th_flags & TH_SYN)) { if (from_client || a_tcp->client.state != TCP_SYN_SENT || a_tcp->server.state != TCP_CLOSE || !(this_tcphdr->th_flags & TH_ACK)) return; if (a_tcp->client.seq != ntohl(this_tcphdr->th_ack)) return; a_tcp->server.state = TCP_SYN_RECV; a_tcp->server.seq = ntohl(this_tcphdr->th_seq) + 1; a_tcp->server.first_data_seq = a_tcp->server.seq; a_tcp->server.ack_seq = ntohl(this_tcphdr->th_ack); a_tcp->server.window = ntohs(this_tcphdr->th_win); if (a_tcp->client.ts_on) { a_tcp->server.ts_on = get_ts(this_tcphdr, &a_tcp->server.curr_ts); if (!a_tcp->server.ts_on) a_tcp->client.ts_on = 0; } else a_tcp->server.ts_on = 0; if (a_tcp->client.wscale_on) { a_tcp->server.wscale_on = get_wscale(this_tcphdr, &a_tcp->server.wscale); if (!a_tcp->server.wscale_on) { a_tcp->client.wscale_on = 0; a_tcp->client.wscale = 1; a_tcp->server.wscale = 1; } } else { a_tcp->server.wscale_on = 0; a_tcp->server.wscale = 1; } return; } if ( ! ( !datalen && ntohl(this_tcphdr->th_seq) == rcv->ack_seq ) && ( !before(ntohl(this_tcphdr->th_seq), rcv->ack_seq + rcv->window*rcv->wscale) || before(ntohl(this_tcphdr->th_seq) + datalen, rcv->ack_seq) ) ) return; if ((this_tcphdr->th_flags & TH_RST)) { if (a_tcp->nids_state == NIDS_DATA) { struct lurker_node *i; a_tcp->nids_state = NIDS_RESET; for (i = a_tcp->listeners; i; i = i->next) (i->item) (a_tcp, &i->data); } free_tcp(a_tcp); return; } /* PAWS check */ if (rcv->ts_on && get_ts(this_tcphdr, &tmp_ts) && before(tmp_ts, snd->curr_ts)) return; if ((this_tcphdr->th_flags & TH_ACK)) { if (from_client && a_tcp->client.state == TCP_SYN_SENT && a_tcp->server.state == TCP_SYN_RECV) { if (ntohl(this_tcphdr->th_ack) == a_tcp->server.seq) { a_tcp->client.state = TCP_ESTABLISHED; a_tcp->client.ack_seq = ntohl(this_tcphdr->th_ack); { struct proc_node *i; struct lurker_node *j; void *data; a_tcp->server.state = TCP_ESTABLISHED; a_tcp->nids_state = NIDS_JUST_EST; for (i = tcp_procs; i; i = i->next) { char whatto = 0; char cc = a_tcp->client.collect; char sc = a_tcp->server.collect; char ccu = a_tcp->client.collect_urg; char scu = a_tcp->server.collect_urg; (i->item) (a_tcp, &data); if (cc < a_tcp->client.collect) whatto |= COLLECT_cc; if (ccu < a_tcp->client.collect_urg) whatto |= COLLECT_ccu; if (sc < a_tcp->server.collect) whatto |= COLLECT_sc; if (scu < a_tcp->server.collect_urg) whatto |= COLLECT_scu; if (nids_params.one_loop_less) { if (a_tcp->client.collect >=2) { a_tcp->client.collect=cc; whatto&=~COLLECT_cc; } if (a_tcp->server.collect >=2 ) { a_tcp->server.collect=sc; whatto&=~COLLECT_sc; } } if (whatto) { j = mknew(struct lurker_node); j->item = i->item; j->data = data; j->whatto = whatto; j->next = a_tcp->listeners; a_tcp->listeners = j; } } if (!a_tcp->listeners) { free_tcp(a_tcp); return; } a_tcp->nids_state = NIDS_DATA; } } // return; } }
/* * process_flags - process the command line options and arguments */ static void process_flags (int argc, char **argv) { int flag; int option_index = 0; static struct option long_options[] = { {"add", required_argument, NULL, 'a'}, {"delete", required_argument, NULL, 'd'}, {"remove-password", no_argument, NULL, 'r'}, {"restrict", no_argument, NULL, 'R'}, {"administrators", required_argument, NULL, 'A'}, {"members", required_argument, NULL, 'M'}, {NULL, 0, NULL, '\0'} }; while ((flag = getopt_long (argc, argv, "a:A:d:gM:rR", long_options, &option_index)) != -1) { switch (flag) { case 'a': /* add a user */ aflg = true; user = optarg; /* local, no need for xgetpwnam */ if (getpwnam (user) == NULL) { fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, user); exit (E_BAD_ARG); } break; #ifdef SHADOWGRP case 'A': /* set the list of administrators */ if (!is_shadowgrp) { fprintf (stderr, _("%s: shadow group passwords required for -A\n"), Prog); exit (E_GSHADOW_NOTFOUND); } admins = optarg; if (!is_valid_user_list (admins)) { exit (E_BAD_ARG); } Aflg = true; break; #endif /* SHADOWGRP */ case 'd': /* delete a user */ dflg = true; user = optarg; break; case 'g': /* no-op from normal password */ break; case 'M': /* set the list of members */ members = optarg; if (!is_valid_user_list (members)) { exit (E_BAD_ARG); } Mflg = true; break; case 'r': /* remove group password */ rflg = true; break; case 'R': /* restrict group password */ Rflg = true; break; default: usage (); } } /* Get the name of the group that is being affected. */ group = argv[optind]; check_flags (argc, optind); }
static int compare_fiemap_and_map(int fd, char *map, int blocks, int blocksize) { struct fiemap *fiemap; char *fiebuf; int blocks_to_map, ret, cur_extent = 0, last_data; __u64 map_start, map_length; int i, c; blocks_to_map = (random() % blocks) + 1; fiebuf = malloc(sizeof(struct fiemap) + (blocks_to_map * sizeof(struct fiemap_extent))); if (!fiebuf) { perror("Could not allocate fiemap buffers"); return -1; } fiemap = (struct fiemap *) fiebuf; map_start = 0; map_length = blocks_to_map * blocksize; for (i = 0; i < blocks; i++) { if (map[i] != 'H') last_data = i; } fiemap->fm_flags = FIEMAP_FLAG_SYNC; fiemap->fm_extent_count = blocks_to_map; fiemap->fm_mapped_extents = 0; do { fiemap->fm_start = map_start; fiemap->fm_length = map_length; ret = ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap); if (ret < 0) { perror("FIEMAP ioctl failed"); free(fiemap); return -1; } if (check_flags(fiemap, blocksize)) goto error; for (i = cur_extent, c = 1; i < blocks; i++, c++) { __u64 logical_offset = i * blocksize; if (c > blocks_to_map) break; switch (map[i]) { case 'D': if (check_data(fiemap, logical_offset, blocksize, last_data == i, 0)) goto error; break; case 'H': if (check_hole(fiemap, fd, logical_offset, blocksize)) goto error; break; case 'P': if (check_data(fiemap, logical_offset, blocksize, last_data == i, 1)) goto error; break; default: printf("ERROR: weird value in map: %c\n", map[i]); goto error; } } cur_extent = i; map_start = i * blocksize; } while (cur_extent < blocks); ret = 0; return ret; error: printf("map is '%s'\n", map); show_extents(fiemap, blocksize); return -1; }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { int c; static struct option long_options[] = { #ifndef USE_PAM {"crypt-method", required_argument, NULL, 'c'}, #endif /* !USE_PAM */ {"help", no_argument, NULL, 'h'}, {"system", no_argument, NULL, 'r'}, {"root", required_argument, NULL, 'R'}, #ifndef USE_PAM #ifdef USE_SHA_CRYPT {"sha-rounds", required_argument, NULL, 's'}, #endif /* USE_SHA_CRYPT */ #endif /* !USE_PAM */ {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, #ifndef USE_PAM #ifdef USE_SHA_CRYPT "c:hrs:", #else /* !USE_SHA_CRYPT */ "c:hr", #endif /* !USE_SHA_CRYPT */ #else /* USE_PAM */ "hr", #endif long_options, NULL)) != -1) { switch (c) { #ifndef USE_PAM case 'c': crypt_method = optarg; break; #endif /* !USE_PAM */ case 'h': usage (EXIT_SUCCESS); break; case 'r': rflg = true; break; case 'R': /* no-op, handled in process_root_flag () */ break; #ifndef USE_PAM #ifdef USE_SHA_CRYPT case 's': sflg = true; if (getlong(optarg, &sha_rounds) == 0) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (EXIT_FAILURE); } break; #endif /* USE_SHA_CRYPT */ #endif /* !USE_PAM */ default: usage (EXIT_FAILURE); break; } } if ( (optind != argc) && (optind + 1 != argc)) { usage (EXIT_FAILURE); } if (argv[optind] != NULL) { if (freopen (argv[optind], "r", stdin) == NULL) { char buf[BUFSIZ]; snprintf (buf, sizeof buf, "%s: %s", Prog, argv[1]); perror (buf); fail_exit (EXIT_FAILURE); } } /* validate options */ check_flags (); }
bool not_on_heap(void) const { return check_flags(Value::F_NOT_ON_HEAP); }
bool has_known_min_length(void) const { return check_flags(Value::F_HAS_KNOWN_MIN_LENGTH); }
bool must_be_nonnull(void) const { return check_flags(Value::F_MUST_BE_NONNULL); }
int main (int argc, char *argv[]) { mpfr_t x, y; mpfr_exp_t emin, emax; tests_start_mpfr (); test_set_underflow (); test_set_overflow (); check_default_rnd(); mpfr_init (x); mpfr_init (y); emin = mpfr_get_emin (); emax = mpfr_get_emax (); if (emin >= emax) { printf ("Error: emin >= emax\n"); exit (1); } mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_mul_2exp (x, x, 1024, MPFR_RNDN); mpfr_set_double_range (); mpfr_check_range (x, 0, MPFR_RNDN); if (!mpfr_inf_p (x) || (mpfr_sgn(x) <= 0)) { printf ("Error: 2^1024 rounded to nearest should give +Inf\n"); exit (1); } set_emax (1025); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_mul_2exp (x, x, 1024, MPFR_RNDN); mpfr_set_double_range (); mpfr_check_range (x, 0, MPFR_RNDD); if (!mpfr_number_p (x)) { printf ("Error: 2^1024 rounded down should give a normal number\n"); exit (1); } mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_mul_2exp (x, x, 1023, MPFR_RNDN); mpfr_add (x, x, x, MPFR_RNDN); if (!mpfr_inf_p (x) || (mpfr_sgn(x) <= 0)) { printf ("Error: x+x rounded to nearest for x=2^1023 should give +Inf\n"); printf ("emax = %ld\n", mpfr_get_emax ()); printf ("got "); mpfr_print_binary (x); puts (""); exit (1); } mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_mul_2exp (x, x, 1023, MPFR_RNDN); mpfr_add (x, x, x, MPFR_RNDD); if (!mpfr_number_p (x)) { printf ("Error: x+x rounded down for x=2^1023 should give" " a normal number\n"); exit (1); } mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_div_2exp (x, x, 1022, MPFR_RNDN); mpfr_set_str_binary (y, "1.1e-1022"); /* y = 3/2*x */ mpfr_sub (y, y, x, MPFR_RNDZ); if (mpfr_cmp_ui (y, 0)) { printf ("Error: y-x rounded to zero should give 0" " for y=3/2*2^(-1022), x=2^(-1022)\n"); printf ("y="); mpfr_print_binary (y); puts (""); exit (1); } set_emin (-1026); mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_div_2exp (x, x, 1025, MPFR_RNDN); mpfr_set_double_range (); mpfr_check_range (x, 0, MPFR_RNDN); if (!MPFR_IS_ZERO (x) ) { printf ("Error: x rounded to nearest for x=2^-1024 should give Zero\n"); printf ("emin = %ld\n", mpfr_get_emin ()); printf ("got "); mpfr_dump (x); exit (1); } mpfr_clear (x); mpfr_clear (y); set_emin (emin); set_emax (emax); check_emin_emax(); check_flags(); check_set_get_prec (); check_powerof2 (); check_set (); tests_end_mpfr (); return 0; }
static void choose_pivot(struct csa *csa) { SPXLP *lp = csa->lp; int m = lp->m; int n = lp->n; double *l = lp->l; int *head = lp->head; SPXAT *at = csa->at; SPXNT *nt = csa->nt; double *beta = csa->beta; double *d = csa->d; SPYSE *se = csa->se; int *list = csa->list; double *rho = csa->work; double *trow = csa->work1; int nnn, try, k, p, q, t; xassert(csa->beta_st); xassert(csa->d_st); /* initial number of eligible basic variables */ nnn = csa->num; /* nothing has been chosen so far */ csa->p = 0; try = 0; try: /* choose basic variable xB[p] */ xassert(nnn > 0); try++; if (se == NULL) { /* dual Dantzig's rule */ p = spy_chuzr_std(lp, beta, nnn, list); } else { /* dual projected steepest edge */ p = spy_chuzr_pse(lp, se, beta, nnn, list); } xassert(1 <= p && p <= m); /* compute p-th row of inv(B) */ spx_eval_rho(lp, p, rho); /* compute p-th row of the simplex table */ if (at != NULL) spx_eval_trow1(lp, at, rho, trow); else spx_nt_prod(lp, nt, trow, 1, -1.0, rho); /* choose non-basic variable xN[q] */ k = head[p]; /* x[k] = xB[p] */ if (!csa->harris) q = spy_chuzc_std(lp, d, beta[p] < l[k] ? +1. : -1., trow, csa->tol_piv, .30 * csa->tol_dj, .30 * csa->tol_dj1); else q = spy_chuzc_harris(lp, d, beta[p] < l[k] ? +1. : -1., trow, csa->tol_piv, .35 * csa->tol_dj, .35 * csa->tol_dj1); /* either keep previous choice or accept new choice depending on * which one is better */ if (csa->p == 0 || q == 0 || fabs(trow[q]) > fabs(csa->trow[csa->q])) { csa->p = p; memcpy(&csa->trow[1], &trow[1], (n-m) * sizeof(double)); csa->q = q; } /* check if current choice is acceptable */ if (csa->q == 0 || fabs(csa->trow[csa->q]) >= 0.001) goto done; if (nnn == 1) goto done; if (try == 5) goto done; /* try to choose other xB[p] and xN[q] */ /* find xB[p] in the list */ for (t = 1; t <= nnn; t++) if (list[t] == p) break; xassert(t <= nnn); /* move xB[p] to the end of the list */ list[t] = list[nnn], list[nnn] = p; /* and exclude it from consideration */ nnn--; /* repeat the choice */ goto try; done: /* the choice has been made */ return; } /*********************************************************************** * display - display search progress * * This routine displays some information about the search progress * that includes: * * search phase; * * number of simplex iterations performed by the solver; * * original objective value (only on phase II); * * sum of (scaled) dual infeasibilities for original bounds; * * number of dual infeasibilities (phase I) or primal infeasibilities * (phase II); * * number of basic factorizations since last display output. */ static void display(struct csa *csa, int spec) { SPXLP *lp = csa->lp; int m = lp->m; int n = lp->n; int *head = lp->head; char *flag = lp->flag; double *l = csa->l; /* original lower bounds */ double *u = csa->u; /* original upper bounds */ double *beta = csa->beta; double *d = csa->d; int j, k, nnn; double sum; /* check if the display output should be skipped */ if (csa->msg_lev < GLP_MSG_ON) goto skip; if (csa->out_dly > 0 && 1000.0 * xdifftime(xtime(), csa->tm_beg) < csa->out_dly) goto skip; if (csa->it_cnt == csa->it_dpy) goto skip; if (!spec && csa->it_cnt % csa->out_frq != 0) goto skip; /* display search progress depending on search phase */ switch (csa->phase) { case 1: /* compute sum and number of (scaled) dual infeasibilities * for original bounds */ sum = 0.0, nnn = 0; for (j = 1; j <= n-m; j++) { k = head[m+j]; /* x[k] = xN[j] */ if (d[j] > 0.0) { /* xN[j] should have lower bound */ if (l[k] == -DBL_MAX) { sum += d[j]; if (d[j] > +1e-7) nnn++; } } else if (d[j] < 0.0) { /* xN[j] should have upper bound */ if (u[k] == +DBL_MAX) { sum -= d[j]; if (d[j] < -1e-7) nnn++; } } } /* on phase I variables have artificial bounds which are * meaningless for original LP, so corresponding objective * function value is also meaningless */ xprintf(" %6d: %23s inf = %11.3e (%d)", csa->it_cnt, "", sum, nnn); break; case 2: /* compute sum of (scaled) dual infeasibilities */ sum = 0.0, nnn = 0; for (j = 1; j <= n-m; j++) { k = head[m+j]; /* x[k] = xN[j] */ if (d[j] > 0.0) { /* xN[j] should have its lower bound active */ if (l[k] == -DBL_MAX || flag[j]) sum += d[j]; } else if (d[j] < 0.0) { /* xN[j] should have its upper bound active */ if (l[k] != u[k] && !flag[j]) sum -= d[j]; } } /* compute number of primal infeasibilities */ nnn = spy_chuzr_sel(lp, beta, csa->tol_bnd, csa->tol_bnd1, NULL); xprintf("#%6d: obj = %17.9e inf = %11.3e (%d)", csa->it_cnt, (double)csa->dir * spx_eval_obj(lp, beta), sum, nnn); break; default: xassert(csa != csa); } if (csa->inv_cnt) { /* number of basis factorizations performed */ xprintf(" %d", csa->inv_cnt); csa->inv_cnt = 0; } xprintf("\n"); csa->it_dpy = csa->it_cnt; skip: return; } /*********************************************************************** * spy_dual - driver to dual simplex method * * This routine is a driver to the two-phase dual simplex method. * * On exit this routine returns one of the following codes: * * 0 LP instance has been successfully solved. * * GLP_EOBJLL * Objective lower limit has been reached (maximization). * * GLP_EOBJUL * Objective upper limit has been reached (minimization). * * GLP_EITLIM * Iteration limit has been exhausted. * * GLP_ETMLIM * Time limit has been exhausted. * * GLP_EFAIL * The solver failed to solve LP instance. */ static int dual_simplex(struct csa *csa) { /* dual simplex method main logic routine */ SPXLP *lp = csa->lp; int m = lp->m; int n = lp->n; double *l = lp->l; double *u = lp->u; int *head = lp->head; SPXNT *nt = csa->nt; double *beta = csa->beta; double *d = csa->d; SPYSE *se = csa->se; int *list = csa->list; double *trow = csa->trow; double *tcol = csa->tcol; double *pi = csa->work; int msg_lev = csa->msg_lev; double tol_bnd = csa->tol_bnd; double tol_bnd1 = csa->tol_bnd1; double tol_dj = csa->tol_dj; double tol_dj1 = csa->tol_dj1; int j, k, p_flag, refct, ret; check_flags(csa); loop: /* main loop starts here */ /* compute factorization of the basis matrix */ if (!lp->valid) { double cond; ret = spx_factorize(lp); csa->inv_cnt++; if (ret != 0) { if (msg_lev >= GLP_MSG_ERR) xprintf("Error: unable to factorize the basis matrix (%d" ")\n", ret); csa->p_stat = csa->d_stat = GLP_UNDEF; ret = GLP_EFAIL; goto fini; } /* check condition of the basis matrix */ cond = bfd_condest(lp->bfd); if (cond > 1.0 / DBL_EPSILON) { if (msg_lev >= GLP_MSG_ERR) xprintf("Error: basis matrix is singular to working prec" "ision (cond = %.3g)\n", cond); csa->p_stat = csa->d_stat = GLP_UNDEF; ret = GLP_EFAIL; goto fini; } if (cond > 0.001 / DBL_EPSILON) { if (msg_lev >= GLP_MSG_ERR) xprintf("Warning: basis matrix is ill-conditioned (cond " "= %.3g)\n", cond); } /* invalidate basic solution components */ csa->beta_st = csa->d_st = 0; } /* compute reduced costs of non-basic variables d = (d[j]) */ if (!csa->d_st) { spx_eval_pi(lp, pi); for (j = 1; j <= n-m; j++) d[j] = spx_eval_dj(lp, pi, j); csa->d_st = 1; /* just computed */ /* determine the search phase, if not determined yet (this is * performed only once at the beginning of the search for the * original bounds) */ if (!csa->phase) { j = check_feas(csa, 0.97 * tol_dj, 0.97 * tol_dj1, 1); if (j > 0) { /* initial basic solution is dual infeasible and cannot * be recovered */ /* start to search for dual feasible solution */ set_art_bounds(csa); csa->phase = 1; } else { /* initial basic solution is either dual feasible or its * dual feasibility has been recovered */ /* start to search for optimal solution */ csa->phase = 2; } } /* make sure that current basic solution is dual feasible */ j = check_feas(csa, tol_dj, tol_dj1, 0); if (j) { /* dual feasibility is broken due to excessive round-off * errors */ if (bfd_get_count(lp->bfd)) { /* try to provide more accuracy */ lp->valid = 0; goto loop; } if (msg_lev >= GLP_MSG_ERR) xprintf("Warning: numerical instability (dual simplex, p" "hase %s)\n", csa->phase == 1 ? "I" : "II"); if (csa->dualp) { /* do not continue the search; report failure */ csa->p_stat = csa->d_stat = GLP_UNDEF; ret = -1; /* special case of GLP_EFAIL */ goto fini; } /* try to recover dual feasibility */ j = check_feas(csa, 0.97 * tol_dj, 0.97 * tol_dj1, 1); if (j > 0) { /* dual feasibility cannot be recovered (this may happen * only on phase II) */ xassert(csa->phase == 2); /* restart to search for dual feasible solution */ set_art_bounds(csa); csa->phase = 1; } } } /* at this point the search phase is determined */ xassert(csa->phase == 1 || csa->phase == 2); /* compute values of basic variables beta = (beta[i]) */ if (!csa->beta_st) { spx_eval_beta(lp, beta); csa->beta_st = 1; /* just computed */ } /* reset the dual reference space, if necessary */ if (se != NULL && !se->valid) spy_reset_refsp(lp, se), refct = 1000; /* at this point the basis factorization and all basic solution * components are valid */ xassert(lp->valid && csa->beta_st && csa->d_st); check_flags(csa); #if CHECK_ACCURACY /* check accuracy of current basic solution components (only for * debugging) */ check_accuracy(csa); #endif /* check if the objective limit has been reached */ if (csa->phase == 2 && csa->obj_lim != DBL_MAX && spx_eval_obj(lp, beta) >= csa->obj_lim) { if (csa->beta_st != 1) csa->beta_st = 0; if (csa->d_st != 1) csa->d_st = 0; if (!(csa->beta_st && csa->d_st)) goto loop; display(csa, 1); if (msg_lev >= GLP_MSG_ALL) xprintf("OBJECTIVE %s LIMIT REACHED; SEARCH TERMINATED\n", csa->dir > 0 ? "UPPER" : "LOWER"); csa->num = spy_chuzr_sel(lp, beta, tol_bnd, tol_bnd1, list); csa->p_stat = (csa->num == 0 ? GLP_FEAS : GLP_INFEAS); csa->d_stat = GLP_FEAS; ret = (csa->dir > 0 ? GLP_EOBJUL : GLP_EOBJLL); goto fini; } /* check if the iteration limit has been exhausted */ if (csa->it_cnt - csa->it_beg >= csa->it_lim) { if (csa->beta_st != 1) csa->beta_st = 0; if (csa->d_st != 1) csa->d_st = 0; if (!(csa->beta_st && csa->d_st)) goto loop; display(csa, 1); if (msg_lev >= GLP_MSG_ALL) xprintf("ITERATION LIMIT EXCEEDED; SEARCH TERMINATED\n"); if (csa->phase == 1) { set_orig_bounds(csa); check_flags(csa); spx_eval_beta(lp, beta); } csa->num = spy_chuzr_sel(lp, beta, tol_bnd, tol_bnd1, list); csa->p_stat = (csa->num == 0 ? GLP_FEAS : GLP_INFEAS); csa->d_stat = (csa->phase == 1 ? GLP_INFEAS : GLP_FEAS); ret = GLP_EITLIM; goto fini; } /* check if the time limit has been exhausted */ if (1000.0 * xdifftime(xtime(), csa->tm_beg) >= csa->tm_lim) { if (csa->beta_st != 1) csa->beta_st = 0; if (csa->d_st != 1) csa->d_st = 0; if (!(csa->beta_st && csa->d_st)) goto loop; display(csa, 1); if (msg_lev >= GLP_MSG_ALL) xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n"); if (csa->phase == 1) { set_orig_bounds(csa); check_flags(csa); spx_eval_beta(lp, beta); } csa->num = spy_chuzr_sel(lp, beta, tol_bnd, tol_bnd1, list); csa->p_stat = (csa->num == 0 ? GLP_FEAS : GLP_INFEAS); csa->d_stat = (csa->phase == 1 ? GLP_INFEAS : GLP_FEAS); ret = GLP_EITLIM; goto fini; } /* display the search progress */ display(csa, 0); /* select eligible basic variables */ switch (csa->phase) { case 1: csa->num = spy_chuzr_sel(lp, beta, 1e-8, 0.0, list); break; case 2: csa->num = spy_chuzr_sel(lp, beta, tol_bnd, tol_bnd1, list); break; default: xassert(csa != csa); } /* check for optimality */ if (csa->num == 0) { if (csa->beta_st != 1) csa->beta_st = 0; if (csa->d_st != 1) csa->d_st = 0; if (!(csa->beta_st && csa->d_st)) goto loop; /* current basis is optimal */ display(csa, 1); switch (csa->phase) { case 1: /* check for dual feasibility */ set_orig_bounds(csa); check_flags(csa); if (check_feas(csa, tol_dj, tol_dj1, 0) == 0) { /* dual feasible solution found; switch to phase II */ csa->phase = 2; xassert(!csa->beta_st); goto loop; } /* no dual feasible solution exists */ if (msg_lev >= GLP_MSG_ALL) xprintf("LP HAS NO DUAL FEASIBLE SOLUTION\n"); spx_eval_beta(lp, beta); csa->num = spy_chuzr_sel(lp, beta, tol_bnd, tol_bnd1, list); csa->p_stat = (csa->num == 0 ? GLP_FEAS : GLP_INFEAS); csa->d_stat = GLP_NOFEAS; ret = 0; goto fini; case 2: /* optimal solution found */ if (msg_lev >= GLP_MSG_ALL) xprintf("OPTIMAL LP SOLUTION FOUND\n"); csa->p_stat = csa->d_stat = GLP_FEAS; ret = 0; goto fini; default: xassert(csa != csa); } } /* choose xB[p] and xN[q] */ choose_pivot(csa); /* check for dual unboundedness */ if (csa->q == 0) { if (csa->beta_st != 1) csa->beta_st = 0; if (csa->d_st != 1) csa->d_st = 0; if (!(csa->beta_st && csa->d_st)) goto loop; display(csa, 1); switch (csa->phase) { case 1: /* this should never happen */ if (msg_lev >= GLP_MSG_ERR) xprintf("Error: dual simplex failed\n"); csa->p_stat = csa->d_stat = GLP_UNDEF; ret = GLP_EFAIL; goto fini; case 2: /* dual unboundedness detected */ if (msg_lev >= GLP_MSG_ALL) xprintf("LP HAS NO PRIMAL FEASIBLE SOLUTION\n"); csa->p_stat = GLP_NOFEAS; csa->d_stat = GLP_FEAS; ret = 0; goto fini; default: xassert(csa != csa); } } /* compute q-th column of the simplex table */ spx_eval_tcol(lp, csa->q, tcol); /* FIXME: tcol[p] and trow[q] should be close to each other */ xassert(tcol[csa->p] != 0.0); /* update values of basic variables for adjacent basis */ k = head[csa->p]; /* x[k] = xB[p] */ p_flag = (l[k] != u[k] && beta[csa->p] > u[k]); spx_update_beta(lp, beta, csa->p, p_flag, csa->q, tcol); csa->beta_st = 2; /* update reduced costs of non-basic variables for adjacent * basis */ if (spx_update_d(lp, d, csa->p, csa->q, trow, tcol) <= 1e-9) { /* successful updating */ csa->d_st = 2; } else { /* new reduced costs are inaccurate */ csa->d_st = 0; } /* update steepest edge weights for adjacent basis, if used */ if (se != NULL) { if (refct > 0) { if (spy_update_gamma(lp, se, csa->p, csa->q, trow, tcol) <= 1e-3) { /* successful updating */ refct--; } else { /* new weights are inaccurate; reset reference space */ se->valid = 0; } } else { /* too many updates; reset reference space */ se->valid = 0; } } /* update matrix N for adjacent basis, if used */ if (nt != NULL) spx_update_nt(lp, nt, csa->p, csa->q); /* change current basis header to adjacent one */ spx_change_basis(lp, csa->p, p_flag, csa->q); /* and update factorization of the basis matrix */ if (csa->p > 0) spx_update_invb(lp, csa->p, head[csa->p]); /* dual simplex iteration complete */ csa->it_cnt++; goto loop; fini: return ret; }
void process_tcp(u_char * data, int skblen) { struct ip *this_iphdr = (struct ip *)data; struct tcphdr *this_tcphdr = (struct tcphdr *)(data + 4 * this_iphdr->ip_hl); int datalen, iplen; int from_client = 1; unsigned int tmp_ts; struct tcp_stream *a_tcp; struct half_stream *snd, *rcv; ugly_iphdr = this_iphdr; iplen = ntohs(this_iphdr->ip_len); if ((unsigned)iplen < 4 * this_iphdr->ip_hl + sizeof(struct tcphdr)) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } // ktos sie bawi datalen = iplen - 4 * this_iphdr->ip_hl - 4 * this_tcphdr->th_off; if (datalen < 0) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } // ktos sie bawi if ((this_iphdr->ip_src.s_addr | this_iphdr->ip_dst.s_addr) == 0) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } if (!(this_tcphdr->th_flags & TH_ACK)) detect_scan(this_iphdr); if (!nids_params.n_tcp_streams) return; /*FIXME: remove the tcp header check function tempor..*/ #ifdef OSPLIT #ifdef CHECK_TCPHDR_DISABLED #if 0 if (my_tcp_check(this_tcphdr, iplen - 4 * this_iphdr->ip_hl, this_iphdr->ip_src.s_addr, this_iphdr->ip_dst.s_addr)) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } #endif #else if (my_tcp_check(this_tcphdr, iplen - 4 * this_iphdr->ip_hl, this_iphdr->ip_src.s_addr, this_iphdr->ip_dst.s_addr)) { nids_params.syslog(NIDS_WARN_TCP, NIDS_WARN_TCP_HDR, this_iphdr, this_tcphdr); return; } #endif #endif #if 0 check_flags(this_iphdr, this_tcphdr); //ECN #endif if (!(a_tcp = find_stream(this_tcphdr, this_iphdr, &from_client))) { if ((this_tcphdr->th_flags & TH_SYN) && !(this_tcphdr->th_flags & TH_ACK) && !(this_tcphdr->th_flags & TH_RST)) add_new_tcp(this_tcphdr, this_iphdr); return; } #ifdef OSPLIT struct ipfrag *frag_tag=this_fragments; struct ipfrag *ip_frag_next; if(this_fragments) ip_frag_next=this_fragments->next; /*write all fragment(s) to fp trace file*/ if(is_frag==0) { write_pcap_hdr(a_tcp->fp,(char*)nids_last_pcap_header,sizeof(struct pcap_sf_pkthdr)); write_ip(a_tcp->fp,(char*)this_iphdr,ntohs(this_iphdr->ip_len),(char*)nids_last_pcap_header); } else { /*fragments*/ while(frag_tag!=NULL) { write_pcap_hdr(a_tcp->fp,(char*)(&(frag_tag->pcap_header)),sizeof(struct pcap_sf_pkthdr)); write_ip(a_tcp->fp,(char*)frag_tag->skb->data,frag_tag->wtrace_len,(char*)(&(frag_tag->pcap_header))); free(frag_tag); frag_tag=ip_frag_next; if(ip_frag_next!=NULL) ip_frag_next=ip_frag_next->next; } is_frag=0; } /*set statistic info*/ store_flag=1; #endif if (from_client) { snd = &a_tcp->client; rcv = &a_tcp->server; } else { rcv = &a_tcp->client; snd = &a_tcp->server; } if ((this_tcphdr->th_flags & TH_SYN)) { if (from_client || a_tcp->client.state != TCP_SYN_SENT || a_tcp->server.state != TCP_CLOSE || !(this_tcphdr->th_flags & TH_ACK)) return; if (a_tcp->client.seq != ntohl(this_tcphdr->th_ack)) return; a_tcp->server.state = TCP_SYN_RECV; a_tcp->server.seq = ntohl(this_tcphdr->th_seq) + 1; a_tcp->server.first_data_seq = a_tcp->server.seq; a_tcp->server.ack_seq = ntohl(this_tcphdr->th_ack); a_tcp->server.window = ntohs(this_tcphdr->th_win); if (a_tcp->client.ts_on) { a_tcp->server.ts_on = get_ts(this_tcphdr, &a_tcp->server.curr_ts); if (!a_tcp->server.ts_on) a_tcp->client.ts_on = 0; } else a_tcp->server.ts_on = 0; if (a_tcp->client.wscale_on) { a_tcp->server.wscale_on = get_wscale(this_tcphdr, &a_tcp->server.wscale); if (!a_tcp->server.wscale_on) { a_tcp->client.wscale_on = 0; a_tcp->client.wscale = 1; a_tcp->server.wscale = 1; } } else { a_tcp->server.wscale_on = 0; a_tcp->server.wscale = 1; } return; } if ( ! ( !datalen && ntohl(this_tcphdr->th_seq) == rcv->ack_seq ) && ( !before(ntohl(this_tcphdr->th_seq), rcv->ack_seq + rcv->window*rcv->wscale) || before(ntohl(this_tcphdr->th_seq) + datalen, rcv->ack_seq) ) ) return; if ((this_tcphdr->th_flags & TH_RST)) { if (a_tcp->nids_state == NIDS_DATA) { struct lurker_node *i; a_tcp->nids_state = NIDS_RESET; for (i = a_tcp->listeners; i; i = i->next) (i->item) (a_tcp, &i->data); } nids_free_tcp_stream(a_tcp); return; } /* PAWS check */ if (rcv->ts_on && get_ts(this_tcphdr, &tmp_ts) && before(tmp_ts, snd->curr_ts)) return; if ((this_tcphdr->th_flags & TH_ACK)) { if (from_client && a_tcp->client.state == TCP_SYN_SENT && a_tcp->server.state == TCP_SYN_RECV) { if (ntohl(this_tcphdr->th_ack) == a_tcp->server.seq) { a_tcp->client.state = TCP_ESTABLISHED; a_tcp->client.ack_seq = ntohl(this_tcphdr->th_ack); { struct proc_node *i; struct lurker_node *j; void *data; a_tcp->server.state = TCP_ESTABLISHED; a_tcp->nids_state = NIDS_JUST_EST; for (i = tcp_procs; i; i = i->next) { char whatto = 0; char cc = a_tcp->client.collect; char sc = a_tcp->server.collect; char ccu = a_tcp->client.collect_urg; char scu = a_tcp->server.collect_urg; (i->item) (a_tcp, &data); if (cc < a_tcp->client.collect) whatto |= COLLECT_cc; if (ccu < a_tcp->client.collect_urg) whatto |= COLLECT_ccu; if (sc < a_tcp->server.collect) whatto |= COLLECT_sc; if (scu < a_tcp->server.collect_urg) whatto |= COLLECT_scu; if (nids_params.one_loop_less) { if (a_tcp->client.collect >=2) { a_tcp->client.collect=cc; whatto&=~COLLECT_cc; } if (a_tcp->server.collect >=2 ) { a_tcp->server.collect=sc; whatto&=~COLLECT_sc; } } if (whatto) { j = mknew(struct lurker_node); j->item = i->item; j->data = data; j->whatto = whatto; j->next = a_tcp->listeners; a_tcp->listeners = j; } } #ifdef OSPLIT #if 0 if (!a_tcp->listeners) { nids_free_tcp_stream(a_tcp); return; } #endif #endif a_tcp->nids_state = NIDS_DATA; } } // return; } }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { int option_index = 0; int c; static struct option long_options[] = { #ifndef USE_PAM {"crypt-method", required_argument, NULL, 'c'}, {"encrypted", no_argument, NULL, 'e'}, {"md5", no_argument, NULL, 'm'}, #ifdef USE_SHA_CRYPT {"sha-rounds", required_argument, NULL, 's'}, #endif /* USE_SHA_CRYPT */ #endif /* !USE_PAM */ {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, #ifndef USE_PAM # ifdef USE_SHA_CRYPT "c:ehms:", # else /* !USE_SHA_CRYPT */ "c:ehm", # endif /* !USE_SHA_CRYPT */ #else "h", #endif /* !USE_PAM */ long_options, &option_index)) != -1) { switch (c) { case 'h': usage (); break; #ifndef USE_PAM case 'c': cflg = true; crypt_method = optarg; break; case 'e': eflg = true; break; case 'm': md5flg = true; break; #ifdef USE_SHA_CRYPT case 's': sflg = true; if (getlong(optarg, &sha_rounds) == 0) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (); } break; #endif /* USE_SHA_CRYPT */ #endif /* !USE_PAM */ default: usage (); break; } } /* validate options */ check_flags (); }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { /* * Parse the command line options. */ int c; static struct option long_options[] = { {"lastday", required_argument, NULL, 'd'}, {"expiredate", required_argument, NULL, 'E'}, {"help", no_argument, NULL, 'h'}, {"inactive", required_argument, NULL, 'I'}, {"list", no_argument, NULL, 'l'}, {"mindays", required_argument, NULL, 'm'}, {"maxdays", required_argument, NULL, 'M'}, {"root", required_argument, NULL, 'R'}, {"warndays", required_argument, NULL, 'W'}, {NULL, 0, NULL, '\0'} }; while ((c = getopt_long (argc, argv, "d:E:hI:lm:M:R:W:", long_options, NULL)) != -1) { switch (c) { case 'd': dflg = true; lstchgdate = strtoday (optarg); if (lstchgdate < -1) { fprintf (stderr, _("%s: invalid date '%s'\n"), Prog, optarg); usage (E_USAGE); } break; case 'E': Eflg = true; expdate = strtoday (optarg); if (expdate < -1) { fprintf (stderr, _("%s: invalid date '%s'\n"), Prog, optarg); usage (E_USAGE); } break; case 'h': usage (E_SUCCESS); /*@notreached@*/break; case 'I': Iflg = true; if ( (getlong (optarg, &inactdays) == 0) || (inactdays < -1)) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (E_USAGE); } break; case 'l': lflg = true; break; case 'm': mflg = true; if ( (getlong (optarg, &mindays) == 0) || (mindays < -1)) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (E_USAGE); } break; case 'M': Mflg = true; if ( (getlong (optarg, &maxdays) == 0) || (maxdays < -1)) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (E_USAGE); } break; case 'R': /* no-op, handled in process_root_flag () */ break; case 'W': Wflg = true; if ( (getlong (optarg, &warndays) == 0) || (warndays < -1)) { fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, optarg); usage (E_USAGE); } break; default: usage (E_USAGE); } } check_flags (argc, optind); }