xref: /titanic_44/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision f80ce222af313ec87dc070b2219b29c81c5e5d8c)
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 2010 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 int
175 _idmap_flush_1(
176     idmap_flush_op  *argp,
177     idmap_retcode *result,
178     struct svc_req *rqstp)
179 {
180 	return (idmap_flush_1_svc(*argp, result, rqstp));
181 }
182 
183 void
184 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
185 {
186 	union {
187 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
188 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
189 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
190 		idmap_update_batch idmap_update_1_arg;
191 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
192 		idmap_prop_type idmap_get_prop_1_arg;
193 		directory_get_common_1_argument directory_get_common_1_arg;
194 		idmap_flush_op idmap_flush_1_arg;
195 	} argument;
196 	union {
197 		idmap_ids_res idmap_get_mapped_ids_1_res;
198 		idmap_mappings_res idmap_list_mappings_1_res;
199 		idmap_namerules_res idmap_list_namerules_1_res;
200 		idmap_update_res idmap_update_1_res;
201 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
202 		idmap_prop_res idmap_get_prop_1_res;
203 		directory_results_rpc directory_get_common_1_res;
204 		idmap_retcode idmap_flush_1_res;
205 	} result;
206 	bool_t retval;
207 	xdrproc_t _xdr_argument, _xdr_result;
208 	bool_t (*local)(char *, void *, struct svc_req *);
209 
210 	(void) mutex_lock(&_svcstate_lock);
211 	_rpcsvccount++;
212 	(void) mutex_unlock(&_svcstate_lock);
213 	switch (rqstp->rq_proc) {
214 	case IDMAP_NULL:
215 		_xdr_argument = (xdrproc_t)
216 		    xdr_void;
217 		_xdr_result = (xdrproc_t)
218 		    xdr_void;
219 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
220 		    _idmap_null_1;
221 		break;
222 
223 	case IDMAP_GET_MAPPED_IDS:
224 		_xdr_argument = (xdrproc_t)
225 		    xdr_idmap_mapping_batch;
226 		_xdr_result = (xdrproc_t)
227 		    xdr_idmap_ids_res;
228 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
229 		    _idmap_get_mapped_ids_1;
230 		break;
231 
232 	case IDMAP_LIST_MAPPINGS:
233 		_xdr_argument = (xdrproc_t)
234 		    xdr_idmap_list_mappings_1_argument;
235 		_xdr_result = (xdrproc_t)
236 		    xdr_idmap_mappings_res;
237 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
238 		    _idmap_list_mappings_1;
239 		break;
240 
241 	case IDMAP_LIST_NAMERULES:
242 		_xdr_argument = (xdrproc_t)
243 		    xdr_idmap_list_namerules_1_argument;
244 		_xdr_result = (xdrproc_t)
245 		    xdr_idmap_namerules_res;
246 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
247 		    _idmap_list_namerules_1;
248 		break;
249 
250 	case IDMAP_UPDATE:
251 		_xdr_argument = (xdrproc_t)
252 		    xdr_idmap_update_batch;
253 		_xdr_result = (xdrproc_t)
254 		    xdr_idmap_update_res;
255 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
256 		    _idmap_update_1;
257 		break;
258 
259 	case IDMAP_GET_MAPPED_ID_BY_NAME:
260 		_xdr_argument = (xdrproc_t)
261 		    xdr_idmap_mapping;
262 		_xdr_result = (xdrproc_t)
263 		    xdr_idmap_mappings_res;
264 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
265 		    _idmap_get_mapped_id_by_name_1;
266 		break;
267 
268 	case IDMAP_GET_PROP:
269 		_xdr_argument = (xdrproc_t)
270 		    xdr_idmap_prop_type;
271 		_xdr_result = (xdrproc_t)
272 		    xdr_idmap_prop_res;
273 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
274 		    _idmap_get_prop_1;
275 		break;
276 
277 	case DIRECTORY_GET_COMMON:
278 		_xdr_argument = (xdrproc_t)
279 		    xdr_directory_get_common_1_argument;
280 		_xdr_result = (xdrproc_t)
281 		    xdr_directory_results_rpc;
282 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
283 		    _directory_get_common_1;
284 		break;
285 
286 	case IDMAP_FLUSH:
287 		_xdr_argument = (xdrproc_t)
288 		    xdr_idmap_flush_op;
289 		_xdr_result = (xdrproc_t)
290 		    xdr_idmap_retcode;
291 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
292 		    _idmap_flush_1;
293 		break;
294 
295 	default:
296 		svcerr_noproc(transp);
297 		(void) mutex_lock(&_svcstate_lock);
298 		_rpcsvccount--;
299 		_rpcsvcstate = _SERVED;
300 		(void) mutex_unlock(&_svcstate_lock);
301 		return; /* CSTYLED */
302 	}
303 	(void) memset((char *)&argument, 0, sizeof (argument));
304 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
305 		svcerr_decode(transp);
306 		(void) mutex_lock(&_svcstate_lock);
307 		_rpcsvccount--;
308 		_rpcsvcstate = _SERVED;
309 		(void) mutex_unlock(&_svcstate_lock);
310 		return; /* CSTYLED */
311 	}
312 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
313 	if (_xdr_result && retval > 0 &&
314 	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
315 		svcerr_systemerr(transp);
316 	}
317 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
318 		RPC_MSGOUT("%s",
319 		    "unable to free arguments");
320 		exit(1);
321 	}
322 	if (_xdr_result != NULL) {
323 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
324 		    (caddr_t)&result))
325 			RPC_MSGOUT("%s",
326 			    "unable to free results");
327 
328 	}
329 	(void) mutex_lock(&_svcstate_lock);
330 	_rpcsvccount--;
331 	_rpcsvcstate = _SERVED;
332 	(void) mutex_unlock(&_svcstate_lock);
333 	return; /* CSTYLED */
334 }
335