summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/syscalls.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2003-09-10 15:51:59 +0000
committerCorinna Vinschen <corinna@vinschen.de>2003-09-10 15:51:59 +0000
commit34a1d63d80fcc64cced0fb40b03f1c2a6fbc8ab8 (patch)
treeed8ef52985251bc75d6cd9ee91e3d67b6c694099 /winsup/cygwin/syscalls.cc
parent136265194d593ddee3923cdb3bc0fcfe087a7e5a (diff)
downloadcygnal-34a1d63d80fcc64cced0fb40b03f1c2a6fbc8ab8.tar.gz
cygnal-34a1d63d80fcc64cced0fb40b03f1c2a6fbc8ab8.tar.bz2
cygnal-34a1d63d80fcc64cced0fb40b03f1c2a6fbc8ab8.zip
* 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.
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc64
1 files changed, 35 insertions, 29 deletions
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);