xref: /titanic_41/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision 257873cfc1dd3337766407f80397db60a56f2f5a)
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 2008 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 {
55 	return (idmap_get_mapped_ids_1_svc(*argp, result, rqstp));
56 }
57 
58 int
59 _idmap_list_mappings_1(idmap_list_mappings_1_argument *argp,
60 		idmap_mappings_res *result, struct svc_req *rqstp)
61 {
62 	return (idmap_list_mappings_1_svc(argp->lastrowid,
63 	    argp->limit, argp->flag, result, rqstp));
64 }
65 
66 int
67 _idmap_list_namerules_1(idmap_list_namerules_1_argument *argp,
68 		idmap_namerules_res *result, struct svc_req *rqstp)
69 {
70 	return (idmap_list_namerules_1_svc(argp->rule, argp->lastrowid,
71 	    argp->limit, result, rqstp));
72 }
73 
74 int
75 _idmap_update_1(idmap_update_batch  *argp, idmap_update_res *res,
76 		struct svc_req *rqstp)
77 {
78 	return (idmap_update_1_svc(*argp, res, rqstp));
79 }
80 
81 int
82 _idmap_get_mapped_id_by_name_1(idmap_mapping  *argp,
83 		idmap_mappings_res *result, struct svc_req *rqstp)
84 {
85 	return (idmap_get_mapped_id_by_name_1_svc(*argp, result, rqstp));
86 }
87 
88 int
89 _idmap_get_prop_1(idmap_prop_type  *argp,
90 		idmap_prop_res *result, struct svc_req *rqstp)
91 {
92 	return (idmap_get_prop_1_svc(*argp, result, rqstp));
93 }
94 
95 
96 
97 void
98 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
99 {
100 	union {
101 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
102 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
103 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
104 		idmap_update_batch idmap_update_1_arg;
105 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
106 		idmap_prop_type idmap_get_prop_1_arg;
107 	} argument;
108 	union {
109 		idmap_ids_res idmap_get_mapped_ids_1_res;
110 		idmap_mappings_res idmap_list_mappings_1_res;
111 		idmap_namerules_res idmap_list_namerules_1_res;
112 		idmap_update_res idmap_update_1_res;
113 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
114 		idmap_prop_res idmap_get_prop_1_res;
115 	} result;
116 	bool_t retval;
117 	xdrproc_t _xdr_argument, _xdr_result;
118 	bool_t (*local)(char *, void *, struct svc_req *);
119 
120 	(void) mutex_lock(&_svcstate_lock);
121 	_rpcsvccount++;
122 	(void) mutex_unlock(&_svcstate_lock);
123 	switch (rqstp->rq_proc) {
124 	case IDMAP_NULL:
125 		_xdr_argument = (xdrproc_t)xdr_void;
126 		_xdr_result = (xdrproc_t)xdr_void;
127 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
128 		    _idmap_null_1;
129 		break;
130 
131 	case IDMAP_GET_MAPPED_IDS:
132 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping_batch;
133 		_xdr_result = (xdrproc_t)xdr_idmap_ids_res;
134 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
135 		    _idmap_get_mapped_ids_1;
136 		break;
137 
138 	case IDMAP_LIST_MAPPINGS:
139 		_xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument;
140 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
141 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
142 		    _idmap_list_mappings_1;
143 		break;
144 
145 	case IDMAP_LIST_NAMERULES:
146 		_xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument;
147 		_xdr_result = (xdrproc_t)xdr_idmap_namerules_res;
148 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
149 		    _idmap_list_namerules_1;
150 		break;
151 
152 	case IDMAP_UPDATE:
153 		_xdr_argument = (xdrproc_t)xdr_idmap_update_batch;
154 		_xdr_result = (xdrproc_t)xdr_idmap_update_res;
155 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
156 		    _idmap_update_1;
157 		break;
158 
159 	case IDMAP_GET_MAPPED_ID_BY_NAME:
160 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping;
161 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
162 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
163 		    _idmap_get_mapped_id_by_name_1;
164 		break;
165 
166 	case IDMAP_GET_PROP:
167 		_xdr_argument = (xdrproc_t)xdr_idmap_prop_type;
168 		_xdr_result = (xdrproc_t)xdr_idmap_prop_res;
169 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
170 		    _idmap_get_prop_1;
171 		break;
172 
173 	default:
174 		svcerr_noproc(transp);
175 		(void) mutex_lock(&_svcstate_lock);
176 		_rpcsvccount--;
177 		_rpcsvcstate = _SERVED;
178 		(void) mutex_unlock(&_svcstate_lock);
179 		return;
180 	}
181 	(void) memset((char *)&argument, 0, sizeof (argument));
182 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
183 		svcerr_decode(transp);
184 		(void) mutex_lock(&_svcstate_lock);
185 		_rpcsvccount--;
186 		_rpcsvcstate = _SERVED;
187 		(void) mutex_unlock(&_svcstate_lock);
188 		return;
189 	}
190 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
191 	if (_xdr_result && retval > 0 && !svc_sendreply(transp, _xdr_result,
192 	    (char *)&result)) {
193 		svcerr_systemerr(transp);
194 	}
195 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
196 		idmapdlog(LOG_ERR,
197 		    "unable to free RPC arguments");
198 		exit(1);
199 	}
200 	if (_xdr_result != NULL) {
201 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
202 		    (caddr_t)&result))
203 			idmapdlog(LOG_ERR,
204 			    "unable to free RPC results");
205 
206 	}
207 	(void) mutex_lock(&_svcstate_lock);
208 	_rpcsvccount--;
209 	_rpcsvcstate = _SERVED;
210 	(void) mutex_unlock(&_svcstate_lock);
211 }
212