/** * Loads a match list. Match lists are supposed to have been * generated by the Locate program. */ struct match_list* load_match_list(U_FILE* f,OutputPolicy *output_policy,unichar *header,Abstract_allocator prv_alloc) { struct match_list* l=NULL; struct match_list* end_of_list=NULL; int start,end,start_char,end_char,start_letter,end_letter; Ustring* line=new_Ustring(); char is_an_output; /* We read the header */ unichar foo=0; if (header==NULL) { header=&foo; } u_fscanf(f,"#%C\n",header); OutputPolicy policy; switch(*header) { case 'D': { policy=DEBUG_OUTPUTS; /* In debug mode, we have to skip the debug header */ int n_graphs; u_fscanf(f,"%d\n",&n_graphs); while ((n_graphs--)>-1) { /* -1, because we also have to skip the #[IMR] line */ readline(line,f); } break; } case 'M': policy=MERGE_OUTPUTS; break; case 'R': case 'T': case 'X': policy=REPLACE_OUTPUTS; break; case 'I': default: policy=IGNORE_OUTPUTS; break; } if (output_policy!=NULL) { (*output_policy)=policy; } while (6==u_fscanf(f,"%d.%d.%d %d.%d.%d",&start,&start_char,&start_letter,&end,&end_char,&end_letter)) { /* We look if there is an output or not, i.e. a space or a new line */ int c=u_fgetc(f); if (c==' ') { /* If we have an output to read */ readline(line,f); /* In debug mode, we have to stop at the char #1 */ int i=-1; while (line->str[++i]!=1 && line->str[i]!='\0') { } line->str[i]='\0'; } is_an_output=(policy!=IGNORE_OUTPUTS); if (l==NULL) { l=new_match(start,end,start_char,end_char,start_letter,end_letter,is_an_output?line->str:NULL,-1,NULL,prv_alloc); end_of_list=l; } else { end_of_list->next=new_match(start,end,start_char,end_char,start_letter,end_letter,is_an_output?line->str:NULL,-1,NULL,prv_alloc); end_of_list=end_of_list->next; } } free_Ustring(line); return l; }
Match * new_subex_match(uint32_t index) { SubexMatch *subex = new_match(MATCH_SUBEX, sizeof(SubexMatch)); subex->index = index; return (Match *) subex; }
/* ip6tables -I %s %d -p %s -i %s -s %s --sport %hu -d %s --dport %hu -j ACCEPT ip6tables -I %s %d -p %s -i %s --sport %hu -d %s --dport %hu -j ACCEPT miniupnpd_forward_chain, line_number, proto, ext_if_name, raddr, rport, iaddr, iport ip6tables -t raw -I PREROUTING %d -p %s -i %s -s %s --sport %hu -d %s --dport %hu -j TRACE ip6tables -t raw -I PREROUTING %d -p %s -i %s --sport %hu -d %s --dport %hu -j TRACE */ int add_pinhole(const char * ifname, const char * rem_host, unsigned short rem_port, const char * int_client, unsigned short int_port, int proto, unsigned int timestamp) { int uid; struct ip6t_entry * e; struct ip6t_entry_match *match = NULL; struct ip6t_entry_target *target = NULL; e = calloc(1, sizeof(struct ip6t_entry)); e->ipv6.proto = proto; if(ifname) strncpy(e->ipv6.iniface, ifname, IFNAMSIZ); if(rem_host) { inet_pton(AF_INET6, rem_host, &e->ipv6.src); memset(&e->ipv6.smsk, 0xff, sizeof(e->ipv6.smsk)); } inet_pton(AF_INET6, int_client, &e->ipv6.dst); memset(&e->ipv6.dmsk, 0xff, sizeof(e->ipv6.dmsk)); /*e->nfcache = NFC_IP_DST_PT;*/ /*e->nfcache |= NFC_UNKNOWN;*/ match = new_match(proto, rem_port, int_port); target = get_accept_target(); e = realloc(e, sizeof(struct ip6t_entry) + match->u.match_size + target->u.target_size); memcpy(e->elems, match, match->u.match_size); memcpy(e->elems + match->u.match_size, target, target->u.target_size); e->target_offset = sizeof(struct ip6t_entry) + match->u.match_size; e->next_offset = sizeof(struct ip6t_entry) + match->u.match_size + target->u.target_size; free(match); free(target); if(ip6tc_init_verify_append("filter", miniupnpd_v6_filter_chain, e) < 0) { free(e); return -1; } uid = add_to_pinhole_list(&e->ipv6.src, rem_port, &e->ipv6.dst, int_port, proto, timestamp); free(e); return uid; }
struct match *get_match(int date, char *sport, char *contestant1, char *contestant2, int contestant1_score, int contestant2_score) { struct match *info = new_match(); if (info == NULL) { return NULL; } info->date = date; strncpy(info->sport, sport, sizeof(info->sport) - 1); strncpy(info->contestant1, contestant1, sizeof(info->contestant1) - 1); strncpy(info->contestant2, contestant2, sizeof(info->contestant2) - 1); info->contestant1_score = contestant1_score; info->contestant2_score = contestant2_score; return info; }
Match * new_regex_match(const char *respec, RegexFlags flags) { RegexMatch *regex = new_match(MATCH_REGEX, sizeof(RegexMatch)); int init_flags = REG_EXTENDED; int rc; memset(®ex->regex, 0, sizeof(regex_t)); regex->regex_string = xstrdup(respec); regex->flags = flags; if (flags & REGEX_IGNORE_CASE) init_flags |= REG_ICASE; rc = regcomp(®ex->regex, respec, init_flags); if (rc != 0) { char *msg = xregerror(rc, ®ex->regex); regfree(®ex->regex); warn("%s", msg); free(msg); exit(1); } return (Match *) regex; }
/** * Allocates, initializes and returns a new match list element. */ struct match_list* new_match(int start,int end,unichar* output,int weight,struct match_list* next,Abstract_allocator prv_alloc) { return new_match(start,end,-1,-1,-1,-1,output,weight,next,prv_alloc); }
/* * wild_match: calculate the "value" of str when matched against pattern. * The "value" of a string is always zero if it is not matched by the pattern. * In all cases where the string is matched by the pattern, then the "value" * of the match is 1 plus the number of non-wildcard characters in "str". * * \\[ and \\] handling done by Jeremy Nelson */ int BX_wild_match (const char *p, const char *str) { /* * Is there a \[ in the pattern to be expanded? * * This stuff here just reduces the \[ \] set into a series of * one-simpler patterns and then recurses over the options. */ if (strstr(p, "\\[")) { char *pattern, *ptr, *ptr2, *arg, *placeholder; int nest = 0; /* * Only make the copy if we're going to be tearing it apart. */ pattern = LOCAL_COPY(p); /* * We will have to null this out, but not until we've used it */ placeholder = ptr = ptr2 = strstr(pattern, "\\["); /* * Look for the matching \]. */ do { switch (ptr[1]) { /* step over it and add to nest */ case '[' : ptr2 = ptr + 2 ; nest++; break; /* step over it and remove nest */ case ']' : ptr2 = ptr + 2; nest--; break; default: ptr2 = ptr + 2; break; } } while (nest && (ptr = strchr(ptr2, '\\'))); /* * Right now, we know that ptr points to a \] or to a NULL. * Remember that '&&' short circuits and that ptr will * not be set to NULL if (nest) is zero. */ if (ptr) { int best_total = 0; *ptr = 0; ptr += 2; *placeholder = 0; placeholder += 2; /* * grab words ("" sets or space words) one at a time * and attempt to match all of them. The best value * matched is the one used. */ while ((arg = new_next_arg(placeholder, &placeholder))) { int tmpval; char my_buff[BIG_BUFFER_SIZE + 1]; strlcpy(my_buff, pattern, BIG_BUFFER_SIZE); strlcat(my_buff, arg, BIG_BUFFER_SIZE); strlcat(my_buff, ptr, BIG_BUFFER_SIZE); /* * The total_explicit we return is whatever * sub-pattern has the highest total_explicit */ if ((tmpval = wild_match(my_buff, str))) { if (tmpval > best_total) best_total = tmpval; } } return best_total; /* end of expansion section */ } /* * Possibly an unmatched \[ \] set. Just wing it. */ else return new_match(pattern, str); } /* * Trivial case -- No \[ \] sets, just do the match. */ else return new_match(p, str); }