1 diff -urN cvs-1.11.2.org/src/client.c cvs-1.11.2/src/client.c
2 --- cvs-1.11.2.org/src/client.c Mon May 13 22:32:42 2002
3 +++ cvs-1.11.2/src/client.c Mon May 13 23:18:44 2002
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 @@ -3646,30 +3646,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 @@ -3871,34 +3841,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 @@ -3930,13 +3925,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 @@ -3965,7 +3960,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 @@ -3980,7 +3975,7 @@
160 char *password = NULL;
166 begin = "BEGIN VERIFICATION REQUEST";
167 @@ -4117,37 +4112,76 @@
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 = xmalloc (strlen (hp->h_name) + 1);
187 - strcpy (hname, hp->h_name);
190 + sprintf (pbuf, "%u", port);
191 + pbuf[sizeof(pbuf)-1] = '\0';
192 + memset (&hints, 0, sizeof(hints));
193 + hints.ai_family = af;
194 + hints.ai_socktype = SOCK_STREAM;
195 + gerr = getaddrinfo (root->hostname, pbuf, &hints, &res0);
198 - fprintf (stderr, " -> Connecting to %s(%s):%d\n",
200 - inet_ntoa (sin.sin_addr), port);
201 + fprintf (stderr, "Unknown host %s.\n", root->hostname);
205 - if (connect (s, (struct sockaddr *) &sin, sizeof sin) < 0)
206 - error (1, 0, "connect to %s(%s):%d failed: %s",
208 - inet_ntoa (sin.sin_addr),
209 - port, SOCK_STRERROR (SOCK_ERRNO));
210 + /* Try connect to current_parsed_root->hostname using all available families */
212 + for (res = res0; res != NULL; res = res->ai_next)
214 + s = socket (res->ai_family, res->ai_socktype, 0);
221 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
222 + freeaddrinfo(res0);
223 + error (1, 0, "cannot create socket: %s", sock_error);
229 + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf),
230 + NULL, 0, NI_NUMERICHOST);
231 + fprintf (stderr, " -> Connecting to %s(%s):%d\n",
232 + root->hostname, hbuf, port);
235 + if (connect (s, res->ai_addr, res->ai_addrlen) < 0)
244 + char *sock_error = SOCK_STRERROR (SOCK_ERRNO);
245 + freeaddrinfo(res0);
246 + error (1, 0, "connect to [%s]:%s failed: %s",
247 + root->hostname, pbuf, sock_error);
250 + getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), NULL, 0, 0);
251 + hname = xmalloc (strlen (hbuf) + 1);
252 + strcpy (hname, hbuf);
256 + freeaddrinfo(res0);
260 - struct sockaddr_in laddr;
261 + struct sockaddr_storage laddr;
265 @@ -4222,10 +4256,10 @@
269 -connect_to_gserver (root, sock, hostinfo)
270 +connect_to_gserver (root, sock, hostname)
273 - struct hostent *hostinfo;
278 @@ -4238,9 +4272,9 @@
279 if (send (sock, str, strlen (str), 0) < 0)
280 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
282 - if (strlen (hostinfo->h_name) > BUFSIZE - 5)
283 + if (strlen (hostname) > BUFSIZE - 5)
284 error (1, 0, "Internal error: hostname exceeds length of buffer");
285 - sprintf (buf, "cvs@%s", hostinfo->h_name);
286 + sprintf (buf, "cvs@%s", hostname);
287 tok_in.length = strlen (buf);
289 gss_import_name (&stat_min, &tok_in, GSS_C_NT_HOSTBASED_SERVICE,
290 diff -urN cvs-1.11.2.org/src/cvs.h cvs-1.11.2/src/cvs.h
291 --- cvs-1.11.2.org/src/cvs.h Mon May 13 22:32:42 2002
292 +++ cvs-1.11.2/src/cvs.h Mon May 13 22:32:57 2002
294 extern int really_quiet, quiet;
295 extern int use_editor;
298 extern mode_t cvsumask;
301 diff -urN cvs-1.11.2.org/src/main.c cvs-1.11.2/src/main.c
302 --- cvs-1.11.2.org/src/main.c Mon May 13 22:32:42 2002
303 +++ cvs-1.11.2/src/main.c Mon May 13 22:32:57 2002
308 +#include <sys/socket.h>
311 #ifdef HAVE_WINSOCK_H
318 /* Set if we should be writing CVSADM directories at top level. At
319 least for now we'll make the default be off (the CVS 1.9, not CVS
321 in --help as it is a rather different format from the rest. */
323 "Usage: %s [cvs-options] command [command-options-and-arguments]\n",
324 - " where cvs-options are -q, -n, etc.\n",
325 + " where cvs-options are -4, -6,-q, -n, etc.\n",
326 " (specify --help-options for a list of options)\n",
327 " where command is add, admin, etc.\n",
328 " (specify --help-commands for a list of commands\n",
330 int help = 0; /* Has the user asked for help? This
331 lets us support the `cvs -H cmd'
332 convention to give help for cmd. */
333 - static const char short_options[] = "+Qqrwtnlvb:T:e:d:Hfz:s:xa";
334 + static const char short_options[] = "+46Qqrwtnlvb:T:e:d:Hfz:s:xa";
335 static struct option long_options[] =
337 {"help", 0, NULL, 'H'},
340 root_allow_add (optarg);
351 diff -urN cvs-1.11.2.org/src/server.c cvs-1.11.2/src/server.c
352 --- cvs-1.11.2.org/src/server.c Mon May 13 22:32:42 2002
353 +++ cvs-1.11.2/src/server.c Mon May 13 22:32:57 2002
354 @@ -5895,8 +5895,8 @@
357 char instance[INST_SZ];
358 - struct sockaddr_in peer;
359 - struct sockaddr_in laddr;
360 + struct sockaddr_storage peer;
361 + struct sockaddr_storage laddr;
365 @@ -5985,7 +5985,8 @@
366 gserver_authenticate_connection ()
368 char hostname[MAXHOSTNAMELEN];
369 - struct hostent *hp;
371 + struct addrinfo hints, *res0;
372 gss_buffer_desc tok_in, tok_out;
374 OM_uint32 stat_min, ret;
375 @@ -5995,11 +5996,16 @@
378 gethostname (hostname, sizeof hostname);
379 - hp = gethostbyname (hostname);
381 + hostname[sizeof(hostname)-1] = '\0';
382 + memset (&hints, 0, sizeof(hints));
383 + hints.ai_family = af;
384 + hints.ai_socktype = SOCK_STREAM;
385 + hints.ai_flags = AI_CANONNAME;
386 + if (getaddrinfo (hostname, NULL, &hints, &res))
387 error (1, 0, "can't get canonical hostname");
389 - sprintf (buf, "cvs@%s", hp->h_name);
390 + sprintf (buf, "cvs@%s", res0->ai_canonname);
391 + freeaddrinfo (res0);
393 tok_in.length = strlen (buf);