diff options
author | matthew <> | 2011-04-05 00:46:06 +0000 |
---|---|---|
committer | matthew <> | 2011-04-05 00:46:06 +0000 |
commit | fdfda2c4a3a790b78f76218ca8a933bfd3944b84 (patch) | |
tree | 32474a7e93d1846732d6afba56dff16944ca0129 | |
parent | 515602fafdedd66b15c0d7c6a1902217acea3b8e (diff) | |
download | openbsd-fdfda2c4a3a790b78f76218ca8a933bfd3944b84.tar.gz openbsd-fdfda2c4a3a790b78f76218ca8a933bfd3944b84.tar.bz2 openbsd-fdfda2c4a3a790b78f76218ca8a933bfd3944b84.zip |
Add AI_FQDN flag to getaddrinfo(3). Prompted by discussions with djm@
about cert checking in OpenSSH. Man page wording tweaks thanks to
jmc@.
ok henning@, jmc@; positive feedback from djm@, ajacoutat@
Committing now to reuse guenther@'s libc minor bump instead of
cranking it again, as suggested by deraadt@.
-rw-r--r-- | src/lib/libc/net/getaddrinfo.3 | 32 | ||||
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 36 |
2 files changed, 46 insertions, 22 deletions
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 index 7250407d65..da6e64683f 100644 --- a/src/lib/libc/net/getaddrinfo.3 +++ b/src/lib/libc/net/getaddrinfo.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: getaddrinfo.3,v 1.47 2009/07/09 10:14:41 eric Exp $ | 1 | .\" $OpenBSD: getaddrinfo.3,v 1.48 2011/04/05 00:46:06 matthew Exp $ |
2 | .\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ | 2 | .\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | 4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") |
@@ -16,7 +16,7 @@ | |||
16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | 16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
17 | .\" PERFORMANCE OF THIS SOFTWARE. | 17 | .\" PERFORMANCE OF THIS SOFTWARE. |
18 | .\" | 18 | .\" |
19 | .Dd $Mdocdate: July 9 2009 $ | 19 | .Dd $Mdocdate: April 5 2011 $ |
20 | .Dt GETADDRINFO 3 | 20 | .Dt GETADDRINFO 3 |
21 | .Os | 21 | .Os |
22 | .Sh NAME | 22 | .Sh NAME |
@@ -126,11 +126,33 @@ If the | |||
126 | bit is set, a successful call to | 126 | bit is set, a successful call to |
127 | .Fn getaddrinfo | 127 | .Fn getaddrinfo |
128 | will return a NUL-terminated string containing the canonical name | 128 | will return a NUL-terminated string containing the canonical name |
129 | of the specified hostname in the | 129 | of the specified host name in the |
130 | .Fa ai_canonname | 130 | .Fa ai_canonname |
131 | element of the first | 131 | element of the first |
132 | .Li addrinfo | 132 | .Li addrinfo |
133 | structure returned. | 133 | structure returned. |
134 | .It Dv AI_FQDN | ||
135 | If the | ||
136 | .Dv AI_FQDN | ||
137 | bit is set, a successful call to | ||
138 | .Fn getaddrinfo | ||
139 | will return a NUL-terminated string containing the fully qualified domain name | ||
140 | of the specified host name in the | ||
141 | .Fa ai_canonname | ||
142 | element of the first | ||
143 | .Li addrinfo | ||
144 | structure returned. | ||
145 | .Pp | ||
146 | This is different from the | ||
147 | .Dv AI_CANONNAME | ||
148 | bit flag that returns the canonical name registered in DNS, | ||
149 | which may be different from the fully qualified domain name | ||
150 | that the host name resolved to. | ||
151 | Only one of the | ||
152 | .Dv AI_FQDN | ||
153 | and | ||
154 | .Dv AI_CANONNAME | ||
155 | bits can be set. | ||
134 | .It Dv AI_NUMERICHOST | 156 | .It Dv AI_NUMERICHOST |
135 | If the | 157 | If the |
136 | .Dv AI_NUMERICHOST | 158 | .Dv AI_NUMERICHOST |
@@ -438,6 +460,10 @@ function is defined by the | |||
438 | draft specification and documented in | 460 | draft specification and documented in |
439 | .Dv "RFC 3493" , | 461 | .Dv "RFC 3493" , |
440 | .Dq Basic Socket Interface Extensions for IPv6 . | 462 | .Dq Basic Socket Interface Extensions for IPv6 . |
463 | .Pp | ||
464 | The | ||
465 | .Dv AI_FQDN | ||
466 | flag bit first appeared in Windows 7. | ||
441 | .Sh BUGS | 467 | .Sh BUGS |
442 | The implementation of | 468 | The implementation of |
443 | .Fn getaddrinfo | 469 | .Fn getaddrinfo |
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 7040fa7c37..29cc1f463e 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.71 2009/11/18 07:43:22 guenther Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.72 2011/04/05 00:46:06 matthew Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -309,7 +309,9 @@ getaddrinfo(const char *hostname, const char *servname, | |||
309 | if (hints->ai_addrlen || hints->ai_canonname || | 309 | if (hints->ai_addrlen || hints->ai_canonname || |
310 | hints->ai_addr || hints->ai_next) | 310 | hints->ai_addr || hints->ai_next) |
311 | ERR(EAI_BADHINTS); /* xxx */ | 311 | ERR(EAI_BADHINTS); /* xxx */ |
312 | if (hints->ai_flags & ~AI_MASK) | 312 | if ((hints->ai_flags & ~AI_MASK) != 0 || |
313 | (hints->ai_flags & (AI_CANONNAME | AI_FQDN)) == | ||
314 | (AI_CANONNAME | AI_FQDN)) | ||
313 | ERR(EAI_BADFLAGS); | 315 | ERR(EAI_BADFLAGS); |
314 | switch (hints->ai_family) { | 316 | switch (hints->ai_family) { |
315 | case PF_UNSPEC: | 317 | case PF_UNSPEC: |
@@ -671,14 +673,13 @@ explore_numeric(const struct addrinfo *pai, const char *hostname, | |||
671 | pai->ai_family == PF_UNSPEC /*?*/) { | 673 | pai->ai_family == PF_UNSPEC /*?*/) { |
672 | GET_AI(cur->ai_next, afd, pton); | 674 | GET_AI(cur->ai_next, afd, pton); |
673 | GET_PORT(cur->ai_next, servname); | 675 | GET_PORT(cur->ai_next, servname); |
674 | if ((pai->ai_flags & AI_CANONNAME)) { | 676 | /* |
675 | /* | 677 | * Set the numeric address itself as |
676 | * Set the numeric address itself as | 678 | * the canonical name, based on a |
677 | * the canonical name, based on a | 679 | * clarification in rfc2553bis-03. |
678 | * clarification in rfc2553bis-03. | 680 | */ |
679 | */ | 681 | GET_CANONNAME(cur->ai_next, canonname); |
680 | GET_CANONNAME(cur->ai_next, canonname); | 682 | |
681 | } | ||
682 | while (cur && cur->ai_next) | 683 | while (cur && cur->ai_next) |
683 | cur = cur->ai_next; | 684 | cur = cur->ai_next; |
684 | } else | 685 | } else |
@@ -764,7 +765,7 @@ explore_numeric_scope(const struct addrinfo *pai, const char *hostname, | |||
764 | static int | 765 | static int |
765 | get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str) | 766 | get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str) |
766 | { | 767 | { |
767 | if ((pai->ai_flags & AI_CANONNAME) != 0) { | 768 | if ((pai->ai_flags & (AI_CANONNAME | AI_FQDN)) != 0) { |
768 | ai->ai_canonname = strdup(str); | 769 | ai->ai_canonname = strdup(str); |
769 | if (ai->ai_canonname == NULL) | 770 | if (ai->ai_canonname == NULL) |
770 | return EAI_MEMORY; | 771 | return EAI_MEMORY; |
@@ -1129,7 +1130,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, | |||
1129 | haveanswer++; | 1130 | haveanswer++; |
1130 | } | 1131 | } |
1131 | if (haveanswer) { | 1132 | if (haveanswer) { |
1132 | if (!canonname) | 1133 | if (!canonname || (pai->ai_flags & AI_FQDN) != 0) |
1133 | (void)get_canonname(pai, sentinel.ai_next, qname); | 1134 | (void)get_canonname(pai, sentinel.ai_next, qname); |
1134 | else | 1135 | else |
1135 | (void)get_canonname(pai, sentinel.ai_next, canonname); | 1136 | (void)get_canonname(pai, sentinel.ai_next, canonname); |
@@ -1275,11 +1276,9 @@ found: | |||
1275 | /* cover it up */ | 1276 | /* cover it up */ |
1276 | res->ai_flags = pai->ai_flags; | 1277 | res->ai_flags = pai->ai_flags; |
1277 | 1278 | ||
1278 | if (pai->ai_flags & AI_CANONNAME) { | 1279 | if (get_canonname(pai, res, cname) != 0) { |
1279 | if (get_canonname(pai, res, cname) != 0) { | 1280 | freeaddrinfo(res0); |
1280 | freeaddrinfo(res0); | 1281 | goto again; |
1281 | goto again; | ||
1282 | } | ||
1283 | } | 1282 | } |
1284 | } | 1283 | } |
1285 | return res0; | 1284 | return res0; |
@@ -1369,8 +1368,7 @@ nextline: | |||
1369 | /* cover it up */ | 1368 | /* cover it up */ |
1370 | res->ai_flags = pai->ai_flags; | 1369 | res->ai_flags = pai->ai_flags; |
1371 | 1370 | ||
1372 | if (pai->ai_flags & AI_CANONNAME) | 1371 | (void)get_canonname(pai, res, canonname); |
1373 | (void)get_canonname(pai, res, canonname); | ||
1374 | } | 1372 | } |
1375 | } else | 1373 | } else |
1376 | res0 = NULL; | 1374 | res0 = NULL; |