xref: /titanic_50/usr/src/lib/nsswitch/files/common/files_common.h (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5004388ebScasper  * Common Development and Distribution License (the "License").
6004388ebScasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21e8031f0aSraf 
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25e8031f0aSraf  */
26e8031f0aSraf 
27e8031f0aSraf /*
287c478bd9Sstevel@tonic-gate  * Common code and structures used by name-service-switch "files" backends.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _FILES_COMMON_H
327c478bd9Sstevel@tonic-gate #define	_FILES_COMMON_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <nss_common.h>
357c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
367c478bd9Sstevel@tonic-gate #include <stdio.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate typedef struct files_backend *files_backend_ptr_t;
437c478bd9Sstevel@tonic-gate typedef nss_status_t	(*files_backend_op_t)(files_backend_ptr_t, void *);
447c478bd9Sstevel@tonic-gate 
45cb5caa98Sdjl typedef uint_t (*files_hash_func)(nss_XbyY_args_t *, int, const char *, int);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate typedef struct files_hashent {
487c478bd9Sstevel@tonic-gate 	struct files_hashent	*h_first;
497c478bd9Sstevel@tonic-gate 	struct files_hashent	*h_next;
50cb5caa98Sdjl 	uint_t			h_hash;
517c478bd9Sstevel@tonic-gate } files_hashent_t;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef struct {
547c478bd9Sstevel@tonic-gate 	char			*l_start;
557c478bd9Sstevel@tonic-gate 	int			l_len;
567c478bd9Sstevel@tonic-gate } files_linetab_t;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef struct {
597c478bd9Sstevel@tonic-gate 	mutex_t		fh_lock;
607c478bd9Sstevel@tonic-gate 	int		fh_resultsize;
617c478bd9Sstevel@tonic-gate 	int		fh_bufsize;
627c478bd9Sstevel@tonic-gate 	int		fh_nhtab;
637c478bd9Sstevel@tonic-gate 	files_hash_func	*fh_hash_func;
647c478bd9Sstevel@tonic-gate 	int		fh_refcnt;
657c478bd9Sstevel@tonic-gate 	int		fh_size;
667c478bd9Sstevel@tonic-gate 	timestruc_t	fh_mtime;
677c478bd9Sstevel@tonic-gate 	char		*fh_file_start;
687c478bd9Sstevel@tonic-gate 	char		*fh_file_end;
697c478bd9Sstevel@tonic-gate 	files_linetab_t	*fh_line;
707c478bd9Sstevel@tonic-gate 	files_hashent_t	*fh_table;
717c478bd9Sstevel@tonic-gate } files_hash_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate struct files_backend {
747c478bd9Sstevel@tonic-gate 	files_backend_op_t	*ops;
757c478bd9Sstevel@tonic-gate 	int			n_ops;
767c478bd9Sstevel@tonic-gate 	const char		*filename;
77004388ebScasper 	FILE			*f;
787c478bd9Sstevel@tonic-gate 	int			minbuf;
797c478bd9Sstevel@tonic-gate 	char			*buf;
807c478bd9Sstevel@tonic-gate 	files_hash_t		*hashinfo;
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * Iterator function for _nss_files_do_all(), which probably calls yp_all().
857c478bd9Sstevel@tonic-gate  *   NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now",
867c478bd9Sstevel@tonic-gate  *   other values don't make much sense.  In other words we're abusing
877c478bd9Sstevel@tonic-gate  *   (overloading) the meaning of nss_status_t, but hey...
887c478bd9Sstevel@tonic-gate  * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the
897c478bd9Sstevel@tonic-gate  *   generic work for nss_XbyY_args_t backends (calls cstr2ent etc).
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate typedef nss_status_t	(*files_do_all_func_t)(const char *, int, void *args);
92cb5caa98Sdjl typedef int		(*files_XY_check_func)(nss_XbyY_args_t *,
93cb5caa98Sdjl 						const char *, int);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #if defined(__STDC__)
967c478bd9Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr(files_backend_op_t	*ops,
977c478bd9Sstevel@tonic-gate 					int			n_ops,
987c478bd9Sstevel@tonic-gate 					const char		*filename,
997c478bd9Sstevel@tonic-gate 					int			min_bufsize,
1007c478bd9Sstevel@tonic-gate 					files_hash_t		*fhp);
1017c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_destr(files_backend_ptr_t, void *dummy);
1027c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_setent(files_backend_ptr_t, void *dummy);
1037c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_endent(files_backend_ptr_t, void *dummy);
1047c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid(files_backend_ptr_t, void *);
1057c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb(files_backend_ptr_t, void *);
1067c478bd9Sstevel@tonic-gate extern nss_status_t 	_nss_files_do_all(files_backend_ptr_t,
1077c478bd9Sstevel@tonic-gate 					void			*func_priv,
1087c478bd9Sstevel@tonic-gate 					const char		*filter,
1097c478bd9Sstevel@tonic-gate 					files_do_all_func_t	func);
1107c478bd9Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_all(files_backend_ptr_t	be,
1117c478bd9Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
1127c478bd9Sstevel@tonic-gate 					int 			netdb,
1137c478bd9Sstevel@tonic-gate 					const char		*filter,
1147c478bd9Sstevel@tonic-gate 					files_XY_check_func	check);
1157c478bd9Sstevel@tonic-gate extern nss_status_t 	_nss_files_XY_hash(files_backend_ptr_t	be,
1167c478bd9Sstevel@tonic-gate 					nss_XbyY_args_t		*args,
1177c478bd9Sstevel@tonic-gate 					int 			netdb,
1187c478bd9Sstevel@tonic-gate 					files_hash_t		*fhp,
1197c478bd9Sstevel@tonic-gate 					int			hashop,
1207c478bd9Sstevel@tonic-gate 					files_XY_check_func	check);
121004388ebScasper int _nss_files_read_line(FILE *f, char *buffer, int	buflen);
1227c478bd9Sstevel@tonic-gate #else
1237c478bd9Sstevel@tonic-gate extern nss_backend_t	*_nss_files_constr();
1247c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_destr();
1257c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_setent();
1267c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_endent();
1277c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_rigid();
1287c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_getent_netdb();
1297c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_do_all();
1307c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_all();
1317c478bd9Sstevel@tonic-gate extern nss_status_t	_nss_files_XY_hash();
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
134cb5caa98Sdjl int	_nss_files_check_name_aliases(nss_XbyY_args_t *, const char *, int);
135cb5caa98Sdjl int	_nss_files_check_name_colon(nss_XbyY_args_t *, const char *, int);
136cb5caa98Sdjl 
137*2b4a7802SBaban Kenkre /* passwd and group validation functions */
138*2b4a7802SBaban Kenkre extern int	validate_group_ids(char *line, int *linelenp, int buflen,
139*2b4a7802SBaban Kenkre 			int extra_chars, files_XY_check_func check);
140*2b4a7802SBaban Kenkre extern int	validate_passwd_ids(char *line, int *linelenp, int buflen,
141*2b4a7802SBaban Kenkre 			int extra_chars);
142*2b4a7802SBaban Kenkre 
1437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate #endif
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #endif /* _FILES_COMMON_H */
148