xref: /titanic_41/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision 5494fa53f9c55de7fb31e3bfb7e0da50d08159a5)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * RPC service routines
30  * It was initially generated using rpcgen.
31  */
32 
33 #include "idmapd.h"
34 #include "idmap_prot.h"
35 #include <stdlib.h>
36 #include <signal.h>
37 #include <rpc/xdr.h>
38 #include <rpc/rpc.h>
39 #include <string.h>
40 #include <thread.h>
41 #include <synch.h>
42 
43 
44 /* ARGSUSED */
45 int
46 _idmap_null_1(void  *argp, void *result, struct svc_req *rqstp)
47 {
48 	return (idmap_null_1_svc(result, rqstp));
49 }
50 
51 int
52 _idmap_get_mapped_ids_1(idmap_mapping_batch  *argp, idmap_ids_res *result,
53 		struct svc_req *rqstp) {
54 	return (idmap_get_mapped_ids_1_svc(*argp, result, rqstp));
55 }
56 
57 int
58 _idmap_list_mappings_1(idmap_list_mappings_1_argument *argp,
59 		idmap_mappings_res *result, struct svc_req *rqstp) {
60 	return (idmap_list_mappings_1_svc(argp->is_user, argp->lastrowid,
61 		argp->limit, result, rqstp));
62 }
63 
64 int
65 _idmap_list_namerules_1(idmap_list_namerules_1_argument *argp,
66 		idmap_namerules_res *result, struct svc_req *rqstp) {
67 	return (idmap_list_namerules_1_svc(argp->rule, argp->lastrowid,
68 		argp->limit, result, rqstp));
69 }
70 
71 int
72 _idmap_update_1(idmap_update_batch  *argp, idmap_retcode *result,
73 		struct svc_req *rqstp) {
74 	return (idmap_update_1_svc(*argp, result, rqstp));
75 }
76 
77 int
78 _idmap_get_mapped_id_by_name_1(idmap_mapping  *argp,
79 		idmap_mappings_res *result, struct svc_req *rqstp) {
80 	return (idmap_get_mapped_id_by_name_1_svc(*argp, result, rqstp));
81 }
82 
83 
84 void
85 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
86 {
87 	union {
88 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
89 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
90 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
91 		idmap_update_batch idmap_update_1_arg;
92 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
93 	} argument;
94 	union {
95 		idmap_ids_res idmap_get_mapped_ids_1_res;
96 		idmap_mappings_res idmap_list_mappings_1_res;
97 		idmap_namerules_res idmap_list_namerules_1_res;
98 		idmap_retcode idmap_update_1_res;
99 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
100 	} result;
101 	bool_t retval;
102 	xdrproc_t _xdr_argument, _xdr_result;
103 	bool_t (*local)(char *, void *, struct svc_req *);
104 
105 	(void) mutex_lock(&_svcstate_lock);
106 	_rpcsvccount++;
107 	(void) mutex_unlock(&_svcstate_lock);
108 	switch (rqstp->rq_proc) {
109 	case IDMAP_NULL:
110 		_xdr_argument = (xdrproc_t)xdr_void;
111 		_xdr_result = (xdrproc_t)xdr_void;
112 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
113 		    _idmap_null_1;
114 		break;
115 
116 	case IDMAP_GET_MAPPED_IDS:
117 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping_batch;
118 		_xdr_result = (xdrproc_t)xdr_idmap_ids_res;
119 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
120 		    _idmap_get_mapped_ids_1;
121 		break;
122 
123 	case IDMAP_LIST_MAPPINGS:
124 		_xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument;
125 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
126 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
127 		    _idmap_list_mappings_1;
128 		break;
129 
130 	case IDMAP_LIST_NAMERULES:
131 		_xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument;
132 		_xdr_result = (xdrproc_t)xdr_idmap_namerules_res;
133 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
134 		    _idmap_list_namerules_1;
135 		break;
136 
137 	case IDMAP_UPDATE:
138 		_xdr_argument = (xdrproc_t)xdr_idmap_update_batch;
139 		_xdr_result = (xdrproc_t)xdr_idmap_retcode;
140 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
141 		    _idmap_update_1;
142 		break;
143 
144 	case IDMAP_GET_MAPPED_ID_BY_NAME:
145 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping;
146 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
147 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
148 		    _idmap_get_mapped_id_by_name_1;
149 		break;
150 
151 	default:
152 		svcerr_noproc(transp);
153 		(void) mutex_lock(&_svcstate_lock);
154 		_rpcsvccount--;
155 		_rpcsvcstate = _SERVED;
156 		(void) mutex_unlock(&_svcstate_lock);
157 		return;
158 	}
159 	(void) memset((char *)&argument, 0, sizeof (argument));
160 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
161 		svcerr_decode(transp);
162 		(void) mutex_lock(&_svcstate_lock);
163 		_rpcsvccount--;
164 		_rpcsvcstate = _SERVED;
165 		(void) mutex_unlock(&_svcstate_lock);
166 		return;
167 	}
168 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
169 	if (_xdr_result && retval > 0 && !svc_sendreply(transp, _xdr_result,
170 	    (char *)&result)) {
171 		svcerr_systemerr(transp);
172 	}
173 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
174 		idmapdlog(LOG_ERR,
175 		    "unable to free RPC arguments");
176 		exit(1);
177 	}
178 	if (_xdr_result != NULL) {
179 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
180 		    (caddr_t)&result))
181 			idmapdlog(LOG_ERR,
182 			    "unable to free RPC results");
183 
184 	}
185 	(void) mutex_lock(&_svcstate_lock);
186 	_rpcsvccount--;
187 	_rpcsvcstate = _SERVED;
188 	(void) mutex_unlock(&_svcstate_lock);
189 }
190