Remove needless bio_err argument
[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
71 # include "apps.h"
72
73 # define BASE_SECTION    "srp"
74 # define CONFIG_FILE "openssl.cnf"
75
76 # define ENV_RANDFILE            "RANDFILE"
77
78 # define ENV_DATABASE            "srpvfile"
79 # define ENV_DEFAULT_SRP         "default_srp"
80
81 static int get_index(CA_DB *db, char *id, char type)
82 {
83     char **pp;
84     int i;
85     if (id == NULL)
86         return -1;
87     if (type == DB_SRP_INDEX)
88         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
89             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
90             if (pp[DB_srptype][0] == DB_SRP_INDEX
91                 && !strcmp(id, pp[DB_srpid]))
92                 return i;
93     } else
94         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
95             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
96
97             if (pp[DB_srptype][0] != DB_SRP_INDEX
98                 && !strcmp(id, pp[DB_srpid]))
99                 return i;
100         }
101
102     return -1;
103 }
104
105 static void print_entry(CA_DB *db, int indx, int verbose, char *s)
106 {
107     if (indx >= 0 && verbose) {
108         int j;
109         char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
110         BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
111         for (j = 0; j < DB_NUMBER; j++) {
112             BIO_printf(bio_err, "  %d = \"%s\"\n", j, pp[j]);
113         }
114     }
115 }
116
117 static void print_index(CA_DB *db, int indexindex, int verbose)
118 {
119     print_entry(db, indexindex, verbose, "g N entry");
120 }
121
122 static void print_user(CA_DB *db, int userindex, int verbose)
123 {
124     if (verbose > 0) {
125         char **pp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);
126
127         if (pp[DB_srptype][0] != 'I') {
128             print_entry(db, userindex, verbose, "User entry");
129             print_entry(db, get_index(db, pp[DB_srpgN], 'I'), verbose,
130                         "g N entry");
131         }
132
133     }
134 }
135
136 static int update_index(CA_DB *db, char **row)
137 {
138     char **irow;
139     int i;
140
141     if ((irow = OPENSSL_malloc(sizeof(char *) * (DB_NUMBER + 1))) == NULL) {
142         BIO_printf(bio_err, "Memory allocation failure\n");
143         return 0;
144     }
145
146     for (i = 0; i < DB_NUMBER; i++) {
147         irow[i] = row[i];
148         row[i] = NULL;
149     }
150     irow[DB_NUMBER] = NULL;
151
152     if (!TXT_DB_insert(db->db, irow)) {
153         BIO_printf(bio_err, "failed to update srpvfile\n");
154         BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);
155         OPENSSL_free(irow);
156         return 0;
157     }
158     return 1;
159 }
160
161 static void lookup_fail(const char *name, const char *tag)
162 {
163     BIO_printf(bio_err, "variable lookup failed for %s::%s\n", name, tag);
164 }
165
166 static char *srp_verify_user(const char *user, const char *srp_verifier,
167                              char *srp_usersalt, const char *g, const char *N,
168                              const char *passin, int verbose)
169 {
170     char password[1024];
171     PW_CB_DATA cb_tmp;
172     char *verifier = NULL;
173     char *gNid = NULL;
174
175     cb_tmp.prompt_info = user;
176     cb_tmp.password = passin;
177
178     if (password_callback(password, 1024, 0, &cb_tmp) > 0) {
179         if (verbose)
180             BIO_printf(bio_err,
181                        "Validating\n   user=\"%s\"\n srp_verifier=\"%s\"\n srp_usersalt=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
182                        user, srp_verifier, srp_usersalt, g, N);
183         BIO_printf(bio_err, "Pass %s\n", password);
184
185         OPENSSL_assert(srp_usersalt != NULL);
186         if (!
187             (gNid =
188              SRP_create_verifier(user, password, &srp_usersalt, &verifier, N,
189                                  g))) {
190             BIO_printf(bio_err, "Internal error validating SRP verifier\n");
191         } else {
192             if (strcmp(verifier, srp_verifier))
193                 gNid = NULL;
194             OPENSSL_free(verifier);
195         }
196     }
197     return gNid;
198 }
199
200 static char *srp_create_user(char *user, char **srp_verifier,
201                              char **srp_usersalt, char *g, char *N,
202                              char *passout, int verbose)
203 {
204     char password[1024];
205     PW_CB_DATA cb_tmp;
206     char *gNid = NULL;
207     char *salt = NULL;
208     cb_tmp.prompt_info = user;
209     cb_tmp.password = passout;
210
211     if (password_callback(password, 1024, 1, &cb_tmp) > 0) {
212         if (verbose)
213             BIO_printf(bio_err, "Creating\n user=\"%s\"\n g=\"%s\"\n N=\"%s\"\n",
214                        user, g, N);
215         if (!
216             (gNid =
217              SRP_create_verifier(user, password, &salt, srp_verifier, N,
218                                  g))) {
219             BIO_printf(bio_err, "Internal error creating SRP verifier\n");
220         } else
221             *srp_usersalt = salt;
222         if (verbose > 1)
223             BIO_printf(bio_err, "gNid=%s salt =\"%s\"\n verifier =\"%s\"\n", gNid,
224                        salt, *srp_verifier);
225
226     }
227     return gNid;
228 }
229
230 typedef enum OPTION_choice {
231     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
232     OPT_VERBOSE, OPT_CONFIG, OPT_NAME, OPT_SRPVFILE, OPT_ADD,
233     OPT_DELETE, OPT_MODIFY, OPT_LIST, OPT_GN, OPT_USERINFO,
234     OPT_PASSIN, OPT_PASSOUT, OPT_ENGINE
235 } OPTION_CHOICE;
236
237 OPTIONS srp_options[] = {
238     {"help", OPT_HELP, '-', "Display this summary"},
239     {"verbose", OPT_VERBOSE, '-', "Talk a lot while doing things"},
240     {"config", OPT_CONFIG, '<', "A config file"},
241     {"name", OPT_NAME, 's', "The particular srp definition to use"},
242     {"srpvfile", OPT_SRPVFILE, '<', "The srp verifier file name"},
243     {"add", OPT_ADD, '-', "Add a user and srp verifier"},
244     {"modify", OPT_MODIFY, '-',
245      "Modify the srp verifier of an existing user"},
246     {"delete", OPT_DELETE, '-', "Delete user from verifier file"},
247     {"list", OPT_LIST, '-', "List users"},
248     {"gn", OPT_GN, 's', "Set g and N values to be used for new verifier"},
249     {"userinfo", OPT_USERINFO, 's', "Additional info to be set for user"},
250     {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
251     {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
252 # ifndef OPENSSL_NO_ENGINE
253     {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
254 # endif
255     {NULL}
256 };
257
258 int srp_main(int argc, char **argv)
259 {
260     CA_DB *db = NULL;
261     DB_ATTR db_attr;
262     CONF *conf = NULL;
263     int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose =
264         0, i, doupdatedb = 0;
265     int mode = OPT_ERR;
266     char *user = NULL, *passinarg = NULL, *passoutarg = NULL;
267     char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;
268     char *randfile = NULL, *tofree = NULL, *section = NULL;
269     char **gNrow = NULL, *configfile = NULL, *dbfile = NULL, **pp, *prog;
270     long errorline = -1;
271     OPTION_CHOICE o;
272
273     prog = opt_init(argc, argv, srp_options);
274     while ((o = opt_next()) != OPT_EOF) {
275         switch (o) {
276         case OPT_EOF:
277         case OPT_ERR:
278  opthelp:
279             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
280             goto end;
281         case OPT_HELP:
282             opt_help(srp_options);
283             ret = 0;
284             goto end;
285         case OPT_VERBOSE:
286             verbose++;
287             break;
288         case OPT_CONFIG:
289             configfile = opt_arg();
290             break;
291         case OPT_NAME:
292             section = opt_arg();
293             break;
294         case OPT_SRPVFILE:
295             dbfile = opt_arg();
296             break;
297         case OPT_ADD:
298         case OPT_DELETE:
299         case OPT_MODIFY:
300         case OPT_LIST:
301             if (mode != OPT_ERR) {
302                 BIO_printf(bio_err,
303                            "%s: Only one of -add/delete-modify/-list\n",
304                            prog);
305                 goto opthelp;
306             }
307             mode = o;
308             break;
309         case OPT_GN:
310             gN = opt_arg();
311             break;
312         case OPT_USERINFO:
313             userinfo = opt_arg();
314             break;
315         case OPT_PASSIN:
316             passinarg = opt_arg();
317             break;
318         case OPT_PASSOUT:
319             passoutarg = opt_arg();
320             break;
321         case OPT_ENGINE:
322             (void)setup_engine(opt_arg(), 0);
323             break;
324         }
325     }
326     argc = opt_num_rest();
327     argv = opt_rest();
328
329     if (dbfile && configfile) {
330         BIO_printf(bio_err,
331                    "-dbfile and -configfile cannot be specified together.\n");
332         goto end;
333     }
334     if (mode == OPT_ERR) {
335         BIO_printf(bio_err,
336                    "Exactly one of the options -add, -delete, -modify -list must be specified.\n");
337         goto opthelp;
338     }
339     if ((mode == OPT_DELETE || mode == OPT_MODIFY || OPT_ADD) && argc < 1) {
340         BIO_printf(bio_err,
341                    "Need at least one user for options -add, -delete, -modify. \n");
342         goto opthelp;
343     }
344     if ((passin || passout) && argc != 1) {
345         BIO_printf(bio_err,
346                    "-passin, -passout arguments only valid with one user.\n");
347         goto opthelp;
348     }
349
350     if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
351         BIO_printf(bio_err, "Error getting passwords\n");
352         goto end;
353     }
354
355     if (!dbfile) {
356
357         /*****************************************************************/
358         tofree = NULL;
359         if (configfile == NULL)
360             configfile = getenv("OPENSSL_CONF");
361         if (configfile == NULL)
362             configfile = getenv("SSLEAY_CONF");
363         if (configfile == NULL) {
364             const char *s = X509_get_default_cert_area();
365             size_t len;
366
367 # ifdef OPENSSL_SYS_VMS
368             len = strlen(s) + sizeof(CONFIG_FILE);
369             tofree = OPENSSL_malloc(len);
370             if (!tofree) {
371                 BIO_printf(bio_err, "Out of memory\n");
372                 goto end;
373             }
374             strcpy(tofree, s);
375 # else
376             len = strlen(s) + sizeof(CONFIG_FILE) + 1;
377             tofree = OPENSSL_malloc(len);
378             if (!tofree) {
379                 BIO_printf(bio_err, "Out of memory\n");
380                 goto end;
381             }
382             BUF_strlcpy(tofree, s, len);
383             BUF_strlcat(tofree, "/", len);
384 # endif
385             BUF_strlcat(tofree, CONFIG_FILE, len);
386             configfile = tofree;
387         }
388
389         if (verbose)
390             BIO_printf(bio_err, "Using configuration from %s\n", configfile);
391         conf = NCONF_new(NULL);
392         if (NCONF_load(conf, configfile, &errorline) <= 0) {
393             if (errorline <= 0)
394                 BIO_printf(bio_err, "error loading the config file '%s'\n",
395                            configfile);
396             else
397                 BIO_printf(bio_err, "error on line %ld of config file '%s'\n",
398                            errorline, configfile);
399             goto end;
400         }
401         if (tofree) {
402             OPENSSL_free(tofree);
403             tofree = NULL;
404         }
405
406         /* Lets get the config section we are using */
407         if (section == NULL) {
408             if (verbose)
409                 BIO_printf(bio_err,
410                            "trying to read " ENV_DEFAULT_SRP
411                            " in \" BASE_SECTION \"\n");
412
413             section = NCONF_get_string(conf, BASE_SECTION, ENV_DEFAULT_SRP);
414             if (section == NULL) {
415                 lookup_fail(BASE_SECTION, ENV_DEFAULT_SRP);
416                 goto end;
417             }
418         }
419
420         if (randfile == NULL && conf)
421             randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");
422
423         if (verbose)
424             BIO_printf(bio_err,
425                        "trying to read " ENV_DATABASE " in section \"%s\"\n",
426                        section);
427
428         if ((dbfile = NCONF_get_string(conf, section, ENV_DATABASE)) == NULL) {
429             lookup_fail(section, ENV_DATABASE);
430             goto end;
431         }
432
433     }
434     if (randfile == NULL)
435         ERR_clear_error();
436     else
437         app_RAND_load_file(randfile, 0);
438
439     if (verbose)
440         BIO_printf(bio_err, "Trying to read SRP verifier file \"%s\"\n",
441                    dbfile);
442
443     db = load_index(dbfile, &db_attr);
444     if (db == NULL)
445         goto end;
446
447     /* Lets check some fields */
448     for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
449         pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
450
451         if (pp[DB_srptype][0] == DB_SRP_INDEX) {
452             maxgN = i;
453             if (gNindex < 0 && gN != NULL && !strcmp(gN, pp[DB_srpid]))
454                 gNindex = i;
455
456             print_index(db, i, verbose > 1);
457         }
458     }
459
460     if (verbose)
461         BIO_printf(bio_err, "Database initialised\n");
462
463     if (gNindex >= 0) {
464         gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);
465         print_entry(db, gNindex, verbose > 1, "Default g and N");
466     } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {
467         BIO_printf(bio_err, "No g and N value for index \"%s\"\n", gN);
468         goto end;
469     } else {
470         if (verbose)
471             BIO_printf(bio_err, "Database has no g N information.\n");
472         gNrow = NULL;
473     }
474
475     if (verbose > 1)
476         BIO_printf(bio_err, "Starting user processing\n");
477
478     if (argc > 0)
479         user = *(argv++);
480
481     while (mode == OPT_LIST || user) {
482         int userindex = -1;
483         if (user)
484             if (verbose > 1)
485                 BIO_printf(bio_err, "Processing user \"%s\"\n", user);
486         if ((userindex = get_index(db, user, 'U')) >= 0) {
487             print_user(db, userindex, (verbose > 0)
488                        || mode == OPT_LIST);
489         }
490
491         if (mode == OPT_LIST) {
492             if (user == NULL) {
493                 BIO_printf(bio_err, "List all users\n");
494
495                 for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
496                     print_user(db, i, 1);
497                 }
498             } else if (userindex < 0) {
499                 BIO_printf(bio_err,
500                            "user \"%s\" does not exist, ignored. t\n", user);
501                 errors++;
502             }
503         } else if (mode == OPT_ADD) {
504             if (userindex >= 0) {
505                 /* reactivation of a new user */
506                 char **row =
507                     sk_OPENSSL_PSTRING_value(db->db->data, userindex);
508                 BIO_printf(bio_err, "user \"%s\" reactivated.\n", user);
509                 row[DB_srptype][0] = 'V';
510
511                 doupdatedb = 1;
512             } else {
513                 char *row[DB_NUMBER];
514                 char *gNid;
515                 row[DB_srpverifier] = NULL;
516                 row[DB_srpsalt] = NULL;
517                 row[DB_srpinfo] = NULL;
518                 if (!
519                     (gNid =
520                      srp_create_user(user, &(row[DB_srpverifier]),
521                                      &(row[DB_srpsalt]),
522                                      gNrow ? gNrow[DB_srpsalt] : gN,
523                                      gNrow ? gNrow[DB_srpverifier] : NULL,
524                                      passout, verbose))) {
525                     BIO_printf(bio_err,
526                                "Cannot create srp verifier for user \"%s\", operation abandoned .\n",
527                                user);
528                     errors++;
529                     goto end;
530                 }
531                 row[DB_srpid] = BUF_strdup(user);
532                 row[DB_srptype] = BUF_strdup("v");
533                 row[DB_srpgN] = BUF_strdup(gNid);
534
535                 if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
536                     || !row[DB_srpverifier] || !row[DB_srpsalt] || (userinfo
537                                                                     &&
538                                                                     (!(row
539                                                                        [DB_srpinfo]
540                                                                        =
541                                                                        BUF_strdup
542                                                                        (userinfo))))
543                     || !update_index(db, row)) {
544                     if (row[DB_srpid])
545                         OPENSSL_free(row[DB_srpid]);
546                     if (row[DB_srpgN])
547                         OPENSSL_free(row[DB_srpgN]);
548                     if (row[DB_srpinfo])
549                         OPENSSL_free(row[DB_srpinfo]);
550                     if (row[DB_srptype])
551                         OPENSSL_free(row[DB_srptype]);
552                     if (row[DB_srpverifier])
553                         OPENSSL_free(row[DB_srpverifier]);
554                     if (row[DB_srpsalt])
555                         OPENSSL_free(row[DB_srpsalt]);
556                     goto end;
557                 }
558                 doupdatedb = 1;
559             }
560         } else if (mode == OPT_MODIFY) {
561             if (userindex < 0) {
562                 BIO_printf(bio_err,
563                            "user \"%s\" does not exist, operation ignored.\n",
564                            user);
565                 errors++;
566             } else {
567
568                 char **row =
569                     sk_OPENSSL_PSTRING_value(db->db->data, userindex);
570                 char type = row[DB_srptype][0];
571                 if (type == 'v') {
572                     BIO_printf(bio_err,
573                                "user \"%s\" already updated, operation ignored.\n",
574                                user);
575                     errors++;
576                 } else {
577                     char *gNid;
578
579                     if (row[DB_srptype][0] == 'V') {
580                         int user_gN;
581                         char **irow = NULL;
582                         if (verbose)
583                             BIO_printf(bio_err,
584                                        "Verifying password for user \"%s\"\n",
585                                        user);
586                         if ((user_gN =
587                              get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)
588                             irow =
589                                 sk_OPENSSL_PSTRING_value(db->db->data,
590                                                          userindex);
591
592                         if (!srp_verify_user
593                             (user, row[DB_srpverifier], row[DB_srpsalt],
594                              irow ? irow[DB_srpsalt] : row[DB_srpgN],
595                              irow ? irow[DB_srpverifier] : NULL, passin,
596                              verbose)) {
597                             BIO_printf(bio_err,
598                                        "Invalid password for user \"%s\", operation abandoned.\n",
599                                        user);
600                             errors++;
601                             goto end;
602                         }
603                     }
604                     if (verbose)
605                         BIO_printf(bio_err, "Password for user \"%s\" ok.\n",
606                                    user);
607
608                     if (!
609                         (gNid =
610                          srp_create_user(user, &(row[DB_srpverifier]),
611                                          &(row[DB_srpsalt]),
612                                          gNrow ? gNrow[DB_srpsalt] : NULL,
613                                          gNrow ? gNrow[DB_srpverifier] : NULL,
614                                          passout, verbose))) {
615                         BIO_printf(bio_err,
616                                    "Cannot create srp verifier for user \"%s\", operation abandoned.\n",
617                                    user);
618                         errors++;
619                         goto end;
620                     }
621
622                     row[DB_srptype][0] = 'v';
623                     row[DB_srpgN] = BUF_strdup(gNid);
624
625                     if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
626                         || !row[DB_srpverifier] || !row[DB_srpsalt]
627                         || (userinfo
628                             && (!(row[DB_srpinfo] = BUF_strdup(userinfo)))))
629                         goto end;
630
631                     doupdatedb = 1;
632                 }
633             }
634         } else if (mode == OPT_DELETE) {
635             if (userindex < 0) {
636                 BIO_printf(bio_err,
637                            "user \"%s\" does not exist, operation ignored. t\n",
638                            user);
639                 errors++;
640             } else {
641                 char **xpp =
642                     sk_OPENSSL_PSTRING_value(db->db->data, userindex);
643                 BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
644
645                 xpp[DB_srptype][0] = 'R';
646
647                 doupdatedb = 1;
648             }
649         }
650         if (--argc > 0)
651             user = *(argv++);
652         else {
653             user = NULL;
654         }
655     }
656
657     if (verbose)
658         BIO_printf(bio_err, "User procession done.\n");
659
660     if (doupdatedb) {
661         /* Lets check some fields */
662         for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {
663             pp = sk_OPENSSL_PSTRING_value(db->db->data, i);
664
665             if (pp[DB_srptype][0] == 'v') {
666                 pp[DB_srptype][0] = 'V';
667                 print_user(db, i, verbose);
668             }
669         }
670
671         if (verbose)
672             BIO_printf(bio_err, "Trying to update srpvfile.\n");
673         if (!save_index(dbfile, "new", db))
674             goto end;
675
676         if (verbose)
677             BIO_printf(bio_err, "Temporary srpvfile created.\n");
678         if (!rotate_index(dbfile, "new", "old"))
679             goto end;
680
681         if (verbose)
682             BIO_printf(bio_err, "srpvfile updated.\n");
683     }
684
685     ret = (errors != 0);
686  end:
687     if (errors != 0)
688         if (verbose)
689             BIO_printf(bio_err, "User errors %d.\n", errors);
690
691     if (verbose)
692         BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
693     if (tofree)
694         OPENSSL_free(tofree);
695     if (ret)
696         ERR_print_errors(bio_err);
697     if (randfile)
698         app_RAND_write_file(randfile);
699     if (conf)
700         NCONF_free(conf);
701     if (db)
702         free_index(db);
703
704     OBJ_cleanup();
705     return (ret);
706 }
707
708 #endif