xref: /titanic_41/usr/src/cmd/idmap/idmapd/rpc_svc.c (revision 8e50dcc9f00b393d43e6aa42b820bcbf1d3e1ce4)
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 
89 void
90 idmap_prog_1(struct svc_req *rqstp, register SVCXPRT *transp)
91 {
92 	union {
93 		idmap_mapping_batch idmap_get_mapped_ids_1_arg;
94 		idmap_list_mappings_1_argument idmap_list_mappings_1_arg;
95 		idmap_list_namerules_1_argument idmap_list_namerules_1_arg;
96 		idmap_update_batch idmap_update_1_arg;
97 		idmap_mapping idmap_get_mapped_id_by_name_1_arg;
98 	} argument;
99 	union {
100 		idmap_ids_res idmap_get_mapped_ids_1_res;
101 		idmap_mappings_res idmap_list_mappings_1_res;
102 		idmap_namerules_res idmap_list_namerules_1_res;
103 		idmap_update_res idmap_update_1_res;
104 		idmap_mappings_res idmap_get_mapped_id_by_name_1_res;
105 	} result;
106 	bool_t retval;
107 	xdrproc_t _xdr_argument, _xdr_result;
108 	bool_t (*local)(char *, void *, struct svc_req *);
109 
110 	(void) mutex_lock(&_svcstate_lock);
111 	_rpcsvccount++;
112 	(void) mutex_unlock(&_svcstate_lock);
113 	switch (rqstp->rq_proc) {
114 	case IDMAP_NULL:
115 		_xdr_argument = (xdrproc_t)xdr_void;
116 		_xdr_result = (xdrproc_t)xdr_void;
117 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
118 		    _idmap_null_1;
119 		break;
120 
121 	case IDMAP_GET_MAPPED_IDS:
122 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping_batch;
123 		_xdr_result = (xdrproc_t)xdr_idmap_ids_res;
124 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
125 		    _idmap_get_mapped_ids_1;
126 		break;
127 
128 	case IDMAP_LIST_MAPPINGS:
129 		_xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument;
130 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
131 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
132 		    _idmap_list_mappings_1;
133 		break;
134 
135 	case IDMAP_LIST_NAMERULES:
136 		_xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument;
137 		_xdr_result = (xdrproc_t)xdr_idmap_namerules_res;
138 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
139 		    _idmap_list_namerules_1;
140 		break;
141 
142 	case IDMAP_UPDATE:
143 		_xdr_argument = (xdrproc_t)xdr_idmap_update_batch;
144 		_xdr_result = (xdrproc_t)xdr_idmap_update_res;
145 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
146 		    _idmap_update_1;
147 		break;
148 
149 	case IDMAP_GET_MAPPED_ID_BY_NAME:
150 		_xdr_argument = (xdrproc_t)xdr_idmap_mapping;
151 		_xdr_result = (xdrproc_t)xdr_idmap_mappings_res;
152 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
153 		    _idmap_get_mapped_id_by_name_1;
154 		break;
155 
156 	default:
157 		svcerr_noproc(transp);
158 		(void) mutex_lock(&_svcstate_lock);
159 		_rpcsvccount--;
160 		_rpcsvcstate = _SERVED;
161 		(void) mutex_unlock(&_svcstate_lock);
162 		return;
163 	}
164 	(void) memset((char *)&argument, 0, sizeof (argument));
165 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
166 		svcerr_decode(transp);
167 		(void) mutex_lock(&_svcstate_lock);
168 		_rpcsvccount--;
169 		_rpcsvcstate = _SERVED;
170 		(void) mutex_unlock(&_svcstate_lock);
171 		return;
172 	}
173 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
174 	if (_xdr_result && retval > 0 && !svc_sendreply(transp, _xdr_result,
175 	    (char *)&result)) {
176 		svcerr_systemerr(transp);
177 	}
178 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
179 		idmapdlog(LOG_ERR,
180 		    "unable to free RPC arguments");
181 		exit(1);
182 	}
183 	if (_xdr_result != NULL) {
184 		if (!idmap_prog_1_freeresult(transp, _xdr_result,
185 		    (caddr_t)&result))
186 			idmapdlog(LOG_ERR,
187 			    "unable to free RPC results");
188 
189 	}
190 	(void) mutex_lock(&_svcstate_lock);
191 	_rpcsvccount--;
192 	_rpcsvcstate = _SERVED;
193 	(void) mutex_unlock(&_svcstate_lock);
194 }
195