From 19d57ea96f903ce8592fb74edd241b1a54853a93 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Wed, 5 Jan 2011 19:39:08 +0000 Subject: add FreeBSD support, partially imported from the FreeBSD port (thanks to Jacques Vidrine, Artem Kazakov and Alexander V. Chernikov) git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1365 ef36b2f9-881f-0410-afb5-c4e39611909c --- AUTHORS | 3 + HACKING | 12 ++++ configure.ac | 6 +- debian/copyright | 5 +- nss/Makefile.am | 7 ++- nss/bsdnss.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++ nss/exports.freebsd | 16 ++++++ nss/prototypes.h | 12 ++++ 8 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 nss/bsdnss.c create mode 100644 nss/exports.freebsd diff --git a/AUTHORS b/AUTHORS index 46f281f..d56509b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -81,3 +81,6 @@ Jan Schampera Nalin Dahyabhai Daniel Dehennin Ted C. Cheng +Jacques Vidrine +Artem Kazakov +Alexander V. Chernikov diff --git a/HACKING b/HACKING index be9750c..d9d8e16 100644 --- a/HACKING +++ b/HACKING @@ -144,6 +144,18 @@ http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/nsswitch/ http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/head/nss_common.h http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/head/nss_dbdefs.h +FreeBSD C Libarary notes +------------------------ + +The FreeBSD C library seems to have support for exposing GNU C Library NSS +module functions through a wrapper function. This makes it very easy to +implement NSS support on FreeBSD. + +Pointers for more documentation on this is welcome. Some information is +available here: +http://nixdoc.net/man-pages/FreeBSD/man3/nsdispatch.3.html +ftp://ftp8.tw.freebsd.org/pub/branches/-current/src/include/nss.h + PAM MODULE ========== diff --git a/configure.ac b/configure.ac index aed2680..643a45d 100644 --- a/configure.ac +++ b/configure.ac @@ -412,7 +412,7 @@ then # check which NSS flavour to build AC_MSG_CHECKING([which NSS flavour to build]) AC_ARG_WITH(nss-flavour, - AS_HELP_STRING([--with-nss-flavour=auto|glibc|solaris], + AS_HELP_STRING([--with-nss-flavour=auto|glibc|solaris|freebsd], [the libc flavour to build our NSS module for @<:@auto@:>@]),, with_nss_flavour=auto) if test "x$with_nss_flavour" = "xauto" @@ -420,6 +420,7 @@ then # do the guessing game case "$target_os" in solaris*) with_nss_flavour=solaris ;; + freebsd*) with_nss_flavour=freebsd ;; *) with_nss_flavour=glibc ;; esac fi @@ -427,6 +428,7 @@ then case "$with_nss_flavour" in glibc) AC_DEFINE(NSS_FLAVOUR_GLIBC,1,[Whether to use the Glibc NSS interface flavour.]) ;; solaris) AC_DEFINE(NSS_FLAVOUR_SOLARIS,1,[Whether to use the Solaris NSS interface flavour.]) ;; + freebsd) AC_DEFINE(NSS_FLAVOUR_FREEBSD,1,[Whether to use the FreeBSD NSS interface flavour.]) ;; esac # check which module source files to use @@ -436,6 +438,7 @@ then case "$with_nss_flavour" in glibc) with_nss_maps="aliases,ethers,group,hosts,netgroup,networks,passwd,protocols,rpc,services,shadow" ;; solaris) with_nss_maps="ethers,group,hosts,netgroup,networks,passwd,protocols,rpc,services,shadow" ;; + freebsd) with_nss_maps="group,hosts,passwd" ;; esac fi AC_MSG_RESULT($with_nss_maps) @@ -729,6 +732,7 @@ fi AM_CONDITIONAL([NSS_FLAVOUR_GLIBC], [test "x${with_nss_flavour}" = xglibc]) AM_CONDITIONAL([NSS_FLAVOUR_SOLARIS], [test "x${with_nss_flavour}" = xsolaris]) +AM_CONDITIONAL([NSS_FLAVOUR_FREEBSD], [test "x${with_nss_flavour}" = xfreebsd]) # generate files AC_CONFIG_FILES([Makefile compat/Makefile common/Makefile nss/Makefile diff --git a/debian/copyright b/debian/copyright index 0744786..9e1dfe6 100644 --- a/debian/copyright +++ b/debian/copyright @@ -23,7 +23,7 @@ Davide Puricelli (evo), Sami Haahtinen and Stephen Frost. Copyright (C) 1997-2006 Luke Howard Copyright (C) 2006-2007 West Consulting - Copyright (C) 2006-2010 Arthur de Jong + Copyright (C) 2006-2011 Arthur de Jong Copyright (C) 2009 Howard Chu Copyright (C) 2010 Symas Corporation @@ -54,6 +54,9 @@ debian/po/es.po: Copyright (C) 2009, 2010 Software in the Public Interest debian/po/fi.po: Copyright (C) 2009 Esko Arajärvi debian/po/fr.po: Copyright (C) 2007, 2009, 2010 Debian French l10n team debian/po/vi.po: Copyright (C) 2010 Free Software Foundation, Inc. +nss/bsdnss.c: Copyright (C) 2003 Jacques Vidrine +nss/bsdnss.c: Copyright (C) 2006 Artem Kazakov +nss/bsdnss.c: Copyright (C) 2009 Alexander V. Chernikov The distribution includes code from the Autoconf and Automake suites. This code is either licensed under the GNU General Public License with the extra diff --git a/nss/Makefile.am b/nss/Makefile.am index f1b7ff0..77fc091 100644 --- a/nss/Makefile.am +++ b/nss/Makefile.am @@ -30,15 +30,18 @@ nss_ldap_so_SOURCES = common.c common.h prototypes.h \ ../compat/attrs.h EXTRA_nss_ldap_so_SOURCES = aliases.c ethers.c group.c hosts.c netgroup.c \ networks.c passwd.c protocols.c rpc.c services.c \ - shadow.c solnss.c + shadow.c solnss.c bsdnss.c nss_ldap_so_LDADD = $(NSS_MODULE_OBJS) if NSS_FLAVOUR_SOLARIS nss_ldap_so_LDADD += solnss.$(OBJEXT) ../common/libdict.a endif +if NSS_FLAVOUR_FREEBSD +nss_ldap_so_LDADD += bsdnss.$(OBJEXT) +endif nss_ldap_so_LDADD += ../common/libtio.a ../common/libprot.a nss_ldap_so_DEPENDENCIES = $(nss_ldap_so_LDADD) -EXTRA_DIST = exports.glibc exports.solaris +EXTRA_DIST = exports.glibc exports.solaris exports.freebsd install-exec-local: install-nss_ldap_so uninstall-local: uninstall-nss_ldap_so diff --git a/nss/bsdnss.c b/nss/bsdnss.c new file mode 100644 index 0000000..da862a5 --- /dev/null +++ b/nss/bsdnss.c @@ -0,0 +1,155 @@ +/* + bsdnss.c - BSD NSS functions + This file was part of the nss-pam-ldapd FreeBSD port and part of the + nss_ldap FreeBSD port before that. + + Copyright (C) 2003 Jacques Vidrine + Copyright (C) 2006 Artem Kazakov + Copyright (C) 2009 Alexander V. Chernikov + Copyright (C) 2011 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "prototypes.h" + +#define BUFFER_SIZE 1024 + +NSS_METHOD_PROTOTYPE(__nss_compat_getgrnam_r); +NSS_METHOD_PROTOTYPE(__nss_compat_getgrgid_r); +NSS_METHOD_PROTOTYPE(__nss_compat_getgrent_r); +NSS_METHOD_PROTOTYPE(__nss_compat_setgrent); +NSS_METHOD_PROTOTYPE(__nss_compat_endgrent); + +NSS_METHOD_PROTOTYPE(__nss_compat_getpwnam_r); +NSS_METHOD_PROTOTYPE(__nss_compat_getpwuid_r); +NSS_METHOD_PROTOTYPE(__nss_compat_getpwent_r); +NSS_METHOD_PROTOTYPE(__nss_compat_setpwent); +NSS_METHOD_PROTOTYPE(__nss_compat_endpwent); + +NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname); +NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyname2); +NSS_METHOD_PROTOTYPE(__nss_compat_gethostbyaddr); + +static ns_mtab methods[]={ + { NSDB_GROUP, "getgrnam_r", __nss_compat_getgrnam_r, _nss_ldap_getgrnam_r }, + { NSDB_GROUP, "getgrgid_r", __nss_compat_getgrgid_r, _nss_ldap_getgrgid_r }, + { NSDB_GROUP, "getgrent_r", __nss_compat_getgrent_r, _nss_ldap_getgrent_r }, + { NSDB_GROUP, "setgrent", __nss_compat_setgrent, _nss_ldap_setgrent }, + { NSDB_GROUP, "endgrent", __nss_compat_endgrent, _nss_ldap_endgrent }, + + { NSDB_PASSWD, "getpwnam_r", __nss_compat_getpwnam_r, _nss_ldap_getpwnam_r }, + { NSDB_PASSWD, "getpwuid_r", __nss_compat_getpwuid_r, _nss_ldap_getpwuid_r }, + { NSDB_PASSWD, "getpwent_r", __nss_compat_getpwent_r, _nss_ldap_getpwent_r }, + { NSDB_PASSWD, "setpwent", __nss_compat_setpwent, _nss_ldap_setpwent }, + { NSDB_PASSWD, "endpwent", __nss_compat_endpwent, _nss_ldap_endpwent }, + + { NSDB_HOSTS, "gethostbyname", __nss_compat_gethostbyname, _nss_ldap_gethostbyname_r }, + { NSDB_HOSTS, "gethostbyaddr", __nss_compat_gethostbyaddr, _nss_ldap_gethostbyaddr_r }, + { NSDB_HOSTS, "gethostbyname2", __nss_compat_gethostbyname2, _nss_ldap_gethostbyname2_r }, + + { NSDB_GROUP_COMPAT, "getgrnam_r", __nss_compat_getgrnam_r, _nss_ldap_getgrnam_r }, + { NSDB_GROUP_COMPAT, "getgrgid_r", __nss_compat_getgrgid_r, _nss_ldap_getgrgid_r }, + { NSDB_GROUP_COMPAT, "getgrent_r", __nss_compat_getgrent_r, _nss_ldap_getgrent_r }, + { NSDB_GROUP_COMPAT, "setgrent", __nss_compat_setgrent, _nss_ldap_setgrent }, + { NSDB_GROUP_COMPAT, "endgrent", __nss_compat_endgrent, _nss_ldap_endgrent }, + + { NSDB_PASSWD_COMPAT, "getpwnam_r", __nss_compat_getpwnam_r, _nss_ldap_getpwnam_r }, + { NSDB_PASSWD_COMPAT, "getpwuid_r", __nss_compat_getpwuid_r, _nss_ldap_getpwuid_r }, + { NSDB_PASSWD_COMPAT, "getpwent_r", __nss_compat_getpwent_r, _nss_ldap_getpwent_r }, + { NSDB_PASSWD_COMPAT, "setpwent", __nss_compat_setpwent, _nss_ldap_setpwent }, + { NSDB_PASSWD_COMPAT, "endpwent", __nss_compat_endpwent, _nss_ldap_endpwent }, +}; + +int __nss_compat_gethostbyname(void *retval,void *mdata,va_list ap) +{ + nss_status_t (*fn)(const char *,struct hostent *,char *,size_t,int *,int *); + const char *name; + struct hostent *result; + char buffer[BUFFER_SIZE]; + int errnop; + int h_errnop; + int af; + nss_status_t status; + fn=mdata; + name=va_arg(ap,const char*); + af=va_arg(ap,int); + result=va_arg(ap,struct hostent *); + status=fn(name,result,buffer,sizeof(buffer),&errnop,&h_errnop); + status=__nss_compat_result(status,errnop); + h_errno=h_errnop; + return (status); +} + +int __nss_compat_gethostbyname2(void *retval,void *mdata,va_list ap) +{ + nss_status_t (*fn)(const char *,struct hostent *,char *,size_t,int *,int *); + const char *name; + struct hostent *result; + char buffer[BUFFER_SIZE]; + int errnop; + int h_errnop; + int af; + nss_status_t status; + fn=mdata; + name=va_arg(ap,const char*); + af=va_arg(ap,int); + result=va_arg(ap,struct hostent *); + status=fn(name,result,buffer,sizeof(buffer),&errnop,&h_errnop); + status=__nss_compat_result(status,errnop); + h_errno=h_errnop; + return (status); +} + +int __nss_compat_gethostbyaddr(void *retval,void *mdata,va_list ap) +{ + struct in_addr *addr; + int len; + int type; + struct hostent *result; + char buffer[BUFFER_SIZE]; + int errnop; + int h_errnop; + nss_status_t (*fn)(struct in_addr *,int,int,struct hostent *,char *,size_t,int *,int *); + nss_status_t status; + fn=mdata; + addr=va_arg(ap,struct in_addr*); + len=va_arg(ap,int); + type=va_arg(ap,int); + result=va_arg(ap,struct hostent*); + status=fn(addr,len,type,result,buffer,sizeof(buffer),&errnop,&h_errnop); + status=__nss_compat_result(status,errnop); + h_errno=h_errnop; + return (status); +} + +ns_mtab *nss_module_register(const char *source,unsigned int *mtabsize, + nss_module_unregister_fn *unreg) +{ + *mtabsize=sizeof(methods)/sizeof(methods[0]); + *unreg=NULL; + return (methods); +} diff --git a/nss/exports.freebsd b/nss/exports.freebsd new file mode 100644 index 0000000..b9cd773 --- /dev/null +++ b/nss/exports.freebsd @@ -0,0 +1,16 @@ +EXPORTED { + + # published NSS service functions + global: + + # flag to enable or disable lookups + _nss_ldap_enablelookups; + + # module init + nss_module_register; + + # everything else should not be exported + local: + *; + +}; diff --git a/nss/prototypes.h b/nss/prototypes.h index 23c7c33..e50aed2 100644 --- a/nss/prototypes.h +++ b/nss/prototypes.h @@ -29,6 +29,18 @@ NSS_STATUS_UNAVAIL */ extern int _nss_ldap_enablelookups; +#ifdef NSS_FLAVOUR_FREEBSD + +/* for FreeBSD we want the GlibC prototypes and functions to be built + (we provide some wrappers in bsdnss.c) */ +#define NSS_FLAVOUR_GLIBC 1 + +/* FreeBSD specific register function */ +ns_mtab *nss_module_register(const char *source, unsigned int *mtabsize, + nss_module_unregister_fn *unreg); + +#endif /* NSS_FLAVOUR_FREEBSD */ + #ifdef NSS_FLAVOUR_GLIBC /* -- cgit v1.2.3