~ubuntu-branches/ubuntu/lucid/curl/lucid-security

« back to all changes in this revision

Viewing changes to debian/patches/c-ares_ipv6

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-04-29 11:10:29 UTC
  • mfrom: (3.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090429111029-2j5eiyokfw2bw049
Tags: 7.19.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build dependencies: stunnel, libdb4.6-dev, libssh2-1-dev
  - Add build-dependency on openssh-server
  - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Call automake-1.9 with --add-missing --copy --force
* drop debian/patches/security_CVE-2009-0037.patch 
  - this patch is part of 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: trunk/lib/hostares.c
2
 
===================================================================
3
 
--- trunk.orig/lib/hostares.c   2008-06-27 03:51:47.000000000 +0200
4
 
+++ trunk/lib/hostares.c        2008-07-11 01:30:24.000000000 +0200
5
 
@@ -18,7 +18,7 @@
6
 
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
7
 
  * KIND, either express or implied.
8
 
  *
9
 
- * $Id: hostares.c,v 1.37 2008-04-29 04:18:02 yangtse Exp $
10
 
+ * $Id: hostares.c,v 1.38 2008-07-09 18:39:49 bagder Exp $
11
 
  ***************************************************************************/
12
 
 
13
 
 #include "setup.h"
14
 
@@ -297,6 +297,70 @@
15
 
   return rc;
16
 
 }
17
 
 
18
 
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
19
 
+/*
20
 
+ * Curl_ip2addr6() takes an ipv6 internet address as input parameter
21
 
+ * together with a pointer to the string version of the address, and it
22
 
+ * returns a Curl_addrinfo chain filled in correctly with information for this
23
 
+ * address/host.
24
 
+ *
25
 
+ * The input parameters ARE NOT checked for validity but they are expected
26
 
+ * to have been checked already when this is called.
27
 
+ */
28
 
+Curl_addrinfo *Curl_ip2addr6(struct in6_addr *in,
29
 
+                            const char *hostname, int port)
30
 
+{
31
 
+  Curl_addrinfo *ai;
32
 
+
33
 
+#if defined(VMS) &&  defined(__INITIAL_POINTER_SIZE) && \
34
 
+  (__INITIAL_POINTER_SIZE == 64)
35
 
+#pragma pointer_size save
36
 
+#pragma pointer_size short
37
 
+#pragma message disable PTRMISMATCH
38
 
+#endif
39
 
+
40
 
+  struct hostent *h;
41
 
+  struct in6_addr *addrentry;
42
 
+  struct namebuf6 {
43
 
+    struct hostent hostentry;
44
 
+    char *h_addr_list[2];
45
 
+    struct in6_addr addrentry;
46
 
+    char hostname[1];
47
 
+  };
48
 
+  struct namebuf6 *buf = malloc(sizeof (struct namebuf6) + strlen(hostname));
49
 
+
50
 
+  if(!buf)
51
 
+    return NULL;
52
 
+
53
 
+  h = &buf->hostentry;
54
 
+  h->h_addr_list = &buf->h_addr_list[0];
55
 
+  addrentry = &buf->addrentry;
56
 
+  memcpy(addrentry, in, sizeof (*in));
57
 
+  h->h_addr_list[0] = (char*)addrentry;
58
 
+  h->h_addr_list[1] = NULL; /* terminate list of entries */
59
 
+  h->h_name = &buf->hostname[0];
60
 
+  h->h_aliases = NULL;
61
 
+  h->h_addrtype = AF_INET6;
62
 
+
63
 
+  /* Now store the dotted version of the address */
64
 
+  strcpy (h->h_name, hostname);
65
 
+
66
 
+#if defined(VMS) && defined(__INITIAL_POINTER_SIZE) && \
67
 
+  (__INITIAL_POINTER_SIZE == 64)
68
 
+#pragma pointer_size restore
69
 
+#pragma message enable PTRMISMATCH
70
 
+#endif
71
 
+
72
 
+  ai = Curl_he2ai(h, port);
73
 
+
74
 
+  free(buf);
75
 
+
76
 
+  return ai;
77
 
+}
78
 
