static int do_reseed(int fd) { unsigned char seed_inbuf[40]; uint32_t v1, v2; struct timeval tval; pid_t mypid; int reseed_data = 0; if (fd == -1) { fd = open( "/dev/urandom", O_RDONLY,0); if (fd != -1) { smb_set_close_on_exec(fd); } } if (fd != -1 && (read(fd, seed_inbuf, sizeof(seed_inbuf)) == sizeof(seed_inbuf))) { seed_random_stream(seed_inbuf, sizeof(seed_inbuf)); return fd; } /* Add in some secret file contents */ do_filehash("/etc/shadow", &seed_inbuf[0]); /* * Add the counter, time of day, and pid. */ GetTimeOfDay(&tval); mypid = getpid(); v1 = (counter++) + mypid + tval.tv_sec; v2 = (counter++) * mypid + tval.tv_usec; SIVAL(seed_inbuf, 32, v1 ^ IVAL(seed_inbuf, 32)); SIVAL(seed_inbuf, 36, v2 ^ IVAL(seed_inbuf, 36)); /* * Add any user-given reseed data. */ get_rand_reseed_data(&reseed_data); if (reseed_data) { size_t i; for (i = 0; i < sizeof(seed_inbuf); i++) seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)]; } seed_random_stream(seed_inbuf, sizeof(seed_inbuf)); return -1; }
static int do_reseed(bool use_fd, int fd) { unsigned char seed_inbuf[40]; uint32 v1, v2; struct timeval tval; pid_t mypid; struct passwd *pw; int reseed_data = 0; if (use_fd) { if (fd != -1) return fd; fd = sys_open( "/dev/urandom", O_RDONLY,0); if(fd >= 0) return fd; } /* Add in some secret file contents */ do_filehash("/etc/shadow", &seed_inbuf[0]); do_filehash(lp_smb_passwd_file(), &seed_inbuf[16]); /* * Add in the root encrypted password. * On any system where security is taken * seriously this will be secret. */ pw = getpwnam_alloc(talloc_autofree_context(), "root"); if (pw && pw->pw_passwd) { size_t i; unsigned char md4_tmp[16]; mdfour(md4_tmp, (unsigned char *)pw->pw_passwd, strlen(pw->pw_passwd)); for (i=0;i<16;i++) seed_inbuf[8+i] ^= md4_tmp[i]; TALLOC_FREE(pw); } /* * Add the counter, time of day, and pid. */ GetTimeOfDay(&tval); mypid = sys_getpid(); v1 = (counter++) + mypid + tval.tv_sec; v2 = (counter++) * mypid + tval.tv_usec; SIVAL(seed_inbuf, 32, v1 ^ IVAL(seed_inbuf, 32)); SIVAL(seed_inbuf, 36, v2 ^ IVAL(seed_inbuf, 36)); /* * Add any user-given reseed data. */ get_rand_reseed_data(&reseed_data); if (reseed_data) { size_t i; for (i = 0; i < sizeof(seed_inbuf); i++) seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)]; } smb_arc4_init(smb_arc4_state, seed_inbuf, sizeof(seed_inbuf)); return -1; }