xref: /illumos-gate/usr/src/cmd/nscd/nscd_frontend.h (revision 2983dda76a6d296fdb560c88114fe41caad1b84f)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _NSCD_FRONTEND_H
27 #define	_NSCD_FRONTEND_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include "cache.h"
34 
35 #define	NSCD_N2NBUF_MAXLEN	1024 * 8
36 #define	NSCD_PHDR_MAXLEN	1024 * 8
37 #define	NSCD_LOOKUP_BUFSIZE	1024 * 16
38 #define	NSCD_DOORBUF_MAXLEN	1024 * 512
39 #define	NSCD_PHDR_LEN(hdrp)	((hdrp)->data_off)
40 #define	NSCD_DATA_LEN(hdrp)	((hdrp)->data_len)
41 /* used to check clients required privileges */
42 #define	NSCD_ALL_PRIV		0
43 #define	NSCD_READ_PRIV		1
44 
45 #define	NSCD_ALLOC_LOOKUP_BUFFER(bufp, bufsiz, hdrp, space, spsiz)  \
46 	if ((hdrp)->pbufsiz <= spsiz) { \
47 		(void) memcpy(space, (hdrp), NSCD_PHDR_LEN((hdrp))); \
48 		bufp = space; \
49 		bufsiz = spsiz; \
50 		hdrp = (nss_pheader_t *)(void *)space; \
51 		(hdrp)->pbufsiz = bufsiz; \
52 		(hdrp)->data_len = bufsiz - (hdrp)->data_off; \
53 	} else { \
54 		(bufp) = NULL; \
55 		bufsiz = (hdrp)->pbufsiz; \
56 		if (bufsiz > spsiz) \
57 			bufsiz = NSCD_DOORBUF_MAXLEN; \
58 		(bufp) = alloca(bufsiz); \
59 		if ((bufp) != NULL) { \
60 			(void) memcpy((bufp), (hdrp), NSCD_PHDR_LEN(hdrp)); \
61 			(hdrp) = (nss_pheader_t *)(void *)(bufp); \
62 			(hdrp)->pbufsiz = bufsiz; \
63 			(hdrp)->data_len = bufsiz - (hdrp)->data_off; \
64 		} else { \
65 			NSCD_SET_STATUS((hdrp), NSS_ERROR, ENOMEM); \
66 			(void) door_return((char *)(hdrp), \
67 				NSCD_PHDR_LEN(hdrp), NULL, 0); \
68 		} \
69 	}
70 
71 #define	NSCD_SET_RETURN_ARG(hdrp, arg_size)  \
72 	if (NSCD_STATUS_IS_OK((nss_pheader_t *)(hdrp))) \
73 		arg_size = NSCD_PHDR_LEN(hdrp) + (NSCD_DATA_LEN(hdrp) > 0 ? \
74 		NSCD_DATA_LEN(hdrp) + 1 : 0); \
75 	else \
76 		arg_size = NSCD_PHDR_LEN(hdrp);
77 
78 /* prototypes */
79 uid_t _nscd_get_client_euid();
80 int _nscd_check_client_priv(int);
81 int _nscd_setup_server(char *execname, char **argv);
82 int _nscd_setup_child_server(int did);
83 int _nscd_get_clearance(sema_t *sema);
84 int _nscd_release_clearance(sema_t *sema);
85 void _nscd_init_cache_sema(sema_t *sema, char *cache_name);
86 nscd_rc_t _nscd_alloc_frontend_cfg();
87 void _nscd_APP_check_cred(void *buf, pid_t *pidp, char *dc_str,
88 	int log_comp, int log_level);
89 void _nscd_restart_if_cfgfile_changed();
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif	/* _NSCD_FRONTEND_H */
95