4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Default backend-finder(s) for the name-service-switch routines.
31 * At present there is a single finder that uses dlopen() to do its thing.
33 * === Could also do a finder that includes db-name in filename
34 * === and one that does dlopen(0) to check in the executable
37 /* Allow our finder(s) to be overridden by user-supplied ones */
39 #pragma weak _nss_default_finders = nss_default_finders
43 #include <nss_common.h>
50 /* === ? move these constants to a public header file ? */
51 static const int dlopen_version
= 1;
52 #ifndef NSS_DLOPEN_FORMAT
53 #define NSS_DLOPEN_FORMAT "nss_%s.so.%d"
55 #ifndef NSS_DLSYM_FORMAT
56 #define NSS_DLSYM_FORMAT "_nss_%s_%s_constr"
58 static const char dlopen_format
[] = NSS_DLOPEN_FORMAT
;
59 static const char dlsym_format
[] = NSS_DLSYM_FORMAT
;
60 static const size_t format_maxlen
= sizeof (dlsym_format
) - 4;
63 static nss_backend_constr_t
64 SO_per_src_lookup(void *dummy
, const char *db_name
, const char *src_name
,
71 nss_backend_constr_t res
= 0;
73 len
= format_maxlen
+ strlen(db_name
) + strlen(src_name
);
75 (void) sprintf(name
, dlopen_format
, src_name
, dlopen_version
);
76 if ((dlhandle
= dlopen(name
, RTLD_LAZY
)) != 0) {
77 (void) sprintf(name
, dlsym_format
, src_name
, db_name
);
78 if ((sym
= dlsym(dlhandle
, name
)) == 0) {
79 (void) dlclose(dlhandle
);
81 *delete_privp
= dlhandle
;
82 res
= (nss_backend_constr_t
)sym
;
90 SO_per_src_delete(void *delete_priv
, nss_backend_constr_t dummy
)
92 (void) dlclose(delete_priv
);
95 static nss_backend_finder_t SO_per_src
= {
102 nss_backend_finder_t
*nss_default_finders
= &SO_per_src
;