| 39 | static int ssl_rand_feedfp(apr_pool_t *, apr_file_t *, int); |
| 40 | |
| 41 | int ssl_rand_seed(server_rec *s, apr_pool_t *p, ssl_rsctx_t nCtx, char *prefix) |
| 42 | { |
| 43 | SSLModConfigRec *mc; |
| 44 | apr_array_header_t *apRandSeed; |
| 45 | ssl_randseed_t *pRandSeeds; |
| 46 | ssl_randseed_t *pRandSeed; |
| 47 | unsigned char stackdata[256]; |
| 48 | int nDone; |
| 49 | apr_file_t *fp; |
| 50 | int i, n, l; |
| 51 | |
| 52 | mc = myModConfig(s); |
| 53 | nDone = 0; |
| 54 | apRandSeed = mc->aRandSeed; |
| 55 | pRandSeeds = (ssl_randseed_t *)apRandSeed->elts; |
| 56 | for (i = 0; i < apRandSeed->nelts; i++) { |
| 57 | pRandSeed = &pRandSeeds[i]; |
| 58 | if (pRandSeed->nCtx == nCtx) { |
| 59 | if (pRandSeed->nSrc == SSL_RSSRC_FILE) { |
| 60 | /* |
| 61 | * seed in contents of an external file |
| 62 | */ |
| 63 | if (apr_file_open(&fp, pRandSeed->cpPath, |
| 64 | APR_READ, APR_OS_DEFAULT, p) != APR_SUCCESS) |
| 65 | continue; |
| 66 | nDone += ssl_rand_feedfp(p, fp, pRandSeed->nBytes); |
| 67 | apr_file_close(fp); |
| 68 | } |
| 69 | else if (pRandSeed->nSrc == SSL_RSSRC_EXEC) { |
| 70 | const char *cmd = pRandSeed->cpPath; |
| 71 | const char **argv = apr_palloc(p, sizeof(char *) * 3); |
| 72 | /* |
| 73 | * seed in contents generated by an external program |
| 74 | */ |
| 75 | argv[0] = cmd; |
| 76 | argv[1] = apr_itoa(p, pRandSeed->nBytes); |
| 77 | argv[2] = NULL; |
| 78 | |
| 79 | if ((fp = ssl_util_ppopen(s, p, cmd, argv)) == NULL) |
| 80 | continue; |
| 81 | nDone += ssl_rand_feedfp(p, fp, pRandSeed->nBytes); |
| 82 | ssl_util_ppclose(s, p, fp); |
| 83 | } |
| 84 | #ifdef HAVE_RAND_EGD |
| 85 | else if (pRandSeed->nSrc == SSL_RSSRC_EGD) { |
| 86 | /* |
| 87 | * seed in contents provided by the external |
| 88 | * Entropy Gathering Daemon (EGD) |
| 89 | */ |
| 90 | if ((n = RAND_egd(pRandSeed->cpPath)) == -1) |
| 91 | continue; |
| 92 | nDone += n; |
| 93 | } |
| 94 | #endif |
| 95 | else if (pRandSeed->nSrc == SSL_RSSRC_BUILTIN) { |
| 96 | struct { |
| 97 | time_t t; |
| 98 | pid_t pid; |
no test coverage detected