xref: /titanic_52/usr/src/cmd/nscd/nscd_door.h (revision b6c3f7863936abeae522e48a13887dddeb691a45)
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 2007 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 /* TX per label nscd indication file */
46 #define	TSOL_NSCD_PER_LABEL_FILE "/var/tsol/doors/nscd_per_label"
47 
48 /* nscd v2 nscd -> nscd call numbers */
49 #define	NSCD_PING	(NSCD_CALLCAT_N2N|0x01)
50 #define	NSCD_GETADMIN	(NSCD_CALLCAT_N2N|0x02)
51 #define	NSCD_SETADMIN	(NSCD_CALLCAT_N2N|0x03)
52 #define	NSCD_GETPUADMIN	(NSCD_CALLCAT_N2N|0x04)
53 #define	NSCD_SETPUADMIN	(NSCD_CALLCAT_N2N|0x05)
54 #define	NSCD_KILLSERVER	(NSCD_CALLCAT_N2N|0x06)
55 
56 #define	NSCD_IMHERE	(NSCD_CALLCAT_N2N|0x10)	/* IMHERE+WHOAMI */
57 #define	NSCD_FORK	(NSCD_CALLCAT_N2N|0x20)
58 #define	NSCD_SETUID	(NSCD_CALLCAT_N2N|0x30)
59 #define	NSCD_KILL	(NSCD_CALLCAT_N2N|0x40)
60 #define	NSCD_PULSE	(NSCD_CALLCAT_N2N|0x50)
61 #define	NSCD_REFRESH	(NSCD_CALLCAT_N2N|0x60)
62 
63 /* nscd v2 nscd identities */
64 
65 #define	NSCD_MAIN	0x00000001
66 #define	NSCD_FORKER	0x00000002
67 #define	NSCD_CHILD	0x00000004
68 #define	NSCD_WHOAMI	0x0000000F
69 
70 #define	NSCD_ALLOC_DOORBUF(cn, dsz, uptr, usz) \
71 	usz = (sizeof (nss_pheader_t) + (dsz)); \
72 	uptr = alloca(usz); \
73 	(void) memset(uptr, 0, usz); \
74 	((nss_pheader_t *)uptr)->nsc_callnumber = (cn); \
75 	((nss_pheader_t *)uptr)->p_version = NSCD_HEADER_REV; \
76 	((nss_pheader_t *)uptr)->pbufsiz = usz; \
77 	((nss_pheader_t *)uptr)->data_off = sizeof (nss_pheader_t); \
78 	((nss_pheader_t *)uptr)->key_off = sizeof (nss_pheader_t); \
79 	((nss_pheader_t *)uptr)->dbd_off = sizeof (nss_pheader_t); \
80 	((nss_pheader_t *)uptr)->data_len = dsz;
81 
82 #define	NSCD_N2N_DOOR_DATA(type, buf) \
83 	(type *)((void *)(((char *)(buf)) + sizeof (nss_pheader_t)))
84 
85 #define	NSCD_N2N_DOOR_BUF_SIZE(struct) \
86 	sizeof (nss_pheader_t) + sizeof (struct)
87 
88 #define	NSCD_SET_STATUS(ph, st, errno) \
89 	{ \
90 		int	e = errno; \
91 		(ph)->p_status = st; \
92 		if (e != -1) \
93 			(ph)->p_errno = e; \
94 	}
95 
96 #define	NSCD_SET_HERRNO(ph, herrno) \
97 	(ph)->p_herrno = herrno;
98 
99 
100 #define	NSCD_RETURN_STATUS(ph, st, errno) \
101 	{ \
102 		int e = errno; \
103 		(ph)->p_status = st; \
104 		if (e != -1) \
105 			(ph)->p_errno = e; \
106 		return; \
107 	}
108 
109 #define	NSCD_SET_STATUS_SUCCESS(ph) \
110 	(ph)->p_status = NSS_SUCCESS; \
111 	(ph)->p_errno = 0;
112 
113 #define	NSCD_RETURN_STATUS_SUCCESS(ph) \
114 	(ph)->p_status = NSS_SUCCESS; \
115 	(ph)->p_errno = 0; \
116 	return;
117 
118 #define	NSCD_SET_N2N_STATUS(ph, st, errno, n2nst) \
119 	{ \
120 		int	e = errno; \
121 		(ph)->p_status = st; \
122 		if (e != -1) \
123 			(ph)->p_errno = e; \
124 		(ph)->nscdpriv = n2nst; \
125 	}
126 
127 #define	NSCD_RETURN_N2N_STATUS(ph, st, errno, n2nst) \
128 	{ \
129 		int	e = errno; \
130 		(ph)->p_status = st; \
131 		if (e != -1) \
132 			(ph)->p_errno = e; \
133 		(ph)->nscdpriv = n2nst; \
134 		return; \
135 	}
136 
137 #define	NSCD_STATUS_IS_OK(ph) \
138 	(((ph)->p_status) == NSS_SUCCESS)
139 
140 #define	NSCD_STATUS_IS_NOT_OK(ph) \
141 	(((ph)->p_status) != NSS_SUCCESS)
142 
143 #define	NSCD_GET_STATUS(ph) \
144 	(((nss_pheader_t *)(ph))->p_status)
145 
146 #define	NSCD_GET_ERRNO(ph) \
147 	(((nss_pheader_t *)(ph))->p_errno)
148 
149 #define	NSCD_GET_HERRNO(ph) \
150 	(((nss_pheader_t *)(ph))->p_herrno)
151 
152 #define	NSCD_GET_NSCD_STATUS(ph) \
153 	(((nss_pheader_t *)(ph))->nscdpriv)
154 
155 #define	NSCD_CLEAR_STATUS(ph) \
156 	(ph)->p_status = 0; \
157 	(ph)->p_errno = 0; \
158 	(ph)->nscdpriv = 0;
159 
160 #define	NSCD_COPY_STATUS(ph, ph1) \
161 	(ph)->p_status = (ph1)->p_status; \
162 	(ph)->p_errno = (ph1)->p_errno; \
163 	(ph)->nscdpriv = (ph1)->nscdpriv;
164 
165 nss_status_t	_nscd_doorcall(int callnum);
166 nss_status_t 	_nscd_doorcall_data(int callnum, void *indata,
167 			int indlen, void *outdata, int outdlen,
168 			nss_pheader_t *phdr);
169 
170 nss_status_t	 _nscd_doorcall_fd(int fd, int callnum, void *indata,
171 			int indlen, void *outdata, int outdlen,
172 			nss_pheader_t *phdr);
173 
174 nss_status_t	_nscd_doorcall_sendfd(int fd, int callnum,
175 			void *indata, int indlen, nss_pheader_t *phdr);
176 
177 #ifdef	__cplusplus
178 }
179 #endif
180 
181 #endif	/* _NSCD_DOOR_H */
182