Branch data Line data Source code
1 : : /* name.c --- Test the gsasl_mechanism_name function.
2 : : * Copyright (C) 2008-2012 Simon Josefsson
3 : : *
4 : : * This file is part of GNU SASL.
5 : : *
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.
10 : : *
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.
15 : : *
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/>.
18 : : *
19 : : */
20 : :
21 : : #ifdef HAVE_CONFIG_H
22 : : #include "config.h"
23 : : #endif
24 : :
25 : : #include <stdio.h>
26 : : #include <stdarg.h>
27 : : #include <stdlib.h>
28 : : #include <string.h>
29 : :
30 : : #include "utils.h"
31 : :
32 : : void
33 : 1 : doit (void)
34 : : {
35 : 1 : Gsasl *ctx = NULL;
36 : 1 : Gsasl_session *server = NULL, *client = NULL;
37 : : int res;
38 : : const char *p;
39 : :
40 : 1 : p = gsasl_mechanism_name (NULL);
41 [ - + ]: 1 : if (p != NULL)
42 : 0 : fail ("gsasl_mechanism_name (NULL) failed: %s\n", p);
43 : 1 : success ("gsasl_mechanism_name (NULL) ok\n");
44 : :
45 : 1 : res = gsasl_init (&ctx);
46 [ - + ]: 1 : if (res != GSASL_OK)
47 : : {
48 : 0 : fail ("gsasl_init() failed (%d):\n%s\n", res, gsasl_strerror (res));
49 : 1 : return;
50 : : }
51 : :
52 [ + - ]: 1 : if (gsasl_server_support_p (ctx, "CRAM-MD5"))
53 : : {
54 : 1 : res = gsasl_server_start (ctx, "CRAM-MD5", &server);
55 [ - + ]: 1 : if (res != GSASL_OK)
56 : 0 : fail ("gsasl_server_start() failed (%d):\n%s\n",
57 : : res, gsasl_strerror (res));
58 : : else
59 : : {
60 : 1 : p = gsasl_mechanism_name (server);
61 : :
62 [ - + ]: 1 : if (!p)
63 : 0 : fail ("gsasl_mechanism_name() returned NULL.\n");
64 [ + - ]: 1 : else if (strcmp ("CRAM-MD5", p) == 0)
65 : 1 : success ("gsasl_mechanism_name() returned correct %s\n", p);
66 : : else
67 : 0 : fail ("gsasl_mechanism_name() returned incorrect %s", p);
68 : :
69 : 1 : gsasl_finish (server);
70 : : }
71 : : }
72 : :
73 [ + - ]: 1 : if (gsasl_client_support_p (ctx, "PLAIN"))
74 : : {
75 : 1 : res = gsasl_client_start (ctx, "PLAIN", &client);
76 [ - + ]: 1 : if (res != GSASL_OK)
77 : 0 : fail ("gsasl_client_start() failed (%d):\n%s\n",
78 : : res, gsasl_strerror (res));
79 : : else
80 : : {
81 : 1 : p = gsasl_mechanism_name (client);
82 : :
83 [ - + ]: 1 : if (!p)
84 : 0 : fail ("gsasl_mechanism_name() returned NULL.\n");
85 [ + - ]: 1 : else if (strcmp ("PLAIN", p) == 0)
86 : 1 : success ("gsasl_mechanism_name() returned correct %s\n", p);
87 : : else
88 : 0 : fail ("gsasl_mechanism_name() returned incorrect %s", p);
89 : :
90 : 1 : gsasl_finish (client);
91 : : }
92 : : }
93 : :
94 : 1 : gsasl_done (ctx);
95 : : }
|