From ce394449c7923b815946d53a1059b04847abed02 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Dec 1999 06:11:25 +0000 Subject: added basic nsswitch support - this allows you to use a "wins" entry in a /etc/nsswitch.conf hosts line. Only tested on RH6.1, but should work on a broad range of Linux distributions. It could probably be made to work with Solaris pretty easily. It does not build by default. Build it with "make nsswitch" (This used to be commit 4058eb5bffeec539f71786580376419ea5749351) --- source3/nsswitch/wins.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 source3/nsswitch/wins.c (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c new file mode 100644 index 0000000000..6c291bb1bf --- /dev/null +++ b/source3/nsswitch/wins.c @@ -0,0 +1,129 @@ +/* + Unix SMB/Netbios implementation. + Version 2.0 + a WINS nsswitch module + Copyright (C) Andrew Tridgell 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#define NO_SYSLOG + +#include "includes.h" +#include + +extern int DEBUGLEVEL; + +#ifndef INADDRSZ +#define INADDRSZ 4 +#endif + +struct in_addr *lookup_backend(const char *name, int *count) +{ + int fd; + static int initialised; + struct in_addr *ret; + char *p; + int j; + + if (!initialised) { + initialised = 1; + DEBUGLEVEL = 0; + TimeInit(); + setup_logging("nss_wins",True); + charset_initialise(); + lp_load(CONFIGFILE,True,False,False); + load_interfaces(); + } + + *count = 0; + + fd = open_socket_in(SOCK_DGRAM,0, 3, interpret_addr("0.0.0.0"), True); + if (fd == -1) return NULL; + + set_socket_options(fd,"SO_BROADCAST"); + + p = lp_wins_server(); + if (p && *p) { + ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count,NULL); + goto out; + } + + if (lp_wins_support()) { + /* we are our own WINS server */ + ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count,NULL); + goto out; + } + + /* uggh, we have to broadcast to each interface in turn */ + for (j=iface_count() - 1; + j >= 0; + j--) { + struct in_addr *bcast = iface_n_bcast(j); + ret = name_query(fd,name,0x20,True,True,*bcast,count,NULL); + if (ret) break; + } + + out: + close(fd); + return ret; +} + + +/**************************************************************************** +gethostbyname() - we ignore any domain portion of the name and only +handle names that are at most 15 characters long + **************************************************************************/ +enum nss_status +_nss_wins_gethostbyname_r(const char *name, struct hostent *he, + char *buffer, size_t buflen, int *errnop, + int *h_errnop) +{ + char **host_addresses; + struct in_addr *ip_list; + int i, count; + + ip_list = lookup_backend(name, &count); + if (!ip_list) { + return NSS_STATUS_NOTFOUND; + } + + if (buflen < (2*count+1)*INADDRSZ) { + /* no ENOMEM error type?! */ + return NSS_STATUS_NOTFOUND; + } + + + host_addresses = (char **)buffer; + he->h_addr_list = host_addresses; + host_addresses[count] = NULL; + buffer += (count + 1) * INADDRSZ; + buflen += (count + 1) * INADDRSZ; + he->h_addrtype = AF_INET; + he->h_length = INADDRSZ; + + for (i=0;i Date: Fri, 7 Jan 2000 08:46:33 +0000 Subject: remove scope parameter here too (This used to be commit c78deb1d229bd301be483a256f1fd2047cec6120) --- source3/nsswitch/wins.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 6c291bb1bf..f8a05a9fbf 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -58,13 +58,13 @@ struct in_addr *lookup_backend(const char *name, int *count) p = lp_wins_server(); if (p && *p) { - ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count,NULL); + ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count); goto out; } if (lp_wins_support()) { /* we are our own WINS server */ - ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count,NULL); + ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count); goto out; } @@ -73,7 +73,7 @@ struct in_addr *lookup_backend(const char *name, int *count) j >= 0; j--) { struct in_addr *bcast = iface_n_bcast(j); - ret = name_query(fd,name,0x20,True,True,*bcast,count,NULL); + ret = name_query(fd,name,0x20,True,True,*bcast,count); if (ret) break; } -- cgit From b35f21fb3a19417e2aab82a573ff121a086b224c Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 19 Jul 2000 01:21:30 +0000 Subject: First cut toward adding WINS server failover. *Note: failover doesn't actually work yet!* It's just that the code I'm adding provides all of the pieces necessary. I do have one big question. Something that I'll have to ask Jeremy, I'm thinkin'. In nmbd/nmbd_subnetdb.c the IP of the WINS server is used to set up the Unicast subnet. ...so what happens if the WINS server changes? My guess is either: a) nothing. b) I'd have to change the unicast subnet entry whenever the WINS server changes. Urq. BTW, the lp_wins_server() function no longer returns the WINS server name or IP. It returns the list of WINS servers entered in smb.conf. To get the currently 'live' WINS server, use the wins_srv() function. Fun, eh? Chris -)----- (This used to be commit cc08bdc74f4cd111fdc582ee7babef47ed8a950d) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index f8a05a9fbf..41b71c64bb 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -56,7 +56,7 @@ struct in_addr *lookup_backend(const char *name, int *count) set_socket_options(fd,"SO_BROADCAST"); - p = lp_wins_server(); + p = wins_srv(); if (p && *p) { ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count); goto out; -- cgit From 3c9e410c340d53897a3f97243d8286812704f6c0 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 19 Jul 2000 05:32:43 +0000 Subject: Instead of handing back a string (which might be a DNS name or an IP string), the wins_srv module now hands back a struct in_addr when it's called. It caches the IP address once it has been looked up. The IP is cleared (and must be looked up again) if the 'wins server' parameter is reread, or if the node is marked 'dead'. A dead node will not be re-tried for 10 minutes (per a #define in wins_srv.c). As it was, the code was reading the WINS server name or IP directly from lp_wins_server. That's okay, except that if the value was expressed as a name, then a DNS lookup would be done every time the client wanted to talk to the server. I still need to work out the implications of failover regarding the 'unicast subnet' list. Chris -)----- (This used to be commit 73aa188320fd3bf10b5dfc057323f40aff2c13bd) --- source3/nsswitch/wins.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 41b71c64bb..ca0f22e3a6 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -36,7 +36,6 @@ struct in_addr *lookup_backend(const char *name, int *count) int fd; static int initialised; struct in_addr *ret; - char *p; int j; if (!initialised) { @@ -56,9 +55,8 @@ struct in_addr *lookup_backend(const char *name, int *count) set_socket_options(fd,"SO_BROADCAST"); - p = wins_srv(); - if (p && *p) { - ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count); + if( !zero_ip( wins_ip ) ) { + ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count ); goto out; } -- cgit From 96e27b10bfebbf8f577d7e341cdf2740b607bb15 Mon Sep 17 00:00:00 2001 From: John Terpstra Date: Mon, 9 Oct 2000 21:44:00 +0000 Subject: Fixes to allow wins.c to compile to allow building of libnss_wins.so. (This used to be commit 3fb2e94c4430c570639c0e4d1caeed3a19bbd09b) --- source3/nsswitch/wins.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index ca0f22e3a6..6fbaedcdea 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -36,6 +36,7 @@ struct in_addr *lookup_backend(const char *name, int *count) int fd; static int initialised; struct in_addr *ret; + char *p; int j; if (!initialised) { @@ -55,8 +56,16 @@ struct in_addr *lookup_backend(const char *name, int *count) set_socket_options(fd,"SO_BROADCAST"); - if( !zero_ip( wins_ip ) ) { - ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count ); +/* The next four lines commented out by JHT + and replaced with the four lines following */ +/* if( !zero_ip( wins_ip ) ) { + * ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count ); + * goto out; + * } + */ + p = lp_wins_server(); + if (p && *p) { + ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count); goto out; } -- cgit From 9a872fb616e54a8cee07963ec318a7939f3794af Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 11 Oct 2000 15:54:17 +0000 Subject: Converted to call lib/wins_srv.c:wins_srv_ip() instead of lp_wins_server() when looking up the WINS server address. Please *don't* use lp_wins_server() any more! The wins_srv_ip() function has the following features: - If the WINS server was entered as a DNS name then the translation to an IP address will already have taken place. We used to do this every time a call to the WINS server was made. Ick. - The return value of wins_srv_ip() is a struct in_addr. Ready to go. - When WINS failover is fully implemented, you'll be able to enter a colon- separated list of WINS servers via the WINS SERVER parameter. Using lp_wins_server() directly will fail if this syntax is used. Chris -)----- (This used to be commit 56be7c2a49a8a918318a70843fff4e89ec10d0d3) --- source3/nsswitch/wins.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 6fbaedcdea..be76c2e54e 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -36,7 +36,7 @@ struct in_addr *lookup_backend(const char *name, int *count) int fd; static int initialised; struct in_addr *ret; - char *p; + struct in_addr p; int j; if (!initialised) { @@ -63,9 +63,9 @@ struct in_addr *lookup_backend(const char *name, int *count) * goto out; * } */ - p = lp_wins_server(); - if (p && *p) { - ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count); + p = wins_srv_ip(); + if( !zero_ip(p) ) { + ret = name_query(fd,name,0x20,False,True, p, count); goto out; } -- cgit From 199bb03916745ecf9ae514f011acff1d6ec63a10 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 May 2001 21:53:19 +0000 Subject: Fixed glibc crash problems with libnss_wins.so Jeremy. (This used to be commit c38a465bef91bc54cd3f3ce81e5a9c818f429801) --- source3/nsswitch/wins.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index be76c2e54e..49edf3a88b 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -31,6 +31,39 @@ extern int DEBUGLEVEL; #define INADDRSZ 4 #endif +/* Use our own create socket code so we don't recurse.... */ + +static int wins_lookup_open_socket_in(void) +{ + struct sockaddr_in sock; + int val=1; + int res; + + memset((char *)&sock,'\0',sizeof(sock)); + +#ifdef HAVE_SOCK_SIN_LEN + sock.sin_len = sizeof(sock); +#endif + sock.sin_port = 0; + sock.sin_family = AF_INET; + sock.sin_addr.s_addr = interpret_addr("0.0.0.0"); + res = socket(AF_INET, SOCK_DGRAM, 0); + if (res == -1) + return -1; + + setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)); +#ifdef SO_REUSEPORT + setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)); +#endif /* SO_REUSEPORT */ + + /* now we've got a socket - we need to bind it */ + + if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) + return(-1); + + return res; +} + struct in_addr *lookup_backend(const char *name, int *count) { int fd; @@ -51,8 +84,9 @@ struct in_addr *lookup_backend(const char *name, int *count) *count = 0; - fd = open_socket_in(SOCK_DGRAM,0, 3, interpret_addr("0.0.0.0"), True); - if (fd == -1) return NULL; + fd = wins_lookup_open_socket_in(); + if (fd == -1) + return NULL; set_socket_options(fd,"SO_BROADCAST"); @@ -85,6 +119,7 @@ struct in_addr *lookup_backend(const char *name, int *count) } out: + close(fd); return ret; } @@ -102,13 +137,14 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, char **host_addresses; struct in_addr *ip_list; int i, count; + size_t namelen = strlen(name) + 1; ip_list = lookup_backend(name, &count); if (!ip_list) { return NSS_STATUS_NOTFOUND; } - if (buflen < (2*count+1)*INADDRSZ) { + if (buflen < namelen + (2*count+1)*INADDRSZ) { /* no ENOMEM error type?! */ return NSS_STATUS_NOTFOUND; } @@ -130,7 +166,11 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, host_addresses++; } - if (ip_list) free(ip_list); + if (ip_list) + free(ip_list); + + memcpy(buffer, name, namelen); + he->h_name = buffer; return NSS_STATUS_SUCCESS; } -- cgit From 109851ae5c40fdbaa426d40c81bf75cd45d7d858 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 May 2001 22:01:48 +0000 Subject: Zero-fill struct hostent. Jeremy. (This used to be commit 86557d633648f279e6ceda4da38801889ca4ed95) --- source3/nsswitch/wins.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 49edf3a88b..ac6d13a64f 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -139,6 +139,8 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, int i, count; size_t namelen = strlen(name) + 1; + memset(he, '\0', sizeof(*he)); + ip_list = lookup_backend(name, &count); if (!ip_list) { return NSS_STATUS_NOTFOUND; -- cgit From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/nsswitch/wins.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index ac6d13a64f..bfd1835b4e 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -77,7 +77,6 @@ struct in_addr *lookup_backend(const char *name, int *count) DEBUGLEVEL = 0; TimeInit(); setup_logging("nss_wins",True); - charset_initialise(); lp_load(CONFIGFILE,True,False,False); load_interfaces(); } -- cgit From b50d10c2a313b45bbc195b13a353a20af0ab917a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 04:52:45 +0000 Subject: move to SAFE_FREE() (This used to be commit 03dc67788f68c9e01b5a82fdf43f837cb19f4608) --- source3/nsswitch/wins.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index bfd1835b4e..c4485ca03a 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -167,8 +167,7 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, host_addresses++; } - if (ip_list) - free(ip_list); + SAFE_FREE(ip_list); memcpy(buffer, name, namelen); he->h_name = buffer; -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/nsswitch/wins.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index c4485ca03a..a3d5bb08de 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -25,8 +25,6 @@ #include "includes.h" #include -extern int DEBUGLEVEL; - #ifndef INADDRSZ #define INADDRSZ 4 #endif -- cgit From f741f656737f4ec46cd318e986b6bf412ed309d2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 02:49:53 +0000 Subject: Store some path names in global variables initialized to configure default, rather than in preprocessor macros. (This used to be commit 79ec88f0da40faebe1e587f1b3e87b5f2b184f58) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index a3d5bb08de..b66ef88e04 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -75,7 +75,7 @@ struct in_addr *lookup_backend(const char *name, int *count) DEBUGLEVEL = 0; TimeInit(); setup_logging("nss_wins",True); - lp_load(CONFIGFILE,True,False,False); + lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); } -- cgit From 79b34d1b11e685d068b9c0ac9a0ec06eaa263d82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 23 Nov 2001 00:52:29 +0000 Subject: Removed TimeInit() call from every client program (except for one place in smbd/process.c where the timezone is reinitialised. Was replaced with check for a static is_initialised boolean. (This used to be commit 8fc772c9e5770cd3a8857670214dcff033ebae32) --- source3/nsswitch/wins.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index b66ef88e04..e23cf9ea03 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -73,7 +73,6 @@ struct in_addr *lookup_backend(const char *name, int *count) if (!initialised) { initialised = 1; DEBUGLEVEL = 0; - TimeInit(); setup_logging("nss_wins",True); lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); -- cgit From 585d0efbc6428e5876d354fee49c241c1bad809d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 26 Nov 2001 03:11:44 +0000 Subject: Got medieval on another pointless extern. Removed extern struct ipzero and replaced with two functions: void zero_ip(struct in_adder *ip); BOOL is_zero_ip(struct in_addr ip); (This used to be commit 778f5f77a66cda76348a7c6f64cd63afe2bfe077) --- source3/nsswitch/wins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index e23cf9ea03..abc7b6f414 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -88,13 +88,13 @@ struct in_addr *lookup_backend(const char *name, int *count) /* The next four lines commented out by JHT and replaced with the four lines following */ -/* if( !zero_ip( wins_ip ) ) { +/* if( !is_zero_ip( wins_ip ) ) { * ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count ); * goto out; * } */ p = wins_srv_ip(); - if( !zero_ip(p) ) { + if( !is_zero_ip(p) ) { ret = name_query(fd,name,0x20,False,True, p, count); goto out; } -- cgit From ed7caa2ecf70eb9a0b08467c37391a54bd4620d0 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 12 Dec 2001 16:08:32 +0000 Subject: allow IRIX to build nsswitch/libnss_wins.so (This used to be commit 564bfd77287b3006c7246065990ca9b91f79826a) --- source3/nsswitch/wins.c | 94 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 12 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index abc7b6f414..0ab0954812 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -23,12 +23,20 @@ #define NO_SYSLOG #include "includes.h" -#include +#ifdef HAVE_NS_API_H +#undef VOLATILE + +#include +#define NSD_LOGLEVEL NSD_LOG_MIN +#endif #ifndef INADDRSZ #define INADDRSZ 4 #endif +static int initialised; + + /* Use our own create socket code so we don't recurse.... */ static int wins_lookup_open_socket_in(void) @@ -62,20 +70,26 @@ static int wins_lookup_open_socket_in(void) return res; } -struct in_addr *lookup_backend(const char *name, int *count) + +static void nss_wins_init(void) +{ + initialised = 1; + DEBUGLEVEL = 0; + + setup_logging("nss_wins",False); + lp_load(dyn_CONFIGFILE,True,False,False); + load_interfaces(); +} + +static struct in_addr *lookup_backend(const char *name, int *count) { int fd; - static int initialised; - struct in_addr *ret; + struct in_addr *ret = NULL; struct in_addr p; int j; if (!initialised) { - initialised = 1; - DEBUGLEVEL = 0; - setup_logging("nss_wins",True); - lp_load(dyn_CONFIGFILE,True,False,False); - load_interfaces(); + nss_wins_init(); } *count = 0; @@ -125,7 +139,60 @@ struct in_addr *lookup_backend(const char *name, int *count) gethostbyname() - we ignore any domain portion of the name and only handle names that are at most 15 characters long **************************************************************************/ -enum nss_status +#ifdef HAVE_NS_API_H +/* IRIX version */ + +int init(void) +{ + nsd_logprintf(NSD_LOGLEVEL, "init (wins)\n"); + nss_wins_init(); + return NSD_OK; +} + +int lookup(nsd_file_t *rq) +{ + char *map; + char *key; + struct in_addr *ip_list; + int count; + char response[80]; + + nsd_logprintf(NSD_LOGLEVEL, "lookup (wins)\n"); + if (! rq) + return NSD_ERROR; + + map = nsd_attr_fetch_string(rq->f_attrs, "table", (char*)0); + if (! map) { + rq->f_status = NS_FATAL; + return NSD_ERROR; + } + + if (strcasecmp(map,"hosts.byname") != 0) { + rq->f_status = NS_NOTFOUND; + return NSD_NEXT; + } + + key = nsd_attr_fetch_string(rq->f_attrs, "key", (char*)0); + if (! key || ! *key) { + rq->f_status = NS_FATAL; + return NSD_ERROR; + } + + ip_list = lookup_backend(key, &count); + + if (!ip_list) { + rq->f_status = NSS_STATUS_NOTFOUND; + return NSD_NEXT; + } + snprintf(response,79,"%s %s\n",inet_ntoa(*ip_list),key); + free(ip_list); + + nsd_set_result(rq,NS_SUCCESS,response,strlen(response),VOLATILE); + return NSD_OK; +} + +#else +NSS_STATUS _nss_wins_gethostbyname_r(const char *name, struct hostent *he, char *buffer, size_t buflen, int *errnop, int *h_errnop) @@ -134,7 +201,7 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, struct in_addr *ip_list; int i, count; size_t namelen = strlen(name) + 1; - + memset(he, '\0', sizeof(*he)); ip_list = lookup_backend(name, &count); @@ -164,10 +231,13 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, host_addresses++; } - SAFE_FREE(ip_list); + if (ip_list) + free(ip_list); memcpy(buffer, name, namelen); he->h_name = buffer; return NSS_STATUS_SUCCESS; } +#endif + -- cgit From e674581416b3b473b919f890518939bd5f6ba574 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Sat, 22 Dec 2001 00:51:32 +0000 Subject: merge IRIX winbind support from Samba 2.2 branch (This used to be commit 20c5f042e3bb79ff96a993c70b843908dcfafb65) --- source3/nsswitch/wins.c | 151 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 116 insertions(+), 35 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 0ab0954812..8f34222bbf 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -27,7 +27,6 @@ #undef VOLATILE #include -#define NSD_LOGLEVEL NSD_LOG_MIN #endif #ifndef INADDRSZ @@ -36,6 +35,7 @@ static int initialised; +extern BOOL AllowDebugChange; /* Use our own create socket code so we don't recurse.... */ @@ -64,8 +64,12 @@ static int wins_lookup_open_socket_in(void) /* now we've got a socket - we need to bind it */ - if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) + if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) { + close(res); return(-1); + } + + set_socket_options(res,"SO_BROADCAST"); return res; } @@ -75,13 +79,42 @@ static void nss_wins_init(void) { initialised = 1; DEBUGLEVEL = 0; + AllowDebugChange = False; + + /* needed for lp_xx() functions */ + charset_initialise(); + TimeInit(); setup_logging("nss_wins",False); lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); + codepage_initialise(lp_client_code_page()); +} + +static struct node_status *lookup_byaddr_backend(char *addr, int *count) +{ + int fd; + struct in_addr ip; + struct nmb_name nname; + struct node_status *status; + + if (!initialised) { + nss_wins_init(); + } + + fd = wins_lookup_open_socket_in(); + if (fd == -1) + return NULL; + + make_nmb_name(&nname, "*", 0); + ip = *interpret_addr2(addr); + status = node_status_query(fd,&nname,ip, count); + + close(fd); + return status; } -static struct in_addr *lookup_backend(const char *name, int *count) +static struct in_addr *lookup_byname_backend(const char *name, int *count) { int fd; struct in_addr *ret = NULL; @@ -98,15 +131,6 @@ static struct in_addr *lookup_backend(const char *name, int *count) if (fd == -1) return NULL; - set_socket_options(fd,"SO_BROADCAST"); - -/* The next four lines commented out by JHT - and replaced with the four lines following */ -/* if( !is_zero_ip( wins_ip ) ) { - * ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count ); - * goto out; - * } - */ p = wins_srv_ip(); if( !is_zero_ip(p) ) { ret = name_query(fd,name,0x20,False,True, p, count); @@ -135,16 +159,12 @@ static struct in_addr *lookup_backend(const char *name, int *count) } -/**************************************************************************** -gethostbyname() - we ignore any domain portion of the name and only -handle names that are at most 15 characters long - **************************************************************************/ #ifdef HAVE_NS_API_H /* IRIX version */ int init(void) { - nsd_logprintf(NSD_LOGLEVEL, "init (wins)\n"); + nsd_logprintf(NSD_LOG_MIN, "entering init (wins)\n"); nss_wins_init(); return NSD_OK; } @@ -153,11 +173,14 @@ int lookup(nsd_file_t *rq) { char *map; char *key; + char *addr; struct in_addr *ip_list; - int count; - char response[80]; + struct node_status *status; + int i, count, len, size; + char response[1024]; + BOOL found = False; - nsd_logprintf(NSD_LOGLEVEL, "lookup (wins)\n"); + nsd_logprintf(NSD_LOG_MIN, "entering lookup (wins)\n"); if (! rq) return NSD_ERROR; @@ -167,31 +190,89 @@ int lookup(nsd_file_t *rq) return NSD_ERROR; } - if (strcasecmp(map,"hosts.byname") != 0) { - rq->f_status = NS_NOTFOUND; - return NSD_NEXT; - } - key = nsd_attr_fetch_string(rq->f_attrs, "key", (char*)0); if (! key || ! *key) { rq->f_status = NS_FATAL; return NSD_ERROR; } - ip_list = lookup_backend(key, &count); - - if (!ip_list) { - rq->f_status = NSS_STATUS_NOTFOUND; - return NSD_NEXT; + response[0] = '\0'; + len = sizeof(response) - 2; + + /* + * response needs to be a string of the following format + * ip_address[ ip_address]*\tname[ alias]* + */ + if (strcasecmp(map,"hosts.byaddr") == 0) { + if ( status = lookup_byaddr_backend(key, &count)) { + size = strlen(key) + 1; + if (size > len) { + free(status); + return NSD_ERROR; + } + len -= size; + strncat(response,key,size); + strncat(response,"\t",1); + for (i = 0; i < count; i++) { + /* ignore group names */ + if (status[i].flags & 0x80) continue; + if (status[i].type == 0x20) { + size = sizeof(status[i].name) + 1; + if (size > len) { + free(status); + return NSD_ERROR; + } + len -= size; + strncat(response, status[i].name, size); + strncat(response, " ", 1); + found = True; + } + } + response[strlen(response)-1] = '\n'; + free(status); + } + } else if (strcasecmp(map,"hosts.byname") == 0) { + if (ip_list = lookup_byname_backend(key, &count)) { + for (i = count; i ; i--) { + addr = inet_ntoa(ip_list[i-1]); + size = strlen(addr) + 1; + if (size > len) { + free(ip_list); + return NSD_ERROR; + } + len -= size; + if (i != 0) + response[strlen(response)-1] = ' '; + strncat(response,addr,size); + strncat(response,"\t",1); + } + size = strlen(key) + 1; + if (size > len) { + free(ip_list); + return NSD_ERROR; + } + strncat(response,key,size); + strncat(response,"\n",1); + found = True; + free(ip_list); + } } - snprintf(response,79,"%s %s\n",inet_ntoa(*ip_list),key); - free(ip_list); - nsd_set_result(rq,NS_SUCCESS,response,strlen(response),VOLATILE); - return NSD_OK; + if (found) { + nsd_logprintf(NSD_LOG_LOW, "lookup (wins %s) %s\n",map,response); + nsd_set_result(rq,NS_SUCCESS,response,strlen(response),VOLATILE); + return NSD_OK; + } + nsd_logprintf(NSD_LOG_LOW, "lookup (wins) not found\n"); + rq->f_status = NS_NOTFOUND; + return NSD_NEXT; } #else +/**************************************************************************** +gethostbyname() - we ignore any domain portion of the name and only +handle names that are at most 15 characters long + **************************************************************************/ NSS_STATUS _nss_wins_gethostbyname_r(const char *name, struct hostent *he, char *buffer, size_t buflen, int *errnop, @@ -204,7 +285,7 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, memset(he, '\0', sizeof(*he)); - ip_list = lookup_backend(name, &count); + ip_list = lookup_byname_backend(name, &count); if (!ip_list) { return NSS_STATUS_NOTFOUND; } -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/nsswitch/wins.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 8f34222bbf..2133f817d1 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 2.0 + Unix SMB/CIFS implementation. a WINS nsswitch module Copyright (C) Andrew Tridgell 1999 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/nsswitch/wins.c | 51 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 2133f817d1..9bb2d6755c 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -80,14 +80,10 @@ static void nss_wins_init(void) DEBUGLEVEL = 0; AllowDebugChange = False; - /* needed for lp_xx() functions */ - charset_initialise(); - TimeInit(); setup_logging("nss_wins",False); lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); - codepage_initialise(lp_client_code_page()); } static struct node_status *lookup_byaddr_backend(char *addr, int *count) @@ -115,10 +111,10 @@ static struct node_status *lookup_byaddr_backend(char *addr, int *count) static struct in_addr *lookup_byname_backend(const char *name, int *count) { - int fd; + int fd = -1; struct in_addr *ret = NULL; struct in_addr p; - int j; + int j, flags = 0; if (!initialised) { nss_wins_init(); @@ -126,33 +122,24 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) *count = 0; - fd = wins_lookup_open_socket_in(); - if (fd == -1) - return NULL; - - p = wins_srv_ip(); - if( !is_zero_ip(p) ) { - ret = name_query(fd,name,0x20,False,True, p, count); - goto out; + /* always try with wins first */ + if (resolve_wins(name,0x20,&ret,count)) { + return ret; } - if (lp_wins_support()) { - /* we are our own WINS server */ - ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count); - goto out; + fd = wins_lookup_open_socket_in(); + if (fd == -1) { + return NULL; } /* uggh, we have to broadcast to each interface in turn */ - for (j=iface_count() - 1; - j >= 0; - j--) { + for (j=iface_count() - 1;j >= 0;j--) { struct in_addr *bcast = iface_n_bcast(j); - ret = name_query(fd,name,0x20,True,True,*bcast,count); + ret = name_query(fd,name,0x20,True,True,*bcast,count, &flags, NULL); if (ret) break; } - out: - +out: close(fd); return ret; } @@ -319,5 +306,19 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, return NSS_STATUS_SUCCESS; } -#endif + +NSS_STATUS +_nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he, + char *buffer, size_t buflen, int *errnop, + int *h_errnop) +{ + if(af!=AF_INET) { + *h_errnop = NO_DATA; + *errnop = EAFNOSUPPORT; + return NSS_STATUS_UNAVAIL; + } + + return _nss_wins_gethostbyname_r(name,he,buffer,buflen,errnop,h_errnop); +} +#endif -- cgit From 145b01a496fcc35cc86cacb1ac79ed754257a7c3 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 16 Jun 2003 02:16:58 +0000 Subject: Fix some compiler warnings. (This used to be commit eec1758e048f38e2ac48a7dda96b90a74ec95449) --- source3/nsswitch/wins.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 9bb2d6755c..61edb1323b 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -113,7 +113,6 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) { int fd = -1; struct in_addr *ret = NULL; - struct in_addr p; int j, flags = 0; if (!initialised) { @@ -139,7 +138,6 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) if (ret) break; } -out: close(fd); return ret; } -- cgit From f51d769dd303027a3dbf46fc89a482933988e866 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Jun 2003 17:41:05 +0000 Subject: large change: *) consolidates the dc location routines again (dns and netbios) get_dc_list() or get_sorted_dc_list() is the authoritative means of locating DC's again. (also inludes a flag to get_dc_list() to define if this should be a DNS only lookup or not) (however, if you set "name resolve order = hosts wins" you could still get DNS queries for domain name IFF ldap_domain2hostlist() fails. The answer? Fix your DNS setup) *) enabled DOMAIN<0x1c> lookups to be funneled through resolve_hosts resulting in a call to ldap_domain2hostlist() if lp_security() == SEC_ADS *) enables name cache for winbind ADS backend *) enable the negative connection cache for winbind ADS backend *) removes some old dead code *) consolidates some duplicate code *) moves the internal_name_resolve() to use an IP/port pair to deal with SRV RR dns replies. The namecache code also supports the IP:port syntax now as well. *) removes 'ads server' and moves the functionality back into 'password server' (which can support "hostname:port" syntax now but works fine with defaults depending on the value of lp_security()) (This used to be commit d7f7fcda425bef380441509734eca33da943c091) --- source3/nsswitch/wins.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 61edb1323b..62493ef0a9 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -112,7 +112,8 @@ static struct node_status *lookup_byaddr_backend(char *addr, int *count) static struct in_addr *lookup_byname_backend(const char *name, int *count) { int fd = -1; - struct in_addr *ret = NULL; + struct ip_service *address = NULL; + struct in_addr *ret; int j, flags = 0; if (!initialised) { @@ -122,7 +123,13 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) *count = 0; /* always try with wins first */ - if (resolve_wins(name,0x20,&ret,count)) { + if (resolve_wins(name,0x20,&address,count)) { + if ( (ret = (struct in_addr *)malloc(sizeof(struct in_addr))) == NULL ) { + free( address ); + return NULL; + } + *ret = address[0].ip; + free( address ); return ret; } -- cgit From 80b46fd6cf5b480ec5656158152b1ab33630c356 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 23 Jul 2003 06:37:51 +0000 Subject: Move a function to avoid a warning. (This used to be commit a3b4c57503e0966145b0adab247297e4c8e0f165) --- source3/nsswitch/wins.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 62493ef0a9..87dac60192 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -86,29 +86,6 @@ static void nss_wins_init(void) load_interfaces(); } -static struct node_status *lookup_byaddr_backend(char *addr, int *count) -{ - int fd; - struct in_addr ip; - struct nmb_name nname; - struct node_status *status; - - if (!initialised) { - nss_wins_init(); - } - - fd = wins_lookup_open_socket_in(); - if (fd == -1) - return NULL; - - make_nmb_name(&nname, "*", 0); - ip = *interpret_addr2(addr); - status = node_status_query(fd,&nname,ip, count); - - close(fd); - return status; -} - static struct in_addr *lookup_byname_backend(const char *name, int *count) { int fd = -1; @@ -149,8 +126,31 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) return ret; } - #ifdef HAVE_NS_API_H + +static struct node_status *lookup_byaddr_backend(char *addr, int *count) +{ + int fd; + struct in_addr ip; + struct nmb_name nname; + struct node_status *status; + + if (!initialised) { + nss_wins_init(); + } + + fd = wins_lookup_open_socket_in(); + if (fd == -1) + return NULL; + + make_nmb_name(&nname, "*", 0); + ip = *interpret_addr2(addr); + status = node_status_query(fd,&nname,ip, count); + + close(fd); + return status; +} + /* IRIX version */ int init(void) -- cgit From f87bd754231387825924454836de23b9777dcaa0 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 8 Sep 2003 05:51:57 +0000 Subject: Fix for bug #299. There was some confusion over dynamically allocated lists of pointers (i.e you have to make space for the list of pointers and what they are pointing too) in the memory buffer passed in from libc. Valgrind is much happer now and as a bonus there is no segfault. (This used to be commit 7907c44414acb841a9001e82285790eece73d032) --- source3/nsswitch/wins.c | 110 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 30 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 87dac60192..0fc4e46cdb 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -260,54 +260,105 @@ int lookup(nsd_file_t *rq) } #else + +/* Allocate some space from the nss static buffer. The buffer and buflen + are the pointers passed in by the C library to the _nss_*_* + functions. */ + +static char *get_static(char **buffer, int *buflen, int len) +{ + char *result; + + /* Error check. We return false if things aren't set up right, or + there isn't enough buffer space left. */ + + if ((buffer == NULL) || (buflen == NULL) || (*buflen < len)) { + return NULL; + } + + /* Return an index into the static buffer */ + + result = *buffer; + *buffer += len; + *buflen -= len; + + return result; +} + /**************************************************************************** gethostbyname() - we ignore any domain portion of the name and only handle names that are at most 15 characters long **************************************************************************/ NSS_STATUS -_nss_wins_gethostbyname_r(const char *name, struct hostent *he, - char *buffer, size_t buflen, int *errnop, - int *h_errnop) +_nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, + char *buffer, size_t buflen, int *h_errnop) { - char **host_addresses; struct in_addr *ip_list; int i, count; - size_t namelen = strlen(name) + 1; + fstring name; + size_t namelen; memset(he, '\0', sizeof(*he)); + fstrcpy(name, hostname); + + /* Do lookup */ ip_list = lookup_byname_backend(name, &count); - if (!ip_list) { - return NSS_STATUS_NOTFOUND; - } - if (buflen < namelen + (2*count+1)*INADDRSZ) { - /* no ENOMEM error type?! */ + if (!ip_list) return NSS_STATUS_NOTFOUND; - } + /* Copy h_name */ - host_addresses = (char **)buffer; - he->h_addr_list = host_addresses; - host_addresses[count] = NULL; - buffer += (count + 1) * INADDRSZ; - buflen += (count + 1) * INADDRSZ; - he->h_addrtype = AF_INET; - he->h_length = INADDRSZ; + namelen = strlen(name) + 1; + + if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) + return NSS_STATUS_TRYAGAIN; + + memcpy(he->h_name, name, namelen); + + /* Copy h_addr_list, align to pointer boundary first */ - for (i=0;ih_addr_list = (char **)get_static( + &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) + return NSS_STATUS_TRYAGAIN; + + for (i = 0; i < count; i++) { + if ((he->h_addr_list[i] = get_static(&buffer, &buflen, + INADDRSZ)) == NULL) + return NSS_STATUS_TRYAGAIN; + memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ); } + he->h_addr_list[count] = NULL; + if (ip_list) free(ip_list); - memcpy(buffer, name, namelen); - he->h_name = buffer; + /* Set h_addr_type and h_length */ + + he->h_addrtype = AF_INET; + he->h_length = INADDRSZ; + + /* Set h_aliases */ + + if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0) + i = sizeof(char*) - i; + + if (get_static(&buffer, &buflen, i) == NULL) + return NSS_STATUS_TRYAGAIN; + + if ((he->h_aliases = (char **)get_static( + &buffer, &buflen, sizeof(char *))) == NULL) + return NSS_STATUS_TRYAGAIN; + + he->h_aliases[0] = NULL; return NSS_STATUS_SUCCESS; } @@ -315,15 +366,14 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he, NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he, - char *buffer, size_t buflen, int *errnop, - int *h_errnop) + char *buffer, size_t buflen, int *h_errnop) { if(af!=AF_INET) { *h_errnop = NO_DATA; - *errnop = EAFNOSUPPORT; return NSS_STATUS_UNAVAIL; } - return _nss_wins_gethostbyname_r(name,he,buffer,buflen,errnop,h_errnop); + return _nss_wins_gethostbyname_r( + name, he, buffer, buflen, h_errnop); } #endif -- cgit From 2719275ebfdfc0dfc460c9d29c51e8968039602e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 11 Dec 2003 15:35:11 +0000 Subject: fixed bad formal parameter type in get_static(); patch Andy Polyakov (This used to be commit 9c70e4b44e0dda8f2af4172b928437bd9d3e8b7c) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 0fc4e46cdb..779d1b2c6c 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -265,7 +265,7 @@ int lookup(nsd_file_t *rq) are the pointers passed in by the C library to the _nss_*_* functions. */ -static char *get_static(char **buffer, int *buflen, int len) +static char *get_static(char **buffer, size_t *buflen, int len) { char *result; -- cgit From 75117a357af0480ef07b703a975d3f12ff4a0887 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Jan 2004 22:53:37 +0000 Subject: Use StrCaseCmp, not strcasecmp. Should fix winbind build on IRIX (This used to be commit 65b01f67d5725bc54e6bc19b6e84beef38e372f8) --- source3/nsswitch/wins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 779d1b2c6c..100a103924 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -194,7 +194,7 @@ int lookup(nsd_file_t *rq) * response needs to be a string of the following format * ip_address[ ip_address]*\tname[ alias]* */ - if (strcasecmp(map,"hosts.byaddr") == 0) { + if (StrCaseCmp(map,"hosts.byaddr") == 0) { if ( status = lookup_byaddr_backend(key, &count)) { size = strlen(key) + 1; if (size > len) { @@ -222,7 +222,7 @@ int lookup(nsd_file_t *rq) response[strlen(response)-1] = '\n'; free(status); } - } else if (strcasecmp(map,"hosts.byname") == 0) { + } else if (StrCaseCmp(map,"hosts.byname") == 0) { if (ip_list = lookup_byname_backend(key, &count)) { for (i = count; i ; i--) { addr = inet_ntoa(ip_list[i-1]); -- cgit From 0374be5d931903f1040fd4e759e6b1d681be2047 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 16 Apr 2004 03:57:30 +0000 Subject: r248: Add support for printing out the MAC address on nmblookup. (This used to be commit bf9f02be5fc1d09c8c08c78c3f2df23b2099ba4f) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 100a103924..88c65b767f 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -145,7 +145,7 @@ static struct node_status *lookup_byaddr_backend(char *addr, int *count) make_nmb_name(&nname, "*", 0); ip = *interpret_addr2(addr); - status = node_status_query(fd,&nname,ip, count); + status = node_status_query(fd,&nname,ip, count, NULL); close(fd); return status; -- cgit From 43fb4632c6903abbcbcad371fec45c7f40c83e0e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 27 Apr 2004 13:12:31 +0000 Subject: r376: BUG 1288: resolve any machine netbios name (0x00) and not just servers (0x20) (This used to be commit d96929b5b1d8d149ac023a30964925952587c258) --- source3/nsswitch/wins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 88c65b767f..b71995998f 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -100,7 +100,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) *count = 0; /* always try with wins first */ - if (resolve_wins(name,0x20,&address,count)) { + if (resolve_wins(name,0x00,&address,count)) { if ( (ret = (struct in_addr *)malloc(sizeof(struct in_addr))) == NULL ) { free( address ); return NULL; @@ -118,7 +118,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) /* uggh, we have to broadcast to each interface in turn */ for (j=iface_count() - 1;j >= 0;j--) { struct in_addr *bcast = iface_n_bcast(j); - ret = name_query(fd,name,0x20,True,True,*bcast,count, &flags, NULL); + ret = name_query(fd,name,0x00,True,True,*bcast,count, &flags, NULL); if (ret) break; } -- cgit From 2e6f3398d61237e04452530a1415f3e0bd8df3b5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 25 Jul 2004 13:14:00 +0000 Subject: r1583: Patch by Fabien Chevalier We may not have any interfaces up at all, so initialise the return variable. Fixes Debian bug #252591 Andrew Bartlett (This used to be commit 35aabae9d9bf66ef2c8eb4e07a850c606d8236d2) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index b71995998f..a1c4f4deec 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -90,7 +90,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) { int fd = -1; struct ip_service *address = NULL; - struct in_addr *ret; + struct in_addr *ret = NULL; int j, flags = 0; if (!initialised) { -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index a1c4f4deec..8d26fc5297 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -101,7 +101,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) /* always try with wins first */ if (resolve_wins(name,0x00,&address,count)) { - if ( (ret = (struct in_addr *)malloc(sizeof(struct in_addr))) == NULL ) { + if ( (ret = SMB_MALLOC_P(struct in_addr)) == NULL ) { free( address ); return NULL; } -- cgit From 19ca97a70f6b7b41d251eaa76e4d3c980c6eedff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Jun 2005 20:25:18 +0000 Subject: r7882: Looks like a large patch - but what it actually does is make Samba safe for using our headers and linking with C++ modules. Stops us from using C++ reserved keywords in our code. Jeremy (This used to be commit 9506b8e145982b1160a2f0aee5c9b7a54980940a) --- source3/nsswitch/wins.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 8d26fc5297..6d4f6cfa26 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -128,12 +128,12 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) #ifdef HAVE_NS_API_H -static struct node_status *lookup_byaddr_backend(char *addr, int *count) +static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count) { int fd; struct in_addr ip; struct nmb_name nname; - struct node_status *status; + NODE_STATUS_STRUCT *status; if (!initialised) { nss_wins_init(); @@ -166,7 +166,7 @@ int lookup(nsd_file_t *rq) char *key; char *addr; struct in_addr *ip_list; - struct node_status *status; + NODE_STATUS_STRUCT *status; int i, count, len, size; char response[1024]; BOOL found = False; -- cgit From ab398643a4e44211696ef5ce72b62ab7ecee7bc9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 19 Jul 2005 02:37:04 +0000 Subject: r8572: Remove crufty #define NO_SYSLOG as it's not used at all anymore. (This used to be commit 985dbb47d925e79c1195ca219f7ab5d6648b22b8) --- source3/nsswitch/wins.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 6d4f6cfa26..ac5b0f1157 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -19,8 +19,6 @@ */ -#define NO_SYSLOG - #include "includes.h" #ifdef HAVE_NS_API_H #undef VOLATILE -- cgit From 9c15bd311db76885b27f30ba92d885833f668550 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 28 Jan 2006 22:53:04 +0000 Subject: r13212: r12414@cabra: derrell | 2006-01-28 17:52:17 -0500 lp_load() could not be called multiple times to modify parameter settings based on reading from multiple configuration settings. Each time, it initialized all of the settings back to their defaults before reading the specified configuration file. This patch adds a parameter to lp_load() specifying whether the settings should be initialized. It does, however, still force the settings to be initialized the first time, even if the request was to not initialize them. (Not doing so could wreak havoc due to uninitialized values.) (This used to be commit f2a24de769d1b2266e576597c57a8e3b1e2a2b51) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index ac5b0f1157..f871a53982 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -80,7 +80,7 @@ static void nss_wins_init(void) TimeInit(); setup_logging("nss_wins",False); - lp_load(dyn_CONFIGFILE,True,False,False); + lp_load(dyn_CONFIGFILE,True,False,False,True); load_interfaces(); } -- cgit From 94ad8543bd27c6cbdcdaf4acf84d91438dbef28b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 17 Jul 2006 22:19:54 +0000 Subject: r17102: Fix segfault in libnss_wins [bugzilla #3937]. Guenther (This used to be commit d73d0ec3d074f1acc4fe1c78d218aabd0fe4118a) --- source3/nsswitch/wins.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index f871a53982..2cc7edb4c7 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -80,6 +80,7 @@ static void nss_wins_init(void) TimeInit(); setup_logging("nss_wins",False); + load_case_tables(); lp_load(dyn_CONFIGFILE,True,False,False,True); load_interfaces(); } -- cgit From e59e787b4868acffad49b6264e319d585643d5ab Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 20 Dec 2006 01:10:04 +0000 Subject: r20269: merge -r20264:20267 from SAMBA_3_0_24 more no previous prototype warnings (This used to be commit 41be182f78762372ae13759ede5d2bd40a71d7f5) --- source3/nsswitch/wins.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 2cc7edb4c7..697bc15f97 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -34,6 +34,11 @@ static int initialised; extern BOOL AllowDebugChange; +NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, + char *buffer, size_t buflen, int *h_errnop); +NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he, + char *buffer, size_t buflen, int *h_errnop); + /* Use our own create socket code so we don't recurse.... */ static int wins_lookup_open_socket_in(void) -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 697bc15f97..9c46b368c2 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/nsswitch/wins.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 9c46b368c2..d54134d01f 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From 1c72c4c360b6443f5b9705f2781fa9917492537e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 28 Aug 2007 14:20:53 +0000 Subject: r24737: Remove older TODO: Convert internal_resolve_name() and friends to NTSTATUS. Guenther (This used to be commit 8300aac4944613e411a78ab98de5d77f8fd38fa7) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index d54134d01f..afc1639f63 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -103,7 +103,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) *count = 0; /* always try with wins first */ - if (resolve_wins(name,0x00,&address,count)) { + if (NT_STATUS_IS_OK(resolve_wins(name,0x00,&address,count))) { if ( (ret = SMB_MALLOC_P(struct in_addr)) == NULL ) { free( address ); return NULL; -- cgit From 2400758fbef9f3a5a8b7138053ca75586af80dce Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 8 Sep 2007 05:18:08 +0000 Subject: r25022: Fix coverity #395. Resource leak on error. Jeremy. (This used to be commit 6a237600b825f4df2241277bdd80e98669f69685) --- source3/nsswitch/wins.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index afc1639f63..8e4d75e545 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -315,8 +315,10 @@ _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, namelen = strlen(name) + 1; - if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) + if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) { + free(ip_list); return NSS_STATUS_TRYAGAIN; + } memcpy(he->h_name, name, namelen); @@ -325,24 +327,29 @@ _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, if ((i = (unsigned long)(buffer) % sizeof(char*)) != 0) i = sizeof(char*) - i; - if (get_static(&buffer, &buflen, i) == NULL) + if (get_static(&buffer, &buflen, i) == NULL) { + free(ip_list); return NSS_STATUS_TRYAGAIN; + } if ((he->h_addr_list = (char **)get_static( - &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) + &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) { + free(ip_list); return NSS_STATUS_TRYAGAIN; + } for (i = 0; i < count; i++) { if ((he->h_addr_list[i] = get_static(&buffer, &buflen, - INADDRSZ)) == NULL) + INADDRSZ)) == NULL) { + free(ip_list); return NSS_STATUS_TRYAGAIN; + } memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ); } he->h_addr_list[count] = NULL; - if (ip_list) - free(ip_list); + free(ip_list); /* Set h_addr_type and h_length */ -- cgit From 8e54530b52fd256137740107e9fdf000f00a7a30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 10 Oct 2007 18:25:16 -0700 Subject: Add start of IPv6 implementation. Currently most of this is avoiding IPv6 in winbindd, but moves most of the socket functions that were wrongly in lib/util.c into lib/util_sock.c and provides generic IPv4/6 independent versions of most things. Still lots of work to do, but now I can see how I'll fix the access check code. Nasty part that remains is the name resolution code which is used to returning arrays of in_addr structs. Jeremy. (This used to be commit 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08) --- source3/nsswitch/wins.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 8e4d75e545..9502a5d17e 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -120,7 +120,10 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) /* uggh, we have to broadcast to each interface in turn */ for (j=iface_count() - 1;j >= 0;j--) { - struct in_addr *bcast = iface_n_bcast(j); + const struct in_addr *bcast = iface_n_bcast_v4(j); + if (!bcast) { + continue; + } ret = name_query(fd,name,0x00,True,True,*bcast,count, &flags, NULL); if (ret) break; } -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/nsswitch/wins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 9502a5d17e..38bf3259f4 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -31,7 +31,7 @@ static int initialised; -extern BOOL AllowDebugChange; +extern bool AllowDebugChange; NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he, char *buffer, size_t buflen, int *h_errnop); @@ -175,7 +175,7 @@ int lookup(nsd_file_t *rq) NODE_STATUS_STRUCT *status; int i, count, len, size; char response[1024]; - BOOL found = False; + bool found = False; nsd_logprintf(NSD_LOG_MIN, "entering lookup (wins)\n"); if (! rq) -- cgit From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/nsswitch/wins.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 38bf3259f4..3401918f59 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -108,7 +108,11 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) free( address ); return NULL; } - *ret = address[0].ip; + if (address[0].ss.ss_family != AF_INET) { + free(address); + return NULL; + } + *ret = ((struct sockaddr_in *)&address[0].ss)->sin_addr; free( address ); return ret; } @@ -121,11 +125,17 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) /* uggh, we have to broadcast to each interface in turn */ for (j=iface_count() - 1;j >= 0;j--) { const struct in_addr *bcast = iface_n_bcast_v4(j); + struct sockaddr_storage ss; + struct sockaddr_storage *pss; if (!bcast) { continue; } - ret = name_query(fd,name,0x00,True,True,*bcast,count, &flags, NULL); - if (ret) break; + in_addr_to_sockaddr_storage(&ss, *bcast); + pss = name_query(fd,name,0x00,True,True,&ss,count, &flags, NULL); + if (pss) { + *ret = ((struct sockaddr_in *)pss)->sin_addr; + break; + } } close(fd); -- cgit From 51a0354d751f48a2542984c81e218da33669bbeb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 22:34:46 -0700 Subject: Remove more static data from lib/util_sock.c and callers. Jeremy. (This used to be commit 35aaa36f82c70964cee5d0778eb04547b226dd3f) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 3401918f59..9d6273ce7b 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -160,7 +160,7 @@ static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count) return NULL; make_nmb_name(&nname, "*", 0); - ip = *interpret_addr2(addr); + (void)interpret_addr2(&ip,addr); status = node_status_query(fd,&nname,ip, count, NULL); close(fd); -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/nsswitch/wins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 9d6273ce7b..c822fc78b9 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -85,7 +85,7 @@ static void nss_wins_init(void) TimeInit(); setup_logging("nss_wins",False); load_case_tables(); - lp_load(dyn_CONFIGFILE,True,False,False,True); + lp_load(get_dyn_CONFIGFILE(),True,False,False,True); load_interfaces(); } -- cgit From 71ab53a13be17c50ed7e640290407f0dca11db3c Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 27 Feb 2008 10:06:53 +0100 Subject: Fix caller of node_status_query() to use sockaddr_storage(). Caller is hidden inside an #ifdef . Michael (This used to be commit 4a0d1ad601facf158db0c1d1c320e9e1369093d0) --- source3/nsswitch/wins.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index c822fc78b9..35649dfda2 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -147,7 +147,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count) { int fd; - struct in_addr ip; + struct sockaddr_storage ss; struct nmb_name nname; NODE_STATUS_STRUCT *status; @@ -160,8 +160,10 @@ static NODE_STATUS_STRUCT *lookup_byaddr_backend(char *addr, int *count) return NULL; make_nmb_name(&nname, "*", 0); - (void)interpret_addr2(&ip,addr); - status = node_status_query(fd,&nname,ip, count, NULL); + if (!interpret_string_addr(&ss, addr, AI_NUMERICHOST)) { + return NULL; + } + status = node_status_query(fd, &nname, &ss, count, NULL); close(fd); return status; -- cgit From 439fe513c168955194730904f6ec5c7ddb4f972c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 6 Mar 2008 11:37:01 +0100 Subject: Fix a memleak Fixes Coverity ID 557 (This used to be commit fe882a575152233de6f4bf2143aca681319b0226) --- source3/nsswitch/wins.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 35649dfda2..e74cfaf69f 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -110,6 +110,7 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) } if (address[0].ss.ss_family != AF_INET) { free(address); + free(ret); return NULL; } *ret = ((struct sockaddr_in *)&address[0].ss)->sin_addr; -- cgit From e06aa46b9fab1e107fea8f6453fb13deffa91e96 Mon Sep 17 00:00:00 2001 From: Marc VanHeyningen Date: Fri, 14 Mar 2008 14:26:28 -0800 Subject: Coverity fixes (This used to be commit 3fc85d22590550f0539215d020e4411bf5b14363) --- source3/nsswitch/wins.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index e74cfaf69f..36415c42b5 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -58,9 +58,15 @@ static int wins_lookup_open_socket_in(void) if (res == -1) return -1; - setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)); + if (setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) != 0) { + close(res); + return -1; + } #ifdef SO_REUSEPORT - setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)); + if (setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) != 0) { + close(res); + return -1; + } #endif /* SO_REUSEPORT */ /* now we've got a socket - we need to bind it */ -- cgit From 8ce3f6b840a259133e2b2cfdb97578e96c94b629 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 6 May 2008 17:02:31 +0200 Subject: wins: fix null pointer crash in nss_wins module. Guenther (This used to be commit 5bf47ebf0fb9f7d94ed36bce6bcaa31b508009bd) --- source3/nsswitch/wins.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nsswitch/wins.c') diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c index 36415c42b5..7d42381986 100644 --- a/source3/nsswitch/wins.c +++ b/source3/nsswitch/wins.c @@ -140,6 +140,9 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count) in_addr_to_sockaddr_storage(&ss, *bcast); pss = name_query(fd,name,0x00,True,True,&ss,count, &flags, NULL); if (pss) { + if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) { + return NULL; + } *ret = ((struct sockaddr_in *)pss)->sin_addr; break; } -- cgit