summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1999-12-17 06:11:25 +0000
committerAndrew Tridgell <tridge@samba.org>1999-12-17 06:11:25 +0000
commitce394449c7923b815946d53a1059b04847abed02 (patch)
treecc9e352fa73deb1c188623431925a5c1ff2768d5 /source3/nsswitch
parent418ba2933f90eecf9abed14a43e02f28358d8d37 (diff)
downloadsamba-ce394449c7923b815946d53a1059b04847abed02.tar.gz
samba-ce394449c7923b815946d53a1059b04847abed02.tar.bz2
samba-ce394449c7923b815946d53a1059b04847abed02.zip
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)
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/README13
-rw-r--r--source3/nsswitch/wins.c129
2 files changed, 142 insertions, 0 deletions
diff --git a/source3/nsswitch/README b/source3/nsswitch/README
new file mode 100644
index 0000000000..9f0c581df6
--- /dev/null
+++ b/source3/nsswitch/README
@@ -0,0 +1,13 @@
+This extension provides a "wins" module for NSS on glibc2/Linux. This
+allows you to use a WINS entry in /etc/nsswitch.conf for hostname
+resolution, allowing you to resolve netbios names via start unix
+gethostbyname() calls. The end result is that you can use netbios
+names as host names in unix apps.
+
+1) run configure
+2) run "make nsswitch"
+3) cp nsswitch/libnss_wins.so /lib/libnss_wins.so.2
+4) add a wins entry to the hosts line in /etc/nsswitch.conf
+5) use it
+
+tridge@linuxcare.com
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 <nss.h>
+
+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<count;i++) {
+ memcpy(buffer, &ip_list[i].s_addr, INADDRSZ);
+ *host_addresses = buffer;
+ buffer += INADDRSZ;
+ buflen -= INADDRSZ;
+ host_addresses++;
+ }
+
+ if (ip_list) free(ip_list);
+
+ return NSS_STATUS_SUCCESS;
+}