1 /* xstart.c --- Start libgsasl session.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Simon Josefsson
4 * This file is part of GNU SASL Library.
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GNU SASL Library 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 License along with GNU SASL Library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
25 static Gsasl_mechanism
*
26 find_mechanism (const char *mech
, size_t n_mechs
, Gsasl_mechanism
* mechs
)
33 for (i
= 0; i
< n_mechs
; i
++)
34 if (strcmp (mech
, mechs
[i
].name
) == 0)
44 size_t n_mechs
, Gsasl_mechanism
* mechs
, int clientp
)
46 Gsasl_mechanism
*mechptr
= NULL
;
49 mechptr
= find_mechanism (mech
, n_mechs
, mechs
);
51 return GSASL_UNKNOWN_MECHANISM
;
55 sctx
->clientp
= clientp
;
59 if (sctx
->mech
->client
.start
)
60 res
= sctx
->mech
->client
.start (sctx
, &sctx
->mech_data
);
61 else if (!sctx
->mech
->client
.step
)
62 res
= GSASL_NO_CLIENT_CODE
;
68 if (sctx
->mech
->server
.start
)
69 res
= sctx
->mech
->server
.start (sctx
, &sctx
->mech_data
);
70 else if (!sctx
->mech
->server
.step
)
71 res
= GSASL_NO_SERVER_CODE
;
84 Gsasl_session
** sctx
,
85 size_t n_mechs
, Gsasl_mechanism
* mechs
, int clientp
)
90 out
= calloc (1, sizeof (*out
));
92 return GSASL_MALLOC_ERROR
;
94 res
= setup (ctx
, mech
, out
, n_mechs
, mechs
, clientp
);
107 * gsasl_client_start:
108 * @ctx: libgsasl handle.
109 * @mech: name of SASL mechanism.
110 * @sctx: pointer to client handle.
112 * This functions initiates a client SASL authentication. This
113 * function must be called before any other gsasl_client_*() function
116 * Return value: Returns GSASL_OK if successful, or error code.
119 gsasl_client_start (Gsasl
* ctx
, const char *mech
, Gsasl_session
** sctx
)
121 return start (ctx
, mech
, sctx
, ctx
->n_client_mechs
, ctx
->client_mechs
, 1);
125 * gsasl_server_start:
126 * @ctx: libgsasl handle.
127 * @mech: name of SASL mechanism.
128 * @sctx: pointer to server handle.
130 * This functions initiates a server SASL authentication. This
131 * function must be called before any other gsasl_server_*() function
134 * Return value: Returns GSASL_OK if successful, or error code.
137 gsasl_server_start (Gsasl
* ctx
, const char *mech
, Gsasl_session
** sctx
)
139 return start (ctx
, mech
, sctx
, ctx
->n_server_mechs
, ctx
->server_mechs
, 0);