diff options
Diffstat (limited to '')
| -rw-r--r-- | util-linux/seedrng.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/util-linux/seedrng.c b/util-linux/seedrng.c index c07bf84f7..3074e9a58 100644 --- a/util-linux/seedrng.c +++ b/util-linux/seedrng.c | |||
| @@ -164,25 +164,27 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
| 164 | { | 164 | { |
| 165 | const char *seed_dir; | 165 | const char *seed_dir; |
| 166 | int fd, dfd; | 166 | int fd, dfd; |
| 167 | int i; | ||
| 168 | unsigned opts; | ||
| 167 | uint8_t new_seed[MAX_SEED_LEN]; | 169 | uint8_t new_seed[MAX_SEED_LEN]; |
| 168 | size_t new_seed_len; | 170 | size_t new_seed_len; |
| 169 | bool new_seed_creditable, skip_credit; | 171 | bool new_seed_creditable; |
| 170 | struct timespec timestamp; | 172 | struct timespec timestamp; |
| 171 | sha256_ctx_t hash; | 173 | sha256_ctx_t hash; |
| 172 | 174 | ||
| 173 | enum { | 175 | enum { |
| 174 | OPT_d = (1 << 0), | 176 | OPT_n = (1 << 0), /* must be 1 */ |
| 175 | OPT_n = (1 << 1) | 177 | OPT_d = (1 << 1), |
| 176 | }; | 178 | }; |
| 177 | #if ENABLE_LONG_OPTS | 179 | #if ENABLE_LONG_OPTS |
| 178 | static const char longopts[] ALIGN1 = | 180 | static const char longopts[] ALIGN1 = |
| 179 | "seed-dir\0" Required_argument "d" | ||
| 180 | "skip-credit\0" No_argument "n" | 181 | "skip-credit\0" No_argument "n" |
| 182 | "seed-dir\0" Required_argument "d" | ||
| 181 | ; | 183 | ; |
| 182 | #endif | 184 | #endif |
| 183 | 185 | ||
| 184 | seed_dir = DEFAULT_SEED_DIR; | 186 | seed_dir = DEFAULT_SEED_DIR; |
| 185 | skip_credit = getopt32long(argv, "d:n", longopts, &seed_dir) & OPT_n; | 187 | opts = getopt32long(argv, "nd:", longopts, &seed_dir); |
| 186 | umask(0077); | 188 | umask(0077); |
| 187 | if (getuid() != 0) | 189 | if (getuid() != 0) |
| 188 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); | 190 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); |
| @@ -209,10 +211,10 @@ int seedrng_main(int argc UNUSED_PARAM, char *argv[]) | |||
| 209 | clock_gettime(CLOCK_BOOTTIME, ×tamp); | 211 | clock_gettime(CLOCK_BOOTTIME, ×tamp); |
| 210 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); | 212 | sha256_hash(&hash, ×tamp, sizeof(timestamp)); |
| 211 | 213 | ||
| 212 | for (int i = 1; i < 3; ++i) { | 214 | for (i = 0; i <= 1; i++) { |
| 213 | seed_from_file_if_exists(i == 1 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, | 215 | seed_from_file_if_exists(i == 0 ? NON_CREDITABLE_SEED_NAME : CREDITABLE_SEED_NAME, |
| 214 | dfd, | 216 | dfd, |
| 215 | /* credit? */ i == 1 ? false : !skip_credit, | 217 | /* credit? */ (opts ^ OPT_n) & i, /* 0, then 1 unless -n */ |
| 216 | &hash); | 218 | &hash); |
| 217 | } | 219 | } |
| 218 | 220 | ||
