- (djm) Clean up. Strip some unnecessary differences with OpenBSD's code,
   tidy necessary differences. Use Markus' new debugN() in entropy.c
diff --git a/ChangeLog b/ChangeLog
index 5928510..04173dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
  - (djm) Fix SSH2 not terminating until all background tasks done problem.
  - (djm) Another off-by-one fix from Pavel Kankovsky 
    <peak@argo.troja.mff.cuni.cz> 
+ - (djm) Clean up. Strip some unnecessary differences with OpenBSD's code,
+   tidy necessary differences. Use Markus' new debugN() in entropy.c
 
 20000926
  - (djm) Update X11-askpass to 1.0.2 in RPM spec file
diff --git a/authfile.c b/authfile.c
index 66bdc0e..c8eac18 100644
--- a/authfile.c
+++ b/authfile.c
@@ -479,9 +479,9 @@
 	if (fd < 0)
 		return 0;
 
-	/* check owner and modes.  */
+	/* check owner and modes */
 #ifdef HAVE_CYGWIN
-        if (check_ntsec(filename))
+	if (check_ntsec(filename))
 #endif
 	if (fstat(fd, &st) < 0 ||
 	    (st.st_uid != 0 && st.st_uid != getuid()) ||
diff --git a/channels.c b/channels.c
index 287e16d..43253b3 100644
--- a/channels.c
+++ b/channels.c
@@ -1763,7 +1763,8 @@
 					error("socket: %.100s", strerror(errno));
 					return NULL;
 				} else {
-					debug("Socket family %d not supported [X11 disp create]", ai->ai_family);
+					debug("x11_create_display_inet: Socket family %d not supported",
+						 ai->ai_family);
 					continue;
 				}
 			}
diff --git a/entropy.c b/entropy.c
index 6a64963..e9608d0 100644
--- a/entropy.c
+++ b/entropy.c
@@ -35,15 +35,12 @@
 # include <floatingpoint.h>
 #endif /* HAVE_FLOATINGPOINT_H */
 
-RCSID("$Id: entropy.c,v 1.19 2000/09/16 05:09:28 djm Exp $");
+RCSID("$Id: entropy.c,v 1.20 2000/09/29 01:12:36 djm Exp $");
 
 #ifndef offsetof
 # define offsetof(type, member) ((size_t) &((type *)0)->member)
 #endif
 
-/* Print lots of detail */
-/* #define DEBUG_ENTROPY */
-
 /* Number of times to pass through command list gathering entropy */
 #define NUM_ENTROPY_RUNS	1
 
@@ -272,10 +269,8 @@
 				/* Stir it in */
 				RAND_add(hash, sizeof(hash), entropy_estimate);
 
