diff options
Diffstat (limited to 'src/usr.bin/openssl/passwd.c')
-rw-r--r-- | src/usr.bin/openssl/passwd.c | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/src/usr.bin/openssl/passwd.c b/src/usr.bin/openssl/passwd.c index f05751f165..a8dfa27db1 100644 --- a/src/usr.bin/openssl/passwd.c +++ b/src/usr.bin/openssl/passwd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: passwd.c,v 1.13 2022/11/11 17:07:39 joshua Exp $ */ | 1 | /* $OpenBSD: passwd.c,v 1.14 2023/03/06 14:32:06 tb Exp $ */ |
2 | 2 | ||
3 | #if defined OPENSSL_NO_MD5 | 3 | #if defined OPENSSL_NO_MD5 |
4 | #define NO_MD5CRYPT_1 | 4 | #define NO_MD5CRYPT_1 |
@@ -51,7 +51,7 @@ static struct { | |||
51 | int use1; | 51 | int use1; |
52 | int useapr1; | 52 | int useapr1; |
53 | int usecrypt; | 53 | int usecrypt; |
54 | } passwd_config; | 54 | } cfg; |
55 | 55 | ||
56 | static const struct option passwd_options[] = { | 56 | static const struct option passwd_options[] = { |
57 | #ifndef NO_MD5CRYPT_1 | 57 | #ifndef NO_MD5CRYPT_1 |
@@ -59,13 +59,13 @@ static const struct option passwd_options[] = { | |||
59 | .name = "1", | 59 | .name = "1", |
60 | .desc = "Use MD5 based BSD password algorithm 1", | 60 | .desc = "Use MD5 based BSD password algorithm 1", |
61 | .type = OPTION_FLAG, | 61 | .type = OPTION_FLAG, |
62 | .opt.flag = &passwd_config.use1, | 62 | .opt.flag = &cfg.use1, |
63 | }, | 63 | }, |
64 | { | 64 | { |
65 | .name = "apr1", | 65 | .name = "apr1", |
66 | .desc = "Use apr1 algorithm (Apache variant of BSD algorithm)", | 66 | .desc = "Use apr1 algorithm (Apache variant of BSD algorithm)", |
67 | .type = OPTION_FLAG, | 67 | .type = OPTION_FLAG, |
68 | .opt.flag = &passwd_config.useapr1, | 68 | .opt.flag = &cfg.useapr1, |
69 | }, | 69 | }, |
70 | #endif | 70 | #endif |
71 | #ifndef OPENSSL_NO_DES | 71 | #ifndef OPENSSL_NO_DES |
@@ -73,7 +73,7 @@ static const struct option passwd_options[] = { | |||
73 | .name = "crypt", | 73 | .name = "crypt", |
74 | .desc = "Use crypt algorithm (default)", | 74 | .desc = "Use crypt algorithm (default)", |
75 | .type = OPTION_FLAG, | 75 | .type = OPTION_FLAG, |
76 | .opt.flag = &passwd_config.usecrypt, | 76 | .opt.flag = &cfg.usecrypt, |
77 | }, | 77 | }, |
78 | #endif | 78 | #endif |
79 | { | 79 | { |
@@ -81,44 +81,44 @@ static const struct option passwd_options[] = { | |||
81 | .argname = "file", | 81 | .argname = "file", |
82 | .desc = "Read passwords from specified file", | 82 | .desc = "Read passwords from specified file", |
83 | .type = OPTION_ARG, | 83 | .type = OPTION_ARG, |
84 | .opt.arg = &passwd_config.infile, | 84 | .opt.arg = &cfg.infile, |
85 | }, | 85 | }, |
86 | { | 86 | { |
87 | .name = "noverify", | 87 | .name = "noverify", |
88 | .desc = "Do not verify password", | 88 | .desc = "Do not verify password", |
89 | .type = OPTION_FLAG, | 89 | .type = OPTION_FLAG, |
90 | .opt.flag = &passwd_config.noverify, | 90 | .opt.flag = &cfg.noverify, |
91 | }, | 91 | }, |
92 | { | 92 | { |
93 | .name = "quiet", | 93 | .name = "quiet", |
94 | .desc = "Do not output warnings", | 94 | .desc = "Do not output warnings", |
95 | .type = OPTION_FLAG, | 95 | .type = OPTION_FLAG, |
96 | .opt.flag = &passwd_config.quiet, | 96 | .opt.flag = &cfg.quiet, |
97 | }, | 97 | }, |
98 | { | 98 | { |
99 | .name = "reverse", | 99 | .name = "reverse", |
100 | .desc = "Reverse table columns (requires -table)", | 100 | .desc = "Reverse table columns (requires -table)", |
101 | .type = OPTION_FLAG, | 101 | .type = OPTION_FLAG, |
102 | .opt.flag = &passwd_config.reverse, | 102 | .opt.flag = &cfg.reverse, |
103 | }, | 103 | }, |
104 | { | 104 | { |
105 | .name = "salt", | 105 | .name = "salt", |
106 | .argname = "string", | 106 | .argname = "string", |
107 | .desc = "Use specified salt", | 107 | .desc = "Use specified salt", |
108 | .type = OPTION_ARG, | 108 | .type = OPTION_ARG, |
109 | .opt.arg = &passwd_config.salt, | 109 | .opt.arg = &cfg.salt, |
110 | }, | 110 | }, |
111 | { | 111 | { |
112 | .name = "stdin", | 112 | .name = "stdin", |
113 | .desc = "Read passwords from stdin", | 113 | .desc = "Read passwords from stdin", |
114 | .type = OPTION_FLAG, | 114 | .type = OPTION_FLAG, |
115 | .opt.flag = &passwd_config.in_stdin, | 115 | .opt.flag = &cfg.in_stdin, |
116 | }, | 116 | }, |
117 | { | 117 | { |
118 | .name = "table", | 118 | .name = "table", |
119 | .desc = "Output cleartext and hashed passwords (tab separated)", | 119 | .desc = "Output cleartext and hashed passwords (tab separated)", |
120 | .type = OPTION_FLAG, | 120 | .type = OPTION_FLAG, |
121 | .opt.flag = &passwd_config.table, | 121 | .opt.flag = &cfg.table, |
122 | }, | 122 | }, |
123 | { NULL }, | 123 | { NULL }, |
124 | }; | 124 | }; |
@@ -150,7 +150,7 @@ passwd_main(int argc, char **argv) | |||
150 | exit(1); | 150 | exit(1); |
151 | } | 151 | } |
152 | 152 | ||
153 | memset(&passwd_config, 0, sizeof(passwd_config)); | 153 | memset(&cfg, 0, sizeof(cfg)); |
154 | 154 | ||
155 | if (options_parse(argc, argv, passwd_options, NULL, &argsused) != 0) { | 155 | if (options_parse(argc, argv, passwd_options, NULL, &argsused) != 0) { |
156 | passwd_usage(); | 156 | passwd_usage(); |
@@ -159,23 +159,23 @@ passwd_main(int argc, char **argv) | |||
159 | 159 | ||
160 | if (argsused < argc) | 160 | if (argsused < argc) |
161 | passwds = &argv[argsused]; | 161 | passwds = &argv[argsused]; |
162 | if (passwd_config.salt != NULL) | 162 | if (cfg.salt != NULL) |
163 | passed_salt = 1; | 163 | passed_salt = 1; |
164 | 164 | ||
165 | if (!passwd_config.usecrypt && !passwd_config.use1 && | 165 | if (!cfg.usecrypt && !cfg.use1 && |
166 | !passwd_config.useapr1) | 166 | !cfg.useapr1) |
167 | passwd_config.usecrypt = 1; /* use default */ | 167 | cfg.usecrypt = 1; /* use default */ |
168 | if (passwd_config.usecrypt + passwd_config.use1 + | 168 | if (cfg.usecrypt + cfg.use1 + |
169 | passwd_config.useapr1 > 1) | 169 | cfg.useapr1 > 1) |
170 | badopt = 1; /* conflicting options */ | 170 | badopt = 1; /* conflicting options */ |
171 | 171 | ||
172 | /* Reject unsupported algorithms */ | 172 | /* Reject unsupported algorithms */ |
173 | #ifdef OPENSSL_NO_DES | 173 | #ifdef OPENSSL_NO_DES |
174 | if (passwd_config.usecrypt) | 174 | if (cfg.usecrypt) |
175 | badopt = 1; | 175 | badopt = 1; |
176 | #endif | 176 | #endif |
177 | #ifdef NO_MD5CRYPT_1 | 177 | #ifdef NO_MD5CRYPT_1 |
178 | if (passwd_config.use1 || passwd_config.useapr1) | 178 | if (cfg.use1 || cfg.useapr1) |
179 | badopt = 1; | 179 | badopt = 1; |
180 | #endif | 180 | #endif |
181 | 181 | ||
@@ -188,21 +188,21 @@ passwd_main(int argc, char **argv) | |||
188 | goto err; | 188 | goto err; |
189 | BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); | 189 | BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); |
190 | 190 | ||
191 | if (passwd_config.infile != NULL || passwd_config.in_stdin) { | 191 | if (cfg.infile != NULL || cfg.in_stdin) { |
192 | if ((in = BIO_new(BIO_s_file())) == NULL) | 192 | if ((in = BIO_new(BIO_s_file())) == NULL) |
193 | goto err; | 193 | goto err; |
194 | if (passwd_config.infile != NULL) { | 194 | if (cfg.infile != NULL) { |
195 | assert(passwd_config.in_stdin == 0); | 195 | assert(cfg.in_stdin == 0); |
196 | if (BIO_read_filename(in, passwd_config.infile) <= 0) | 196 | if (BIO_read_filename(in, cfg.infile) <= 0) |
197 | goto err; | 197 | goto err; |
198 | } else { | 198 | } else { |
199 | assert(passwd_config.in_stdin); | 199 | assert(cfg.in_stdin); |
200 | BIO_set_fp(in, stdin, BIO_NOCLOSE); | 200 | BIO_set_fp(in, stdin, BIO_NOCLOSE); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | if (passwd_config.usecrypt) | 203 | if (cfg.usecrypt) |
204 | pw_maxlen = 8; | 204 | pw_maxlen = 8; |
205 | else if (passwd_config.use1 || passwd_config.useapr1) | 205 | else if (cfg.use1 || cfg.useapr1) |
206 | pw_maxlen = 256;/* arbitrary limit, should be enough for most | 206 | pw_maxlen = 256;/* arbitrary limit, should be enough for most |
207 | * passwords */ | 207 | * passwords */ |
208 | 208 | ||
@@ -223,7 +223,7 @@ passwd_main(int argc, char **argv) | |||
223 | if (in == NULL) | 223 | if (in == NULL) |
224 | if (EVP_read_pw_string(passwd_malloc, | 224 | if (EVP_read_pw_string(passwd_malloc, |
225 | passwd_malloc_size, "Password: ", | 225 | passwd_malloc_size, "Password: ", |
226 | !(passed_salt || passwd_config.noverify)) != 0) | 226 | !(passed_salt || cfg.noverify)) != 0) |
227 | goto err; | 227 | goto err; |
228 | passwds[0] = passwd_malloc; | 228 | passwds[0] = passwd_malloc; |
229 | } | 229 | } |
@@ -233,11 +233,11 @@ passwd_main(int argc, char **argv) | |||
233 | 233 | ||
234 | do { /* loop over list of passwords */ | 234 | do { /* loop over list of passwords */ |
235 | passwd = *passwds++; | 235 | passwd = *passwds++; |
236 | if (!do_passwd(passed_salt, &passwd_config.salt, | 236 | if (!do_passwd(passed_salt, &cfg.salt, |
237 | &salt_malloc, passwd, out, passwd_config.quiet, | 237 | &salt_malloc, passwd, out, cfg.quiet, |
238 | passwd_config.table, passwd_config.reverse, | 238 | cfg.table, cfg.reverse, |
239 | pw_maxlen, passwd_config.usecrypt, | 239 | pw_maxlen, cfg.usecrypt, |
240 | passwd_config.use1, passwd_config.useapr1)) | 240 | cfg.use1, cfg.useapr1)) |
241 | goto err; | 241 | goto err; |
242 | } while (*passwds != NULL); | 242 | } while (*passwds != NULL); |
243 | } else { | 243 | } else { |
@@ -258,12 +258,12 @@ passwd_main(int argc, char **argv) | |||
258 | while ((r > 0) && (!strchr(trash, '\n'))); | 258 | while ((r > 0) && (!strchr(trash, '\n'))); |
259 | } | 259 | } |
260 | 260 | ||
261 | if (!do_passwd(passed_salt, &passwd_config.salt, | 261 | if (!do_passwd(passed_salt, &cfg.salt, |
262 | &salt_malloc, passwd, out, | 262 | &salt_malloc, passwd, out, |
263 | passwd_config.quiet, passwd_config.table, | 263 | cfg.quiet, cfg.table, |
264 | passwd_config.reverse, pw_maxlen, | 264 | cfg.reverse, pw_maxlen, |
265 | passwd_config.usecrypt, passwd_config.use1, | 265 | cfg.usecrypt, cfg.use1, |
266 | passwd_config.useapr1)) | 266 | cfg.useapr1)) |
267 | goto err; | 267 | goto err; |
268 | } | 268 | } |
269 | done = (r <= 0); | 269 | done = (r <= 0); |