Deleted Added
full compact
yppasswdd_main.c (24428) yppasswdd_main.c (27758)
1/*
2 * Copyright (c) 1995, 1996
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1995, 1996
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: yppasswdd_main.c,v 1.9 1997/02/22 16:12:56 peter Exp $
32 * $Id: yppasswdd_main.c,v 1.2 1997/07/28 18:31:11 wpaul Exp $
33 */
34
35#include "yppasswd.h"
36#include <stdio.h>
37#include <sys/types.h>
38#include <stdlib.h> /* getenv, exit */
39#include <unistd.h>
40#include <string.h>

--- 13 unchanged lines hidden (view full) ---

54#include <netinet/in.h>
55#include <syslog.h>
56#include <err.h>
57#include <errno.h>
58#include <rpcsvc/yp.h>
59struct dom_binding {};
60#include <rpcsvc/ypclnt.h>
61#include "yppasswdd_extern.h"
33 */
34
35#include "yppasswd.h"
36#include <stdio.h>
37#include <sys/types.h>
38#include <stdlib.h> /* getenv, exit */
39#include <unistd.h>
40#include <string.h>

--- 13 unchanged lines hidden (view full) ---

54#include <netinet/in.h>
55#include <syslog.h>
56#include <err.h>
57#include <errno.h>
58#include <rpcsvc/yp.h>
59struct dom_binding {};
60#include <rpcsvc/ypclnt.h>
61#include "yppasswdd_extern.h"
62#include "yppasswd_comm.h"
62#include "yppasswd_private.h"
63#include "ypxfr_extern.h"
64
65#ifndef SIG_PF
66#define SIG_PF void(*)(int)
67#endif
68
69#ifdef DEBUG
70#define RPC_SVC_FG
71#endif
72
73#define _RPCSVC_CLOSEDOWN 120
74#ifndef lint
63#include "ypxfr_extern.h"
64
65#ifndef SIG_PF
66#define SIG_PF void(*)(int)
67#endif
68
69#ifdef DEBUG
70#define RPC_SVC_FG
71#endif
72
73#define _RPCSVC_CLOSEDOWN 120
74#ifndef lint
75static const char rcsid[] = "$Id: yppasswdd_main.c,v 1.9 1997/02/22 16:12:56 peter Exp $";
75static const char rcsid[] = "$Id: yppasswdd_main.c,v 1.2 1997/07/28 18:31:11 wpaul Exp $";
76#endif /* not lint */
77int _rpcpmstart = 0; /* Started by a port monitor ? */
78static int _rpcfdtype;
79 /* Whether Stream or Datagram ? */
80 /* States a server can be in wrt request */
81
82#define _IDLE 0
83#define _SERVED 1

--- 7 unchanged lines hidden (view full) ---

91char *yppasswd_domain = NULL;
92int no_chsh = 0;
93int no_chfn = 0;
94int allow_additions = 0;
95int multidomain = 0;
96int verbose = 0;
97int resvport = 1;
98int inplace = 0;
76#endif /* not lint */
77int _rpcpmstart = 0; /* Started by a port monitor ? */
78static int _rpcfdtype;
79 /* Whether Stream or Datagram ? */
80 /* States a server can be in wrt request */
81
82#define _IDLE 0
83#define _SERVED 1

--- 7 unchanged lines hidden (view full) ---

