gsasl  2.2.1
xstep.c
Go to the documentation of this file.
1 /* xstep.c --- Perform one SASL authentication step.
2  * Copyright (C) 2002-2024 Simon Josefsson
3  *
4  * This file is part of GNU SASL Library.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 
23 #include <config.h>
24 #include "internal.h"
25 
51 int
53  const char *input, size_t input_len,
54  char **output, size_t *output_len)
55 {
57 
58  if (sctx->clientp)
59  step = sctx->mech->client.step;
60  else
61  step = sctx->mech->server.step;
62 
63  return step (sctx, sctx->mech_data, input, input_len, output, output_len);
64 }
65 
86 int
87 gsasl_step64 (Gsasl_session *sctx, const char *b64input, char **b64output)
88 {
89  size_t input_len = 0, output_len = 0;
90  char *input = NULL, *output = NULL;
91  int res;
92 
93  if (b64input)
94  {
95  res = gsasl_base64_from (b64input, strlen (b64input),
96  &input, &input_len);
97  if (res != GSASL_OK)
98  return GSASL_BASE64_ERROR;
99  }
100 
101  res = gsasl_step (sctx, input, input_len, &output, &output_len);
102 
103  free (input);
104 
105  if (res == GSASL_OK || res == GSASL_NEEDS_MORE)
106  {
107  int tmpres = gsasl_base64_to (output, output_len, b64output, NULL);
108 
109  free (output);
110 
111  if (tmpres != GSASL_OK)
112  return tmpres;
113  }
114 
115  return res;
116 }
int gsasl_base64_from(const char *in, size_t inlen, char **out, size_t *outlen)
Definition: base64.c:75
int gsasl_base64_to(const char *in, size_t inlen, char **out, size_t *outlen)
Definition: base64.c:45
int(* Gsasl_step_function)(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: gsasl-mech.h:100
@ GSASL_OK
Definition: gsasl.h:129
@ GSASL_BASE64_ERROR
Definition: gsasl.h:134
@ GSASL_NEEDS_MORE
Definition: gsasl.h:130
Gsasl_step_function step
Definition: gsasl-mech.h:156
struct Gsasl_mechanism_functions server
Definition: gsasl-mech.h:176
struct Gsasl_mechanism_functions client
Definition: gsasl-mech.h:175
void * mech_data
Definition: internal.h:53
Gsasl_mechanism * mech
Definition: internal.h:52
int gsasl_step64(Gsasl_session *sctx, const char *b64input, char **b64output)
Definition: xstep.c:87
int gsasl_step(Gsasl_session *sctx, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: xstep.c:52