1 /* Xstep.c perform one SASL authentication step in the X
2 * Copyright (C) 2002 Simon Josefsson
4 * This file is part of libgsasl.
6 * Libgsasl is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libgsasl 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with libgsasl; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * @xctx: libgsasl client handle.
27 * @input: input byte array.
28 * @input_len: size of input byte array.
29 * @output: output byte array.
30 * @output_len: size of output byte array.
32 * Perform one step of SASL authentication in client. This reads data
33 * from server (specified with input and input_len), processes it
34 * (potentially invoking callbacks to the application), and writes
35 * data to server (into variables output and output_len).
37 * The contents of the output buffer is unspecified if this functions
38 * returns anything other than GSASL_NEEDS_MORE.
40 * Return value: Returns GSASL_OK if authenticated terminated
41 * successfully, GSASL_NEEDS_MORE if more data is needed, or error
45 gsasl_client_step (Gsasl_session_ctx
*xctx
,
51 return xctx
->mech
->client
.step(xctx
, xctx
->mech_data
,
59 * @xctx: libgsasl server handle.
60 * @input: input byte array.
61 * @input_len: size of input byte array.
62 * @output: output byte array.
63 * @output_len: size of output byte array.
65 * Perform one step of SASL authentication in server. This reads data
66 * from client (specified with input and input_len), processes it
67 * (potentially invoking callbacks to the application), and writes
68 * data to client (into variables output and output_len).
70 * The contents of the output buffer is unspecified if this functions
71 * returns anything other than GSASL_NEEDS_MORE.
73 * Return value: Returns GSASL_OK if authenticated terminated
74 * successfully, GSASL_NEEDS_MORE if more data is needed, or error
78 gsasl_server_step (Gsasl_session_ctx
*xctx
,
84 return xctx
->mech
->server
.step(xctx
, xctx
->mech_data
,
90 _gsasl_session_step_base64 (Gsasl_session_ctx
*xctx
,
96 size_t input_len
, output_len
;
100 if (b64input
&& strlen(b64input
) > 0)
102 input_len
= strlen(b64input
) + 1;
103 input
= (char*) malloc(input_len
);
105 input_len
= gsasl_base64_decode(b64input
, input
, input_len
);
109 return GSASL_BASE64_ERROR
;
118 if (b64output
&& b64output_len
> 0)
121 output_len
= b64output_len
; /* As good guess as any */
122 output
= (char*) malloc(output_len
);
131 res
= gsasl_client_step (xctx
, input
, input_len
, output
, &output_len
);
133 res
= gsasl_server_step (xctx
, input
, input_len
, output
, &output_len
);
135 if (res
== GSASL_NEEDS_MORE
&& output
&& output_len
> 0)
137 output_len
= gsasl_base64_encode(output
, output_len
,
138 b64output
, b64output_len
);
139 if (output_len
== -1)
143 return GSASL_BASE64_ERROR
;
154 * gsasl_client_step_base64:
155 * @xctx: libgsasl client handle.
156 * @b64input: input base64 encoded byte array.
157 * @b64output: output base64 encoded byte array.
158 * @b64output_len: size of output base64 encoded byte array.
160 * This is a simple wrapper around gsasl_client_step() that base64
161 * decodes the input and base64 encodes the output.
163 * Return value: See gsasl_client_step().
166 gsasl_client_step_base64 (Gsasl_session_ctx
*xctx
,
167 const char *b64input
,
169 size_t b64output_len
)
171 return _gsasl_session_step_base64 (xctx
, b64input
, b64output
,
176 * gsasl_server_step_base64:
177 * @xctx: libgsasl server handle.
178 * @b64input: input base64 encoded byte array.
179 * @b64output: output base64 encoded byte array.
180 * @b64output_len: size of output base64 encoded byte array.
182 * This is a simple wrapper around gsasl_server_step() that base64
183 * decodes the input and base64 encodes the output.
185 * Return value: See gsasl_server_step().
188 gsasl_server_step_base64 (Gsasl_session_ctx
*xctx
,
189 const char *b64input
,
191 size_t b64output_len
)
193 return _gsasl_session_step_base64 (xctx
, b64input
, b64output
,