1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/* client.c --- SASL mechanism PLAIN as defined in RFC 2595, client side.
* Copyright (C) 2002-2022 Simon Josefsson
*
* This file is part of GNU SASL Library.
*
* GNU SASL Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GNU SASL Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GNU SASL Library; if not, write to the Free
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* Get specification. */
#include "plain.h"
/* Get memcpy, strdup, strlen. */
#include <string.h>
/* Get malloc, free. */
#include <stdlib.h>
int
_gsasl_plain_client_step (Gsasl_session * sctx,
void *mech_data _GL_UNUSED,
const char *input _GL_UNUSED,
size_t input_len _GL_UNUSED,
char **output, size_t *output_len)
{
const char *authzid = gsasl_property_get (sctx, GSASL_AUTHZID);
const char *authid = gsasl_property_get (sctx, GSASL_AUTHID);
const char *password = gsasl_property_get (sctx, GSASL_PASSWORD);
size_t authzidlen = 0, authidlen = 0, passwordlen = 0;
char *out;
if (authzid)
authzidlen = strlen (authzid);
if (authid)
authidlen = strlen (authid);
else
return GSASL_NO_AUTHID;
if (password)
passwordlen = strlen (password);
else
return GSASL_NO_PASSWORD;
*output_len = authzidlen + 1 + authidlen + 1 + passwordlen;
*output = out = malloc (*output_len);
if (!out)
return GSASL_MALLOC_ERROR;
if (authzid)
{
memcpy (out, authzid, authzidlen);
out += authzidlen;
}
*out++ = '\0';
memcpy (out, authid, authidlen);
out += authidlen;
*out++ = '\0';
memcpy (out, password, passwordlen);
return GSASL_OK;
}
|