|
gsasl
1.7.6
|
00001 /* client.c --- SASL mechanism PLAIN as defined in RFC 2595, client side. 00002 * Copyright (C) 2002-2012 Simon Josefsson 00003 * 00004 * This file is part of GNU SASL Library. 00005 * 00006 * GNU SASL Library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * GNU SASL Library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with GNU SASL Library; if not, write to the Free 00018 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #ifdef HAVE_CONFIG_H 00024 #include "config.h" 00025 #endif 00026 00027 /* Get specification. */ 00028 #include "plain.h" 00029 00030 /* Get memcpy, strdup, strlen. */ 00031 #include <string.h> 00032 00033 /* Get malloc, free. */ 00034 #include <stdlib.h> 00035 00036 int 00037 _gsasl_plain_client_step (Gsasl_session * sctx, 00038 void *mech_data, 00039 const char *input, size_t input_len, 00040 char **output, size_t * output_len) 00041 { 00042 const char *authzid = gsasl_property_get (sctx, GSASL_AUTHZID); 00043 const char *authid = gsasl_property_get (sctx, GSASL_AUTHID); 00044 const char *password = gsasl_property_get (sctx, GSASL_PASSWORD); 00045 size_t authzidlen = 0, authidlen = 0, passwordlen = 0; 00046 char *out; 00047 00048 if (authzid) 00049 authzidlen = strlen (authzid); 00050 00051 if (authid) 00052 authidlen = strlen (authid); 00053 else 00054 return GSASL_NO_AUTHID; 00055 00056 if (password) 00057 passwordlen = strlen (password); 00058 else 00059 return GSASL_NO_PASSWORD; 00060 00061 *output_len = authzidlen + 1 + authidlen + 1 + passwordlen; 00062 *output = out = malloc (*output_len); 00063 if (!out) 00064 return GSASL_MALLOC_ERROR; 00065 00066 if (authzid) 00067 { 00068 memcpy (out, authzid, authzidlen); 00069 out += authzidlen; 00070 } 00071 00072 *out++ = '\0'; 00073 00074 memcpy (out, authid, authidlen); 00075 out += authidlen; 00076 00077 *out++ = '\0'; 00078 00079 memcpy (out, password, passwordlen); 00080 00081 return GSASL_OK; 00082 }
1.7.6.1