cleartext.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  * RFC4616 PLAIN authentication
00022  * Draft   LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
00023  *
00024  ***************************************************************************/
00025 
00026 #include "curl_setup.h"
00027 
00028 #include <curl/curl.h>
00029 #include "urldata.h"
00030 
00031 #include "vauth/vauth.h"
00032 #include "curl_base64.h"
00033 #include "curl_md5.h"
00034 #include "warnless.h"
00035 #include "strtok.h"
00036 #include "sendf.h"
00037 #include "curl_printf.h"
00038 
00039 /* The last #include files should be: */
00040 #include "curl_memory.h"
00041 #include "memdebug.h"
00042 
00043 /*
00044  * Curl_auth_create_plain_message()
00045  *
00046  * This is used to generate an already encoded PLAIN message ready
00047  * for sending to the recipient.
00048  *
00049  * Parameters:
00050  *
00051  * data    [in]     - The session handle.
00052  * userp   [in]     - The user name.
00053  * passdwp [in]     - The user's password.
00054  * outptr  [in/out] - The address where a pointer to newly allocated memory
00055  *                    holding the result will be stored upon completion.
00056  * outlen  [out]    - The length of the output message.
00057  *
00058  * Returns CURLE_OK on success.
00059  */
00060 CURLcode Curl_auth_create_plain_message(struct Curl_easy *data,
00061                                         const char *userp,
00062                                         const char *passwdp,
00063                                         char **outptr, size_t *outlen)
00064 {
00065   CURLcode result;
00066   char *plainauth;
00067   size_t ulen;
00068   size_t plen;
00069   size_t plainlen;
00070 
00071   *outlen = 0;
00072   *outptr = NULL;
00073   ulen = strlen(userp);
00074   plen = strlen(passwdp);
00075 
00076   /* Compute binary message length, checking for overflows. */
00077   plainlen = 2 * ulen;
00078   if(plainlen < ulen)
00079     return CURLE_OUT_OF_MEMORY;
00080   plainlen += plen;
00081   if(plainlen < plen)
00082     return CURLE_OUT_OF_MEMORY;
00083   plainlen += 2;
00084   if(plainlen < 2)
00085     return CURLE_OUT_OF_MEMORY;
00086 
00087   plainauth = malloc(plainlen);
00088   if(!plainauth)
00089     return CURLE_OUT_OF_MEMORY;
00090 
00091   /* Calculate the reply */
00092   memcpy(plainauth, userp, ulen);
00093   plainauth[ulen] = '\0';
00094   memcpy(plainauth + ulen + 1, userp, ulen);
00095   plainauth[2 * ulen + 1] = '\0';
00096   memcpy(plainauth + 2 * ulen + 2, passwdp, plen);
00097 
00098   /* Base64 encode the reply */
00099   result = Curl_base64_encode(data, plainauth, plainlen, outptr, outlen);
00100   free(plainauth);
00101 
00102   return result;
00103 }
00104 
00105 /*
00106  * Curl_auth_create_login_message()
00107  *
00108  * This is used to generate an already encoded LOGIN message containing the
00109  * user name or password ready for sending to the recipient.
00110  *
00111  * Parameters:
00112  *
00113  * data    [in]     - The session handle.
00114  * valuep  [in]     - The user name or user's password.
00115  * outptr  [in/out] - The address where a pointer to newly allocated memory
00116  *                    holding the result will be stored upon completion.
00117  * outlen  [out]    - The length of the output message.
00118  *
00119  * Returns CURLE_OK on success.
00120  */
00121 CURLcode Curl_auth_create_login_message(struct Curl_easy *data,
00122                                         const char *valuep, char **outptr,
00123                                         size_t *outlen)
00124 {
00125   size_t vlen = strlen(valuep);
00126 
00127   if(!vlen) {
00128     /* Calculate an empty reply */
00129     *outptr = strdup("=");
00130     if(*outptr) {
00131       *outlen = (size_t) 1;
00132       return CURLE_OK;
00133     }
00134 
00135     *outlen = 0;
00136     return CURLE_OUT_OF_MEMORY;
00137   }
00138 
00139   /* Base64 encode the value */
00140   return Curl_base64_encode(data, valuep, vlen, outptr, outlen);
00141 }
00142 
00143 /*
00144  * Curl_auth_create_external_message()
00145  *
00146  * This is used to generate an already encoded EXTERNAL message containing
00147  * the user name ready for sending to the recipient.
00148  *
00149  * Parameters:
00150  *
00151  * data    [in]     - The session handle.
00152  * user    [in]     - The user name.
00153  * outptr  [in/out] - The address where a pointer to newly allocated memory
00154  *                    holding the result will be stored upon completion.
00155  * outlen  [out]    - The length of the output message.
00156  *
00157  * Returns CURLE_OK on success.
00158  */
00159 CURLcode Curl_auth_create_external_message(struct Curl_easy *data,
00160                                            const char *user, char **outptr,
00161                                            size_t *outlen)
00162 {
00163   /* This is the same formatting as the login message */
00164   return Curl_auth_create_login_message(data, user, outptr, outlen);
00165 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02