 +	default:
 +		debug3("user_key_found_by_script: script pid %d", pid);
 +
++		close(pipe_in[0]);
 +		close(pipe_out[1]);
 +
-+		if (waitpid(pid, &exit_code, 0) < 0) {
-+			error("waitpid(): %s", strerror(errno));
++		f = fdopen(pipe_in[1], "w");
++		key_write(key, f);
++		fclose(f);
++
++		while(waitpid(pid, &exit_code, 0) < 0) {
++			switch(errno) {
++			case EINTR:
++				debug3("user_key_found_by_script: waitpid() EINTR, continuing");
++				continue;
++			default:
++				error("waitpid(): %s", strerror(errno));
++				goto waitpid_error;
++			}
 +		}
-+		else if (WIFEXITED(exit_code) && WEXITSTATUS(exit_code) == 0) {
++		if (WIFEXITED(exit_code) && WEXITSTATUS(exit_code) == 0) {
 +			int amt_read = read(pipe_out[0], line, sizeof(line) - 1);
 +			line[amt_read] = ' ';
 +			line[amt_read + 1] = 0;

+		restore_uid();
+		return (-1);
+	case 0:
+		/* setup output pipe */
+		close(0);
+		close(pipe_out[0]);
+		dup2(pipe_out[1], 1);
+		close(pipe_out[1]);
+
+		/* BN_bn2hex allocates a string, but we cant free it anyway */
+		switch(key->type) {
+		case KEY_RSA1:
+		case KEY_RSA:
+			execl(file, file, "rsa", BN_bn2hex(key->rsa->e),
+				BN_bn2hex(key->rsa->n), NULL);
+		case KEY_DSA:
+			execl(file, file, "dsa", BN_bn2hex(key->dsa->p),
+				BN_bn2hex(key->dsa->q), BN_bn2hex(key->dsa->g),
+				BN_bn2hex(key->dsa->pub_key), NULL);
+		}
+
+		/* exec failed */
+		error("execl(): %s", strerror(errno));

+{
+	pid_t pid;
+	char line[SSH_MAX_PUBKEY_BYTES];
+	int pipe_in[2];
+	int pipe_out[2];
+	int exit_code = 1;
+	int success = 0;
+	FILE *f;
+	//mysig_t oldsig;
+
+	pipe(pipe_in);
+	pipe(pipe_out);
+
+	//oldsig = signal(SIGCHLD, SIG_IGN);
+	temporarily_use_uid(pw);
+
+	debug3("user_key_found_by_script: executing %s", file);
