1*4520Snw141292 /*
2*4520Snw141292  * CDDL HEADER START
3*4520Snw141292  *
4*4520Snw141292  * The contents of this file are subject to the terms of the
5*4520Snw141292  * Common Development and Distribution License (the "License").
6*4520Snw141292  * You may not use this file except in compliance with the License.
7*4520Snw141292  *
8*4520Snw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*4520Snw141292  * or http://www.opensolaris.org/os/licensing.
10*4520Snw141292  * See the License for the specific language governing permissions
11*4520Snw141292  * and limitations under the License.
12*4520Snw141292  *
13*4520Snw141292  * When distributing Covered Code, include this CDDL HEADER in each
14*4520Snw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*4520Snw141292  * If applicable, add the following below this CDDL HEADER, with the
16*4520Snw141292  * fields enclosed by brackets "[]" replaced with your own identifying
17*4520Snw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
18*4520Snw141292  *
19*4520Snw141292  * CDDL HEADER END
20*4520Snw141292  */
21*4520Snw141292 /*
22*4520Snw141292  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*4520Snw141292  * Use is subject to license terms.
24*4520Snw141292  */
25*4520Snw141292 
26*4520Snw141292 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*4520Snw141292 
28*4520Snw141292 /*
29*4520Snw141292  * RPC service routines
30*4520Snw141292  * It was initially generated using rpcgen.
31*4520Snw141292  */
32*4520Snw141292 
33*4520Snw141292 #include "idmapd.h"
34*4520Snw141292 #include "idmap_prot.h"
35*4520Snw141292 #include <stdlib.h>
36*4520Snw141292 #include <signal.h>
37*4520Snw141292 #include <rpc/xdr.h>
38*4520Snw141292 #include <rpc/rpc.h>
39*4520Snw141292 #include <string.h>
40*4520Snw141292 #include <thread.h>
41*4520Snw141292 #include <synch.h>
42*4520Snw141292 
43*4520Snw141292 
44*4520Snw141292 /* ARGSUSED */
45*4520Snw141292 int
46*4520Snw141292 _idmap_null_1(void  *argp, void *result, struct svc_req *rqstp)
47*4520Snw141292 {
48*4520Snw141292 	return (idmap_null_1_svc(result, rqstp));
49*4520Snw141292 }
50*4520Snw141292 
51*4520Snw141292 int
52*4520Snw141292 _idmap_get_mapped_ids_1(idmap_mapping_batch  *argp, idmap_ids_res *result,
53*4520Snw141292 		struct svc_req *rqstp) {
54*4520Snw141292 	return (idmap_get_mapped_ids_1_svc(*argp, result, rqstp));
55*4520Snw141292 }
56*4520Snw141292 
57*4520Snw141292 int
58*4520Snw141292 _idmap_list_mappings_1(idmap_list_mappings_1_argument *argp,
59*4520Snw141292 		idmap_mappings_res *result, struct svc_req *rqstp) {
60*4520Snw141292 	return (idmap_list_mappings_1_svc(argp->is_user, argp->lastrowid,
61*4520Snw141292 		argp->limit, result, rqstp));
62*4520Snw141292 }
63*4520Snw141292 
64*4520Snw141292 int
65*4520Snw141292 _idmap_list_namerules_1(idmap_list_namerules_1_argument *argp,
66*4520Snw141292 		idmap_namerules_res *result, struct svc_req *rqstp) {
67*4520Snw141292 	return (idmap_list_namerules_1_svc(argp->rule, argp->lastrowid,
68*4520Snw141292 		argp->limit, result, rqstp));
69*4520Snw141292 }
70*4520Snw141292 
71*4520Snw141292 int
72*4520Snw141292 _idmap_update_1(idmap_update_batch  *argp, idmap_retcode *result,
73*4520Snw141292 		struct svc_req *rqstp) {
74*4520Snw141292 	return (idmap_update_1_svc(*argp, result, rqstp));
75*4520Snw141292 }
76*4520Snw141292 
77*4520Snw141292 int
78*4520Snw141292 _idmap_get_mapped_id_by_name_1(idmap_mapping  *argp,
79*4520Snw141292 		idmap_mappings_res *result, struct svc_req *rqstp) {
80*4520Snw141292 	return (idmap_get_mapped_id_by_name_1_svc(*argp, result, rqstp));
81*4520Snw141292 }
82*4520Snw141292 
83*4520Snw141292 
84*4520Snw141292 void
85*4520Snw141292 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
86*4520Snw141292 {
87*4520Snw141292 	union {
88*4520Snw141292 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
89*4520Snw141292 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
90*4520Snw141292 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
91*4520Snw141292 		idmap_update_batch idmap_update_1_arg;
92*4520Snw141292 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
93*4520Snw141292 	} argument;
94*4520Snw141292 	union {
95*4520Snw141292 		idmap_ids_res idmap_get_mapped_ids_1_res;
96*4520Snw141292 		idmap_mappings_res idmap_list_mappings_1_res;
97*4520Snw141292 		idmap_namerules_res idmap_list_namerules_1_res;
98*4520Snw141292 		idmap_retcode idmap_update_1_res;
99*4520Snw141292 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
100*4520Snw141292 	} result;
101*4520Snw141292 	bool_t retval;
102*4520Snw141292 	xdrproc_t _xdr_argument, _xdr_result;
103*4520Snw141292 	bool_t (*local)(char *, void *, struct svc_req *);
104*4520Snw141292 
105*4520Snw141292 	(void) mutex_lock(&_svcstate_lock);
106*4520Snw141292 	_rpcsvccount++;
107*4520Snw141292 	(void) mutex_unlock(&_svcstate_lock);
108*4520Snw141292 	switch (rqstp->rq_proc) {
109*4520Snw141292 	case IDMAP_NULL:
110*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_void;
111*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_void;
112*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
113*4520Snw141292 		    _idmap_null_1;
114*4520Snw141292 		break;
115*4520Snw141292 
116*4520Snw141292 	case IDMAP_GET_MAPPED_IDS:
117*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping_batch;
118*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_ids_res;
119*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
120*4520Snw141292 		    _idmap_get_mapped_ids_1;
121*4520Snw141292 		break;
122*4520Snw141292 
123*4520Snw141292 	case IDMAP_LIST_MAPPINGS:
124*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument;
125*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
126*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
127*4520Snw141292 		    _idmap_list_mappings_1;
128*4520Snw141292 		break;
129*4520Snw141292 
130*4520Snw141292 	case IDMAP_LIST_NAMERULES:
131*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument;
132*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_namerules_res;
133*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
134*4520Snw141292 		    _idmap_list_namerules_1;
135*4520Snw141292 		break;
136*4520Snw141292 
137*4520Snw141292 	case IDMAP_UPDATE:
138*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_update_batch;
139*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_retcode;
140*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
141*4520Snw141292 		    _idmap_update_1;
142*4520Snw141292 		break;
143*4520Snw141292 
144*4520Snw141292 	case IDMAP_GET_MAPPED_ID_BY_NAME:
145*4520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping;
146*4520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
147*4520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
148*4520Snw141292 		    _idmap_get_mapped_id_by_name_1;
149*4520Snw141292 		break;
150*4520Snw141292 
151*4520Snw141292 	default:
152*4520Snw141292 		svcerr_noproc(transp);
153*4520Snw141292 		(void) mutex_lock(&_svcstate_lock);
154*4520Snw141292 		_rpcsvccount--;
155*4520Snw141292 		_rpcsvcstate = _SERVED;
156*4520Snw141292 		(void) mutex_unlock(&_svcstate_lock);
157*4520Snw141292 		return;
158*4520Snw141292 	}
159*4520Snw141292 	(void) memset((char *)&argument, 0, sizeof (argument));
160*4520Snw141292 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
161*4520Snw141292 		svcerr_decode(transp);
162*4520Snw141292 		(void) mutex_lock(&_svcstate_lock);
163*4520Snw141292 		_rpcsvccount--;
164*4520Snw141292 		_rpcsvcstate = _SERVED;
165*4520Snw141292 		(void) mutex_unlock(&_svcstate_lock);
166*4520Snw141292 		return;
167*4520Snw141292 	}
168*4520Snw141292 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
169*4520Snw141292 	if (_xdr_result && retval > 0 && !svc_sendreply(transp, _xdr_result,
170*4520Snw141292 	    (char *)&result)) {
171*4520Snw141292 		svcerr_systemerr(transp);
172*4520Snw141292 	}
173*4520Snw141292 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
174*4520Snw141292 		idmapdlog(LOG_ERR,
175*4520Snw141292 		    "unable to free RPC arguments");
176*4520Snw141292 		exit(1);
177*4520Snw141292 	}
178*4520Snw141292 	if (_xdr_result != NULL) {
179*4520Snw141292 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
180*4520Snw141292 		    (caddr_t)&result))
181*4520Snw141292 			idmapdlog(LOG_ERR,
182*4520Snw141292 			    "unable to free RPC results");
183*4520Snw141292 
184*4520Snw141292 	}
185*4520Snw141292 	(void) mutex_lock(&_svcstate_lock);
186*4520Snw141292 	_rpcsvccount--;
187*4520Snw141292 	_rpcsvcstate = _SERVED;
188*4520Snw141292 	(void) mutex_unlock(&_svcstate_lock);
189*4520Snw141292 }
190