1 /*
2  * Please do not edit this file.
3  * It was generated using rpcgen.
4  */
5 
6 #include "../../../lib/libads/common/ads_priv.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 /*
29  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
30  */
31 /*
32  * from ads_priv.x
33  * Active Directory Services (ADS) Private interface between
34  * libads and the ADS deamon.  (RPC over doors)
35  */
36 
37 /*
38  *  Server side stubs for the ADS API
39  */
40 
41 extern int _rpcpmstart;		/* Started by a port monitor ? */
42 
43 /* States a server can be in wrt request */
44 
45 #define	_IDLE 0
46 #define	_SERVED 1
47 
48 /* LINTED static unused if no main */
49 static int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
50 static int _rpcsvccount = 0;		/* Number of requests being serviced */
51 mutex_t _svcstate_lock;		/* lock for _rpcsvcstate, _rpcsvccount */
52 
53 #if	defined(RPC_MSGOUT)
54 extern void RPC_MSGOUT(const char *, ...);
55 #else	/* defined(RPC_MSGOUT) */
56 static void
57 RPC_MSGOUT(const char *fmt, char *msg)
58 {
59 #ifdef RPC_SVC_FG
60 	if (_rpcpmstart)
61 		syslog(LOG_ERR, fmt, msg);
62 	else {
63 		(void) fprintf(stderr, fmt, msg);
64 		(void) putc('\n', stderr);
65 	}
66 #else
67 	syslog(LOG_ERR, fmt, msg);
68 #endif
69 }
70 #endif	/* defined(RPC_MSGOUT) */
71 
72 /* ARGSUSED */
73 int
74 _adspriv_null_1(
75     void  *argp,
76     void *result,
77     struct svc_req *rqstp)
78 {
79 	return (adspriv_null_1_svc(result, rqstp));
80 }
81 
82 int
83 _adspriv_forcerediscovery_1(
84     DsForceRediscoveryArgs  *argp,
85     int *result,
86     struct svc_req *rqstp)
87 {
88 	return (adspriv_forcerediscovery_1_svc(*argp, result, rqstp));
89 }
90 
91 int
92 _adspriv_getdcname_1(
93     DsGetDcNameArgs  *argp,
94     DsGetDcNameRes *result,
95     struct svc_req *rqstp)
96 {
97 	return (adspriv_getdcname_1_svc(*argp, result, rqstp));
98 }
99 
100 void
101 adspriv_program_1(struct svc_req *rqstp, register SVCXPRT *transp)
102 {
103 	union {
104 		DsForceRediscoveryArgs adspriv_forcerediscovery_1_arg;
105 		DsGetDcNameArgs adspriv_getdcname_1_arg;
106 	} argument;
107 	union {
108 		int adspriv_forcerediscovery_1_res;
109 		DsGetDcNameRes adspriv_getdcname_1_res;
110 	} result;
111 	bool_t retval;
112 	xdrproc_t _xdr_argument, _xdr_result;
113 	bool_t (*local)(char *, void *, struct svc_req *);
114 
115 	(void) mutex_lock(&_svcstate_lock);
116 	_rpcsvccount++;
117 	(void) mutex_unlock(&_svcstate_lock);
118 	switch (rqstp->rq_proc) {
119 	case ADSPRIV_NULL:
120 		_xdr_argument = (xdrproc_t)
121 		    xdr_void;
122 		_xdr_result = (xdrproc_t)
123 		    xdr_void;
124 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
125 		    _adspriv_null_1;
126 		break;
127 
128 	case ADSPRIV_ForceRediscovery:
129 		_xdr_argument = (xdrproc_t)
130 		    xdr_DsForceRediscoveryArgs;
131 		_xdr_result = (xdrproc_t)
132 		    xdr_int;
133 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
134 		    _adspriv_forcerediscovery_1;
135 		break;
136 
137 	case ADSPRIV_GetDcName:
138 		_xdr_argument = (xdrproc_t)
139 		    xdr_DsGetDcNameArgs;
140 		_xdr_result = (xdrproc_t)
141 		    xdr_DsGetDcNameRes;
142 		local = (bool_t (*) (char *,  void *,  struct svc_req *))
143 		    _adspriv_getdcname_1;
144 		break;
145 
146 	default:
147 		svcerr_noproc(transp);
148 		(void) mutex_lock(&_svcstate_lock);
149 		_rpcsvccount--;
150 		_rpcsvcstate = _SERVED;
151 		(void) mutex_unlock(&_svcstate_lock);
152 		return; /* CSTYLED */
153 	}
154 	(void) memset((char *)&argument, 0, sizeof (argument));
155 	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
156 		svcerr_decode(transp);
157 		(void) mutex_lock(&_svcstate_lock);
158 		_rpcsvccount--;
159 		_rpcsvcstate = _SERVED;
160 		(void) mutex_unlock(&_svcstate_lock);
161 		return; /* CSTYLED */
162 	}
163 	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
164 	if (_xdr_result && retval > 0 &&
165 	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
166 		svcerr_systemerr(transp);
167 	}
168 	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
169 		RPC_MSGOUT("%s",
170 		    "unable to free arguments");
171 		exit(1);
172 	}
173 	if (_xdr_result != NULL) {
174 		if (!adspriv_program_1_freeresult(transp, _xdr_result,
175 		    (caddr_t)&result))
176 			RPC_MSGOUT("%s",
177 			    "unable to free results");
178 
179 	}
180 	(void) mutex_lock(&_svcstate_lock);
181 	_rpcsvccount--;
182 	_rpcsvcstate = _SERVED;
183 	(void) mutex_unlock(&_svcstate_lock);
184 	return; /* CSTYLED */
185 }
186