+#endif /* CURLRES_IPV6 */
79
 
+
80
 
+
81
 
+
82
 
 /*
83
 
  * Curl_getaddrinfo() - when using ares
84
 
  *
85
 
@@ -313,7 +377,10 @@
86
 
   char *bufp;
87
 
   struct SessionHandle *data = conn->data;
88
 
   in_addr_t in = inet_addr(hostname);
89
 
-
90
 
+  int family = PF_INET;
91
 
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
92
 
+  struct in6_addr in6;
93
 
+#endif /* CURLRES_IPV6 */
94
 
   *waitp = FALSE;
95
 
 
96
 
   if(in != CURL_INADDR_NONE) {
97
 
@@ -321,6 +388,23 @@
98
 
     return Curl_ip2addr(in, hostname, port);
99
 
   }
100
 
 
101
 
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
102
 
+  if (inet_pton (AF_INET6, hostname, &in6) > 0) {
103
 
+    /* This must be an IPv6 address literal.  */
104
 
+    return Curl_ip2addr6(&in6, hostname, port);
105
 
+  }
106
 
+
107
 
+  switch(data->set.ip_version) {
108
 
+  case CURL_IPRESOLVE_V4:
109
 
+    family = PF_INET;
110
 
+    break;
111
 
+  default: /* by default we try ipv6, as PF_UNSPEC isn't supported by (c-)ares */
112
 
+  case CURL_IPRESOLVE_V6:
113
 
+    family = PF_INET6;
114
 
+    break;
115
 
+  }
116
 
+#endif /* CURLRES_IPV6 */
117
 
+
118
 
   bufp = strdup(hostname);
119
 
 
120
 
   if(bufp) {
121
 
@@ -332,7 +416,7 @@
122
 
     conn->async.dns = NULL;   /* clear */
123
 
 
124
 
     /* areschannel is already setup in the Curl_open() function */
125
 
-    ares_gethostbyname(data->state.areschannel, hostname, PF_INET,
126
 
+    ares_gethostbyname(data->state.areschannel, hostname, family,
127
 
                        (ares_host_callback)Curl_addrinfo4_callback, conn);
128
 
 
129
 
     *waitp = TRUE; /* please wait for the response */
130
 
Index: trunk/lib/hostip4.c
131
 
===================================================================
132
 
--- trunk.orig/lib/hostip4.c    2008-06-27 03:51:47.000000000 +0200
133
 
+++ trunk/lib/hostip4.c 2008-07-11 01:31:01.000000000 +0200
134
 
@@ -5,7 +5,7 @@
135
 
  *                            | (__| |_| |  _ <| |___
136
 
  *                             \___|\___/|_| \_\_____|
137
 
  *
138
 
- * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
139
 
+ * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
140
 
  *
141
 
  * This software is licensed as described in the file COPYING, which
142
 
  * you should have received as part of this distribution. The terms
143
 
@@ -18,7 +18,7 @@
144
 
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
145
 
  * KIND, either express or implied.
146
 
  *
147
 
- * $Id: hostip4.c,v 1.42 2007-11-07 09:21:35 bagder Exp $
148
 
+ * $Id: hostip4.c,v 1.43 2008-07-09 18:39:49 bagder Exp $
149
 
  ***************************************************************************/
150
 
 
151
 
 #include "setup.h"
152
 
@@ -307,91 +307,3 @@
153
 
 #endif /* CURLRES_SYNCH */
154
 
 #endif /* CURLRES_IPV4 */
155
 
 
156
 
-/*
157
 
- * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct.
158
 
- * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6
159
 
- * stacks, but for all hosts and environments.
160
 
- *
161
 
- *   Curl_addrinfo defined in "lib/hostip.h"
162
 
- *
163
 
- *     struct Curl_addrinfo {
164
 
- *       int                   ai_flags;
165
 
- *       int                   ai_family;
166
 
- *       int                   ai_socktype;
167
 
- *       int                   ai_protocol;
168
 
- *       socklen_t             ai_addrlen;   * Follow rfc3493 struct addrinfo *
169
 
- *       char                 *ai_canonname;
170
 
- *       struct sockaddr      *ai_addr;
171
 
- *       struct Curl_addrinfo *ai_next;
172
 
- *     };
173
 
- *
174
 
- *   hostent defined in <netdb.h>
175
 
- *
176
 
- *     struct hostent {
177
 
- *       char    *h_name;
178
 
- *       char    **h_aliases;
179
 
- *       int     h_addrtype;
180
 
- *       int     h_length;
181
 
- *       char    **h_addr_list;
182
 
- *     };
183
 
- *
184
 
- *   for backward compatibility:
185
 
- *
186
 
- *     #define h_addr  h_addr_list[0]
187
 
- */
188
 
-
189
 
-Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port)
190
 
-{
191
 
-  Curl_addrinfo *ai;
192
 
-  Curl_addrinfo *prevai = NULL;
193
 
-  Curl_addrinfo *firstai = NULL;
194
 
-  struct sockaddr_in *addr;
195
 
-  int i;
196
 
-  struct in_addr *curr;
197
 
-
198
 
-  if(!he)
199
 
-    /* no input == no output! */
200
 
-    return NULL;
201
 
-
202
 
-  for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) {
203
 
-
204
 
-    ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in));
205
 
-
206
 
-    if(!ai)
207
 
-      break;
208
 
-
209
 
-    if(!firstai)
210
 
-      /* store the pointer we want to return from this function */
211
 
-      firstai = ai;
212
 
-
213
 
-    if(prevai)
214
 
-      /* make the previous entry point to this */
215
 
-      prevai->ai_next = ai;
216
 
-
217
 
-    ai->ai_family = AF_INET;              /* we only support this */
218
 
-
219
 
-    /* we return all names as STREAM, so when using this address for TFTP
220
 
-       the type must be ignored and conn->socktype be used instead! */
221
 
-    ai->ai_socktype = SOCK_STREAM;
222
 
-
223
 
-    ai->ai_addrlen = sizeof(struct sockaddr_in);
224
 
-    /* make the ai_addr point to the address immediately following this struct
225
 
-       and use that area to store the address */
226
 
-    ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo));
227
 
