xref: /titanic_44/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision a4aeef46cda1835da2b19f8f62b4526de6521e6c)
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 /*
27  * Please do not edit this file.
28  * It was generated using rpcgen.
29  * Edit idmap_prot.x and rebuild this file with
30  * rpcgen -CMNm -o idmap_prot_svc.c.new ../../../uts/common/rpcsvc/idmap_prot.x
31  * then merge as required.  A recent version of rpcgen is needed to
32  * produce this exact file; when the revised rpcgen is available in the
33  * build environment this file can be built automatically.
34  */
35 
36 #include "../../../uts/common/rpcsvc/idmap_prot.h"
37 #include <stdio.h>
38 #include <stdlib.h> /* getenv, exit */
39 #include <signal.h>
40 #include <rpc/pmap_clnt.h> /* for pmap_unset */
41 #include <string.h> /* strcmp */
42 #include <unistd.h> /* setsid */
43 #include <sys/types.h>
44 #include <memory.h>
45 #include <stropts.h>
46 #include <sys/resource.h> /* rlimit */
47 #include <syslog.h>
48 
49 #ifndef SIG_PF
50 #define	SIG_PF void(*)(int)
51 #endif
52 
53 #ifdef DEBUG
54 #define	RPC_SVC_FG
55 #endif
56 
57 #define	_RPCSVC_CLOSEDOWN 120
58 extern int _rpcpmstart;		/* Started by a port monitor ? */
59 
60 /* States a server can be in wrt request */
61 
62 #define	_IDLE 0
63 #define	_SERVED 1
64 
65 /* LINTED static unused if no main */
66 static int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
67 static int _rpcsvccount = 0;		/* Number of requests being serviced */
68 mutex_t _svcstate_lock;		/* lock for _rpcsvcstate, _rpcsvccount */
69 
70 #if	defined(RPC_MSGOUT)
71 extern void RPC_MSGOUT(const char *, ...);
72 #else	/* defined(RPC_MSGOUT) */
73 static void
74 RPC_MSGOUT(const char *fmt, char *msg)
75 {
76 #ifdef RPC_SVC_FG
77 	if (_rpcpmstart)
78 		syslog(LOG_ERR, fmt, msg);
79 	else {
80 		(void) fprintf(stderr, fmt, msg);
81 		(void) putc('\n', stderr);
82 	}
83 #else
84 	syslog(LOG_ERR, fmt, msg);
85 #endif
86 }
87 #endif	/* defined(RPC_MSGOUT) */
88 
89 /* ARGSUSED */
90 int
91 _idmap_null_1(
92     void  *argp,
93     void *result,
94     struct svc_req *rqstp)
95 {
96 	return (idmap_null_1_svc(result, rqstp));
97 }
98 
99 int
100 _idmap_get_mapped_ids_1(
101     idmap_mapping_batch  *argp,
102     idmap_ids_res *result,
103     struct svc_req *rqstp)
104 {
105 	return (idmap_get_mapped_ids_1_svc(*argp, result, rqstp));
106 }
107 
108 int
109 _idmap_list_mappings_1(
110     idmap_list_mappings_1_argument *argp,
111     idmap_mappings_res *result,
112     struct svc_req *rqstp)
113 {
114 	return (idmap_list_mappings_1_svc(
115 	    argp->lastrowid,
116 	    argp->limit,
117 	    argp->flag,
118 	    result, rqstp));
119 }
120 
121 int
122 _idmap_list_namerules_1(
123     idmap_list_namerules_1_argument *argp,
124     idmap_namerules_res *result,
125     struct svc_req *rqstp)
126 {
127 	return (idmap_list_namerules_1_svc(
128 	    argp->rule,
129 	    argp->lastrowid,
130 	    argp->limit,
131 	    result, rqstp));
132 }
133 
134 int
135 _idmap_update_1(
136     idmap_update_batch  *argp,
137     idmap_update_res *result,
138     struct svc_req *rqstp)
139 {
140 	return (idmap_update_1_svc(*argp, result, rqstp));
141 }
142 
143 int
144 _idmap_get_mapped_id_by_name_1(
145     idmap_mapping  *argp,
146     idmap_mappings_res *result,
147     struct svc_req *rqstp)
148 {
149 	return (idmap_get_mapped_id_by_name_1_svc(*argp, result, rqstp));
150 }
151 
152 int
153 _idmap_get_prop_1(
154     idmap_prop_type  *argp,
155     idmap_prop_res *result,
156     struct svc_req *rqstp)
157 {
158 	return (idmap_get_prop_1_svc(*argp, result, rqstp));
159 }
160 
161 int
162 _directory_get_common_1(
163     directory_get_common_1_argument *argp,
164     directory_results_rpc *result,
165     struct svc_req *rqstp)
166 {
167 	return (directory_get_common_1_svc(
168 	    argp->ids,
169 	    argp->types,
170 	    argp->attrs,
171 	    result, rqstp));
172 }
173 
174 void
175 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
176 {
177 	union {
178 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
179 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
180 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
181 		idmap_update_batch idmap_update_1_arg;
182 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
183 		idmap_prop_type idmap_get_prop_1_arg;
184 		directory_get_common_1_argument directory_get_common_1_arg;
185 	} argument;
186 	union {
187 		idmap_ids_res idmap_get_mapped_ids_1_res;
188 		idmap_mappings_res idmap_list_mappings_1_res;
189 		idmap_namerules_res idmap_list_namerules_1_res;
190 		idmap_update_res idmap_update_1_res;
191 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
192 		idmap_prop_res idmap_get_prop_1_res;
193 		directory_results_rpc directory_get_common_1_res;
194 	} result;
195 	bool_t retval;
196 	xdrproc_t _xdr_argument, _xdr_result;
197 	bool_t (*local)(char *, void *, struct svc_req *);
198 
199 	(void) mutex_lock(&_svcstate_lock);
200 	_rpcsvccount++;
201 	(void) mutex_unlock(&_svcstate_lock);
202 	switch (rqstp->rq_proc) {
203 	case IDMAP_NULL:
204 		_xdr_argument = (xdrproc_t)
205 		    xdr_void;
206 		_xdr_result = (xdrproc_t)
207 		    xdr_void;
208 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
209 		    _idmap_null_1;
210 		break;
211 
212 	case IDMAP_GET_MAPPED_IDS:
213 		_xdr_argument = (xdrproc_t)
214 		    xdr_idmap_mapping_batch;
215 		_xdr_result = (xdrproc_t)
216 		    xdr_idmap_ids_res;
217 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
218 		    _idmap_get_mapped_ids_1;
219 		break;
220 
221 	case IDMAP_LIST_MAPPINGS:
222 		_xdr_argument = (xdrproc_t)
223 		    xdr_idmap_list_mappings_1_argument;
224 		_xdr_result = (xdrproc_t)
225 		    xdr_idmap_mappings_res;
226 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
227 		    _idmap_list_mappings_1;
228 		break;
229 
230 	case IDMAP_LIST_NAMERULES:
231 		_xdr_argument = (xdrproc_t)
232 		    xdr_idmap_list_namerules_1_argument;
233 		_xdr_result = (xdrproc_t)
234 		    xdr_idmap_namerules_res;
235 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
236 		    _idmap_list_namerules_1;
237 		break;
238 
239 	case IDMAP_UPDATE:
240 		_xdr_argument = (xdrproc_t)
241 		    xdr_idmap_update_batch;
242 		_xdr_result = (xdrproc_t)
243 		    xdr_idmap_update_res;
244 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
245 		    _idmap_update_1;
246 		break;
247 
248 	case IDMAP_GET_MAPPED_ID_BY_NAME:
249 		_xdr_argument = (xdrproc_t)
250 		    xdr_idmap_mapping;
251 		_xdr_result = (xdrproc_t)
252 		    xdr_idmap_mappings_res;
253 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
254 		    _idmap_get_mapped_id_by_name_1;
255 		break;
256 
257 	case IDMAP_GET_PROP:
258 		_xdr_argument = (xdrproc_t)
259 		    xdr_idmap_prop_type;
260 		_xdr_result = (xdrproc_t)
261 		    xdr_idmap_prop_res;
262 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
263 		    _idmap_get_prop_1;
264 		break;
265 
266 	case DIRECTORY_GET_COMMON:
267 		_xdr_argument = (xdrproc_t)
268 		    xdr_directory_get_common_1_argument;
269 		_xdr_result = (xdrproc_t)
270 		    xdr_directory_results_rpc;
271 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
272 		    _directory_get_common_1;
273 		break;
274 
275 	default:
276 		svcerr_noproc(transp);
277 		(void) mutex_lock(&_svcstate_lock);
278 		_rpcsvccount--;
279 		_rpcsvcstate = _SERVED;
280 		(void) mutex_unlock(&_svcstate_lock);
281 		return; /* CSTYLED */
282 	}
283 	(void) memset((char *)&argument, 0, sizeof (argument));
284 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
285 		svcerr_decode(transp);
286 		(void) mutex_lock(&_svcstate_lock);
287 		_rpcsvccount--;
288 		_rpcsvcstate = _SERVED;
289 		(void) mutex_unlock(&_svcstate_lock);
290 		return; /* CSTYLED */
291 	}
292 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
293 	if (_xdr_result && retval > 0 &&
294 	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
295 		svcerr_systemerr(transp);
296 	}
297 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
298 		RPC_MSGOUT("%s",
299 		    "unable to free arguments");
300 		exit(1);
301 	}
302 	if (_xdr_result != NULL) {
303 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
304 		    (caddr_t)&result))
305 			RPC_MSGOUT("%s",
306 			    "unable to free results");
307 
308 	}
309 	(void) mutex_lock(&_svcstate_lock);
310 	_rpcsvccount--;
311 	_rpcsvcstate = _SERVED;
312 	(void) mutex_unlock(&_svcstate_lock);
313 	return; /* CSTYLED */
314 }
315