diff options
Diffstat (limited to 'libbsd')
-rw-r--r-- | libbsd/Make.defs | 64 | ||||
-rw-r--r-- | libbsd/Makefile | 46 | ||||
-rw-r--r-- | libbsd/README | 127 | ||||
-rw-r--r-- | libbsd/README.HLU | 15 | ||||
-rw-r--r-- | libbsd/cfsetspeed.c | 49 | ||||
-rw-r--r-- | libbsd/checkrhosts.c | 4 | ||||
-rw-r--r-- | libbsd/daemon.c | 71 | ||||
-rw-r--r-- | libbsd/login_tty.c | 55 | ||||
-rw-r--r-- | libbsd/logout.c | 71 | ||||
-rw-r--r-- | libbsd/logwtmp.c | 70 | ||||
-rw-r--r-- | libbsd/pty.c | 127 | ||||
-rw-r--r-- | libbsd/revoke.c | 9 | ||||
-rw-r--r-- | libbsd/setpassent.c | 6 | ||||
-rw-r--r-- | libbsd/sgtty.c | 272 | ||||
-rw-r--r-- | libbsd/snprintf.c | 15 |
15 files changed, 1001 insertions, 0 deletions
diff --git a/libbsd/Make.defs b/libbsd/Make.defs new file mode 100644 index 0000000..fbeb0e5 --- /dev/null +++ b/libbsd/Make.defs @@ -0,0 +1,64 @@ +# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk> +# This file is part of the Linux-8086 C library and is distributed +# under the GNU Library General Public License. + +# Set PLATFORM to i386-Linux to build for Linux/386 and to i86-ELKS to +# build for ELKS. This doesn't quite work yet, though, because of some of +# the platform and/or compiler-specific code flying around here. +# Eventually, compiler-specificity won't be an issue, and we can put +# platform-specific code in i86/ and i386/. -Nat + +# Define enviroment var for others. +ifeq ($(PLATFORM),) +PLATFORM=i86-ELKS +#PLATFORM=i86-DOS +#PLATFORM=i386-Linux +endif + +VERMAJOR=0 +VERMINOR=0 +VERPATCH=4 +VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH) + +LIBDEFS=-D__LIBBSD__ +LIBBSD=libbsd.a + +ifneq ($(PLATFORM),i386-Linux) + +# Normal standard 8086 code +ifeq ($(PLATFORM),i86-ELKS) +ARCH=-0 + +# 8086 elks code With "Caller saves" and "First arg in AX" +# ARCH=-0 -C-c -C-f +endif + +# MSDOS COM file (msdos libs don't support "First arg in AX") +ifeq ($(PLATFORM),i86-DOS) +ARCH=-0 -d -D__MSDOS__ +LIBC=libdos.a +endif + +# BCC 386. +ifeq ($(PLATFORM),i386-BCC) +ARCH=-3 +endif + +CC=bcc $(ARCH) +CCFLAGS=-O -I -I$(TOP)/libc/include +LKFLAGS=-L -L$(TOP)/ -s + +else # ifeq ($(PLATFORM),i386-Linux) + +CC=gcc $(ARCH) +# ARCH=-b i486-linuxaout +LKFLAGS=-static -N +CCFLAGS=-O6 -fomit-frame-pointer -I- -I$(TOP)/include -I. -fno-builtin +WALL= -ansi -pedantic -Wwrite-strings -Wpointer-arith -Wcast-qual \ + -Wcast-align -Wtraditional -Wstrict-prototypes -Wmissing-prototypes \ + -Wnested-externs -Winline -Wshadow + +endif # ifeq ($(PLATFORM),i386-Linux) + +CFLAGS=$(CCFLAGS) $(LIBDEFS) +LDFLAGS=$(LKFLAGS) diff --git a/libbsd/Makefile b/libbsd/Makefile new file mode 100644 index 0000000..a33fbde --- /dev/null +++ b/libbsd/Makefile @@ -0,0 +1,46 @@ +# libbsd A collection of library modules similar or equal to their +# BSD UNIX equivalents, to make the job of porting BSD pro- +# grams to LINUX easier. +# +# Author: Rick Sladkey, <jrs@world.std.com> +# Ported to linux-86 (by removing select.c): Dick Porter <dick@cymru.net> +# + +# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk> +# This file is part of the Linux-8086 C library and is distributed +# under the GNU Library General Public License. + +TOP=.. +include $(TOP)/Make.defs +include ./Make.defs + +LIBBSD=libbsd.a +TARGETS=$(LIBBSD) +SRCS= daemon.c logwtmp.c logout.c pty.c login_tty.c \ + sgtty.c cfsetspeed.c revoke.c setpassent.c \ + checkrhosts.c +OBJS=$(SRCS:.c=.o) + +TXT=COPYING Changes Contributors MAGIC \ + Make.defs Makefile New_subdir Pre_main README TODO KERNEL + +all: $(TARGETS) + +install: all + install -d $(BCCHOME) + install -d $(LIBDIR)/i86 + install -m 644 $(LIBBSD) $(LIBDIR)/i86 + +tests: dummy + make -C tests + +$(LIBBSD): $(OBJS) + $(AR) rcs $(LIBBSD) $(OBJS) + +realclean: clean + rm -f $(LIBBSD) + +clean: dummy + rm -f *.o + +dummy: diff --git a/libbsd/README b/libbsd/README new file mode 100644 index 0000000..9541b55 --- /dev/null +++ b/libbsd/README @@ -0,0 +1,127 @@ + + LINUX NET DISTRIBUTION + + Version 0.03 + + Fred N. van Kempen <waltje@uwalt.nl.mugnet.org> + + Ross Biro <bir7@leland.stanford.edu> + + Rick Sladkey <jrs@world.std.com> + + +The NET distribution for LINUX is a complete set of executables, +setup files, documentation and all the sources needed to rebuild +the package. It is intended as the `official' NET package for +the LINUX operating system, mostly to get rid of the current +situation of total chaos in NETland... + +The first distribution has been done by Ross Biro, who wrote the +TCP/IP stuff in the LINUX kernel to start with. As usual, the +Berkeley BSD UNIX software was taken as a base for this distri- +bution. Several `foreign' programs are included as well. + +To make porting easy, a library has been built which contains the +modules from BSD UNIX that were missing in the LINUX library. They +are declared in the header files that go with it. These files +must be copied to the /usr/net/include/bsd directory and a symbolic +link must be created from /usr/include/bsd. + +This is a compliation of some net sources, mostly from bsd-net2. I +have made an effort to get the programs to compile with few or no +changes except for a new Makefile. This resulted in a bsd include +directory and a bsd library. Take a look at them to see what types of +things are required to get BSD sources to compile correctly without +changes. Some of the tricks are pretty ugly. Please don't laugh... + +Everything should compile straight with the libc-4.2 libraries. Just +type "make" in this directory. You may have to do some surgery on +libbsd/libbsd.a to get things to compile with libc-4.1. + +Notes +===== + +bsd: The directory "bsd" contains include files that, for the most +part, just overload include files of the same name from /usr/include. +It provides some BSD things like "union wait" and others. + +libbsd: The libbsd.a archive is a small library of some functions that +are not in our libc as well as some emulation support functions +referenced in the bsd header files. Notably, it includes a +half-decent transparent sgtty emulation package. + +inetd: Works. Only pathname changes. + +ftp: Works. No changes. + +ftpd: I find that ls with ftpd doesn't work very often. It reports +"Transport endpoint already connected" 9 times out of 10. I think +this is a bug in the kernel which will be fixed in a subsequent +release. There was a memory allocation bug in the original source, +look for "#ifdef linux". Also, the shadow password stuff is not +compiled in as I haven't had a chance to mess with that. + +telnet: Works but see the man page for info about the .telnetrc file +and other new options. This is a really nice telnet with rlogin +emulation and lots of other stuff not present in older telnets. The +original Linux port of telnet/telnetd was done by Pete Chown. + +telnetd: Several people have reported that the 0.1 telnetd sometimes +disconnected before getting to the login prompt. The 0.2 version +omits the vhangup stuff which might have been causing the problem. +Also fixed is the problem with /etc/wtmp not being updated correctly +on logout. It was trying to use /var/adm/wtmp. + +finger: Works. One minor change for POSIX timezone handling. + +fingerd: Works, no changes. + +ping: Works, no changes. Must be suid to root. + +named: Works. A few changes for pathnames and net device +configuration stuff. + +nslookup: Works, but it's fussier than older nslookups about named +being setup correctly. Note the -I option is needed for flex -- that +was a tough one to find. No changes. + +named-xfer: Not tested. + +rcp: Works. Must be suid to root. + +rsh: Works. Must be suid to root. + +rshd: Works. + +rlogin: Works OK but needs more testing. This one depends pretty heavily +on the sgtty emulation in libbsd which is not complete yet. There is +an odd timing bug with select and termio settings. Look for "sleep(1)" +to see what I mean. Must be suid to root. + +rlogind: Works with the URGENT stuff commented out. There was a nasty +bug with shared libraries because environ was redefined. + +talk: Works. This is the new byte-order independent talk, not the old +talk that, e.g., native SunOS uses. The old one wouldn't work with +them anyway. Not the fault of Linux. Includes a one line patch for a +bug in our curses and another for a bug in the original source dealing +with select. + +ntalkd: Works. No changes. + +tftp: Works. No changes. + +tftpd: Works. No changes. + +Sample Entries for inetd.conf +============================= +telnet stream tcp nowait root /usr/etc/inet/telnetd telnetd +ntalk dgram udp wait root /usr/etc/inet/ntalkd ntalkd +ftp stream tcp nowait root /usr/etc/inet/ftpd ftpd -l +finger stream tcp nowait root /usr/etc/inet/fingerd finger +shell stream tcp nowait root /usr/etc/inet/rshd rshd +login stream tcp nowait root /usr/etc/inet/rlogind rlogind +tftp dgram udp wait root /usr/etc/inet/tftpd tftpd + +Rick Sladkey +jrs@world.std.com diff --git a/libbsd/README.HLU b/libbsd/README.HLU new file mode 100644 index 0000000..8736852 --- /dev/null +++ b/libbsd/README.HLU @@ -0,0 +1,15 @@ +HJ, + +This is the source of the current "libbsd.a" as I have it +next to the libc 4.3.2. You can safely ignore the blahblah +in the other README- throw it away after you added this stuff +to the rest of libc... + +I think the best way to add this to the standard set of C +libraries is to keep it in the form of a single non-sharable +library (/usr/lib/libbsd.a) that only gets linked if the user +asks for it by typing "-lbsd". I don't know if this is pos- +sible, but I don't think it should be added to the "shared" +image, because it might cause other problems in that case... + +Fred. diff --git a/libbsd/cfsetspeed.c b/libbsd/cfsetspeed.c new file mode 100644 index 0000000..50d0052 --- /dev/null +++ b/libbsd/cfsetspeed.c @@ -0,0 +1,49 @@ +/* cfsetspeed.c - emulate BSD cfsetspeed with cfset[io]speed - rick sladkey */ + +#include <termios.h> + +struct { + int flag, val; +} xref[] = { + B0, 0, + B50, 50, + B75, 75, + B110, 110, + B134, 134, + B150, 150, + B200, 200, + B300, 300, + B600, 600, + B1200, 1200, + B1800, 1800, + B2400, 2400, + B4800, 4800, + B9600, 9600, + B19200, 19200, + B38400, 38400, +#ifdef B57600 + B57600, 57600, +#endif +#ifdef B115200 + B115200,115200, +#endif + 0, -1, +}; + +int cfsetspeed(p,speed) +struct termios *p; +int speed; +{ + int i; + + for (i = 0; xref[i].val != -1; i++) { + if (xref[i].val == speed) { + speed = xref[i].flag; + cfsetispeed(p, speed); + cfsetospeed(p, speed); + return 0; + } + } + return -1; +} + diff --git a/libbsd/checkrhosts.c b/libbsd/checkrhosts.c new file mode 100644 index 0000000..bef2a3c --- /dev/null +++ b/libbsd/checkrhosts.c @@ -0,0 +1,4 @@ + + +/* This is not functional. Oh well. */ +int _check_rhosts_file; diff --git a/libbsd/daemon.c b/libbsd/daemon.c new file mode 100644 index 0000000..6b3409c --- /dev/null +++ b/libbsd/daemon.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ + +#include <fcntl.h> +#include <paths.h> +#include <unistd.h> + +int +daemon(nochdir, noclose) + int nochdir, noclose; +{ + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + (void)dup2(fd, STDIN_FILENO); + (void)dup2(fd, STDOUT_FILENO); + (void)dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)close (fd); + } + return (0); +} diff --git a/libbsd/login_tty.c b/libbsd/login_tty.c new file mode 100644 index 0000000..1968a02 --- /dev/null +++ b/libbsd/login_tty.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)login_tty.c 1.2 (Berkeley) 6/21/90"; +#endif /* LIBC_SCCS and not lint */ + +#include <unistd.h> +#include <sys/param.h> +#include <sys/ioctl.h> +#include <termios.h> + +login_tty(fd) + int fd; +{ + (void) setsid(); + if (ioctl(fd, TIOCSCTTY, (char *)1) == -1) + return (-1); + (void) dup2(fd, 0); + (void) dup2(fd, 1); + (void) dup2(fd, 2); + if (fd > 2) + (void) close(fd); + return (0); +} diff --git a/libbsd/logout.c b/libbsd/logout.c new file mode 100644 index 0000000..43b96c5 --- /dev/null +++ b/libbsd/logout.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)logout.c 5.5 (Berkeley) 6/1/90"; +#endif /* LIBC_SCCS and not lint */ + +#include <string.h> +#include <sys/types.h> +#include <sys/file.h> +#include <time.h> +#include <unistd.h> +#include <utmp.h> + + +typedef struct utmp UTMP; + +logout(line) + register char *line; +{ + register int fd; + UTMP ut; + int rval; + off_t lseek(); + time_t time(); + + if ((fd = open(_PATH_UTMP, O_RDWR)) < 0) + return(0); + rval = 0; + while (read(fd, (char *)&ut, sizeof(UTMP)) == sizeof(UTMP)) { + if (!ut.ut_user[0] || strncmp(ut.ut_line, line, UT_LINESIZE)) + continue; + ut.ut_type = DEAD_PROCESS; + (void)time(&ut.ut_time); + (void)lseek(fd, -(long)sizeof(UTMP), L_INCR); + (void)write(fd, (char *)&ut, sizeof(UTMP)); + rval = 1; + } + (void)close(fd); + return(rval); +} diff --git a/libbsd/logwtmp.c b/libbsd/logwtmp.c new file mode 100644 index 0000000..0f83934 --- /dev/null +++ b/libbsd/logwtmp.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)logwtmp.c 5.5 (Berkeley) 6/1/90"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/types.h> +#include <sys/file.h> +#include <time.h> +#include <sys/stat.h> +#include <unistd.h> +#include <utmp.h> + + +logwtmp(line, name, host) + char *line, *name, *host; +{ + struct utmp ut; + struct stat buf; + int fd; + time_t time(); + char *strncpy(); + + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0) + return; + if (fstat(fd, &buf) == 0) { + ut.ut_pid = getpid(); + ut.ut_type = (name[0] != '\0')? USER_PROCESS : DEAD_PROCESS; + (void) strncpy(ut.ut_id, "", 2); + (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line)); + (void) strncpy(ut.ut_user, name, sizeof(ut.ut_user)); + (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host)); + (void) time(&ut.ut_time); + if (write(fd, (char *)&ut, sizeof(struct utmp)) != + sizeof(struct utmp)) + (void) ftruncate(fd, buf.st_size); + } + (void) close(fd); +} diff --git a/libbsd/pty.c b/libbsd/pty.c new file mode 100644 index 0000000..e5661dc --- /dev/null +++ b/libbsd/pty.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)pty.c 5.6 (Berkeley) 5/10/91"; +#endif /* LIBC_SCCS and not lint */ + +#include <sys/cdefs.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <termios.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <grp.h> + +openpty(amaster, aslave, name, termp, winp) + int *amaster, *aslave; + char *name; + struct termios *termp; + struct winsize *winp; +{ + static char line[] = "/dev/ptyXX"; + register const char *cp1, *cp2; + register int master, slave, ttygid; + struct group *gr; + + if ((gr = getgrnam("tty")) != NULL) + ttygid = gr->gr_gid; + else + ttygid = -1; + + for (cp1 = "pqrs"; *cp1; cp1++) { + line[8] = *cp1; + for (cp2 = "0123456789abcdef"; *cp2; cp2++) { + line[9] = *cp2; + if ((master = open(line, O_RDWR, 0)) == -1) { + if (errno == ENOENT) + return (-1); /* out of ptys */ + } else { + line[5] = 't'; + (void) chown(line, getuid(), ttygid); + (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP); + (void) revoke(line); + if ((slave = open(line, O_RDWR, 0)) != -1) { + *amaster = master; + *aslave = slave; + if (name) + strcpy(name, line); + if (termp) + (void) tcsetattr(slave, + TCSAFLUSH, termp); + if (winp) + (void) ioctl(slave, TIOCSWINSZ, + (char *)winp); + return (0); + } + (void) close(master); + line[5] = 'p'; + } + } + } + errno = ENOENT; /* out of ptys */ + return (-1); +} + +forkpty(amaster, name, termp, winp) + int *amaster; + char *name; + struct termios *termp; + struct winsize *winp; +{ + int master, slave, pid; + + if (openpty(&master, &slave, name, termp, winp) == -1) + return (-1); + switch (pid = fork()) { + case -1: + return (-1); + case 0: + /* + * child + */ + (void) close(master); + login_tty(slave); + return (0); + } + /* + * parent + */ + *amaster = master; + (void) close(slave); + return (pid); +} diff --git a/libbsd/revoke.c b/libbsd/revoke.c new file mode 100644 index 0000000..f4aa524 --- /dev/null +++ b/libbsd/revoke.c @@ -0,0 +1,9 @@ +/* revoke.c - can't quite emulate BSD revoke? - rick sladkey */ + + +int revoke(line) +char *line; +{ + return 0; +} + diff --git a/libbsd/setpassent.c b/libbsd/setpassent.c new file mode 100644 index 0000000..e77c06f --- /dev/null +++ b/libbsd/setpassent.c @@ -0,0 +1,6 @@ +/* setpassent.c - vacuous setpassent for BSD - rick sladkey */ + +void setpassent(i) +int i; +{ +} diff --git a/libbsd/sgtty.c b/libbsd/sgtty.c new file mode 100644 index 0000000..c3cecc1 --- /dev/null +++ b/libbsd/sgtty.c @@ -0,0 +1,272 @@ +/* sgtty.c - emulate BSD sgtty stuff with termios - ross biro, rick sladkey */ + +#define _SGTTY_SOURCE + +#include <bsd/sgtty.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <termios.h> + +struct mask +{ + unsigned short mask; + unsigned short res; +}; + +struct sf +{ + struct mask iflag; + struct mask oflag; + struct mask cflag; + struct mask lflag; +}; + +static struct sf trans[] = +{ + /* order is important here. */ + /* iflag oflag cflag lflag */ + /* this needs to be fixed. */ + {{0,0}, {OPOST,0}, {0,0}, {ISIG,0}}, /* O_RAW */ + {{0,0}, {0,0}, {0,0}, {XCASE,XCASE}}, /* O_LCASE */ + {{ICRNL,ICRNL}, {ONLCR, ONLCR}, {0,0}, {0,0}}, /* O_CRMOD */ + {{0,0}, {0,0}, {0,0}, {ECHO,ECHO}}, /* O_ECHO */ + {{0,0}, {0,0}, {PARENB|PARODD,PARENB|PARODD}, {0,0}},/* O_ODDP */ + {{0,0}, {0,0}, {PARENB|PARODD,PARENB}, {0,0}}, /* O_EVENP */ + {{0,0}, {0,0}, {0,0}, {ICANON,0}}, /* O_CBREAK */ +}; + +#define _BSD_VDISABLE 255 + +static int +bchar (c) +unsigned char c; +{ + return c == _POSIX_VDISABLE ? _BSD_VDISABLE : c; +} + +static int +pchar (c) +unsigned char c; +{ + return c == _BSD_VDISABLE ? _POSIX_VDISABLE : c; +} + +int +gtty (fd,sg) +int fd; +struct sgttyb *sg; +{ + struct termios t; + int err; + int i; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + sg->sg_ispeed = cfgetispeed (&t); + sg->sg_ospeed = cfgetospeed (&t); + sg->sg_erase = bchar (t.c_cc[VERASE]); + sg->sg_kill = bchar (t.c_cc[VKILL]); + sg->sg_flags = 0; + for (i = 0; i < sizeof (trans) / sizeof (struct sf); i++) + { + if ((t.c_iflag & trans[i].iflag.mask) == trans[i].iflag.res && + (t.c_oflag & trans[i].oflag.mask) == trans[i].oflag.res && + (t.c_cflag & trans[i].cflag.mask) == trans[i].cflag.res && + (t.c_lflag & trans[i].lflag.mask) == trans[i].lflag.res) + { + sg->sg_flags |= 1 << i; + } + } + return (0); +} + +static int +tiocset (fd,sg,method) +int fd; +struct sgttyb *sg; +int method; +{ + struct termios t; + int err; + int i; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + + cfsetispeed (&t, sg->sg_ispeed); + cfsetospeed (&t, sg->sg_ospeed); + t.c_cc[VERASE] = pchar (sg->sg_erase); + t.c_cc[VKILL] = pchar (sg->sg_kill); + for (i = sizeof (trans) / sizeof (struct sf) - 1; i >= 0; i--) + { + t.c_iflag &= ~trans[i].iflag.mask; + t.c_oflag &= ~trans[i].oflag.mask; + t.c_cflag &= ~trans[i].cflag.mask; + t.c_lflag &= ~trans[i].lflag.mask; + if (sg->sg_flags & (1 << i)) + { + t.c_iflag |= trans[i].iflag.res; + t.c_oflag |= trans[i].oflag.res; + t.c_cflag |= trans[i].cflag.res; + t.c_lflag |= trans[i].lflag.res; + } + else + { + t.c_iflag |= (~trans[i].iflag.res) & trans[i].iflag.mask; + t.c_oflag |= (~trans[i].oflag.res) & trans[i].oflag.mask; + t.c_cflag |= (~trans[i].cflag.res) & trans[i].cflag.mask; + t.c_lflag |= (~trans[i].lflag.res) & trans[i].lflag.mask; + } + } + return (ioctl (fd, method, &t)); +} + +int +stty (fd,sg) +int fd; +struct sgttyb *sg; +{ + return tiocset (fd, sg, TCSETSF); +} + +static int +tiocsetn (fd,sg) +int fd; +struct sgttyb *sg; +{ + return tiocset (fd, sg, TCSETS); +} + +static int +tiocgetc (fd,tc) +int fd; +struct tchars *tc; +{ + struct termios t; + int err; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + tc->t_intrc = bchar (t.c_cc[VINTR]); + tc->t_quitc = bchar (t.c_cc[VQUIT]); + tc->t_eofc = bchar (t.c_cc[VEOF]); + tc->t_startc = bchar (t.c_cc[VSTART]); + tc->t_stopc = bchar (t.c_cc[VSTOP]); + tc->t_brkc = bchar (t.c_cc[VEOL]); + return (0); +} + +static int +tiocsetc (fd,tc) +int fd; +struct tchars *tc; +{ + struct termios t; + int err; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + t.c_cc[VINTR] = pchar (tc->t_intrc); + t.c_cc[VQUIT] = pchar (tc->t_quitc); + t.c_cc[VEOF] = pchar (tc->t_eofc); + t.c_cc[VEOL] = pchar (tc->t_brkc); + t.c_cc[VSTART] = pchar (tc->t_startc); + t.c_cc[VSTOP] = pchar (tc->t_stopc); + return (ioctl (fd, TCSETS, &t)); +} + +static int +tiocgltc (fd,tc) +int fd; +struct ltchars *tc; +{ + struct termios t; + int err; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + tc->t_werasc = bchar (t.c_cc[VWERASE]); + tc->t_suspc = bchar (t.c_cc[VSUSP]); + tc->t_dsuspc = bchar (t.c_cc[VSUSP]); + tc->t_rprntc = bchar (t.c_cc[VREPRINT]); + tc->t_flushc = bchar (t.c_cc[VDISCARD]); + tc->t_lnextc = bchar (t.c_cc[VLNEXT]); + return (0); +} + +static int +tiocsltc (fd,tc) +int fd; +struct ltchars *tc; +{ + struct termios t; + int err; + err = ioctl (fd, TCGETS, &t); + if (err < 0) return (err); + t.c_cc[VWERASE] = pchar (tc->t_werasc); + t.c_cc[VSUSP] = pchar (tc->t_suspc); + if(t.c_cc[VSUSP] == _POSIX_VDISABLE) + t.c_cc[VSUSP] = pchar (tc->t_dsuspc); + t.c_cc[VREPRINT] = pchar (tc->t_rprntc); + t.c_cc[VDISCARD] = pchar (tc->t_flushc); + t.c_cc[VLNEXT] = pchar (tc->t_lnextc); + return (ioctl (fd, TCSETS, &t)); +} + +static int +tioclget (fd,lflagsp) +int fd; +int *lflagsp; +{ + struct termios t; + int lflags = 0; + + *lflagsp = lflags; + return 0; +} + +static int +tioclset (fd,lflagsp) +int fd; +int *lflagsp; +{ + return 0; +} + +static int +tiocflush (fd,arg) +int fd; +int *arg; +{ + return 0; +} + +int +bsd_ioctl (fd,option,arg) +int fd; +int option; +void *arg; +{ + switch (option) { + case TIOCGETP: + return gtty(fd, (struct sgttyb *) arg); + case TIOCSETP: + return stty(fd, (struct sgttyb *) arg); + case TIOCGETC: + return tiocgetc(fd, (struct tchars *) arg); + case TIOCSETC: + return tiocsetc(fd, (struct tchars *) arg); + case TIOCGLTC: + return tiocgltc(fd, (struct ltchars *) arg); + case TIOCSLTC: + return tiocsltc(fd, (struct ltchars *) arg); + case TIOCLGET: + return tioclget(fd, (int *) arg); + case TIOCLSET: + return tioclset(fd, (int *) arg); + case TIOCFLUSH: + return tiocflush(fd, (int *) arg); + case TIOCSETN: + return tiocsetn(fd, (struct sgttyb *) arg); + default: + return ioctl(fd, option, arg); + } +} + diff --git a/libbsd/snprintf.c b/libbsd/snprintf.c new file mode 100644 index 0000000..04bc387 --- /dev/null +++ b/libbsd/snprintf.c @@ -0,0 +1,15 @@ +/* snprintf.c - emulate BSD snprintf with sprintf - rick sladkey */ + +#include <stdio.h> +#include <stdarg.h> + +int snprintf(char *s, int len, char *format, ...) +{ + va_list args; + int result; + + va_start(args, format); + result = vsprintf(s, format, args); + va_end(args); + return result; +} |