-
228
 
-    /* FIXME: need to free this eventually */
229
 
-    ai->ai_canonname = strdup(he->h_name);
230
 
-
231
 
-    /* leave the rest of the struct filled with zero */
232
 
-
233
 
-    addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */
234
 
-
235
 
-    memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr));
236
 
-    addr->sin_family = (unsigned short)(he->h_addrtype);
237
 
-    addr->sin_port = htons((unsigned short)port);
238
 
-
239
 
-    prevai = ai;
240
 
-  }
241
 
-  return firstai;
242
 
-}
243
 
-
244
 
Index: trunk/lib/hostip.h
245
 
===================================================================
246
 
--- trunk.orig/lib/hostip.h     2008-06-27 03:51:47.000000000 +0200
247
 
+++ trunk/lib/hostip.h  2008-07-11 01:30:55.000000000 +0200
248
 
@@ -20,7 +20,7 @@
249
 
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
250
 
  * KIND, either express or implied.
251
 
  *
252
 
- * $Id: hostip.h,v 1.61 2008-01-15 22:44:12 bagder Exp $
253
 
+ * $Id: hostip.h,v 1.62 2008-07-09 18:39:49 bagder Exp $
254
 
  ***************************************************************************/
255
 
 
256
 
 #include "setup.h"
257
 
@@ -104,6 +104,10 @@
258
 
  */
259
 
 #ifdef CURLRES_IPV6
260
 
 typedef struct addrinfo Curl_addrinfo;
261
 
+#ifdef CURLRES_ARES
262
 
+Curl_addrinfo *Curl_ip2addr6(struct in6_addr *in,
263
 
+                            const char *hostname, int port);
264
 
+#endif
265
 
 #else
266
 
 /* OK, so some ipv4-only include tree probably have the addrinfo struct, but
267
 
    to work even on those that don't, we provide our own look-alike! */
268
 
Index: trunk/CHANGES
269
 
===================================================================
270
 
--- trunk.orig/CHANGES  2008-07-11 01:26:35.000000000 +0200
271
 
