Module Name:    src
Committed By:   kre
Date:           Tue Oct 29 13:10:06 UTC 2024

Modified Files:
        src/lib/libtelnet: enc-proto.h enc_des.c encrypt.c encrypt.h

Log Message:
PR bin/58787  libtelnet - avoid using a global variable

>From RVP -- make 'encrypt_debug_mode' be a static (file scope)
variable instead of extern, and convert the (had been recently
anyway) unused function encrypt_debug() into an accensor function
for it.

This is the minor (almost irrelevant) change from PR bin/58787


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libtelnet/enc-proto.h
cvs rdiff -u -r1.17 -r1.18 src/lib/libtelnet/enc_des.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libtelnet/encrypt.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libtelnet/encrypt.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libtelnet/enc-proto.h
diff -u src/lib/libtelnet/enc-proto.h:1.10 src/lib/libtelnet/enc-proto.h:1.11
--- src/lib/libtelnet/enc-proto.h:1.10	Sat Jan  5 08:55:58 2019
+++ src/lib/libtelnet/enc-proto.h	Tue Oct 29 13:10:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: enc-proto.h,v 1.10 2019/01/05 08:55:58 maya Exp $	*/
+/*	$NetBSD: enc-proto.h,v 1.11 2024/10/29 13:10:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -73,6 +73,7 @@ int EncryptDebug(int);
 int EncryptVerbose(int);
 int EncryptAutoEnc(int);
 int EncryptAutoDec(int);
+int encrypt_debug(void);
 void encrypt_support(unsigned char *, int);
 void encrypt_is(unsigned char *, int);
 void encrypt_reply(unsigned char *, int);
@@ -93,7 +94,6 @@ void encrypt_send_end(void);
 void encrypt_send_request_start(void);
 void encrypt_send_request_end(void);
 void encrypt_wait(void);
-void encrypt_debug(int);
 void encrypt_gen_printsub(unsigned char *, int, unsigned char *, int );
 void encrypt_printsub(unsigned char *, int, unsigned char *, int );
 

Index: src/lib/libtelnet/enc_des.c
diff -u src/lib/libtelnet/enc_des.c:1.17 src/lib/libtelnet/enc_des.c:1.18
--- src/lib/libtelnet/enc_des.c:1.17	Sun Sep  8 09:36:47 2024
+++ src/lib/libtelnet/enc_des.c	Tue Oct 29 13:10:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: enc_des.c,v 1.17 2024/09/08 09:36:47 rillig Exp $	*/
+/*	$NetBSD: enc_des.c,v 1.18 2024/10/29 13:10:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)enc_des.c	8.3 (Berkeley) 5/30/95"; */
 #else
