Add.
[gsasl.git] / tests / md5file.c
blobd28b09a919fc9edf135418dfb47cc1b71b9a185d
1 /* md5file.c --- Test the MD5 file password function.
2 * Copyright (C) 2002, 2003, 2004, 2007 Simon Josefsson
4 * This file is part of GNU SASL.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <gsasl.h>
31 #include "utils.h"
33 /* Should match values from cram-md5.pwd. */
34 #define BILL "bill"
35 #define BILL_PASSWD "hubba-hubba"
37 void
38 doit (void)
40 char *md5file;
41 char *key;
42 int res;
44 md5file = getenv ("MD5FILE");
45 if (md5file)
47 char *p;
48 if ((p = strchr (md5file, '=')))
49 md5file = p;
52 if (!md5file)
53 md5file = "cram-md5.pwd";
55 res = gsasl_simple_getpass ("non-existing-file", "user", &key);
56 if (res == GSASL_AUTHENTICATION_ERROR)
57 success ("non-existing-file OK\n");
58 else
59 fail ("non-existing-file FAIL (%d): %s\n", res, gsasl_strerror (res));
61 res = gsasl_simple_getpass (md5file, BILL, &key);
62 if (res == GSASL_OK)
63 success ("user-found OK\n");
64 else
65 fail ("user-found FAIL (%d): %s\n", res, gsasl_strerror (res));
66 if (strcmp (key, BILL_PASSWD) != 0)
67 fail ("user-password FAIL: %s\n", key);
68 else
69 success ("user-password OK\n");
70 if (res == GSASL_OK)
71 free (key);
73 res = gsasl_simple_getpass (md5file, "user", &key);
74 if (res == GSASL_AUTHENTICATION_ERROR)
75 success ("no-such-user OK\n");
76 else
77 fail ("no-such-user FAIL (%d): %s\n", res, gsasl_strerror (res));