* 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.
This commit is contained in:
Corinna Vinschen
2003-09-10 15:51:59 +00:00
parent 136265194d
commit 34a1d63d80
12 changed files with 590 additions and 35 deletions

View File

@@ -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);