-#ifdef DEBUG_ENTROPY
-				debug("Got %0.2f bytes of entropy from '%s'", entropy_estimate, 
+				debug3("Got %0.2f bytes of entropy from '%s'", entropy_estimate, 
 					entropy_sources[c].cmdstring);
-#endif
 
 				total_entropy_estimate += entropy_estimate;
 
@@ -285,10 +280,8 @@
 				total_entropy_estimate += stir_rusage(RUSAGE_SELF, 0.1);
 				total_entropy_estimate += stir_rusage(RUSAGE_CHILDREN, 0.1);
 			} else {
-#ifdef DEBUG_ENTROPY
-				debug("Command '%s' disabled (badness %d)",
+				debug2("Command '%s' disabled (badness %d)",
 					entropy_sources[c].cmdstring, entropy_sources[c].badness);
-#endif
 
 				if (entropy_sources[c].badness > 0)
 					entropy_sources[c].badness--;
@@ -373,6 +366,8 @@
 	int total_bytes_read;
 	SHA_CTX sha;
 	
+	debug3("Reading output from \'%s\'", src->cmdstring);
+
 	if (devnull == -1) {
 		devnull = open("/dev/null", O_RDWR);
 		if (devnull == -1)
@@ -470,12 +465,10 @@
 
 	close(p[0]);
 
-#ifdef DEBUG_ENTROPY
-	debug("Time elapsed: %d msec", msec_elapsed);
-#endif
+	debug3("Time elapsed: %d msec", msec_elapsed);
 	
 	if (waitpid(pid, &status, 0) == -1) {
-	       debug("Couldn't wait for child '%s' completion: %s", src->cmdstring,
+	       error("Couldn't wait for child '%s' completion: %s", src->cmdstring,
 		     strerror(errno));
 		return(0.0);
 	}
@@ -486,7 +479,7 @@
 		/* closing p[0] on timeout causes the entropy command to
 		 * SIGPIPE. Take whatever output we got, and mark this command
 		 * as slow */
-		debug("Command '%s' timed out", src->cmdstring);
+		debug2("Command '%s' timed out", src->cmdstring);
 		src->sticky_badness *= 2;
 		src->badness = src->sticky_badness;
 		return(total_bytes_read);
@@ -496,13 +489,13 @@
 		if (WEXITSTATUS(status)==0) {
 			return(total_bytes_read);
 		} else {
-			debug("Command '%s' exit status was %d", src->cmdstring, 
+			debug2("Command '%s' exit status was %d", src->cmdstring, 
 				WEXITSTATUS(status));
 			src->badness = src->sticky_badness = 128;
 			return (0.0);
 		}
 	} else if (WIFSIGNALED(status)) {
-		debug("Command '%s' returned on uncaught signal %d !", src->cmdstring, 
+		debug2("Command '%s' returned on uncaught signal %d !", src->cmdstring, 
 			status);
 		src->badness = src->sticky_badness = 128;
 		return(0.0);
diff --git a/rsa.c b/rsa.c
index 8f64440..0c9aef7 100644
--- a/rsa.c
+++ b/rsa.c
@@ -83,21 +83,6 @@
 }
 
 /*
- * Key generation progress meter callback
- */
-void
-keygen_progress(int p, int n, void *arg)
-{
-	const char progress_chars[] = ".o+O?";
-
-	if ((p < 0) || (p > (sizeof(progress_chars) - 2)))
-		p = sizeof(progress_chars) - 2;
-
-	putchar(progress_chars[p]);
-	fflush(stdout);
-}
-
-/*
  * Generates RSA public and private keys.  This initializes the data
  * structures; they should be freed with rsa_clear_private_key and
  * rsa_clear_public_key.
@@ -113,11 +98,8 @@
 	if (rsa_verbose) {
 		printf("Generating RSA keys:  ");
 		fflush(stdout);
-		key = RSA_generate_key(bits, 35, keygen_progress, NULL);
-		printf("\n");
-	} else {
-		key = RSA_generate_key(bits, 35, NULL, NULL);
 	}
+	key = RSA_generate_key(bits, 35, NULL, NULL);
 	if (key == NULL)
 		fatal("rsa_generate_key: key generation failed.");
 
diff --git a/session.c b/session.c
index ca12a4f..f5bbf19 100644
--- a/session.c
+++ b/session.c
@@ -867,7 +867,7 @@
 			strncpy(var_name, pam_env[i], equals - pam_env[i]);
 			strcpy(var_val, equals + 1);
 
-			debug("PAM environment: %s=%s", var_name, var_val);
+			debug3("PAM environment: %s=%s", var_name, var_val);
 
 			child_set_env(env, envsize, var_name, var_val);
 		}
@@ -875,6 +875,32 @@
 }
 #endif /* USE_PAM */
 
+
+#ifdef HAVE_CYGWIN
+void copy_environment(char ***env, int *envsize)
+{
+	char *equals, var_name[512], var_val[512];
+	int i;
+
+	for(i = 0; environ[i] != NULL; i++) {
+		if ((equals = strstr(environ[i], "=")) == NULL)
+			continue;
+			
+		if (strlen(environ[i]) < (sizeof(var_name) - 1)) {
+			memset(var_name, '\0', sizeof(var_name));
+			memset(var_val, '\0', sizeof(var_val));
+
+			strncpy(var_name, environ[i], equals - environ[i]);
+			strcpy(var_val, equals + 1);
+
+			debug3("Copy environment: %s=%s", var_name, var_val);
+
+			child_set_env(env, envsize, var_name, var_val);
+		}
+	}
+}
+#endif
+
 #if defined(HAVE_GETUSERATTR)
 /*
  * AIX-specific login initialisation
@@ -1107,15 +1133,7 @@
 	 * The Windows environment contains some setting which are
 	 * important for a running system. They must not be dropped.
 	 */
-	{
-		char **ep;
-		for (ep = environ; *ep; ++ep) {
-			char *esp = strchr(*ep, '=');
-			*esp = '\0';
-			child_set_env(&env, &envsize, *ep, esp + 1);
-			*esp = '=';
-		}
-	}
+	copy_environment(&env, &envsize);
 #endif
 
 	if (!options.use_login) {
@@ -1126,8 +1144,8 @@
 #ifdef HAVE_LOGIN_CAP
 		(void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH);
 		child_set_env(&env, &envsize, "PATH", getenv("PATH"));
-#else
-#ifndef HAVE_CYGWIN
+#else /* HAVE_LOGIN_CAP */
+# ifndef HAVE_CYGWIN
 		/*
 		 * There's no standard path on Windows. The path contains
 		 * important components pointing to the system directories,
@@ -1135,8 +1153,8 @@
 		 * remains intact here.
 		 */
 		child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
-#endif
-#endif
+# endif /* HAVE_CYGWIN */
+#endif /* HAVE_LOGIN_CAP */
 
 		snprintf(buf, sizeof buf, "%.200s/%.50s",
 			 _PATH_MAILDIR, pw->pw_name);
@@ -1178,15 +1196,11 @@
 		    original_command);
 
 #ifdef _AIX
-	{
-           char *authstate,*krb5cc;
-
-	   if ((authstate = getenv("AUTHSTATE")) != NULL)
-		 child_set_env(&env,&envsize,"AUTHSTATE",authstate);
-
-	   if ((krb5cc = getenv("KRB5CCNAME")) != NULL)
-		 child_set_env(&env,&envsize,"KRB5CCNAME",krb5cc);
-	}
+	if ((cp = getenv("AUTHSTATE")) != NULL)
+		child_set_env(&env, &envsize, "AUTHSTATE", cp);
+	if ((cp = getenv("KRB5CCNAME")) != NULL)
+		child_set_env(&env, &envsize, "KRB5CCNAME", cp);
+	read_environment_file(&env, &envsize, "/etc/environment");
 #endif
 
 #ifdef KRB4
@@ -1203,8 +1217,6 @@
 	do_pam_environment(&env, &envsize);
 #endif /* USE_PAM */
 
-	read_environment_file(&env,&envsize,"/etc/environment");
-
 	if (xauthfile)
 		child_set_env(&env, &envsize, "XAUTHORITY", xauthfile);
 	if (auth_get_socket_name() != NULL)
@@ -1313,13 +1325,11 @@
 					    "Running %.100s add %.100s %.100s %.100s\n",
 					    options.xauth_location, display,
 					    auth_proto, auth_data);
-#ifndef HAVE_CYGWIN
 					if (screen != NULL)
 						fprintf(stderr,
 						    "Adding %.*s/unix%s %s %s\n",
 						    (int)(screen-display), display,
 						    screen, auth_proto, auth_data);
-#endif
 				}
 				snprintf(cmd, sizeof cmd, "%s -q -",
 				    options.xauth_location);
@@ -1327,12 +1337,10 @@
 				if (f) {
 					fprintf(f, "add %s %s %s\n", display,
 					    auth_proto, auth_data);
-#ifndef HAVE_CYGWIN
 					if (screen != NULL) 
 						fprintf(f, "add %.*s/unix%s %s %s\n",
 						    (int)(screen-display), display,
 						    screen, auth_proto, auth_data);
-#endif
 					pclose(f);
 				} else {
 					fprintf(stderr, "Could not run %s\n",
diff --git a/ssh.c b/ssh.c
index 33eac93..5a69115 100644
--- a/ssh.c
+++ b/ssh.c
@@ -485,11 +485,11 @@
 	if (!host)
 		usage();
 
+	SSLeay_add_all_algorithms();
+
 	/* Initialize the command to execute on remote host. */
 	buffer_init(&command);
 
-	SSLeay_add_all_algorithms();
-
 	/*
 	 * Save the command to execute on the remote host in a buffer. There
 	 * is no limit on the length of the command, except by the maximum
diff --git a/version.h b/version.h
index 9fb86ab..f015025 100644
--- a/version.h
+++ b/version.h
@@ -1 +1 @@
-#define SSH_VERSION	"OpenSSH_2.2.0p1"
+#define SSH_VERSION	"OpenSSH_2.2.0p2"