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 /* 236812Sraf * 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 #include <nss_common.h> 350Sstevel@tonic-gate #include <nss_dbdefs.h> 360Sstevel@tonic-gate #include <stdio.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate typedef struct files_backend *files_backend_ptr_t; 430Sstevel@tonic-gate typedef nss_status_t (*files_backend_op_t)(files_backend_ptr_t, void *); 440Sstevel@tonic-gate 452830Sdjl typedef uint_t (*files_hash_func)(nss_XbyY_args_t *, int, const char *, int); 460Sstevel@tonic-gate 470Sstevel@tonic-gate typedef struct files_hashent { 480Sstevel@tonic-gate struct files_hashent *h_first; 490Sstevel@tonic-gate struct files_hashent *h_next; 502830Sdjl uint_t h_hash; 510Sstevel@tonic-gate } files_hashent_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate typedef struct { 540Sstevel@tonic-gate char *l_start; 550Sstevel@tonic-gate int l_len; 560Sstevel@tonic-gate } files_linetab_t; 570Sstevel@tonic-gate 580Sstevel@tonic-gate typedef struct { 590Sstevel@tonic-gate mutex_t fh_lock; 600Sstevel@tonic-gate int fh_resultsize; 610Sstevel@tonic-gate int fh_bufsize; 620Sstevel@tonic-gate int fh_nhtab; 630Sstevel@tonic-gate files_hash_func *fh_hash_func; 640Sstevel@tonic-gate int fh_refcnt; 650Sstevel@tonic-gate int fh_size; 660Sstevel@tonic-gate timestruc_t fh_mtime; 670Sstevel@tonic-gate char *fh_file_start; 680Sstevel@tonic-gate char *fh_file_end; 690Sstevel@tonic-gate files_linetab_t *fh_line; 700Sstevel@tonic-gate files_hashent_t *fh_table; 710Sstevel@tonic-gate } files_hash_t; 720Sstevel@tonic-gate 730Sstevel@tonic-gate struct files_backend { 740Sstevel@tonic-gate files_backend_op_t *ops; 750Sstevel@tonic-gate int n_ops; 760Sstevel@tonic-gate const char *filename; 771914Scasper FILE *f; 780Sstevel@tonic-gate int minbuf; 790Sstevel@tonic-gate char *buf; 800Sstevel@tonic-gate files_hash_t *hashinfo; 810Sstevel@tonic-gate }; 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* 840Sstevel@tonic-gate * Iterator function for _nss_files_do_all(), which probably calls yp_all(). 850Sstevel@tonic-gate * NSS_NOTFOUND means "keep enumerating", NSS_SUCCESS means"return now", 860Sstevel@tonic-gate * other values don't make much sense. In other words we're abusing 870Sstevel@tonic-gate * (overloading) the meaning of nss_status_t, but hey... 880Sstevel@tonic-gate * _nss_files_XY_all() is a wrapper around _nss_files_do_all() that does the 890Sstevel@tonic-gate * generic work for nss_XbyY_args_t backends (calls cstr2ent etc). 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate typedef nss_status_t (*files_do_all_func_t)(const char *, int, void *args); 922830Sdjl typedef int (*files_XY_check_func)(nss_XbyY_args_t *, 932830Sdjl const char *, int); 940Sstevel@tonic-gate 950Sstevel@tonic-gate #if defined(__STDC__) 960Sstevel@tonic-gate extern nss_backend_t *_nss_files_constr(files_backend_op_t *ops, 970Sstevel@tonic-gate int n_ops, 980Sstevel@tonic-gate const char *filename, 990Sstevel@tonic-gate int min_bufsize, 1000Sstevel@tonic-gate files_hash_t *fhp); 1011914Scasper extern nss_status_t _nss_files_destr(files_backend_ptr_t, void *dummy); 1020Sstevel@tonic-gate extern nss_status_t _nss_files_setent(files_backend_ptr_t, void *dummy); 1030Sstevel@tonic-gate extern nss_status_t _nss_files_endent(files_backend_ptr_t, void *dummy); 1040Sstevel@tonic-gate extern nss_status_t _nss_files_getent_rigid(files_backend_ptr_t, void *); 1050Sstevel@tonic-gate extern nss_status_t _nss_files_getent_netdb(files_backend_ptr_t, void *); 1060Sstevel@tonic-gate extern nss_status_t _nss_files_do_all(files_backend_ptr_t, 1070Sstevel@tonic-gate void *func_priv, 1080Sstevel@tonic-gate const char *filter, 1090Sstevel@tonic-gate files_do_all_func_t func); 1100Sstevel@tonic-gate extern nss_status_t _nss_files_XY_all(files_backend_ptr_t be, 1110Sstevel@tonic-gate nss_XbyY_args_t *args, 1120Sstevel@tonic-gate int netdb, 1130Sstevel@tonic-gate const char *filter, 1140Sstevel@tonic-gate files_XY_check_func check); 1150Sstevel@tonic-gate extern nss_status_t _nss_files_XY_hash(files_backend_ptr_t be, 1160Sstevel@tonic-gate nss_XbyY_args_t *args, 1170Sstevel@tonic-gate int netdb, 1180Sstevel@tonic-gate files_hash_t *fhp, 1190Sstevel@tonic-gate int hashop, 1200Sstevel@tonic-gate files_XY_check_func check); 1211914Scasper int _nss_files_read_line(FILE *f, char *buffer, int buflen); 1220Sstevel@tonic-gate #else 1230Sstevel@tonic-gate extern nss_backend_t *_nss_files_constr(); 1241914Scasper extern nss_status_t _nss_files_destr(); 1250Sstevel@tonic-gate extern nss_status_t _nss_files_setent(); 1260Sstevel@tonic-gate extern nss_status_t _nss_files_endent(); 1270Sstevel@tonic-gate extern nss_status_t _nss_files_getent_rigid(); 1280Sstevel@tonic-gate extern nss_status_t _nss_files_getent_netdb(); 1290Sstevel@tonic-gate extern nss_status_t _nss_files_do_all(); 1300Sstevel@tonic-gate extern nss_status_t _nss_files_XY_all(); 1310Sstevel@tonic-gate extern nss_status_t _nss_files_XY_hash(); 1320Sstevel@tonic-gate #endif 1330Sstevel@tonic-gate 1342830Sdjl int _nss_files_check_name_aliases(nss_XbyY_args_t *, const char *, int); 1352830Sdjl int _nss_files_check_name_colon(nss_XbyY_args_t *, const char *, int); 1362830Sdjl 137*8040SBaban.Kenkre@Sun.COM /* passwd and group validation functions */ 138*8040SBaban.Kenkre@Sun.COM extern int validate_group_ids(char *line, int *linelenp, int buflen, 139*8040SBaban.Kenkre@Sun.COM int extra_chars, files_XY_check_func check); 140*8040SBaban.Kenkre@Sun.COM extern int validate_passwd_ids(char *line, int *linelenp, int buflen, 141*8040SBaban.Kenkre@Sun.COM int extra_chars); 142*8040SBaban.Kenkre@Sun.COM 1430Sstevel@tonic-gate #ifdef __cplusplus 1440Sstevel@tonic-gate } 1450Sstevel@tonic-gate #endif 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate #endif /* _FILES_COMMON_H */ 148