Index: head/include/Makefile =================================================================== --- head/include/Makefile (revision 113594) +++ head/include/Makefile (revision 113595) @@ -1,126 +1,127 @@ # @(#)Makefile 8.2 (Berkeley) 1/4/94 # $FreeBSD$ # # Doing a make install builds /usr/include # # The ``rm -rf''s used below are safe because rm doesn't follow symbolic # links. CLEANFILES= osreldate.h version vers.c SUBDIR= arpa protocols rpcsvc rpc INCS= a.out.h ar.h assert.h bitstring.h complex.h cpio.h ctype.h db.h \ dirent.h dlfcn.h elf.h elf-hints.h err.h fmtmsg.h fnmatch.h fstab.h \ fts.h getopt.h glob.h grp.h hesiod.h histedit.h ieeefp.h ifaddrs.h \ inttypes.h iso646.h kenv.h langinfo.h libgen.h limits.h link.h \ locale.h malloc.h memory.h monetary.h mpool.h ndbm.h netconfig.h \ - netdb.h nl_types.h nlist.h nsswitch.h objformat.h paths.h pthread.h \ + netdb.h nl_types.h nlist.h nss.h nsswitch.h objformat.h paths.h \ + pthread.h \ pthread_np.h pwd.h ranlib.h readpassphrase.h regex.h regexp.h \ resolv.h rune.h runetype.h search.h setjmp.h sgtty.h signal.h stab.h \ stdbool.h stddef.h stdio.h stdlib.h strhash.h string.h stringlist.h \ strings.h sysexits.h tar.h time.h timeconv.h timers.h ttyent.h \ ulimit.h unistd.h utime.h utmp.h uuid.h vis.h wchar.h wctype.h \ wordexp.h MHDRS= float.h floatingpoint.h stdarg.h varargs.h # posix4/mqueue.h is useless without an implementation and isn't installed: PHDRS= sched.h semaphore.h _semaphore.h # mqueue.h LHDRS= aio.h errno.h fcntl.h linker_set.h poll.h stdint.h syslog.h \ termios.h ucontext.h LDIRS= cam geom net netatalk netatm netgraph netinet netinet6 netipsec \ netipx netkey netnatm netncp netsmb nfs nfsclient nfsserver \ pccard posix4 sys vm LSUBDIRS= cam/scsi dev/an dev/ic dev/iicbus dev/firewire dev/ofw \ dev/ppbus dev/smbus dev/usb dev/wi fs/devfs \ fs/fdescfs fs/fifofs fs/msdosfs fs/ntfs fs/nullfs fs/nwfs fs/portalfs \ fs/procfs fs/smbfs fs/umapfs fs/unionfs isofs/cd9660 \ netatm/ipatm netatm/sigpvc netatm/spans netatm/uni \ netgraph/bluetooth/include \ security/mac_biba security/mac_bsdextended security/mac_lomac\ security/mac_mls security/mac_partition ufs/ffs ufs/ufs # For SHARED=symlinks, cam, netatm, and netgraph are symlinks, so cam/scsi, # netatm/*, and netgraph/* are taken care of LSYMSUBDIRS= ${LSUBDIRS:Ncam/scsi:Nnetatm/*:Nnetgraph/*} # Define SHARED to indicate whether you want symbolic links to the system # source (``symlinks''), or a separate copy (``copies''). ``symlinks'' is # probably only useful for developers and should be avoided if you do not # wish to tie your /usr/include and /usr/src together. #SHARED= symlinks SHARED?= copies INCS+= osreldate.h osreldate.h: ${.CURDIR}/../sys/conf/newvers.sh \ ${.CURDIR}/../sys/sys/param.h \ ${.CURDIR}/Makefile @${ECHO} creating osreldate.h from newvers.sh setvar PARAMFILE ${.CURDIR}/../sys/sys/param.h; \ . ${.CURDIR}/../sys/conf/newvers.sh; \ echo "$$COPYRIGHT" > osreldate.h; \ echo "#ifdef _KERNEL" >> osreldate.h; \ echo '#error "/usr/include/osreldate.h cannot be used in the kernel, use sys/param.h"' >> osreldate.h; \ echo "#else" >> osreldate.h; \ echo \#'undef __FreeBSD_version' >> osreldate.h; \ echo \#'define __FreeBSD_version' $$RELDATE >> osreldate.h; \ echo "#endif" >> osreldate.h .for i in ${LHDRS} INCSLINKS+= sys/$i ${INCLUDEDIR}/$i .endfor .for i in ${MHDRS} INCSLINKS+= machine/$i ${INCLUDEDIR}/$i .endfor .for i in ${PHDRS} INCSLINKS+= posix4/$i ${INCLUDEDIR}/$i .endfor copies: .for i in ${LDIRS} ${LSYMSUBDIRS} machine crypto if [ -L ${DESTDIR}/usr/include/$i ]; then \ rm -f ${DESTDIR}/usr/include/$i; \ fi .endfor mtree -deU ${MTREE_FOLLOWS_SYMLINKS} -f ${.CURDIR}/../etc/mtree/BSD.include.dist \ -p ${DESTDIR}/usr/include .for i in ${LDIRS} ${LSUBDIRS} cd ${.CURDIR}/../sys; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 $i/*.h \ ${DESTDIR}/usr/include/$i .endfor cd ${.CURDIR}/../sys; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 opencrypto/*.h \ ${DESTDIR}/usr/include/crypto .if exists(${.CURDIR}/../sys/${MACHINE_ARCH}/include) cd ${.CURDIR}/../sys/${MACHINE_ARCH}/include; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \ ${DESTDIR}/usr/include/machine .if exists(${.CURDIR}/../sys/${MACHINE_ARCH}/include/pc) cd ${.CURDIR}/../sys/${MACHINE_ARCH}/include/pc; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \ ${DESTDIR}/usr/include/machine/pc .endif .endif symlinks: @${ECHO} "Setting up symlinks to kernel source tree..." .for i in ${LDIRS} rm -rf ${DESTDIR}/usr/include/$i ln -s ../../sys/$i ${DESTDIR}/usr/include/$i .endfor rm -rf ${DESTDIR}/usr/include/crypto ln -s ../../sys/opencrypto ${DESTDIR}/usr/include/crypto .for i in ${LSYMSUBDIRS} rm -rf ${DESTDIR}/usr/include/$i ln -s ../../../sys/$i ${DESTDIR}/usr/include/$i .endfor rm -rf ${DESTDIR}/usr/include/machine ln -s ../../sys/${MACHINE_ARCH}/include ${DESTDIR}/usr/include/machine .include installincludes: ${SHARED} Index: head/include/nss.h =================================================================== --- head/include/nss.h (nonexistent) +++ head/include/nss.h (revision 113595) @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Compatibility header for the GNU C Library-style nsswitch interface. + */ +#ifndef _NSS_H_ +#define _NSS_H_ + +#include + +enum nss_status { + NSS_STATUS_TRYAGAIN = -2, + NSS_STATUS_UNAVAIL, + NSS_STATUS_NOTFOUND, + NSS_STATUS_SUCCESS, + NSS_STATUS_RETURN +}; + +#define __nss_compat_result(rv) \ +((rv == NSS_STATUS_TRYAGAIN) ? NS_TRYAGAIN : \ + (rv == NSS_STATUS_UNAVAIL) ? NS_UNAVAIL : \ + (rv == NSS_STATUS_NOTFOUND) ? NS_NOTFOUND : \ + (rv == NSS_STATUS_SUCCESS) ? NS_SUCCESS : \ + (rv == NSS_STATUS_RETURN) ? NS_RETURN : 0) + +#endif Property changes on: head/include/nss.h ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/include/nsswitch.h =================================================================== --- head/include/nsswitch.h (revision 113594) +++ head/include/nsswitch.h (revision 113595) @@ -1,184 +1,246 @@ /* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ /* $FreeBSD$ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _NSSWITCH_H #define _NSSWITCH_H 1 #include - #include +#define NSS_MODULE_INTERFACE_VERSION 1 + #ifndef _PATH_NS_CONF #define _PATH_NS_CONF "/etc/nsswitch.conf" #endif -#define NS_CONTINUE 0 -#define NS_RETURN 1 +/* NSS source actions */ +#define NS_ACTION_CONTINUE 0 /* try the next source */ +#define NS_ACTION_RETURN 1 /* look no further */ #define NS_SUCCESS (1<<0) /* entry was found */ #define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ #define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ -#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retrys */ +#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ +#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ +#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ #define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ /* * currently implemented sources */ #define NSSRC_FILES "files" /* local files */ #define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ #define NSSRC_NIS "nis" /* YP/NIS */ #define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ /* * currently implemented databases */ #define NSDB_HOSTS "hosts" #define NSDB_GROUP "group" #define NSDB_GROUP_COMPAT "group_compat" #define NSDB_NETGROUP "netgroup" #define NSDB_NETWORKS "networks" #define NSDB_PASSWD "passwd" #define NSDB_PASSWD_COMPAT "passwd_compat" #define NSDB_SHELLS "shells" /* * suggested databases to implement */ #define NSDB_ALIASES "aliases" #define NSDB_AUTH "auth" #define NSDB_AUTOMOUNT "automount" #define NSDB_BOOTPARAMS "bootparams" #define NSDB_ETHERS "ethers" #define NSDB_EXPORTS "exports" #define NSDB_NETMASKS "netmasks" #define NSDB_PHONES "phones" #define NSDB_PRINTCAP "printcap" #define NSDB_PROTOCOLS "protocols" #define NSDB_REMOTE "remote" #define NSDB_RPC "rpc" #define NSDB_SENDMAILVARS "sendmailvars" #define NSDB_SERVICES "services" #define NSDB_TERMCAP "termcap" #define NSDB_TTYS "ttys" /* + * ns_dtab `method' function signature. + */ +typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); + +/* + * Macro for generating method prototypes. + */ +#define NSS_METHOD_PROTOTYPE(method) \ + int method(void *, void *, va_list) + +/* * ns_dtab - `nsswitch dispatch table' - * contains an entry for each source and the appropriate function to call + * Contains an entry for each source and the appropriate function to + * call. ns_dtabs are used in the nsdispatch() API in order to allow + * the application to override built-in actions. */ -typedef struct { - const char *src; - int (*callback)(void *retval, void *cb_data, va_list ap); - void *cb_data; +typedef struct _ns_dtab { + const char *src; /* Source this entry implements */ + nss_method method; /* Method to be called */ + void *mdata; /* Data passed to method */ } ns_dtab; /* * macros to help build an ns_dtab[] */ #define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, #define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, #ifdef HESIOD # define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, #else # define NS_DNS_CB(F,C) #endif #ifdef YP # define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, #else # define NS_NIS_CB(F,C) #endif /* * ns_src - `nsswitch source' * used by the nsparser routines to store a mapping between a source * and its dispatch control flags for a given database. */ -typedef struct { +typedef struct _ns_src { const char *name; u_int32_t flags; } ns_src; /* * default sourcelist (if nsswitch.conf is missing, corrupt, * or the requested database doesn't have an entry. */ extern const ns_src __nsdefaultsrc[]; +/* + * ns_mtab - NSS method table + * An NSS module provides a mapping from (database name, method name) + * tuples to the nss_method and associated data. + */ +typedef struct _ns_mtab { + const char *database; + const char *name; + nss_method method; + void *mdata; +} ns_mtab; +/* + * NSS module de-registration, called at module unload. + */ +typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); + +/* + * NSS module registration, called at module load. + */ +typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, + nss_module_unregister_fn *); + +/* + * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. + * Developers are encouraged to use nss_lookup_type where approriate. + */ +enum nss_lookup_type { + nss_lt_name = 1, + nss_lt_id = 2, + nss_lt_all = 3 +}; + #ifdef _NS_PRIVATE /* * private data structures for back-end nsswitch implementation */ /* * ns_dbt - `nsswitch database thang' * for each database in /etc/nsswitch.conf there is a ns_dbt, with its * name and a list of ns_src's containing the source information. */ -typedef struct { +typedef struct _ns_dbt { const char *name; /* name of database */ ns_src *srclist; /* list of sources */ int srclistsize; /* size of srclist */ } ns_dbt; +/* + * ns_mod - NSS module + */ +typedef struct _ns_mod { + char *name; /* module name */ + void *handle; /* handle from dlopen */ + ns_mtab *mtab; /* method table */ + unsigned int mtabsize; /* count of entries in method table */ + nss_module_unregister_fn unregister; /* called to unload module */ +} ns_mod; + #endif /* _NS_PRIVATE */ #include __BEGIN_DECLS extern int nsdispatch(void *, const ns_dtab [], const char *, const char *, const ns_src [], ...); #ifdef _NS_PRIVATE extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); -extern void _nsdbtdump(const ns_dbt *); -extern const ns_dbt *_nsdbtget(const char *); extern void _nsdbtput(const ns_dbt *); extern void _nsyyerror(const char *); extern int _nsyylex(void); +extern int _nsyyparse(void); extern int _nsyylineno; +#ifdef _NSS_DEBUG +extern void _nsdbtdump(const ns_dbt *); +#endif #endif /* _NS_PRIVATE */ __END_DECLS #endif /* !_NSSWITCH_H */ Index: head/lib/libc/gen/Makefile.inc =================================================================== --- head/lib/libc/gen/Makefile.inc (revision 113594) +++ head/lib/libc/gen/Makefile.inc (revision 113595) @@ -1,141 +1,143 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # $FreeBSD$ # machine-independent gen sources .PATH: ${.CURDIR}/${MACHINE_ARCH}/gen ${.CURDIR}/gen SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ alarm.c arc4random.c assert.c basename.c check_utility_compat.c \ clock.c closedir.c confstr.c \ crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ dlfcn.c dlfunc.c drand48.c erand48.c err.c errlst.c errno.c \ exec.c fmtcheck.c fmtmsg.c fnmatch.c fpclassify.c fstab.c ftok.c fts.c \ getbootfile.c getbsize.c \ getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \ getobjformat.c getosreldate.c getpagesize.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getvfsbyname.c getvfsent.c glob.c \ initgroups.c isatty.c jrand48.c lcong48.c \ lockf.c lrand48.c mrand48.c nice.c \ nlist.c nrand48.c ntp_gettime.c opendir.c \ pause.c popen.c posixshm.c pselect.c psignal.c pw_scan.c pwcache.c \ raise.c readdir.c readpassphrase.c rewinddir.c \ scandir.c seed48.c seekdir.c semctl.c \ setdomainname.c sethostname.c setjmperr.c setmode.c \ setproctitle.c setprogname.c \ siginterrupt.c siglist.c signal.c signbit.c \ sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ syslog.c telldir.c termios.c time.c times.c timezone.c ttyname.c \ ttyslot.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c \ valloc.c vis.c wait.c wait3.c waitpid.c wordexp.c # machine-dependent gen sources .if exists(${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc) .include "${.CURDIR}/${MACHINE_ARCH}/gen/Makefile.inc" .endif MAN+= alarm.3 arc4random.3 \ basename.3 check_utility_compat.3 clock.3 \ confstr.3 ctermid.3 daemon.3 devname.3 directory.3 dirname.3 \ dladdr.3 dlinfo.3 dllockinit.3 dlopen.3 \ err.3 exec.3 fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 frexp.3 \ ftok.3 fts.3 \ getbootfile.3 getbsize.3 getcap.3 getcontext.3 getcwd.3 \ getdiskbyname.3 getdomainname.3 getfsent.3 \ getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ getmntinfo.3 getnetgrent.3 getobjformat.3 getosreldate.3 \ getpagesize.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \ getttyent.3 getusershell.3 getvfsbyname.3 getvfsent.3 \ glob.3 initgroups.3 isgreater.3 ldexp.3 lockf.3 makecontext.3 \ modf.3 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \ nice.3 nlist.3 pause.3 popen.3 pselect.3 psignal.3 pwcache.3 \ raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \ scandir.3 setjmp.3 setmode.3 setproctitle.3 shm_open.3 \ siginterrupt.3 signal.3 signbit.3 sigsetops.3 sleep.3 \ statvfs.3 stringlist.3 \ strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 \ tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 time.3 times.3 timezone.3 \ ttyname.3 tzset.3 ualarm.3 ucontext.3 ulimit.3 uname.3 \ unvis.3 usleep.3 utime.3 valloc.3 vis.3 wordexp.3 MLINKS+=arc4random.3 arc4random_addrandom.3 arc4random.3 arc4random_stir.3 MLINKS+=ctermid.3 ctermid_r.3 MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ directory.3 readdir.3 directory.3 readdir_r.3 directory.3 rewinddir.3 \ directory.3 seekdir.3 directory.3 telldir.3 MLINKS+=dlopen.3 dlclose.3 dlopen.3 dlerror.3 dlopen.3 dlfunc.3 \ dlopen.3 dlsym.3 MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \ err.3 verr.3 err.3 verrc.3 err.3 verrx.3 err.3 vwarn.3 err.3 vwarnc.3 \ err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3 MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \ exec.3 execv.3 exec.3 execvp.3 MLINKS+=fpclassify.3 isfinite.3 fpclassify.3 isinf.3 fpclassify.3 isnan.3 \ fpclassify.3 isnormal.3 MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_open.3 \ fts.3 fts_read.3 fts.3 fts_set.3 MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \ getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \ getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \ getcap.3 cgetustr.3 MLINKS+=getcwd.3 getwd.3 MLINKS+=getcontext.3 setcontext.3 MLINKS+=getdomainname.3 setdomainname.3 MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ getfsent.3 getfstype.3 getfsent.3 setfsent.3 \ getfsent.3 setfstab.3 getfsent.3 getfstab.3 MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \ getgrent.3 setgrent.3 getgrent.3 setgroupent.3 MLINKS+=gethostname.3 sethostname.3 MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ getnetgrent.3 setnetgrent.3 MLINKS+=getprogname.3 setprogname.3 MLINKS+=getpwent.3 endpwent.3 getpwent.3 getpwnam.3 getpwent.3 getpwuid.3 \ - getpwent.3 setpassent.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 + getpwent.3 setpassent.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 \ + getpwent.3 getpwent_r.3 getpwent.3 getpwnam_r.3 \ + getpwent.3 getpwuid_r.3 MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \ getttyent.3 isdialuptty.3 getttyent.3 isnettty.3 \ getttyent.3 setttyent.3 MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 MLINKS+=getvfsent.3 endvfsent.3 getvfsent.3 getvfsbytype.3 \ getvfsent.3 setvfsent.3 getvfsent.3 vfsisloadable.3 \ getvfsent.3 vfsload.3 MLINKS+=glob.3 globfree.3 MLINKS+=isgreater.3 isgreaterequal.3 isgreater.3 isless.3 \ isgreater.3 islessequal.3 isgreater.3 islessgreater.3 \ isgreater.3 isunordered.3 MLINKS+=makecontext.3 swapcontext.3 MLINKS+=popen.3 pclose.3 MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3 MLINKS+=pwcache.3 group_from_gid.3 pwcache.3 user_from_uid.3 MLINKS+=rand48.3 _rand48.3 rand48.3 drand48.3 rand48.3 erand48.3 \ rand48.3 jrand48.3 rand48.3 lcong48.3 rand48.3 lrand48.3 \ rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 seed48.3 \ rand48.3 srand48.3 MLINKS+=scandir.3 alphasort.3 MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \ setjmp.3 longjmperr.3 setjmp.3 longjmperror.3 \ setjmp.3 siglongjmp.3 setjmp.3 sigsetjmp.3 MLINKS+=setmode.3 getmode.3 MLINKS+=shm_open.3 shm_unlink.3 MLINKS+=sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \ sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \ sigsetops.3 sigismember.3 MLINKS+=statvfs.3 fstatvfs.3 MLINKS+=stringlist.3 sl_add.3 stringlist.3 sl_find.3 \ stringlist.3 sl_free.3 stringlist.3 sl_init.3 MLINKS+=strtofflags.3 fflagstostr.3 MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlnametomib.3 MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \ syslog.3 vsyslog.3 MLINKS+=tcsendbreak.3 tcdrain.3 tcsendbreak.3 tcflow.3 tcsendbreak.3 tcflush.3 MLINKS+=tcsetattr.3 cfgetispeed.3 tcsetattr.3 cfgetospeed.3 \ tcsetattr.3 cfmakeraw.3 tcsetattr.3 cfsetispeed.3 \ tcsetattr.3 cfsetospeed.3 tcsetattr.3 cfsetspeed.3 \ tcsetattr.3 tcgetattr.3 MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 MLINKS+=tzset.3 tzsetwall.3 MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 MLINKS+=vis.3 strvis.3 vis.3 strvisx.3 MLINKS+=wordexp.3 wordfree.3 Index: head/lib/libc/include/namespace.h =================================================================== --- head/lib/libc/include/namespace.h (revision 113594) +++ head/lib/libc/include/namespace.h (revision 113595) @@ -1,162 +1,163 @@ /* * Copyright (c) 2001 Daniel Eischen . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _NAMESPACE_H_ #define _NAMESPACE_H_ /* * Adjust names so that headers declare "hidden" names. * * README: When modifying this file don't forget to make the appropriate * changes in un-namespace.h!!! */ /* * ISO C (C90) section. Most names in libc aren't in ISO C, so they * should be here. Most aren't here... */ #define err _err #define warn _warn +#define nsdispatch _nsdispatch /* * Prototypes for syscalls/functions that need to be overridden * in libc_r/libpthread. */ #define accept _accept #define __acl_aclcheck_fd ___acl_aclcheck_fd #define __acl_delete_fd ___acl_delete_fd #define __acl_get_fd ___acl_get_fd #define __acl_set_fd ___acl_set_fd #define bind _bind #define __cap_get_fd ___cap_get_fd #define __cap_set_fd ___cap_set_fd #define close _close #define connect _connect #define dup _dup #define dup2 _dup2 #define execve _execve #define fcntl _fcntl /*#define flock _flock */ #define flockfile _flockfile #define fpathconf _fpathconf #define fstat _fstat #define fstatfs _fstatfs #define fsync _fsync #define funlockfile _funlockfile #define getdirentries _getdirentries #define getlogin _getlogin #define getpeername _getpeername #define getprogname _getprogname #define getsockname _getsockname #define getsockopt _getsockopt #define ioctl _ioctl /* #define kevent _kevent */ #define listen _listen #define nanosleep _nanosleep #define open _open #define poll _poll #define pthread_cond_broadcast _pthread_cond_broadcast #define pthread_cond_destroy _pthread_cond_destroy #define pthread_cond_init _pthread_cond_init #define pthread_cond_signal _pthread_cond_signal #define pthread_cond_timedwait _pthread_cond_timedwait #define pthread_cond_wait _pthread_cond_wait #define pthread_exit _pthread_exit #define pthread_getspecific _pthread_getspecific #define pthread_key_create _pthread_key_create #define pthread_key_delete _pthread_key_delete #define pthread_main_np _pthread_main_np #define pthread_mutex_destroy _pthread_mutex_destroy #define pthread_mutex_init _pthread_mutex_init #define pthread_mutex_lock _pthread_mutex_lock #define pthread_mutex_trylock _pthread_mutex_trylock #define pthread_mutex_unlock _pthread_mutex_unlock #define pthread_mutexattr_destroy _pthread_mutexattr_destroy #define pthread_mutexattr_init _pthread_mutexattr_init #define pthread_mutexattr_settype _pthread_mutexattr_settype #define pthread_once _pthread_once #define pthread_rwlock_destroy _pthread_rwlock_destroy #define pthread_rwlock_init _pthread_rwlock_init #define pthread_rwlock_rdlock _pthread_rwlock_rdlock #define pthread_rwlock_wrlock _pthread_rwlock_wrlock #define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock #define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock #define pthread_rwlock_unlock _pthread_rwlock_unlock #define pthread_self _pthread_self #define pthread_setspecific _pthread_setspecific #define pthread_sigmask _pthread_sigmask #define read _read #define readv _readv #define recvfrom _recvfrom #define recvmsg _recvmsg #define select _select #define sendmsg _sendmsg #define sendto _sendto #define setsockopt _setsockopt /*#define sigaction _sigaction*/ #define sigprocmask _sigprocmask #define sigsuspend _sigsuspend #define socket _socket #define socketpair _socketpair #define wait4 _wait4 #define waitpid _waitpid #define write _write #define writev _writev /* * Other hidden syscalls/functions that libc_r needs to override * but are not used internally by libc. * * XXX - When modifying libc to use one of the following, remove * the prototype from below and place it in the list above. */ #if 0 #define creat _creat #define fchflags _fchflags #define fchmod _fchmod #define ftrylockfile _ftrylockfile #define msync _msync #define nfssvc _nfssvc #define pause _pause #define pthread_rwlockattr_init _pthread_rwlockattr_init #define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy #define sched_yield _sched_yield #define sendfile _sendfile #define shutdown _shutdown #define sigaltstack _sigaltstack #define sigpending _sigpending #define sigreturn _sigreturn #define sigsetmask _sigsetmask #define sleep _sleep #define system _system #define tcdrain _tcdrain #define wait _wait #endif #endif /* _NAMESPACE_H_ */ Index: head/lib/libc/include/nss_tls.h =================================================================== --- head/lib/libc/include/nss_tls.h (nonexistent) +++ head/lib/libc/include/nss_tls.h (revision 113595) @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + * + * Macros which generate thread local storage handling code in NSS modules. + */ +#ifndef _NSS_TLS_H_ +#define _NSS_TLS_H_ + +#define NSS_TLS_HANDLING(name) \ +static pthread_key_t name##_state_key; \ +static void name##_keyinit(void); \ +static int name##_getstate(struct name##_state **); \ +\ +static void \ +name##_keyinit(void) \ +{ \ + (void)_pthread_key_create(&name##_state_key, name##_endstate); \ +} \ +\ +static int \ +name##_getstate(struct name##_state **p) \ +{ \ + static struct name##_state st; \ + static pthread_once_t keyinit = PTHREAD_ONCE_INIT; \ + int rv; \ + \ + if (!__isthreaded || _pthread_main_np() != 0) { \ + *p = &st; \ + return (0); \ + } \ + rv = _pthread_once(&keyinit, name##_keyinit); \ + if (rv != 0) \ + return (rv); \ + *p = _pthread_getspecific(name##_state_key); \ + if (*p != NULL) \ + return (0); \ + *p = calloc(1, sizeof(*p)); \ + if (*p == NULL) \ + return (ENOMEM); \ + rv = _pthread_setspecific(name##_state_key, *p); \ + if (rv != 0) { \ + free(*p); \ + *p = NULL; \ + } \ + return (rv); \ +} \ +/* allow the macro invocation to end with a semicolon */ \ +typedef int _##name##_bmVjdGFy + +#endif /* _NSS_TLS_H_ */ Property changes on: head/lib/libc/include/nss_tls.h ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/lib/libc/include/un-namespace.h =================================================================== --- head/lib/libc/include/un-namespace.h (revision 113594) +++ head/lib/libc/include/un-namespace.h (revision 113595) @@ -1,152 +1,153 @@ /* * Copyright (c) 2001 Daniel Eischen . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _UN_NAMESPACE_H_ #define _UN_NAMESPACE_H_ #undef accept #undef __acl_aclcheck_fd #undef __acl_delete_fd #undef __acl_get_fd #undef __acl_set_fd #undef bind #undef __cap_get_fd #undef __cap_set_fd #undef close #undef connect #undef dup #undef dup2 #undef execve #undef fcntl #undef flock #undef flockfile #undef fpathconf #undef fstat #undef fstatfs #undef fsync #undef funlockfile #undef getdirentries #undef getlogin #undef getpeername #undef getprogname #undef getsockname #undef getsockopt #undef ioctl #undef kevent #undef listen #undef nanosleep #undef open #undef poll #undef pthread_cond_broadcast #undef pthread_cond_destroy #undef pthread_cond_init #undef pthread_cond_signal #undef pthread_cond_timedwait #undef pthread_cond_wait #undef pthread_exit #undef pthread_getspecific #undef pthread_key_create #undef pthread_key_delete #undef pthread_main_np #undef pthread_mutex_destroy #undef pthread_mutex_init #undef pthread_mutex_lock #undef pthread_mutex_trylock #undef pthread_mutex_unlock #undef pthread_mutexattr_init #undef pthread_mutexattr_destroy #undef pthread_mutexattr_settype #undef pthread_once #undef pthread_rwlock_destroy #undef pthread_rwlock_init #undef pthread_rwlock_rdlock #undef pthread_rwlock_wrlock #undef pthread_rwlock_tryrdlock #undef pthread_rwlock_trywrlock #undef pthread_rwlock_unlock #undef pthread_self #undef pthread_setspecific #undef pthread_sigmask #undef read #undef readv #undef recvfrom #undef recvmsg #undef select #undef sendmsg #undef sendto #undef setsockopt #undef sigaction #undef sigprocmask #undef sigsuspend #undef socket #undef socketpair #undef wait4 #undef waitpid #undef write #undef writev #if 0 #undef creat #undef fchflags #undef fchmod #undef ftrylockfile #undef msync #undef nfssvc #undef pause #undef pthread_rwlockattr_init #undef pthread_rwlockattr_destroy #undef sched_yield #undef sendfile #undef shutdown #undef sigaltstack #undef sigpending #undef sigreturn #undef sigsetmask #undef sleep #undef system #undef tcdrain #undef wait #endif /* 0 */ #ifdef _SIGNAL_H_ int _sigaction(int, const struct sigaction *, struct sigaction *); #endif #ifdef _SYS_EVENT_H_ int _kevent(int, const struct kevent *, int, struct kevent *, int, const struct timespec *); #endif #ifdef _SYS_FCNTL_H_ int _flock(int, int); #endif #undef err #undef warn +#undef nsdispatch #endif /* _UN_NAMESPACE_H_ */ Index: head/lib/libc/net/Makefile.inc =================================================================== --- head/lib/libc/net/Makefile.inc (revision 113594) +++ head/lib/libc/net/Makefile.inc (revision 113595) @@ -1,97 +1,97 @@ # from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # $FreeBSD$ # machine-independent net sources .PATH: ${.CURDIR}/${MACHINE_ARCH}/net ${.CURDIR}/net SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c getaddrinfo.c \ gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ getifaddrs.c getnameinfo.c \ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ getproto.c getprotoent.c getprotoname.c getservbyname.c \ getservbyport.c getservent.c herror.c hesiod.c inet_addr.c \ if_indextoname.c if_nameindex.c if_nametoindex.c inet_lnaof.c \ inet_makeaddr.c inet_net_ntop.c inet_net_pton.c inet_neta.c \ inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \ inet_pton.c ip6opt.c linkaddr.c map_v4v6.c name6.c \ ns_name.c ns_netint.c ns_parse.c ns_print.c ns_ttl.c \ - nsdispatch.c nslexer.c nsparser.c \ + nsdispatch.c nslexer.c nsparser.c nss_compat.c \ nsap_addr.c rcmd.c rcmdsh.c recv.c res_comp.c res_data.c res_debug.c \ res_init.c res_mkquery.c res_mkupdate.c res_query.c res_send.c \ res_update.c rthdr.c send.c sockatmark.c vars.c CFLAGS+=-DINET6 -I${.OBJDIR} YFLAGS+=-p_nsyy LFLAGS+=-P_nsyy CLEANFILES+=nsparser.c nslexer.c nsparser.h nsparser.h: nsparser.c mv y.tab.h ${.TARGET} nslexer.c: nslexer.l nsparser.h ${LEX} ${LFLAGS} -o/dev/stdout ${.IMPSRC} | \ sed -e '/YY_BUF_SIZE/s/16384/1024/' >${.TARGET} # machine-dependent net sources .if exists(${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc) .include "${.CURDIR}/${MACHINE_ARCH}/net/Makefile.inc" .endif MAN+= addr2ascii.3 byteorder.3 ethers.3 getaddrinfo.3 gethostbyname.3 \ getifaddrs.3 getipnodebyname.3 \ getnameinfo.3 getnetent.3 getprotoent.3 getservent.3 hesiod.3 \ if_indextoname.3 \ inet.3 inet_net.3 \ inet6_option_space.3 inet6_rthdr_space.3 linkaddr.3 \ nsdispatch.3 rcmd.3 rcmdsh.3 resolver.3 sockatmark.3 MLINKS+=addr2ascii.3 ascii2addr.3 MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ byteorder.3 ntohs.3 MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 MLINKS+=getaddrinfo.3 freeaddrinfo.3 getaddrinfo.3 gai_strerror.3 MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ gethostbyname.3 gethostbyname2.3 gethostbyname.3 gethostent.3 \ gethostbyname.3 herror.3 gethostbyname.3 hstrerror.3 \ gethostbyname.3 sethostent.3 MLINKS+=getifaddrs.3 freeifaddrs.3 MLINKS+=getipnodebyname.3 getipnodebyaddr.3 getipnodebyname.3 freehostent.3 MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3 MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ getservent.3 getservbyport.3 getservent.3 setservent.3 MLINKS+=if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ if_indextoname.3 if_freenameindex.3 MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ inet.3 inet_network.3 inet.3 inet_ntoa.3 \ inet.3 inet_ntop.3 inet.3 inet_pton.3 \ inet.3 network.3 inet.3 ntoa.3 MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 MLINKS+=inet6_option_space.3 inet6_option_alloc.3 \ inet6_option_space.3 inet6_option_append.3 \ inet6_option_space.3 inet6_option_find.3 \ inet6_option_space.3 inet6_option_init.3 \ inet6_option_space.3 inet6_option_next.3 \ inet6_rthdr_space.3 inet6_rthdr_add.3 \ inet6_rthdr_space.3 inet6_rthdr_getaddr.3 \ inet6_rthdr_space.3 inet6_rthdr_getflags.3 \ inet6_rthdr_space.3 inet6_rthdr_init.3 \ inet6_rthdr_space.3 inet6_rthdr_lasthop.3 \ inet6_rthdr_space.3 inet6_rthdr_reverse.3 \ inet6_rthdr_space.3 inet6_rthdr_segments.3 MLINKS+=linkaddr.3 link_addr.3 linkaddr.3 link_ntoa.3 MLINKS+=rcmd.3 iruserok.3 rcmd.3 iruserok_sa.3 \ rcmd.3 rcmd_af.3 \ rcmd.3 rresvport.3 rcmd.3 rresvport_af.3 \ rcmd.3 ruserok.3 MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ resolver.3 res_mkquery.3 resolver.3 res_query.3 \ resolver.3 res_search.3 resolver.3 res_send.3 resolver.3 dn_skipname.3 \ resolver.3 ns_get16.3 resolver.3 ns_get32.3 \ resolver.3 ns_put16.3 resolver.3 ns_put32.3 Index: head/lib/libc/net/nsdispatch.3 =================================================================== --- head/lib/libc/net/nsdispatch.3 (revision 113594) +++ head/lib/libc/net/nsdispatch.3 (revision 113595) @@ -1,232 +1,245 @@ .\" $NetBSD: nsdispatch.3,v 1.8 1999/03/22 19:44:53 garbled Exp $ .\" $FreeBSD$ .\" .\" Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Luke Mewburn. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the NetBSD .\" Foundation, Inc. and its contributors. .\" 4. Neither the name of The NetBSD Foundation nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 19, 1999 +.Dd April 16, 2003 .Dt NSDISPATCH 3 .Os .Sh NAME .Nm nsdispatch .Nd name-service switch dispatcher routine .Sh LIBRARY .Lb libc .Sh SYNOPSIS +.In sys/types.h +.In stdarg.h .In nsswitch.h .Ft int .Fo nsdispatch .Fa "void *retval" .Fa "const ns_dtab dtab[]" .Fa "const char *database" -.Fa "const char *method" +.Fa "const char *method_name" .Fa "const ns_src defaults[]" .Fa "..." .Fc .Sh DESCRIPTION The .Fn nsdispatch -function invokes the callback functions specified in +function invokes the methods specified in .Va dtab -in the order given in -.Pa /etc/nsswitch.conf +in the order given by +.Xr nsswitch.conf 5 for the database .Va database until a successful entry is found. .Pp .Va retval -is passed to each callback function to modify as necessary -(to pass back to the caller of -.Fn nsdispatch ) +is passed to each method to modify as necessary, to pass back results to +the caller of +.Fn nsdispatch . .Pp +Each method has the function signature described by the typedef: +.Pp +.Ft typedef "int \*(lp*nss_method\*(rp\*(lpvoid *retval, void *mdata, va_list *ap\*(rp" ; +.Pp .Va dtab is an array of .Va ns_dtab structures, which have the following format: .Bd -literal -offset indent -typedef struct { - const char *src; - int (*cb)(void *retval, void *cb_data, va_list ap); - void *cb_data; +typedef struct _ns_dtab { + const char *src; + nss_method method; + void *mdata; } ns_dtab; .Ed .Pp .Bd -ragged -offset indent -For each source type that is implemented, an entry with +The +.Fa dtab +array should consist of one entry for each source type that is +implemented, with .Va src -set to the name of the source, -.Va cb -defined as a function which handles that source, and -.Va cb_data -is used to pass arbitrary data to the callback function. +as the name of the source, +.Va method +as a function which handles that source, and +.Va mdata +as a handle on arbitrary data to be passed to the method. The last entry in .Va dtab should contain .Dv NULL values for .Va src , -.Va cb , +.Va method , and -.Va cb_data . +.Va mdata . .Ed .Pp -.Va method -is usually the name of the function calling -.Fn nsdispatch . -When dynamic loading is supported, a symbol constructed from -.Va database , -the current source, and -.Va method -will be used as the name to invoke the dynamically loaded function. +Additionally, methods may be implemented in NSS modules, in +which case they are selected using the +.Fa database +and +.Fa method_name +arguments along with the configured source. +(The methods supplied via +.Fa dtab +take priority over those implemented in NSS modules in the event +of a conflict.) .Pp .Va defaults -contains a list of default sources to try in the case of -a missing or corrupt -.Xr nsswitch.conf 5 , -or if there isn't a relevant entry for +contains a list of default sources to try if +.Xr nsswitch.conf 5 +is missing or corrupted, or if there is no relevant entry for .Va database . It is an array of .Va ns_src structures, which have the following format: .Bd -literal -offset indent -typedef struct { - const char *src; - u_int32_t flags; +typedef struct _ns_src { + const char *src; + u_int32_t flags; } ns_src; .Ed .Pp .Bd -ragged -offset indent -For each default source type, an entry with -.Va src -set to the name of the source, and +The +.Fa defaults +array should consist of one entry for each source to be configured by +default indicated by +.Va src , +and .Va flags -set to the relevant flags +set to the criterion desired (usually .Dv NS_SUCCESS ; refer to -.Sx Callback return values +.Sx Method return values for more information). The last entry in .Va defaults should have .Va src set to .Dv NULL and .Va flags set to 0. .Pp For convenience, a global variable defined as: .Dl extern const ns_src __nsdefaultsrc[]; -exists which contains a single default entry for +exists which contains a single default entry for the source .Sq files -for use by callers which don't require complicated default rules. +that may be used by callers which do not require complicated default +rules. .Ed .Pp .Sq Va ... -are optional extra arguments, which -are passed to the appropriate callback function as a variable argument -list of the type -.Va va_list . +are optional extra arguments, which are passed to the appropriate method +as a variable argument list of the type +.Vt va_list . .Ss Valid source types -Whilst there is support for arbitrary sources, the following +While there is support for arbitrary sources, the following #defines for commonly implemented sources are available: .Bl -column NS_COMPAT COMPAT -offset indent .It Sy "#define value" .It "NSSRC_FILES ""files""" .It "NSSRC_DNS ""dns""" .It "NSSRC_NIS ""nis""" .It "NSSRC_COMPAT ""compat""" .El .Pp Refer to .Xr nsswitch.conf 5 for a complete description of what each source type is. .Pp -.Ss Callback return values -The callback functions should return one of the following values -depending upon status of the lookup: -.Bl -column NS_NOTFOUND -offset indent +.Ss Method return values +The +.Vt nss_method +functions must return one of the following values depending upon status +of the lookup: +.Bl -column "RETURN VALUE" "STATUS CODE" .It Sy "Return value Status code" .It "NS_SUCCESS success" .It "NS_NOTFOUND notfound" .It "NS_UNAVAIL unavail" .It "NS_TRYAGAIN tryagain" +.It "NS_RETURN -none-" .El .Pp Refer to .Xr nsswitch.conf 5 -for a complete description of what each status code is. +for a complete description of each status code. .Pp The .Fn nsdispatch -function returns the value of the callback that caused the dispatcher to -finish, or NS_NOTFOUND otherwise. +function returns the value of the method that caused the dispatcher to +terminate, or NS_NOTFOUND otherwise. .Sh SEE ALSO .Xr hesiod 3 , .Xr stdarg 3 , -.Xr ypclnt 3 , +.Xr yp 8 , .Xr nsswitch.conf 5 .Sh HISTORY The .Fn nsdispatch function first appeared in .Fx 5.0 . It was imported from the .Nx Project, where it appeared first in .Nx 1.4 . +Support for NSS modules first appeared in +.Fx 5.1 . .Sh AUTHORS Luke Mewburn .Aq lukem@netbsd.org -wrote this freely distributable name-service switch implementation, +wrote this freely-distributable name-service switch implementation, using ideas from the .Tn ULTRIX -.Xr svc.conf 5 +"svc.conf\*(lp5\*(rp" and .Tn Solaris -.Xr nsswitch.conf 4 +"nsswitch.conf\*(lp4\*(rp" manual pages. -.Sh BUGS The +.Fx Project +added the support for threads and NSS modules, and normalized the uses +of .Fn nsdispatch -function is not thread safe. -This will be rectified in the future. -.Pp -Currently there is no support for dynamically loadable dispatcher callback -functions. -It is anticipated that this will be added in the future in the back-end -without requiring changes to code that invokes -.Fn nsdispatch . +within the standard C library. Index: head/lib/libc/net/nsdispatch.c =================================================================== --- head/lib/libc/net/nsdispatch.c (revision 113594) +++ head/lib/libc/net/nsdispatch.c (revision 113595) @@ -1,255 +1,609 @@ /* $NetBSD: nsdispatch.c,v 1.9 1999/01/25 00:16:17 lukem Exp $ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * Portions of this software were developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ #include __FBSDID("$FreeBSD$"); -#include +#include "namespace.h" #include #include -#include "namespace.h" -#include +#include +#include #include #define _NS_PRIVATE #include +#include #include #include #include +#include #include #include "un-namespace.h" +enum _nss_constants { + /* Number of elements allocated when we grow a vector */ + ELEMSPERCHUNK = 8 +}; + /* + * Global NSS data structures are mostly read-only, but we update + * them when we read or re-read the nsswitch.conf. + */ +static pthread_rwlock_t nss_lock = PTHREAD_RWLOCK_INITIALIZER; + +/* + * Runtime determination of whether we are dynamically linked or not. + */ +extern int _DYNAMIC __attribute__ ((weak)); +#define is_dynamic() (&_DYNAMIC != NULL) + +/* * default sourcelist: `files' */ const ns_src __nsdefaultsrc[] = { { NSSRC_FILES, NS_SUCCESS }, { 0 }, }; - -static int _nsmapsize = 0; +/* Database, source mappings. */ +static unsigned int _nsmapsize; static ns_dbt *_nsmap = NULL; +/* NSS modules. */ +static unsigned int _nsmodsize; +static ns_mod *_nsmod; + +/* Placeholder for builtin modules' dlopen `handle'. */ +static int __nss_builtin_handle; +static void *nss_builtin_handle = &__nss_builtin_handle; + /* - * size of dynamic array chunk for _nsmap and _nsmap[x].srclist + * Attempt to spew relatively uniform messages to syslog. */ -#define NSELEMSPERCHUNK 8 +#define nss_log(level, fmt, ...) \ + syslog((level), "NSSWITCH(%s): " fmt, __func__, __VA_ARGS__) +#define nss_log_simple(level, s) \ + syslog((level), "NSSWITCH(%s): " s, __func__) +/* + * Dynamically growable arrays are used for lists of databases, sources, + * and modules. The following `vector' interface is used to isolate the + * common operations. + */ +typedef int (*vector_comparison)(const void *, const void *); +typedef void (*vector_free_elem)(void *); +static void vector_sort(void *, unsigned int, size_t, + vector_comparison); +static void vector_free(void **, unsigned int *, size_t, + vector_free_elem); +static void *vector_ref(unsigned int, void *, unsigned int, size_t); +static void *vector_search(const void *, void *, unsigned int, size_t, + vector_comparison); +static int vector_append(const void *, void **, unsigned int *, size_t); -int _nscmp(const void *, const void *); +/* + * Internal interfaces. + */ +static int string_compare(const void *, const void *); +static int mtab_compare(const void *, const void *); +static int nss_configure(void); +static void ns_dbt_free(ns_dbt *); +static void ns_mod_free(ns_mod *); +static void ns_src_free(ns_src **, int); +static void nss_load_builtin_modules(void); +static void nss_load_module(const char *, nss_module_register_fn); +static void nss_atexit(void); +/* nsparser */ +extern FILE *_nsyyin; -int -_nscmp(a, b) - const void *a; - const void *b; + +/* + * The vector operations + */ +static void +vector_sort(void *vec, unsigned int count, size_t esize, + vector_comparison comparison) { - return (strcasecmp(((const ns_dbt *)a)->name, - ((const ns_dbt *)b)->name)); + qsort(vec, count, esize, comparison); } -void -_nsdbtaddsrc(dbt, src) - ns_dbt *dbt; - const ns_src *src; +static void * +vector_search(const void *key, void *vec, unsigned int count, size_t esize, + vector_comparison comparison) { - if ((dbt->srclistsize % NSELEMSPERCHUNK) == 0) { - dbt->srclist = (ns_src *)realloc(dbt->srclist, - (dbt->srclistsize + NSELEMSPERCHUNK) * sizeof(ns_src)); - if (dbt->srclist == NULL) - _err(1, "nsdispatch: memory allocation failure"); + return (bsearch(key, vec, count, esize, comparison)); +} + + +static int +vector_append(const void *elem, void **vec, unsigned int *count, size_t esize) +{ + void *p; + + if ((*count % ELEMSPERCHUNK) == 0) { + p = realloc(*vec, (*count + ELEMSPERCHUNK) * esize); + if (p == NULL) { + nss_log_simple(LOG_ERR, "memory allocation failure"); + return (0); + } else + *vec = p; } - memmove(&dbt->srclist[dbt->srclistsize++], src, sizeof(ns_src)); + memmove((void *)(((uintptr_t)*vec) + (*count * esize)), + elem, esize); + (*count)++; + return (1); } +static void * +vector_ref(unsigned int i, void *vec, unsigned int count, size_t esize) +{ + if (i < count) + return (void *)((uintptr_t)vec + (i * esize)); + else + return (NULL); +} + + +static void +vector_free(void **vec, unsigned int *count, size_t esize, + vector_free_elem free_elem) +{ + unsigned int i; + void *elem; + + for (i = 0; i < *count; i++) { + elem = vector_ref(i, *vec, *count, esize); + if (elem != NULL) + free_elem(elem); + } + free(*vec); + *vec = NULL; + *count = 0; +} + + + +/* + * Comparison functions for vector_search. + */ +static int +string_compare(const void *a, const void *b) +{ + return (strcasecmp(*(const char * const *)a, *(const char * const *)b)); +} + + +static int +mtab_compare(const void *a, const void *b) +{ + int cmp; + + cmp = strcmp(((const ns_mtab *)a)->name, ((const ns_mtab *)b)->name); + if (cmp != 0) + return (cmp); + else + return (strcmp(((const ns_mtab *)a)->database, + ((const ns_mtab *)b)->database)); +} + + + +/* + * NSS nsmap management. + */ void -_nsdbtdump(dbt) - const ns_dbt *dbt; +_nsdbtaddsrc(ns_dbt *dbt, const ns_src *src) { + const ns_mod *modp; + + vector_append(src, (void **)&dbt->srclist, &dbt->srclistsize, + sizeof(*src)); + modp = vector_search(&src->name, _nsmod, _nsmodsize, sizeof(*_nsmod), + string_compare); + if (modp == NULL) + nss_load_module(src->name, NULL); +} + + +#ifdef _NSS_DEBUG +void +_nsdbtdump(const ns_dbt *dbt) +{ int i; printf("%s (%d source%s):", dbt->name, dbt->srclistsize, dbt->srclistsize == 1 ? "" : "s"); - for (i = 0; i < dbt->srclistsize; i++) { + for (i = 0; i < (int)dbt->srclistsize; i++) { printf(" %s", dbt->srclist[i].name); if (!(dbt->srclist[i].flags & (NS_UNAVAIL|NS_NOTFOUND|NS_TRYAGAIN)) && (dbt->srclist[i].flags & NS_SUCCESS)) continue; printf(" ["); if (!(dbt->srclist[i].flags & NS_SUCCESS)) printf(" SUCCESS=continue"); if (dbt->srclist[i].flags & NS_UNAVAIL) printf(" UNAVAIL=return"); if (dbt->srclist[i].flags & NS_NOTFOUND) printf(" NOTFOUND=return"); if (dbt->srclist[i].flags & NS_TRYAGAIN) printf(" TRYAGAIN=return"); printf(" ]"); } printf("\n"); } +#endif -const ns_dbt * -_nsdbtget(name) - const char *name; +/* + * The first time nsdispatch is called (during a process's lifetime, + * or after nsswitch.conf has been updated), nss_configure will + * prepare global data needed by NSS. + */ +static int +nss_configure(void) { - static time_t confmod; - + static pthread_mutex_t conf_lock = PTHREAD_MUTEX_INITIALIZER; + static time_t confmod; struct stat statbuf; - ns_dbt dbt; + int result; + const char *path; - extern FILE *_nsyyin; - extern int _nsyyparse(void); +#if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT) + /* NOTE WELL: THIS IS A SECURITY HOLE. This must only be built + * for debugging purposes and MUST NEVER be used in production. + */ + path = getenv("NSSWITCH_CONF"); + if (path == NULL) +#endif + path = _PATH_NS_CONF; + if (stat(path, &statbuf) != 0) + return (0); + if (statbuf.st_mtime <= confmod) + return (0); + result = _pthread_mutex_trylock(&conf_lock); + if (result != 0) + return (0); + (void)_pthread_rwlock_unlock(&nss_lock); + result = _pthread_rwlock_wrlock(&nss_lock); + if (result != 0) + goto fin2; + _nsyyin = fopen(path, "r"); + if (_nsyyin == NULL) + goto fin; + vector_free((void **)&_nsmap, &_nsmapsize, sizeof(*_nsmap), + (vector_free_elem)ns_dbt_free); + vector_free((void **)&_nsmod, &_nsmodsize, sizeof(*_nsmod), + (vector_free_elem)ns_mod_free); + nss_load_builtin_modules(); + _nsyyparse(); + (void)fclose(_nsyyin); + vector_sort(_nsmap, _nsmapsize, sizeof(*_nsmap), string_compare); + if (confmod == 0) + (void)atexit(nss_atexit); + confmod = statbuf.st_mtime; +fin: + (void)_pthread_rwlock_unlock(&nss_lock); + result = _pthread_rwlock_rdlock(&nss_lock); +fin2: + (void)_pthread_mutex_unlock(&conf_lock); + return (result); +} - dbt.name = name; - if (confmod) { - if (stat(_PATH_NS_CONF, &statbuf) == -1) - return (NULL); - if (confmod < statbuf.st_mtime) { - int i, j; +void +_nsdbtput(const ns_dbt *dbt) +{ + unsigned int i; + ns_dbt *p; - for (i = 0; i < _nsmapsize; i++) { - for (j = 0; j < _nsmap[i].srclistsize; j++) { - if (_nsmap[i].srclist[j].name != NULL) { - /*LINTED const cast*/ - free((void *) - _nsmap[i].srclist[j].name); - } - } - if (_nsmap[i].srclist) - free(_nsmap[i].srclist); - if (_nsmap[i].name) { - /*LINTED const cast*/ - free((void *)_nsmap[i].name); - } - } - if (_nsmap) - free(_nsmap); - _nsmap = NULL; - _nsmapsize = 0; - confmod = 0; + for (i = 0; i < _nsmapsize; i++) { + p = vector_ref(i, _nsmap, _nsmapsize, sizeof(*_nsmap)); + if (string_compare(&dbt->name, &p->name) == 0) { + /* overwrite existing entry */ + if (p->srclist != NULL) + ns_src_free(&p->srclist, p->srclistsize); + memmove(p, dbt, sizeof(*dbt)); + return; } } - if (!confmod) { - if (stat(_PATH_NS_CONF, &statbuf) == -1) - return (NULL); - _nsyyin = fopen(_PATH_NS_CONF, "r"); - if (_nsyyin == NULL) - return (NULL); - _nsyyparse(); - (void)fclose(_nsyyin); - qsort(_nsmap, (size_t)_nsmapsize, sizeof(ns_dbt), _nscmp); - confmod = statbuf.st_mtime; - } - return (bsearch(&dbt, _nsmap, (size_t)_nsmapsize, sizeof(ns_dbt), - _nscmp)); + vector_append(dbt, (void **)&_nsmap, &_nsmapsize, sizeof(*_nsmap)); } -void -_nsdbtput(dbt) - const ns_dbt *dbt; +static void +ns_dbt_free(ns_dbt *dbt) { + ns_src_free(&dbt->srclist, dbt->srclistsize); +} + + +static void +ns_src_free(ns_src **src, int srclistsize) +{ int i; - for (i = 0; i < _nsmapsize; i++) { - if (_nscmp(dbt, &_nsmap[i]) == 0) { - /* overwrite existing entry */ - if (_nsmap[i].srclist != NULL) - free(_nsmap[i].srclist); - memmove(&_nsmap[i], dbt, sizeof(ns_dbt)); - return; + for (i = 0; i < srclistsize; i++) + if ((*src)[i].name != NULL) + /* This one was allocated by nslexer. You'll just + * have to trust me. + */ + free((void *)((*src)[i].name)); + free(*src); + *src = NULL; +} + + + +/* + * NSS module management. + */ +/* The built-in NSS modules are all loaded at once. */ +#define NSS_BACKEND(name, reg) \ +ns_mtab *reg(unsigned int *, nss_module_unregister_fn *); +#include "nss_backends.h" +#undef NSS_BACKEND + +static void +nss_load_builtin_modules(void) +{ +#define NSS_BACKEND(name, reg) nss_load_module(#name, reg); +#include "nss_backends.h" +#undef NSS_BACKEND +} + + +/* Load a built-in or dynamically linked module. If the `reg_fn' + * argument is non-NULL, assume a built-in module and use reg_fn to + * register it. Otherwise, search for a dynamic NSS module. + */ +static void +nss_load_module(const char *source, nss_module_register_fn reg_fn) +{ + char buf[PATH_MAX]; + ns_mod mod; + nss_module_register_fn fn; + + memset(&mod, 0, sizeof(mod)); + mod.name = strdup(source); + if (mod.name == NULL) { + nss_log_simple(LOG_ERR, "memory allocation failure"); + return; + } + if (reg_fn != NULL) { + /* The placeholder is required, as a NULL handle + * represents an invalid module. + */ + mod.handle = nss_builtin_handle; + fn = reg_fn; + } else if (!is_dynamic()) + goto fin; + else { + if (snprintf(buf, sizeof(buf), "nss_%s.so.%d", mod.name, + NSS_MODULE_INTERFACE_VERSION) >= (int)sizeof(buf)) + goto fin; + mod.handle = dlopen(buf, RTLD_LOCAL|RTLD_LAZY); + if (mod.handle == NULL) { +#ifdef _NSS_DEBUG + /* This gets pretty annoying since the built-in + * sources aren't modules yet. + */ + nss_log(LOG_DEBUG, "%s, %s", mod.name, dlerror()); +#endif + goto fin; } + fn = (nss_module_register_fn)dlfunc(mod.handle, + "nss_module_register"); + if (fn == NULL) { + (void)dlclose(mod.handle); + mod.handle = NULL; + nss_log(LOG_ERR, "%s, %s", mod.name, dlerror()); + goto fin; + } } + mod.mtab = fn(mod.name, &mod.mtabsize, &mod.unregister); + if (mod.mtab == NULL || mod.mtabsize == 0) { + if (mod.handle != nss_builtin_handle) + (void)dlclose(mod.handle); + mod.handle = NULL; + nss_log(LOG_ERR, "%s, registration failed", mod.name); + goto fin; + } + if (mod.mtabsize > 1) + qsort(mod.mtab, mod.mtabsize, sizeof(mod.mtab[0]), + mtab_compare); +fin: + vector_append(&mod, (void **)&_nsmod, &_nsmodsize, sizeof(*_nsmod)); + vector_sort(_nsmod, _nsmodsize, sizeof(*_nsmod), string_compare); +} - if ((_nsmapsize % NSELEMSPERCHUNK) == 0) { - _nsmap = (ns_dbt *)realloc(_nsmap, - (_nsmapsize + NSELEMSPERCHUNK) * sizeof(ns_dbt)); - if (_nsmap == NULL) - _err(1, "nsdispatch: memory allocation failure"); + + +static void +ns_mod_free(ns_mod *mod) +{ + + free(mod->name); + if (mod->handle == NULL) + return; + if (mod->unregister != NULL) + mod->unregister(mod->mtab, mod->mtabsize); + if (mod->handle != nss_builtin_handle) + (void)dlclose(mod->handle); +} + + + +/* + * Cleanup + */ +static void +nss_atexit(void) +{ + (void)_pthread_rwlock_wrlock(&nss_lock); + vector_free((void **)&_nsmap, &_nsmapsize, sizeof(*_nsmap), + (vector_free_elem)ns_dbt_free); + vector_free((void **)&_nsmod, &_nsmodsize, sizeof(*_nsmod), + (vector_free_elem)ns_mod_free); + (void)_pthread_rwlock_unlock(&nss_lock); +} + + + +/* + * Finally, the actual implementation. + */ +static nss_method +nss_method_lookup(const char *source, const char *database, + const char *method, const ns_dtab disp_tab[], void **mdata) +{ + ns_mod *mod; + ns_mtab *match, key; + int i; + + if (disp_tab != NULL) + for (i = 0; disp_tab[i].src != NULL; i++) + if (strcasecmp(source, disp_tab[i].src) == 0) { + *mdata = disp_tab[i].mdata; + return (disp_tab[i].method); + } + mod = vector_search(&source, _nsmod, _nsmodsize, sizeof(*_nsmod), + string_compare); + if (mod != NULL && mod->handle != NULL) { + key.database = database; + key.name = method; + match = bsearch(&key, mod->mtab, mod->mtabsize, + sizeof(mod->mtab[0]), mtab_compare); + if (match != NULL) { + *mdata = match->mdata; + return (match->method); + } } - memmove(&_nsmap[_nsmapsize++], dbt, sizeof(ns_dbt)); + nss_log(LOG_DEBUG, "%s, %s, %s, not found", source, database, method); + *mdata = NULL; + return (NULL); } +__weak_reference(_nsdispatch, nsdispatch); + int -nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, - const char *method, const ns_src defaults[], ...) +_nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, + const char *method_name, const ns_src defaults[], ...) { va_list ap; - int i, curdisp, result; const ns_dbt *dbt; const ns_src *srclist; - int srclistsize; + nss_method method; + void *mdata; + int serrno, i, result, srclistsize; - dbt = _nsdbtget(database); + serrno = errno; + result = _pthread_rwlock_rdlock(&nss_lock); + if (result != 0) { + result = NS_UNAVAIL; + goto fin; + } + result = nss_configure(); + if (result != 0) { + result = NS_UNAVAIL; + goto fin; + } + dbt = vector_search(&database, _nsmap, _nsmapsize, sizeof(*_nsmap), + string_compare); if (dbt != NULL) { srclist = dbt->srclist; srclistsize = dbt->srclistsize; } else { srclist = defaults; srclistsize = 0; while (srclist[srclistsize].name != NULL) srclistsize++; } - result = 0; - for (i = 0; i < srclistsize; i++) { - for (curdisp = 0; disp_tab[curdisp].src != NULL; curdisp++) - if (strcasecmp(disp_tab[curdisp].src, - srclist[i].name) == 0) - break; - result = 0; - if (disp_tab[curdisp].callback) { + result = NS_NOTFOUND; + method = nss_method_lookup(srclist[i].name, database, + method_name, disp_tab, &mdata); + if (method != NULL) { va_start(ap, defaults); - result = disp_tab[curdisp].callback(retval, - disp_tab[curdisp].cb_data, ap); + result = method(retval, mdata, ap); va_end(ap); - if (result & srclist[i].flags) { + if (result & (srclist[i].flags)) break; - } } } - return (result ? result : NS_NOTFOUND); + (void)_pthread_rwlock_unlock(&nss_lock); +fin: + errno = serrno; + return (result); } Index: head/lib/libc/net/nslexer.l =================================================================== --- head/lib/libc/net/nslexer.l (revision 113594) +++ head/lib/libc/net/nslexer.l (revision 113595) @@ -1,117 +1,119 @@ %{ /* $NetBSD: nslexer.l,v 1.3 1999/01/25 00:16:17 lukem Exp $ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #if defined(LIBC_SCCS) && !defined(lint) static char *rcsid = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include -#include #define _NS_PRIVATE #include #include +#include #include "un-namespace.h" #include "nsparser.h" #define YY_NO_UNPUT %} %option yylineno BLANK [ \t] CR \n STRING [a-zA-Z][a-zA-Z0-9_]* %% {BLANK}+ ; /* skip whitespace */ #.* ; /* skip comments */ \\{CR} ; /* allow continuation */ {CR} return NL; [sS][uU][cC][cC][eE][sS][sS] return SUCCESS; [uU][nN][aA][vV][aA][iI][lL] return UNAVAIL; [nN][oO][tT][fF][oO][uU][nN][dD] return NOTFOUND; [tT][rR][yY][aA][gG][aA][iI][nN] return TRYAGAIN; [rR][eE][tT][uU][rR][nN] return RETURN; [cC][oO][nN][tT][iI][nN][uU][eE] return CONTINUE; {STRING} { char *p; int i; - if ((p = strdup(yytext)) == NULL) - _err(1, - "nsdispatch: memory allocation failure"); - + if ((p = strdup(yytext)) == NULL) { + syslog(LOG_ERR, + "NSSWITCH(nslexer): memory allocation failure"); + return ERRORTOKEN; + } for (i = 0; i < strlen(p); i++) { if (isupper((unsigned char)p[i])) p[i] = tolower((unsigned char)p[i]); } _nsyylval.str = p; return STRING; } . return yytext[0]; %% #undef _nsyywrap int _nsyywrap() { return 1; } /* _nsyywrap */ void _nsyyerror(msg) const char *msg; { - warnx("%s line %d: %s at '%s'", _PATH_NS_CONF, yylineno, msg, yytext); + syslog(LOG_ERR, "NSSWITCH(nslexer): %s line %d: %s at '%s'", + _PATH_NS_CONF, yylineno, msg, yytext); } /* _nsyyerror */ Index: head/lib/libc/net/nsparser.y =================================================================== --- head/lib/libc/net/nsparser.y (revision 113594) +++ head/lib/libc/net/nsparser.y (revision 113595) @@ -1,179 +1,178 @@ %{ /* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Luke Mewburn. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the NetBSD * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include -#if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = - "$FreeBSD$"; -#endif /* LIBC_SCCS and not lint */ +__FBSDID("$FreeBSD$"); -#include +#include "namespace.h" #define _NS_PRIVATE #include #include #include +#include +#include "un-namespace.h" - static void _nsaddsrctomap(const char *); static ns_dbt curdbt; static ns_src cursrc; %} %union { char *str; int mapval; } %token NL %token SUCCESS UNAVAIL NOTFOUND TRYAGAIN %token RETURN CONTINUE +%token ERRORTOKEN %token STRING %type Status Action %% File : /* empty */ | Lines ; Lines : Entry | Lines Entry ; Entry : NL | Database ':' NL | Database ':' Srclist NL { _nsdbtput(&curdbt); } | error NL { yyerrok; } ; Database : STRING { curdbt.name = yylval.str; curdbt.srclist = NULL; curdbt.srclistsize = 0; } ; Srclist : Item | Srclist Item ; Item : STRING { - cursrc.flags = NS_SUCCESS; + cursrc.flags = NS_TERMINATE; _nsaddsrctomap($1); } | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' { _nsaddsrctomap($1); } ; Criteria : Criterion | Criteria Criterion ; Criterion : Status '=' Action { - if ($3) /* if action == RETURN set RETURN bit */ + if ($3) /* if action == RETURN set RETURN bit */ cursrc.flags |= $1; - else /* else unset it */ + else /* else unset it */ cursrc.flags &= ~$1; } ; Status : SUCCESS { $$ = NS_SUCCESS; } | UNAVAIL { $$ = NS_UNAVAIL; } | NOTFOUND { $$ = NS_NOTFOUND; } | TRYAGAIN { $$ = NS_TRYAGAIN; } ; Action - : RETURN { $$ = 1L; } - | CONTINUE { $$ = 0L; } + : RETURN { $$ = NS_ACTION_RETURN; } + | CONTINUE { $$ = NS_ACTION_CONTINUE; } ; %% static void _nsaddsrctomap(elem) const char *elem; { int i, lineno; extern int _nsyylineno; extern char * _nsyytext; lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); if (curdbt.srclistsize > 0) { if ((strcasecmp(elem, NSSRC_COMPAT) == 0) || (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { - /* XXX: syslog the following */ - warnx("%s line %d: 'compat' used with other sources", + syslog(LOG_ERR, + "NSSWITCH(nsparser): %s line %d: 'compat' used with other sources", _PATH_NS_CONF, lineno); return; } } for (i = 0; i < curdbt.srclistsize; i++) { if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { - /* XXX: syslog the following */ - warnx("%s line %d: duplicate source '%s'", + syslog(LOG_ERR, + "NSSWITCH(nsparser): %s line %d: duplicate source '%s'", _PATH_NS_CONF, lineno, elem); return; } } cursrc.name = elem; _nsdbtaddsrc(&curdbt, &cursrc); } Index: head/lib/libc/net/nss_backends.h =================================================================== --- head/lib/libc/net/nss_backends.h (nonexistent) +++ head/lib/libc/net/nss_backends.h (revision 113595) @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +/* + * Eventually, the implementations of existing built-in NSS functions + * may be moved into NSS modules and live here. + */ +#if 0 +NSS_BACKEND( files, _files_nss_module_register ) +NSS_BACKEND( dns, _dns_nss_module_register ) +NSS_BACKEND( nis, _nis_nss_module_register ) +NSS_BACKEND( compat, _compat_nss_module_register ) +#endif Property changes on: head/lib/libc/net/nss_backends.h ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Index: head/lib/libc/net/nss_compat.c =================================================================== --- head/lib/libc/net/nss_compat.c (nonexistent) +++ head/lib/libc/net/nss_compat.c (revision 113595) @@ -0,0 +1,270 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Compatibility shims for the GNU C Library-style nsswitch interface. + */ +#include +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + + +struct group; +struct passwd; + +static int terminator; + +#define DECLARE_TERMINATOR(x) \ +static pthread_key_t _term_key_##x; \ +static void \ +_term_create_##x(void) \ +{ \ + (void)_pthread_key_create(&_term_key_##x, NULL); \ +} \ +static void *_term_main_##x; \ +static pthread_once_t _term_once_##x = PTHREAD_ONCE_INIT + +#define SET_TERMINATOR(x, y) \ +do { \ + if (_pthread_main_np()) \ + _term_main_##x = (y); \ + else { \ + (void)_pthread_once(&_term_once_##x, _term_create_##x); \ + (void)_pthread_setspecific(_term_key_##x, y); \ + } \ +} while (0) + +#define CHECK_TERMINATOR(x) \ +(_pthread_main_np() ? \ + (_term_main_##x) : \ + ((void)_pthread_once(&_term_once_##x, _term_create_##x), \ + _pthread_getspecific(_term_key_##x))) + + + +DECLARE_TERMINATOR(group); + + +int +__nss_compat_getgrnam_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(const char *, struct group *, char *, size_t, int *); + const char *name; + struct group *grp; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + fn = mdata; + name = va_arg(ap, const char *); + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(name, grp, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct group **)retval = grp; + return (__nss_compat_result(status)); +} + + +int +__nss_compat_getgrgid_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(gid_t, struct group *, char *, size_t, int *); + gid_t gid; + struct group *grp; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + fn = mdata; + gid = va_arg(ap, gid_t); + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(gid, grp, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct group **)retval = grp; + return (__nss_compat_result(status)); +} + + +int +__nss_compat_getgrent_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(struct group *, char *, size_t, int *); + struct group *grp; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + if (CHECK_TERMINATOR(group)) + return (NS_NOTFOUND); + fn = mdata; + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(grp, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct group **)retval = grp; + else + SET_TERMINATOR(group, &terminator); + return (__nss_compat_result(status)); +} + + +int +__nss_compat_setgrent(void *retval, void *mdata, va_list ap) +{ + + SET_TERMINATOR(group, NULL); + ((int (*)(void))mdata)(); + return (NS_UNAVAIL); +} + + +int +__nss_compat_endgrent(void *retval, void *mdata, va_list ap) +{ + + SET_TERMINATOR(group, NULL); + ((int (*)(void))mdata)(); + return (NS_UNAVAIL); +} + + + +DECLARE_TERMINATOR(passwd); + + +int +__nss_compat_getpwnam_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(const char *, struct passwd *, char *, size_t, int *); + const char *name; + struct passwd *pwd; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + fn = mdata; + name = va_arg(ap, const char *); + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(name, pwd, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct passwd **)retval = pwd; + return (__nss_compat_result(status)); +} + + +int +__nss_compat_getpwuid_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(uid_t, struct passwd *, char *, size_t, int *); + uid_t uid; + struct passwd *pwd; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + fn = mdata; + uid = va_arg(ap, uid_t); + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(uid, pwd, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct passwd **)retval = pwd; + return (__nss_compat_result(status)); +} + + +int +__nss_compat_getpwent_r(void *retval, void *mdata, va_list ap) +{ + int (*fn)(struct passwd *, char *, size_t, int *); + struct passwd *pwd; + char *buffer; + int *errnop; + size_t bufsize; + enum nss_status status; + + if (CHECK_TERMINATOR(passwd)) + return (NS_NOTFOUND); + fn = mdata; + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + status = fn(pwd, buffer, bufsize, errnop); + if (status == NS_SUCCESS) + *(struct passwd **)retval = pwd; + else + SET_TERMINATOR(passwd, &terminator); + return (__nss_compat_result(status)); +} + + +int +__nss_compat_setpwent(void *retval, void *mdata, va_list ap) +{ + + SET_TERMINATOR(passwd, NULL); + ((int (*)(void))mdata)(); + return (NS_UNAVAIL); +} + + +int +__nss_compat_endpwent(void *retval, void *mdata, va_list ap) +{ + + SET_TERMINATOR(passwd, NULL); + ((int (*)(void))mdata)(); + return (NS_UNAVAIL); +} Property changes on: head/lib/libc/net/nss_compat.c ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property