1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 /* 29 * Common code and structures used by name-service-switch "files" backends. 30 */ 31 32 #ifndef _FILES_COMMON_H 33 #define _FILES_COMMON_H 34 35 #pragma ident "%Z%%M% %I% %E% SMI" 36 37 #include "c_synonyms.h" 38 #include <nss_common.h> 39 #include <nss_dbdefs.h> 40 #include <stdio.h> 41 42 #include "../../../libnsl/include/nsl_stdio_prv.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 typedef struct files_backend *files_backend_ptr_t; 49 typedef nss_status_t (*files_backend_op_t)(files_backend_ptr_t, void *); 50 51 typedef u_int (*files_hash_func)(nss_XbyY_args_t *, int); 52 53 typedef struct files_hashent { 54 struct files_hashent *h_first; 55 struct files_hashent *h_next; 56 u_int h_hash; 57 } files_hashent_t; 58 59 typedef struct { 60 char *l_start; 61 int l_len; 62 } files_linetab_t; 63 64 typedef struct { 65 mutex_t fh_lock; 66 int fh_resultsize; 67 int fh_bufsize; 68 int fh_nhtab; 69 files_hash_func *fh_hash_func; 70 int fh_refcnt; 71 int fh_size; 72 timestruc_t fh_mtime; 73 char *fh_file_start; 74 char *fh_file_end; 75 files_linetab_t *fh_line; 76 files_hashent_t *fh_table; 77 } files_hash_t; 78 79 struct files_backend { 80 files_backend_op_t *ops; 81 int n_ops; 82 const char *filename; 83 __NSL_FILE *f; 84 int minbuf; 85 char *buf; 86 files_hash_t *hashinfo; 87 }; 88 89 /* 90 * Iterator function for _nss_files_do_all(), which probably calls yp_all(). 91 * NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now", 92 * other values don't make much sense. In other words we're abusing 93 * (overloading) the meaning of nss_status_t, but hey... 94 * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the 95 * generic work for nss_XbyY_args_t backends (calls cstr2ent etc). 96 */ 97 typedef nss_status_t (*files_do_all_func_t)(const char *, int, void *args); 98 typedef int (*files_XY_check_func)(nss_XbyY_args_t *); 99 100 #if defined(__STDC__) 101 extern nss_backend_t *_nss_files_constr(files_backend_op_t *ops, 102 int n_ops, 103 const char *filename, 104 int min_bufsize, 105 files_hash_t *fhp); 106 extern nss_status_t _nss_files_destr (files_backend_ptr_t, void *dummy); 107 extern nss_status_t _nss_files_setent(files_backend_ptr_t, void *dummy); 108 extern nss_status_t _nss_files_endent(files_backend_ptr_t, void *dummy); 109 extern nss_status_t _nss_files_getent_rigid(files_backend_ptr_t, void *); 110 extern nss_status_t _nss_files_getent_netdb(files_backend_ptr_t, void *); 111 extern nss_status_t _nss_files_do_all(files_backend_ptr_t, 112 void *func_priv, 113 const char *filter, 114 files_do_all_func_t func); 115 extern nss_status_t _nss_files_XY_all(files_backend_ptr_t be, 116 nss_XbyY_args_t *args, 117 int netdb, 118 const char *filter, 119 files_XY_check_func check); 120 extern nss_status_t _nss_files_XY_hash(files_backend_ptr_t be, 121 nss_XbyY_args_t *args, 122 int netdb, 123 files_hash_t *fhp, 124 int hashop, 125 files_XY_check_func check); 126 int _nss_files_read_line(__NSL_FILE *f, char *buffer, int buflen); 127 #else 128 extern nss_backend_t *_nss_files_constr(); 129 extern nss_status_t _nss_files_destr (); 130 extern nss_status_t _nss_files_setent(); 131 extern nss_status_t _nss_files_endent(); 132 extern nss_status_t _nss_files_getent_rigid(); 133 extern nss_status_t _nss_files_getent_netdb(); 134 extern nss_status_t _nss_files_do_all(); 135 extern nss_status_t _nss_files_XY_all(); 136 extern nss_status_t _nss_files_XY_hash(); 137 #endif 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* _FILES_COMMON_H */ 144