diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2018-12-15 15:16:13 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2018-12-15 15:16:13 +0000 |
commit | 41d43cda283dfff21b7d5685cb433805d215733e (patch) | |
tree | ec72ace33d70f1443f1f1058981f59a4b63df53c | |
parent | cb05d18e244c558da4f29bd23f302e42ca6518c2 (diff) |
add a -R option to set/unset resolver flags.
use strcasecmp for reading args.
-rw-r--r-- | regress/lib/libc/asr/bin/common.c | 68 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/common.h | 4 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/getaddrinfo.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/gethostnamadr.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/getnameinfo.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/getnetnamadr.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/getrrsetbyname.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/res_mkquery.c | 7 | ||||
-rw-r--r-- | regress/lib/libc/asr/bin/res_query.c | 7 |
9 files changed, 101 insertions, 20 deletions
diff --git a/regress/lib/libc/asr/bin/common.c b/regress/lib/libc/asr/bin/common.c index c808c86d618..08a7bccbb79 100644 --- a/regress/lib/libc/asr/bin/common.c +++ b/regress/lib/libc/asr/bin/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.3 2014/08/10 07:31:58 guenther Exp $ */ +/* $OpenBSD: common.c,v 1.4 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -86,8 +86,8 @@ kv_lookup_name(struct kv *kv, int code, char *buf, size_t sz) } struct keyval { - const char *key; - uint16_t value; + const char *key; + int value; }; static struct keyval kv_class[] = { @@ -135,6 +135,24 @@ static struct keyval kv_rcode[] = { { NULL, 0 }, }; +static struct keyval kv_resopt[] = { + { "DEBUG", RES_DEBUG }, + { "AAONLY", RES_AAONLY }, + { "USEVC", RES_USEVC }, + { "PRIMARY", RES_PRIMARY }, + { "IGNTC", RES_IGNTC }, + { "RECURSE", RES_RECURSE }, + { "DEFNAMES", RES_DEFNAMES }, + { "STAYOPEN", RES_STAYOPEN }, + { "DNSRCH", RES_DNSRCH }, + { "INSECURE1", RES_INSECURE1 }, + { "INSECURE2", RES_INSECURE2 }, + { "NOALIASES", RES_NOALIASES }, + { "USE_INET6", RES_USE_INET6 }, + { "USE_EDNS0", RES_USE_EDNS0 }, + { "USE_DNSSEC", RES_USE_DNSSEC }, + { NULL, 0 }, +}; const char * rcodetostr(uint16_t v) @@ -187,7 +205,7 @@ strtotype(const char *name) size_t i; for(i = 0; kv_type[i].key; i++) - if (!strcmp(kv_type[i].key, name)) + if (!strcasecmp(kv_type[i].key, name)) return (kv_type[i].value); return (0); @@ -199,12 +217,52 @@ strtoclass(const char *name) size_t i; for(i = 0; kv_class[i].key; i++) - if (!strcmp(kv_class[i].key, name)) + if (!strcasecmp(kv_class[i].key, name)) return (kv_class[i].value); return (0); } +int +strtoresopt(const char *name) +{ + size_t i; + + for(i = 0; kv_resopt[i].key; i++) + if (!strcasecmp(kv_resopt[i].key, name)) + return (kv_resopt[i].value); + + return (0); +} + +void +parseresopt(const char *name) +{ + static int init = 0; + int flag, neg = 0; + + if (init == 0) { + res_init(); + init = 1; + } + + if (name[0] == '-') { + neg = 1; + name++; + } + else if (name[0] == '+') + name++; + + flag = strtoresopt(name); + if (flag == 0) + errx(1, "unknown reslover option %s", name); + + if (neg) + _res.options &= ~flag; + else + _res.options |= flag; +} + void print_hostent(struct hostent *e) { diff --git a/regress/lib/libc/asr/bin/common.h b/regress/lib/libc/asr/bin/common.h index eac806a2182..6a6b90a34f3 100644 --- a/regress/lib/libc/asr/bin/common.h +++ b/regress/lib/libc/asr/bin/common.h @@ -1,4 +1,4 @@ -/* $OpenBSD: common.h,v 1.1 2012/07/13 17:49:53 eric Exp $ */ +/* $OpenBSD: common.h,v 1.2 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -41,6 +41,8 @@ const char *rcodetostr(uint16_t); uint16_t strtotype(const char*); uint16_t strtoclass(const char*); +int strtoresopt(const char*); +void parseresopt(const char*); void print_rrsetinfo(struct rrsetinfo *); void print_addrinfo(struct addrinfo *); diff --git a/regress/lib/libc/asr/bin/getaddrinfo.c b/regress/lib/libc/asr/bin/getaddrinfo.c index 7b8674aea95..6605a00c1b8 100644 --- a/regress/lib/libc/asr/bin/getaddrinfo.c +++ b/regress/lib/libc/asr/bin/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.2 2013/03/28 09:36:03 eric Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -48,7 +48,7 @@ main(int argc, char *argv[]) memset(&hints, 0, sizeof hints); - while((ch = getopt(argc, argv, "CFHPSef:p:s:t:")) != -1) { + while((ch = getopt(argc, argv, "CFHPR:Sef:p:s:t:")) != -1) { switch(ch) { case 'C': hints.ai_flags |= AI_CANONNAME; @@ -62,6 +62,9 @@ main(int argc, char *argv[]) case 'P': hints.ai_flags |= AI_PASSIVE; break; + case 'R': + parseresopt(optarg); + break; case 'S': hints.ai_flags |= AI_NUMERICSERV; break; diff --git a/regress/lib/libc/asr/bin/gethostnamadr.c b/regress/lib/libc/asr/bin/gethostnamadr.c index b1b3e331a7e..9cdf7ed4487 100644 --- a/regress/lib/libc/asr/bin/gethostnamadr.c +++ b/regress/lib/libc/asr/bin/gethostnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr.c,v 1.2 2012/07/29 19:51:36 eric Exp $ */ +/* $OpenBSD: gethostnamadr.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -47,7 +47,7 @@ main(int argc, char *argv[]) int addrlen; aflag = 0; - while((ch = getopt(argc, argv, "46ae")) != -1) { + while((ch = getopt(argc, argv, "46R:ae")) != -1) { switch(ch) { case '4': family = AF_INET; @@ -55,6 +55,9 @@ main(int argc, char *argv[]) case '6': family = AF_INET6; break; + case 'R': + parseresopt(optarg); + break; case 'a': aflag = 1; break; diff --git a/regress/lib/libc/asr/bin/getnameinfo.c b/regress/lib/libc/asr/bin/getnameinfo.c index 3b383fa578e..bd0fbe224fc 100644 --- a/regress/lib/libc/asr/bin/getnameinfo.c +++ b/regress/lib/libc/asr/bin/getnameinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo.c,v 1.1 2012/07/13 17:49:54 eric Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -45,7 +45,7 @@ main(int argc, char *argv[]) sa = (struct sockaddr*)&ss; - while((ch = getopt(argc, argv, "DFHNSaep:")) != -1) { + while((ch = getopt(argc, argv, "DFHNR:Saep:")) != -1) { switch(ch) { case 'D': flags |= NI_DGRAM; @@ -59,6 +59,9 @@ main(int argc, char *argv[]) case 'N': flags |= NI_NAMEREQD; break; + case 'R': + parseresopt(optarg); + break; case 'S': flags |= NI_NUMERICSERV; break; diff --git a/regress/lib/libc/asr/bin/getnetnamadr.c b/regress/lib/libc/asr/bin/getnetnamadr.c index 94d17654080..e615e8663f5 100644 --- a/regress/lib/libc/asr/bin/getnetnamadr.c +++ b/regress/lib/libc/asr/bin/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.1 2012/07/13 17:49:54 eric Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -44,8 +44,11 @@ main(int argc, char *argv[]) struct netent *n; char *host; - while((ch = getopt(argc, argv, "en")) != -1) { + while((ch = getopt(argc, argv, "R:en")) != -1) { switch(ch) { + case 'R': + parseresopt(optarg); + break; case 'e': long_err += 1; break; diff --git a/regress/lib/libc/asr/bin/getrrsetbyname.c b/regress/lib/libc/asr/bin/getrrsetbyname.c index e9158c22b92..8f48501a3f2 100644 --- a/regress/lib/libc/asr/bin/getrrsetbyname.c +++ b/regress/lib/libc/asr/bin/getrrsetbyname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.1 2012/07/13 17:49:54 eric Exp $ */ +/* $OpenBSD: getrrsetbyname.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -48,8 +48,11 @@ main(int argc, char *argv[]) char *host; struct rrsetinfo *rrset; - while((ch = getopt(argc, argv, "et:")) != -1) { + while((ch = getopt(argc, argv, "R:et:")) != -1) { switch(ch) { + case 'R': + parseresopt(optarg); + break; case 'e': long_err += 1; break; diff --git a/regress/lib/libc/asr/bin/res_mkquery.c b/regress/lib/libc/asr/bin/res_mkquery.c index a37bfcf2924..b32f471cdff 100644 --- a/regress/lib/libc/asr/bin/res_mkquery.c +++ b/regress/lib/libc/asr/bin/res_mkquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_mkquery.c,v 1.1 2012/07/13 17:49:53 eric Exp $ */ +/* $OpenBSD: res_mkquery.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -59,8 +59,11 @@ main(int argc, char *argv[]) uint16_t type = T_A; char buf[1024], *host; - while((ch = getopt(argc, argv, "et:")) != -1) { + while((ch = getopt(argc, argv, "R:et:")) != -1) { switch(ch) { + case 'R': + parseresopt(optarg); + break; case 'e': long_err += 1; break; diff --git a/regress/lib/libc/asr/bin/res_query.c b/regress/lib/libc/asr/bin/res_query.c index 3565eeebed4..ca95a89a7cc 100644 --- a/regress/lib/libc/asr/bin/res_query.c +++ b/regress/lib/libc/asr/bin/res_query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_query.c,v 1.2 2017/03/09 07:56:38 eric Exp $ */ +/* $OpenBSD: res_query.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -72,8 +72,11 @@ main(int argc, char *argv[]) dflag = 0; qflag = 0; - while((ch = getopt(argc, argv, "deqt:")) != -1) { + while((ch = getopt(argc, argv, "R:deqt:")) != -1) { switch(ch) { + case 'R': + parseresopt(optarg); + break; case 'd': dflag = 1; break; |