Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 May 2001 21:22:30 +0200
From:      Theo van Klaveren <t.vanklaveren@student.utwente.nl>
To:        freebsd-questions@freebsd.org
Subject:   SU and PTYs
Message-ID:  <20010531212230.A10596@phoenix.student.utwente.nl>

next in thread | raw e-mail | index | archive | help

--qMm9M+Fa2AknHoGS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi,

I'm trying to let a program get super-user rights by calling su in a
pseudo-terminal (the attached program demonstrates this). This however does not
work, because su gets stuck in ttywait.

Can anyone tell me what I'm doing wrong, or at least provide me with a program
that does do the trick?

Thanks in advance,
Theo

P.S. Please reply to me directly. I am not subscribed.

-- 
Theo van Klaveren <t.vanklaveren@student.utwente.nl>
http://home.student.utwente.nl/t.vanklaveren

--qMm9M+Fa2AknHoGS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test.c"

#include <stdlib.h>
#include <sys/types.h>
#include <libutil.h>
#include <stdio.h>
#include <unistd.h>

int
main (int argc, char **argv)
{
	int fd, fds;
	pid_t pid;

	if ((pid = forkpty(&fd, NULL, NULL, NULL)) < 0) {
		perror ("fork");
		exit (-1);
	}

	if (pid > 0) {
		write (fds, "mypasswd\n", strlen("mypasswd\n"));
		waitpid (pid, NULL, 0);
		_exit(0);
	} else {
		execlp ("su", "su", NULL);
	}

}

--qMm9M+Fa2AknHoGS--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010531212230.A10596>