Deleted Added
full compact
chat.c (48227) chat.c (49976)
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * 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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
3 * 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

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

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: chat.c,v 1.58 1999/06/26 02:54:24 brian Exp $
26 * $Id: chat.c,v 1.59 1999/06/26 02:54:36 brian Exp $
27 */
28
29#include <sys/param.h>
30#include <netinet/in.h>
31#include <netinet/in_systm.h>
32#include <netinet/ip.h>
33#include <sys/un.h>
34

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

677}
678
679static void
680ExecStr(struct physical *physical, char *command, char *out, int olen)
681{
682 pid_t pid;
683 int fids[2];
684 char *argv[MAXARGS], *vector[MAXARGS], *startout, *endout;
27 */
28
29#include <sys/param.h>
30#include <netinet/in.h>
31#include <netinet/in_systm.h>
32#include <netinet/ip.h>
33#include <sys/un.h>
34

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

677}
678
679static void
680ExecStr(struct physical *physical, char *command, char *out, int olen)
681{
682 pid_t pid;
683 int fids[2];
684 char *argv[MAXARGS], *vector[MAXARGS], *startout, *endout;
685 int stat, nb, argc;
685 int stat, nb, argc, i;
686
687 log_Printf(LogCHAT, "Exec: %s\n", command);
688 argc = MakeArgs(command, vector, VECSIZE(vector));
689 command_Expand(argv, argc, (char const *const *)vector,
690 physical->dl->bundle, 0, getpid());
691
692 if (pipe(fids) < 0) {
693 log_Printf(LogCHAT, "Unable to create pipe in ExecStr: %s\n",
694 strerror(errno));
695 *out = '\0';
696 return;
697 }
698 if ((pid = fork()) == 0) {
699 close(fids[0]);
700 timer_TermService();
686
687 log_Printf(LogCHAT, "Exec: %s\n", command);
688 argc = MakeArgs(command, vector, VECSIZE(vector));
689 command_Expand(argv, argc, (char const *const *)vector,
690 physical->dl->bundle, 0, getpid());
691
692 if (pipe(fids) < 0) {
693 log_Printf(LogCHAT, "Unable to create pipe in ExecStr: %s\n",
694 strerror(errno));
695 *out = '\0';
696 return;
697 }
698 if ((pid = fork()) == 0) {
699 close(fids[0]);
700 timer_TermService();
701 fids[1] = fcntl(fids[1], F_DUPFD, 4);
701 if (fids[1] == STDIN_FILENO)
702 fids[1] = dup(fids[1]);
702 dup2(physical->fd, STDIN_FILENO);
703 dup2(physical->fd, STDIN_FILENO);
703 dup2(STDIN_FILENO, STDOUT_FILENO);
704 dup2(fids[1], STDERR_FILENO);
704 dup2(fids[1], STDERR_FILENO);
705 dup2(STDIN_FILENO, STDOUT_FILENO);
705 close(3);
706 close(3);
706 if (open(_PATH_TTY, O_RDWR) == 3)
707 fcntl(3, F_SETFD, 0); /* Clear close-on-exec flag */
708 else
709 fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
707 if (open(_PATH_TTY, O_RDWR) != 3)
708 open(_PATH_DEVNULL, O_RDWR); /* Leave it closed if it fails... */
709 for (i = getdtablesize(); i > 3; i--)
710 fcntl(i, F_SETFD, 1);
710 setuid(geteuid());
711 execvp(argv[0], argv);
712 fprintf(stderr, "execvp: %s: %s\n", argv[0], strerror(errno));
711 setuid(geteuid());
712 execvp(argv[0], argv);
713 fprintf(stderr, "execvp: %s: %s\n", argv[0], strerror(errno));
713 exit(127);
714 _exit(127);
714 } else {
715 char *name = strdup(vector[0]);
716
717 close(fids[1]);
718 endout = out + olen - 1;
719 startout = out;
720 while (out < endout) {
721 nb = read(fids[0], out, 1);

--- 39 unchanged lines hidden ---
715 } else {
716 char *name = strdup(vector[0]);
717
718 close(fids[1]);
719 endout = out + olen - 1;
720 startout = out;
721 while (out < endout) {
722 nb = read(fids[0], out, 1);

--- 39 unchanged lines hidden ---