-__RCSID("$NetBSD: enc_des.c,v 1.17 2024/09/08 09:36:47 rillig Exp $");
+__RCSID("$NetBSD: enc_des.c,v 1.18 2024/10/29 13:10:06 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -201,7 +201,7 @@ fb64_start(struct fb *fbp, int dir, int 
 		}
 		state &= ~NO_SEND_IV;
 		state |= NO_RECV_IV;
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("Creating new feed\r\n");
 		/*
 		 * Create a random feed and send it over.
@@ -257,16 +257,16 @@ fb64_is(unsigned char *data, int cnt, st
 	switch (*data++) {
 	case FB64_IV:
 		if (cnt != sizeof(Block)) {
-			if (encrypt_debug_mode)
+			if (encrypt_debug())
 				printf("CFB64: initial vector failed on size\r\n");
 			state = FAILED;
 			goto failure;
 		}
 
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("CFB64: initial vector received\r\n");
 
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("Initializing Decrypt stream\r\n");
 
 		fb64_stream_iv((void *)data, &fbp->streams[DIR_DECRYPT-1]);
@@ -284,7 +284,7 @@ fb64_is(unsigned char *data, int cnt, st
 		break;
 
 	default:
-		if (encrypt_debug_mode) {
+		if (encrypt_debug()) {
 			printf("Unknown option type: %d\r\n", *(data-1));
 			printd(data, cnt);
 			printf("\r\n");
@@ -351,7 +351,7 @@ fb64_reply(unsigned char *data, int cnt,
 		break;
 
 	default:
-		if (encrypt_debug_mode) {
+		if (encrypt_debug()) {
 			printf("Unknown option type: %d\r\n", data[-1]);
 			printd(data, cnt);
 			printf("\r\n");
@@ -381,7 +381,7 @@ fb64_session(Session_Key *key, int serve
 {
 
 	if (!key || key->type != SK_DES) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("Can't set krbdes's session key (%d != %d)\r\n",
 				key ? key->type : -1, SK_DES);
 		return;

Index: src/lib/libtelnet/encrypt.c
diff -u src/lib/libtelnet/encrypt.c:1.19 src/lib/libtelnet/encrypt.c:1.20
--- src/lib/libtelnet/encrypt.c:1.19	Wed Feb 23 21:54:40 2022
+++ src/lib/libtelnet/encrypt.c	Tue Oct 29 13:10:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: encrypt.c,v 1.19 2022/02/23 21:54:40 andvar Exp $	*/
+/*	$NetBSD: encrypt.c,v 1.20 2024/10/29 13:10:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -33,7 +33,7 @@
 #if 0
 static char sccsid[] = "@(#)encrypt.c	8.2 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: encrypt.c,v 1.19 2022/02/23 21:54:40 andvar Exp $");
+__RCSID("$NetBSD: encrypt.c,v 1.20 2024/10/29 13:10:06 kre Exp $");
 #endif /* not lint */
 
 /*
@@ -79,7 +79,7 @@ __RCSID("$NetBSD: encrypt.c,v 1.19 2022/
 void	(*encrypt_output)(unsigned char *, int);
 int	(*decrypt_input)(int);
 
-int encrypt_debug_mode = 0;
+static int encrypt_debug_mode = 0;
 static int decrypt_mode = 0;
 static int encrypt_mode = 0;
 static int encrypt_verbose = 0;
@@ -192,7 +192,7 @@ encrypt_init(const char *name, int serve
 	str_suplen = 4;
 
 	while (ep->type) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: I will support %s\r\n",
 				Name, ENCTYPE_NAME(ep->type));
 		i_support_encrypt |= typemask(ep->type);
@@ -483,7 +483,7 @@ encrypt_support(unsigned char *typelist,
 
 	while (cnt-- > 0) {
 		type = *typelist++;
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: He is supporting %s (%d)\r\n",
 				Name,
 				ENCTYPE_NAME(type), type);
@@ -499,7 +499,7 @@ encrypt_support(unsigned char *typelist,
 		if (!ep)
 			return;
 		type = ep->start ? (*ep->start)(DIR_ENCRYPT, Server) : 0;
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: (*ep->start)() returned %d\r\n",
 					Name, type);
 		if (type < 0)
@@ -522,7 +522,7 @@ encrypt_is(unsigned char *data, int cnt)
 	if (type < ENCTYPE_CNT)
 		remote_supports_encrypt |= typemask(type);
 	if (!(ep = finddecryption(type))) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: Can't find type %s (%d) for initial negotiation\r\n",
 				Name,
 				ENCTYPE_NAME_OK(type)
@@ -531,7 +531,7 @@ encrypt_is(unsigned char *data, int cnt)
 		return;
 	}
 	if (!ep->is) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: No initial negotiation needed for type %s (%d)\r\n",
 				Name,
 				ENCTYPE_NAME_OK(type)
@@ -540,7 +540,7 @@ encrypt_is(unsigned char *data, int cnt)
 		ret = 0;
 	} else {
 		ret = (*ep->is)(data, cnt);
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("(*ep->is)(%p, %d) returned %s(%d)\n", data, cnt,
 				(ret < 0) ? "FAIL " :
 				(ret == 0) ? "SUCCESS " : "MORE_TO_DO ", ret);
@@ -564,7 +564,7 @@ encrypt_reply(unsigned char *data, int c
 		return;
 	type = *data++;
 	if (!(ep = findencryption(type))) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: Can't find type %s (%d) for initial negotiation\r\n",
 				Name,
 				ENCTYPE_NAME_OK(type)
@@ -573,7 +573,7 @@ encrypt_reply(unsigned char *data, int c
 		return;
 	}
 	if (!ep->reply) {
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: No initial negotiation needed for type %s (%d)\r\n",
 				Name,
 				ENCTYPE_NAME_OK(type)
@@ -582,13 +582,13 @@ encrypt_reply(unsigned char *data, int c
 		ret = 0;
 	} else {
 		ret = (*ep->reply)(data, cnt);
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf("(*ep->reply)(%p, %d) returned %s(%d)\n",
 				data, cnt,
 				(ret < 0) ? "FAIL " :
 				(ret == 0) ? "SUCCESS " : "MORE_TO_DO ", ret);
 	}
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: encrypt_reply returned %d\n", Name, ret);
 	if (ret < 0) {
 		autoencrypt = 0;
@@ -624,7 +624,7 @@ encrypt_start(unsigned char *data, int c
 		if (encrypt_verbose)
 			printf("[ Input is now decrypted with type %s ]\r\n",
 				ENCTYPE_NAME(decrypt_mode));
-		if (encrypt_debug_mode)
+		if (encrypt_debug())
 			printf(">>>%s: Start to decrypt input with type %s\r\n",
 				Name, ENCTYPE_NAME(decrypt_mode));
 	} else {
@@ -665,7 +665,7 @@ void
 encrypt_end(void)
 {
 	decrypt_input = 0;
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: Input is back to clear text\r\n", Name);
 	if (encrypt_verbose)
 		printf("[ Input is now clear text ]\r\n");
@@ -803,7 +803,7 @@ encrypt_start_output(int type)
 	register int i;
 
 	if (!(ep = findencryption(type))) {
-		if (encrypt_debug_mode) {
+		if (encrypt_debug()) {
 			printf(">>>%s: Can't encrypt with type %s (%d)\r\n",
 				Name,
 				ENCTYPE_NAME_OK(type)
@@ -814,7 +814,7 @@ encrypt_start_output(int type)
 	}
 	if (ep->start) {
 		i = (*ep->start)(DIR_ENCRYPT, Server);
-		if (encrypt_debug_mode) {
+		if (encrypt_debug()) {
 			printf(">>>%s: Encrypt start: %s (%d) %s\r\n",
 				Name,
 				(i < 0) ? "failed" :
@@ -843,7 +843,7 @@ encrypt_start_output(int type)
 	 */
 	encrypt_output = ep->output;
 	encrypt_mode = type;
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: Started to encrypt output with type %s\r\n",
 			Name, ENCTYPE_NAME(type));
 	if (encrypt_verbose)
