diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2003-09-10 19:51:59 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2003-09-10 19:51:59 +0400 |
commit | 34a1d63d80fcc64cced0fb40b03f1c2a6fbc8ab8 (patch) | |
tree | ed8ef52985251bc75d6cd9ee91e3d67b6c694099 | |
parent | 136265194d593ddee3923cdb3bc0fcfe087a7e5a (diff) |
* Makefile.in (DLL_OFILES): Add bsdlib.o.
* autoload.cc (RegisterServiceProcess): Add.
* bsdlib.cc: New file.
(daemon): New function.
(login_tty): Ditto.
(openpty): Ditto.
(forkpty): Ditto.
* cygwin.din: Export daemon, forkpty, login_tty, logwtmp, updwtmp,
openpty and revoke.
* syscalls.cc (updwtmp): New function, writing to wtmp exclusively.
(logwtmp): Ditto.
(login): Call updwtmp instead of writing to wtmp by itself.
(logout): Ditto.
* tty.cc (revoke): New funtion.
* include/paths.h: Define _PATH_DEVNULL.
* include/pty.h: New header.
* include/cygwin/version.h: Bump API minor number.
* include/sys/utmp.h: Declare logwtmp with const arguments.
Declare updwtmp.
* lib/iruserok.c: New file.
(ruserok): New function.
(iruserok): Ditto.
(__ivaliduser): Ditto.
(__icheckhost): Ditto.
-rw-r--r-- | winsup/cygwin/ChangeLog | 27 | ||||
-rw-r--r-- | winsup/cygwin/Makefile.in | 6 | ||||
-rw-r--r-- | winsup/cygwin/autoload.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/cygwin.din | 7 | ||||
-rw-r--r-- | winsup/cygwin/include/cygwin/version.h | 6 | ||||
-rw-r--r-- | winsup/cygwin/include/paths.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/include/pty.h | 18 | ||||
-rw-r--r-- | winsup/cygwin/include/sys/utmp.h | 3 | ||||
-rw-r--r-- | winsup/cygwin/lib/iruserok.c | 319 | ||||
-rw-r--r-- | winsup/cygwin/libc/bsdlib.cc | 165 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 64 | ||||
-rw-r--r-- | winsup/cygwin/tty.cc | 7 |
12 files changed, 590 insertions, 35 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b2cef0e61..6212ac9b9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,32 @@ 2003-09-10 Corinna Vinschen <corinna@vinschen.de> + * Makefile.in (DLL_OFILES): Add bsdlib.o. + * autoload.cc (RegisterServiceProcess): Add. + * bsdlib.cc: New file. + (daemon): New function. + (login_tty): Ditto. + (openpty): Ditto. + (forkpty): Ditto. + * cygwin.din: Export daemon, forkpty, login_tty, logwtmp, updwtmp, + openpty and revoke. + * syscalls.cc (updwtmp): New function, writing to wtmp exclusively. + (logwtmp): Ditto. + (login): Call updwtmp instead of writing to wtmp by itself. + (logout): Ditto. + * tty.cc (revoke): New funtion. + * include/paths.h: Define _PATH_DEVNULL. + * include/pty.h: New header. + * include/cygwin/version.h: Bump API minor number. + * include/sys/utmp.h: Declare logwtmp with const arguments. + Declare updwtmp. + * lib/iruserok.c: New file. + (ruserok): New function. + (iruserok): Ditto. + (__ivaliduser): Ditto. + (__icheckhost): Ditto. + +2003-09-10 Corinna Vinschen <corinna@vinschen.de> + * fhandler_socket.cc (fhandler_socket::fstat): Don't use PC_POSIX. 2003-09-09 Pierre Humblet <pierre.humblet@ieee.org> diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index 41dad9621..13227a508 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -142,9 +142,9 @@ MALLOC_OFILES=@MALLOC_OFILES@ DLL_IMPORTS:=$(w32api_lib)/libkernel32.a # Please maintain this list in sorted order, with maximum files per 80 col line -DLL_OFILES:=assert.o autoload.o cxx.o cygheap.o cygthread.o dcrt0.o debug.o \ - delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o errno.o \ - exceptions.o exec.o external.o fcntl.o fhandler.o \ +DLL_OFILES:=assert.o autoload.o cxx.o bsdlib.o cygheap.o cygthread.o dcrt0.o \ + debug.o delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o \ + errno.o exceptions.o exec.o external.o fcntl.o fhandler.o \ fhandler_clipboard.o fhandler_console.o fhandler_disk_file.o \ fhandler_dsp.o fhandler_floppy.o fhandler_mem.o \ fhandler_proc.o fhandler_process.o fhandler_random.o \ diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index c2c7ae352..6344a6d0c 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -509,6 +509,7 @@ LoadDLLfuncEx2 (IsDebuggerPresent, 0, kernel32, 1, 1) LoadDLLfunc (IsProcessorFeaturePresent, 4, kernel32); LoadDLLfuncEx (Process32First, 8, kernel32, 1) LoadDLLfuncEx (Process32Next, 8, kernel32, 1) +LoadDLLfuncEx (RegisterServiceProcess, 8, kernel32, 1) LoadDLLfuncEx (SignalObjectAndWait, 16, kernel32, 1) LoadDLLfuncEx (SwitchToThread, 0, kernel32, 1) LoadDLLfunc (TryEnterCriticalSection, 4, kernel32) diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index b67d7a687..9df575b37 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -350,6 +350,7 @@ cygwin_win32_to_posix_path_list_buf_size cygwin32_win32_to_posix_path_list_buf_size = cygwin_win32_to_posix_path_list_buf_size cygwin_winpid_to_pid cygwin32_winpid_to_pid = cygwin_winpid_to_pid +daemon difftime _difftime = difftime dirfd @@ -509,6 +510,7 @@ _fopen = fopen _fopen64 = fopen64 fork _fork = fork +forkpty fpathconf fprintf _fprintf = fprintf @@ -816,7 +818,10 @@ _logbf = logbf logf _logf = logf login +login_tty logout +logwtmp +updwtmp longjmp _longjmp = longjmp lrand48 @@ -918,6 +923,7 @@ opendir _opendir = opendir openlog _openlog = openlog +openpty pathconf _pathconf = pathconf pause @@ -1062,6 +1068,7 @@ remquo remquof rename _rename = rename +revoke rewind _rewind = rewind rewinddir diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 9fc8cdf2b..c37f52910 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -214,14 +214,16 @@ details. */ argz_create_sep argz_delete argz_extract argz_insert argz_next argz_replace argz_stringify envz_add envz_entry envz_get envz_merge envz_remove envz_strip - 92: Export getusershell, setusershell, eetusershell + 92: Export getusershell, setusershell, endusershell + 93: Export daemon, forkpty, openpty, iruserok, ruserok, login_tty, + openpty, forkpty, revoke, logwtmp, updwtmp */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 92 +#define CYGWIN_VERSION_API_MINOR 93 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/paths.h b/winsup/cygwin/include/paths.h index e5ff51e96..fd03f9790 100644 --- a/winsup/cygwin/include/paths.h +++ b/winsup/cygwin/include/paths.h @@ -16,4 +16,6 @@ details. */ #define _PATH_LASTLOG "/var/log/lastlog" #define _PATH_UTMP "/var/run/utmp" #define _PATH_WTMP "/var/log/wtmp" +#define _PATH_DEVNULL "/dev/null" + #endif /* _PATHS_H_ */ diff --git a/winsup/cygwin/include/pty.h b/winsup/cygwin/include/pty.h new file mode 100644 index 000000000..e4b4da03f --- /dev/null +++ b/winsup/cygwin/include/pty.h @@ -0,0 +1,18 @@ +#ifndef __PTY_H__ +#define __PTY_H__ + +#include <_ansi.h> +#include <sys/termios.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int _EXFUN(openpty ,(int *, int *, char *, struct termios *, struct winsize *)); +int _EXFUN(forkpty ,(int *, char *, struct termios *, struct winsize *)); + +#ifdef __cplusplus +} +#endif + +#endif /* __PTY_H__ */ diff --git a/winsup/cygwin/include/sys/utmp.h b/winsup/cygwin/include/sys/utmp.h index 2d959d806..b78c56317 100644 --- a/winsup/cygwin/include/sys/utmp.h +++ b/winsup/cygwin/include/sys/utmp.h @@ -60,7 +60,8 @@ extern void utmpname (const char *); void login (struct utmp *); int logout (char *); int login_tty (int); -void logwtmp (char *, char *, char *); +void updwtmp (const char *, const struct utmp *); +void logwtmp (const char *, const char *, const char *); #ifdef __cplusplus } diff --git a/winsup/cygwin/lib/iruserok.c b/winsup/cygwin/lib/iruserok.c new file mode 100644 index 000000000..5e957184e --- /dev/null +++ b/winsup/cygwin/lib/iruserok.c @@ -0,0 +1,319 @@ +/* Based on the rcmd.c.new file distributed with linux libc 5.4.19 + Adapted to inetutils by Bernhard Rosenkraenzer <bero@startrek.in-trier.de> + + Note that a lot in this file is superfluous; hopefully it won't be a + problem for systems that need it for iruserok &c.... */ +/* + * Copyright (c) 1983, 1993, 1994 + * 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. + */ + +#ifdef __CYGWIN__ +#define HAVE_MALLOC_H +#define HAVE_STDLIB_H +#define HAVE_STRING_H +#define TIME_WITH_SYS_TIME +#define PATH_HEQUIV "/etc/hosts.equiv" + +static int __ivaliduser(); +static int __icheckhost(); + +struct hostent *cygwin_gethostbyname (const char *name); +unsigned long cygwin_inet_addr (const char *cp); + +#define gethostbyname cygwin_gethostbyname +#define inet_addr cygwin_inet_addr +#endif + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <pwd.h> +#include <sys/file.h> +#include <sys/signal.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <sys/param.h> +#include <sys/socket.h> +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif +#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H) +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +# include <string.h> +#endif +#include <netinet/in.h> +#ifdef HAVE_ARPA_NAMESER_H +# include <arpa/nameser.h> +#endif +#include <netdb.h> +#include <unistd.h> +#include <ctype.h> +#include <stdio.h> +#include <errno.h> +#ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif +#ifndef __CYGWIN__ +#include <resolv.h> +#endif + +int __check_rhosts_file = 1; +const char *__rcmd_errstr; + +int +ruserok(rhost, superuser, ruser, luser) + const char *rhost; + int superuser; + const char *ruser; + const char *luser; +{ + struct hostent *hp; + u_long addr; + char **ap; + + if ((hp = gethostbyname(rhost)) == NULL) + return (-1); + for (ap = hp->h_addr_list; *ap; ++ap) { + bcopy(*ap, &addr, sizeof(addr)); + if (iruserok(addr, superuser, ruser, luser) == 0) + return (0); + } + return (-1); +} + +/* + * New .rhosts strategy: We are passed an ip address. We spin through + * hosts.equiv and .rhosts looking for a match. When the .rhosts only + * has ip addresses, we don't have to trust a nameserver. When it + * contains hostnames, we spin through the list of addresses the nameserver + * gives us and look for a match. + * + * Returns 0 if ok, -1 if not ok. + */ +int +iruserok(raddr, superuser, ruser, luser) + u_long raddr; + int superuser; + const char *ruser; + const char *luser; +{ + register const char *cp; + struct stat sbuf; + struct passwd *pwd; + FILE *hostf; + uid_t uid; + int first = 1; + char *pbuf; + + first = 1; + hostf = superuser ? NULL : fopen(PATH_HEQUIV, "r"); +again: + if (hostf) { + if (__ivaliduser(hostf, raddr, luser, ruser) == 0) { + (void) fclose(hostf); + return(0); + } + (void) fclose(hostf); + } + if (first == 1 && (__check_rhosts_file || superuser)) { + first = 0; + if ((pwd = getpwnam(luser)) == NULL) + return(-1); + + pbuf = malloc (strlen (pwd->pw_dir) + sizeof "/.rhosts"); + if (! pbuf) + { + errno = ENOMEM; + return -1; + } + strcpy (pbuf, pwd->pw_dir); + strcat (pbuf, "/.rhosts"); + + /* + * Change effective uid while opening .rhosts. If root and + * reading an NFS mounted file system, can't read files that + * are protected read/write owner only. + */ + uid = geteuid(); + (void)seteuid(pwd->pw_uid); + hostf = fopen(pbuf, "r"); + (void)seteuid(uid); + + if (hostf == NULL) + return(-1); + /* + * If not a regular file, or is owned by someone other than + * user or root or if writeable by anyone but the owner, quit. + */ + cp = NULL; + if (lstat(pbuf, &sbuf) < 0) + cp = ".rhosts not regular file"; + else if (!S_ISREG(sbuf.st_mode)) + cp = ".rhosts not regular file"; + else if (fstat(fileno(hostf), &sbuf) < 0) + cp = ".rhosts fstat failed"; + else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) + cp = "bad .rhosts owner"; + else if (sbuf.st_mode & (S_IWGRP|S_IWOTH)) + cp = ".rhosts writeable by other than owner"; + /* If there were any problems, quit. */ + if (cp) { + __rcmd_errstr = (char *) cp; + fclose(hostf); + return(-1); + } + goto again; + } + return (-1); +} + +/* + * XXX + * Don't make static, used by lpd(8). + * + * Returns 0 if ok, -1 if not ok. + */ +#ifdef __CYGWIN__ +static +#endif +int +__ivaliduser(hostf, raddr, luser, ruser) + FILE *hostf; + u_long raddr; + const char *luser; + const char *ruser; +{ + size_t buf_offs = 0; + size_t buf_len = 256; + char *buf = malloc (buf_len); + + if (! buf) + return -1; + + while (fgets(buf + buf_offs, buf_len - buf_offs, hostf)) { + /*int ch;*/ + register char *user, *p; + + if (strchr(buf + buf_offs, '\n') == NULL) { + /* No newline yet, read some more. */ + buf_offs += strlen (buf + buf_offs); + + if (buf_offs >= buf_len - 1) { + /* Make more room in BUF. */ + char *new_buf; + + buf_len += buf_len; + new_buf = realloc (buf, buf_len); + + if (! new_buf) { + free (buf); + return -1; + } + + buf = new_buf; + } + + continue; + } + + buf_offs = 0; /* Start at beginning next time around. */ + + p = buf; + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { + /* *p = isupper(*p) ? tolower(*p) : *p; -- Uli */ + *p = tolower(*p); /* works for linux libc */ + p++; + } + if (*p == ' ' || *p == '\t') { + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + user = p; + while (*p != '\n' && *p != ' ' && + *p != '\t' && *p != '\0') + p++; + } else + user = p; + *p = '\0'; + + if (__icheckhost(raddr, buf) && !strcmp(ruser, *user ? user : luser)) { + free (buf); + return (0); + } + } + + free (buf); + + return (-1); +} + +/* + * Returns "true" if match, 0 if no match. + */ +#ifdef __CYGWIN__ +static +#endif +int +__icheckhost(raddr, lhost) + u_long raddr; + register char *lhost; +{ + register struct hostent *hp; + register u_long laddr; + register char **pp; + + /* Try for raw ip address first. */ + if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1) + return (raddr == laddr); + + /* Better be a hostname. */ + if ((hp = gethostbyname(lhost)) == NULL) + return (0); + + /* Spin through ip addresses. */ + for (pp = hp->h_addr_list; *pp; ++pp) + if (!bcmp(&raddr, *pp, sizeof(u_long))) + return (1); + + /* No match. */ + return (0); +} diff --git a/winsup/cygwin/libc/bsdlib.cc b/winsup/cygwin/libc/bsdlib.cc new file mode 100644 index 000000000..acf43adbf --- /dev/null +++ b/winsup/cygwin/libc/bsdlib.cc @@ -0,0 +1,165 @@ +/*- + * 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. 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. + * + * CV 2003-09-10: Cygwin specific changes applied. Code simplified just + * for Cygwin alone. + */ + +#include "winsup.h" +#include <stdlib.h> +#include <utmp.h> +#include <unistd.h> +#include <sys/termios.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include "cygerrno.h" + +extern "C" int +daemon (int nochdir, int noclose) +{ + int fd; + + switch (fork ()) + { + case -1: + return -1; + case 0: + if (!wincap.is_winnt ()) + { + /* Register as service under 9x/Me which allows to close + the parent window with the daemon still running. + This function only exists on 9x/Me and is autoloaded + so it fails silently on NT. */ + DWORD WINAPI RegisterServiceProcess (DWORD, DWORD); + RegisterServiceProcess (0, 1); + } + break; + default: + /* This sleep avoids a race condition which kills the + child process if parent is started by a NT/W2K service. + FIXME: Is that still true? */ + Sleep (1000L); + _exit (0); + } + if (setsid () == -1) + return -1; + if (!nochdir) + chdir ("/"); + if (!noclose && (fd = open (_PATH_DEVNULL, O_RDWR, 0)) >= 0) + { + dup2 (fd, STDIN_FILENO); + dup2 (fd, STDOUT_FILENO); + dup2 (fd, STDERR_FILENO); + if (fd > 2) + close (fd); + } + return 0; +} + +extern "C" int +login_tty (int fd) +{ + char *fdname; + int newfd; + + if (setsid () == -1) + return -1; + if ((fdname = ttyname (fd))) + { + if (fd != STDIN_FILENO) + close (STDIN_FILENO); + if (fd != STDOUT_FILENO) + close (STDOUT_FILENO); + if (fd != STDERR_FILENO) + close (STDERR_FILENO); + newfd = open (fdname, O_RDWR); + close (newfd); + } + dup2 (fd, STDIN_FILENO); + dup2 (fd, STDOUT_FILENO); + dup2 (fd, STDERR_FILENO); + if (fd > 2) + close (fd); + return 0; +} + +extern "C" int +openpty (int *amaster, int *aslave, char *name, struct termios *termp, + struct winsize *winp) +{ + int master, slave; + char pts[MAX_PATH]; + + if ((master = open ("/dev/ptmx", O_RDWR | O_NOCTTY)) >= 0) + { + grantpt (master); + unlockpt (master); + strcpy (pts, ptsname (master)); + revoke (pts); + if ((slave = open (pts, O_RDWR | O_NOCTTY)) >= 0) + { + if (amaster) + *amaster = master; + if (aslave) + *aslave = slave; + if (name) + strcpy (name, pts); + if (termp) + tcsetattr (slave, TCSAFLUSH, termp); + if (winp) + ioctl (slave, TIOCSWINSZ, (char *) winp); + return 0; + } + close (master); + } + set_errno (ENOENT); + return -1; +} + +extern "C" int +forkpty (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: + close (master); + login_tty (slave); + return 0; + } + if (amaster) + *amaster = master; + close (slave); + return pid; +} + diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index b3253473b..753712126 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2540,21 +2540,18 @@ ffs (int i) } extern "C" void -login (struct utmp *ut) +updwtmp (const char *wtmp_file, const struct utmp *ut) { - sigframe thisframe (mainthread); - register int fd; - - pututline (ut); - endutent (); /* Writing to wtmp must be atomic to prevent mixed up data. */ char mutex_name[MAX_PATH]; - HANDLE mutex = CreateMutex (NULL, FALSE, - shared_name (mutex_name, "wtmp_mutex", 0)); + HANDLE mutex; + int fd; + + mutex = CreateMutex (NULL, FALSE, shared_name (mutex_name, "wtmp_mutex", 0)); if (mutex) while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED) ; - if ((fd = open (_PATH_WTMP, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0) + if ((fd = open (wtmp_file, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0) { write (fd, ut, sizeof *ut); close (fd); @@ -2566,6 +2563,33 @@ login (struct utmp *ut) } } +extern "C" void +logwtmp (const char *line, const char *user, const char *host) +{ + sigframe thisframe (mainthread); + struct utmp ut; + memset (&ut, 0, sizeof ut); + ut.ut_type = USER_PROCESS; + ut.ut_pid = getpid (); + if (line) + strncpy (ut.ut_line, line, sizeof ut.ut_line); + time (&ut.ut_time); + if (user) + strncpy (ut.ut_user, user, sizeof ut.ut_user); + if (host) + strncpy (ut.ut_host, host, sizeof ut.ut_host); + updwtmp (_PATH_WTMP, &ut); +} + +extern "C" void +login (struct utmp *ut) +{ + sigframe thisframe (mainthread); + pututline (ut); + endutent (); + updwtmp (_PATH_WTMP, ut); +} + extern "C" int logout (char *line) { @@ -2579,29 +2603,11 @@ logout (char *line) if (ut) { - int fd; - ut->ut_type = DEAD_PROCESS; memset (ut->ut_user, 0, sizeof ut->ut_user); time (&ut->ut_time); - /* Writing to wtmp must be atomic to prevent mixed up data. */ - char mutex_name[MAX_PATH]; - HANDLE mutex = CreateMutex (NULL, FALSE, - shared_name (mutex_name, "wtmp_mutex", 0)); - if (mutex) - while (WaitForSingleObject (mutex, INFINITE) == WAIT_ABANDONED) - ; - if ((fd = open (_PATH_WTMP, O_WRONLY | O_APPEND | O_BINARY, 0)) >= 0) - { - write (fd, &ut_buf, sizeof ut_buf); - debug_printf ("set logout time for %s", line); - close (fd); - } - if (mutex) - { - ReleaseMutex (mutex); - CloseHandle (mutex); - } + updwtmp (_PATH_WTMP, &ut_buf); + debug_printf ("set logout time for %s", line); memset (ut->ut_line, 0, sizeof ut_buf.ut_line); ut->ut_time = 0; pututline (ut); diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index d972f0d82..df301819c 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -40,6 +40,13 @@ unlockpt (int fd) } extern "C" int +revoke (char *ttyname) +{ + set_errno (ENOSYS); + return -1; +} + +extern "C" int ttyslot (void) { if (NOTSTATE (myself, PID_USETTY)) |