xref: /illumos-gate/usr/src/cmd/nscd/nscd_door.h (revision 150d2c5288c645a1c1a7d2bee61199a3729406c7)
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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_NSCD_DOOR_H
28 #define	_NSCD_DOOR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Definitions for nscd to nscd door interfaces
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #include <alloca.h>
41 #include <nss_dbdefs.h>
42 
43 /* door for Trusted Extensions */
44 #define	TSOL_NAME_SERVICE_DOOR	"/var/tsol/doors/name_service_door"
45 
46 /* nscd v2 nscd -> nscd call numbers */
47 #define	NSCD_PING	(NSCD_CALLCAT_N2N|0x01)
48 #define	NSCD_GETADMIN	(NSCD_CALLCAT_N2N|0x02)
49 #define	NSCD_SETADMIN	(NSCD_CALLCAT_N2N|0x03)
50 #define	NSCD_GETPUADMIN	(NSCD_CALLCAT_N2N|0x04)
51 #define	NSCD_SETPUADMIN	(NSCD_CALLCAT_N2N|0x05)
52 #define	NSCD_KILLSERVER	(NSCD_CALLCAT_N2N|0x06)
53 
54 #define	NSCD_IMHERE	(NSCD_CALLCAT_N2N|0x10)	/* IMHERE+WHOAMI */
55 #define	NSCD_FORK	(NSCD_CALLCAT_N2N|0x20)
56 #define	NSCD_SETUID	(NSCD_CALLCAT_N2N|0x30)
57 #define	NSCD_KILL	(NSCD_CALLCAT_N2N|0x40)
58 #define	NSCD_PULSE	(NSCD_CALLCAT_N2N|0x50)
59 #define	NSCD_REFRESH	(NSCD_CALLCAT_N2N|0x60)
60 
61 /* nscd v2 nscd identities */
62 
63 #define	NSCD_MAIN	0x00000001
64 #define	NSCD_FORKER	0x00000002
65 #define	NSCD_CHILD	0x00000004
66 #define	NSCD_WHOAMI	0x0000000F
67 
68 #define	NSCD_ALLOC_DOORBUF(cn, dsz, uptr, usz) \
69 	usz = (sizeof (nss_pheader_t) + (dsz)); \
70 	uptr = alloca(usz); \
71 	(void) memset(uptr, 0, usz); \
72 	((nss_pheader_t *)uptr)->nsc_callnumber = (cn); \
73 	((nss_pheader_t *)uptr)->pbufsiz = usz; \
74 	((nss_pheader_t *)uptr)->data_off = sizeof (nss_pheader_t);
75 
76 #define	NSCD_N2N_DOOR_DATA(type, buf) \
77 	(type *)((void *)(((char *)(buf)) + sizeof (nss_pheader_t)))
78 
79 #define	NSCD_N2N_DOOR_BUF_SIZE(struct) \
80 	sizeof (nss_pheader_t) + sizeof (struct)
81 
82 #define	NSCD_SET_STATUS(ph, st, errno) \
83 	{ \
84 		int	e = errno; \
85 		(ph)->p_status = st; \
86 		if (e != -1) \
87 			(ph)->p_errno = e; \
88 	}
89 
90 #define	NSCD_SET_HERRNO(ph, herrno) \
91 	(ph)->p_herrno = herrno;
92 
93 
94 #define	NSCD_RETURN_STATUS(ph, st, errno) \
95 	{ \
96 		int e = errno; \
97 		(ph)->p_status = st; \
98 		if (e != -1) \
99 			(ph)->p_errno = e; \
100 		return; \
101 	}
102 
103 #define	NSCD_SET_STATUS_SUCCESS(ph) \
104 	(ph)->p_status = NSS_SUCCESS; \
105 	(ph)->p_errno = 0;
106 
107 #define	NSCD_RETURN_STATUS_SUCCESS(ph) \
108 	(ph)->p_status = NSS_SUCCESS; \
109 	(ph)->p_errno = 0; \
110 	return;
111 
112 #define	NSCD_SET_N2N_STATUS(ph, st, errno, n2nst) \
113 	{ \
114 		int	e = errno; \
115 		(ph)->p_status = st; \
116 		if (e != -1) \
117 			(ph)->p_errno = e; \
118 		(ph)->nscdpriv = n2nst; \
119 	}
120 
121 #define	NSCD_RETURN_N2N_STATUS(ph, st, errno, n2nst) \
122 	{ \
123 		int	e = errno; \
124 		(ph)->p_status = st; \
125 		if (e != -1) \
126 			(ph)->p_errno = e; \
127 		(ph)->nscdpriv = n2nst; \
128 		return; \
129 	}
130 
131 #define	NSCD_STATUS_IS_OK(ph) \
132 	(((ph)->p_status) == NSS_SUCCESS)
133 
134 #define	NSCD_STATUS_IS_NOT_OK(ph) \
135 	(((ph)->p_status) != NSS_SUCCESS)
136 
137 #define	NSCD_GET_STATUS(ph) \
138 	(((nss_pheader_t *)(ph))->p_status)
139 
140 #define	NSCD_GET_ERRNO(ph) \
141 	(((nss_pheader_t *)(ph))->p_errno)
142 
143 #define	NSCD_GET_HERRNO(ph) \
144 	(((nss_pheader_t *)(ph))->p_herrno)
145 
146 #define	NSCD_GET_NSCD_STATUS(ph) \
147 	(((nss_pheader_t *)(ph))->nscdpriv)
148 
149 #define	NSCD_CLEAR_STATUS(ph) \
150 	(ph)->p_status = 0; \
151 	(ph)->p_errno = 0; \
152 	(ph)->nscdpriv = 0;
153 
154 #define	NSCD_COPY_STATUS(ph, ph1) \
155 	(ph)->p_status = (ph1)->p_status; \
156 	(ph)->p_errno = (ph1)->p_errno; \
157 	(ph)->nscdpriv = (ph1)->nscdpriv;
158 
159 nss_status_t	_nscd_doorcall(int callnum);
160 nss_status_t 	_nscd_doorcall_data(int callnum, void *indata,
161 			int indlen, void *outdata, int outdlen,
162 			nss_pheader_t *phdr);
163 
164 nss_status_t	 _nscd_doorcall_fd(int fd, int callnum, void *indata,
165 			int indlen, void *outdata, int outdlen,
166 			nss_pheader_t *phdr);
167 
168 nss_status_t	_nscd_doorcall_sendfd(int fd, int callnum,
169 			void *indata, int indlen, nss_pheader_t *phdr);
170 
171 #ifdef	__cplusplus
172 }
173 #endif
174 
175 #endif	/* _NSCD_DOOR_H */
176