summaryrefslogtreecommitdiff
path: root/ssh-rand-helper.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2004-03-01 02:25:32 +0000
committerColin Watson <cjwatson@debian.org>2004-03-01 02:25:32 +0000
commitea8116a11e3de70036dbc665ccb0d486cf89cac9 (patch)
treed73ccdff78d8608e156465af42e6a1b3527fb2d6 /ssh-rand-helper.c
parente39b311381a5609cc05acf298c42fba196dc524b (diff)
parentf5bda272678ec6dccaa5f29379cf60cb855018e8 (diff)
Merge 3.8p1 to the trunk. This builds and runs, but I haven't tested it
extensively yet. ProtocolKeepAlives is now just a compatibility alias for ServerAliveInterval.
Diffstat (limited to 'ssh-rand-helper.c')
-rw-r--r--ssh-rand-helper.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/ssh-rand-helper.c b/ssh-rand-helper.c
index 7e65e4569..8a320a71e 100644
--- a/ssh-rand-helper.c
+++ b/ssh-rand-helper.c
@@ -39,7 +39,7 @@
39#include "pathnames.h" 39#include "pathnames.h"
40#include "log.h" 40#include "log.h"
41 41
42RCSID("$Id: ssh-rand-helper.c,v 1.13 2003/08/21 23:34:41 djm Exp $"); 42RCSID("$Id: ssh-rand-helper.c,v 1.16 2003/11/21 12:56:47 djm Exp $");
43 43
44/* Number of bytes we write out */ 44/* Number of bytes we write out */
45#define OUTPUT_SEED_SIZE 48 45#define OUTPUT_SEED_SIZE 48
@@ -115,19 +115,19 @@ double stir_gettimeofday(double entropy_estimate);
115double stir_clock(double entropy_estimate); 115double stir_clock(double entropy_estimate);
116double stir_rusage(int who, double entropy_estimate); 116double stir_rusage(int who, double entropy_estimate);
117double hash_command_output(entropy_cmd_t *src, unsigned char *hash); 117double hash_command_output(entropy_cmd_t *src, unsigned char *hash);
118int get_random_bytes_prngd(unsigned char *buf, int len, 118int get_random_bytes_prngd(unsigned char *buf, int len,
119 unsigned short tcp_port, char *socket_path); 119 unsigned short tcp_port, char *socket_path);
120 120
121/* 121/*
122 * Collect 'len' bytes of entropy into 'buf' from PRNGD/EGD daemon 122 * Collect 'len' bytes of entropy into 'buf' from PRNGD/EGD daemon
123 * listening either on 'tcp_port', or via Unix domain socket at * 123 * listening either on 'tcp_port', or via Unix domain socket at *
124 * 'socket_path'. 124 * 'socket_path'.
125 * Either a non-zero tcp_port or a non-null socket_path must be 125 * Either a non-zero tcp_port or a non-null socket_path must be
126 * supplied. 126 * supplied.
127 * Returns 0 on success, -1 on error 127 * Returns 0 on success, -1 on error
128 */ 128 */
129int 129int
130get_random_bytes_prngd(unsigned char *buf, int len, 130get_random_bytes_prngd(unsigned char *buf, int len,
131 unsigned short tcp_port, char *socket_path) 131 unsigned short tcp_port, char *socket_path)
132{ 132{
133 int fd, addr_len, rval, errors; 133 int fd, addr_len, rval, errors;
@@ -289,7 +289,7 @@ hash_command_output(entropy_cmd_t *src, unsigned char *hash)
289 if (devnull == -1) { 289 if (devnull == -1) {
290 devnull = open("/dev/null", O_RDWR); 290 devnull = open("/dev/null", O_RDWR);
291 if (devnull == -1) 291 if (devnull == -1)
292 fatal("Couldn't open /dev/null: %s", 292 fatal("Couldn't open /dev/null: %s",
293 strerror(errno)); 293 strerror(errno));
294 } 294 }
295 295
@@ -314,7 +314,7 @@ hash_command_output(entropy_cmd_t *src, unsigned char *hash)
314 314
315 execv(src->path, (char**)(src->args)); 315 execv(src->path, (char**)(src->args));
316 316
317 debug("(child) Couldn't exec '%s': %s", 317 debug("(child) Couldn't exec '%s': %s",
318 src->cmdstring, strerror(errno)); 318 src->cmdstring, strerror(errno));
319 _exit(-1); 319 _exit(-1);
320 default: /* Parent */ 320 default: /* Parent */
@@ -376,7 +376,7 @@ hash_command_output(entropy_cmd_t *src, unsigned char *hash)
376 case -1: 376 case -1:
377 default: 377 default:
378 /* error */ 378 /* error */
379 debug("Command '%s': select() failed: %s", 379 debug("Command '%s': select() failed: %s",
380 src->cmdstring, strerror(errno)); 380 src->cmdstring, strerror(errno));
381 error_abort = 1; 381 error_abort = 1;
382 break; 382 break;
@@ -400,8 +400,8 @@ hash_command_output(entropy_cmd_t *src, unsigned char *hash)
400 if (error_abort) { 400 if (error_abort) {
401 /* 401 /*
402 * Closing p[0] on timeout causes the entropy command to 402 * Closing p[0] on timeout causes the entropy command to
403 * SIGPIPE. Take whatever output we got, and mark this 403 * SIGPIPE. Take whatever output we got, and mark this
404 * command as slow 404 * command as slow
405 */ 405 */
406 debug2("Command '%s' timed out", src->cmdstring); 406 debug2("Command '%s' timed out", src->cmdstring);
407 src->sticky_badness *= 2; 407 src->sticky_badness *= 2;
@@ -479,7 +479,7 @@ stir_from_programs(void)
479 /* Stir it in */ 479 /* Stir it in */
480 RAND_add(hash, sizeof(hash), entropy); 480 RAND_add(hash, sizeof(hash), entropy);
481 481
482 debug3("Got %0.2f bytes of entropy from '%s'", 482 debug3("Got %0.2f bytes of entropy from '%s'",
483 entropy, entropy_cmds[c].cmdstring); 483 entropy, entropy_cmds[c].cmdstring);
484 484
485 total_entropy += entropy; 485 total_entropy += entropy;
@@ -491,7 +491,7 @@ stir_from_programs(void)
491 total_entropy += stir_rusage(RUSAGE_CHILDREN, 0.1); 491 total_entropy += stir_rusage(RUSAGE_CHILDREN, 0.1);
492 } else { 492 } else {
493 debug2("Command '%s' disabled (badness %d)", 493 debug2("Command '%s' disabled (badness %d)",
494 entropy_cmds[c].cmdstring, 494 entropy_cmds[c].cmdstring,
495 entropy_cmds[c].badness); 495 entropy_cmds[c].badness);
496 496
497 if (entropy_cmds[c].badness > 0) 497 if (entropy_cmds[c].badness > 0)
@@ -511,8 +511,8 @@ prng_check_seedfile(char *filename)
511 struct stat st; 511 struct stat st;
512 512
513 /* 513 /*
514 * XXX raceable: eg replace seed between this stat and subsequent 514 * XXX raceable: eg replace seed between this stat and subsequent
515 * open. Not such a problem because we don't really trust the 515 * open. Not such a problem because we don't really trust the
516 * seed file anyway. 516 * seed file anyway.
517 * XXX: use secure path checking as elsewhere in OpenSSH 517 * XXX: use secure path checking as elsewhere in OpenSSH
518 */ 518 */
@@ -563,7 +563,7 @@ prng_write_seedfile(void)
563 debug("writing PRNG seed to file %.100s", filename); 563 debug("writing PRNG seed to file %.100s", filename);
564 564
565 if (RAND_bytes(seed, sizeof(seed)) <= 0) 565 if (RAND_bytes(seed, sizeof(seed)) <= 0)
566 fatal("PRNG seed extration failed"); 566 fatal("PRNG seed extraction failed");
567 567
568 /* Don't care if the seed doesn't exist */ 568 /* Don't care if the seed doesn't exist */
569 prng_check_seedfile(filename); 569 prng_check_seedfile(filename);
@@ -651,7 +651,7 @@ prng_read_commands(char *cmdfilename)
651 continue; /* done with this line */ 651 continue; /* done with this line */
652 652
653 /* 653 /*
654 * The first non-whitespace char should be a double quote 654 * The first non-whitespace char should be a double quote
655 * delimiting the commandline 655 * delimiting the commandline
656 */ 656 */
657 if (*cp != '"') { 657 if (*cp != '"') {
@@ -726,7 +726,7 @@ prng_read_commands(char *cmdfilename)
726 726
727 /* 727 /*
728 * If we've filled the array, reallocate it twice the size 728 * If we've filled the array, reallocate it twice the size
729 * Do this now because even if this we're on the last 729 * Do this now because even if this we're on the last
730 * command we need another slot to mark the last entry 730 * command we need another slot to mark the last entry
731 */ 731 */
732 if (cur_cmd == num_cmds) { 732 if (cur_cmd == num_cmds) {
@@ -761,7 +761,7 @@ usage(void)
761 OUTPUT_SEED_SIZE); 761 OUTPUT_SEED_SIZE);
762} 762}
763 763
764int 764int
765main(int argc, char **argv) 765main(int argc, char **argv)
766{ 766{
767 unsigned char *buf; 767 unsigned char *buf;
@@ -779,7 +779,7 @@ main(int argc, char **argv)
779 /* Don't write binary data to a tty, unless we are forced to */ 779 /* Don't write binary data to a tty, unless we are forced to */
780 if (isatty(STDOUT_FILENO)) 780 if (isatty(STDOUT_FILENO))
781 output_hex = 1; 781 output_hex = 1;
782 782
783 while ((ch = getopt(argc, argv, "vxXhb:")) != -1) { 783 while ((ch = getopt(argc, argv, "vxXhb:")) != -1) {
784 switch (ch) { 784 switch (ch) {
785 case 'v': 785 case 'v':
@@ -806,7 +806,7 @@ main(int argc, char **argv)
806 } 806 }
807 807
808 log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1); 808 log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1);
809 809
810#ifdef USE_SEED_FILES 810#ifdef USE_SEED_FILES
811 prng_read_seedfile(); 811 prng_read_seedfile();
812#endif 812#endif
@@ -816,11 +816,11 @@ main(int argc, char **argv)
816 /* 816 /*
817 * Seed the RNG from wherever we can 817 * Seed the RNG from wherever we can
818 */ 818 */
819 819
820 /* Take whatever is on the stack, but don't credit it */ 820 /* Take whatever is on the stack, but don't credit it */
821 RAND_add(buf, bytes, 0); 821 RAND_add(buf, bytes, 0);
822 822
823 debug("Seeded RNG with %i bytes from system calls", 823 debug("Seeded RNG with %i bytes from system calls",
824 (int)stir_from_system()); 824 (int)stir_from_system());
825 825
826#ifdef PRNGD_PORT 826#ifdef PRNGD_PORT
@@ -835,7 +835,7 @@ main(int argc, char **argv)
835 /* Read in collection commands */ 835 /* Read in collection commands */
836 if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1) 836 if (prng_read_commands(SSH_PRNG_COMMAND_FILE) == -1)
837 fatal("PRNG initialisation failed -- exiting."); 837 fatal("PRNG initialisation failed -- exiting.");
838 debug("Seeded RNG with %i bytes from programs", 838 debug("Seeded RNG with %i bytes from programs",
839 (int)stir_from_programs()); 839 (int)stir_from_programs());
840#endif 840#endif
841 841
@@ -859,9 +859,9 @@ main(int argc, char **argv)
859 printf("\n"); 859 printf("\n");
860 } else 860 } else
861 ret = atomicio(vwrite, STDOUT_FILENO, buf, bytes); 861 ret = atomicio(vwrite, STDOUT_FILENO, buf, bytes);
862 862
863 memset(buf, '\0', bytes); 863 memset(buf, '\0', bytes);
864 xfree(buf); 864 xfree(buf);
865 865
866 return ret == bytes ? 0 : 1; 866 return ret == bytes ? 0 : 1;
867} 867}