4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This source was formally rpcgen generated, but has been
36 #include <stdlib.h> /* getenv, exit */
38 #include <rpc/pmap_clnt.h> /* for pmap_unset */
39 #include <string.h> /* strcmp */
40 #include <unistd.h> /* setsid */
41 #include <sys/types.h>
44 #include <netconfig.h>
45 #include <sys/resource.h> /* rlimit */
52 #define SIG_PF void(*)(int)
59 #define _RPCSVC_CLOSEDOWN 120
62 * Copyr 1989 Sun Micro
63 * #ident "@(#)ypxfrd.x 1.2 00/05/01 SMI"
64 * This is NOT source code!
65 * DO NOT EDIT THIS FILE!
67 static int _rpcpmstart
; /* Started by a port monitor ? */
69 /* States a server can be in wrt request */
74 static int _rpcsvcstate
= _IDLE
; /* Set when a request is serviced */
75 static int _rpcsvccount
= 0; /* Number of requests being serviced */
82 syslog(LOG_ERR
, "%s", msg
);
84 (void) fprintf(stderr
, "%s\n", msg
);
86 syslog(LOG_ERR
, "%s", msg
);
93 if (_rpcsvcstate
== _IDLE
&& _rpcsvccount
== 0) {
97 size
= svc_max_pollfd
;
98 for (i
= 0; i
< size
&& openfd
< 2; i
++)
99 if (svc_pollfd
[i
].fd
>= 0)
104 _rpcsvcstate
= _IDLE
;
106 (void) signal(SIGALRM
, (SIG_PF
) closedown
);
107 (void) alarm(_RPCSVC_CLOSEDOWN
/2);
111 ypxfrd_1(struct svc_req
*rqstp
, register SVCXPRT
*transp
)
114 hosereq getdbm_1_arg
;
117 xdrproc_t _xdr_argument
, _xdr_result
;
118 char *(*local
)(char *, struct svc_req
*);
121 switch (rqstp
->rq_proc
) {
123 (void) svc_sendreply(transp
,
124 (xdrproc_t
)xdr_void
, NULL
);
126 _rpcsvcstate
= _SERVED
;
130 _xdr_argument
= (xdrproc_t
)xdr_hosereq
;
131 _xdr_result
= (xdrproc_t
)xdr_dbmfyl
;
132 local
= (char *(*)(char *, struct svc_req
*)) getdbm_1_svc
;
136 svcerr_noproc(transp
);
138 _rpcsvcstate
= _SERVED
;
141 (void) memset((char *)&argument
, 0, sizeof (argument
));
142 if (!svc_getargs(transp
, _xdr_argument
, (caddr_t
)&argument
)) {
143 svcerr_decode(transp
);
145 _rpcsvcstate
= _SERVED
;
148 result
= (*local
)((char *)&argument
, rqstp
);
149 if (_xdr_result
&& result
!= NULL
&&
150 !svc_sendreply(transp
, _xdr_result
, result
)) {
151 svcerr_systemerr(transp
);
153 if (!svc_freeargs(transp
, _xdr_argument
, (caddr_t
)&argument
)) {
154 _msgout("unable to free arguments");
158 _rpcsvcstate
= _SERVED
;
168 (void) sigset(SIGPIPE
, SIG_IGN
);
171 * If stdin looks like a TLI endpoint, we assume
172 * that we were started by a port monitor. If
173 * t_getstate fails with TBADF, this is not a
176 if (t_getstate(0) != -1 || t_errno
!= TBADF
) {
178 struct netconfig
*nconf
= NULL
;
183 openlog("ypxfrd", LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
185 if ((netid
= getenv("NLSPROVIDER")) == NULL
) {
186 /* started from inetd */
189 if ((nconf
= getnetconfigent(netid
)) == NULL
)
190 _msgout("cannot get transport info");
192 pmclose
= (t_getstate(0) != T_DATAXFER
);
194 if ((transp
= svc_tli_create(0, nconf
, NULL
, 0, 0)) == NULL
) {
195 _msgout("cannot create server handle");
199 freenetconfigent(nconf
);
200 if (!svc_reg(transp
, YPXFRD
, V1
, ypxfrd_1
, 0)) {
201 _msgout("unable to register (YPXFRD, V1).");
205 (void) signal(SIGALRM
, (SIG_PF
) closedown
);
206 (void) alarm(_RPCSVC_CLOSEDOWN
/2);
210 stat
= parseConfig(NULL
, NTOL_MAP_FILE
);
212 _msgout("NIS to LDAP mapping inactive.");
213 } else if (stat
!= 0) {
214 _msgout("Aborting after NIS to LDAP "
225 #pragma weak closefrom
226 extern void closefrom();
231 perror("cannot fork");
237 if (closefrom
!= NULL
)
241 getrlimit(RLIMIT_NOFILE
, &rl
);
242 if ((size
= rl
.rlim_max
) == 0)
244 for (i
= 0; i
< size
; i
++)
247 i
= open("/dev/null", O_RDWR
);
250 openlog("ypxfrd", LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
256 stat
= parseConfig(NULL
, NTOL_MAP_FILE
);
258 _msgout("NIS to LDAP mapping inactive.");
259 } else if (stat
!= 0) {
260 _msgout("Aborting after NIS to LDAP mapping error.");
265 if (!svc_create(ypxfrd_1
, YPXFRD
, V1
, "visible")) {
266 _msgout("unable to create (YPXFRD, V1) for visible.");
271 _msgout("svc_run returned");