summaryrefslogtreecommitdiff
path: root/sshd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshd.c')
-rw-r--r--sshd.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/sshd.c b/sshd.c
index be7ae5ab4..7f9c3ee7f 100644
--- a/sshd.c
+++ b/sshd.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: sshd.c,v 1.150 2001/01/13 18:32:51 markus Exp $"); 43RCSID("$OpenBSD: sshd.c,v 1.152 2001/01/18 16:20:22 markus Exp $");
44 44
45#include "xmalloc.h" 45#include "xmalloc.h"
46#include "rsa.h" 46#include "rsa.h"
@@ -153,10 +153,10 @@ struct {
153} sensitive_data; 153} sensitive_data;
154 154
155/* 155/*
156 * Flag indicating whether the current session key has been used. This flag 156 * Flag indicating whether the RSA server key needs to be regenerated.
157 * is set whenever the key is used, and cleared when the key is regenerated. 157 * Is set in the SIGALRM handler and cleared when the key is regenerated.
158 */ 158 */
159int key_used = 0; 159int key_do_regen = 0;
160 160
161/* This is set to true when SIGHUP is received. */ 161/* This is set to true when SIGHUP is received. */
162int received_sighup = 0; 162int received_sighup = 0;
@@ -266,7 +266,6 @@ grace_alarm_handler(int sig)
266 * do anything with the private key or random state before forking. 266 * do anything with the private key or random state before forking.
267 * Thus there should be no concurrency control/asynchronous execution 267 * Thus there should be no concurrency control/asynchronous execution
268 * problems. 268 * problems.
269 * XXX calling log() is not safe from races.
270 */ 269 */
271void 270void
272generate_empheral_server_key(void) 271generate_empheral_server_key(void)
@@ -284,17 +283,9 @@ void
284key_regeneration_alarm(int sig) 283key_regeneration_alarm(int sig)
285{ 284{
286 int save_errno = errno; 285 int save_errno = errno;
287 286 signal(SIGALRM, SIG_DFL);
288 /* Check if we should generate a new key. */
289 if (key_used) {
290 /* This should really be done in the background. */
291 generate_empheral_server_key();
292 key_used = 0;
293 }
294 /* Reschedule the alarm. */
295 signal(SIGALRM, key_regeneration_alarm);
296 alarm(options.key_regeneration_time);
297 errno = save_errno; 287 errno = save_errno;
288 key_do_regen = 1;
298} 289}
299 290
300void 291void
@@ -568,6 +559,7 @@ main(int ac, char **av)
568 int listen_sock, maxfd; 559 int listen_sock, maxfd;
569 int startup_p[2]; 560 int startup_p[2];
570 int startups = 0; 561 int startups = 0;
562 int ret, key_used = 0;
571 563
572 __progname = get_progname(av[0]); 564 __progname = get_progname(av[0]);
573 init_rng(); 565 init_rng();
@@ -674,7 +666,7 @@ main(int ac, char **av)
674 * key (unless started from inetd) 666 * key (unless started from inetd)
675 */ 667 */
676 log_init(__progname, 668 log_init(__progname,
677 options.log_level == -1 ? SYSLOG_LEVEL_NOTICE : options.log_level, 669 options.log_level == -1 ? SYSLOG_LEVEL_INFO : options.log_level,
678 options.log_facility == -1 ? SYSLOG_FACILITY_AUTH : options.log_facility, 670 options.log_facility == -1 ? SYSLOG_FACILITY_AUTH : options.log_facility,
679 !silent && !inetd_flag); 671 !silent && !inetd_flag);
680 672
@@ -890,14 +882,9 @@ main(int ac, char **av)
890 fclose(f); 882 fclose(f);
891 } 883 }
892 } 884 }
893 if (options.protocol & SSH_PROTO_1) { 885 if (options.protocol & SSH_PROTO_1)
894 generate_empheral_server_key(); 886 generate_empheral_server_key();
895 887
896 /* Schedule server key regeneration alarm. */
897 signal(SIGALRM, key_regeneration_alarm);
898 alarm(options.key_regeneration_time);
899 }
900
901 /* Arrange to restart on SIGHUP. The handler needs listen_sock. */ 888 /* Arrange to restart on SIGHUP. The handler needs listen_sock. */
902 signal(SIGHUP, sighup_handler); 889 signal(SIGHUP, sighup_handler);
903 890
@@ -938,11 +925,17 @@ main(int ac, char **av)
938 FD_SET(startup_pipes[i], fdset); 925 FD_SET(startup_pipes[i], fdset);
939 926
940 /* Wait in select until there is a connection. */ 927 /* Wait in select until there is a connection. */
941 if (select(maxfd+1, fdset, NULL, NULL, NULL) < 0) { 928 ret = select(maxfd+1, fdset, NULL, NULL, NULL);
942 if (errno != EINTR) 929 if (ret < 0 && errno != EINTR)
943 error("select: %.100s", strerror(errno)); 930 error("select: %.100s", strerror(errno));
944 continue; 931 if (key_used && key_do_regen) {
932 generate_empheral_server_key();
933 key_used = 0;
934 key_do_regen = 0;
945 } 935 }
936 if (ret < 0)
937 continue;
938
946 for (i = 0; i < options.max_startups; i++) 939 for (i = 0; i < options.max_startups; i++)
947 if (startup_pipes[i] != -1 && 940 if (startup_pipes[i] != -1 &&
948 FD_ISSET(startup_pipes[i], fdset)) { 941 FD_ISSET(startup_pipes[i], fdset)) {
@@ -1042,7 +1035,13 @@ main(int ac, char **av)
1042 close(startup_p[1]); 1035 close(startup_p[1]);
1043 1036
1044 /* Mark that the key has been used (it was "given" to the child). */ 1037 /* Mark that the key has been used (it was "given" to the child). */
1045 key_used = 1; 1038 if ((options.protocol & SSH_PROTO_1) &&
1039 key_used == 0) {
1040 /* Schedule server key regeneration alarm. */
1041 signal(SIGALRM, key_regeneration_alarm);
1042 alarm(options.key_regeneration_time);
1043 key_used = 1;
1044 }
1046 1045
1047 arc4random_stir(); 1046 arc4random_stir();
1048 1047