nss_wins: add module for FreeBSD
authorBjörn Jacke <bj@sernet.de>
Thu, 10 Sep 2015 09:27:42 +0000 (11:27 +0200)
committerBjoern Jacke <bj@sernet.de>
Thu, 10 Sep 2015 22:34:30 +0000 (00:34 +0200)
Thanks to Timur Bakeyev <timur@FreeBSD.org> for the patch.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11493

Signed-off-by: Bjoern Jacke <bj@sernet.de>
Reviewed-by: Ralph Böhme <rb@sernet.de>
nsswitch/wins_freebsd.c [new file with mode: 0644]
nsswitch/wscript_build

diff --git a/nsswitch/wins_freebsd.c b/nsswitch/wins_freebsd.c
new file mode 100644 (file)
index 0000000..c1845d2
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Copyright (C) Timur I. Bakeyev 2007
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with this library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA  02111-1307, USA.
+*/
+
+#include "winbind_client.h"
+
+extern enum nss_status _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he,
+                          char *buffer, size_t buflen, int *h_errnop);
+
+ns_mtab *nss_module_register(const char *source, unsigned int *, nss_module_unregister_fn *);
+
+NSS_METHOD_PROTOTYPE(__nss_wins_freebsd_gethostbyname2_r);
+
+static ns_mtab methods[] =
+{
+       { NSDB_HOSTS, "getaddrinfo",      NULL, NULL },
+       { NSDB_HOSTS, "ghbyname",         NULL, NULL },
+       { NSDB_HOSTS, "ghbyaddr",         NULL, NULL },
+       { NSDB_HOSTS, "gethostbyaddr_r",  NULL, NULL },
+       { NSDB_HOSTS, "gethostbyname2_r", __nss_wins_freebsd_gethostbyname2_r, _nss_wins_gethostbyname2_r },
+       { NSDB_HOSTS, "getnetbyname_r",   NULL, NULL },
+       { NSDB_HOSTS, "getnetbyaddr_r",   NULL, NULL },
+       { NSDB_HOSTS, "gethostbyname",    NULL, NULL },
+       { NSDB_HOSTS, "gethostbyaddr",    NULL, NULL },
+       { NSDB_HOSTS, "getnetbyname",     NULL, NULL },
+       { NSDB_HOSTS, "getnetbyaddr",     NULL, NULL }
+};
+
+int
+__nss_wins_freebsd_gethostbyname2_r(void *retval, void *mdata, va_list ap)
+{
+       int (*fn)(const char *, int, struct hostent *, char *, size_t, int *);
+       const char      *hostname;
+       int             af;
+       struct hostent  *he;
+       char            *buffer;
+       size_t          buflen;
+       int             *h_errnop;
+       enum nss_status status;
+
+       fn = mdata;
+       hostname = va_arg(ap, const char *);
+       af = va_arg(ap, int);
+       he = va_arg(ap, struct hostent *);
+       buffer = va_arg(ap, char *);
+       buflen = va_arg(ap, size_t);
+       h_errnop = va_arg(ap, int *);
+
+       status = fn(hostname, af, he, buffer, buflen, h_errnop);
+       status = __nss_compat_result(status, *h_errnop);
+       if (status == NS_SUCCESS)
+               *(struct hostent **)retval = he;
+
+       return (status);
+}
+
+ns_mtab *
+nss_module_register(const char *source __unused, unsigned int *mtabsize,
+    nss_module_unregister_fn *unreg)
+{
+       *mtabsize = sizeof(methods) / sizeof(methods[0]);
+       *unreg = NULL;
+       return (methods);
+}
index 381ff44a669d737a7fe5b841ea8ab2c6e7d6e44f..bf7d90826c0254995890b696e7ccbf6ebcb00932 100644 (file)
@@ -39,7 +39,6 @@ if (Utils.unversioned_sys_platform() == 'linux' or (host_os.rfind('gnu') > -1)):
               pc_files=[],
               vnum='2')
 
-    # for nss_wins is linux only
     bld.SAMBA3_LIBRARY('nss_wins',
                        keep_underscore=True,
                        source='wins.c',
@@ -57,6 +56,12 @@ elif (host_os.rfind('freebsd') > -1):
                          realname='nss_winbind.so.1',
                          vnum='1')
 
+       bld.SAMBA3_LIBRARY('nss_wins',
+                         source='wins.c wins_freebsd.c',
+                         deps='''param libsmb LIBTSOCKET''',
+                         realname='nss_wins.so.1',
+                         vnum='1')
+
 elif (host_os.rfind('netbsd') > -1):
        # NetBSD winbind client is implemented as a wrapper
        # around the Linux version. It needs getpwent_r() to