|
root / base / usr / src / cmd / idmap / idmapd / adspriv_srv.c
adspriv_srv.c C 186 lines 4.3 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * Please do not edit this file.
 * It was generated using rpcgen.
 */

#include "ads_priv.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <signal.h>
#include <rpc/pmap_clnt.h> /* for pmap_unset */
#include <string.h> /* strcmp */
#include <unistd.h> /* setsid */
#include <sys/types.h>
#include <memory.h>
#include <stropts.h>
#include <sys/resource.h> /* rlimit */
#include <syslog.h>

#ifndef SIG_PF
#define	SIG_PF void(*)(int)
#endif

#ifdef DEBUG
#define	RPC_SVC_FG
#endif

#define	_RPCSVC_CLOSEDOWN 120
/*
 * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
 */
/*
 * from ads_priv.x
 * Active Directory Services (ADS) Private interface between
 * libads and the ADS deamon.  (RPC over doors)
 */

/*
 *  Server side stubs for the ADS API
 */

extern int _rpcpmstart;		/* Started by a port monitor ? */

/* States a server can be in wrt request */

#define	_IDLE 0
#define	_SERVED 1

/* LINTED static unused if no main */
static int _rpcsvcstate = _IDLE;	/* Set when a request is serviced */
static int _rpcsvccount = 0;		/* Number of requests being serviced */
extern mutex_t _svcstate_lock;		/* lock for _rpcsvcstate, _rpcsvccount */

#if	defined(RPC_MSGOUT)
extern void RPC_MSGOUT(const char *, ...);
#else	/* defined(RPC_MSGOUT) */
static void
RPC_MSGOUT(const char *fmt, char *msg)
{
#ifdef RPC_SVC_FG
	if (_rpcpmstart)
		syslog(LOG_ERR, fmt, msg);
	else {
		(void) fprintf(stderr, fmt, msg);
		(void) putc('\n', stderr);
	}
#else
	syslog(LOG_ERR, fmt, msg);
#endif
}
#endif	/* defined(RPC_MSGOUT) */

/* ARGSUSED */
int
_adspriv_null_1(
    void  *argp,
    void *result,
    struct svc_req *rqstp)
{
	return (adspriv_null_1_svc(result, rqstp));
}

int
_adspriv_forcerediscovery_1(
    DsForceRediscoveryArgs  *argp,
    int *result,
    struct svc_req *rqstp)
{
	return (adspriv_forcerediscovery_1_svc(*argp, result, rqstp));
}

int
_adspriv_getdcname_1(
    DsGetDcNameArgs  *argp,
    DsGetDcNameRes *result,
    struct svc_req *rqstp)
{
	return (adspriv_getdcname_1_svc(*argp, result, rqstp));
}

void
adspriv_program_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
	union {
		DsForceRediscoveryArgs adspriv_forcerediscovery_1_arg;
		DsGetDcNameArgs adspriv_getdcname_1_arg;
	} argument;
	union {
		int adspriv_forcerediscovery_1_res;
		DsGetDcNameRes adspriv_getdcname_1_res;
	} result;
	bool_t retval;
	xdrproc_t _xdr_argument, _xdr_result;
	bool_t (*local)(char *, void *, struct svc_req *);

	(void) mutex_lock(&_svcstate_lock);
	_rpcsvccount++;
	(void) mutex_unlock(&_svcstate_lock);
	switch (rqstp->rq_proc) {
	case ADSPRIV_NULL:
		_xdr_argument = (xdrproc_t)
		    xdr_void;
		_xdr_result = (xdrproc_t)
		    xdr_void;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _adspriv_null_1;
		break;

	case ADSPRIV_ForceRediscovery:
		_xdr_argument = (xdrproc_t)
		    xdr_DsForceRediscoveryArgs;
		_xdr_result = (xdrproc_t)
		    xdr_int;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _adspriv_forcerediscovery_1;
		break;

	case ADSPRIV_GetDcName:
		_xdr_argument = (xdrproc_t)
		    xdr_DsGetDcNameArgs;
		_xdr_result = (xdrproc_t)
		    xdr_DsGetDcNameRes;
		local = (bool_t (*) (char *,  void *,  struct svc_req *))
		    _adspriv_getdcname_1;
		break;

	default:
		svcerr_noproc(transp);
		(void) mutex_lock(&_svcstate_lock);
		_rpcsvccount--;
		_rpcsvcstate = _SERVED;
		(void) mutex_unlock(&_svcstate_lock);
		return; /* CSTYLED */
	}
	(void) memset((char *)&argument, 0, sizeof (argument));
	if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
		svcerr_decode(transp);
		(void) mutex_lock(&_svcstate_lock);
		_rpcsvccount--;
		_rpcsvcstate = _SERVED;
		(void) mutex_unlock(&_svcstate_lock);
		return; /* CSTYLED */
	}
	retval = (bool_t)(*local)((char *)&argument, (void *)&result, rqstp);
	if (_xdr_result && retval > 0 &&
	    !svc_sendreply(transp, _xdr_result, (char *)&result)) {
		svcerr_systemerr(transp);
	}
	if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
		RPC_MSGOUT("%s",
		    "unable to free arguments");
		exit(1);
	}
	if (_xdr_result != NULL) {
		if (!adspriv_program_1_freeresult(transp, _xdr_result,
		    (caddr_t)&result))
			RPC_MSGOUT("%s",
			    "unable to free results");

	}
	(void) mutex_lock(&_svcstate_lock);
	_rpcsvccount--;
	_rpcsvcstate = _SERVED;
	(void) mutex_unlock(&_svcstate_lock);
	return; /* CSTYLED */
}