xref: /illumos-gate/usr/src/cmd/nscd/nscd_door.h (revision 7d7551bc)
1cb5caa98Sdjl /*
2cb5caa98Sdjl  * CDDL HEADER START
3cb5caa98Sdjl  *
4cb5caa98Sdjl  * The contents of this file are subject to the terms of the
5cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6cb5caa98Sdjl  * You may not use this file except in compliance with the License.
7cb5caa98Sdjl  *
8cb5caa98Sdjl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9cb5caa98Sdjl  * or http://www.opensolaris.org/os/licensing.
10cb5caa98Sdjl  * See the License for the specific language governing permissions
11cb5caa98Sdjl  * and limitations under the License.
12cb5caa98Sdjl  *
13cb5caa98Sdjl  * When distributing Covered Code, include this CDDL HEADER in each
14cb5caa98Sdjl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15cb5caa98Sdjl  * If applicable, add the following below this CDDL HEADER, with the
16cb5caa98Sdjl  * fields enclosed by brackets "[]" replaced with your own identifying
17cb5caa98Sdjl  * information: Portions Copyright [yyyy] [name of copyright owner]
18cb5caa98Sdjl  *
19cb5caa98Sdjl  * CDDL HEADER END
20cb5caa98Sdjl  */
21cb5caa98Sdjl 
22cb5caa98Sdjl /*
23606f6aa3Smichen  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24cb5caa98Sdjl  * Use is subject to license terms.
25*7d7551bcSMilan Jurik  * Copyright 2012 Milan Jurik. All rights reserved.
26cb5caa98Sdjl  */
27cb5caa98Sdjl 
28cb5caa98Sdjl #ifndef	_NSCD_DOOR_H
29cb5caa98Sdjl #define	_NSCD_DOOR_H
30cb5caa98Sdjl 
31cb5caa98Sdjl /*
32cb5caa98Sdjl  * Definitions for nscd to nscd door interfaces
33cb5caa98Sdjl  */
34cb5caa98Sdjl 
35cb5caa98Sdjl #ifdef	__cplusplus
36cb5caa98Sdjl extern "C" {
37cb5caa98Sdjl #endif
38cb5caa98Sdjl 
39cb5caa98Sdjl #include <alloca.h>
40cb5caa98Sdjl #include <nss_dbdefs.h>
41cb5caa98Sdjl 
42cb5caa98Sdjl /* door for Trusted Extensions */
43cb5caa98Sdjl #define	TSOL_NAME_SERVICE_DOOR	"/var/tsol/doors/name_service_door"
44bf1e3beeSmichen /* TX per label nscd indication file */
45bf1e3beeSmichen #define	TSOL_NSCD_PER_LABEL_FILE "/var/tsol/doors/nscd_per_label"
46cb5caa98Sdjl 
47cb5caa98Sdjl /* nscd v2 nscd -> nscd call numbers */
48cb5caa98Sdjl #define	NSCD_PING	(NSCD_CALLCAT_N2N|0x01)
49cb5caa98Sdjl #define	NSCD_GETADMIN	(NSCD_CALLCAT_N2N|0x02)
50cb5caa98Sdjl #define	NSCD_SETADMIN	(NSCD_CALLCAT_N2N|0x03)
51cb5caa98Sdjl #define	NSCD_GETPUADMIN	(NSCD_CALLCAT_N2N|0x04)
52cb5caa98Sdjl #define	NSCD_SETPUADMIN	(NSCD_CALLCAT_N2N|0x05)
53cb5caa98Sdjl #define	NSCD_KILLSERVER	(NSCD_CALLCAT_N2N|0x06)
54cb5caa98Sdjl 
55cb5caa98Sdjl #define	NSCD_IMHERE	(NSCD_CALLCAT_N2N|0x10)	/* IMHERE+WHOAMI */
56cb5caa98Sdjl #define	NSCD_FORK	(NSCD_CALLCAT_N2N|0x20)
57cb5caa98Sdjl #define	NSCD_SETUID	(NSCD_CALLCAT_N2N|0x30)
58cb5caa98Sdjl #define	NSCD_KILL	(NSCD_CALLCAT_N2N|0x40)
59cb5caa98Sdjl #define	NSCD_PULSE	(NSCD_CALLCAT_N2N|0x50)
60cb5caa98Sdjl #define	NSCD_REFRESH	(NSCD_CALLCAT_N2N|0x60)
61cb5caa98Sdjl 
62cb5caa98Sdjl /* nscd v2 nscd identities */
63cb5caa98Sdjl 
64cb5caa98Sdjl #define	NSCD_MAIN	0x00000001
65cb5caa98Sdjl #define	NSCD_FORKER	0x00000002
66cb5caa98Sdjl #define	NSCD_CHILD	0x00000004
67cb5caa98Sdjl #define	NSCD_WHOAMI	0x0000000F
68cb5caa98Sdjl 
69cb5caa98Sdjl #define	NSCD_ALLOC_DOORBUF(cn, dsz, uptr, usz) \
70cb5caa98Sdjl 	usz = (sizeof (nss_pheader_t) + (dsz)); \
71cb5caa98Sdjl 	uptr = alloca(usz); \
72cb5caa98Sdjl 	(void) memset(uptr, 0, usz); \
73cb5caa98Sdjl 	((nss_pheader_t *)uptr)->nsc_callnumber = (cn); \
74606f6aa3Smichen 	((nss_pheader_t *)uptr)->p_version = NSCD_HEADER_REV; \
75cb5caa98Sdjl 	((nss_pheader_t *)uptr)->pbufsiz = usz; \
76606f6aa3Smichen 	((nss_pheader_t *)uptr)->data_off = sizeof (nss_pheader_t); \
77606f6aa3Smichen 	((nss_pheader_t *)uptr)->key_off = sizeof (nss_pheader_t); \
78606f6aa3Smichen 	((nss_pheader_t *)uptr)->dbd_off = sizeof (nss_pheader_t); \
79606f6aa3Smichen 	((nss_pheader_t *)uptr)->data_len = dsz;
80cb5caa98Sdjl 
81cb5caa98Sdjl #define	NSCD_N2N_DOOR_DATA(type, buf) \
82cb5caa98Sdjl 	(type *)((void *)(((char *)(buf)) + sizeof (nss_pheader_t)))
83cb5caa98Sdjl 
84cb5caa98Sdjl #define	NSCD_N2N_DOOR_BUF_SIZE(struct) \
85cb5caa98Sdjl 	sizeof (nss_pheader_t) + sizeof (struct)
86cb5caa98Sdjl 
87cb5caa98Sdjl #define	NSCD_SET_STATUS(ph, st, errno) \
88cb5caa98Sdjl 	{ \
89cb5caa98Sdjl 		int	e = errno; \
90cb5caa98Sdjl 		(ph)->p_status = st; \
91cb5caa98Sdjl 		if (e != -1) \
92cb5caa98Sdjl 			(ph)->p_errno = e; \
93cb5caa98Sdjl 	}
94cb5caa98Sdjl 
95cb5caa98Sdjl #define	NSCD_SET_HERRNO(ph, herrno) \
96cb5caa98Sdjl 	(ph)->p_herrno = herrno;
97cb5caa98Sdjl 
98cb5caa98Sdjl 
99cb5caa98Sdjl #define	NSCD_SET_STATUS_SUCCESS(ph) \
100cb5caa98Sdjl 	(ph)->p_status = NSS_SUCCESS; \
101cb5caa98Sdjl 	(ph)->p_errno = 0;
102cb5caa98Sdjl 
103cb5caa98Sdjl #define	NSCD_SET_N2N_STATUS(ph, st, errno, n2nst) \
104cb5caa98Sdjl 	{ \
105cb5caa98Sdjl 		int	e = errno; \
106cb5caa98Sdjl 		(ph)->p_status = st; \
107cb5caa98Sdjl 		if (e != -1) \
108cb5caa98Sdjl 			(ph)->p_errno = e; \
109cb5caa98Sdjl 		(ph)->nscdpriv = n2nst; \
110cb5caa98Sdjl 	}
111cb5caa98Sdjl 
112cb5caa98Sdjl #define	NSCD_STATUS_IS_OK(ph) \
113cb5caa98Sdjl 	(((ph)->p_status) == NSS_SUCCESS)
114cb5caa98Sdjl 
115cb5caa98Sdjl #define	NSCD_STATUS_IS_NOT_OK(ph) \
116cb5caa98Sdjl 	(((ph)->p_status) != NSS_SUCCESS)
117cb5caa98Sdjl 
118cb5caa98Sdjl #define	NSCD_GET_STATUS(ph) \
119cb5caa98Sdjl 	(((nss_pheader_t *)(ph))->p_status)
120cb5caa98Sdjl 
121cb5caa98Sdjl #define	NSCD_GET_ERRNO(ph) \
122cb5caa98Sdjl 	(((nss_pheader_t *)(ph))->p_errno)
123cb5caa98Sdjl 
124cb5caa98Sdjl #define	NSCD_GET_HERRNO(ph) \
125cb5caa98Sdjl 	(((nss_pheader_t *)(ph))->p_herrno)
126cb5caa98Sdjl 
127cb5caa98Sdjl #define	NSCD_GET_NSCD_STATUS(ph) \
128cb5caa98Sdjl 	(((nss_pheader_t *)(ph))->nscdpriv)
129cb5caa98Sdjl 
130cb5caa98Sdjl #define	NSCD_CLEAR_STATUS(ph) \
131cb5caa98Sdjl 	(ph)->p_status = 0; \
132cb5caa98Sdjl 	(ph)->p_errno = 0; \
133cb5caa98Sdjl 	(ph)->nscdpriv = 0;
134cb5caa98Sdjl 
135cb5caa98Sdjl #define	NSCD_COPY_STATUS(ph, ph1) \
136cb5caa98Sdjl 	(ph)->p_status = (ph1)->p_status; \
137cb5caa98Sdjl 	(ph)->p_errno = (ph1)->p_errno; \
138cb5caa98Sdjl 	(ph)->nscdpriv = (ph1)->nscdpriv;
139cb5caa98Sdjl 
140cb5caa98Sdjl nss_status_t	_nscd_doorcall(int callnum);
141cb5caa98Sdjl nss_status_t 	_nscd_doorcall_data(int callnum, void *indata,
142cb5caa98Sdjl 			int indlen, void *outdata, int outdlen,
143cb5caa98Sdjl 			nss_pheader_t *phdr);
144cb5caa98Sdjl 
145cb5caa98Sdjl nss_status_t	 _nscd_doorcall_fd(int fd, int callnum, void *indata,
146cb5caa98Sdjl 			int indlen, void *outdata, int outdlen,
147cb5caa98Sdjl 			nss_pheader_t *phdr);
148cb5caa98Sdjl 
149cb5caa98Sdjl nss_status_t	_nscd_doorcall_sendfd(int fd, int callnum,
150cb5caa98Sdjl 			void *indata, int indlen, nss_pheader_t *phdr);
151cb5caa98Sdjl 
152cb5caa98Sdjl #ifdef	__cplusplus
153cb5caa98Sdjl }
154cb5caa98Sdjl #endif
155cb5caa98Sdjl 
156cb5caa98Sdjl #endif	/* _NSCD_DOOR_H */
157