1 /* gssapi.c --- Test the GSSAPI mechanism.
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/>.
32 #define SERVICE "host"
33 #define HOST "latte.josefsson.org"
34 #define GSSAPI_USER "jas"
36 static const char *USERNAME
[] = {
37 "foo", "BABABA", "jas", "hepp", "@"
42 callback (Gsasl
* ctx
, Gsasl_session
* sctx
, Gsasl_property prop
)
44 int rc
= GSASL_NO_CALLBACK
;
46 printf ("Callback for property %d\n", prop
);
51 gsasl_property_set (sctx
, GSASL_AUTHID
, USERNAME
[i
]);
56 gsasl_property_set (sctx
, prop
, SERVICE
);
61 gsasl_property_set (sctx
, prop
, HOST
);
65 case GSASL_VALIDATE_GSSAPI
:
67 const char *client_name
=
68 gsasl_property_fast (sctx
, GSASL_GSSAPI_DISPLAY_NAME
);
69 const char *authzid
= gsasl_property_fast (sctx
, GSASL_AUTHZID
);
71 printf ("GSSAPI user: %s\n", client_name
);
72 printf ("Authorization ID: %s\n", authzid
);
74 if (strcmp (client_name
, GSSAPI_USER
) == 0 &&
75 strcmp (authzid
, USERNAME
[i
]) == 0)
78 rc
= GSASL_AUTHENTICATION_ERROR
;
83 fail ("Unknown callback property %d\n", prop
);
94 Gsasl_session
*server
= NULL
, *client
= NULL
;
95 char *s1
= NULL
, *s2
= NULL
;
98 rc
= gsasl_init (&ctx
);
101 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
105 gsasl_callback_set (ctx
, callback
);
107 for (i
= 0; i
< 5; i
++)
109 rc
= gsasl_server_start (ctx
, "GSSAPI", &server
);
112 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
115 rc
= gsasl_client_start (ctx
, "GSSAPI", &client
);
118 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
124 res1
= gsasl_step64 (server
, s1
, &s2
);
130 if (res1
!= GSASL_OK
&& res1
!= GSASL_NEEDS_MORE
)
132 fail ("gsasl_step64 (1) failed (%d):\n%s\n", res1
,
133 gsasl_strerror (res1
));
138 printf ("S: %s\n", s2
);
140 if (res1
== GSASL_OK
&& strcmp (s2
, "") == 0)
143 res2
= gsasl_step64 (client
, s2
, &s1
);
145 if (res2
!= GSASL_OK
&& res2
!= GSASL_NEEDS_MORE
)
147 fail ("gsasl_step64 (2) failed (%d):\n%s\n", res2
,
148 gsasl_strerror (res2
));
153 printf ("C: %s\n", s1
);
155 while (res1
!= GSASL_OK
|| res2
!= GSASL_OK
);
166 gsasl_finish (client
);
167 gsasl_finish (server
);