Deleted Added
full compact
chap.c (48817) chap.c (49976)
1/*
2 * PPP CHAP Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP CHAP Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: chap.c,v 1.52 1999/06/09 08:47:29 brian Exp $
20 * $Id: chap.c,v 1.53 1999/07/15 02:02:51 brian Exp $
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>
29
30#include <errno.h>
31#include <fcntl.h>
32#ifdef HAVE_DES
33#include <md4.h>
34#endif
35#include <md5.h>
36#include <paths.h>
37#include <signal.h>
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>
29
30#include <errno.h>
31#include <fcntl.h>
32#ifdef HAVE_DES
33#include <md4.h>
34#endif
35#include <md5.h>
36#include <paths.h>
37#include <signal.h>
38#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <sys/wait.h>
41#include <termios.h>
42#include <unistd.h>
43
44#include "layer.h"
45#include "mbuf.h"

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

226 close(out[1]);
227 chap->child.pid = 0;
228 return;
229
230 case 0:
231 timer_TermService();
232 close(in[1]);
233 close(out[0]);
39#include <stdlib.h>
40#include <string.h>
41#include <sys/wait.h>
42#include <termios.h>
43#include <unistd.h>
44
45#include "layer.h"
46#include "mbuf.h"

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

227 close(out[1]);
228 chap->child.pid = 0;
229 return;
230
231 case 0:
232 timer_TermService();
233 close(in[1]);
234 close(out[0]);
234 if (out[1] == STDIN_FILENO) {
235 fd = dup(out[1]);
236 close(out[1]);
237 out[1] = fd;
238 }
235 if (out[1] == STDIN_FILENO)
236 out[1] = dup(out[1]);
239 dup2(in[0], STDIN_FILENO);
240 dup2(out[1], STDOUT_FILENO);
237 dup2(in[0], STDIN_FILENO);
238 dup2(out[1], STDOUT_FILENO);
241 if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
239 close(STDERR_FILENO);
240 if (open(_PATH_DEVNULL, O_RDWR) != STDERR_FILENO) {
242 log_Printf(LogALERT, "Chap: Failed to open %s: %s\n",
243 _PATH_DEVNULL, strerror(errno));
244 exit(1);
245 }
241 log_Printf(LogALERT, "Chap: Failed to open %s: %s\n",
242 _PATH_DEVNULL, strerror(errno));
243 exit(1);
244 }
246 dup2(fd, STDERR_FILENO);
247 fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
248
245 for (fd = getdtablesize(); fd > STDERR_FILENO; fd--)
246 fcntl(fd, F_SETFD, 1);
249 setuid(geteuid());
250 argc = command_Interpret(prog, strlen(prog), argv);
251 command_Expand(nargv, argc, (char const *const *)argv,
252 chap->auth.physical->dl->bundle, 0, pid);
253 execvp(nargv[0], nargv);
247 setuid(geteuid());
248 argc = command_Interpret(prog, strlen(prog), argv);
249 command_Expand(nargv, argc, (char const *const *)argv,
250 chap->auth.physical->dl->bundle, 0, pid);
251 execvp(nargv[0], nargv);
252 printf("exec() of %s failed: %s\n", nargv[0], strerror(errno));
253 _exit(255);
254
254
255 log_Printf(LogWARN, "exec() of %s failed: %s\n",
256 nargv[0], strerror(errno));
257 exit(255);
258
259 default:
260 close(in[0]);
261 close(out[1]);
262 chap->child.fd = out[0];
263 chap->child.buf.len = 0;
264 write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
265 write(in[1], "\n", 1);
266 write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);

--- 512 unchanged lines hidden ---
255 default:
256 close(in[0]);
257 close(out[1]);
258 chap->child.fd = out[0];
259 chap->child.buf.len = 0;
260 write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
261 write(in[1], "\n", 1);
262 write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);

--- 512 unchanged lines hidden ---