1 /*
2  * Please do not edit this file.
3  * It was generated using rpcgen.
4  */
5 
6 #include "../common/fmd_rpc_adm.h"
7 #include <stdio.h>
8 #include <stdlib.h> /* getenv, exit */
9 #include <signal.h>
10 #include <rpc/pmap_clnt.h> /* for pmap_unset */
11 #include <string.h> /* strcmp */
12 #include <unistd.h> /* setsid */
13 #include <sys/types.h>
14 #include <memory.h>
15 #include <stropts.h>
16 #include <sys/resource.h> /* rlimit */
17 #include <syslog.h>
18 
19 #ifndef SIG_PF
20 #define	SIG_PF void(*)(int)
21 #endif
22 
23 #ifdef DEBUG
24 #define	RPC_SVC_FG
25 #endif
26 
27 #define	_RPCSVC_CLOSEDOWN 120
28 #include <fm/fmd_api.h>
29 extern void fmd_adm_1(struct svc_req *, SVCXPRT *);
30 extern bool_t xdr_fmd_stat(XDR *, struct fmd_stat *);
31 #undef	RW_READ_HELD
32 #undef	RW_WRITE_HELD
33 #undef	RW_LOCK_HELD
34 #undef	MUTEX_HELD
35 extern int _rpcpmstart;		/* Started by a port monitor ? */
36 
37 /* States a server can be in wrt request */
38 
39 #define	_IDLE 0
40 #define	_SERVED 1
41 
42 /* LINTED static unused if no main */
43 static int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
44 static int _rpcsvccount = 0;		/* Number of requests being serviced */
45 mutex_t _svcstate_lock;		/* lock for _rpcsvcstate, _rpcsvccount */
46 
47 #if	defined(RPC_MSGOUT)
48 extern void RPC_MSGOUT(const char *, ...);
49 #else	/* defined(RPC_MSGOUT) */
50 static void
51 RPC_MSGOUT(const char *fmt, char *msg)
52 {
53 #ifdef RPC_SVC_FG
54 	if (_rpcpmstart)
55 		syslog(LOG_ERR, fmt, msg);
56 	else {
57 		(void) fprintf(stderr, fmt, msg);
58 		(void) putc('\n', stderr);
59 	}
60 #else
61 	syslog(LOG_ERR, fmt, msg);
62 #endif
63 }
64 #endif	/* defined(RPC_MSGOUT) */
65 
66 /* ARGSUSED */
67 int
68 _fmd_adm_modinfo_1(
69     void  *argp,
70     struct fmd_rpc_modlist *result,
71     struct svc_req *rqstp)
72 {
73 	return (fmd_adm_modinfo_1_svc(result, rqstp));
74 }
75 
76 int
77 _fmd_adm_modcstat_1(
78     char * *argp,
79     struct fmd_rpc_modstat *result,
80     struct svc_req *rqstp)
81 {
82 	return (fmd_adm_modcstat_1_svc(*argp, result, rqstp));
83 }
84 
85 int
86 _fmd_adm_moddstat_1(
87     char * *argp,
88     struct fmd_rpc_modstat *result,
89     struct svc_req *rqstp)
90 {
91 	return (fmd_adm_moddstat_1_svc(*argp, result, rqstp));
92 }
93 
94 /* ARGSUSED */
95 int
96 _fmd_adm_modgstat_1(
97     void  *argp,
98     struct fmd_rpc_modstat *result,
99     struct svc_req *rqstp)
100 {
101 	return (fmd_adm_modgstat_1_svc(result, rqstp));
102 }
103 
104 int
105 _fmd_adm_modload_1(
106     char * *argp,
107     int *result,
108     struct svc_req *rqstp)
109 {
110 	return (fmd_adm_modload_1_svc(*argp, result, rqstp));
111 }
112 
113 int
114 _fmd_adm_modunload_1(
115     char * *argp,
116     int *result,
117     struct svc_req *rqstp)
118 {
119 	return (fmd_adm_modunload_1_svc(*argp, result, rqstp));
120 }
121 
122 int
123 _fmd_adm_modreset_1(
124     char * *argp,
125     int *result,
126     struct svc_req *rqstp)
127 {
128 	return (fmd_adm_modreset_1_svc(*argp, result, rqstp));
129 }
130 
131 int
132 _fmd_adm_modgc_1(
133     char * *argp,
134     int *result,
135     struct svc_req *rqstp)
136 {
137 	return (fmd_adm_modgc_1_svc(*argp, result, rqstp));
138 }
139 
140 int
141 _fmd_adm_rsrclist_1(
142     bool_t  *argp,
143     struct fmd_rpc_rsrclist *result,
144     struct svc_req *rqstp)
145 {
146 	return (fmd_adm_rsrclist_1_svc(*argp, result, rqstp));
147 }
148 
149 int
150 _fmd_adm_rsrcinfo_1(
151     char * *argp,
152     struct fmd_rpc_rsrcinfo *result,
153     struct svc_req *rqstp)
154 {
155 	return (fmd_adm_rsrcinfo_1_svc(*argp, result, rqstp));
156 }
157 
158 int
159 _fmd_adm_rsrcflush_1(
160     char * *argp,
161     int *result,
162     struct svc_req *rqstp)
163 {
164 	return (fmd_adm_rsrcflush_1_svc(*argp, result, rqstp));
165 }
166 
167 int
168 _fmd_adm_rsrcrepaired_1(
169     char * *argp,
170     int *result,
171     struct svc_req *rqstp)
172 {
173 	return (fmd_adm_rsrcrepaired_1_svc(*argp, result, rqstp));
174 }
175 
176 int
177 _fmd_adm_serdinfo_old_1(
178     char * *argp,
179     struct fmd_rpc_serdlist *result,
180     struct svc_req *rqstp)
181 {
182 	return (fmd_adm_serdinfo_old_1_svc(*argp, result, rqstp));
183 }
184 
185 int
186 _fmd_adm_serdreset_1(
187     fmd_adm_serdreset_1_argument *argp,
188     int *result,
189     struct svc_req *rqstp)
190 {
191 	return (fmd_adm_serdreset_1_svc(
192 	    argp->arg1,
193 	    argp->arg2,
194 	    result, rqstp));
195 }
196 
197 int
198 _fmd_adm_logrotate_1(
199     char * *argp,
200     int *result,
201     struct svc_req *rqstp)
202 {
203 	return (fmd_adm_logrotate_1_svc(*argp, result, rqstp));
204 }
205 
206 int
207 _fmd_adm_caserepair_1(
208     char * *argp,
209     int *result,
210     struct svc_req *rqstp)
211 {
212 	return (fmd_adm_caserepair_1_svc(*argp, result, rqstp));
213 }
214 
215 /* ARGSUSED */
216 int
217 _fmd_adm_xprtlist_1(
218     void  *argp,
219     struct fmd_rpc_xprtlist *result,
220     struct svc_req *rqstp)
221 {
222 	return (fmd_adm_xprtlist_1_svc(result, rqstp));
223 }
224 
225 int
226 _fmd_adm_xprtstat_1(
227     int32_t  *argp,
228     struct fmd_rpc_modstat *result,
229     struct svc_req *rqstp)
230 {
231 	return (fmd_adm_xprtstat_1_svc(*argp, result, rqstp));
232 }
233 
234 /* ARGSUSED */
235 int
236 _fmd_adm_caselist_1(
237     void  *argp,
238     struct fmd_rpc_caselist *result,
239     struct svc_req *rqstp)
240 {
241 	return (fmd_adm_caselist_1_svc(result, rqstp));
242 }
243 
244 int
245 _fmd_adm_caseinfo_1(
246     char * *argp,
247     struct fmd_rpc_caseinfo *result,
248     struct svc_req *rqstp)
249 {
250 	return (fmd_adm_caseinfo_1_svc(*argp, result, rqstp));
251 }
252 
253 int
254 _fmd_adm_rsrcreplaced_1(
255     char * *argp,
256     int *result,
257     struct svc_req *rqstp)
258 {
259 	return (fmd_adm_rsrcreplaced_1_svc(*argp, result, rqstp));
260 }
261 
262 int
263 _fmd_adm_rsrcacquit_1(
264     fmd_adm_rsrcacquit_1_argument *argp,
265     int *result,
266     struct svc_req *rqstp)
267 {
268 	return (fmd_adm_rsrcacquit_1_svc(
269 	    argp->arg1,
270 	    argp->arg2,
271 	    result, rqstp));
272 }
273 
274 int
275 _fmd_adm_caseacquit_1(
276     char * *argp,
277     int *result,
278     struct svc_req *rqstp)
279 {
280 	return (fmd_adm_caseacquit_1_svc(*argp, result, rqstp));
281 }
282 
283 int
284 _fmd_adm_serdlist_1(
285     char * *argp,
286     struct fmd_rpc_serdlist *result,
287     struct svc_req *rqstp)
288 {
289 	return (fmd_adm_serdlist_1_svc(*argp, result, rqstp));
290 }
291 
292 int
293 _fmd_adm_serdinfo_1(
294     fmd_adm_serdinfo_1_argument *argp,
295     struct fmd_rpc_serdinfo *result,
296     struct svc_req *rqstp)
297 {
298 	return (fmd_adm_serdinfo_1_svc(
299 	    argp->arg1,
300 	    argp->arg2,
301 	    result, rqstp));
302 }
303 
304 void
305 fmd_adm_1(struct svc_req *rqstp, register SVCXPRT *transp)
306 {
307 	union {
308 		char *fmd_adm_modcstat_1_arg;
309 		char *fmd_adm_moddstat_1_arg;
310 		char *fmd_adm_modload_1_arg;
311 		char *fmd_adm_modunload_1_arg;
312 		char *fmd_adm_modreset_1_arg;
313 		char *fmd_adm_modgc_1_arg;
314 		bool_t fmd_adm_rsrclist_1_arg;
315 		char *fmd_adm_rsrcinfo_1_arg;
316 		char *fmd_adm_rsrcflush_1_arg;
317 		char *fmd_adm_rsrcrepaired_1_arg;
318 		char *fmd_adm_serdinfo_old_1_arg;
319 		fmd_adm_serdreset_1_argument fmd_adm_serdreset_1_arg;
320 		char *fmd_adm_logrotate_1_arg;
321 		char *fmd_adm_caserepair_1_arg;
322 		int32_t fmd_adm_xprtstat_1_arg;
323 		char *fmd_adm_caseinfo_1_arg;
324 		char *fmd_adm_rsrcreplaced_1_arg;
325 		fmd_adm_rsrcacquit_1_argument fmd_adm_rsrcacquit_1_arg;
326 		char *fmd_adm_caseacquit_1_arg;
327 		char *fmd_adm_serdlist_1_arg;
328 		fmd_adm_serdinfo_1_argument fmd_adm_serdinfo_1_arg;
329 	} argument;
330 	union {
331 		struct fmd_rpc_modlist fmd_adm_modinfo_1_res;
332 		struct fmd_rpc_modstat fmd_adm_modcstat_1_res;
333 		struct fmd_rpc_modstat fmd_adm_moddstat_1_res;
334 		struct fmd_rpc_modstat fmd_adm_modgstat_1_res;
335 		int fmd_adm_modload_1_res;
336 		int fmd_adm_modunload_1_res;
337 		int fmd_adm_modreset_1_res;
338 		int fmd_adm_modgc_1_res;
339 		struct fmd_rpc_rsrclist fmd_adm_rsrclist_1_res;
340 		struct fmd_rpc_rsrcinfo fmd_adm_rsrcinfo_1_res;
341 		int fmd_adm_rsrcflush_1_res;
342 		int fmd_adm_rsrcrepaired_1_res;
343 		struct fmd_rpc_serdlist fmd_adm_serdinfo_old_1_res;
344 		int fmd_adm_serdreset_1_res;
345 		int fmd_adm_logrotate_1_res;
346 		int fmd_adm_caserepair_1_res;
347 		struct fmd_rpc_xprtlist fmd_adm_xprtlist_1_res;
348 		struct fmd_rpc_modstat fmd_adm_xprtstat_1_res;
349 		struct fmd_rpc_caselist fmd_adm_caselist_1_res;
350 		struct fmd_rpc_caseinfo fmd_adm_caseinfo_1_res;
351 		int fmd_adm_rsrcreplaced_1_res;
352 		int fmd_adm_rsrcacquit_1_res;
353 		int fmd_adm_caseacquit_1_res;
354 		struct fmd_rpc_serdlist fmd_adm_serdlist_1_res;
355 		struct fmd_rpc_serdinfo fmd_adm_serdinfo_1_res;
356 	} result;
357 	bool_t retval;
358 	xdrproc_t _xdr_argument, _xdr_result;
359 	bool_t (*local)(char *, void *, struct svc_req *);
360 
361 	(void) mutex_lock(&_svcstate_lock);
362 	_rpcsvccount++;
363 	(void) mutex_unlock(&_svcstate_lock);
364 	switch (rqstp->rq_proc) {
365 	case NULLPROC:
366 		(void) svc_sendreply(transp,
367 		    (xdrproc_t)xdr_void, NULL);
368 		(void) mutex_lock(&_svcstate_lock);
369 		_rpcsvccount--;
370 		_rpcsvcstate = _SERVED;
371 		(void) mutex_unlock(&_svcstate_lock);
372 		return; /* CSTYLED */
373 
374 	case FMD_ADM_MODINFO:
375 		_xdr_argument = (xdrproc_t)
376 		    xdr_void;
377 		_xdr_result = (xdrproc_t)
378 		    xdr_fmd_rpc_modlist;
379 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
380 		    _fmd_adm_modinfo_1;
381 		break;
382 
383 	case FMD_ADM_MODCSTAT:
384 		_xdr_argument = (xdrproc_t)
385 		    xdr_wrapstring;
386 		_xdr_result = (xdrproc_t)
387 		    xdr_fmd_rpc_modstat;
388 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
389 		    _fmd_adm_modcstat_1;
390 		break;
391 
392 	case FMD_ADM_MODDSTAT:
393 		_xdr_argument = (xdrproc_t)
394 		    xdr_wrapstring;
395 		_xdr_result = (xdrproc_t)
396 		    xdr_fmd_rpc_modstat;
397 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
398 		    _fmd_adm_moddstat_1;
399 		break;
400 
401 	case FMD_ADM_MODGSTAT:
402 		_xdr_argument = (xdrproc_t)
403 		    xdr_void;
404 		_xdr_result = (xdrproc_t)
405 		    xdr_fmd_rpc_modstat;
406 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
407 		    _fmd_adm_modgstat_1;
408 		break;
409 
410 	case FMD_ADM_MODLOAD:
411 		_xdr_argument = (xdrproc_t)
412 		    xdr_wrapstring;
413 		_xdr_result = (xdrproc_t)
414 		    xdr_int;
415 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
416 		    _fmd_adm_modload_1;
417 		break;
418 
419 	case FMD_ADM_MODUNLOAD:
420 		_xdr_argument = (xdrproc_t)
421 		    xdr_wrapstring;
422 		_xdr_result = (xdrproc_t)
423 		    xdr_int;
424 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
425 		    _fmd_adm_modunload_1;
426 		break;
427 
428 	case FMD_ADM_MODRESET:
429 		_xdr_argument = (xdrproc_t)
430 		    xdr_wrapstring;
431 		_xdr_result = (xdrproc_t)
432 		    xdr_int;
433 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
434 		    _fmd_adm_modreset_1;
435 		break;
436 
437 	case FMD_ADM_MODGC:
438 		_xdr_argument = (xdrproc_t)
439 		    xdr_wrapstring;
440 		_xdr_result = (xdrproc_t)
441 		    xdr_int;
442 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
443 		    _fmd_adm_modgc_1;
444 		break;
445 
446 	case FMD_ADM_RSRCLIST:
447 		_xdr_argument = (xdrproc_t)
448 		    xdr_bool;
449 		_xdr_result = (xdrproc_t)
450 		    xdr_fmd_rpc_rsrclist;
451 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
452 		    _fmd_adm_rsrclist_1;
453 		break;
454 
455 	case FMD_ADM_RSRCINFO:
456 		_xdr_argument = (xdrproc_t)
457 		    xdr_wrapstring;
458 		_xdr_result = (xdrproc_t)
459 		    xdr_fmd_rpc_rsrcinfo;
460 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
461 		    _fmd_adm_rsrcinfo_1;
462 		break;
463 
464 	case FMD_ADM_RSRCFLUSH:
465 		_xdr_argument = (xdrproc_t)
466 		    xdr_wrapstring;
467 		_xdr_result = (xdrproc_t)
468 		    xdr_int;
469 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
470 		    _fmd_adm_rsrcflush_1;
471 		break;
472 
473 	case FMD_ADM_RSRCREPAIRED:
474 		_xdr_argument = (xdrproc_t)
475 		    xdr_wrapstring;
476 		_xdr_result = (xdrproc_t)
477 		    xdr_int;
478 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
479 		    _fmd_adm_rsrcrepaired_1;
480 		break;
481 
482 	case FMD_ADM_SERDINFO_OLD:
483 		_xdr_argument = (xdrproc_t)
484 		    xdr_wrapstring;
485 		_xdr_result = (xdrproc_t)
486 		    xdr_fmd_rpc_serdlist;
487 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
488 		    _fmd_adm_serdinfo_old_1;
489 		break;
490 
491 	case FMD_ADM_SERDRESET:
492 		_xdr_argument = (xdrproc_t)
493 		    xdr_fmd_adm_serdreset_1_argument;
494 		_xdr_result = (xdrproc_t)
495 		    xdr_int;
496 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
497 		    _fmd_adm_serdreset_1;
498 		break;
499 
500 	case FMD_ADM_LOGROTATE:
501 		_xdr_argument = (xdrproc_t)
502 		    xdr_wrapstring;
503 		_xdr_result = (xdrproc_t)
504 		    xdr_int;
505 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
506 		    _fmd_adm_logrotate_1;
507 		break;
508 
509 	case FMD_ADM_CASEREPAIR:
510 		_xdr_argument = (xdrproc_t)
511 		    xdr_wrapstring;
512 		_xdr_result = (xdrproc_t)
513 		    xdr_int;
514 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
515 		    _fmd_adm_caserepair_1;
516 		break;
517 
518 	case FMD_ADM_XPRTLIST:
519 		_xdr_argument = (xdrproc_t)
520 		    xdr_void;
521 		_xdr_result = (xdrproc_t)
522 		    xdr_fmd_rpc_xprtlist;
523 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
524 		    _fmd_adm_xprtlist_1;
525 		break;
526 
527 	case FMD_ADM_XPRTSTAT:
528 		_xdr_argument = (xdrproc_t)
529 		    xdr_int32_t;
530 		_xdr_result = (xdrproc_t)
531 		    xdr_fmd_rpc_modstat;
532 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
533 		    _fmd_adm_xprtstat_1;
534 		break;
535 
536 	case FMD_ADM_CASELIST:
537 		_xdr_argument = (xdrproc_t)
538 		    xdr_void;
539 		_xdr_result = (xdrproc_t)
540 		    xdr_fmd_rpc_caselist;
541 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
542 		    _fmd_adm_caselist_1;
543 		break;
544 
545 	case FMD_ADM_CASEINFO:
546 		_xdr_argument = (xdrproc_t)
547 		    xdr_wrapstring;
548 		_xdr_result = (xdrproc_t)
549 		    xdr_fmd_rpc_caseinfo;
550 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
551 		    _fmd_adm_caseinfo_1;
552 		break;
553 
554 	case FMD_ADM_RSRCREPLACED:
555 		_xdr_argument = (xdrproc_t)
556 		    xdr_wrapstring;
557 		_xdr_result = (xdrproc_t)
558 		    xdr_int;
559 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
560 		    _fmd_adm_rsrcreplaced_1;
561 		break;
562 
563 	case FMD_ADM_RSRCACQUIT:
564 		_xdr_argument = (xdrproc_t)
565 		    xdr_fmd_adm_rsrcacquit_1_argument;
566 		_xdr_result = (xdrproc_t)
567 		    xdr_int;
568 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
569 		    _fmd_adm_rsrcacquit_1;
570 		break;
571 
572 	case FMD_ADM_CASEACQUIT:
573 		_xdr_argument = (xdrproc_t)
574 		    xdr_wrapstring;
575 		_xdr_result = (xdrproc_t)
576 		    xdr_int;
577 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
578 		    _fmd_adm_caseacquit_1;
579 		break;
580 
581 	case FMD_ADM_SERDLIST:
582 		_xdr_argument = (xdrproc_t)
583 		    xdr_wrapstring;
584 		_xdr_result = (xdrproc_t)
585 		    xdr_fmd_rpc_serdlist;
586 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
587 		    _fmd_adm_serdlist_1;
588 		break;
589 
590 	case FMD_ADM_SERDINFO:
591 		_xdr_argument = (xdrproc_t)
592 		    xdr_fmd_adm_serdinfo_1_argument;
593 		_xdr_result = (xdrproc_t)
594 		    xdr_fmd_rpc_serdinfo;
595 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
596 		    _fmd_adm_serdinfo_1;
597 		break;
598 
599 	default:
600 		svcerr_noproc(transp);
601 		(void) mutex_lock(&_svcstate_lock);
602 		_rpcsvccount--;
603 		_rpcsvcstate = _SERVED;
604 		(void) mutex_unlock(&_svcstate_lock);
605 		return; /* CSTYLED */
606 	}
607 	(void) memset((char *)&argument, 0, sizeof (argument));
608 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
609 		svcerr_decode(transp);
610 		(void) mutex_lock(&_svcstate_lock);
611 		_rpcsvccount--;
612 		_rpcsvcstate = _SERVED;
613 		(void) mutex_unlock(&_svcstate_lock);
614 		return; /* CSTYLED */
615 	}
616 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
617 	if (_xdr_result && retval > 0 &&
618 	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
619 		svcerr_systemerr(transp);
620 	}
621 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
622 		RPC_MSGOUT("%s",
623 		    "unable to free arguments");
624 		exit(1);
625 	}
626 	if (_xdr_result != NULL) {
627 		if (!fmd_adm_1_freeresult(transp, _xdr_result,
628 		    (caddr_t)&result))
629 			RPC_MSGOUT("%s",
630 			    "unable to free results");
631 
632 	}
633 	(void) mutex_lock(&_svcstate_lock);
634 	_rpcsvccount--;
635 	_rpcsvcstate = _SERVED;
636 	(void) mutex_unlock(&_svcstate_lock);
637 	return; /* CSTYLED */
638 }
639