10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51914Scasper  * Common Development and Distribution License (the "License").
61914Scasper  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
251219Sraf  */
261219Sraf 
271219Sraf /*
280Sstevel@tonic-gate  * Common code and structures used by name-service-switch "files" backends.
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifndef _FILES_COMMON_H
320Sstevel@tonic-gate #define	_FILES_COMMON_H
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <nss_common.h>
370Sstevel@tonic-gate #include <nss_dbdefs.h>
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate typedef struct files_backend *files_backend_ptr_t;
450Sstevel@tonic-gate typedef nss_status_t	(*files_backend_op_t)(files_backend_ptr_t, void *);
460Sstevel@tonic-gate 
472830Sdjl typedef uint_t (*files_hash_func)(nss_XbyY_args_t *, int, const char *, int);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate typedef struct files_hashent {
500Sstevel@tonic-gate 	struct files_hashent	*h_first;
510Sstevel@tonic-gate 	struct files_hashent	*h_next;
522830Sdjl 	uint_t			h_hash;
530Sstevel@tonic-gate } files_hashent_t;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate typedef struct {
560Sstevel@tonic-gate 	char			*l_start;
570Sstevel@tonic-gate 	int			l_len;
580Sstevel@tonic-gate } files_linetab_t;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef struct {
610Sstevel@tonic-gate 	mutex_t		fh_lock;
620Sstevel@tonic-gate 	int		fh_resultsize;
630Sstevel@tonic-gate 	int		fh_bufsize;
640Sstevel@tonic-gate 	int		fh_nhtab;
650Sstevel@tonic-gate 	files_hash_func	*fh_hash_func;
660Sstevel@tonic-gate 	int		fh_refcnt;
670Sstevel@tonic-gate 	int		fh_size;
680Sstevel@tonic-gate 	timestruc_t	fh_mtime;
690Sstevel@tonic-gate 	char		*fh_file_start;
700Sstevel@tonic-gate 	char		*fh_file_end;
710Sstevel@tonic-gate 	files_linetab_t	*fh_line;
720Sstevel@tonic-gate 	files_hashent_t	*fh_table;
730Sstevel@tonic-gate } files_hash_t;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate struct files_backend {
760Sstevel@tonic-gate 	files_backend_op_t	*ops;
770Sstevel@tonic-gate 	int			n_ops;
780Sstevel@tonic-gate 	const char		*filename;
791914Scasper 	FILE			*f;
800Sstevel@tonic-gate 	int			minbuf;
810Sstevel@tonic-gate 	char			*buf;
820Sstevel@tonic-gate 	files_hash_t		*hashinfo;
830Sstevel@tonic-gate };
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
870Sstevel@tonic-gate  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
880Sstevel@tonic-gate  *   other values don't make much sense.  In other words we're abusing
890Sstevel@tonic-gate  *   (overloading) the meaning of nss_status_t, but hey...
900Sstevel@tonic-gate  * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the
910Sstevel@tonic-gate  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
942830Sdjl typedef int		(*files_XY_check_func)(nss_XbyY_args_t *,
952830Sdjl 						const char *, int);
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #if defined(__STDC__)
980Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr(files_backend_op_t	*ops,
990Sstevel@tonic-gate 					int			n_ops,
1000Sstevel@tonic-gate 					const char		*filename,
1010Sstevel@tonic-gate 					int			min_bufsize,
1020Sstevel@tonic-gate 					files_hash_t		*fhp);
1031914Scasper extern nss_status_t	_nss_files_destr(files_backend_ptr_t, void *dummy);
1040Sstevel@tonic-gate extern nss_status_t	_nss_files_setent(files_backend_ptr_t, void *dummy);
1050Sstevel@tonic-gate extern nss_status_t	_nss_files_endent(files_backend_ptr_t, void *dummy);
1060Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid(files_backend_ptr_t, void *);
1070Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb(files_backend_ptr_t, void *);
1080Sstevel@tonic-gate extern nss_status_t 	_nss_files_do_all(files_backend_ptr_t,
1090Sstevel@tonic-gate 					void			*func_priv,
1100Sstevel@tonic-gate 					const char		*filter,
1110Sstevel@tonic-gate 					files_do_all_func_t	func);
1120Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_all(files_backend_ptr_t	be,
1130Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
1140Sstevel@tonic-gate 					int 			netdb,
1150Sstevel@tonic-gate 					const char		*filter,
1160Sstevel@tonic-gate 					files_XY_check_func	check);
1170Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_hash(files_backend_ptr_t	be,
1180Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
1190Sstevel@tonic-gate 					int 			netdb,
1200Sstevel@tonic-gate 					files_hash_t		*fhp,
1210Sstevel@tonic-gate 					int			hashop,
1220Sstevel@tonic-gate 					files_XY_check_func	check);
1231914Scasper int _nss_files_read_line(FILE *f, char *buffer, int	buflen);
1240Sstevel@tonic-gate #else
1250Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr();
1261914Scasper extern nss_status_t	_nss_files_destr();
1270Sstevel@tonic-gate extern nss_status_t	_nss_files_setent();
1280Sstevel@tonic-gate extern nss_status_t	_nss_files_endent();
1290Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid();
1300Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb();
1310Sstevel@tonic-gate extern nss_status_t	_nss_files_do_all();
1320Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_all();
1330Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_hash();
1340Sstevel@tonic-gate #endif
1350Sstevel@tonic-gate 
1362830Sdjl int	_nss_files_check_name_aliases(nss_XbyY_args_t *, const char *, int);
1372830Sdjl int	_nss_files_check_name_colon(nss_XbyY_args_t *, const char *, int);
1382830Sdjl 
1390Sstevel@tonic-gate #ifdef	__cplusplus
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate #endif
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate #endif /* _FILES_COMMON_H */
144