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