1 /* md5file.c --- Test the MD5 file password function.
2 * Copyright (C) 2002, 2003, 2004, 2005, 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/>.
33 /* Should match values from cram-md5.pwd. */
35 #define BILL_PASSWD "hubba-hubba"
42 size_t keylen
= BUFSIZ
- 1;
45 md5file
= getenv ("MD5FILE");
49 if ((p
= strchr (md5file
, '=')))
54 md5file
= "cram-md5.pwd";
56 keylen
= sizeof (key
) - 1;
57 res
= gsasl_md5pwd_get_password ("non-existing-file", "user", key
, &keylen
);
58 if (res
== GSASL_FOPEN_ERROR
)
59 success ("non-existing-file OK\n");
61 fail ("non-existing-file FAIL (%d): %s\n", res
, gsasl_strerror (res
));
63 keylen
= sizeof (key
) - 1;
64 res
= gsasl_md5pwd_get_password (md5file
, BILL
, key
, &keylen
);
66 success ("user-found OK\n");
68 fail ("user-found FAIL (%d): %s\n", res
, gsasl_strerror (res
));
69 if (keylen
!= strlen (BILL_PASSWD
)
70 || memcmp (key
, BILL_PASSWD
, keylen
) != 0)
71 fail ("user-password FAIL (%d): %.*s\n", keylen
, keylen
, key
);
73 success ("user-password OK\n");
76 res
= gsasl_md5pwd_get_password (md5file
, BILL
, key
, &keylen
);
77 if (res
== GSASL_TOO_SMALL_BUFFER
)
78 success ("too-small-buffer OK\n");
80 fail ("too-small-buffer FAIL (%d): %s\n", res
, gsasl_strerror (res
));
82 keylen
= sizeof (key
) - 1;
83 res
= gsasl_md5pwd_get_password (md5file
, "user", key
, &keylen
);
84 if (res
== GSASL_AUTHENTICATION_ERROR
)
85 success ("no-such-user OK\n");
87 fail ("no-such-user FAIL (%d): %s\n", res
, gsasl_strerror (res
));