Loading...
util/logout.c Libc-583 Libc-262
--- Libc/Libc-583/util/logout.c
+++ Libc/Libc-262/util/logout.c
@@ -1,22 +1,21 @@
 /*
- * Copyright (c) 1999, 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -53,51 +52,39 @@
  * SUCH DAMAGE.
  */
 
+
 #include <sys/types.h>
 #include <sys/time.h>
 
-#ifdef UTMP_COMPAT
+#include <fcntl.h>
 #include <utmp.h>
-#endif /* UTMP_COMPAT */
-#include <utmpx.h>
-#include <utmpx-darwin.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <string.h>
 
+typedef struct utmp UTMP;
+
 int
-logout(char *line)
+logout(line)
+	register char *line;
 {
-	struct utmpx *ux, utx;
-#ifdef UTMP_COMPAT
-#ifdef __LP64__
-	struct utmp32 u;
-#else /* __LP64__ */
-	struct utmp u;
-#endif /* __LP64__ */
-	int which;
-#endif /* UTMP_COMPAT */
+	register int fd;
+	UTMP ut;
+	int rval;
 
-	bzero(&utx, sizeof(utx));
-	strncpy(utx.ut_line, line, sizeof(utx.ut_line));
-	utx.ut_type = UTMPX_AUTOFILL_MASK | UTMPX_DEAD_IF_CORRESPONDING_MASK | DEAD_PROCESS;
-	(void)gettimeofday(&utx.ut_tv, NULL);
-	UTMPX_LOCK;
-	_setutxent();
-	ux = _pututxline(&utx);
-	_endutxent();
-	if (!ux) {
-		UTMPX_UNLOCK;
-		return 0;
+	if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
+		return(0);
+	rval = 0;
+	while (read(fd, &ut, sizeof(UTMP)) == sizeof(UTMP)) {
+		if (!ut.ut_name[0] || strncmp(ut.ut_line, line, UT_LINESIZE))
+			continue;
+		bzero(ut.ut_name, UT_NAMESIZE);
+		bzero(ut.ut_host, UT_HOSTSIZE);
+		(void)time(&ut.ut_time);
+		(void)lseek(fd, -(off_t)sizeof(UTMP), L_INCR);
+		(void)write(fd, &ut, sizeof(UTMP));
+		rval = 1;
 	}
-#ifdef UTMP_COMPAT
-	if (utfile_system) { /* only if we are using _PATH_UTMPX */
-		which = _utmp_compat(ux, &u);
-		if (which & UTMP_COMPAT_UTMP0)
-			_write_utmp(&u, 0);
-		else if (which & UTMP_COMPAT_UTMP1)
-			_write_utmp(&u, 1);
-	}
-#endif /* UTMP_COMPAT */
-	UTMPX_UNLOCK;
-	return 1;
+	(void)close(fd);
+	return(rval);
 }