91char *yppasswd_domain = NULL;
92int no_chsh = 0;
93int no_chfn = 0;
94int allow_additions = 0;
95int multidomain = 0;
96int verbose = 0;
97int resvport = 1;
98int inplace = 0;
99int yp_sock;
99char *sockname = YP_SOCKNAME;
100
100
101
102static void
103my_svc_run()
104{
105#ifdef FD_SETSIZE
106 fd_set readfds;
107#else
108 int readfds;
109#endif /* def FD_SETSIZE */
110 extern int errno;
111
112 for (;;) {
113
114
115#ifdef FD_SETSIZE
116 readfds = svc_fdset;
117#else
118 readfds = svc_fds;
119#endif /* def FD_SETSIZE */
120 FD_SET(yp_sock, &readfds);
121
122 switch (select(_rpc_dtablesize(), &readfds, (fd_set *)0, (fd_set *)0,
123 (struct timeval *)0)) {
124 case -1:
125 if (errno == EINTR) {
126 continue;
127 }
128 perror("svc_run: - select failed");
129 return;
130 case 0:
131 continue;
132 default:
133 if (FD_ISSET(yp_sock, &readfds)) {
134 do_master();
135 FD_CLR(yp_sock, &readfds);
136 }
137 svc_getreqset(&readfds);
138 }
139 }
140}
141
142static void terminate(sig)
143 int sig;
144{
145 svc_unregister(YPPASSWDPROG, YPPASSWDVERS);
101static void terminate(sig)
102 int sig;
103{
104 svc_unregister(YPPASSWDPROG, YPPASSWDVERS);
146 close(yp_sock);
105 svc_unregister(MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS);
147 unlink(sockname);
148 exit(0);
149}
150
151static void reload(sig)
152 int sig;
153{
154 load_securenets();
155}
156
157static void
158closedown(int sig)
159{
160 if (_rpcsvcstate == _IDLE) {
161 extern fd_set svc_fdset;
162 static int size;
163 int i, openfd;
164
165 if (_rpcfdtype == SOCK_DGRAM) {
106 unlink(sockname);
107 exit(0);
108}
109
110static void reload(sig)
111 int sig;
112{
113 load_securenets();
114}
115
116static void
117closedown(int sig)
118{
119 if (_rpcsvcstate == _IDLE) {
120 extern fd_set svc_fdset;
121 static int size;
122 int i, openfd;
123
124 if (_rpcfdtype == SOCK_DGRAM) {
166 close(yp_sock);
167 unlink(sockname);
168 exit(0);
169 }
170 if (size == 0) {
171 size = getdtablesize();
172 }
173 for (i = 0, openfd = 0; i < size && openfd < 2; i++)
174 if (FD_ISSET(i, &svc_fdset))
175 openfd++;
176 if (openfd <= 1) {
125 unlink(sockname);
126 exit(0);
127 }
128 if (size == 0) {
129 size = getdtablesize();
130 }
131 for (i = 0, openfd = 0; i < size && openfd < 2; i++)
132 if (FD_ISSET(i, &svc_fdset))
133 openfd++;
134 if (openfd <= 1) {
177 close(yp_sock);
178 unlink(sockname);
179 exit(0);
180 }
181 }
182 if (_rpcsvcstate == _SERVED)
183 _rpcsvcstate = _IDLE;
184
185 (void) signal(SIGALRM, (SIG_PF) closedown);

--- 119 unchanged lines hidden (view full) ---

305 if (!debug) {
306 if (daemon(0,0)) {
307 err(1,"cannot fork");
308 }
309 }
310 openlog(progname, LOG_PID, LOG_DAEMON);
311 sock = RPC_ANYSOCK;
312 (void) pmap_unset(YPPASSWDPROG, YPPASSWDVERS);
135 unlink(sockname);
136 exit(0);
137 }
138 }
139 if (_rpcsvcstate == _SERVED)
140 _rpcsvcstate = _IDLE;
141
142 (void) signal(SIGALRM, (SIG_PF) closedown);

--- 119 unchanged lines hidden (view full) ---

262 if (!debug) {
263 if (daemon(0,0)) {
264 err(1,"cannot fork");
265 }
266 }
267 openlog(progname, LOG_PID, LOG_DAEMON);
268 sock = RPC_ANYSOCK;
269 (void) pmap_unset(YPPASSWDPROG, YPPASSWDVERS);
270 (void) pmap_unset(MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS);
271 unlink(sockname);
313 }
314
315 if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
316 transp = svcudp_create(sock);
317 if (transp == NULL) {
318 yp_error("cannot create udp service.");
319 exit(1);
320 }

--- 14 unchanged lines hidden (view full) ---

335 if (!_rpcpmstart)
336 proto = IPPROTO_TCP;
337 if (!svc_register(transp, YPPASSWDPROG, YPPASSWDVERS, yppasswdprog_1, proto)) {
338 yp_error("unable to register (YPPASSWDPROG, YPPASSWDVERS, tcp).");
339 exit(1);
340 }
341 }
342
272 }
273
274 if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
275 transp = svcudp_create(sock);
276 if (transp == NULL) {
277 yp_error("cannot create udp service.");
278 exit(1);
279 }

--- 14 unchanged lines hidden (view full) ---

294 if (!_rpcpmstart)
295 proto = IPPROTO_TCP;
296 if (!svc_register(transp, YPPASSWDPROG, YPPASSWDVERS, yppasswdprog_1, proto)) {
297 yp_error("unable to register (YPPASSWDPROG, YPPASSWDVERS, tcp).");
298 exit(1);
299 }
300 }
301
302 unlink(sockname);
303 transp = svcunix_create(sock, 0, 0, sockname);
304 if (transp == NULL) {
305 yp_error("cannot create AF_LOCAL service.");
306 exit(1);
307 }
308 if (!svc_register(transp, MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS, master_yppasswdprog_1, 0)) {
309 yp_error("unable to register (MASTER_YPPASSWDPROG, MASTER_YPPASSWDVERS, unix).");
310 exit(1);
311 }
312 /* Only root may connect() to the AF_UNIX link. */
313 if (chmod(sockname, 0))
314 err(1, "chmod of %s failed", sockname);
315
343 if (transp == (SVCXPRT *)NULL) {
344 yp_error("could not create a handle");
345 exit(1);
346 }
347 if (_rpcpmstart) {
348 (void) signal(SIGALRM, (SIG_PF) closedown);
349 (void) alarm(_RPCSVC_CLOSEDOWN/2);
350 }
351 /* set up resource limits and block signals */
352 pw_init();
353
354 /* except SIGCHLD, which we need to catch */
355 install_reaper(1);
356 signal(SIGTERM, (SIG_PF) terminate);
357
358 signal(SIGHUP, (SIG_PF) reload);
359
316 if (transp == (SVCXPRT *)NULL) {
317 yp_error("could not create a handle");
318 exit(1);
319 }
320 if (_rpcpmstart) {
321 (void) signal(SIGALRM, (SIG_PF) closedown);
322 (void) alarm(_RPCSVC_CLOSEDOWN/2);
323 }
324 /* set up resource limits and block signals */
325 pw_init();
326
327 /* except SIGCHLD, which we need to catch */
328 install_reaper(1);
329 signal(SIGTERM, (SIG_PF) terminate);
330
331 signal(SIGHUP, (SIG_PF) reload);
332
360 unlink(sockname);
361 yp_sock = makeservsock();
362 if (chmod(sockname, 0))
363 err(1, "chmod of %s failed", sockname);
364
365 my_svc_run();
333 svc_run();
366 yp_error("svc_run returned");
367 exit(1);
368 /* NOTREACHED */
369}
334 yp_error("svc_run returned");
335 exit(1);
336 /* NOTREACHED */
337}