@@ -866,7 +866,7 @@ encrypt_send_end(void)
 	 * netflush...
 	 */
 	encrypt_output = 0;
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: Output is back to clear text\r\n", Name);
 	if (encrypt_verbose)
 		printf("[ Output is now clear text ]\r\n");
@@ -888,7 +888,7 @@ encrypt_send_request_start(void)
 	*p++ = SE;
 	telnet_net_write(str_start, p - str_start);
 	printsub('>', &str_start[2], p - &str_start[2]);
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: Request input to be encrypted\r\n", Name);
 }
 
@@ -899,14 +899,14 @@ encrypt_send_request_end(void)
 	telnet_net_write(str_end, sizeof(str_end));
 	printsub('>', &str_end[2], sizeof(str_end) - 2);
 
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: Request input to be clear text\r\n", Name);
 }
 
 void
 encrypt_wait(void)
 {
-	if (encrypt_debug_mode)
+	if (encrypt_debug())
 		printf(">>>%s: in encrypt_wait\r\n", Name);
 	if (!havesessionkey || !(I_SUPPORT_ENCRYPT & remote_supports_decrypt))
 		return;
@@ -915,10 +915,10 @@ encrypt_wait(void)
 			return;
 }
 
-void
-encrypt_debug(int mode)
+int
+encrypt_debug(void)
 {
-	encrypt_debug_mode = mode;
+	return encrypt_debug_mode;
 }
 
 void

Index: src/lib/libtelnet/encrypt.h
diff -u src/lib/libtelnet/encrypt.h:1.9 src/lib/libtelnet/encrypt.h:1.10
--- src/lib/libtelnet/encrypt.h:1.9	Mon Jan  9 15:25:33 2012
+++ src/lib/libtelnet/encrypt.h	Tue Oct 29 13:10:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: encrypt.h,v 1.9 2012/01/09 15:25:33 christos Exp $	*/
+/*	$NetBSD: encrypt.h,v 1.10 2024/10/29 13:10:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -94,7 +94,6 @@ typedef struct {
 
 #include "enc-proto.h"
 
-extern int encrypt_debug_mode;
 extern int (*decrypt_input)(int);
 extern void (*encrypt_output)(unsigned char *, int);
 # endif /* __ENCRYPTION__ */

Reply via email to