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