+++ trunk/CHANGES       2008-07-11 01:32:29.000000000 +0200
272
 
@@ -9,6 +9,11 @@
273
 
 
274
 
 Version 7.18.2 (4 June 2008)
275
 
 
276
 
+Daniel Stenberg (9 Jul 2008)
277
 
+- Andreas Schuldei improved Phil Blundell's patch for IPv6 using c-ares, and I
278
 
+  edited it slightly. Now you should be able to use IPv6 addresses fine even
279
 
+  with libcurl built to use c-ares.
280
 
+
281
 
 Daniel Fandrich (3 Jun 2008)
282
 
 - Fixed a problem where telnet data would be lost if an EWOULDBLOCK
283
 
   condition were encountered.
284
 
Index: trunk/RELEASE-NOTES
285
 
===================================================================
286
 
--- trunk.orig/RELEASE-NOTES    2008-07-11 01:26:49.000000000 +0200
287
 
+++ trunk/RELEASE-NOTES 2008-07-11 01:35:17.000000000 +0200
288
 
@@ -15,6 +15,7 @@
289
 
  o curl can now run on Symbian OS
290
 
  o curl -w redirect_url and CURLINFO_REDIRECT_URL
291
 
  o added curl_easy_send() and curl_easy_recv()
292
 
+ o c-ares powered libcurls can resolve/use IPv6 addresses
293
 
 
294
 
 This release includes the following bugfixes:
295
 
 
296
 
@@ -64,5 +65,6 @@
297
 
  David Shaw, Norbert Frese, Bart Whiteley, Jean-Francois Bertrand, Ben Van Hof,
298
 
  Yuriy Sosov, Christopher Palow, Yang Tse, Liam Healy, Nikolai Kondrashov,
299
 
  David Rosenstrauch, Andreas Faerber, Scott McCreary, Jeff Weber, Emil Romanus
300
 
+ Rolland Dudemaine, Phil Blundell, Scott Barrett, Andreas Schuldei
301
 
 
302
 
-        Thanks! (and sorry if I forgot to mention someone)
303
 
+     Thanks! (and sorry if I forgot to mention someone)
304
 
Index: trunk/lib/hostip.c
305
 
===================================================================
306
 
--- trunk.orig/lib/hostip.c     2008-07-11 01:25:33.000000000 +0200
307
 
+++ trunk/lib/hostip.c  2008-07-11 01:30:45.000000000 +0200
308
 
@@ -18,7 +18,7 @@
309
 
  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
310
 
  * KIND, either express or implied.
311
 
  *
312
 
- * $Id: hostip.c,v 1.191 2008-03-11 22:55:24 bagder Exp $
313
 
+ * $Id: hostip.c,v 1.192 2008-07-09 18:39:49 bagder Exp $
314
 
  ***************************************************************************/
315
 
 
316
 
 #include "setup.h"
317
 
@@ -545,7 +545,8 @@
318
 
 #endif /* CURLRES_ADDRINFO_COPY */
319
 
 
320
 
 /***********************************************************************
321
 
- * Only for plain-ipv4 and c-ares builds
322
 
+ * Only for plain-ipv4 and c-ares builds (NOTE: c-ares builds can be IPv6
323
 
+ * enabled)
324
 
  **********************************************************************/
325
 
 
326
 
 #if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
327
 
@@ -630,6 +631,118 @@
328
 
 
329
 
   return ai;
330
 
 }
331
 
-#endif /* CURLRES_IPV4 || CURLRES_ARES */
332
 
 
333
 
