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 --- SASL mechanism SECURID from RFC 2808, server 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 specification. */
28 #include "securid.h"
29 
30 /* Get malloc, free. */
31 #include <stdlib.h>
32 
33 /* Get memchr, strdup, strlen. */
34 #include <string.h>
35 
36 #define PASSCODE "passcode"
37 #define PIN "pin"
38 
39 int
41  void *mech_data _GL_UNUSED,
42  const char *input, size_t input_len,
43  char **output, size_t *output_len)
44 {
45  const char *authorization_id = NULL;
46  const char *authentication_id = NULL;
47  const char *passcode = NULL;
48  const char *suggestedpin;
49  char *pin = NULL;
50  int res;
51  size_t len;
52 
53  if (input_len == 0)
54  {
55  *output_len = 0;
56  *output = NULL;
57  return GSASL_NEEDS_MORE;
58  }
59 
60  authorization_id = input;
61  authentication_id = memchr (input, '\0', input_len - 1);
62  if (authentication_id)
63  {
64  authentication_id++;
65  passcode = memchr (authentication_id, '\0',
66  input_len - strlen (authorization_id) - 1 - 1);
67  if (passcode)
68  {
69  passcode++;
70  pin = memchr (passcode, '\0', input_len -
71  strlen (authorization_id) - 1 -
72  strlen (authentication_id) - 1 - 1);
73  if (pin)
74  {
75  pin++;
76  if (pin && !*pin)
77  pin = NULL;
78  }
79  }
80  }
81 
82  if (passcode == NULL)
84 
85  gsasl_property_set (sctx, GSASL_AUTHID, authentication_id);
86  gsasl_property_set (sctx, GSASL_AUTHZID, authorization_id);
87  gsasl_property_set (sctx, GSASL_PASSCODE, passcode);
88  if (pin)
89  gsasl_property_set (sctx, GSASL_PIN, pin);
90  else
92 
94  switch (res)
95  {
97  *output = strdup (PASSCODE);
98  if (!*output)
99  return GSASL_MALLOC_ERROR;
100  *output_len = strlen (PASSCODE);
102  break;
103 
105  suggestedpin = gsasl_property_get (sctx, GSASL_SUGGESTED_PIN);
106  if (suggestedpin)
107  len = strlen (suggestedpin);
108  else
109  len = 0;
110  *output_len = strlen (PIN) + len;
111  *output = malloc (*output_len);
112  if (!*output)
113  return GSASL_MALLOC_ERROR;
114  memcpy (*output, PIN, strlen (PIN));
115  if (suggestedpin)
116  memcpy (*output + strlen (PIN), suggestedpin, len);
118  break;
119 
120  default:
121  *output_len = 0;
122  *output = NULL;
123  break;
124  }
125 
126  return res;
127 }
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:75
void * memchr(void const *s, int c_in, size_t n)
Definition: memchr.c:59
#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_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE
Definition: gsasl.h:210
@ GSASL_SECURID_SERVER_NEED_NEW_PIN
Definition: gsasl.h:211
@ GSASL_NEEDS_MORE
Definition: gsasl.h:172
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
@ GSASL_MECHANISM_PARSE_ERROR
Definition: gsasl.h:179
@ GSASL_AUTHZID
Definition: gsasl.h:336
@ GSASL_PASSCODE
Definition: gsasl.h:342
@ GSASL_AUTHID
Definition: gsasl.h:335
@ GSASL_PIN
Definition: gsasl.h:344
@ GSASL_VALIDATE_SECURID
Definition: gsasl.h:367
@ GSASL_SUGGESTED_PIN
Definition: gsasl.h:343
int res
Definition: mbrtowc-impl.h:45
int _gsasl_securid_server_step(Gsasl_session *sctx, void *mech_data _GL_UNUSED, const char *input, size_t input_len, char **output, size_t *output_len)
Definition: server.c:40
#define PASSCODE
Definition: server.c:36
#define PIN
Definition: server.c:37
char * strdup(const char *s)
Definition: strdup.c:39