]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/srp.c
Check # of arguments for remaining commands.
[thirdparty/openssl.git] / apps / srp.c
CommitLineData
0f113f3e 1/*
2234212c 2 * Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
edc032b5 3 *
846e33c7
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
edc032b5 8 */
effaf4de 9
edc032b5 10#include <openssl/opensslconf.h>
effaf4de
RS
11#ifdef OPENSSL_NO_SRP
12NON_EMPTY_TRANSLATION_UNIT
13#else
edc032b5 14
effaf4de
RS
15# include <stdio.h>
16# include <stdlib.h>
17# include <string.h>
18# include <openssl/conf.h>
19# include <openssl/bio.h>
20# include <openssl/err.h>
21# include <openssl/txt_db.h>
22# include <openssl/buffer.h>
23# include <openssl/srp.h>
24# include "apps.h"
6e81b270 25
6e81b270
AP
26# define BASE_SECTION "srp"
27# define CONFIG_FILE "openssl.cnf"
28
6e81b270
AP
29
30# define ENV_DATABASE "srpvfile"
31# define ENV_DEFAULT_SRP "default_srp"
32
6e81b270
AP
33static int get_index(CA_DB *db, char *id, char type)
34{
35 char **pp;
36 int i;
37 if (id == NULL)
38 return -1;
5ec3210f 39 if (type == DB_SRP_INDEX) {
6e81b270
AP
40 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
41 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
42 if (pp[DB_srptype][0] == DB_SRP_INDEX
86885c28 43 && strcmp(id, pp[DB_srpid]) == 0)
6e81b270 44 return i;
5ec3210f
DSC
45 }
46 } else {
6e81b270
AP
47 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
48 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
49
50 if (pp[DB_srptype][0] != DB_SRP_INDEX
86885c28 51 && strcmp(id, pp[DB_srpid]) == 0)
6e81b270
AP
52 return i;
53 }
5ec3210f 54 }
6e81b270
AP
55
56 return -1;
57}
edc032b5 58
ecf3a1fb 59static void print_entry(CA_DB *db, int indx, int verbose, char *s)
6e81b270
AP
60{
61 if (indx >= 0 && verbose) {
62 int j;
63 char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
ecf3a1fb 64 BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
6e81b270
AP
65 for (j = 0; j < DB_NUMBER; j++) {
66 BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
67 }
68 }
69}
edc032b5 70
ecf3a1fb 71static void print_index(CA_DB *db, int indexindex, int verbose)
6e81b270 72{
ecf3a1fb 73 print_entry(db, indexindex, verbose, "g N entry");
6e81b270 74}
edc032b5 75
ecf3a1fb 76static void print_user(CA_DB *db, int userindex, int verbose)
6e81b270
AP
77{
78 if (verbose > 0) {
79 char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
edc032b5 80
6e81b270 81 if (pp[DB_srptype][0] != 'I') {
ecf3a1fb
RS
82 print_entry(db, userindex, verbose, "User entry");
83 print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
6e81b270
AP
84 "g N entry");
85 }
edc032b5 86
6e81b270
AP
87 }
88}
edc032b5 89
ecf3a1fb 90static int update_index(CA_DB *db, char **row)
6e81b270
AP
91{
92 char **irow;
93 int i;
94
b4faea50 95 irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
0fbaef9e 96 for (i = 0; i < DB_NUMBER; i++)
6e81b270 97 irow[i] = row[i];
6e81b270
AP
98 irow[DB_NUMBER] = NULL;
99
100 if (!TXT_DB_insert(db->db, irow)) {
ecf3a1fb
RS
101 BIO_printf(bio_err, "failed to update srpvfile\n");
102 BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
6e81b270
AP
103 OPENSSL_free(irow);
104 return 0;
105 }
106 return 1;
107}
edc032b5 108
edbff8da 109static char *lookup_conf(const CONF *conf, const char *section, const char *tag)
6e81b270 110{
edbff8da
F
111 char *entry = NCONF_get_string(conf, section, tag);
112 if (entry == NULL)
113 BIO_printf(bio_err, "variable lookup failed for %s::%s\n", section, tag);
114 return entry;
6e81b270 115}
edc032b5
BL
116
117static char *srp_verify_user(const char *user, const char *srp_verifier,
6e81b270 118 char *srp_usersalt, const char *g, const char *N,
ecf3a1fb 119 const char *passin, int verbose)
6e81b270 120{
0e83981d 121 char password[1025];
6e81b270
AP
122 PW_CB_DATA cb_tmp;
123 char *verifier = NULL;
124 char *gNid = NULL;
0e83981d 125 int len;
6e81b270
AP
126
127 cb_tmp.prompt_info = user;
128 cb_tmp.password = passin;
129
0e83981d
DSC
130 len = password_callback(password, sizeof(password)-1, 0, &cb_tmp);
131 if (len > 0) {
132 password[len] = 0;
7e1b7485 133 if (verbose)
ecf3a1fb 134 BIO_printf(bio_err,
7e1b7485
RS
135 "Validating\n user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
136 user, srp_verifier, srp_usersalt, g, N);
0e83981d
DSC
137 if (verbose > 1)
138 BIO_printf(bio_err, "Pass %s\n", password);
6e81b270
AP
139
140 OPENSSL_assert(srp_usersalt != NULL);
2234212c
PY
141 if ((gNid = SRP_create_verifier(user, password, &srp_usersalt,
142 &verifier, N, g)) == NULL) {
ecf3a1fb 143 BIO_printf(bio_err, "Internal error validating SRP verifier\n");
6e81b270
AP
144 } else {
145 if (strcmp(verifier, srp_verifier))
146 gNid = NULL;
147 OPENSSL_free(verifier);
148 }
0e83981d 149 OPENSSL_cleanse(password, len);
6e81b270
AP
150 }
151 return gNid;
152}
edc032b5 153
71fa4513 154static char *srp_create_user(char *user, char **srp_verifier,
6e81b270 155 char **srp_usersalt, char *g, char *N,
ecf3a1fb 156 char *passout, int verbose)
6e81b270 157{
0e83981d 158 char password[1025];
6e81b270
AP
159 PW_CB_DATA cb_tmp;
160 char *gNid = NULL;
161 char *salt = NULL;
0e83981d 162 int len;
6e81b270
AP
163 cb_tmp.prompt_info = user;
164 cb_tmp.password = passout;
165
0e83981d
DSC
166 len = password_callback(password, sizeof(password)-1, 1, &cb_tmp);
167 if (len > 0) {
168 password[len] = 0;
7e1b7485 169 if (verbose)
ecf3a1fb 170 BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
7e1b7485 171 user, g, N);
2234212c
PY
172 if ((gNid = SRP_create_verifier(user, password, &salt,
173 srp_verifier, N, g)) == NULL) {
ecf3a1fb 174 BIO_printf(bio_err, "Internal error creating SRP verifier\n");
0e83981d 175 } else {
6e81b270 176 *srp_usersalt = salt;
0e83981d
DSC
177 }
178 OPENSSL_cleanse(password, len);
7e1b7485 179 if (verbose > 1)
0e83981d
DSC
180 BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n",
181 gNid, salt, *srp_verifier);
6e81b270
AP
182
183 }
184 return gNid;
185}
edc032b5 186
7e1b7485
RS
187typedef enum OPTION_choice {
188 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
189 OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
190 OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
f1b8b001 191 OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE, OPT_R_ENUM
7e1b7485
RS
192} OPTION_CHOICE;
193
44c83ebd 194const OPTIONS srp_options[] = {
7e1b7485
RS
195 {"help", OPT_HELP, '-', "Display this summary"},
196 {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
197 {"config", OPT_CONFIG, '<', "A config file"},
198 {"name", OPT_NAME, 's', "The particular srp definition to use"},
199 {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
200 {"add", OPT_ADD, '-', "Add a user and srp verifier"},
201 {"modify", OPT_MODIFY, '-',
202 "Modify the srp verifier of an existing user"},
203 {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
204 {"list", OPT_LIST, '-', "List users"},
205 {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
206 {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
207 {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
208 {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
3ee1eac2 209 OPT_R_OPTIONS,
6e81b270 210# ifndef OPENSSL_NO_ENGINE
7e1b7485 211 {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
6e81b270 212# endif
7e1b7485
RS
213 {NULL}
214};
215
216int srp_main(int argc, char **argv)
217{
dd1abd44 218 ENGINE *e = NULL;
7e1b7485 219 CA_DB *db = NULL;
7e1b7485 220 CONF *conf = NULL;
cc01d217
RS
221 int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
222 int doupdatedb = 0, mode = OPT_ERR;
7e1b7485
RS
223 char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
224 char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
3ee1eac2 225 char *section = NULL;
dfd6211c
MC
226 char **gNrow = NULL, *configfile = NULL;
227 char *srpvfile = NULL, **pp, *prog;
7e1b7485 228 OPTION_CHOICE o;
6e81b270 229
7e1b7485
RS
230 prog = opt_init(argc, argv, srp_options);
231 while ((o = opt_next()) != OPT_EOF) {
232 switch (o) {
233 case OPT_EOF:
234 case OPT_ERR:
235 opthelp:
236 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
237 goto end;
238 case OPT_HELP:
239 opt_help(srp_options);
240 ret = 0;
241 goto end;
242 case OPT_VERBOSE:
6e81b270 243 verbose++;
6e81b270 244 break;
7e1b7485
RS
245 case OPT_CONFIG:
246 configfile = opt_arg();
6e81b270 247 break;
7e1b7485
RS
248 case OPT_NAME:
249 section = opt_arg();
250 break;
251 case OPT_SRPVFILE:
dfd6211c 252 srpvfile = opt_arg();
7e1b7485
RS
253 break;
254 case OPT_ADD:
255 case OPT_DELETE:
256 case OPT_MODIFY:
257 case OPT_LIST:
258 if (mode != OPT_ERR) {
259 BIO_printf(bio_err,
0e83981d 260 "%s: Only one of -add/-delete/-modify/-list\n",
7e1b7485
RS
261 prog);
262 goto opthelp;
263 }
264 mode = o;
265 break;
266 case OPT_GN:
267 gN = opt_arg();
268 break;
269 case OPT_USERINFO:
270 userinfo = opt_arg();
271 break;
272 case OPT_PASSIN:
273 passinarg = opt_arg();
274 break;
275 case OPT_PASSOUT:
276 passoutarg = opt_arg();
277 break;
278 case OPT_ENGINE:
dd1abd44 279 e = setup_engine(opt_arg(), 0);
7e1b7485 280 break;
3ee1eac2
RS
281 case OPT_R_CASES:
282 if (!opt_rand(o))
283 goto end;
284 break;
7e1b7485 285 }
6e81b270 286 }
7e1b7485
RS
287 argc = opt_num_rest();
288 argv = opt_rest();
6e81b270 289
2234212c 290 if (srpvfile != NULL && configfile != NULL) {
6e81b270 291 BIO_printf(bio_err,
dfd6211c 292 "-srpvfile and -configfile cannot be specified together.\n");
7e1b7485 293 goto end;
6e81b270 294 }
7e1b7485
RS
295 if (mode == OPT_ERR) {
296 BIO_printf(bio_err,
297 "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
298 goto opthelp;
6e81b270 299 }
c27363f5
RS
300 if (mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD) {
301 if (argc == 0) {
302 BIO_printf(bio_err, "Need at least one user.\n");
303 goto opthelp;
304 }
305 user = *argv++;
6e81b270 306 }
2234212c 307 if ((passinarg != NULL || passoutarg != NULL) && argc != 1) {
6e81b270
AP
308 BIO_printf(bio_err,
309 "-passin, -passout arguments only valid with one user.\n");
7e1b7485 310 goto opthelp;
6e81b270 311 }
6e81b270 312
7e1b7485 313 if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
6e81b270 314 BIO_printf(bio_err, "Error getting passwords\n");
7e1b7485 315 goto end;
6e81b270
AP
316 }
317
2234212c
PY
318 if (srpvfile == NULL) {
319 if (configfile == NULL)
dfd6211c
MC
320 configfile = default_config_file;
321
7e1b7485 322 if (verbose)
cc01d217
RS
323 BIO_printf(bio_err, "Using configuration from %s\n",
324 configfile);
325 conf = app_load_config(configfile);
326 if (conf == NULL)
7e1b7485 327 goto end;
c821defc 328 if (configfile != default_config_file && !app_load_modules(conf))
296f54ee 329 goto end;
6e81b270 330
6e81b270
AP
331 /* Lets get the config section we are using */
332 if (section == NULL) {
7e1b7485
RS
333 if (verbose)
334 BIO_printf(bio_err,
335 "trying to read " ENV_DEFAULT_SRP
44fdf1c2 336 " in " BASE_SECTION "\n");
6e81b270 337
edbff8da
F
338 section = lookup_conf(conf, BASE_SECTION, ENV_DEFAULT_SRP);
339 if (section == NULL)
7e1b7485 340 goto end;
6e81b270
AP
341 }
342
3ee1eac2 343 app_RAND_load_conf(conf, BASE_SECTION);
6e81b270 344
7e1b7485
RS
345 if (verbose)
346 BIO_printf(bio_err,
347 "trying to read " ENV_DATABASE " in section \"%s\"\n",
348 section);
6e81b270 349
edbff8da
F
350 srpvfile = lookup_conf(conf, section, ENV_DATABASE);
351 if (srpvfile == NULL)
7e1b7485 352 goto end;
6e81b270 353 }
6e81b270 354
7e1b7485
RS
355 if (verbose)
356 BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
dfd6211c 357 srpvfile);
6e81b270 358
9d7ec809 359 db = load_index(srpvfile, NULL);
6e81b270 360 if (db == NULL)
7e1b7485 361 goto end;
6e81b270
AP
362
363 /* Lets check some fields */
364 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
365 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
366
367 if (pp[DB_srptype][0] == DB_SRP_INDEX) {
368 maxgN = i;
86885c28 369 if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
6e81b270
AP
370 gNindex = i;
371
ecf3a1fb 372 print_index(db, i, verbose > 1);
6e81b270
AP
373 }
374 }
375
7e1b7485
RS
376 if (verbose)
377 BIO_printf(bio_err, "Database initialised\n");
6e81b270
AP
378
379 if (gNindex >= 0) {
380 gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
ecf3a1fb 381 print_entry(db, gNindex, verbose > 1, "Default g and N");
6e81b270
AP
382 } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
383 BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
7e1b7485 384 goto end;
6e81b270 385 } else {
7e1b7485
RS
386 if (verbose)
387 BIO_printf(bio_err, "Database has no g N information.\n");
6e81b270
AP
388 gNrow = NULL;
389 }
390
7e1b7485
RS
391 if (verbose > 1)
392 BIO_printf(bio_err, "Starting user processing\n");
6e81b270 393
c27363f5 394 while (mode == OPT_LIST || user != NULL) {
6e81b270 395 int userindex = -1;
edbff8da
F
396
397 if (user != NULL && verbose > 1)
398 BIO_printf(bio_err, "Processing user \"%s\"\n", user);
2234212c 399 if ((userindex = get_index(db, user, 'U')) >= 0)
edbff8da 400 print_user(db, userindex, (verbose > 0) || mode == OPT_LIST);
6e81b270 401
7e1b7485 402 if (mode == OPT_LIST) {
6e81b270
AP
403 if (user == NULL) {
404 BIO_printf(bio_err, "List all users\n");
405
2234212c 406 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++)
ecf3a1fb 407 print_user(db, i, 1);
6e81b270
AP
408 } else if (userindex < 0) {
409 BIO_printf(bio_err,
410 "user \"%s\" does not exist, ignored. t\n", user);
411 errors++;
412 }
7e1b7485 413 } else if (mode == OPT_ADD) {
6e81b270
AP
414 if (userindex >= 0) {
415 /* reactivation of a new user */
416 char **row =
417 sk_OPENSSL_PSTRING_value(db->db->data, userindex);
418 BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
419 row[DB_srptype][0] = 'V';
420
421 doupdatedb = 1;
422 } else {
423 char *row[DB_NUMBER];
424 char *gNid;
425 row[DB_srpverifier] = NULL;
426 row[DB_srpsalt] = NULL;
427 row[DB_srpinfo] = NULL;
7e1b7485
RS
428 if (!
429 (gNid =
430 srp_create_user(user, &(row[DB_srpverifier]),
431 &(row[DB_srpsalt]),
432 gNrow ? gNrow[DB_srpsalt] : gN,
433 gNrow ? gNrow[DB_srpverifier] : NULL,
ecf3a1fb 434 passout, verbose))) {
6e81b270 435 BIO_printf(bio_err,
7e1b7485
RS
436 "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
437 user);
6e81b270 438 errors++;
7e1b7485 439 goto end;
6e81b270 440 }
7644a9ae
RS
441 row[DB_srpid] = OPENSSL_strdup(user);
442 row[DB_srptype] = OPENSSL_strdup("v");
443 row[DB_srpgN] = OPENSSL_strdup(gNid);
6e81b270 444
75ebbd9a
RS
445 if ((row[DB_srpid] == NULL)
446 || (row[DB_srpgN] == NULL)
447 || (row[DB_srptype] == NULL)
448 || (row[DB_srpverifier] == NULL)
449 || (row[DB_srpsalt] == NULL)
450 || (userinfo
7644a9ae 451 && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))
ecf3a1fb 452 || !update_index(db, row)) {
b548a1f1
RS
453 OPENSSL_free(row[DB_srpid]);
454 OPENSSL_free(row[DB_srpgN]);
455 OPENSSL_free(row[DB_srpinfo]);
456 OPENSSL_free(row[DB_srptype]);
457 OPENSSL_free(row[DB_srpverifier]);
458 OPENSSL_free(row[DB_srpsalt]);
7e1b7485 459 goto end;
6e81b270
AP
460 }
461 doupdatedb = 1;
462 }
7e1b7485 463 } else if (mode == OPT_MODIFY) {
6e81b270
AP
464 if (userindex < 0) {
465 BIO_printf(bio_err,
466 "user \"%s\" does not exist, operation ignored.\n",
467 user);
468 errors++;
469 } else {
470
471 char **row =
472 sk_OPENSSL_PSTRING_value(db->db->data, userindex);
473 char type = row[DB_srptype][0];
474 if (type == 'v') {
475 BIO_printf(bio_err,
476 "user \"%s\" already updated, operation ignored.\n",
477 user);
478 errors++;
479 } else {
480 char *gNid;
481
482 if (row[DB_srptype][0] == 'V') {
483 int user_gN;
484 char **irow = NULL;
7e1b7485
RS
485 if (verbose)
486 BIO_printf(bio_err,
487 "Verifying password for user \"%s\"\n",
488 user);
6e81b270
AP
489 if ((user_gN =
490 get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
491 irow =
492 sk_OPENSSL_PSTRING_value(db->db->data,
493 userindex);
494
495 if (!srp_verify_user
496 (user, row[DB_srpverifier], row[DB_srpsalt],
497 irow ? irow[DB_srpsalt] : row[DB_srpgN],
498 irow ? irow[DB_srpverifier] : NULL, passin,
ecf3a1fb 499 verbose)) {
6e81b270
AP
500 BIO_printf(bio_err,
501 "Invalid password for user \"%s\", operation abandoned.\n",
502 user);
503 errors++;
7e1b7485 504 goto end;
6e81b270
AP
505 }
506 }
7e1b7485
RS
507 if (verbose)
508 BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
509 user);
510
511 if (!
512 (gNid =
513 srp_create_user(user, &(row[DB_srpverifier]),
514 &(row[DB_srpsalt]),
515 gNrow ? gNrow[DB_srpsalt] : NULL,
516 gNrow ? gNrow[DB_srpverifier] : NULL,
ecf3a1fb 517 passout, verbose))) {
6e81b270 518 BIO_printf(bio_err,
7e1b7485
RS
519 "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
520 user);
6e81b270 521 errors++;
7e1b7485 522 goto end;
6e81b270
AP
523 }
524
525 row[DB_srptype][0] = 'v';
7644a9ae 526 row[DB_srpgN] = OPENSSL_strdup(gNid);
6e81b270 527
75ebbd9a
RS
528 if (row[DB_srpid] == NULL
529 || row[DB_srpgN] == NULL
530 || row[DB_srptype] == NULL
531 || row[DB_srpverifier] == NULL
532 || row[DB_srpsalt] == NULL
6e81b270 533 || (userinfo
7644a9ae 534 && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))
75ebbd9a 535 == NULL)))
7e1b7485 536 goto end;
6e81b270
AP
537
538 doupdatedb = 1;
539 }
540 }
7e1b7485 541 } else if (mode == OPT_DELETE) {
6e81b270
AP
542 if (userindex < 0) {
543 BIO_printf(bio_err,
544 "user \"%s\" does not exist, operation ignored. t\n",
545 user);
546 errors++;
547 } else {
75ebbd9a 548 char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
6e81b270 549
75ebbd9a 550 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
6e81b270 551 xpp[DB_srptype][0] = 'R';
6e81b270
AP
552 doupdatedb = 1;
553 }
554 }
c27363f5
RS
555 user = *argv++;
556 if (user == NULL) {
5ec3210f
DSC
557 /* no more processing in any mode if no users left */
558 break;
6e81b270
AP
559 }
560 }
561
7e1b7485
RS
562 if (verbose)
563 BIO_printf(bio_err, "User procession done.\n");
6e81b270
AP
564
565 if (doupdatedb) {
566 /* Lets check some fields */
567 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
568 pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
569
570 if (pp[DB_srptype][0] == 'v') {
571 pp[DB_srptype][0] = 'V';
ecf3a1fb 572 print_user(db, i, verbose);
6e81b270
AP
573 }
574 }
575
7e1b7485
RS
576 if (verbose)
577 BIO_printf(bio_err, "Trying to update srpvfile.\n");
dfd6211c 578 if (!save_index(srpvfile, "new", db))
7e1b7485 579 goto end;
6e81b270 580
7e1b7485
RS
581 if (verbose)
582 BIO_printf(bio_err, "Temporary srpvfile created.\n");
dfd6211c 583 if (!rotate_index(srpvfile, "new", "old"))
7e1b7485 584 goto end;
6e81b270 585
7e1b7485
RS
586 if (verbose)
587 BIO_printf(bio_err, "srpvfile updated.\n");
6e81b270
AP
588 }
589
590 ret = (errors != 0);
7e1b7485 591 end:
6e81b270 592 if (errors != 0)
7e1b7485
RS
593 if (verbose)
594 BIO_printf(bio_err, "User errors %d.\n", errors);
6e81b270 595
7e1b7485
RS
596 if (verbose)
597 BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
8bf78043 598
7b0ee135
MC
599 OPENSSL_free(passin);
600 OPENSSL_free(passout);
6e81b270
AP
601 if (ret)
602 ERR_print_errors(bio_err);
25aaa98a
RS
603 NCONF_free(conf);
604 free_index(db);
dd1abd44 605 release_engine(e);
7e1b7485 606 return (ret);
6e81b270 607}
edc032b5 608#endif