1 /* md5file.c --- Test the MD5 file password function.
2 * Copyright (C) 2002, 2003, 2004, 2005 Simon Josefsson
4 * This file is part of GNU SASL.
6 * GNU SASL 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 2 of the License, or
9 * (at your option) any later version.
11 * GNU SASL 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 GNU SASL; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34 /* Should match values from cram-md5.pwd. */
36 #define BILL_PASSWD "hubba-hubba"
43 size_t keylen
= BUFSIZ
- 1;
46 md5file
= getenv ("MD5FILE");
50 if ((p
= strchr (md5file
, '=')))
55 md5file
= "cram-md5.pwd";
57 keylen
= sizeof (key
) - 1;
58 res
= gsasl_md5pwd_get_password ("non-existing-file", "user", key
, &keylen
);
59 if (res
== GSASL_FOPEN_ERROR
)
60 success ("non-existing-file OK\n");
62 fail ("non-existing-file FAIL (%d): %s\n", res
, gsasl_strerror (res
));
64 keylen
= sizeof (key
) - 1;
65 res
= gsasl_md5pwd_get_password (md5file
, BILL
, key
, &keylen
);
67 success ("user-found OK\n");
69 fail ("user-found FAIL (%d): %s\n", res
, gsasl_strerror (res
));
70 if (keylen
!= strlen (BILL_PASSWD
)
71 || memcmp (key
, BILL_PASSWD
, keylen
) != 0)
72 fail ("user-password FAIL (%d): %.*s\n", keylen
, keylen
, key
);
74 success ("user-password OK\n");
77 res
= gsasl_md5pwd_get_password (md5file
, BILL
, key
, &keylen
);
78 if (res
== GSASL_TOO_SMALL_BUFFER
)
79 success ("too-small-buffer OK\n");
81 fail ("too-small-buffer FAIL (%d): %s\n", res
, gsasl_strerror (res
));
83 keylen
= sizeof (key
) - 1;
84 res
= gsasl_md5pwd_get_password (md5file
, "user", key
, &keylen
);
85 if (res
== GSASL_AUTHENTICATION_ERROR
)
86 success ("no-such-user OK\n");
88 fail ("no-such-user FAIL (%d): %s\n", res
, gsasl_strerror (res
));