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