X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-bsd.c;h=60a7927489868dbe4e963c40e9071a8d2aaa4a33;hp=27c568921187984fa3d53b460b2d24503858b917;hb=093489a1ce40a2075b1c5c9feb03c7ab1659d884;hpb=5ba9d88b943e9d5a3ababdadf1d2e246581dfdc6 diff --git a/pppd/sys-bsd.c b/pppd/sys-bsd.c index 27c5689..60a7927 100644 --- a/pppd/sys-bsd.c +++ b/pppd/sys-bsd.c @@ -21,7 +21,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-bsd.c,v 1.41 1999/03/22 05:55:36 paulus Exp $"; +static char rcsid[] = "$Id: sys-bsd.c,v 1.42 1999/04/01 07:20:10 paulus Exp $"; /* $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */ #endif @@ -460,6 +460,38 @@ int fd, on; ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits); } +/* + * get_pty - get a pty master/slave pair and chown the slave side + * to the uid given. Assumes slave_name points to >= 12 bytes of space. + */ +int +get_pty(master_fdp, slave_fdp, slave_name, uid) + int *master_fdp; + int *slave_fdp; + char *slave_name; + int uid; +{ + struct termios tios; + + if (openpty(master_fdp, slave_fdp, slave_name, NULL, NULL) < 0) + return 0; + + fchown(*slave_fdp, uid, -1); + fchmod(*slave_fdp, S_IRUSR | S_IWUSR); + if (tcgetattr(*slave_fdp, &tios) == 0) { + tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + tios.c_cflag |= CS8 | CREAD; + tios.c_iflag = IGNPAR | CLOCAL; + tios.c_oflag = 0; + tios.c_lflag = 0; + if (tcsetattr(*slave_fdp, TCSAFLUSH, &tios) < 0) + warn("couldn't set attributes on pty: %m"); + } else + warn("couldn't get attributes on pty: %m"); + + return 1; +} + /* * open_ppp_loopback - open the device we use for getting