+/*
334
 
+ * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct.
335
 
+ * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6
336
 
+ * stacks, but for all hosts and environments.
337
 
+ *
338
 
+ *   Curl_addrinfo defined in "lib/hostip.h"
339
 
+ *
340
 
+ *     struct Curl_addrinfo {
341
 
+ *       int                   ai_flags;
342
 
+ *       int                   ai_family;
343
 
+ *       int                   ai_socktype;
344
 
+ *       int                   ai_protocol;
345
 
+ *       socklen_t             ai_addrlen;   * Follow rfc3493 struct addrinfo *
346
 
+ *       char                 *ai_canonname;
347
 
+ *       struct sockaddr      *ai_addr;
348
 
+ *       struct Curl_addrinfo *ai_next;
349
 
+ *     };
350
 
+ *
351
 
+ *   hostent defined in <netdb.h>
352
 
+ *
353
 
+ *     struct hostent {
354
 
+ *       char    *h_name;
355
 
+ *       char    **h_aliases;
356
 
+ *       int     h_addrtype;
357
 
+ *       int     h_length;
358
 
+ *       char    **h_addr_list;
359
 
+ *     };
360
 
+ *
361
 
+ *   for backward compatibility:
362
 
+ *
363
 
+ *     #define h_addr  h_addr_list[0]
364
 
+ */
365
 
+
366
 
+Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port)
367
 
+{
368
 
+  Curl_addrinfo *ai;
369
 
+  Curl_addrinfo *prevai = NULL;
370
 
+  Curl_addrinfo *firstai = NULL;
371
 
+  struct sockaddr_in *addr;
372
 
+#ifdef CURLRES_IPV6
373
 
+  struct sockaddr_in6 *addr6;
374
 
+#endif /* CURLRES_IPV6 */
375
 
+  int i;
376
 
+  struct in_addr *curr;
377
 
+
378
 
+  if(!he)
379
 
+    /* no input == no output! */
380
 
+    return NULL;
381
 
+
382
 
+  for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) {
383
 
+
384
 
+    int ss_size;
385
 
+#ifdef CURLRES_IPV6
386
 
+    if (he->h_addrtype == AF_INET6)
387
 
+      ss_size = sizeof (struct sockaddr_in6);
388
 
+    else
389
 
+#endif /* CURLRES_IPV6 */
390
 
+      ss_size = sizeof (struct sockaddr_in);
391
 
+
392
 
+    ai = calloc(1, sizeof(Curl_addrinfo) + ss_size);
393
 
+
394
 
+    if(!ai)
395
 
+      break;
396
 
 
397
 
+    if(!firstai)
398
 
+      /* store the pointer we want to return from this function */
399
 
+      firstai = ai;
400
 
+
401
 
+    if(prevai)
402
 
+      /* make the previous entry point to this */
403
 
+      prevai->ai_next = ai;
404
 
+
405
 
+    ai->ai_family = he->h_addrtype;
406
 
+
407
 
+    /* we return all names as STREAM, so when using this address for TFTP
408
 
+       the type must be ignored and conn->socktype be used instead! */
409
 
+    ai->ai_socktype = SOCK_STREAM;
410
 
+
411
 
+    ai->ai_addrlen = ss_size;
412
 
+    /* make the ai_addr point to the address immediately following this struct
413
 
+       and use that area to store the address */
414
 
+    ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo));
415
 
+
416
 
+    /* need to free this eventually */
417
 
+    ai->ai_canonname = strdup(he->h_name);
418
 
+
419
 
+    /* leave the rest of the struct filled with zero */
420
 
+
421
 
+    switch (ai->ai_family) {
422
 
+    case AF_INET:
423
 
+      addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */
424
 
+
425
 
+      memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr));
426
 
+      addr->sin_family = (unsigned short)(he->h_addrtype);
427
 
+      addr->sin_port = htons((unsigned short)port);
428
 
+      break;
429
 
+
430
 
+#ifdef CURLRES_IPV6
431
 
+    case AF_INET6:
432
 
+      addr6 = (struct sockaddr_in6 *)ai->ai_addr; /* storage area for this info */
433
 
+
434
 
+      memcpy((char *)&(addr6->sin6_addr), curr, sizeof(struct in6_addr));
435
 
+      addr6->sin6_family = (unsigned short)(he->h_addrtype);
436
 
+      addr6->sin6_port = htons((unsigned short)port);
437
 
+      break;
438
 
+#endif /* CURLRES_IPV6 */
439
 
+    }
440
 
+
441
 
+    prevai = ai;
442
 
+  }
443
 
+  return firstai;
444
 
+}
445
 
+
446
 
+#endif /* CURLRES_IPV4 || CURLRES_ARES */