/* check if dom ends with an element of tldlist[] */ int domfind (const char *dom, const char *tldlist[]) { int i; for (i = 0; tldlist[i]; i++) if (domcmp (dom, tldlist[i])) return 1; return 0; }
const char *whichwhois(const char *s) { unsigned long ip; unsigned int i; /* IPv6 address */ if (strchr(s, ':')) { if (strncmp(s, "2001:", 5) == 0) { unsigned long v6net = strtol(s + 5, NULL, 16); v6net = v6net & 0xfe00; /* we care about the first 7 bits */ for (i = 0; ip6_assign[i].serv; i++) if (v6net == ip6_assign[i].net) return ip6_assign[i].serv; return "\x06"; /* unknown allocation */ } else if (strncasecmp(s, "3ffe:", 5) == 0) return "whois.6bone.net"; /* RPSL hierarchical object like AS8627:fltr-TRANSIT-OUT */ else if (strncasecmp(s, "as", 2) == 0 && isasciidigit(s[2])) return whereas(atoi(s + 2)); else return "\x05"; } /* email address */ if (strchr(s, '@')) return "\x05"; /* no dot and no hyphen means it's a NSI NIC handle or ASN (?) */ if (!strpbrk(s, ".-")) { const char *p; for (p = s; *p; p++); /* go to the end of s */ if (strncasecmp(s, "as", 2) == 0 && /* it's an AS */ (isasciidigit(s[2]) || s[2] == ' ')) return whereas(atoi(s + 2)); else if (strncasecmp(p - 2, "jp", 2) == 0) /* JP NIC handle */ return "whois.nic.ad.jp"; if (*s == '!') /* NSI NIC handle */ return "whois.networksolutions.com"; else return "\x05"; /* probably a unknown kind of nic handle */ } /* smells like an IP? */ if ((ip = myinet_aton(s))) { for (i = 0; ip_assign[i].serv; i++) if ((ip & ip_assign[i].mask) == ip_assign[i].net) return ip_assign[i].serv; return "\x05"; /* not in the unicast IPv4 space */ } /* check the TLDs list */ for (i = 0; tld_serv[i]; i += 2) if (domcmp(s, tld_serv[i])) return tld_serv[i + 1]; /* no dot but hyphen */ if (!strchr(s, '.')) { /* search for strings at the start of the word */ for (i = 0; nic_handles[i]; i += 2) if (strncasecmp(s, nic_handles[i], strlen(nic_handles[i])) == 0) return nic_handles[i + 1]; /* it's probably a network name */ return ""; } /* has dot and maybe a hyphen and it's not in tld_serv[], WTF is it? */ /* either a TLD or a NIC handle we don't know about yet */ return "\x05"; }
const char *match_config_file(const char *s) { FILE *fp; char buf[512]; static const char delim[] = " \t"; #ifdef HAVE_REGEXEC regex_t re; #endif if ((fp = fopen(CONFIG_FILE, "r")) == NULL) { if (errno != ENOENT) h_perror("Cannot open " CONFIG_FILE); return NULL; } while (fgets(buf, sizeof(buf), fp) != NULL) { char *p; const char *pattern, *server; #ifdef HAVE_REGEXEC int i; #endif for (p = buf; *p; p++) if (*p == '\n') *p = '\0'; p = buf; while (*p == ' ' || *p == '\t') /* eat leading blanks */ p++; if (!*p) continue; /* skip empty lines */ if (*p == '#') continue; /* skip comments */ pattern = strtok(p, delim); server = strtok(NULL, delim); if (!pattern || !server) err_quit(_("Cannot parse this line: %s"), p); p = strtok(NULL, delim); if (p) err_quit(_("Cannot parse this line: %s"), p); #ifdef HAVE_REGEXEC i = regcomp(&re, pattern, REG_EXTENDED|REG_ICASE|REG_NOSUB); if (i != 0) { char m[1024]; regerror(i, &re, m, sizeof(m)); err_quit("Invalid regular expression '%s': %s", pattern, m); } i = regexec(&re, s, 0, NULL, 0); if (i == 0) { regfree(&re); return strdup(server); } if (i != REG_NOMATCH) { char m[1024]; regerror(i, &re, m, sizeof(m)); err_quit("regexec: %s", m); } regfree(&re); #else if (domcmp(s, pattern)) return strdup(server); #endif } return NULL; }
static int match_triple_entry(struct nss_innetgr_args *ia, const ns_ldap_entry_t *entry) { int ndomains; char **pdomains; int nhost; char **phost; int nusers; char **pusers; char **attr; char triple[MAX_TRIPLE_LEN]; char *tuser, *thost, *tdomain; int i; char *current, *limit; int pulen, phlen; char *pusers0, *phost0; nhost = ia->arg[NSS_NETGR_MACHINE].argc; phost = (char **)ia->arg[NSS_NETGR_MACHINE].argv; if (phost == NULL || *phost == NULL) { nhost = 0; } else { phost0 = phost[0]; phlen = strlen(phost0); } nusers = ia->arg[NSS_NETGR_USER].argc; pusers = (char **)ia->arg[NSS_NETGR_USER].argv; if (pusers == NULL || *pusers == NULL) { nusers = 0; } else { pusers0 = pusers[0]; pulen = strlen(pusers0); } ndomains = ia->arg[NSS_NETGR_DOMAIN].argc; pdomains = (char **)ia->arg[NSS_NETGR_DOMAIN].argv; if (pdomains == NULL || *pdomains == NULL) ndomains = 0; attr = __ns_ldap_getAttr(entry, _N_TRIPLE); if (attr == NULL || *attr == NULL) return (0); /* Special cases for speedup */ if (nusers == 1 && nhost == 0 && ndomains == 0) { /* Special case for finding a single user in a netgroup */ for (; *attr; attr++) { /* jump to first comma and check next character */ current = *attr; if ((current = strchr(current, COMMA)) == NULL) continue; current++; /* skip whitespaces */ while (isspace(*current)) current++; /* if user part is null, then treat as wildcard */ if (*current == COMMA) return (1); /* compare first character */ if (*pusers0 != *current) continue; /* limit username to COMMA */ if ((limit = strchr(current, COMMA)) == NULL) continue; *limit = '\0'; /* remove blanks before COMMA */ if ((limit = strpbrk(current, " \t")) != NULL) *limit = '\0'; /* compare size of username */ if (pulen != strlen(current)) { continue; } /* do actual compare */ if (strncmp(pusers0, current, pulen) == 0) { return (1); } else { continue; } } } else if (nusers == 0 && nhost == 1 && ndomains == 0) { /* Special case for finding a single host in a netgroup */ for (; *attr; attr++) { /* jump to first character and check */ current = *attr; current++; /* skip whitespaces */ while (isspace(*current)) current++; /* if host part is null, then treat as wildcard */ if (*current == COMMA) return (1); /* limit hostname to COMMA */ if ((limit = strchr(current, COMMA)) == NULL) continue; *limit = '\0'; /* remove blanks before COMMA */ if ((limit = strpbrk(current, " \t")) != NULL) *limit = '\0'; /* compare size of hostname */ if (phlen != strlen(current)) { continue; } /* do actual compare */ if (strncasecmp(phost0, current, phlen) == 0) { return (1); } else { continue; } } } else { for (; *attr; attr++) { if (strlcpy(triple, *attr, sizeof (triple)) >= sizeof (triple)) continue; if (split_triple(triple, &thost, &tuser, &tdomain) != 0) continue; if (thost != NULL && *thost != '\0' && nhost != 0) { for (i = 0; i < nhost; i++) if (strcasecmp(thost, phost[i]) == 0) break; if (i == nhost) continue; } if (tuser != NULL && *tuser != '\0' && nusers != 0) { for (i = 0; i < nusers; i++) if (strcmp(tuser, pusers[i]) == 0) break; if (i == nusers) continue; } if (tdomain != NULL && *tdomain != '\0' && ndomains != 0) { for (i = 0; i < ndomains; i++) if (domcmp(tdomain, pdomains[i]) == 0) break; if (i == ndomains) continue; } return (1); } } return (0); }
const char * whichwhois (const char *s) { unsigned long ip; unsigned int i; /* -v or -t has been used */ if (*s == '\0') return "whois.ripe.net"; /* IPv6 address */ if (strchr (s, ':')) { if (strncasecmp (s, "2001:2", 6) == 0) /* XXX ugly hack! */ return "whois.apnic.net"; if (strncasecmp (s, "2001:4", 6) == 0) return "whois.arin.net"; if (strncasecmp (s, "2001:6", 6) == 0) return "whois.ripe.net"; /* if (strncasecmp(s, "3ffe", 4) == 0) */ return "whois.6bone.net"; } /* email address */ if (strchr (s, '@')) return ""; /* no dot and no hyphen means it's a NSI NIC handle or ASN (?) */ if (!strpbrk (s, ".-")) { const char *p; for (p = s; *p != '\0'; p++); /* go to the end of s */ if (strncasecmp (s, "as", 2) == 0 && /* it's an AS */ ((s[2] >= '0' && s[2] <= '9') || s[2] == ' ')) return whereas (atoi (s + 2), as_assign); else if (strncasecmp (p - 2, "jp", 2) == 0) /* JP NIC handle */ return "whois.nic.ad.jp"; if (*p == '!') /* NSI NIC handle */ return "whois.networksolutions.com"; else /* it's a NSI NIC handle or something we don't know about */ return ""; } /* smells like an IP? */ if ((ip = myinet_aton (s))) { for (i = 0; ip_assign[i].serv; i++) if ((ip & ip_assign[i].mask) == ip_assign[i].net) return ip_assign[i].serv; if (verb) puts (_("I don't know where this IP has been delegated.\n" "I'll try ARIN and hope for the best...")); return "whois.arin.net"; } /* check TLD list */ for (i = 0; tld_serv[i]; i += 2) if (domcmp (s, tld_serv[i])) return tld_serv[i + 1]; /* no dot but hyphen */ if (!strchr (s, '.')) { /* search for strings at the start of the word */ for (i = 0; nic_handles[i]; i += 2) if (strncasecmp (s, nic_handles[i], strlen (nic_handles[i])) == 0) return nic_handles[i + 1]; if (verb) puts (_("I guess it's a netblock name but I don't know where to" " look it up.")); return "whois.arin.net"; } /* has dot and hypen and it's not in tld_serv[], WTF is it? */ if (verb) puts (_("I guess it's a domain but I don't know where to look it" " up.")); return ""; }