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