1 /* gssapi.c --- Test the GSSAPI mechanism.
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.
33 #define SERVICE "host"
34 #define HOST "latte.josefsson.org"
35 #define GSSAPI_USER "jas"
37 static const char *USERNAME
[] = {
38 "foo", "BABABA", "jas", "hepp", "@"
43 callback (Gsasl
* ctx
, Gsasl_session
* sctx
, Gsasl_property prop
)
45 int rc
= GSASL_NO_CALLBACK
;
47 printf ("Callback for property %d\n", prop
);
52 gsasl_property_set (sctx
, GSASL_AUTHID
, USERNAME
[i
]);
57 gsasl_property_set (sctx
, prop
, SERVICE
);
62 gsasl_property_set (sctx
, prop
, HOST
);
66 case GSASL_VALIDATE_GSSAPI
:
68 const char *client_name
=
69 gsasl_property_fast (sctx
, GSASL_GSSAPI_DISPLAY_NAME
);
70 const char *authzid
= gsasl_property_fast (sctx
, GSASL_AUTHZID
);
72 printf ("GSSAPI user: %s\n", client_name
);
73 printf ("Authorization ID: %s\n", authzid
);
75 if (strcmp (client_name
, GSSAPI_USER
) == 0 &&
76 strcmp (authzid
, USERNAME
[i
]) == 0)
79 rc
= GSASL_AUTHENTICATION_ERROR
;
84 fail ("Unknown callback property %d\n", prop
);
95 Gsasl_session
*server
= NULL
, *client
= NULL
;
96 char *s1
= NULL
, *s2
= NULL
;
99 rc
= gsasl_init (&ctx
);
102 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
106 gsasl_callback_set (ctx
, callback
);
108 for (i
= 0; i
< 5; i
++)
110 rc
= gsasl_server_start (ctx
, "GSSAPI", &server
);
113 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
116 rc
= gsasl_client_start (ctx
, "GSSAPI", &client
);
119 fail ("gsasl_init() failed (%d):\n%s\n", rc
, gsasl_strerror (rc
));
125 res1
= gsasl_step64 (server
, s1
, &s2
);
131 if (res1
!= GSASL_OK
&& res1
!= GSASL_NEEDS_MORE
)
133 fail ("gsasl_step64 (1) failed (%d):\n%s\n", res1
,
134 gsasl_strerror (res1
));
139 printf ("S: %s\n", s2
);
141 if (res1
== GSASL_OK
&& strcmp (s2
, "") == 0)
144 res2
= gsasl_step64 (client
, s2
, &s1
);
146 if (res2
!= GSASL_OK
&& res2
!= GSASL_NEEDS_MORE
)
148 fail ("gsasl_step64 (2) failed (%d):\n%s\n", res2
,
149 gsasl_strerror (res2
));
154 printf ("C: %s\n", s1
);
156 while (res1
!= GSASL_OK
|| res2
!= GSASL_OK
);
167 gsasl_finish (client
);
168 gsasl_finish (server
);