$OpenBSD: patch-konsole_src_konsole_grantpty_c,v 1.2 2001/08/20 23:42:08 espie Exp $
--- konsole/src/konsole_grantpty.c.orig	Mon Jan 22 13:03:53 2001
+++ konsole/src/konsole_grantpty.c	Fri Aug 17 09:20:29 2001
@@ -40,6 +40,12 @@
 #  include <dirent.h>
 #endif
 
+#ifdef __OpenBSD__
+#  include <utmp.h>
+#  include <util.h>
+#  include <fcntl.h>
+#endif
+
 #define PTY_FILENO 3    /* keep in sync with grantpty */
 #define TTY_GROUP "tty"
 
@@ -52,6 +58,8 @@ int main (int argc, char *argv[])
   uid_t         uid;
   mode_t        mod;
   char*         tty;
+  char*		rtty;
+  int		log_in;
 
   /* check preconditions **************************************************/
   if (argc != 2 || (strcmp(argv[1],"--grant") && strcmp(argv[1],"--revoke")))
@@ -77,11 +85,13 @@ int main (int argc, char *argv[])
   { 
     uid = getuid(); /* current user id */
     mod = S_IRUSR|S_IWUSR|S_IWGRP;
+    log_in = 1;
   }
   else
   {
     uid = 0;        /* root */
     mod = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
+    log_in = 0;
   }
   /* Get the group ID of the special `tty' group.  */
   p = getgrnam(TTY_GROUP);            /* posix */
@@ -175,5 +185,36 @@ int main (int argc, char *argv[])
     return 1; /* FAIL */
   }
 
+#ifdef __OpenBSD__
+  /* Make sure the tty is fd 0, to help login work */
+  dup2(open(tty, O_RDWR), 0);
+  rtty = strrchr(tty, '/');
+  if (rtty)
+    rtty++;
+  else
+    rtty = tty;
+  if (log_in)
+  {
+      char *str_ptr;
+      struct utmp l_struct;
+      memset(&l_struct, 0, sizeof(struct utmp));
+
+      if (! (str_ptr=getlogin()) ) {
+	return 1;
+      }
+      strncpy(l_struct.ut_name, str_ptr, UT_NAMESIZE);
+
+      if (gethostname(l_struct.ut_host, UT_HOSTSIZE) == -1) {
+	 if (errno != ENOMEM)
+	    return 1;
+	 l_struct.ut_host[UT_HOSTSIZE]=0;
+      }
+
+      strncpy(l_struct.ut_line, rtty, UT_LINESIZE);
+      time(&l_struct.ut_time); 
+      login(&l_struct);
+  } else
+	logout(rtty);
+#endif
   return 0; /* OK */
 }
