]> git.pld-linux.org Git - packages/samba.git/blame - samba-2.2.4+IPv6-20020609.diff
- more specific Requires
[packages/samba.git] / samba-2.2.4+IPv6-20020609.diff
CommitLineData
5cd408db 1diff -ur samba-2.2.4/source/acconfig.h samba-2.2.4+IPv6-20020609/source/acconfig.h
2--- samba-2.2.4/source/acconfig.h Thu May 2 21:02:26 2002
3+++ samba-2.2.4+IPv6-20020609/source/acconfig.h Sun May 19 15:13:29 2002
4@@ -59,6 +59,7 @@
5 #undef WITH_SYSLOG
6 #undef WITH_PROFILE
7 #undef WITH_SSL
8+#undef HAVE_INET6
9 #undef WITH_LDAP
10 #undef WITH_NISPLUS
11 #undef WITH_TDBPWD
12diff -ur samba-2.2.4/source/client/client.c samba-2.2.4+IPv6-20020609/source/client/client.c
13--- samba-2.2.4/source/client/client.c Thu May 2 21:02:58 2002
14+++ samba-2.2.4+IPv6-20020609/source/client/client.c Sun May 19 15:19:01 2002
15@@ -30,7 +30,7 @@
16 struct cli_state *cli;
17 extern BOOL in_client;
18 extern BOOL AllowDebugChange;
19-static int port = SMB_PORT;
20+static int port = 0;
21 pstring cur_dir = "\\";
22 pstring cd_path = "";
23 static pstring service;
24@@ -80,7 +80,7 @@
25 static BOOL recurse = False;
26 BOOL lowercase = False;
27
28-struct in_addr dest_ip;
29+char dest_ip[512];
30
31 #define SEPARATORS " \t\n\r"
32
33@@ -2145,8 +2145,8 @@
34 struct cli_state *c;
35 struct nmb_name called, calling;
36 char *server_n;
37- struct in_addr ip;
38 fstring servicename;
39+ struct sockaddr_list *salist;
40 char *sharename;
41
42 /* make a copy so we don't modify the global string 'service' */
43@@ -2162,21 +2162,18 @@
44
45 server_n = server;
46
47- zero_ip(&ip);
48-
49 make_nmb_name(&calling, global_myname, 0x0);
50 make_nmb_name(&called , server, name_type);
51
52 again:
53- zero_ip(&ip);
54- if (have_ip) ip = dest_ip;
55-
56- /* have to open a new connection */
57- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) == 0) ||
58- !cli_connect(c, server_n, &ip)) {
59- DEBUG(0,("Connection to %s failed\n", server_n));
60- return NULL;
61- }
62+ salist = resolve_name_smb(have_ip ? dest_ip : server_n, port);
63+
64+ /* have to open a new connection */
65+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, salist)) {
66+ DEBUG(0,("Connection to %s failed\n", server_n));
67+ free_sockaddr_list(salist);
68+ return NULL;
69+ }
70
71 c->protocol = max_protocol;
72
73@@ -2414,21 +2411,19 @@
74 ****************************************************************************/
75 static int do_message_op(void)
76 {
77- struct in_addr ip;
78 struct nmb_name called, calling;
79-
80- zero_ip(&ip);
81+ struct sockaddr_list *salist;
82
83 make_nmb_name(&calling, global_myname, 0x0);
84 make_nmb_name(&called , desthost, name_type);
85
86- zero_ip(&ip);
87- if (have_ip) ip = dest_ip;
88+ salist = resolve_name_smb(have_ip ? dest_ip : desthost, port);
89
90- if (!(cli=cli_initialise(NULL)) || (cli_set_port(cli, port) == 0) || !cli_connect(cli, desthost, &ip)) {
91- DEBUG(0,("Connection to %s failed\n", desthost));
92- return 1;
93- }
94+ if (!(cli=cli_initialise(NULL)) || !cli_connect(cli, desthost, salist)) {
95+ DEBUG(0,("Connection to %s failed\n", desthost));
96+ free_sockaddr_list(salist);
97+ return 1;
98+ }
99
100 if (!cli_session_request(cli, &calling, &called)) {
101 DEBUG(0,("session request failed\n"));
102@@ -2658,9 +2653,7 @@
103 break;
104 case 'I':
105 {
106- dest_ip = *interpret_addr2(optarg);
107- if (is_zero_ip(dest_ip))
108- exit(1);
109+ strncpy(dest_ip, optarg, sizeof(dest_ip));
110 have_ip = True;
111 }
112 break;
113diff -ur samba-2.2.4/source/client/smbmount.c samba-2.2.4+IPv6-20020609/source/client/smbmount.c
114--- samba-2.2.4/source/client/smbmount.c Thu May 2 21:02:58 2002
115+++ samba-2.2.4+IPv6-20020609/source/client/smbmount.c Sun May 19 15:21:06 2002
116@@ -41,9 +41,9 @@
117 static pstring service;
118 static pstring options;
119
120-static struct in_addr dest_ip;
121+static char dest_ip[512];
122 static BOOL have_ip;
123-static int smb_port = 139;
124+static int smb_port = 0;
125 static BOOL got_pass;
126 static uid_t mount_uid;
127 static gid_t mount_gid;
128@@ -116,8 +116,8 @@
129 {
130 struct cli_state *c;
131 struct nmb_name called, calling;
132+ struct sockaddr_list *salist;
133 char *server_n;
134- struct in_addr ip;
135 pstring server;
136 char *share;
137
138@@ -141,16 +141,15 @@
139 make_nmb_name(&called , server, 0x20);
140
141 again:
142- zero_ip(&ip);
143- if (have_ip) ip = dest_ip;
144+ salist = resolve_name_smb(have_ip ? dest_ip : server_n, smb_port);
145
146 /* have to open a new connection */
147- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) == 0) ||
148- !cli_connect(c, server_n, &ip)) {
149- DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
150- if (c) {
151- cli_shutdown(c);
152- }
153+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, salist)) {
154+ DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n));
155+ free_sockaddr_list(salist);
156+ if (c) {
157+ cli_shutdown(c);
158+ }
159 return NULL;
160 }
161
162@@ -744,11 +743,7 @@
163 } else if(!strcmp(opts, "debug")) {
164 DEBUGLEVEL = val;
165 } else if(!strcmp(opts, "ip")) {
166- dest_ip = *interpret_addr2(opteq+1);
167- if (is_zero_ip(dest_ip)) {
168- fprintf(stderr,"Can't resolve address %s\n", opteq+1);
169- exit(1);
170- }
171+ strncpy(dest_ip, optarg, sizeof(dest_ip));
172 have_ip = True;
173 } else if(!strcmp(opts, "workgroup")) {
174 pstrcpy(workgroup,opteq+1);
175diff -ur samba-2.2.4/source/client/smbspool.c samba-2.2.4+IPv6-20020609/source/client/smbspool.c
176--- samba-2.2.4/source/client/smbspool.c Thu May 2 21:02:58 2002
177+++ samba-2.2.4+IPv6-20020609/source/client/smbspool.c Sun May 19 15:22:25 2002
178@@ -279,7 +279,6 @@
179 struct cli_state *c; /* New connection */
180 struct nmb_name called, /* NMB name of server */
181 calling; /* NMB name of client */
182- struct in_addr ip; /* IP address of server */
183 pstring myname; /* Client name */
184
185
186@@ -289,8 +288,6 @@
187
188 get_myname(myname);
189
190- zero_ip(&ip);
191-
192 make_nmb_name(&calling, myname, 0x0);
193 make_nmb_name(&called, server, 0x20);
194
195@@ -304,13 +301,7 @@
196 return (NULL);
197 }
198
199- if (!cli_set_port(c, SMB_PORT))
200- {
201- fputs("ERROR: cli_set_port() failed...\n", stderr);
202- return (NULL);
203- }
204-
205- if (!cli_connect(c, server, &ip))
206+ if (!cli_connect(c, server, NULL))
207 {
208 fputs("ERROR: cli_connect() failed...\n", stderr);
209 return (NULL);
210diff -ur samba-2.2.4/source/configure.in samba-2.2.4+IPv6-20020609/source/configure.in
211--- samba-2.2.4/source/configure.in Thu May 2 21:02:46 2002
212+++ samba-2.2.4+IPv6-20020609/source/configure.in Sun May 19 15:13:29 2002
213@@ -2176,6 +2176,53 @@
214 )
215
216 #################################################
217+# check for IPv6 support
218+AC_MSG_CHECKING(whether to use IPv6)
219+AC_ARG_WITH(ipv6,
220+[ --with-ipv6 Include IPv6 support (default=no)],
221+[ case "$withval" in
222+ yes)
223+ AC_MSG_RESULT(yes)
224+ AC_DEFINE(HAVE_INET6)
225+
226+ AC_CACHE_CHECK(for struct sockaddr_in6,samba_cv_struct_sockaddr_in6,
227+ AC_TRY_COMPILE(
228+ [#include <sys/types.h>
229+ #include <sys/socket.h>
230+ #include <netinet/in.h>],
231+ [struct sockaddr_in6 sin6;
232+ sin6.sin6_port = 0;],
233+ [samba_cv_struct_sockaddr_in6=yes],
234+ [samba_cv_struct_sockaddr_in6=no]))
235+ if test "$samba_cv_struct_sockaddr_in6" != yes ; then
236+ AC_MSG_ERROR([This system does not have IPv6 support. Reconfigure without the --with-ipv6 flag.])
237+ fi
238+
239+ AC_CHECK_FUNC(getaddrinfo,,
240+ AC_MSG_ERROR([IPv6 functionality requires getaddrinfo. Reconfigure without the --with-ipv6 flag.]))
241+
242+ dnl This can't check for member names because we're not sure what they
243+ dnl might be. Doesn't matter - we only need it defined for sizeof.
244+ AC_CACHE_CHECK(for struct sockaddr_storage,samba_cv_struct_sockaddr_storage,
245+ AC_TRY_COMPILE(
246+ [#include <sys/types.h>
247+ #include <sys/socket.h>
248+ #include <netinet/in.h>],
249+ [struct sockaddr_storage ss;],
250+ [samba_cv_struct_sockaddr_storage=yes],
251+ [samba_cv_struct_sockaddr_storage=no]))
252+ if test "$samba_cv_struct_sockaddr_storage" != yes ; then
253+ AC_MSG_ERROR([IPv6 functionality requires the sockaddr_storage structure. Reconfigure without the --with-ipv6 flag.])
254+ fi
255+ ;;
256+ *)
257+ AC_MSG_RESULT(no)
258+ ;;
259+ esac],
260+ AC_MSG_RESULT(no)
261+)
262+
263+#################################################
264 # check for syslog logging
265 AC_MSG_CHECKING(whether to use syslog logging)
266 AC_ARG_WITH(syslog,
267diff -ur samba-2.2.4/source/include/client.h samba-2.2.4+IPv6-20020609/source/include/client.h
268--- samba-2.2.4/source/include/client.h Sat Feb 2 19:46:39 2002
269+++ samba-2.2.4+IPv6-20020609/source/include/client.h Sun May 19 15:13:42 2002
270@@ -58,7 +58,7 @@
271 };
272
273 struct cli_state {
274- int port;
275+ int default_port;
276 int fd;
277 uint16 cnum;
278 uint16 pid;
279@@ -88,7 +88,8 @@
280 struct nmb_name called;
281 struct nmb_name calling;
282 fstring full_dest_host_name;
283- struct in_addr dest_ip;
284+ struct sockaddr_list *dest_addrs;
285+ struct sockaddr_list *connected_addr;
286
287 struct pwd_info pwd;
288 unsigned char cryptkey[8];
289diff -ur samba-2.2.4/source/include/config.h.in samba-2.2.4+IPv6-20020609/source/include/config.h.in
290--- samba-2.2.4/source/include/config.h.in Thu May 2 21:03:02 2002
291+++ samba-2.2.4+IPv6-20020609/source/include/config.h.in Sun May 19 15:13:42 2002
292@@ -125,6 +125,7 @@
293 #undef WITH_SYSLOG
294 #undef WITH_PROFILE
295 #undef WITH_SSL
296+#undef HAVE_INET6
297 #undef WITH_LDAP
298 #undef WITH_NISPLUS
299 #undef WITH_TDBPWD
300diff -ur samba-2.2.4/source/include/nameserv.h samba-2.2.4+IPv6-20020609/source/include/nameserv.h
301--- samba-2.2.4/source/include/nameserv.h Sat Feb 2 19:46:39 2002
302+++ samba-2.2.4+IPv6-20020609/source/include/nameserv.h Sun May 19 15:13:42 2002
303@@ -129,6 +129,17 @@
304 #define FIND_SELF_NAME 1
305
306 /*
307+ * Linked-list structure for storing resolved IP addresses.
308+ */
309+
310+struct sockaddr_list {
311+ struct sockaddr_list *next;
312+ int pfamily;
313+ int len;
314+ struct sockaddr *addr;
315+};
316+
317+/*
318 * The different name types that can be in namelists.
319 *
320 * SELF_NAME should only be on the broadcast and unicast subnets.
321diff -ur samba-2.2.4/source/include/proto.h samba-2.2.4+IPv6-20020609/source/include/proto.h
322--- samba-2.2.4/source/include/proto.h Thu May 2 21:03:05 2002
323+++ samba-2.2.4+IPv6-20020609/source/include/proto.h Sat Jun 8 23:21:27 2002
324@@ -196,9 +196,10 @@
325 BOOL cli_negprot(struct cli_state *cli);
326 BOOL cli_session_request(struct cli_state *cli,
327 struct nmb_name *calling, struct nmb_name *called);
328-BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
329+BOOL cli_connect(struct cli_state *cli, const char *host,
330+ struct sockaddr_list *salist);
331 BOOL cli_establish_connection(struct cli_state *cli,
332- char *dest_host, struct in_addr *dest_ip,
333+ char *dest_host, struct sockaddr_list *salist,
334 struct nmb_name *calling, struct nmb_name *called,
335 char *service, char *service_type,
336 BOOL do_shutdown, BOOL do_tcon);
337@@ -208,8 +209,8 @@
338 char *service, char *service_type,
339 char *user, char *domain,
340 char *password, int pass_len) ;
341-BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
342- struct in_addr *pdest_ip);
343+BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost,
344+ char *desthost);
345
346 /* The following definitions come from libsmb/cli_dfs.c */
347
348@@ -702,11 +703,12 @@
349 BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
350 void endlmhosts(FILE *fp);
351 BOOL name_register_wins(const char *name, int name_type);
352-BOOL name_resolve_bcast(const char *name, int name_type,
353- struct in_addr **return_ip_list, int *return_count);
354-BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
355-BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
356- struct in_addr *ip);
357+struct sockaddr_list *name_resolve_bcast(const char *name, int name_type);
358+BOOL resolve_name_netbios(const char *name, struct in_addr *return_ip,
359+ int name_type);
360+struct sockaddr_list *resolve_name_smb(const char *name, int port);
361+struct sockaddr_list *resolve_srv_name(const char* srv_name,
362+ fstring dest_host, int port);
363 BOOL find_master_ip(char *group, struct in_addr *master_ip);
364 BOOL lookup_dc_name(const char *srcname, const char *domain,
365 struct in_addr *dc_ip, char *ret_name);
366@@ -1131,8 +1133,21 @@
367 void safe_free(void *p);
368 BOOL get_myname(char *my_name);
369 int interpret_protocol(char *str,int def);
370+BOOL is_ipv4address(const char *str);
371 BOOL is_ipaddress(const char *str);
372 uint32 interpret_addr(const char *str);
373+struct sockaddr *get_numeric_addr(const char *str);
374+BOOL sa_host_equal(struct sockaddr *a, struct sockaddr *b);
375+int get_sockaddr_port(struct sockaddr *sa);
376+void set_sockaddr_port(struct sockaddr *sa, int port);
377+struct sockaddr_list *set_default_ports(struct sockaddr_list *salist);
378+BOOL is_directsmb(struct sockaddr *sa);
379+char *print_sockaddr(struct sockaddr *sa);
380+void make_sockaddr_in(struct sockaddr *sa, struct in_addr *addr);
381+void free_sockaddr_list(struct sockaddr_list *salist);
382+struct sockaddr_list *make_sin_list(struct in_addr *addr, int count);
383+struct sockaddr_list *make_singlet_list(struct in_addr *addr, int port);
384+struct sockaddr_list *make_sa_list(struct addrinfo *ai);
385 struct in_addr *interpret_addr2(const char *str);
386 BOOL is_zero_ip(struct in_addr ip);
387 void zero_ip(struct in_addr *ip);
388@@ -1285,7 +1300,8 @@
389 BOOL send_smb(int fd,char *buffer);
390 BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
391 int open_socket_in( int type, int port, int dlevel, uint32 socket_addr, BOOL rebind );
392-int open_socket_out(int type, struct in_addr *addr, int port ,int timeout);
393+int open_socket_out(struct sockaddr_list *addrs,
394+ struct sockaddr_list **connected_addr, int timeout);
395 void client_setfd(int fd);
396 char *client_name(void);
397 char *client_addr(void);
398@@ -4449,10 +4465,6 @@
399 char *inbuf,char *outbuf, int dum_size,
400 int dum_buffsize);
401
402-/* The following definitions come from smbd/noquotas.c */
403-
404-BOOL disk_quotas(const char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT *dsize);
405-
406 /* The following definitions come from smbd/notify.c */
407
408 void remove_pending_change_notify_requests_by_fid(files_struct *fsp);
409@@ -4583,6 +4595,16 @@
410 void check_reload(int t);
411 void smbd_process(void);
412
413+/* The following definitions come from smbd/quotas.c */
414+
415+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
416+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
417+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
418+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
419+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
420+BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
421+BOOL disk_quotas_vxfs(const pstring name, char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
422+
423 /* The following definitions come from smbd/reply.c */
424
425 int reply_special(char *inbuf,char *outbuf);
426diff -ur samba-2.2.4/source/include/smb.h samba-2.2.4+IPv6-20020609/source/include/smb.h
427--- samba-2.2.4/source/include/smb.h Thu May 2 21:03:06 2002
428+++ samba-2.2.4+IPv6-20020609/source/include/smb.h Sun May 19 15:13:42 2002
429@@ -472,7 +472,8 @@
430 char *user; /* name of user who *opened* this connection */
431 uid_t uid; /* uid of user who *opened* this connection */
432 gid_t gid; /* gid of user who *opened* this connection */
433- char client_address[18]; /* String version of client IP address. */
434+ char client_address[50]; /* String version of client IP address.
435+ * Nice and long for IPv6 addresses... */
436
437 uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
438
439diff -ur samba-2.2.4/source/lib/access.c samba-2.2.4+IPv6-20020609/source/lib/access.c
440--- samba-2.2.4/source/lib/access.c Thu May 2 21:03:07 2002
441+++ samba-2.2.4+IPv6-20020609/source/lib/access.c Sun May 19 15:13:42 2002
442@@ -18,7 +18,7 @@
443 #define ALLONES ((uint32)0xFFFFFFFF)
444
445 /* masked_match - match address against netnumber/netmask */
446-static int masked_match(char *tok, char *slash, char *s)
447+static BOOL masked_match_ipv4(char *tok, char *slash, char *s)
448 {
449 uint32 net;
450 uint32 mask;
451@@ -43,6 +43,54 @@
452 return ((addr & mask) == net);
453 }
454
455+#ifdef HAVE_INET6
456+static BOOL masked_match_ipv6(char *tok, char *slash, char *s)
457+{
458+ struct in6_addr net, addr;
459+ unsigned char *n = (unsigned char *)&net;
460+ unsigned char *a = (unsigned char *)&addr;
461+ int ret, len, i, mask;
462+
463+ if(inet_pton(AF_INET6, s, &addr) <= 0)
464+ {
465+ DEBUG(0,("access: unable to parse remote address: %s\n", s));
466+ return False;
467+ }
468+ *slash = '\0';
469+ ret = inet_pton(AF_INET6, tok, &net);
470+ *slash = '/';
471+ len = atoi(slash + 1);
472+ if(ret <= 0 || len < 0 || len > 128
473+ || (len == 0 && strcmp(slash + 1, "0")))
474+ {
475+ DEBUG(0,("access: bad net/mask access control: %s\n", tok));
476+ return False;
477+ }
478+ for(i = 0; i < len; i += 8)
479+ {
480+
481+ if( len - i < 8 )
482+ mask = ~((1 << (8 - (len - i))) - 1);
483+ else
484+ mask = ~0;
485+ DEBUG(3,("len=%d i=%d mask=%02x *n=%02x *a=%02x *a&mask=%02x\n",
486+ len, i, mask, *n, *a, *a & mask));
487+ if(*(n++) != (*(a++) & mask)) return False;
488+ }
489+ return True;
490+}
491+#endif
492+
493+static BOOL masked_match(char *tok, char *slash, char *s)
494+{
495+ if(is_ipv4address(s)) return masked_match_ipv4(tok, slash, s);
496+#ifdef HAVE_INET6
497+ return masked_match_ipv6(tok, slash, s);
498+#else
499+ return False;
500+#endif
501+}
502+
503 /* string_match - match string against token */
504 static int string_match(char *tok,char *s, char *invalid_char)
505 {
506@@ -113,8 +161,13 @@
507 } else if (tok[(tok_len = strlen(tok)) - 1] == '.') { /* network */
508 if (strncmp(tok, s, tok_len) == 0)
509 return (True);
510+#ifdef HAVE_INET6
511+ } else if (tok[(tok_len = strlen(tok)) - 1] == ':') { /* IPv6 network */
512+ if (strncasecmp(tok, s, tok_len) == 0)
513+ return (True);
514+#endif
515 } else if ((cut = strchr(tok, '/')) != 0) { /* netnumber/netmask */
516- if (isdigit((int)s[0]) && masked_match(tok, cut, s))
517+ if (isxdigit((int)s[0]) && masked_match(tok, cut, s))
518 return (True);
519 } else if (strchr(tok, '*') != 0) {
520 *invalid_char = '*';
521@@ -208,9 +261,13 @@
522 client[1] = caddr;
523
524 /* if it is loopback then always allow unless specifically denied */
525+#ifdef HAVE_INET6
526+ if (strcmp(caddr, "127.0.0.1") == 0 || strcmp(caddr, "::1") == 0) {
527+#else
528 if (strcmp(caddr, "127.0.0.1") == 0) {
529+#endif
530 /*
531- * If 127.0.0.1 matches both allow and deny then allow.
532+ * If 127.0.0.1 or ::1 matches both allow and deny then allow.
533 * Patch from Steve Langasek vorlon@netexpress.net.
534 */
535 if (deny_list &&
536diff -ur samba-2.2.4/source/lib/util.c samba-2.2.4+IPv6-20020609/source/lib/util.c
537--- samba-2.2.4/source/lib/util.c Thu May 2 21:03:11 2002
538+++ samba-2.2.4+IPv6-20020609/source/lib/util.c Sat Jun 8 23:21:19 2002
539@@ -743,11 +743,11 @@
540 Return true if a string could be a pure IP address.
541 ****************************************************************************/
542
543-BOOL is_ipaddress(const char *str)
544+BOOL is_ipv4address(const char *str)
545 {
546 BOOL pure_address = True;
547 int i;
548-
549+
550 for (i=0; pure_address && str[i]; i++)
551 if (!(isdigit((int)str[i]) || str[i] == '.'))
552 pure_address = False;
553@@ -758,6 +758,26 @@
554 return pure_address;
555 }
556
557+BOOL is_ipaddress(const char *str)
558+{
559+#ifdef HAVE_INET6
560+ /* First we see if the address is an IPv6 address */
561+ if (strchr(str, ':'))
562+ {
563+ int i;
564+
565+ /* It contains a colon; it probably is */
566+ for (i=0; str[i]; i++)
567+ if (!(isxdigit((int)str[i]) || str[i] == '.' || str[i] == ':'))
568+ return False;
569+
570+ return True;
571+ }
572+#endif
573+
574+ return is_ipv4address(str);
575+}
576+
577 /****************************************************************************
578 interpret an internet address or name into an IP address in 4 byte form
579 ****************************************************************************/
580@@ -792,6 +812,204 @@
581 return(res);
582 }
583
584+struct sockaddr *get_numeric_addr(const char *str)
585+{
586+#ifdef HAVE_INET6
587+ struct sockaddr *sa;
588+ struct addrinfo *ai, hints;
589+
590+ memset(&hints, 0, sizeof(hints));
591+ hints.ai_socktype = SOCK_STREAM;
592+ hints.ai_flags = AI_NUMERICHOST;
593+ if(getaddrinfo(str, NULL, &hints, &ai) || ! ai) return NULL;
594+ sa = (struct sockaddr *)malloc(ai->ai_addrlen);
595+ memcpy(sa, ai->ai_addr, ai->ai_addrlen);
596+ freeaddrinfo(ai);
597+ return sa;
598+#else
599+ struct sockaddr *sa;
600+ struct in_addr addr;
601+
602+ if(inet_aton(str, &addr))
603+ {
604+ sa = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
605+ make_sockaddr_in(sa, &addr);
606+ return sa;
607+ }
608+ return NULL;
609+#endif
610+}
611+
612+BOOL sa_host_equal(struct sockaddr *a, struct sockaddr *b)
613+{
614+#ifdef HAVE_INET6
615+ if(a->sa_family == AF_INET6 && b->sa_family == AF_INET6)
616+ {
617+ return IN6_ARE_ADDR_EQUAL(
618+ &((struct sockaddr_in6 *)a)->sin6_addr,
619+ &((struct sockaddr_in6 *)b)->sin6_addr);
620+ } else
621+#endif
622+ if(a->sa_family == AF_INET && b->sa_family == AF_INET)
623+ {
624+ return ((struct sockaddr_in *)a)->sin_addr.s_addr
625+ == ((struct sockaddr_in *)b)->sin_addr.s_addr;
626+ }
627+ return False;
628+}
629+
630+int get_sockaddr_port(struct sockaddr *sa)
631+{
632+#ifdef HAVE_INET6
633+ if(sa->sa_family==AF_INET6)
634+ return ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
635+ else
636+#endif
637+ if(sa->sa_family==AF_INET)
638+ return ntohs(((struct sockaddr_in *)sa)->sin_port);
639+ else
640+ return 0;
641+}
642+
643+void set_sockaddr_port(struct sockaddr *sa, int port)
644+{
645+#ifdef HAVE_INET6
646+ if(sa->sa_family==AF_INET6)
647+ ((struct sockaddr_in6 *)sa)->sin6_port = htons(port);
648+ else
649+#endif
650+ if(sa->sa_family==AF_INET)
651+ ((struct sockaddr_in *)sa)->sin_port = htons(port);
652+}
653+
654+struct sockaddr_list *set_default_ports(struct sockaddr_list *salist)
655+{
656+ struct sockaddr_list *cur;
657+
658+ for(cur = salist; cur; cur = cur->next)
659+ {
660+ set_sockaddr_port(cur->addr, 445);
661+ if(cur->addr->sa_family == AF_INET)
662+ {
663+ struct sockaddr_list *sc;
664+
665+ sc = (struct sockaddr_list *)
666+ malloc(sizeof(struct sockaddr_list));
667+ sc->next = cur->next;
668+ cur->next = sc;
669+ sc->pfamily = cur->pfamily;
670+ sc->len = cur->len;
671+ sc->addr = (struct sockaddr *)malloc(sc->len);
672+ memcpy(sc->addr, cur->addr, cur->len);
673+ set_sockaddr_port(sc->addr, 139);
674+ cur = sc;
675+ }
676+ }
677+ return salist;
678+}
679+
680+
681+BOOL is_directsmb(struct sockaddr *sa)
682+{
683+ BOOL ret = sa->sa_family != AF_INET
684+ || ((struct sockaddr_in *)sa)->sin_port == htons(445);
685+ DEBUG(4,("connection is%s direct SMB\n", ret ? "" : " not"));
686+ return ret;
687+}
688+
689+char *print_sockaddr(struct sockaddr *sa)
690+{
691+#ifdef HAVE_INET6
692+ static char addr[64];
693+
694+ if(sa->sa_family == AF_INET6)
695+ {
696+ inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr,
697+ addr, sizeof(addr));
698+ return addr;
699+ } else
700+#endif
701+ if(sa->sa_family == AF_INET)
702+ return inet_ntoa(((struct sockaddr_in *)sa)->sin_addr);
703+ else return NULL;
704+}
705+
706+void make_sockaddr_in(struct sockaddr *sa, struct in_addr *addr)
707+{
708+ memset(sa, 0, sizeof(struct sockaddr_in));
709+ ((struct sockaddr_in *)sa)->sin_family = AF_INET;
710+ ((struct sockaddr_in *)sa)->sin_port = 0;
711+ memcpy(&((struct sockaddr_in *)sa)->sin_addr, addr,
712+ sizeof(struct in_addr));
713+}
714+
715+void free_sockaddr_list(struct sockaddr_list *salist)
716+{
717+ struct sockaddr_list *next;
718+
719+ while(salist)
720+ {
721+ next = salist->next;
722+ SAFE_FREE(salist->addr);
723+ SAFE_FREE(salist);
724+ salist = next;
725+ }
726+}
727+
728+struct sockaddr_list *make_sin_list(struct in_addr *addr, int count)
729+{
730+ int i;
731+ struct sockaddr_list *top = NULL, *last = NULL, *sc;
732+
733+ for(i = 0; i<count; ++i)
734+ {
735+ sc = (struct sockaddr_list *)
736+ malloc(sizeof(struct sockaddr_list));
737+ if(i==0) top = sc;
738+ else last->next = sc;
739+ last = sc;
740+ sc->next = NULL;
741+ sc->pfamily = PF_INET;
742+ sc->len = sizeof(struct sockaddr_in);
743+ sc->addr = (struct sockaddr *)
744+ malloc(sizeof(struct sockaddr_in));
745+ make_sockaddr_in(sc->addr, &addr[i]);
746+ }
747+ return top;
748+}
749+
750+struct sockaddr_list *make_singlet_list(struct in_addr *addr, int port)
751+{
752+ struct sockaddr_list *salist;
753+
754+ salist = make_sin_list(addr, 1);
755+ if(port) set_sockaddr_port(salist->addr, port);
756+ else salist = set_default_ports(salist);
757+ return salist;
758+}
759+
760+#ifdef HAVE_INET6
761+struct sockaddr_list *make_sa_list(struct addrinfo *ai)
762+{
763+ struct sockaddr_list *top = NULL, *last = NULL, *sc;
764+
765+ for(; ai; ai = ai->ai_next)
766+ {
767+ sc = (struct sockaddr_list *)
768+ malloc(sizeof(struct sockaddr_list));
769+ if(top==NULL) top = sc;
770+ else last->next = sc;
771+ last = sc;
772+ sc->next = NULL;
773+ sc->pfamily = ai->ai_family;
774+ sc->len = ai->ai_addrlen;
775+ sc->addr = (struct sockaddr *)malloc(ai->ai_addrlen);
776+ memcpy(sc->addr, ai->ai_addr, ai->ai_addrlen);
777+ }
778+ return top;
779+}
780+#endif
781+
782 /*******************************************************************
783 a convenient addition to interpret_addr()
784 ******************************************************************/
785@@ -1388,7 +1606,7 @@
786 return True;
787
788 /* maybe its an IP address? */
789- if (is_ipaddress(s))
790+ if (is_ipv4address(s))
791 {
792 struct iface_struct nics[MAX_INTERFACES];
793 int i, n;
794diff -ur samba-2.2.4/source/lib/util_sock.c samba-2.2.4+IPv6-20020609/source/lib/util_sock.c
795--- samba-2.2.4/source/lib/util_sock.c Thu May 2 21:03:12 2002
796+++ samba-2.2.4+IPv6-20020609/source/lib/util_sock.c Sun May 19 15:13:42 2002
797@@ -817,67 +817,94 @@
798 create an outgoing socket. timeout is in milliseconds.
799 **************************************************************************/
800
801-int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
802+int open_socket_out(struct sockaddr_list *addrs,
803+ struct sockaddr_list **connected_addr, int timeout)
804 {
805- struct sockaddr_in sock_out;
806- int res,ret;
807- int connect_loop = 250; /* 250 milliseconds */
808- int loops = (timeout) / connect_loop;
809-
810- /* create a socket to write to */
811- res = socket(PF_INET, type, 0);
812- if (res == -1)
813- { DEBUG(0,("socket error\n")); return -1; }
814-
815- if (type != SOCK_STREAM) return(res);
816-
817- memset((char *)&sock_out,'\0',sizeof(sock_out));
818- putip((char *)&sock_out.sin_addr,(char *)addr);
819-
820- sock_out.sin_port = htons( port );
821- sock_out.sin_family = PF_INET;
822-
823- /* set it non-blocking */
824- set_blocking(res,False);
825-
826- DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port));
827-
828- /* and connect it to the destination */
829-connect_again:
830- ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out));
831-
832- /* Some systems return EAGAIN when they mean EINPROGRESS */
833- if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
834- errno == EAGAIN) && loops--) {
835- msleep(connect_loop);
836- goto connect_again;
837- }
838-
839- if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
840- errno == EAGAIN)) {
841- DEBUG(1,("timeout connecting to %s:%d\n",inet_ntoa(*addr),port));
842- close(res);
843- return -1;
844- }
845+ struct sockaddr_list *sl;
846+ int res,ret;
847+ int connect_loop = 250; /* 250 milliseconds */
848+ int loops = (timeout) / connect_loop;
849+
850+ if(connected_addr) *connected_addr = NULL;
851+
852+ for(sl = addrs; sl; sl = sl->next)
853+ {
854+ /* create a socket to write to */
855+ res = socket(sl->pfamily, SOCK_STREAM, 0);
856+ if (res == -1)
857+ {
858+ /* If there are more addresses available, then we
859+ * are probably running on a platform without IPv6
860+ * support in the kernel, and we just tried
861+ * connecting to an IPv6 address. Don't complain
862+ * until we're out of addresses. */
863+
864+ if(!sl->next) DEBUG(0,("socket error\n"));
865+ continue;
866+ }
867+
868+ /* set it non-blocking */
869+ set_blocking(res,False);
870+
871+ DEBUG(3,("Connecting to %s at port %d\n",
872+ print_sockaddr(sl->addr), get_sockaddr_port(sl->addr)));
873+
874+ /* and connect it to the destination */
875+ connect_again:
876+ ret = connect(res,sl->addr,sl->len);
877+
878+ /* Some systems return EAGAIN when they mean EINPROGRESS */
879+ if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
880+ errno == EAGAIN) && loops--) {
881+ msleep(connect_loop);
882+ goto connect_again;
883+ }
884+
885+ if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
886+ errno == EAGAIN)) {
887+ DEBUG(1,("timeout connecting to [%s]:%d\n",
888+ print_sockaddr(sl->addr),
889+ get_sockaddr_port(sl->addr)));
890+ close(res);
891+ if(sl->next) {
892+ DEBUG(1,("attempting next address...\n"));
893+ continue;
894+ } else return -1;
895+ }
896
897 #ifdef EISCONN
898- if (ret < 0 && errno == EISCONN) {
899- errno = 0;
900- ret = 0;
901- }
902-#endif
903-
904- if (ret < 0) {
905- DEBUG(2,("error connecting to %s:%d (%s)\n",
906- inet_ntoa(*addr),port,strerror(errno)));
907- close(res);
908- return -1;
909- }
910+ if (ret < 0 && errno == EISCONN) {
911+ errno = 0;
912+ ret = 0;
913+ }
914+#endif
915
916- /* set it blocking again */
917- set_blocking(res,True);
918+ if (ret < 0) {
919+ /* If we got connection refused or host unreachable,
920+ * we may be trying to connect to an IPv6 host but
921+ * this system isn't configured for IPv6. If we have
922+ * more addresses, don't complain about this one --
923+ * just try the next ones. */
924+
925+ BOOL can_ignore = sl->next &&
926+ (errno == ECONNREFUSED || errno == ENETUNREACH);
927+ DEBUG(can_ignore ? 3 : 2,
928+ ("error connecting to [%s]:%d (%s)\n",
929+ print_sockaddr(sl->addr),
930+ get_sockaddr_port(sl->addr),
931+ strerror(errno)));
932+ close(res);
933+ continue;
934+ }
935
936- return res;
937+ /* set it blocking again */
938+ set_blocking(res,True);
939+
940+ if(connected_addr) *connected_addr = sl;
941+
942+ return res;
943+ }
944+ return -1;
945 }
946
947 /* the following 3 client_*() functions are nasty ways of allowing
948@@ -904,9 +931,63 @@
949 matchname - determine if host name matches IP address. Used to
950 confirm a hostname lookup to prevent spoof attacks
951 ******************************************************************/
952-static BOOL matchname(char *remotehost,struct in_addr addr)
953+#ifdef HAVE_INET6
954+static BOOL addr_equal(struct sockaddr *a, struct sockaddr *b)
955+{
956+ if(a->sa_family == AF_INET6 && b->sa_family == AF_INET6)
957+ {
958+ struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)a;
959+ struct sockaddr_in6 *b6 = (struct sockaddr_in6 *)b;
960+
961+ return !memcmp(&a6->sin6_addr, &b6->sin6_addr, 16);
962+ }
963+ if(a->sa_family == AF_INET && b->sa_family == AF_INET)
964+ {
965+ struct sockaddr_in *a4 = (struct sockaddr_in *)a;
966+ struct sockaddr_in *b4 = (struct sockaddr_in *)b;
967+
968+ return a4->sin_addr.s_addr == b4->sin_addr.s_addr;
969+ }
970+ return False;
971+}
972+#endif
973+
974+/*******************************************************************
975+ matchname - determine if host name matches IP address. Used to
976+ confirm a hostname lookup to prevent spoof attacks
977+ ******************************************************************/
978+static BOOL matchname(char *remotehost, struct sockaddr *can)
979 {
980+#ifdef HAVE_INET6
981+ struct addrinfo *ai, hints, *cur;
982+
983+ memset(&hints, 0, sizeof(hints));
984+ hints.ai_socktype = SOCK_STREAM;
985+ if(getaddrinfo(remotehost, NULL, &hints, &ai)){
986+ DEBUG(0,("getaddrinfo(%s): lookup failure.\n", remotehost));
987+ return False;
988+ }
989+ for( cur = ai; cur; cur = cur->ai_next )
990+ if(addr_equal(cur->ai_addr, can))
991+ {
992+ freeaddrinfo(ai);
993+ return True;
994+ }
995+
996+ /*
997+ * The host name does not map to the original host address. Perhaps
998+ * someone has compromised a name server. More likely someone botched
999+ * it, but that could be dangerous, too.
1000+ */
1001+
1002+ DEBUG(0,("host name/address mismatch: %s != %s\n",
1003+ print_sockaddr(can), remotehost));
1004+
1005+ freeaddrinfo(ai);
1006+ return False;
1007+#else
1008 struct hostent *hp;
1009+ struct in_addr addr = ((struct sockaddr_in *)can)->sin_addr;
1010 int i;
1011
1012 if ((hp = sys_gethostbyname(remotehost)) == 0) {
1013@@ -944,6 +1025,56 @@
1014 DEBUG(0,("host name/address mismatch: %s != %s\n",
1015 inet_ntoa(addr), hp->h_name));
1016 return False;
1017+#endif
1018+}
1019+
1020+/*******************************************************************
1021+ return a sockaddr describing the remote endpoint
1022+ ******************************************************************/
1023+static BOOL get_socket_sa(int fd, struct sockaddr **sa, int *len)
1024+{
1025+ if (fd == -1) {
1026+ return False;
1027+ }
1028+
1029+#ifdef HAVE_INET6
1030+ *len = sizeof(struct sockaddr_storage);
1031+#else
1032+ *len = sizeof(struct sockaddr);
1033+#endif
1034+
1035+ *sa = (struct sockaddr *)malloc(*len);
1036+
1037+ if (getpeername(fd, *sa, len) < 0) {
1038+ DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) ));
1039+ SAFE_FREE(*sa);
1040+ *sa = NULL;
1041+ return False;
1042+ }
1043+
1044+#ifdef HAVE_INET6
1045+ if((*sa)->sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(
1046+ &((struct sockaddr_in6 *)(*sa))->sin6_addr))
1047+ {
1048+ struct sockaddr_in *newsin;
1049+ struct in_addr addr;
1050+ int port = ((struct sockaddr_in6 *)(*sa))->sin6_port;
1051+
1052+ DEBUG(5,("converting IPv6-mapped address %s\n",
1053+ print_sockaddr(*sa)));
1054+ memcpy(&addr, &((struct sockaddr_in6 *)
1055+ (*sa))->sin6_addr + 12, 4);
1056+ SAFE_FREE(*sa);
1057+ *len = sizeof(struct sockaddr_in);
1058+ *sa = (struct sockaddr *)malloc(*len);
1059+ newsin = (struct sockaddr_in *)(*sa);
1060+ newsin->sin_family = AF_INET;
1061+ newsin->sin_port = port;
1062+ newsin->sin_addr = addr;
1063+ }
1064+#endif
1065+
1066+ return True;
1067 }
1068
1069
1070@@ -953,34 +1084,60 @@
1071 char *get_socket_name(int fd)
1072 {
1073 static pstring name_buf;
1074- static fstring addr_buf;
1075- struct hostent *hp;
1076- struct in_addr addr;
1077+ struct sockaddr *sa;
1078 char *p;
1079+ int len;
1080
1081- p = get_socket_addr(fd);
1082-
1083- /* it might be the same as the last one - save some DNS work */
1084- if (strcmp(p, addr_buf) == 0) return name_buf;
1085-
1086 pstrcpy(name_buf,"UNKNOWN");
1087 if (fd == -1) return name_buf;
1088
1089- fstrcpy(addr_buf, p);
1090+ if(!get_socket_sa(fd, &sa, &len)) return name_buf;
1091+ p = print_sockaddr(sa);
1092
1093- addr = *interpret_addr2(p);
1094-
1095- /* Look up the remote host name. */
1096- if ((hp = gethostbyaddr((char *)&addr.s_addr, sizeof(addr.s_addr), AF_INET)) == 0) {
1097- DEBUG(1,("Gethostbyaddr failed for %s\n",p));
1098- pstrcpy(name_buf, p);
1099- } else {
1100- pstrcpy(name_buf,(char *)hp->h_name);
1101- if (!matchname(name_buf, addr)) {
1102- DEBUG(0,("Matchname failed on %s %s\n",name_buf,p));
1103- pstrcpy(name_buf,"UNKNOWN");
1104+#ifdef HAVE_INET6
1105+ {
1106+ char hostbuf[NI_MAXHOST];
1107+
1108+ if(getnameinfo(sa, len, hostbuf, NI_MAXHOST, NULL, 0, 0)) {
1109+ DEBUG(1,("Getnameinfo failed for %s\n",p));
1110+ pstrcpy(name_buf, p);
1111+ } else {
1112+ if (matchname(hostbuf, sa))
1113+ pstrcpy(name_buf, hostbuf);
1114+ else {
1115+ DEBUG(0,("Matchname failed on %s %s\n",
1116+ name_buf, p));
1117+ pstrcpy(name_buf,p);
1118+ }
1119 }
1120 }
1121+#else
1122+ {
1123+ struct hostent *hp;
1124+ struct sockaddr_in *nsin = (struct sockaddr_in *)sa;
1125+
1126+ if(sa->sa_family != AF_INET)
1127+ {
1128+ SAFE_FREE(sa);
1129+ return name_buf;
1130+ }
1131+
1132+ /* Look up the remote host name. */
1133+ if ((hp = gethostbyaddr((char *)&nsin->sin_addr.s_addr,
1134+ sizeof(nsin->sin_addr.s_addr), AF_INET)) == 0) {
1135+ DEBUG(1,("Gethostbyaddr failed for %s\n",p));
1136+ pstrcpy(name_buf, p);
1137+ } else {
1138+ pstrcpy(name_buf,(char *)hp->h_name);
1139+ if (!matchname(name_buf, sa)) {
1140+ DEBUG(0,("Matchname failed on %s %s\n",
1141+ name_buf, p));
1142+ pstrcpy(name_buf,p);
1143+ }
1144+ }
1145+ }
1146+#endif
1147+ SAFE_FREE(sa);
1148
1149 alpha_strcpy(name_buf, name_buf, "_-.", sizeof(name_buf));
1150 if (strstr(name_buf,"..")) {
1151@@ -995,24 +1152,18 @@
1152 ******************************************************************/
1153 char *get_socket_addr(int fd)
1154 {
1155- struct sockaddr sa;
1156- struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
1157- int length = sizeof(sa);
1158 static fstring addr_buf;
1159+ struct sockaddr *sa;
1160+ int len;
1161
1162 fstrcpy(addr_buf,"0.0.0.0");
1163
1164- if (fd == -1) {
1165- return addr_buf;
1166+ if(get_socket_sa(fd, &sa, &len))
1167+ {
1168+ fstrcpy(addr_buf,print_sockaddr(sa));
1169+ SAFE_FREE(sa);
1170 }
1171
1172- if (getpeername(fd, &sa, &length) < 0) {
1173- DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) ));
1174- return addr_buf;
1175- }
1176-
1177- fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
1178-
1179 return addr_buf;
1180 }
1181
1182diff -ur samba-2.2.4/source/lib/wins_srv.c samba-2.2.4+IPv6-20020609/source/lib/wins_srv.c
1183--- samba-2.2.4/source/lib/wins_srv.c Thu May 2 21:03:12 2002
1184+++ samba-2.2.4+IPv6-20020609/source/lib/wins_srv.c Sun May 19 15:13:42 2002
1185@@ -155,7 +155,7 @@
1186 else
1187 {
1188 /* Add server to list. */
1189- if( is_ipaddress( wins_id_bufr ) )
1190+ if( is_ipv4address( wins_id_bufr ) )
1191 entry->ip_addr = *interpret_addr2( wins_id_bufr );
1192 else
1193 entry->ip_addr = *interpret_addr2( "0.0.0.0" );
1194diff -ur samba-2.2.4/source/libsmb/cli_lsarpc.c samba-2.2.4+IPv6-20020609/source/libsmb/cli_lsarpc.c
1195--- samba-2.2.4/source/libsmb/cli_lsarpc.c Thu May 2 21:03:12 2002
1196+++ samba-2.2.4+IPv6-20020609/source/libsmb/cli_lsarpc.c Sat Jun 8 20:21:05 2002
1197@@ -1057,6 +1057,7 @@
1198 {
1199 extern pstring global_myname;
1200 struct cli_state cli;
1201+ struct sockaddr_list *dest_addrs;
1202 NTSTATUS result;
1203 POLICY_HND lsa_pol;
1204 BOOL ret = False;
1205@@ -1067,20 +1068,22 @@
1206 return False;
1207 }
1208
1209- if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
1210+ if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
1211 DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
1212 goto done;
1213 }
1214
1215- if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
1216+ if (!cli_connect(&cli, remote_machine, dest_addrs)) {
1217 DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
1218 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
1219 goto done;
1220 }
1221
1222- if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
1223+ if (!attempt_netbios_session_request(&cli, global_myname,
1224+ remote_machine)) {
1225 DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
1226 remote_machine));
1227+ free_sockaddr_list(dest_addrs);
1228 goto done;
1229 }
1230
1231diff -ur samba-2.2.4/source/libsmb/cli_pipe_util.c samba-2.2.4+IPv6-20020609/source/libsmb/cli_pipe_util.c
1232--- samba-2.2.4/source/libsmb/cli_pipe_util.c Fri Feb 1 17:21:48 2002
1233+++ samba-2.2.4+IPv6-20020609/source/libsmb/cli_pipe_util.c Sun May 19 15:13:42 2002
1234@@ -27,7 +27,7 @@
1235 char *pipe_name,
1236 struct ntuser_creds *creds)
1237 {
1238- struct in_addr dest_ip;
1239+ struct sockaddr_list *dest_addrs;
1240 struct nmb_name calling, called;
1241 fstring dest_host;
1242 extern pstring global_myname;
1243@@ -49,15 +49,18 @@
1244
1245 /* Establish a SMB connection */
1246
1247- if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
1248+ if (!(dest_addrs = resolve_srv_name(system_name, dest_host,
1249+ cli->default_port))) {
1250 return NULL;
1251 }
1252
1253 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
1254 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
1255
1256- if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
1257+ if (!cli_establish_connection(cli, dest_host, dest_addrs, &calling,
1258 &called, "IPC$", "IPC", False, True)) {
1259+ cli_shutdown(cli);
1260+ free_sockaddr_list(dest_addrs);
1261 return NULL;
1262 }
1263
1264diff -ur samba-2.2.4/source/libsmb/cliconnect.c samba-2.2.4+IPv6-20020609/source/libsmb/cliconnect.c
1265--- samba-2.2.4/source/libsmb/cliconnect.c Thu May 2 21:03:13 2002
1266+++ samba-2.2.4+IPv6-20020609/source/libsmb/cliconnect.c Sat Jun 8 20:19:11 2002
1267@@ -430,7 +430,7 @@
1268 }
1269 }
1270
1271- if (cli->port == 445) {
1272+ if (is_directsmb(cli->connected_addr->addr)) {
1273 slprintf(fullshare, sizeof(fullshare)-1,
1274 "%s", share);
1275 } else {
1276@@ -638,8 +638,8 @@
1277 int len = 4;
1278 extern pstring user_socket_options;
1279
1280- /* 445 doesn't have session request */
1281- if (cli->port == 445) return True;
1282+ /* Direct SMB doesn't have session request */
1283+ if (is_directsmb(cli->connected_addr->addr)) return True;
1284
1285 /* send a session request (RFC 1002) */
1286 memcpy(&(cli->calling), calling, sizeof(*calling));
1287@@ -683,9 +683,12 @@
1288 */
1289 int port = (CVAL(cli->inbuf,8)<<8)+CVAL(cli->inbuf,9);
1290 /* SESSION RETARGET */
1291- putip((char *)&cli->dest_ip,cli->inbuf+4);
1292-
1293- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, port, LONG_CONNECT_TIMEOUT);
1294+ struct in_addr addr;
1295+ putip((char *)&addr,cli->inbuf+4);
1296+ if(cli->dest_addrs) free_sockaddr_list(cli->dest_addrs);
1297+ cli->dest_addrs = make_singlet_list(&addr, port);
1298+ cli->fd = open_socket_out(cli->dest_addrs,
1299+ &cli->connected_addr, LONG_CONNECT_TIMEOUT);
1300 if (cli->fd == -1)
1301 return False;
1302
1303@@ -728,10 +731,11 @@
1304 /****************************************************************************
1305 open the client sockets
1306 ****************************************************************************/
1307-BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
1308+BOOL cli_connect(struct cli_state *cli, const char *host,
1309+ struct sockaddr_list *salist)
1310 {
1311 extern pstring user_socket_options;
1312- int name_type = 0x20;
1313+ BOOL free_on_error = False;
1314 char *p;
1315
1316 /* reasonable default hostname */
1317@@ -739,45 +743,44 @@
1318 host = "*SMBSERVER";
1319
1320 fstrcpy(cli->desthost, host);
1321-
1322- /* allow hostnames of the form NAME#xx and do a netbios lookup */
1323- if ((p = strchr(cli->desthost, '#'))) {
1324- name_type = strtol(p+1, NULL, 16);
1325- *p = 0;
1326- }
1327-
1328- if (!ip || is_zero_ip(*ip)) {
1329- if (!resolve_name(cli->desthost, &cli->dest_ip, name_type)) {
1330- return False;
1331+
1332+ /* At this point, cli->dest_addrs should be empty */
1333+ if(cli->dest_addrs) free_sockaddr_list(cli->dest_addrs);
1334+
1335+ if(!salist) {
1336+ free_on_error = True;
1337+ if ((p = strchr(cli->desthost, '#'))) {
1338+ struct in_addr ip;
1339+ int name_type = strtol(p+1, NULL, 16);
1340+
1341+ *p = 0;
1342+ if(!resolve_name_netbios(cli->desthost, &ip, name_type))
1343+ return False;
1344+ salist = make_singlet_list(&ip, 139);
1345+ } else {
1346+ if(!(salist = resolve_name_smb(cli->desthost,
1347+ cli->default_port)))
1348+ return False;
1349 }
1350- if (ip)
1351- *ip = cli->dest_ip;
1352- } else {
1353- cli->dest_ip = *ip;
1354 }
1355-
1356+
1357 if (getenv("LIBSMB_PROG")) {
1358 cli->fd = sock_exec(getenv("LIBSMB_PROG"));
1359 } else {
1360- /* try 445 first, then 139 */
1361- int port = cli->port?cli->port:445;
1362- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
1363- port, cli->timeout);
1364- if (cli->fd == -1 && cli->port == 0) {
1365- port = 139;
1366- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
1367- port, cli->timeout);
1368- }
1369- if (cli->fd != -1) cli->port = port;
1370+ cli->fd = open_socket_out(salist, &cli->connected_addr,
1371+ cli->timeout);
1372 }
1373 if (cli->fd == -1) {
1374 DEBUG(1,("Error connecting to %s (%s)\n",
1375- inet_ntoa(*ip),strerror(errno)));
1376+ print_sockaddr(salist->addr),strerror(errno)));
1377+ if(free_on_error) free_sockaddr_list(salist);
1378 return False;
1379 }
1380
1381 set_socket_options(cli->fd,user_socket_options);
1382
1383+ cli->dest_addrs = salist;
1384+
1385 return True;
1386 }
1387
1388@@ -785,13 +788,14 @@
1389 establishes a connection right up to doing tconX, reading in a password.
1390 ****************************************************************************/
1391 BOOL cli_establish_connection(struct cli_state *cli,
1392- char *dest_host, struct in_addr *dest_ip,
1393+ char *dest_host, struct sockaddr_list *salist,
1394 struct nmb_name *calling, struct nmb_name *called,
1395 char *service, char *service_type,
1396 BOOL do_shutdown, BOOL do_tcon)
1397 {
1398 DEBUG(5,("cli_establish_connection: %s connecting to %s (%s) - %s [%s]\n",
1399- nmb_namestr(calling), nmb_namestr(called), inet_ntoa(*dest_ip),
1400+ nmb_namestr(calling), nmb_namestr(called),
1401+ salist ? print_sockaddr(salist->addr) : "unspecified",
1402 cli->user_name, cli->domain));
1403
1404 /* establish connection */
1405@@ -803,10 +807,12 @@
1406
1407 if (cli->fd == -1)
1408 {
1409- if (!cli_connect(cli, dest_host, dest_ip))
1410+ if (!cli_connect(cli, dest_host, salist))
1411 {
1412 DEBUG(1,("cli_establish_connection: failed to connect to %s (%s)\n",
1413- nmb_namestr(called), inet_ntoa(*dest_ip)));
1414+ nmb_namestr(called),
1415+ salist ? print_sockaddr(salist->addr)
1416+ : "unknown"));
1417 return False;
1418 }
1419 }
1420@@ -955,7 +961,7 @@
1421 struct nmb_name calling;
1422 struct nmb_name called;
1423 struct cli_state *cli;
1424- struct in_addr ip;
1425+ struct sockaddr_list *salist;
1426
1427 if (!output_cli)
1428 DEBUG(0, ("output_cli is NULL!?!"));
1429@@ -975,14 +981,14 @@
1430 return NT_STATUS_UNSUCCESSFUL;
1431 }
1432
1433- ip = *dest_ip;
1434+ salist = make_singlet_list(dest_ip, port);
1435
1436 DEBUG(3,("Connecting to host=%s share=%s\n", dest_host, service));
1437
1438- if (!cli_connect(cli, dest_host, &ip)) {
1439+ if (!cli_connect(cli, dest_host, salist)) {
1440 DEBUG(1,("cli_establish_connection: failed to connect to %s (%s)\n",
1441 nmb_namestr(&called), inet_ntoa(*dest_ip)));
1442- cli_shutdown(cli);
1443+ free_sockaddr_list(salist);
1444 return NT_STATUS_UNSUCCESSFUL;
1445 }
1446
1447@@ -1042,9 +1048,10 @@
1448 Attempt a NetBIOS session request, falling back to *SMBSERVER if needed.
1449 ****************************************************************************/
1450
1451-BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
1452- struct in_addr *pdest_ip)
1453+BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost,
1454+ char *desthost)
1455 {
1456+ struct sockaddr_list *dest_addrs_cache = cli->dest_addrs;
1457 struct nmb_name calling, called;
1458
1459 make_nmb_name(&calling, srchost, 0x0);
1460@@ -1082,9 +1089,11 @@
1461 return False;
1462 }
1463
1464+ cli->dest_addrs = NULL; /* we cached it, so it shouldn't free */
1465 cli_shutdown(cli);
1466
1467- if (!cli_initialise(cli) || !cli_connect(cli, desthost, pdest_ip) ||
1468+ if (!cli_initialise(cli) ||
1469+ !cli_connect(cli, desthost, dest_addrs_cache) ||
1470 !cli_session_request(cli, &calling, &smbservername))
1471 {
1472 DEBUG(0,("attempt_netbios_session_request: %s rejected the session for name *SMBSERVER with error %s\n",
1473diff -ur samba-2.2.4/source/libsmb/clidgram.c samba-2.2.4+IPv6-20020609/source/libsmb/clidgram.c
1474--- samba-2.2.4/source/libsmb/clidgram.c Thu May 2 21:03:13 2002
1475+++ samba-2.2.4+IPv6-20020609/source/libsmb/clidgram.c Sun May 19 15:13:42 2002
1476@@ -147,7 +147,7 @@
1477 struct sockaddr_in sock_out;
1478 socklen_t name_size;
1479
1480- if (!resolve_name(send_to_name, &sendto_ip, 0x1d)) {
1481+ if (!resolve_name_netbios(send_to_name, &sendto_ip, 0x1d)) {
1482
1483 DEBUG(0, ("Could not resolve name: %s<1D>\n", send_to_name));
1484 return False;
1485@@ -156,17 +156,15 @@
1486
1487 my_ip.s_addr = inet_addr("0.0.0.0");
1488
1489- if (!resolve_name(myname, &my_ip, 0x00)) { /* FIXME: Call others here */
1490+ if (!resolve_name_netbios(myname, &my_ip, 0x00)) { /* FIXME: Call others here */
1491
1492 DEBUG(0, ("Could not resolve name: %s<00>\n", myname));
1493
1494 }
1495
1496- if ((dgram_sock = open_socket_out(SOCK_DGRAM, &sendto_ip, 138, LONG_CONNECT_TIMEOUT)) < 0) {
1497-
1498- DEBUG(4, ("open_sock_out failed ..."));
1499+ if ((dgram_sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
1500+ DEBUG(0, ("socket failed (%s)", strerror(errno)));
1501 return False;
1502-
1503 }
1504
1505 /* Make it a broadcast socket ... */
1506diff -ur samba-2.2.4/source/libsmb/clientgen.c samba-2.2.4+IPv6-20020609/source/libsmb/clientgen.c
1507--- samba-2.2.4/source/libsmb/clientgen.c Thu May 2 21:03:13 2002
1508+++ samba-2.2.4+IPv6-20020609/source/libsmb/clientgen.c Sun May 19 15:13:42 2002
1509@@ -24,11 +24,14 @@
1510 #include "includes.h"
1511
1512 /*
1513- * Change the port number used to call on
1514+ * Change the default port number used to call on.
1515+ *
1516+ * This should only truly be used if we're operating on a non-standard
1517+ * port. The default behavior is to first try port 445, then 139.
1518 */
1519 int cli_set_port(struct cli_state *cli, int port)
1520 {
1521- cli->port = port;
1522+ cli->default_port = port;
1523 return port;
1524 }
1525
1526@@ -180,7 +183,9 @@
1527
1528 ZERO_STRUCTP(cli);
1529
1530- cli->port = 0;
1531+ cli->default_port = 0;
1532+ cli->dest_addrs = NULL;
1533+ cli->connected_addr = NULL;
1534 cli->fd = -1;
1535 cli->cnum = -1;
1536 cli->pid = (uint16)sys_getpid();
1537@@ -238,6 +243,9 @@
1538 SAFE_FREE(cli->outbuf);
1539 SAFE_FREE(cli->inbuf);
1540
1541+ if (cli->dest_addrs)
1542+ free_sockaddr_list(cli->dest_addrs);
1543+
1544 if (cli->mem_ctx)
1545 talloc_destroy(cli->mem_ctx);
1546
1547diff -ur samba-2.2.4/source/libsmb/domain_client_validate.c samba-2.2.4+IPv6-20020609/source/libsmb/domain_client_validate.c
1548--- samba-2.2.4/source/libsmb/domain_client_validate.c Thu May 2 21:03:14 2002
1549+++ samba-2.2.4+IPv6-20020609/source/libsmb/domain_client_validate.c Sat Jun 8 20:23:48 2002
1550@@ -32,7 +32,7 @@
1551 static BOOL connect_to_domain_password_server(struct cli_state *pcli,
1552 char *server, unsigned char *trust_passwd)
1553 {
1554- struct in_addr dest_ip;
1555+ struct sockaddr_list *dest_addrs;
1556 fstring remote_machine;
1557 NTSTATUS result;
1558
1559@@ -41,7 +41,7 @@
1560 return False;
1561 }
1562
1563- if (is_ipaddress(server)) {
1564+ if (is_ipv4address(server)) {
1565 struct in_addr to_ip;
1566
1567 /* we shouldn't have 255.255.255.255 forthe IP address of
1568@@ -63,27 +63,31 @@
1569 standard_sub_basic(remote_machine);
1570 strupper(remote_machine);
1571
1572- if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
1573+ if(!(dest_addrs = resolve_name_smb(remote_machine, pcli->default_port))) {
1574 DEBUG(1,("connect_to_domain_password_server: Can't resolve address for %s\n", remote_machine));
1575 cli_shutdown(pcli);
1576 return False;
1577 }
1578
1579+#if 0
1580 if (ismyip(dest_ip)) {
1581 DEBUG(1,("connect_to_domain_password_server: Password server loop - not using password server %s\n",
1582 remote_machine));
1583 cli_shutdown(pcli);
1584 return False;
1585 }
1586+#endif
1587
1588- if (!cli_connect(pcli, remote_machine, &dest_ip)) {
1589+ if (!cli_connect(pcli, remote_machine, dest_addrs)) {
1590 DEBUG(0,("connect_to_domain_password_server: unable to connect to SMB server on \
1591 machine %s. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
1592+ free_sockaddr_list(dest_addrs)
1593 cli_shutdown(pcli);
1594 return False;
1595 }
1596
1597- if (!attempt_netbios_session_request(pcli, global_myname, remote_machine, &dest_ip)) {
1598+ if (!attempt_netbios_session_request(pcli, global_myname,
1599+ remote_machine)) {
1600 DEBUG(0,("connect_to_password_server: machine %s rejected the NetBIOS session request.\n", remote_machine));
1601 return False;
1602 }
1603diff -ur samba-2.2.4/source/libsmb/libsmbclient.c samba-2.2.4+IPv6-20020609/source/libsmb/libsmbclient.c
1604--- samba-2.2.4/source/libsmb/libsmbclient.c Thu May 2 21:03:14 2002
1605+++ samba-2.2.4+IPv6-20020609/source/libsmb/libsmbclient.c Sat Jun 8 20:28:00 2002
1606@@ -244,10 +244,8 @@
1607 char *p, *server_n = server;
1608 fstring group;
1609 pstring ipenv;
1610- struct in_addr ip;
1611 int tried_reverse = 0;
1612
1613- zero_ip(&ip);
1614 ZERO_STRUCT(c);
1615
1616 /* try to use an existing connection */
1617@@ -305,10 +303,8 @@
1618 again:
1619 slprintf(ipenv,sizeof(ipenv)-1,"HOST_%s", server_n);
1620
1621- zero_ip(&ip);
1622-
1623 /* have to open a new connection */
1624- if (!cli_initialise(&c) || !cli_connect(&c, server_n, &ip)) {
1625+ if (!cli_initialise(&c) || !cli_connect(&c, server_n, NULL)) {
1626 if (c.initialised) cli_shutdown(&c);
1627 errno = ENOENT;
1628 return NULL;
1629@@ -324,7 +320,7 @@
1630
1631 /* Only try this if server is an IP address ... */
1632
1633- if (is_ipaddress(server) && !tried_reverse) {
1634+ if (is_ipv4address(server) && !tried_reverse) {
1635 fstring remote_name;
1636 struct in_addr rem_ip;
1637
1638@@ -1617,8 +1613,8 @@
1639 /* first try to get the LMB for our workgroup, and if that fails, */
1640 /* try the DMB */
1641
1642- if (!(resolve_name(lp_workgroup(), &rem_ip, 0x1d) ||
1643- resolve_name(lp_workgroup(), &rem_ip, 0x1b))) {
1644+ if (!(resolve_name_netbios(lp_workgroup(), &rem_ip, 0x1d) ||
1645+ resolve_name_netbios(lp_workgroup(), &rem_ip, 0x1b))) {
1646
1647 errno = EINVAL; /* Something wrong with smb.conf? */
1648 return -1;
1649@@ -1689,9 +1685,9 @@
1650 /* Check to see if <server><1D>, <server><1B>, or <server><20> translates */
1651 /* However, we check to see if <server> is an IP address first */
1652
1653- if (!is_ipaddress(server) && /* Not an IP addr so check next */
1654- (resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */
1655- resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */
1656+ if (!is_ipv4address(server) && /* Not an IP addr so check next */
1657+ (resolve_name_netbios(server, &rem_ip, 0x1d) || /* Found LMB */
1658+ resolve_name_netbios(server, &rem_ip, 0x1b) )) { /* Found DMB */
1659 pstring buserver;
1660
1661 smbc_file_table[slot]->dir_type = SMBC_SERVER;
1662@@ -1743,8 +1739,7 @@
1663
1664 }
1665 else {
1666-
1667- if (resolve_name(server, &rem_ip, 0x20)) {
1668+ if (resolve_name_netbios(server, &rem_ip, 0x20)) {
1669
1670 /* Now, list the shares ... */
1671
1672diff -ur samba-2.2.4/source/libsmb/namequery.c samba-2.2.4+IPv6-20020609/source/libsmb/namequery.c
1673--- samba-2.2.4/source/libsmb/namequery.c Thu May 2 21:03:14 2002
1674+++ samba-2.2.4+IPv6-20020609/source/libsmb/namequery.c Sat Jun 8 23:23:23 2002
1675@@ -628,15 +628,11 @@
1676 Resolve via "bcast" method.
1677 *********************************************************/
1678
1679-BOOL name_resolve_bcast(const char *name, int name_type,
1680- struct in_addr **return_ip_list, int *return_count)
1681+struct sockaddr_list *name_resolve_bcast(const char *name, int name_type)
1682 {
1683 int sock, i;
1684 int num_interfaces = iface_count();
1685
1686- *return_ip_list = NULL;
1687- *return_count = 0;
1688-
1689 /*
1690 * "bcast" means do a broadcast lookup on all the local interfaces.
1691 */
1692@@ -646,7 +642,7 @@
1693 sock = open_socket_in( SOCK_DGRAM, 0, 3,
1694 interpret_addr(lp_socket_address()), True );
1695
1696- if (sock == -1) return False;
1697+ if (sock == -1) return NULL;
1698
1699 set_socket_options(sock,"SO_BROADCAST");
1700 /*
1701@@ -655,33 +651,36 @@
1702 */
1703 for( i = num_interfaces-1; i >= 0; i--) {
1704 struct in_addr sendto_ip;
1705+ struct in_addr *addr;
1706+ int return_count;
1707+
1708 /* Done this way to fix compiler error on IRIX 5.x */
1709 sendto_ip = *iface_bcast(*iface_n_ip(i));
1710- *return_ip_list = name_query(sock, name, name_type, True,
1711- True, sendto_ip, return_count);
1712- if(*return_ip_list != NULL) {
1713+ addr = name_query(sock, name, name_type, True,
1714+ True, sendto_ip, &return_count);
1715+ if(addr != NULL) {
1716+ struct sockaddr_list *salist;
1717+
1718 close(sock);
1719- return True;
1720+ salist = make_sin_list(addr, return_count);
1721+ SAFE_FREE(addr);
1722+ return salist;
1723 }
1724 }
1725
1726 close(sock);
1727- return False;
1728+ return NULL;
1729 }
1730
1731 /********************************************************
1732 Resolve via "wins" method.
1733 *********************************************************/
1734
1735-static BOOL resolve_wins(const char *name, int name_type,
1736- struct in_addr **return_iplist, int *return_count)
1737+static struct sockaddr_list *resolve_wins(const char *name, int name_type)
1738 {
1739 int sock;
1740 struct in_addr wins_ip;
1741 BOOL wins_ismyip;
1742-
1743- *return_iplist = NULL;
1744- *return_count = 0;
1745
1746 /*
1747 * "wins" means do a unicast lookup to the WINS server.
1748@@ -703,7 +702,7 @@
1749 wins_ismyip = True;
1750 } else if( wins_srv_count() < 1 ) {
1751 DEBUG(3,("resolve_wins: WINS server resolution selected and no WINS servers listed.\n"));
1752- return False;
1753+ return NULL;
1754 } else {
1755 wins_ip = wins_srv_ip();
1756 wins_ismyip = ismyip(wins_ip);
1757@@ -715,27 +714,32 @@
1758 interpret_addr(lp_socket_address()),
1759 True );
1760 if (sock != -1) {
1761- *return_iplist = name_query( sock, name,
1762- name_type, False,
1763- True, wins_ip,
1764- return_count);
1765- if(*return_iplist != NULL) {
1766- close(sock);
1767- return True;
1768- }
1769+ struct in_addr *addr;
1770+ int return_count;
1771+
1772+ addr = name_query(sock, name,
1773+ name_type, False,
1774+ True, wins_ip,
1775+ &return_count);
1776 close(sock);
1777+ if(addr != NULL) {
1778+ struct sockaddr_list *salist;
1779+
1780+ salist = make_sin_list(addr, return_count);
1781+ SAFE_FREE(addr);
1782+ return salist;
1783+ }
1784 }
1785 }
1786
1787- return False;
1788+ return NULL;
1789 }
1790
1791 /********************************************************
1792 Resolve via "lmhosts" method.
1793 *********************************************************/
1794
1795-static BOOL resolve_lmhosts(const char *name, int name_type,
1796- struct in_addr **return_iplist, int *return_count)
1797+static struct sockaddr_list *resolve_lmhosts(const char *name, int name_type)
1798 {
1799 /*
1800 * "lmhosts" means parse the local lmhosts file.
1801@@ -746,9 +750,6 @@
1802 int name_type2;
1803 struct in_addr return_ip;
1804
1805- *return_iplist = NULL;
1806- *return_count = 0;
1807-
1808 DEBUG(3,("resolve_lmhosts: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
1809
1810 fp = startlmhosts( LMHOSTSFILE );
1811@@ -758,19 +759,12 @@
1812 ((name_type2 == -1) || (name_type == name_type2))
1813 ) {
1814 endlmhosts(fp);
1815- *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
1816- if(*return_iplist == NULL) {
1817- DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
1818- return False;
1819- }
1820- **return_iplist = return_ip;
1821- *return_count = 1;
1822- return True;
1823+ return make_sin_list(&return_ip, 1);
1824 }
1825 }
1826 endlmhosts(fp);
1827 }
1828- return False;
1829+ return NULL;
1830 }
1831
1832
1833@@ -778,32 +772,35 @@
1834 Resolve via "hosts" method.
1835 *********************************************************/
1836
1837-static BOOL resolve_hosts(const char *name,
1838- struct in_addr **return_iplist, int *return_count)
1839+static struct sockaddr_list *resolve_hosts(const char *name)
1840 {
1841 /*
1842 * "host" means do a localhost, or dns lookup.
1843 */
1844+#ifdef HAVE_INET6
1845+ struct addrinfo *ai, hints;
1846+ struct sockaddr_list *ret;
1847+
1848+ DEBUG(3,("resolve_hosts: Attempting getaddrinfo for name %s<0x20>\n", name));
1849+ memset(&hints, 0, sizeof(hints));
1850+ hints.ai_socktype = SOCK_STREAM;
1851+ if(getaddrinfo(name, NULL, &hints, &ai)) return NULL;
1852+ ret = make_sa_list(ai);
1853+ freeaddrinfo(ai);
1854+ return ret;
1855+#else
1856 struct hostent *hp;
1857
1858- *return_iplist = NULL;
1859- *return_count = 0;
1860-
1861 DEBUG(3,("resolve_hosts: Attempting host lookup for name %s<0x20>\n", name));
1862
1863 if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
1864- struct in_addr return_ip;
1865- putip((char *)&return_ip,(char *)hp->h_addr);
1866- *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
1867- if(*return_iplist == NULL) {
1868- DEBUG(3,("resolve_hosts: malloc fail !\n"));
1869- return False;
1870- }
1871- **return_iplist = return_ip;
1872- *return_count = 1;
1873- return True;
1874+ struct in_addr addr;
1875+
1876+ memcpy(&addr.s_addr, hp->h_addr, sizeof(addr.s_addr));
1877+ return make_sin_list(&addr, 1);
1878 }
1879- return False;
1880+ return NULL;
1881+#endif
1882 }
1883
1884 /********************************************************
1885@@ -811,40 +808,45 @@
1886 Use this function if the string is either an IP address, DNS
1887 or host name or NetBIOS name. This uses the name switch in the
1888 smb.conf to determine the order of name resolution.
1889+
1890+ WARNING: This function returns sockaddrs without the port set!
1891+ Don't try to connect to these without first setting
1892+ the port!
1893 *********************************************************/
1894
1895-static BOOL internal_resolve_name(const char *name, int name_type,
1896- struct in_addr **return_iplist, int *return_count)
1897+static struct sockaddr_list *internal_resolve_name(const char *name, int name_type)
1898 {
1899 pstring name_resolve_list;
1900 fstring tok;
1901 char *ptr;
1902- BOOL allones = (strcmp(name,"255.255.255.255") == 0);
1903- BOOL allzeros = (strcmp(name,"0.0.0.0") == 0);
1904- BOOL is_address = is_ipaddress(name);
1905- BOOL result = False;
1906- struct in_addr *nodupes_iplist;
1907- int i;
1908-
1909- *return_iplist = NULL;
1910- *return_count = 0;
1911-
1912- if (allzeros || allones || is_address) {
1913- *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr));
1914- if(*return_iplist == NULL) {
1915- DEBUG(3,("internal_resolve_name: malloc fail !\n"));
1916- return False;
1917- }
1918- if(is_address) {
1919- /* if it's in the form of an IP address then get the lib to interpret it */
1920- (*return_iplist)->s_addr = inet_addr(name);
1921- } else {
1922- (*return_iplist)->s_addr = allones ? 0xFFFFFFFF : 0;
1923- *return_count = 1;
1924- }
1925- return True;
1926+ struct sockaddr_list *salist = NULL, *cur;
1927+
1928+ if (is_ipaddress(name)) {
1929+ /* if it's in the form of an IP address then get
1930+ * the lib to interpret it */
1931+ struct sockaddr *sa;
1932+
1933+ if(!(sa = get_numeric_addr(name))) return NULL;
1934+ salist = (struct sockaddr_list *)malloc(sizeof(struct sockaddr_list));
1935+ salist->next = NULL;
1936+ salist->addr = sa;
1937+
1938+ /* This isn't kosher, but it would take a lot to make Samba
1939+ * be truly AF-independent. */
1940+#ifdef HAVE_INET6
1941+ if( sa->sa_family == AF_INET6 )
1942+ {
1943+ salist->pfamily = PF_INET6;
1944+ salist->len = sizeof(struct sockaddr_in6);
1945+ } else
1946+#endif
1947+ {
1948+ salist->pfamily = PF_INET;
1949+ salist->len = sizeof(struct sockaddr_in);
1950+ }
1951+ return salist;
1952 }
1953-
1954+
1955 pstrcpy(name_resolve_list, lp_name_resolve_order());
1956 ptr = name_resolve_list;
1957 if (!ptr || !*ptr)
1958@@ -852,138 +854,177 @@
1959
1960 while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
1961 if((strequal(tok, "host") || strequal(tok, "hosts"))) {
1962- if (name_type == 0x20 && resolve_hosts(name, return_iplist, return_count)) {
1963- result = True;
1964- goto done;
1965+ if (name_type == 0x20 && (salist = resolve_hosts(name)))
1966+ {
1967+ goto done;
1968 }
1969 } else if(strequal( tok, "lmhosts")) {
1970- if (resolve_lmhosts(name, name_type, return_iplist, return_count)) {
1971- result = True;
1972- goto done;
1973+ if ((salist=resolve_lmhosts(name, name_type))) {
1974+ goto done;
1975 }
1976 } else if(strequal( tok, "wins")) {
1977 /* don't resolve 1D via WINS */
1978 if (name_type != 0x1D &&
1979- resolve_wins(name, name_type, return_iplist, return_count)) {
1980- result = True;
1981- goto done;
1982+ (salist=resolve_wins(name, name_type))) {
1983+ goto done;
1984 }
1985 } else if(strequal( tok, "bcast")) {
1986- if (name_resolve_bcast(name, name_type, return_iplist, return_count)) {
1987- result = True;
1988- goto done;
1989+ if ((salist=name_resolve_bcast(name, name_type))) {
1990+ goto done;
1991 }
1992 } else {
1993 DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
1994 }
1995 }
1996
1997- /* All of the resolve_* functions above have returned false. */
1998-
1999- SAFE_FREE(*return_iplist);
2000- return False;
2001-
2002 done:
2003
2004 /* Remove duplicate entries. Some queries, notably #1c (domain
2005- controllers) return the PDC in iplist[0] and then all domain
2006- controllers including the PDC in iplist[1..n]. Iterating over
2007- the iplist when the PDC is down will cause two sets of timeouts. */
2008-
2009- if (*return_count && (nodupes_iplist =
2010- (struct in_addr *)malloc(sizeof(struct in_addr) * (*return_count)))) {
2011- int nodupes_count = 0;
2012-
2013- /* Iterate over return_iplist looking for duplicates */
2014-
2015- for (i = 0; i < *return_count; i++) {
2016- BOOL is_dupe = False;
2017- int j;
2018-
2019- for (j = i + 1; j < *return_count; j++) {
2020- if (ip_equal((*return_iplist)[i],
2021- (*return_iplist)[j])) {
2022- is_dupe = True;
2023- break;
2024- }
2025- }
2026-
2027- if (!is_dupe) {
2028-
2029- /* This one not a duplicate */
2030-
2031- nodupes_iplist[nodupes_count] = (*return_iplist)[i];
2032- nodupes_count++;
2033- }
2034- }
2035-
2036- /* Switcheroo with original list */
2037-
2038- free(*return_iplist);
2039-
2040- *return_iplist = nodupes_iplist;
2041- *return_count = nodupes_count;
2042+ controllers) return the PDC in the first node and then all domain
2043+ controllers including the PDC in the remainder of the list.
2044+ Iterating over the list when the PDC is down will cause two
2045+ sets of timeouts. */
2046+
2047+ for (cur = salist; cur; cur = cur->next)
2048+ {
2049+ struct sockaddr_list *i;
2050+
2051+ for(i = cur; i->next; i = i->next)
2052+ {
2053+ if(sa_host_equal(cur->addr,i->next->addr))
2054+ {
2055+ struct sockaddr_list *del = i->next;
2056+
2057+ i->next = del->next;
2058+ del->next = NULL;
2059+ free_sockaddr_list(del);
2060+ }
2061+ }
2062 }
2063-
2064- /* Display some debugging info */
2065-
2066- DEBUG(10, ("internal_resolve_name: returning %d addresses: ",
2067- *return_count));
2068-
2069- for (i = 0; i < *return_count; i++)
2070- DEBUGADD(10, ("%s ", inet_ntoa((*return_iplist)[i])));
2071-
2072- DEBUG(10, ("\n"));
2073-
2074- return result;
2075+
2076+ return salist;
2077 }
2078
2079+static BOOL internal_resolve_name_netbios(const char *name, int name_type,
2080+ struct in_addr **return_iplist, int *return_count)
2081+{
2082+ struct sockaddr_list *salist, *sl;
2083+ int i;
2084+
2085+ *return_iplist = NULL;
2086+ *return_count = 0;
2087+
2088+ salist = internal_resolve_name(name, name_type);
2089+ if(!salist) return False;
2090+
2091+ for(sl = salist; sl; sl = sl->next)
2092+ if(sl->addr->sa_family == AF_INET) ++*return_count;
2093+
2094+ *return_iplist = (struct in_addr *)
2095+ malloc(*return_count * sizeof(struct in_addr));
2096+
2097+ for(i = 0, sl = salist; i < *return_count; ++i)
2098+ if(sl->addr->sa_family == AF_INET)
2099+ *return_iplist[i] =
2100+ ((struct sockaddr_in *)(sl->addr))->sin_addr;
2101+
2102+ free_sockaddr_list(salist);
2103+
2104+ return True;
2105+}
2106+
2107+
2108 /********************************************************
2109- Internal interface to resolve a name into one IP address.
2110+ Internal interface to resolve a name into one IP address for NetBIOS.
2111 Use this function if the string is either an IP address, DNS
2112 or host name or NetBIOS name. This uses the name switch in the
2113 smb.conf to determine the order of name resolution.
2114 *********************************************************/
2115
2116-BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
2117+BOOL resolve_name_netbios(const char *name, struct in_addr *return_ip,
2118+ int name_type)
2119 {
2120- struct in_addr *ip_list = NULL;
2121- int count = 0;
2122+ struct sockaddr_list *salist;
2123
2124 if (is_ipaddress(name)) {
2125 *return_ip = *interpret_addr2(name);
2126 return True;
2127 }
2128
2129- if(internal_resolve_name(name, name_type, &ip_list, &count)) {
2130- int i;
2131+ if((salist = internal_resolve_name(name, name_type))) {
2132+ struct sockaddr_list *sl;
2133+ char *ip_str;
2134+
2135 /* only return valid addresses for TCP connections */
2136- for (i=0; i<count; i++) {
2137- char *ip_str = inet_ntoa(ip_list[i]);
2138- if (ip_str &&
2139+ for(sl = salist; sl; sl = sl->next) {
2140+ if ( sl->addr->sa_family == AF_INET &&
2141+ (ip_str = inet_ntoa(((struct sockaddr_in *)
2142+ (sl->addr))->sin_addr)) &&
2143 strcmp(ip_str, "255.255.255.255") != 0 &&
2144 strcmp(ip_str, "0.0.0.0") != 0) {
2145- *return_ip = ip_list[i];
2146- SAFE_FREE(ip_list);
2147+ *return_ip = ((struct sockaddr_in *)
2148+ (sl->addr))->sin_addr;
2149+ free_sockaddr_list(salist);
2150 return True;
2151 }
2152 }
2153+ free_sockaddr_list(salist);
2154 }
2155- SAFE_FREE(ip_list);
2156 return False;
2157 }
2158
2159+/********************************************************
2160+ Function to resolve a name into a list of addresses for
2161+ use with SMB. This uses the name switch in the smb.conf
2162+ to determine the order of name resolution.
2163+*********************************************************/
2164+
2165+struct sockaddr_list *resolve_name_smb(const char *name, int port)
2166+{
2167+ struct sockaddr_list *salist;
2168+
2169+ if((salist=internal_resolve_name(name, 0x20))) {
2170+ struct sockaddr_list *sl = salist, *old = NULL;
2171+ char *ip_str;
2172+
2173+ /* only return valid addresses for TCP connections */
2174+ while(sl)
2175+ {
2176+ if ( sl->addr->sa_family == AF_INET &&
2177+ (ip_str = inet_ntoa(((struct sockaddr_in *)
2178+ (sl->addr))->sin_addr)) &&
2179+ ( strcmp(ip_str, "255.255.255.255") == 0 ||
2180+ strcmp(ip_str, "0.0.0.0") == 0 ) )
2181+ {
2182+ struct sockaddr_list *next = sl->next;
2183+
2184+ SAFE_FREE(sl->addr);
2185+ SAFE_FREE(sl);
2186+ if(old == NULL) salist = next;
2187+ else old->next = next;
2188+ sl = next;
2189+ } else {
2190+ if(port) set_sockaddr_port(sl->addr, port);
2191+ old = sl;
2192+ sl = sl->next;
2193+ }
2194+ }
2195+ }
2196+ return port ? salist : set_default_ports(salist);
2197+}
2198+
2199
2200 /********************************************************
2201 resolve a name of format \\server_name or \\ipaddress
2202 into a name. also, cut the \\ from the front for us.
2203 *********************************************************/
2204
2205-BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
2206- struct in_addr *ip)
2207+struct sockaddr_list *resolve_srv_name(const char* srv_name,
2208+ fstring dest_host, int port)
2209 {
2210- BOOL ret;
2211 const char *sv_name = srv_name;
2212+ struct in_addr ip;
2213+ struct sockaddr_list *salist;
2214
2215 DEBUG(10,("resolve_srv_name: %s\n", srv_name));
2216
2217@@ -991,8 +1032,11 @@
2218 {
2219 extern pstring global_myname;
2220 fstrcpy(dest_host, global_myname);
2221- ip = interpret_addr2("127.0.0.1");
2222- return True;
2223+ inet_aton("127.0.0.1", &ip);
2224+ salist = make_sin_list(&ip, 1);
2225+ if(port) set_sockaddr_port(salist->addr, port);
2226+ else salist = set_default_ports(salist);
2227+ return salist;
2228 }
2229
2230 if (strnequal("\\\\", srv_name, 2))
2231@@ -1004,18 +1048,24 @@
2232 /* treat the '*' name specially - it is a magic name for the PDC */
2233 if (strcmp(dest_host,"*") == 0) {
2234 extern pstring global_myname;
2235- ret = resolve_name(lp_workgroup(), ip, 0x1B);
2236- lookup_dc_name(global_myname, lp_workgroup(), ip, dest_host);
2237- } else {
2238- ret = resolve_name(dest_host, ip, 0x20);
2239+
2240+ if(resolve_name_netbios(lp_workgroup(), &ip, 0x1B))
2241+ {
2242+ lookup_dc_name(global_myname, lp_workgroup(),
2243+ &ip, dest_host);
2244+ return make_singlet_list( &ip, port );
2245+ }
2246+ return NULL;
2247 }
2248+
2249+ salist = resolve_name_smb(dest_host, port);
2250
2251 if (is_ipaddress(dest_host))
2252 {
2253 fstrcpy(dest_host, "*SMBSERVER");
2254 }
2255
2256- return ret;
2257+ return salist;
2258 }
2259
2260
2261@@ -1028,12 +1078,12 @@
2262 struct in_addr *ip_list = NULL;
2263 int count = 0;
2264
2265- if (internal_resolve_name(group, 0x1D, &ip_list, &count)) {
2266+ if (internal_resolve_name_netbios(group, 0x1D, &ip_list, &count)) {
2267 *master_ip = ip_list[0];
2268 SAFE_FREE(ip_list);
2269 return True;
2270 }
2271- if(internal_resolve_name(group, 0x1B, &ip_list, &count)) {
2272+ if(internal_resolve_name_netbios(group, 0x1B, &ip_list, &count)) {
2273 *master_ip = ip_list[0];
2274 SAFE_FREE(ip_list);
2275 return True;
2276@@ -1271,7 +1321,7 @@
2277 struct in_addr *return_iplist = NULL;
2278
2279 if (! *pserver)
2280- return internal_resolve_name(group, name_type, ip_list, count);
2281+ return internal_resolve_name_netbios(group, name_type, ip_list, count);
2282
2283 p = pserver;
2284 while (next_token(&p,name,LIST_SEP,sizeof(name))) {
2285@@ -1280,14 +1330,14 @@
2286 * Use 1C followed by 1B. This shouldn't work but with
2287 * broken WINS servers it might. JRA.
2288 */
2289- if (!pdc_only && internal_resolve_name(group, 0x1C, ip_list, count))
2290+ if (!pdc_only && internal_resolve_name_netbios(group, 0x1C, ip_list, count))
2291 return True;
2292- return internal_resolve_name(group, 0x1B, ip_list, count);
2293+ return internal_resolve_name_netbios(group, 0x1B, ip_list, count);
2294 }
2295 num_adresses++;
2296 }
2297 if (num_adresses == 0)
2298- return internal_resolve_name(group, name_type, ip_list, count);
2299+ return internal_resolve_name_netbios(group, name_type, ip_list, count);
2300
2301 return_iplist = (struct in_addr *)malloc(num_adresses * sizeof(struct in_addr));
2302 if(return_iplist == NULL) {
2303@@ -1298,14 +1348,14 @@
2304 *count = 0;
2305 while (next_token(&p,name,LIST_SEP,sizeof(name))) {
2306 struct in_addr name_ip;
2307- if (resolve_name( name, &name_ip, 0x20) == False)
2308+ if (resolve_name_netbios(name, &name_ip, 0x20) == False)
2309 continue;
2310 return_iplist[(*count)++] = name_ip;
2311 }
2312 *ip_list = return_iplist;
2313 return (*count != 0);
2314 } else
2315- return internal_resolve_name(group, name_type, ip_list, count);
2316+ return internal_resolve_name_netbios(group, name_type, ip_list, count);
2317 }
2318
2319 /********************************************************
2320@@ -1314,5 +1364,5 @@
2321
2322 BOOL get_lmb_list(struct in_addr **ip_list, int *count)
2323 {
2324- return internal_resolve_name( MSBROWSE, 0x1, ip_list, count);
2325+ return internal_resolve_name_netbios( MSBROWSE, 0x1, ip_list, count);
2326 }
2327diff -ur samba-2.2.4/source/libsmb/passchange.c samba-2.2.4+IPv6-20020609/source/libsmb/passchange.c
2328--- samba-2.2.4/source/libsmb/passchange.c Fri Jan 7 01:55:34 2000
2329+++ samba-2.2.4+IPv6-20020609/source/libsmb/passchange.c Sun May 19 15:13:42 2002
2330@@ -33,11 +33,11 @@
2331 {
2332 struct nmb_name calling, called;
2333 struct cli_state cli;
2334- struct in_addr ip;
2335+ struct sockaddr_list *dest_addrs;
2336
2337 *err_str = '\0';
2338
2339- if(!resolve_name( remote_machine, &ip, 0x20)) {
2340+ if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
2341 slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
2342 remote_machine );
2343 return False;
2344@@ -45,9 +45,11 @@
2345
2346 ZERO_STRUCT(cli);
2347
2348- if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) {
2349+ if (!cli_initialise(&cli) ||
2350+ !cli_connect(&cli, remote_machine, dest_addrs)) {
2351 slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
2352 remote_machine, cli_errstr(&cli) );
2353+ free_sockaddr_list(dest_addrs);
2354 return False;
2355 }
2356
2357diff -ur samba-2.2.4/source/nmbd/nmbd_synclists.c samba-2.2.4+IPv6-20020609/source/nmbd/nmbd_synclists.c
2358--- samba-2.2.4/source/nmbd/nmbd_synclists.c Thu May 2 21:03:19 2002
2359+++ samba-2.2.4+IPv6-20020609/source/nmbd/nmbd_synclists.c Sun May 19 15:13:42 2002
2360@@ -68,10 +68,13 @@
2361 extern fstring local_machine;
2362 fstring unix_workgroup;
2363 static struct cli_state cli;
2364+ struct sockaddr_list *dest_addrs;
2365 uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
2366 struct nmb_name called, calling;
2367
2368- if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) {
2369+ dest_addrs = make_singlet_list(&ip, 0);
2370+ if (!cli_initialise(&cli) || !cli_connect(&cli, name, dest_addrs)) {
2371+ free_sockaddr_list(dest_addrs);
2372 return;
2373 }
2374
2375diff -ur samba-2.2.4/source/rpc_client/cli_spoolss_notify.c samba-2.2.4+IPv6-20020609/source/rpc_client/cli_spoolss_notify.c
2376--- samba-2.2.4/source/rpc_client/cli_spoolss_notify.c Thu May 2 21:03:33 2002
2377+++ samba-2.2.4+IPv6-20020609/source/rpc_client/cli_spoolss_notify.c Sat Jun 8 21:14:37 2002
2378@@ -75,25 +75,14 @@
2379 return False;
2380 }
2381
2382- if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
2383- DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
2384- cli_shutdown(cli);
2385- return False;
2386- }
2387-
2388- if (ismyip(cli->dest_ip)) {
2389- DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2390- cli_shutdown(cli);
2391- return False;
2392- }
2393-
2394- if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
2395+ if (!cli_connect(cli, remote_machine, NULL)) {
2396 DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
2397 cli_shutdown(cli);
2398 return False;
2399 }
2400
2401- if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
2402+ if (!attempt_netbios_session_request(cli, global_myname,
2403+ remote_machine)) {
2404 DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request.\n",
2405 remote_machine));
2406 return False;
2407diff -ur samba-2.2.4/source/rpc_client/cli_trust.c samba-2.2.4+IPv6-20020609/source/rpc_client/cli_trust.c
2408--- samba-2.2.4/source/rpc_client/cli_trust.c Thu May 2 21:03:33 2002
2409+++ samba-2.2.4+IPv6-20020609/source/rpc_client/cli_trust.c Sat Jun 8 21:17:22 2002
2410@@ -53,27 +53,14 @@
2411 return False;
2412 }
2413
2414- if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
2415- DEBUG(0,("modify_trust_password: Can't resolve address for %s\n", remote_machine));
2416- cli_shutdown(&cli);
2417- return False;
2418- }
2419-
2420- if (ismyip(cli.dest_ip)) {
2421- DEBUG(0,("modify_trust_password: Machine %s is one of our addresses. Cannot add \
2422-to ourselves.\n", remote_machine));
2423- cli_shutdown(&cli);
2424- return False;
2425- }
2426-
2427- if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
2428+ if (!cli_connect(&cli, remote_machine, NULL)) {
2429 DEBUG(0,("modify_trust_password: unable to connect to SMB server on \
2430 machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
2431 cli_shutdown(&cli);
2432 return False;
2433 }
2434
2435- if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
2436+ if (!attempt_netbios_session_request(&cli, global_myname, remote_machine)) {
2437 DEBUG(0,("modify_trust_password: machine %s rejected the NetBIOS session request.\n",
2438 remote_machine ));
2439 return False;
2440diff -ur samba-2.2.4/source/rpcclient/rpcclient.c samba-2.2.4+IPv6-20020609/source/rpcclient/rpcclient.c
2441--- samba-2.2.4/source/rpcclient/rpcclient.c Thu May 2 21:03:44 2002
2442+++ samba-2.2.4+IPv6-20020609/source/rpcclient/rpcclient.c Sat Jun 8 23:29:30 2002
2443@@ -741,7 +741,7 @@
2444
2445 /* Resolve the IP address */
2446
2447- if (!resolve_name(server, &server_ip, 0x20)) {
2448+ if (!resolve_name_netbios(server, &server_ip, 0x20)) {
2449 DEBUG(1,("Unable to resolve %s\n", server));
2450 return 1;
2451 }
2452diff -ur samba-2.2.4/source/smbd/password.c samba-2.2.4+IPv6-20020609/source/smbd/password.c
2453--- samba-2.2.4/source/smbd/password.c Thu May 2 21:03:48 2002
2454+++ samba-2.2.4+IPv6-20020609/source/smbd/password.c Sun May 19 15:25:05 2002
2455@@ -1015,7 +1015,7 @@
2456 {
2457 struct cli_state *cli;
2458 fstring desthost;
2459- struct in_addr dest_ip;
2460+ struct sockaddr_list *dest_addrs;
2461 char *p, *pserver;
2462 BOOL connected_ok = False;
2463
2464@@ -1031,21 +1031,23 @@
2465 standard_sub_basic(desthost);
2466 strupper(desthost);
2467
2468- if(!resolve_name( desthost, &dest_ip, 0x20)) {
2469+ if(!(dest_addrs = resolve_name_smb(desthost, 0))) {
2470 DEBUG(1,("server_cryptkey: Can't resolve address for %s\n",desthost));
2471 continue;
2472 }
2473
2474+#if 0
2475 if (ismyip(dest_ip)) {
2476 DEBUG(1,("Password server loop - disabling password server %s\n",desthost));
2477 continue;
2478 }
2479+#endif
2480
2481- if (cli_connect(cli, desthost, &dest_ip)) {
2482+ if (cli_connect(cli, desthost, dest_addrs)) {
2483 DEBUG(3,("connected to password server %s\n",desthost));
2484 connected_ok = True;
2485 break;
2486- }
2487+ } else free_sockaddr_list(dest_addrs);
2488 }
2489
2490 SAFE_FREE(pserver);
2491@@ -1056,7 +1058,7 @@
2492 return NULL;
2493 }
2494
2495- if (!attempt_netbios_session_request(cli, global_myname, desthost, &dest_ip))
2496+ if (!attempt_netbios_session_request(cli, global_myname, desthost))
2497 return NULL;
2498
2499 DEBUG(3,("got session\n"));
2500@@ -1220,7 +1222,7 @@
2501 static BOOL connect_to_domain_password_server(struct cli_state **ppcli,
2502 char *server, unsigned char *trust_passwd)
2503 {
2504- struct in_addr dest_ip;
2505+ struct sockaddr_list *dest_addrs;
2506 fstring remote_machine;
2507 struct cli_state *pcli = NULL;
2508
2509@@ -1231,7 +1233,7 @@
2510 return False;
2511 }
2512
2513- if (is_ipaddress(server)) {
2514+ if (is_ipv4address(server)) {
2515 struct in_addr to_ip;
2516
2517 /* we shouldn't have 255.255.255.255 forthe IP address of a password server anyways */
2518@@ -1251,18 +1253,20 @@
2519 standard_sub_basic(remote_machine);
2520 strupper(remote_machine);
2521
2522- if(!resolve_name( remote_machine, &dest_ip, 0x20)) {
2523+ if(!(dest_addrs = resolve_name_smb(remote_machine, 0))) {
2524 DEBUG(1,("connect_to_domain_password_server: Can't resolve address for %s\n", remote_machine));
2525 cli_shutdown(pcli);
2526 return False;
2527 }
2528
2529+#if 0
2530 if (ismyip(dest_ip)) {
2531 DEBUG(1,("connect_to_domain_password_server: Password server loop - not using password server %s\n",
2532 remote_machine));
2533 cli_shutdown(pcli);
2534 return False;
2535 }
2536+#endif
2537
2538 /* we use a mutex to prevent two connections at once - when a NT PDC gets
2539 two connections where one hasn't completed a negprot yet it will send a
2540@@ -1271,15 +1275,16 @@
2541 if (!grab_server_mutex(server))
2542 return False;
2543
2544- if (!cli_connect(pcli, remote_machine, &dest_ip)) {
2545+ if (!cli_connect(pcli, remote_machine, dest_addrs)) {
2546 DEBUG(0,("connect_to_domain_password_server: unable to connect to SMB server on \
2547 machine %s. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
2548+ free_sockaddr_list(dest_addrs);
2549 cli_shutdown(pcli);
2550 release_server_mutex();
2551 return False;
2552 }
2553
2554- if (!attempt_netbios_session_request(pcli, global_myname, remote_machine, &dest_ip)) {
2555+ if (!attempt_netbios_session_request(pcli, global_myname, remote_machine)) {
2556 DEBUG(0,("connect_to_password_server: machine %s rejected the NetBIOS \
2557 session request. Error was : %s.\n", remote_machine, cli_errstr(pcli) ));
2558 release_server_mutex();
2559diff -ur samba-2.2.4/source/smbwrapper/smbw.c samba-2.2.4+IPv6-20020609/source/smbwrapper/smbw.c
2560--- samba-2.2.4/source/smbwrapper/smbw.c Thu May 2 21:03:50 2002
2561+++ samba-2.2.4+IPv6-20020609/source/smbwrapper/smbw.c Sun May 19 15:26:18 2002
2562@@ -261,9 +261,7 @@
2563 {
2564 fstring server;
2565 char *p;
2566- struct in_addr *ip_list = NULL;
2567- int count = 0;
2568- int i;
2569+ struct sockaddr_list *wglist, *wg;
2570
2571 /* first off see if an existing workgroup name exists */
2572 p = smbw_getshared("WORKGROUP");
2573@@ -273,24 +271,29 @@
2574 if (smbw_server(server, "IPC$")) return p;
2575
2576 /* go looking for workgroups */
2577- if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) {
2578+ if (!(wglist = name_resolve_bcast(MSBROWSE, 1))) {
2579 DEBUG(1,("No workgroups found!"));
2580 return p;
2581 }
2582
2583- for (i=0;i<count;i++) {
2584+ for(wg = wglist; wg; wg = wg->next)
2585+ {
2586 static fstring name;
2587- if (name_status_find("*", 0, 0x1d, ip_list[i], name)) {
2588+
2589+ if(wg->addr->sa_family != AF_INET) continue;
2590+ if (name_status_find("*", 0, 0x1d, ((struct sockaddr_in *)
2591+ (wg->addr))->sin_addr, name))
2592+ {
2593 slprintf(server, sizeof(server), "%s#1D", name);
2594 if (smbw_server(server, "IPC$")) {
2595 smbw_setshared("WORKGROUP", name);
2596- SAFE_FREE(ip_list);
2597+ free_sockaddr_list(wglist);
2598 return name;
2599 }
2600 }
2601 }
2602
2603- SAFE_FREE(ip_list);
2604+ free_sockaddr_list(wglist);
2605
2606 return p;
2607 }
2608@@ -448,9 +451,8 @@
2609 char *p, *server_n = server;
2610 fstring group;
2611 pstring ipenv;
2612- struct in_addr ip;
2613+ struct sockaddr_list *salist;
2614
2615- zero_ip(&ip);
2616 ZERO_STRUCT(c);
2617
2618 get_auth_data_fn(server, share, &workgroup, &username, &password);
2619@@ -501,13 +503,15 @@
2620 again:
2621 slprintf(ipenv,sizeof(ipenv)-1,"HOST_%s", server_n);
2622
2623- zero_ip(&ip);
2624+ salist = resolve_name_smb((p=smbw_getshared(ipenv)) ? p : server_n, 0);
2625+
2626 if ((p=smbw_getshared(ipenv))) {
2627 ip = *(interpret_addr2(p));
2628 }
2629
2630 /* have to open a new connection */
2631- if (!cli_initialise(&c) || !cli_connect(&c, server_n, &ip)) {
2632+ if (!cli_initialise(&c) || !cli_connect(&c, server_n, salist)) {
2633+ free_sockaddr_list(salist);
2634 errno = ENOENT;
2635 return NULL;
2636 }
2637@@ -550,7 +554,7 @@
2638 return NULL;
2639 }
2640
2641- smbw_setshared(ipenv,inet_ntoa(ip));
2642+ smbw_setshared(ipenv,print_sockaddr(c.connected_addr->addr));
2643
2644 DEBUG(4,(" tconx ok\n"));
2645
2646diff -ur samba-2.2.4/source/utils/locktest.c samba-2.2.4+IPv6-20020609/source/utils/locktest.c
2647--- samba-2.2.4/source/utils/locktest.c Thu May 2 21:03:53 2002
2648+++ samba-2.2.4+IPv6-20020609/source/utils/locktest.c Sat Jun 8 19:47:44 2002
2649@@ -114,7 +114,6 @@
2650 struct nmb_name called, calling;
2651 char *server_n;
2652 fstring server;
2653- struct in_addr ip;
2654 fstring myname;
2655 static int count;
2656
2657@@ -126,19 +125,14 @@
2658
2659 server_n = server;
2660
2661- zero_ip(&ip);
2662-
2663 slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
2664
2665 make_nmb_name(&calling, myname, 0x0);
2666 make_nmb_name(&called , server, 0x20);
2667
2668 again:
2669- zero_ip(&ip);
2670-
2671 /* have to open a new connection */
2672- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2673- !cli_connect(c, server_n, &ip)) {
2674+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2675 DEBUG(0,("Connection to %s failed\n", server_n));
2676 return NULL;
2677 }
2678diff -ur samba-2.2.4/source/utils/locktest2.c samba-2.2.4+IPv6-20020609/source/utils/locktest2.c
2679--- samba-2.2.4/source/utils/locktest2.c Thu May 2 21:03:53 2002
2680+++ samba-2.2.4+IPv6-20020609/source/utils/locktest2.c Sat Jun 8 19:58:56 2002
2681@@ -156,7 +156,6 @@
2682 struct nmb_name called, calling;
2683 char *server_n;
2684 fstring server;
2685- struct in_addr ip;
2686 fstring myname;
2687 static int count;
2688
2689@@ -168,19 +167,14 @@
2690
2691 server_n = server;
2692
2693- zero_ip(&ip);
2694-
2695 slprintf(myname,sizeof(myname), "lock-%u-%u", getpid(), count++);
2696
2697 make_nmb_name(&calling, myname, 0x0);
2698 make_nmb_name(&called , server, 0x20);
2699
2700 again:
2701- zero_ip(&ip);
2702-
2703 /* have to open a new connection */
2704- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2705- !cli_connect(c, server_n, &ip)) {
2706+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2707 DEBUG(0,("Connection to %s failed\n", server_n));
2708 return NULL;
2709 }
2710diff -ur samba-2.2.4/source/utils/masktest.c samba-2.2.4+IPv6-20020609/source/utils/masktest.c
2711--- samba-2.2.4/source/utils/masktest.c Thu May 2 21:03:53 2002
2712+++ samba-2.2.4+IPv6-20020609/source/utils/masktest.c Sat Jun 8 19:49:52 2002
2713@@ -165,7 +165,6 @@
2714 struct nmb_name called, calling;
2715 char *server_n;
2716 char *server;
2717- struct in_addr ip;
2718
2719 server = share+2;
2720 share = strchr(server,'\\');
2721@@ -175,17 +174,12 @@
2722
2723 server_n = server;
2724
2725- zero_ip(&ip);
2726-
2727 make_nmb_name(&calling, "masktest", 0x0);
2728 make_nmb_name(&called , server, 0x20);
2729
2730 again:
2731- zero_ip(&ip);
2732-
2733 /* have to open a new connection */
2734- if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
2735- !cli_connect(c, server_n, &ip)) {
2736+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, NULL)) {
2737 DEBUG(0,("Connection to %s failed\n", server_n));
2738 return NULL;
2739 }
2740diff -ur samba-2.2.4/source/utils/smbcacls.c samba-2.2.4+IPv6-20020609/source/utils/smbcacls.c
2741--- samba-2.2.4/source/utils/smbcacls.c Thu May 2 21:03:53 2002
2742+++ samba-2.2.4+IPv6-20020609/source/utils/smbcacls.c Sat Jun 8 23:31:45 2002
2743@@ -712,7 +712,6 @@
2744 {
2745 struct cli_state *c;
2746 struct nmb_name called, calling;
2747- struct in_addr ip;
2748 extern pstring global_myname;
2749
2750 fstrcpy(server,share+2);
2751@@ -721,18 +720,13 @@
2752 *share = 0;
2753 share++;
2754
2755- zero_ip(&ip);
2756-
2757 make_nmb_name(&calling, global_myname, 0x0);
2758 make_nmb_name(&called , server, 0x20);
2759
2760 again:
2761- zero_ip(&ip);
2762-
2763 /* have to open a new connection */
2764- if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, &ip)) {
2765+ if (!(c=cli_initialise(NULL)) || !cli_connect(c, server, NULL)) {
2766 DEBUG(0,("Connection to %s failed\n", server));
2767- cli_shutdown(c);
2768 return NULL;
2769 }
2770
2771diff -ur samba-2.2.4/source/utils/smbfilter.c samba-2.2.4+IPv6-20020609/source/utils/smbfilter.c
2772--- samba-2.2.4/source/utils/smbfilter.c Sat Feb 2 19:46:57 2002
2773+++ samba-2.2.4+IPv6-20020609/source/utils/smbfilter.c Sun May 19 15:13:43 2002
2774@@ -98,15 +98,17 @@
2775 }
2776
2777
2778-static void filter_child(int c, struct in_addr dest_ip)
2779+static void filter_child(int c, struct sockaddr_list *dest_addrs)
2780 {
2781 int s;
2782
2783 /* we have a connection from a new client, now connect to the server */
2784- s = open_socket_out(SOCK_STREAM, &dest_ip, 139, LONG_CONNECT_TIMEOUT);
2785+ s = open_socket_out(dest_addrs, NULL, LONG_CONNECT_TIMEOUT);
2786+ free_sockaddr_list(dest_addrs);
2787
2788 if (s == -1) {
2789- DEBUG(0,("Unable to connect to %s\n", inet_ntoa(dest_ip)));
2790+ DEBUG(0,("Unable to connect to %s\n",
2791+ print_sockaddr(dest_addrs->addr)));
2792 exit(1);
2793 }
2794
2795@@ -152,7 +154,7 @@
2796 static void start_filter(char *desthost)
2797 {
2798 int s, c;
2799- struct in_addr dest_ip;
2800+ struct sockaddr_list *dest_addrs;
2801
2802 CatchChild();
2803
2804@@ -168,7 +170,7 @@
2805 DEBUG(0,("listen failed\n"));
2806 }
2807
2808- if (!resolve_name(desthost, &dest_ip, 0x20)) {
2809+ if (!(dest_addrs = resolve_name_smb(desthost, 0))) {
2810 DEBUG(0,("Unable to resolve host %s\n", desthost));
2811 exit(1);
2812 }
2813@@ -188,7 +190,7 @@
2814 if (c != -1) {
2815 if (fork() == 0) {
2816 close(s);
2817- filter_child(c, dest_ip);
2818+ filter_child(c, dest_addrs);
2819 exit(0);
2820 } else {
2821 close(c);
2822diff -ur samba-2.2.4/source/utils/smbpasswd.c samba-2.2.4+IPv6-20020609/source/utils/smbpasswd.c
2823--- samba-2.2.4/source/utils/smbpasswd.c Thu May 2 21:03:54 2002
2824+++ samba-2.2.4+IPv6-20020609/source/utils/smbpasswd.c Sat Jun 8 19:58:05 2002
2825@@ -280,7 +280,7 @@
2826 struct ntuser_creds creds;
2827 struct cli_state cli;
2828 fstring acct_name;
2829- struct in_addr dest_ip;
2830+ struct sockaddr_list *dest_addrs = NULL;
2831 TALLOC_CTX *mem_ctx;
2832
2833 /* rpc variables */
2834@@ -343,19 +343,20 @@
2835 fprintf(stderr, "Unable to lookup the name for the domain controller for domain %s.\n", domain);
2836 return 1;
2837 }
2838- dest_ip = ip_list[0];
2839+ dest_addrs = make_singlet_list( &ip_list[0], 0 );
2840 }
2841
2842 make_nmb_name(&called, pdc_name, 0x20);
2843 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
2844
2845- if (!cli_establish_connection(&cli, pdc_name, &dest_ip, &calling,
2846+ if (!cli_establish_connection(&cli, pdc_name, dest_addrs, &calling,
2847 &called, "IPC$", "IPC", False, True)) {
2848 if (!NT_STATUS_IS_OK(cli_nt_error(&cli))) {
2849 DEBUG(0, ("Error connecting to %s - %s\n", pdc_name,cli_errstr(&cli)));
2850 } else {
2851 DEBUG(0, ("Error connecting to %s\n", pdc_name));
2852 }
2853+ if( dest_addrs ) free_sockaddr_list( dest_addrs );
2854 goto done;
2855 }
2856
2857@@ -541,6 +542,9 @@
2858 if (cli.nt_pipe_fnum)
2859 cli_nt_session_close(&cli);
2860
2861+ if (cli.dest_addrs)
2862+ free_sockaddr_list(cli.dest_addrs);
2863+
2864 /* Display success or failure */
2865
2866 if (retval != 0) {
2867diff -ur samba-2.2.4/source/utils/torture.c samba-2.2.4+IPv6-20020609/source/utils/torture.c
2868--- samba-2.2.4/source/utils/torture.c Thu May 2 21:03:54 2002
2869+++ samba-2.2.4+IPv6-20020609/source/utils/torture.c Sat Jun 8 19:48:28 2002
2870@@ -134,16 +134,13 @@
2871 static BOOL open_nbt_connection(struct cli_state *c)
2872 {
2873 struct nmb_name called, calling;
2874- struct in_addr ip;
2875
2876 ZERO_STRUCTP(c);
2877
2878 make_nmb_name(&calling, myname, 0x0);
2879 make_nmb_name(&called , host, 0x20);
2880
2881- zero_ip(&ip);
2882-
2883- if (!cli_initialise(c) || !cli_connect(c, host, &ip)) {
2884+ if (!cli_initialise(c) || !cli_connect(c, host, NULL)) {
2885 printf("Failed to connect with %s\n", host);
2886 return False;
2887 }
2888diff -ur samba-2.2.4/source/web/diagnose.c samba-2.2.4+IPv6-20020609/source/web/diagnose.c
2889--- samba-2.2.4/source/web/diagnose.c Sat Feb 2 19:46:58 2002
2890+++ samba-2.2.4+IPv6-20020609/source/web/diagnose.c Sun May 19 15:13:43 2002
2891@@ -52,12 +52,16 @@
2892 BOOL smbd_running(void)
2893 {
2894 static struct cli_state cli;
2895+ struct sockaddr_list *localaddrs;
2896 extern struct in_addr loopback_ip;
2897
2898 if (!cli_initialise(&cli))
2899 return False;
2900
2901- if (!cli_connect(&cli, "localhost", &loopback_ip)) {
2902+ localaddrs = make_singlet_list(&loopback_ip, 0);
2903+ if (!cli_connect(&cli, "localhost", localaddrs))
2904+ {
2905+ free_sockaddr_list(localaddrs);
2906 cli_shutdown(&cli);
2907 return False;
2908 }
This page took 0.501601 seconds and 4 git commands to generate.