gsasl  1.10.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL). Development version.
  Fossies Dox: gsasl-1.10.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

client.c
Go to the documentation of this file.
1 /* client.c --- Non-standard SASL mechanism LOGIN, client side.
2  * Copyright (C) 2002-2021 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 along with GNU SASL Library; if not, write to the Free
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 /* Get malloc, free. */
28 #include <stdlib.h>
29 
30 /* Get strlen. */
31 #include <string.h>
32 
33 /* Get specification. */
34 #include "login.h"
35 
37 {
38  int step;
39 };
40 
41 int
42 _gsasl_login_client_start (Gsasl_session * sctx _GL_UNUSED, void **mech_data)
43 {
44  struct _Gsasl_login_client_state *state;
45 
46  state = malloc (sizeof (*state));
47  if (state == NULL)
48  return GSASL_MALLOC_ERROR;
49 
50  state->step = 0;
51 
52  *mech_data = state;
53 
54  return GSASL_OK;
55 }
56 
57 int
59  void *mech_data,
60  const char *input _GL_UNUSED,
61  size_t input_len _GL_UNUSED,
62  char **output, size_t *output_len)
63 {
64  struct _Gsasl_login_client_state *state = mech_data;
65  const char *p;
66  int res;
67 
68  switch (state->step)
69  {
70  case 0:
72  if (!p)
73  return GSASL_NO_AUTHID;
74 
75  *output = strdup (p);
76  *output_len = strlen (p);
77 
78  state->step++;
80  break;
81 
82  case 1:
84  if (!p)
85  return GSASL_NO_PASSWORD;
86 
87  *output = strdup (p);
88  *output_len = strlen (*output);
89 
90  state->step++;
91  res = GSASL_OK;
92  break;
93 
94  default:
96  break;
97  }
98 
99  return res;
100 }
101 
102 void
103 _gsasl_login_client_finish (Gsasl_session * sctx _GL_UNUSED, void *mech_data)
104 {
105  struct _Gsasl_login_client_state *state = mech_data;
106 
107  if (!state)
108  return;
109 
110  free (state);
111 }
#define NULL
Definition: stddef.in.h:72
const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:263
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_NEEDS_MORE
Definition: gsasl.h:172
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
@ GSASL_NO_PASSWORD
Definition: gsasl.h:188
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
Definition: gsasl.h:174
@ GSASL_NO_AUTHID
Definition: gsasl.h:186
@ GSASL_PASSWORD
Definition: gsasl.h:337
@ GSASL_AUTHID
Definition: gsasl.h:335
void _gsasl_login_client_finish(Gsasl_session *sctx _GL_UNUSED, void *mech_data)
Definition: client.c:103
int _gsasl_login_client_start(Gsasl_session *sctx _GL_UNUSED, void **mech_data)
Definition: client.c:42
int _gsasl_login_client_step(Gsasl_session *sctx _GL_UNUSED, void *mech_data, const char *input _GL_UNUSED, size_t input_len _GL_UNUSED, char **output, size_t *output_len)
Definition: client.c:58
int res
Definition: mbrtowc-impl.h:45
const char * p
Definition: mbrtowc-impl.h:42
char * strdup(const char *s)
Definition: strdup.c:39