From f90454ed9c9befd2079d34d8d5a90128d669e570 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 11 Nov 2019 09:15:39 +0100
Subject: [PATCH 1/2] Remove OPIE remains.

---
 libexec/ftpd/ftpd.c       | 35 +--------------------------------
 usr.bin/telnet/commands.c | 34 --------------------------------
 usr.bin/telnet/telnet.1   |  6 +-----
 usr.sbin/pw/pw_user.c     | 41 ---------------------------------------
 4 files changed, 2 insertions(+), 114 deletions(-)

diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index fa6e145c78..5bbe0fffc8 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -61,9 +61,6 @@
 #include <netdb.h>
 #include <pwd.h>
 #include <grp.h>
-#ifdef OPIE
-#include <opie.h>
-#endif
 #include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -168,10 +165,6 @@ static int	auth_pam(struct passwd**, const char*);
 pam_handle_t	*pamh = NULL;
 #endif
 
-#ifdef OPIE
-static struct opie	opiedata;
-static char		opieprompt[OPIE_CHALLENGE_MAX+1];
-#endif
 static int		pwok;
 
 char	*pid_file = NULL; /* means default location to pidfile(3) */
@@ -1041,25 +1034,8 @@ user(char *name)
 	if (logging)
 		strncpy(curname, name, sizeof(curname)-1);
 
-	pwok = 0;
-#ifdef OPIE
-#ifdef USE_PAM
-	/* XXX Kluge! The conversation mechanism needs to be fixed. */
-#endif
-	if (opiechallenge(&opiedata, name, opieprompt) == 0) {
-		pwok = (pw != NULL) &&
-		       opieaccessfile(remotehost) &&
-		       opiealways(pw->pw_dir);
-		reply(331, "Response to %s %s for %s.",
-		      opieprompt, pwok ? "requested" : "required", name);
-	} else {
-		pwok = 1;
-		reply(331, "Password required for %s.", name);
-	}
-#else
 	pwok = 1;
 	reply(331, "Password required for %s.", name);
-#endif
 	askpasswd = 1;
 	/*
 	 * Delay before reading passwd after first failed
@@ -1370,17 +1346,8 @@ pass(char *passwd)
 		}
 #ifdef USE_PAM
 		rval = auth_pam(&pw, passwd);
-		if (rval >= 0) {
-#ifdef OPIE
-			opieunlock();
-#endif
+		if (rval >= 0)
 			goto skip;
-		}
-#endif
-#ifdef OPIE
-		if (opieverify(&opiedata, passwd) == 0)
-			xpasswd = pw->pw_passwd;
-		else
 #endif
 		if (pwok) {
 			xpasswd = crypt(passwd, pw->pw_passwd);
diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c
index 1edfa3cf36..6d2001afab 100644
--- a/usr.bin/telnet/commands.c
+++ b/usr.bin/telnet/commands.c
@@ -119,34 +119,6 @@ static char saveline[256];
 static int margc;
 static char *margv[20];
 
-#ifdef OPIE
-#define PATH_OPIEKEY	"/usr/bin/opiekey"
-static int
-opie_calc(int argc, char *argv[])
-{
-	int status;
-
-	if(argc != 3) {
-		printf("%s sequence challenge\n", argv[0]);
-		return (0);
-	}
-
-	switch(fork()) {
-	case 0:
-		execv(PATH_OPIEKEY, argv);
-		exit (1);
-	case -1:
-		perror("fork");
-		break;
-	default:
-		(void) wait(&status);
-		if (WIFEXITED(status))
-			return (WEXITSTATUS(status));
-	}
-	return (0);
-}
-#endif
-
 static void
 makeargv(void)
 {
@@ -2478,9 +2450,6 @@ static char
 	encrypthelp[] =	"turn on (off) encryption ('encrypt ?' for more)",
 #endif	/* ENCRYPTION */
 	zhelp[] =	"suspend telnet",
-#ifdef OPIE
-	opiehelp[] =    "compute response to OPIE challenge",
-#endif
 	shellhelp[] =	"invoke a subshell",
 	envhelp[] =	"change environment variables ('environ ?' for more)",
 	modestring[] = "try to enter line or character mode ('mode ?' for more)";
@@ -2509,9 +2478,6 @@ static Command cmdtab[] = {
 	{ "!",		shellhelp,	shell,		1 },
 	{ "environ",	envhelp,	env_cmd,	0 },
 	{ "?",		helphelp,	help,		0 },
-#ifdef OPIE
-	{ "opie",       opiehelp,       opie_calc,      0 },
-#endif		
 	{ NULL, NULL, NULL, 0 }
 };
 
diff --git a/usr.bin/telnet/telnet.1 b/usr.bin/telnet/telnet.1
index d84a6a685a..649845f8ce 100644
--- a/usr.bin/telnet/telnet.1
+++ b/usr.bin/telnet/telnet.1
@@ -28,7 +28,7 @@
 .\"	@(#)telnet.1	8.6 (Berkeley) 6/1/94
 .\" $FreeBSD: src/crypto/telnet/telnet/telnet.1,v 1.4.2.9 2002/04/13 10:59:08 markm Exp $
 .\"
-.Dd December 31, 2017
+.Dd November 11, 2019
 .Dt TELNET 1
 .Os
 .Sh NAME
@@ -1056,10 +1056,6 @@ Displays the legal
 .Pq Ic unset
 commands.
 .El
-.It Ic opie Ar sequence challenge
-The
-.Ic opie
-command computes a response to the OPIE challenge.
 .It Ic slc Ar state
 The
 .Ic slc
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index c96c49cf95..903b70c8fd 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -55,9 +55,6 @@ static char    *pw_shellpolicy(struct userconf * cnf, struct cargs * args, char
 static char    *pw_password(struct userconf * cnf, struct cargs * args, char const * user);
 static char    *shell_path(char const * path, char *shells[], char *sh);
 static void     rmat(uid_t uid);
-#ifdef OPIE
-static void     rmopie(char const * name);
-#endif
 
 /*-
  * -C config      configuration file
@@ -379,14 +376,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
 				errx(EX_DATAERR, "cannot remove user 'root'");
 
 			if (!PWALTDIR()) {
-#ifdef OPIE
-				/*
-				 * Remove opie record from /etc/opiekeys
-		        	 */
-
-				rmopie(pwd->pw_name);
-#endif
-
 				/*
 				 * Remove crontabs
 				 */
@@ -1244,33 +1233,3 @@ rmat(uid_t uid)
 		closedir(d);
 	}
 }
-
-#ifdef OPIE
-static void
-rmopie(char const * name)
-{
-	static const char etcopie[] = "/etc/opiekeys";
-	FILE   *fp = fopen(etcopie, "r+");
-
-	if (fp != NULL) {
-		char	tmp[1024];
-		off_t	atofs = 0;
-		int	length = strlen(name);
-
-		while (fgets(tmp, sizeof tmp, fp) != NULL) {
-			if (strncmp(name, tmp, length) == 0 && tmp[length]==' ') {
-				if (fseek(fp, atofs, SEEK_SET) == 0) {
-					fwrite("#", 1, 1, fp);	/* Comment username out */
-				}
-				break;
-			}
-			atofs = ftell(fp);
-		}
-		/*
-		 * If we got an error of any sort, don't update!
-		 */
-		fclose(fp);
-	}
-}
-#endif
-
-- 
2.23.0

