xref: /onnv-gate/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision 6616:b32ce38b23ab)
14520Snw141292 /*
24520Snw141292  * CDDL HEADER START
34520Snw141292  *
44520Snw141292  * The contents of this file are subject to the terms of the
54520Snw141292  * Common Development and Distribution License (the "License").
64520Snw141292  * You may not use this file except in compliance with the License.
74520Snw141292  *
84520Snw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94520Snw141292  * or http://www.opensolaris.org/os/licensing.
104520Snw141292  * See the License for the specific language governing permissions
114520Snw141292  * and limitations under the License.
124520Snw141292  *
134520Snw141292  * When distributing Covered Code, include this CDDL HEADER in each
144520Snw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154520Snw141292  * If applicable, add the following below this CDDL HEADER, with the
164520Snw141292  * fields enclosed by brackets "[]" replaced with your own identifying
174520Snw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
184520Snw141292  *
194520Snw141292  * CDDL HEADER END
204520Snw141292  */
214520Snw141292 /*
226386Sjp151216  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
234520Snw141292  * Use is subject to license terms.
244520Snw141292  */
254520Snw141292 
264520Snw141292 #pragma ident	"%Z%%M%	%I%	%E% SMI"
274520Snw141292 
284520Snw141292 /*
294520Snw141292  * RPC service routines
304520Snw141292  * It was initially generated using rpcgen.
314520Snw141292  */
324520Snw141292 
334520Snw141292 #include "idmapd.h"
344520Snw141292 #include "idmap_prot.h"
354520Snw141292 #include <stdlib.h>
364520Snw141292 #include <signal.h>
374520Snw141292 #include <rpc/xdr.h>
384520Snw141292 #include <rpc/rpc.h>
394520Snw141292 #include <string.h>
404520Snw141292 #include <thread.h>
414520Snw141292 #include <synch.h>
424520Snw141292 
434520Snw141292 
444520Snw141292 /* ARGSUSED */
454520Snw141292 int
464520Snw141292 _idmap_null_1(void  *argp, void *result, struct svc_req *rqstp)
474520Snw141292 {
484520Snw141292 	return (idmap_null_1_svc(result, rqstp));
494520Snw141292 }
504520Snw141292 
514520Snw141292 int
524520Snw141292 _idmap_get_mapped_ids_1(idmap_mapping_batch  *argp, idmap_ids_res *result,
535696Snw141292 		struct svc_req *rqstp)
545696Snw141292 {
554520Snw141292 	return (idmap_get_mapped_ids_1_svc(*argp, result, rqstp));
564520Snw141292 }
574520Snw141292 
584520Snw141292 int
594520Snw141292 _idmap_list_mappings_1(idmap_list_mappings_1_argument *argp,
605696Snw141292 		idmap_mappings_res *result, struct svc_req *rqstp)
615696Snw141292 {
625696Snw141292 	return (idmap_list_mappings_1_svc(argp->lastrowid,
636386Sjp151216 	    argp->limit, argp->flag, result, rqstp));
644520Snw141292 }
654520Snw141292 
664520Snw141292 int
674520Snw141292 _idmap_list_namerules_1(idmap_list_namerules_1_argument *argp,
685696Snw141292 		idmap_namerules_res *result, struct svc_req *rqstp)
695696Snw141292 {
704520Snw141292 	return (idmap_list_namerules_1_svc(argp->rule, argp->lastrowid,
715696Snw141292 	    argp->limit, result, rqstp));
724520Snw141292 }
734520Snw141292 
744520Snw141292 int
755064Sdm199847 _idmap_update_1(idmap_update_batch  *argp, idmap_update_res *res,
765696Snw141292 		struct svc_req *rqstp)
775696Snw141292 {
785064Sdm199847 	return (idmap_update_1_svc(*argp, res, rqstp));
794520Snw141292 }
804520Snw141292 
814520Snw141292 int
824520Snw141292 _idmap_get_mapped_id_by_name_1(idmap_mapping  *argp,
835696Snw141292 		idmap_mappings_res *result, struct svc_req *rqstp)
845696Snw141292 {
854520Snw141292 	return (idmap_get_mapped_id_by_name_1_svc(*argp, result, rqstp));
864520Snw141292 }
874520Snw141292 
88*6616Sdm199847 int
89*6616Sdm199847 _idmap_get_prop_1(idmap_prop_type  *argp,
90*6616Sdm199847 		idmap_prop_res *result, struct svc_req *rqstp)
91*6616Sdm199847 {
92*6616Sdm199847 	return (idmap_get_prop_1_svc(*argp, result, rqstp));
93*6616Sdm199847 }
94*6616Sdm199847 
95*6616Sdm199847 
964520Snw141292 
974520Snw141292 void
984520Snw141292 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
994520Snw141292 {
1004520Snw141292 	union {
1014520Snw141292 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
1024520Snw141292 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
1034520Snw141292 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
1044520Snw141292 		idmap_update_batch idmap_update_1_arg;
1054520Snw141292 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
106*6616Sdm199847 		idmap_prop_type idmap_get_prop_1_arg;
1074520Snw141292 	} argument;
1084520Snw141292 	union {
1094520Snw141292 		idmap_ids_res idmap_get_mapped_ids_1_res;
1104520Snw141292 		idmap_mappings_res idmap_list_mappings_1_res;
1114520Snw141292 		idmap_namerules_res idmap_list_namerules_1_res;
1125064Sdm199847 		idmap_update_res idmap_update_1_res;
1134520Snw141292 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
114*6616Sdm199847 		idmap_prop_res idmap_get_prop_1_res;
1154520Snw141292 	} result;
1164520Snw141292 	bool_t retval;
1174520Snw141292 	xdrproc_t _xdr_argument, _xdr_result;
1184520Snw141292 	bool_t (*local)(char *, void *, struct svc_req *);
1194520Snw141292 
1204520Snw141292 	(void) mutex_lock(&_svcstate_lock);
1214520Snw141292 	_rpcsvccount++;
1224520Snw141292 	(void) mutex_unlock(&_svcstate_lock);
1234520Snw141292 	switch (rqstp->rq_proc) {
1244520Snw141292 	case IDMAP_NULL:
1254520Snw141292 		_xdr_argument = (xdrproc_t)xdr_void;
1264520Snw141292 		_xdr_result = (xdrproc_t)xdr_void;
1274520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1284520Snw141292 		    _idmap_null_1;
1294520Snw141292 		break;
1304520Snw141292 
1314520Snw141292 	case IDMAP_GET_MAPPED_IDS:
1324520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping_batch;
1334520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_ids_res;
1344520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1354520Snw141292 		    _idmap_get_mapped_ids_1;
1364520Snw141292 		break;
1374520Snw141292 
1384520Snw141292 	case IDMAP_LIST_MAPPINGS:
1394520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument;
1404520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
1414520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1424520Snw141292 		    _idmap_list_mappings_1;
1434520Snw141292 		break;
1444520Snw141292 
1454520Snw141292 	case IDMAP_LIST_NAMERULES:
1464520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument;
1474520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_namerules_res;
1484520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1494520Snw141292 		    _idmap_list_namerules_1;
1504520Snw141292 		break;
1514520Snw141292 
1524520Snw141292 	case IDMAP_UPDATE:
1534520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_update_batch;
1545064Sdm199847 		_xdr_result = (xdrproc_t)xdr_idmap_update_res;
1554520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1564520Snw141292 		    _idmap_update_1;
1574520Snw141292 		break;
1584520Snw141292 
1594520Snw141292 	case IDMAP_GET_MAPPED_ID_BY_NAME:
1604520Snw141292 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping;
1614520Snw141292 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
1624520Snw141292 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
1634520Snw141292 		    _idmap_get_mapped_id_by_name_1;
1644520Snw141292 		break;
1654520Snw141292 
166*6616Sdm199847 	case IDMAP_GET_PROP:
167*6616Sdm199847 		_xdr_argument = (xdrproc_t)xdr_idmap_prop_type;
168*6616Sdm199847 		_xdr_result = (xdrproc_t)xdr_idmap_prop_res;
169*6616Sdm199847 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
170*6616Sdm199847 		    _idmap_get_prop_1;
171*6616Sdm199847 		break;
172*6616Sdm199847 
1734520Snw141292 	default:
1744520Snw141292 		svcerr_noproc(transp);
1754520Snw141292 		(void) mutex_lock(&_svcstate_lock);
1764520Snw141292 		_rpcsvccount--;
1774520Snw141292 		_rpcsvcstate = _SERVED;
1784520Snw141292 		(void) mutex_unlock(&_svcstate_lock);
1794520Snw141292 		return;
1804520Snw141292 	}
1814520Snw141292 	(void) memset((char *)&argument, 0, sizeof (argument));
1824520Snw141292 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
1834520Snw141292 		svcerr_decode(transp);
1844520Snw141292 		(void) mutex_lock(&_svcstate_lock);
1854520Snw141292 		_rpcsvccount--;
1864520Snw141292 		_rpcsvcstate = _SERVED;
1874520Snw141292 		(void) mutex_unlock(&_svcstate_lock);
1884520Snw141292 		return;
1894520Snw141292 	}
1904520Snw141292 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
1914520Snw141292 	if (_xdr_result && retval > 0 && !svc_sendreply(transp, _xdr_result,
1924520Snw141292 	    (char *)&result)) {
1934520Snw141292 		svcerr_systemerr(transp);
1944520Snw141292 	}
1954520Snw141292 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
1964520Snw141292 		idmapdlog(LOG_ERR,
1974520Snw141292 		    "unable to free RPC arguments");
1984520Snw141292 		exit(1);
1994520Snw141292 	}
2004520Snw141292 	if (_xdr_result != NULL) {
2014520Snw141292 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
2024520Snw141292 		    (caddr_t)&result))
2034520Snw141292 			idmapdlog(LOG_ERR,
2044520Snw141292 			    "unable to free RPC results");
2054520Snw141292 
2064520Snw141292 	}
2074520Snw141292 	(void) mutex_lock(&_svcstate_lock);
2084520Snw141292 	_rpcsvccount--;
2094520Snw141292 	_rpcsvcstate = _SERVED;
2104520Snw141292 	(void) mutex_unlock(&_svcstate_lock);
2114520Snw141292 }
212