1 /* anonymous.c implementation of SASL mechanism ANONYMOUS from RFC 2245
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
27 _gsasl_anonymous_client_init (Gsasl_ctx
*ctx
)
33 _gsasl_anonymous_client_done (Gsasl_ctx
*ctx
)
39 _gsasl_anonymous_client_start (Gsasl_session_ctx
*cctx
,
45 ctx
= gsasl_client_ctx_get (cctx
);
47 return GSASL_CANNOT_GET_CTX
;
49 if (gsasl_client_callback_anonymous_get (ctx
) == NULL
)
50 return GSASL_NEED_SERVER_ANONYMOUS_CALLBACK
;
52 step
= (int*) malloc(sizeof(*step
));
54 return GSASL_MALLOC_ERROR
;
64 _gsasl_anonymous_client_step (Gsasl_session_ctx
*cctx
,
71 int *step
= mech_data
;
72 Gsasl_client_callback_anonymous cb_anonymous
;
81 ctx
= gsasl_client_ctx_get (cctx
);
83 return GSASL_CANNOT_GET_CTX
;
85 cb_anonymous
= gsasl_client_callback_anonymous_get (ctx
);
86 if (cb_anonymous
== NULL
)
87 return GSASL_NEED_SERVER_ANONYMOUS_CALLBACK
;
89 res
= cb_anonymous (cctx
, output
, output_len
);
93 *output_len
= strlen(output
);
95 return GSASL_NEEDS_MORE
;
99 _gsasl_anonymous_client_finish (Gsasl_session_ctx
*cctx
,
102 int *step
= mech_data
;
112 _gsasl_anonymous_server_init (Gsasl_ctx
*ctx
)
118 _gsasl_anonymous_server_done (Gsasl_ctx
*ctx
)
124 _gsasl_anonymous_server_start (Gsasl_session_ctx
*sctx
,
129 ctx
= gsasl_server_ctx_get (sctx
);
131 return GSASL_CANNOT_GET_CTX
;
133 if (gsasl_server_callback_anonymous_get (ctx
) == NULL
)
134 return GSASL_NEED_SERVER_ANONYMOUS_CALLBACK
;
140 _gsasl_anonymous_server_step (Gsasl_session_ctx
*sctx
,
147 Gsasl_server_callback_anonymous cb_anonymous
;
155 return GSASL_NEEDS_MORE
;
158 ctx
= gsasl_server_ctx_get (sctx
);
160 return GSASL_CANNOT_GET_CTX
;
162 cb_anonymous
= gsasl_server_callback_anonymous_get (ctx
);
163 if (cb_anonymous
== NULL
)
164 return GSASL_NEED_SERVER_ANONYMOUS_CALLBACK
;
166 token
= malloc(input_len
+ 1);
168 return GSASL_MALLOC_ERROR
;
170 memcpy(token
, input
, input_len
);
171 token
[input_len
] = '\0';
173 res
= cb_anonymous(sctx
, token
);
181 _gsasl_anonymous_server_finish (Gsasl_session_ctx
*sctx
,
187 #endif /* USE_ANONYMOUS */