fix s_client crash
[openssl.git] / apps / srp.c
1 /*
2  * Written by Peter Sylvester (peter.sylvester@edelweb.fr) for the EdelKey
3  * project and contributed to the OpenSSL project 2004.
4  */
5 /* ====================================================================
6  * Copyright (c) 2004 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    licensing@OpenSSL.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58 #include <openssl/opensslconf.h>
59
60 #ifndef OPENSSL_NO_SRP
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64 #include <openssl/conf.h>
65 #include <openssl/bio.h>
66 #include <openssl/err.h>
67 #include <openssl/txt_db.h>
68 #include <openssl/buffer.h>
69 #include <openssl/srp.h>
70 #include "apps.h"
71
72 # define BASE_SECTION    "srp"
73 # define CONFIG_FILE "openssl.cnf"
74
75 # define ENV_RANDFILE            "RANDFILE"
76
77 # define ENV_DATABASE            "srpvfile"
78 # define ENV_DEFAULT_SRP         "default_srp"
79
80 static int get_index(CA_DB *db, char *id, char type)
81 {
82     char **pp;
83     int i;
84     if (id == NULL)
85         return -1;
86     if (type == DB_SRP_INDEX)
87         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
88             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
89             if (pp[DB_srptype][0] == DB_SRP_INDEX
90                 && strcmp(id, pp[DB_srpid]) == 0)
91                 return i;
92     } else
93         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
94             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
95
96             if (pp[DB_srptype][0] != DB_SRP_INDEX
97                 && strcmp(id, pp[DB_srpid]) == 0)
98                 return i;
99         }
100
101     return -1;
102 }
103
104 static void print_entry(CA_DB *db, int indx, int verbose, char *s)
105 {
106     if (indx >= 0 && verbose) {
107         int j;
108         char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
109         BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
110         for (j = 0; j < DB_NUMBER; j++) {
111             BIO_printf(bio_err, "  %d = \"%s\"\n", j, pp[j]);
112         }
113     }
114 }
115
116 static void print_index(CA_DB *db, int indexindex, int verbose)
117 {
118     print_entry(db, indexindex, verbose, "g N entry");
119 }
120
121 static void print_user(CA_DB *db, int userindex, int verbose)
122 {
123     if (verbose > 0) {
124         char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
125
126         if (pp[DB_srptype][0] != 'I') {
127             print_entry(db, userindex, verbose, "User entry");
128             print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
129                         "g N entry");
130         }
131
132     }
133 }
134
135 static int update_index(CA_DB *db, char **row)
136 {
137     char **irow;
138     int i;
139
140     irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");
141     for (i = 0; i < DB_NUMBER; i++) {
142         irow[i] = row[i];
143         row[i] = NULL;
144     }
145     irow[DB_NUMBER] = NULL;
146
147     if (!TXT_DB_insert(db->db, irow)) {
148         BIO_printf(bio_err, "failed to update srpvfile\n");
149         BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
150         OPENSSL_free(irow);
151         return 0;
152     }
153     return 1;
154 }
155
156 static void lookup_fail(const char *name, const char *tag)
157 {
158     BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
159 }
160
161 static char *srp_verify_user(const char *user, const char *srp_verifier,
162                              char *srp_usersalt, const char *g, const char *N,
163                              const char *passin, int verbose)
164 {
165     char password[1024];
166     PW_CB_DATA cb_tmp;
167     char *verifier = NULL;
168     char *gNid = NULL;
169
170     cb_tmp.prompt_info = user;
171     cb_tmp.password = passin;
172
173     if (password_callback(password, 1024, 0, &cb_tmp) > 0) {
174         if (verbose)
175             BIO_printf(bio_err,
176                        "Validating\n   user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
177                        user, srp_verifier, srp_usersalt, g, N);
178         BIO_printf(bio_err, "Pass %s\n", password);
179
180         OPENSSL_assert(srp_usersalt != NULL);
181         if (!
182             (gNid =
183              SRP_create_verifier(user, password, &srp_usersalt, &verifier, N,
184                                  g))) {
185             BIO_printf(bio_err, "Internal error validating SRP verifier\n");
186         } else {
187             if (strcmp(verifier, srp_verifier))
188                 gNid = NULL;
189             OPENSSL_free(verifier);
190         }
191     }
192     return gNid;
193 }
194
195 static char *srp_create_user(char *user, char **srp_verifier,
196                              char **srp_usersalt, char *g, char *N,
197                              char *passout, int verbose)
198 {
199     char password[1024];
200     PW_CB_DATA cb_tmp;
201     char *gNid = NULL;
202     char *salt = NULL;
203     cb_tmp.prompt_info = user;
204     cb_tmp.password = passout;
205
206     if (password_callback(password, 1024, 1, &cb_tmp) > 0) {
207         if (verbose)
208             BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
209                        user, g, N);
210         if (!
211             (gNid =
212              SRP_create_verifier(user, password, &salt, srp_verifier, N,
213                                  g))) {
214             BIO_printf(bio_err, "Internal error creating SRP verifier\n");
215         } else
216             *srp_usersalt = salt;
217         if (verbose > 1)
218             BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n", gNid,
219                        salt, *srp_verifier);
220
221     }
222     return gNid;
223 }
224
225 typedef enum OPTION_choice {
226     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
227     OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
228     OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
229     OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE
230 } OPTION_CHOICE;
231
232 OPTIONS srp_options[] = {
233     {"help", OPT_HELP, '-', "Display this summary"},
234     {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
235     {"config", OPT_CONFIG, '<', "A config file"},
236     {"name", OPT_NAME, 's', "The particular srp definition to use"},
237     {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
238     {"add", OPT_ADD, '-', "Add a user and srp verifier"},
239     {"modify", OPT_MODIFY, '-',
240      "Modify the srp verifier of an existing user"},
241     {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
242     {"list", OPT_LIST, '-', "List users"},
243     {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
244     {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
245     {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
246     {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
247 # ifndef OPENSSL_NO_ENGINE
248     {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
249 # endif
250     {NULL}
251 };
252
253 int srp_main(int argc, char **argv)
254 {
255     CA_DB *db = NULL;
256     DB_ATTR db_attr;
257     CONF *conf = NULL;
258     int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose =
259         0, i, doupdatedb = 0;
260     int mode = OPT_ERR;
261     char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
262     char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
263     char *randfile = NULL, *tofree = NULL, *section = NULL;
264     char **gNrow = NULL, *configfile = NULL, *dbfile = NULL, **pp, *prog;
265     long errorline = -1;
266     OPTION_CHOICE o;
267
268     prog = opt_init(argc, argv, srp_options);
269     while ((o = opt_next()) != OPT_EOF) {
270         switch (o) {
271         case OPT_EOF:
272         case OPT_ERR:
273  opthelp:
274             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
275             goto end;
276         case OPT_HELP:
277             opt_help(srp_options);
278             ret = 0;
279             goto end;
280         case OPT_VERBOSE:
281             verbose++;
282             break;
283         case OPT_CONFIG:
284             configfile = opt_arg();
285             break;
286         case OPT_NAME:
287             section = opt_arg();
288             break;
289         case OPT_SRPVFILE:
290             dbfile = opt_arg();
291             break;
292         case OPT_ADD:
293         case OPT_DELETE:
294         case OPT_MODIFY:
295         case OPT_LIST:
296             if (mode != OPT_ERR) {
297                 BIO_printf(bio_err,
298                            "%s: Only one of -add/delete-modify/-list\n",
299                            prog);
300                 goto opthelp;
301             }
302             mode = o;
303             break;
304         case OPT_GN:
305             gN = opt_arg();
306             break;
307         case OPT_USERINFO:
308             userinfo = opt_arg();
309             break;
310         case OPT_PASSIN:
311             passinarg = opt_arg();
312             break;
313         case OPT_PASSOUT:
314             passoutarg = opt_arg();
315             break;
316         case OPT_ENGINE:
317             (void)setup_engine(opt_arg(), 0);
318             break;
319         }
320     }
321     argc = opt_num_rest();
322     argv = opt_rest();
323
324     if (dbfile && configfile) {
325         BIO_printf(bio_err,
326                    "-dbfile and -configfile cannot be specified together.\n");
327         goto end;
328     }
329     if (mode == OPT_ERR) {
330         BIO_printf(bio_err,
331                    "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
332         goto opthelp;
333     }
334     if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD)
335         && argc < 1) {
336         BIO_printf(bio_err,
337                    "Need at least one user for options -add, -delete, -modify. \n");
338         goto opthelp;
339     }
340     if ((passin || passout) && argc != 1) {
341         BIO_printf(bio_err,
342                    "-passin, -passout arguments only valid with one user.\n");
343         goto opthelp;
344     }
345
346     if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
347         BIO_printf(bio_err, "Error getting passwords\n");
348         goto end;
349     }
350
351     if (!dbfile) {
352
353         /*****************************************************************/
354         tofree = NULL;
355         if (configfile == NULL)
356             configfile = getenv("OPENSSL_CONF");
357         if (configfile == NULL)
358             configfile = getenv("SSLEAY_CONF");
359         if (configfile == NULL) {
360             const char *s = X509_get_default_cert_area();
361             size_t len = strlen(s) + 1 + sizeof(CONFIG_FILE);
362
363             tofree = app_malloc(len, "config filename space");
364 # ifdef OPENSSL_SYS_VMS
365             strcpy(tofree, s);
366 # else
367             BUF_strlcpy(tofree, s, len);
368             BUF_strlcat(tofree, "/", len);
369 # endif
370             BUF_strlcat(tofree, CONFIG_FILE, len);
371             configfile = tofree;
372         }
373
374         if (verbose)
375             BIO_printf(bio_err, "Using configuration from %s\n", configfile);
376         conf = NCONF_new(NULL);
377         if (NCONF_load(conf, configfile, &errorline) <= 0) {
378             if (errorline <= 0)
379                 BIO_printf(bio_err, "error loading the config file '%s'\n",
380                            configfile);
381             else
382                 BIO_printf(bio_err, "error on line %ld of config file '%s'\n",
383                            errorline, configfile);
384             goto end;
385         }
386         OPENSSL_free(tofree);
387         tofree = NULL;
388
389         /* Lets get the config section we are using */
390         if (section == NULL) {
391             if (verbose)
392                 BIO_printf(bio_err,
393                            "trying to read " ENV_DEFAULT_SRP
394                            " in \" BASE_SECTION \"\n");
395
396             section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);
397             if (section == NULL) {
398                 lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);
399                 goto end;
400             }
401         }
402
403         if (randfile == NULL && conf)
404             randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
405
406         if (verbose)
407             BIO_printf(bio_err,
408                        "trying to read " ENV_DATABASE " in section \"%s\"\n",
409                        section);
410
411         if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
412             lookup_fail(section, ENV_DATABASE);
413             goto end;
414         }
415
416     }
417     if (randfile == NULL)
418         ERR_clear_error();
419     else
420         app_RAND_load_file(randfile, 0);
421
422     if (verbose)
423         BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
424                    dbfile);
425
426     db = load_index(dbfile, &db_attr);
427     if (db == NULL)
428         goto end;
429
430     /* Lets check some fields */
431     for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
432         pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
433
434         if (pp[DB_srptype][0] == DB_SRP_INDEX) {
435             maxgN = i;
436             if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)
437                 gNindex = i;
438
439             print_index(db, i, verbose > 1);
440         }
441     }
442
443     if (verbose)
444         BIO_printf(bio_err, "Database initialised\n");
445
446     if (gNindex >= 0) {
447         gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
448         print_entry(db, gNindex, verbose > 1, "Default g and N");
449     } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
450         BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
451         goto end;
452     } else {
453         if (verbose)
454             BIO_printf(bio_err, "Database has no g N information.\n");
455         gNrow = NULL;
456     }
457
458     if (verbose > 1)
459         BIO_printf(bio_err, "Starting user processing\n");
460
461     if (argc > 0)
462         user = *(argv++);
463
464     while (mode == OPT_LIST || user) {
465         int userindex = -1;
466         if (user)
467             if (verbose > 1)
468                 BIO_printf(bio_err, "Processing user \"%s\"\n", user);
469         if ((userindex = get_index(db, user, 'U')) >= 0) {
470             print_user(db, userindex, (verbose > 0)
471                        || mode == OPT_LIST);
472         }
473
474         if (mode == OPT_LIST) {
475             if (user == NULL) {
476                 BIO_printf(bio_err, "List all users\n");
477
478                 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
479                     print_user(db, i, 1);
480                 }
481             } else if (userindex < 0) {
482                 BIO_printf(bio_err,
483                            "user \"%s\" does not exist, ignored. t\n", user);
484                 errors++;
485             }
486         } else if (mode == OPT_ADD) {
487             if (userindex >= 0) {
488                 /* reactivation of a new user */
489                 char **row =
490                     sk_OPENSSL_PSTRING_value(db->db->data, userindex);
491                 BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
492                 row[DB_srptype][0] = 'V';
493
494                 doupdatedb = 1;
495             } else {
496                 char *row[DB_NUMBER];
497                 char *gNid;
498                 row[DB_srpverifier] = NULL;
499                 row[DB_srpsalt] = NULL;
500                 row[DB_srpinfo] = NULL;
501                 if (!
502                     (gNid =
503                      srp_create_user(user, &(row[DB_srpverifier]),
504                                      &(row[DB_srpsalt]),
505                                      gNrow ? gNrow[DB_srpsalt] : gN,
506                                      gNrow ? gNrow[DB_srpverifier] : NULL,
507                                      passout, verbose))) {
508                     BIO_printf(bio_err,
509                                "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
510                                user);
511                     errors++;
512                     goto end;
513                 }
514                 row[DB_srpid] = BUF_strdup(user);
515                 row[DB_srptype] = BUF_strdup("v");
516                 row[DB_srpgN] = BUF_strdup(gNid);
517
518                 if ((row[DB_srpid] == NULL)
519                     || (row[DB_srpgN] == NULL)
520                     || (row[DB_srptype] == NULL)
521                     || (row[DB_srpverifier] == NULL)
522                     || (row[DB_srpsalt] == NULL)
523                     || (userinfo
524                         && ((row[DB_srpinfo] = BUF_strdup(userinfo)) == NULL))
525                     || !update_index(db, row)) {
526                     OPENSSL_free(row[DB_srpid]);
527                     OPENSSL_free(row[DB_srpgN]);
528                     OPENSSL_free(row[DB_srpinfo]);
529                     OPENSSL_free(row[DB_srptype]);
530                     OPENSSL_free(row[DB_srpverifier]);
531                     OPENSSL_free(row[DB_srpsalt]);
532                     goto end;
533                 }
534                 doupdatedb = 1;
535             }
536         } else if (mode == OPT_MODIFY) {
537             if (userindex < 0) {
538                 BIO_printf(bio_err,
539                            "user \"%s\" does not exist, operation ignored.\n",
540                            user);
541                 errors++;
542             } else {
543
544                 char **row =
545                     sk_OPENSSL_PSTRING_value(db->db->data, userindex);
546                 char type = row[DB_srptype][0];
547                 if (type == 'v') {
548                     BIO_printf(bio_err,
549                                "user \"%s\" already updated, operation ignored.\n",
550                                user);
551                     errors++;
552                 } else {
553                     char *gNid;
554
555                     if (row[DB_srptype][0] == 'V') {
556                         int user_gN;
557                         char **irow = NULL;
558                         if (verbose)
559                             BIO_printf(bio_err,
560                                        "Verifying password for user \"%s\"\n",
561                                        user);
562                         if ((user_gN =
563                              get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
564                             irow =
565                                 sk_OPENSSL_PSTRING_value(db->db->data,
566                                                          userindex);
567
568                         if (!srp_verify_user
569                             (user, row[DB_srpverifier], row[DB_srpsalt],
570                              irow ? irow[DB_srpsalt] : row[DB_srpgN],
571                              irow ? irow[DB_srpverifier] : NULL, passin,
572                              verbose)) {
573                             BIO_printf(bio_err,
574                                        "Invalid password for user \"%s\", operation abandoned.\n",
575                                        user);
576                             errors++;
577                             goto end;
578                         }
579                     }
580                     if (verbose)
581                         BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
582                                    user);
583
584                     if (!
585                         (gNid =
586                          srp_create_user(user, &(row[DB_srpverifier]),
587                                          &(row[DB_srpsalt]),
588                                          gNrow ? gNrow[DB_srpsalt] : NULL,
589                                          gNrow ? gNrow[DB_srpverifier] : NULL,
590                                          passout, verbose))) {
591                         BIO_printf(bio_err,
592                                    "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
593                                    user);
594                         errors++;
595                         goto end;
596                     }
597
598                     row[DB_srptype][0] = 'v';
599                     row[DB_srpgN] = BUF_strdup(gNid);
600
601                     if (row[DB_srpid] == NULL
602                         || row[DB_srpgN] == NULL
603                         || row[DB_srptype] == NULL
604                         || row[DB_srpverifier] == NULL
605                         || row[DB_srpsalt] == NULL
606                         || (userinfo
607                             && ((row[DB_srpinfo] = BUF_strdup(userinfo))
608                                 == NULL)))
609                         goto end;
610
611                     doupdatedb = 1;
612                 }
613             }
614         } else if (mode == OPT_DELETE) {
615             if (userindex < 0) {
616                 BIO_printf(bio_err,
617                            "user \"%s\" does not exist, operation ignored. t\n",
618                            user);
619                 errors++;
620             } else {
621                 char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
622
623                 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
624                 xpp[DB_srptype][0] = 'R';
625                 doupdatedb = 1;
626             }
627         }
628         if (--argc > 0)
629             user = *(argv++);
630         else {
631             user = NULL;
632         }
633     }
634
635     if (verbose)
636         BIO_printf(bio_err, "User procession done.\n");
637
638     if (doupdatedb) {
639         /* Lets check some fields */
640         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
641             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
642
643             if (pp[DB_srptype][0] == 'v') {
644                 pp[DB_srptype][0] = 'V';
645                 print_user(db, i, verbose);
646             }
647         }
648
649         if (verbose)
650             BIO_printf(bio_err, "Trying to update srpvfile.\n");
651         if (!save_index(dbfile, "new", db))
652             goto end;
653
654         if (verbose)
655             BIO_printf(bio_err, "Temporary srpvfile created.\n");
656         if (!rotate_index(dbfile, "new", "old"))
657             goto end;
658
659         if (verbose)
660             BIO_printf(bio_err, "srpvfile updated.\n");
661     }
662
663     ret = (errors != 0);
664  end:
665     if (errors != 0)
666         if (verbose)
667             BIO_printf(bio_err, "User errors %d.\n", errors);
668
669     if (verbose)
670         BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
671     OPENSSL_free(tofree);
672     if (ret)
673         ERR_print_errors(bio_err);
674     if (randfile)
675         app_RAND_write_file(randfile);
676     NCONF_free(conf);
677     free_index(db);
678     OBJ_cleanup();
679     return (ret);
680 }
681
682 #else
683
684 # if PEDANTIC
685 static void *dummy = &dummy;
686 # endif
687
688 #endif