File netkit-rsh-0.17-tty-4-pam.diff of Package rsh

--- rlogind/auth.c
+++ rlogind/auth.c	2008-05-13 17:17:58.501527680 +0200
@@ -33,6 +33,7 @@
 
 #include <stdio.h>
 #include <sys/types.h>
+#include <grp.h>
 #include <pwd.h>
 
 #include "rlogind.h"
@@ -108,11 +109,11 @@ static int attempt_auth(void) {
  * or return 0 on authentication success. Dying is discouraged.
  */
 int auth_checkauth(const char *remoteuser, const char *host,
-		   char *localuser, size_t localusersize) 
+		   char *localuser, size_t localusersize, const char *line)
 {
     static struct pam_conv conv = { sock_conv, NULL };
     struct passwd *pwd;
-    char *ln;
+    const char *ln;
     int retval;
 
     retval = pam_start("rlogin", localuser, &conv, &pamh);
@@ -124,7 +125,7 @@ int auth_checkauth(const char *remoteuse
     pam_set_item(pamh, PAM_USER, localuser);
     pam_set_item(pamh, PAM_RUSER, remoteuser);
     pam_set_item(pamh, PAM_RHOST, host);
-    pam_set_item(pamh, PAM_TTY, "rlogin");   /* we don't have a tty yet! */
+    pam_set_item(pamh, PAM_TTY, line);
 	
     network_confirm();
     retval = attempt_auth();
@@ -203,7 +204,7 @@ void auth_finish(void) {}
  * or return 0 on authentication success. Dying is discouraged.
  */
 int auth_checkauth(const char *remoteuser, const char *host,
-		   char *localuser, size_t localusersize) 
+		   char *localuser, size_t localusersize, const char *line)
 {
     struct passwd *pwd;
 
--- rlogind/rlogind.c
+++ rlogind/rlogind.c	2008-05-13 17:24:39.865233188 +0200
@@ -63,6 +63,8 @@ char rcsid[] = 
 #include <arpa/inet.h>   /* for ntohs() */
 #include <stdio.h>       /* for EOF, BUFSIZ, snprintf() */
 #include <syslog.h>      /* for syslog() */
+#include <pty.h>         /* for openpty() */
+#include <utmp.h>        /* for login_tty() */
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -72,9 +74,6 @@ char rcsid[] = 
 #include "logwtmp.h"
 #include "rlogind.h"
 
-pid_t forkpty(int *, char *, struct termios *, struct winsize *);
-int logout(const char *);
-
 #ifndef TIOCPKT_WINDOW
 #define TIOCPKT_WINDOW 0x80
 #endif
@@ -86,7 +85,7 @@ int allow_root_rhosts = 0;
 int deny_all_rhosts_hequiv = 0;
 
 static char oobdata[] = {(char)TIOCPKT_WINDOW};
-static char line[MAXPATHLEN];
+static char *line;
 struct winsize win = { 0, 0, 0, 0 };
 
 
@@ -382,6 +381,7 @@ static void getstr(char *buf, int cnt, c
 static void doit(int netfd) {
     int master, pid, on = 1;
     int authenticated = 0;
+    int slave;
     char *hname;
     int hostok;
     char lusername[32], rusername[32], termtype[256];
@@ -391,7 +391,13 @@ static void doit(int netfd) {
     getstr(rusername, sizeof(rusername), "remuser too long");
     getstr(lusername, sizeof(lusername), "locuser too long");
     getstr(termtype, sizeof(termtype), "Terminal type too long");
-    
+
+    if (openpty(&master, &slave, 0, 0, &win) != 0) {
+	if (errno == ENOENT) fatal(netfd, "Out of ptys", 0);
+	fatal(netfd, "Openpty", 1);
+    }
+    line = ttyname(slave);
+
     /*
      * This function will either die, return -1 if authentication failed,
      * or return 0 if authentication succeeded.
@@ -402,7 +408,7 @@ static void doit(int netfd) {
      */
     if (hostok) {
 	if (auth_checkauth(rusername, hname, 
-			   lusername, sizeof(lusername)) == 0) {
+			   lusername, sizeof(lusername), line) == 0) {
 	   authenticated=1;
 	}
     }
@@ -412,16 +418,19 @@ static void doit(int netfd) {
 	write(netfd, "rlogind: Host address mismatch.\r\n", 33);
     }
 
-    pid = forkpty(&master, line, NULL, &win);
-    if (pid < 0) {
-	if (errno == ENOENT) fatal(netfd, "Out of ptys", 0);
-	fatal(netfd, "Forkpty", 1);
+    if ((pid = fork()) < 0) {
+	fatal(netfd, "Fork", 1);
     }
     if (pid == 0) {
+	close(master);
+	if (login_tty(slave)) {
+	    fatal(netfd, "Login_tty", 1);
+	}
 	/* netfd should always be 0, but... */ 
 	if (netfd > 2) close(netfd);
 	child(hname, termtype, lusername, authenticated);
     }
+    close(slave);
     on = 1;
     ioctl(netfd, FIONBIO, &on);
     ioctl(master, FIONBIO, &on);
--- rlogind/rlogind.h
+++ rlogind/rlogind.h	2008-05-13 17:18:58.789294627 +0200
@@ -1,6 +1,6 @@
 
 /* rlogind.c */
-void fatal(int f, const char *msg, int syserr);
+void fatal(int f, const char *msg, int syserr) __attribute__ ((__noreturn__));
 
 /* network.c */
 char *network_init(int fd, int *hostokp);
@@ -12,7 +12,8 @@ void network_close(void);
 void auth_checkoptions(void);
 void auth_finish(void);
 int auth_checkauth(const char *remoteuser, const char *host,
-		   char *localuser, size_t localusermaxsize);
+		   char *localuser, size_t localusermaxsize,
+		   const char *line);
 
 /* 
  * Global flag variables 
openSUSE Build Service is sponsored by