1 diff -urN cvs-1.11.9.org/src/client.c cvs-1.11.9/src/client.c
2 --- cvs-1.11.9.org/src/client.c 2003-10-15 19:28:25.000000000 +0200
3 +++ cvs-1.11.9/src/client.c 2003-10-15 19:28:34.000000000 +0200
5 /* This is needed for GSSAPI encryption. */
6 static gss_ctx_id_t gcontext;
8 -static int connect_to_gserver PROTO((cvsroot_t *, int, struct hostent *));
9 +static int connect_to_gserver PROTO((cvsroot_t *, int, char *));
11 # endif /* HAVE_GSSAPI */
14 static size_t try_read_from_server PROTO ((char *, size_t));
16 static void auth_server PROTO ((cvsroot_t *, struct buffer *, struct buffer *,
17 - int, int, struct hostent *));
20 /* We need to keep track of the list of directories we've sent to the
21 server. This list, along with the current CVSROOT, will help us
22 @@ -3487,30 +3487,6 @@
25 #if defined (AUTH_CLIENT_SUPPORT) || defined (HAVE_KERBEROS) || defined (HAVE_GSSAPI)
26 -static struct hostent *init_sockaddr PROTO ((struct sockaddr_in *, char *,
29 -static struct hostent *
30 -init_sockaddr (name, hostname, port)
31 - struct sockaddr_in *name;
35 - struct hostent *hostinfo;
36 - unsigned short shortport = port;
38 - memset (name, 0, sizeof (*name));
39 - name->sin_family = AF_INET;
40 - name->sin_port = htons (shortport);
41 - hostinfo = gethostbyname (hostname);
42 - if (hostinfo == NULL)
44 - fprintf (stderr, "Unknown host %s.\n", hostname);
47 - name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
53 @@ -3685,34 +3661,59 @@
58 - struct sockaddr_in client_sai;
59 - struct hostent *hostinfo;
61 + struct addrinfo hints, *res, *res0;
63 struct buffer *to_server, *from_server;
65 - sock = socket (AF_INET, SOCK_STREAM, 0);
67 + sprintf (pbuf, "%u", get_cvs_port_number (root));
68 + pbuf[sizeof(pbuf)-1] = '\0';
69 + memset (&hints, 0, sizeof (hints));
70 + hints.ai_family = af;
71 + hints.ai_socktype = SOCK_STREAM;
72 + gerr = getaddrinfo (root->hostname, pbuf, &hints, &res0);
75 - error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
76 + fprintf (stderr, "Unknown host %s.\n", root->hostname);
79 - port_number = get_cvs_port_number (root);
80 - hostinfo = init_sockaddr (&client_sai, root->hostname, port_number);
83 + /* Try connect to current_parsed_root->hostname using all available families */
84 + for (res = res0; res != NULL; res = res->ai_next)
86 - fprintf (stderr, " -> Connecting to %s(%s):%d\n",
88 - inet_ntoa (client_sai.sin_addr), port_number);
90 - if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai))
92 - error (1, 0, "connect to %s(%s):%d failed: %s",
94 - inet_ntoa (client_sai.sin_addr),
95 - port_number, SOCK_STRERROR (SOCK_ERRNO));
96 + sock = socket (res->ai_family, res->ai_socktype, 0);
101 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
102 + freeaddrinfo(res0);
103 + error (1, 0, "cannot create socket: %s", sock_error);
107 + if (connect (sock, res->ai_addr, res->ai_addrlen) < 0)
116 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
117 + freeaddrinfo(res0);
118 + error (1, 0, "connect to [%s]:%s failed: %s", root->hostname,
126 make_bufs_from_fds (sock, sock, 0, &to_server, &from_server, 1);
128 - auth_server (root, to_server, from_server, verify_only, do_gssapi, hostinfo);
129 + auth_server (root, to_server, from_server, verify_only, do_gssapi, root->hostname);
133 @@ -3746,13 +3747,13 @@
137 -auth_server (root, lto_server, lfrom_server, verify_only, do_gssapi, hostinfo)
138 +auth_server (root, lto_server, lfrom_server, verify_only, do_gssapi, hostname)
140 struct buffer *lto_server;
141 struct buffer *lfrom_server;
144 - struct hostent *hostinfo;
147 char *username; /* the username we use to connect */
148 char no_passwd = 0; /* gets set if no password found */
149 @@ -3782,7 +3783,7 @@
150 error (1, 0, "gserver currently only enabled for socket connections");
153 - if (! connect_to_gserver (root, fd, hostinfo))
154 + if (! connect_to_gserver (root, fd, hostname))
157 "authorization failed: server %s rejected access to %s",
158 @@ -3798,7 +3799,7 @@
160 char *password = NULL;
166 begin = "BEGIN VERIFICATION REQUEST";
167 @@ -3979,36 +3980,75 @@
171 - struct hostent *hp;
172 - struct sockaddr_in sin;
174 + struct addrinfo hints, *res, *res0;
177 - s = socket (AF_INET, SOCK_STREAM, 0);
179 - error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
180 + char pbuf[32], hbuf[1025];
182 port = get_cvs_port_number (root);
184 - hp = init_sockaddr (&sin, root->hostname, port);
186 - hname = xstrdup (hp->h_name);
189 + sprintf (pbuf, "%u", port);
190 + pbuf[sizeof(pbuf)-1] = '\0';
191 + memset (&hints, 0, sizeof(hints));
192 + hints.ai_family = af;
193 + hints.ai_socktype = SOCK_STREAM;
194 + gerr = getaddrinfo (root->hostname, pbuf, &hints, &res0);
197 - fprintf (stderr, " -> Connecting to %s(%s):%d\n",
199 - inet_ntoa (sin.sin_addr), port);
200 + fprintf (stderr, "Unknown host %s.\n", root->hostname);
204 - if (connect (s, (struct sockaddr *) &sin, sizeof sin) < 0)
205 - error (1, 0, "connect to %s(%s):%d failed: %s",
207 - inet_ntoa (sin.sin_addr),
208 - port, SOCK_STRERROR (SOCK_ERRNO));
209 + /* Try connect to current_parsed_root->hostname using all available families */
211 + for (res = res0; res != NULL; res = res->ai_next)
213 + s = socket (res->ai_family, res->ai_socktype, 0);
220 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
221 + freeaddrinfo(res0);
222 + error (1, 0, "cannot create socket: %s", sock_error);
228 + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
229 + NULL, 0, NI_NUMERICHOST);
230 + fprintf (stderr, " -> Connecting to %s(%s):%d\n",
231 + root->hostname, hbuf, port);
234 + if (connect (s, res->ai_addr, res->ai_addrlen) < 0)
243 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
244 + freeaddrinfo(res0);
245 + error (1, 0, "connect to [%s]:%s failed: %s",
246 + root->hostname, pbuf, sock_error);
249 + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), NULL, 0, 0);
250 + hname = xstrdup (hbuf);
254 + freeaddrinfo(res0);
258 - struct sockaddr_in laddr;
259 + struct sockaddr_storage laddr;
263 @@ -4084,10 +4124,10 @@
267 -connect_to_gserver (root, sock, hostinfo)
268 +connect_to_gserver (root, sock, hostname)
271 - struct hostent *hostinfo;
276 @@ -4100,9 +4140,9 @@
277 if (send (sock, str, strlen (str), 0) < 0)
278 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
280 - if (strlen (hostinfo->h_name) > BUFSIZE - 5)
281 + if (strlen (hostname) > BUFSIZE - 5)
282 error (1, 0, "Internal error: hostname exceeds length of buffer");
283 - sprintf (buf, "cvs@%s", hostinfo->h_name);
284 + sprintf (buf, "cvs@%s", hostname);
285 tok_in.length = strlen (buf);
287 gss_import_name (&stat_min, &tok_in, GSS_C_NT_HOSTBASED_SERVICE,
288 diff -urN cvs-1.11.9.org/src/cvs.h cvs-1.11.9/src/cvs.h
289 --- cvs-1.11.9.org/src/cvs.h 2003-10-15 19:28:25.000000000 +0200
290 +++ cvs-1.11.9/src/cvs.h 2003-10-15 19:28:34.000000000 +0200
292 extern int really_quiet, quiet;
293 extern int use_editor;
296 extern mode_t cvsumask;
299 diff -urN cvs-1.11.9.org/src/main.c cvs-1.11.9/src/main.c
300 --- cvs-1.11.9.org/src/main.c 2003-10-15 19:28:25.000000000 +0200
301 +++ cvs-1.11.9/src/main.c 2003-10-15 19:28:34.000000000 +0200
306 +#include <sys/socket.h>
309 #ifdef HAVE_WINSOCK_H
316 /* Set if we should be writing CVSADM directories at top level. At
317 least for now we'll make the default be off (the CVS 1.9, not CVS
319 in --help as it is a rather different format from the rest. */
321 "Usage: %s [cvs-options] command [command-options-and-arguments]\n",
322 - " where cvs-options are -q, -n, etc.\n",
323 + " where cvs-options are -4, -6,-q, -n, etc.\n",
324 " (specify --help-options for a list of options)\n",
325 " where command is add, admin, etc.\n",
326 " (specify --help-commands for a list of commands\n",
328 int help = 0; /* Has the user asked for help? This
329 lets us support the `cvs -H cmd'
330 convention to give help for cmd. */
331 - static const char short_options[] = "+Qqrwtnvb:T:e:d:Hfz:s:xa";
332 + static const char short_options[] = "+46Qqrwtnvb:T:e:d:Hfz:s:xa";
333 static struct option long_options[] =
335 {"help", 0, NULL, 'H'},
338 root_allow_add (optarg);
349 diff -urN cvs-1.11.9.org/src/server.c cvs-1.11.9/src/server.c
350 --- cvs-1.11.9.org/src/server.c 2003-10-15 19:28:25.000000000 +0200
351 +++ cvs-1.11.9/src/server.c 2003-10-15 19:29:16.000000000 +0200
352 @@ -5756,8 +5756,8 @@
355 char instance[INST_SZ];
356 - struct sockaddr_in peer;
357 - struct sockaddr_in laddr;
358 + struct sockaddr_storage peer;
359 + struct sockaddr_storage laddr;
363 @@ -5834,7 +5834,8 @@
364 gserver_authenticate_connection ()
366 char hostname[MAXHOSTNAMELEN];
367 - struct hostent *hp;
369 + struct addrinfo hints, *res0;
370 gss_buffer_desc tok_in, tok_out;
372 OM_uint32 stat_min, ret;
373 @@ -5844,11 +5845,16 @@
376 gethostname (hostname, sizeof hostname);
377 - hp = gethostbyname (hostname);
379 + hostname[sizeof(hostname)-1] = '\0';
380 + memset (&hints, 0, sizeof(hints));
381 + hints.ai_family = af;
382 + hints.ai_socktype = SOCK_STREAM;
383 + hints.ai_flags = AI_CANONNAME;
384 + if (getaddrinfo (hostname, NULL, &hints, &res0))
385 error (1, 0, "can't get canonical hostname");
387 - sprintf (buf, "cvs@%s", hp->h_name);
388 + sprintf (buf, "cvs@%s", res0->ai_canonname);
389 + freeaddrinfo (res0);
391 tok_in.length = strlen (buf);