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)  

server.c
Go to the documentation of this file.
1 /* server.c --- SAML20 mechanism, server side.
2  * Copyright (C) 2010-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 specification. */
28 #include "saml20.h"
29 
30 /* Get strdup, strlen. */
31 #include <string.h>
32 
33 /* Get free. */
34 #include <stdlib.h>
35 
36 /* Get _gsasl_parse_gs2_header. */
37 #include "mechtools.h"
38 
40 {
41  int step;
42 };
43 
44 int
45 _gsasl_saml20_server_start (Gsasl_session * sctx _GL_UNUSED, void **mech_data)
46 {
47  struct saml20_server_state *state;
48 
49  state = (struct saml20_server_state *) calloc (sizeof (*state), 1);
50  if (state == NULL)
51  return GSASL_MALLOC_ERROR;
52 
53  *mech_data = state;
54 
55  return GSASL_OK;
56 }
57 
58 int
60  void *mech_data,
61  const char *input, size_t input_len,
62  char **output, size_t *output_len)
63 {
64  struct saml20_server_state *state = mech_data;
66 
67  *output_len = 0;
68  *output = NULL;
69 
70  switch (state->step)
71  {
72  case 0:
73  {
74  const char *p;
75  char *authzid;
76  size_t headerlen;
77 
78  if (input_len == 0)
79  return GSASL_NEEDS_MORE;
80 
81  res = _gsasl_parse_gs2_header (input, input_len,
82  &authzid, &headerlen);
83  if (res != GSASL_OK)
84  return res;
85 
86  if (authzid)
87  {
88  gsasl_property_set (sctx, GSASL_AUTHZID, authzid);
89  free (authzid);
90  }
91 
92  input += headerlen;
93  input_len -= headerlen;
94 
96  input, input_len);
97 
99  if (!p || !*p)
101 
102  *output_len = strlen (p);
103  *output = malloc (*output_len);
104  if (!*output)
105  return GSASL_MALLOC_ERROR;
106 
107  memcpy (*output, p, *output_len);
108 
110  state->step++;
111  break;
112  }
113 
114  case 1:
115  {
116  if (!(input_len == 1 && *input == '='))
118 
120  if (res != GSASL_OK)
121  return res;
122 
123  *output = NULL;
124  *output_len = 0;
125 
126  res = GSASL_OK;
127  state->step++;
128  break;
129  }
130 
131  default:
132  break;
133  }
134 
135  return res;
136 }
137 
138 void
139 _gsasl_saml20_server_finish (Gsasl_session * sctx _GL_UNUSED, void *mech_data)
140 {
141  struct saml20_server_state *state = mech_data;
142 
143  if (!state)
144  return;
145 
146  free (state);
147 }
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:75
#define NULL
Definition: stddef.in.h:72
const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
Definition: property.c:263
void gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
Definition: property.c:158
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_NEEDS_MORE
Definition: gsasl.h:172
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
Definition: gsasl.h:174
@ GSASL_MECHANISM_PARSE_ERROR
Definition: gsasl.h:179
@ GSASL_NO_SAML20_REDIRECT_URL
Definition: gsasl.h:195
void gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
Definition: property.c:184
@ GSASL_AUTHZID
Definition: gsasl.h:336
@ GSASL_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:355
@ GSASL_VALIDATE_SAML20
Definition: gsasl.h:368
@ GSASL_SAML20_REDIRECT_URL
Definition: gsasl.h:356
int res
Definition: mbrtowc-impl.h:45
const char * p
Definition: mbrtowc-impl.h:42
int _gsasl_parse_gs2_header(const char *data, size_t len, char **authzid, size_t *headerlen)
Definition: mechtools.c:99
int _gsasl_saml20_server_start(Gsasl_session *sctx _GL_UNUSED, void **mech_data)
Definition: server.c:45
int _gsasl_saml20_server_step(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: server.c:59
void _gsasl_saml20_server_finish(Gsasl_session *sctx _GL_UNUSED, void *mech_data)
Definition: server.c:139