Coverage Report

Created: 2025-10-10 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/vauth/cleartext.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 * RFC4616 PLAIN authentication
24
 * Draft   LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
25
 *
26
 ***************************************************************************/
27
28
#include "../curl_setup.h"
29
30
#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) ||       \
31
  !defined(CURL_DISABLE_POP3) || \
32
  (!defined(CURL_DISABLE_LDAP) && defined(USE_OPENLDAP))
33
34
#include <curl/curl.h>
35
#include "../urldata.h"
36
37
#include "vauth.h"
38
#include "../curlx/warnless.h"
39
#include "../sendf.h"
40
41
/* The last #include files should be: */
42
#include "../curl_memory.h"
43
#include "../memdebug.h"
44
45
/*
46
 * Curl_auth_create_plain_message()
47
 *
48
 * This is used to generate an already encoded PLAIN message ready
49
 * for sending to the recipient.
50
 *
51
 * Parameters:
52
 *
53
 * authzid [in]     - The authorization identity.
54
 * authcid [in]     - The authentication identity.
55
 * passwd  [in]     - The password.
56
 * out     [out]    - The result storage.
57
 *
58
 * Returns CURLE_OK on success.
59
 */
60
CURLcode Curl_auth_create_plain_message(const char *authzid,
61
                                        const char *authcid,
62
                                        const char *passwd,
63
                                        struct bufref *out)
64
58
{
65
58
  char *plainauth;
66
58
  size_t plainlen;
67
58
  size_t zlen;
68
58
  size_t clen;
69
58
  size_t plen;
70
71
58
  zlen = (authzid == NULL ? 0 : strlen(authzid));
72
58
  clen = strlen(authcid);
73
58
  plen = strlen(passwd);
74
75
  /* Compute binary message length. Check for overflows. */
76
58
  if((zlen > SIZE_MAX/4) || (clen > SIZE_MAX/4) ||
77
58
     (plen > (SIZE_MAX/2 - 2)))
78
0
    return CURLE_OUT_OF_MEMORY;
79
58
  plainlen = zlen + clen + plen + 2;
80
81
58
  plainauth = malloc(plainlen + 1);
82
58
  if(!plainauth)
83
0
    return CURLE_OUT_OF_MEMORY;
84
85
  /* Calculate the reply */
86
58
  if(zlen)
87
7
    memcpy(plainauth, authzid, zlen);
88
58
  plainauth[zlen] = '\0';
89
58
  memcpy(plainauth + zlen + 1, authcid, clen);
90
58
  plainauth[zlen + clen + 1] = '\0';
91
58
  memcpy(plainauth + zlen + clen + 2, passwd, plen);
92
58
  plainauth[plainlen] = '\0';
93
58
  Curl_bufref_set(out, plainauth, plainlen, curl_free);
94
58
  return CURLE_OK;
95
58
}
96
97
/*
98
 * Curl_auth_create_login_message()
99
 *
100
 * This is used to generate an already encoded LOGIN message containing the
101
 * username or password ready for sending to the recipient.
102
 *
103
 * Parameters:
104
 *
105
 * valuep  [in]     - The username or user's password.
106
 * out     [out]    - The result storage.
107
 *
108
 * Returns void.
109
 */
110
void Curl_auth_create_login_message(const char *valuep, struct bufref *out)
111
62
{
112
62
  Curl_bufref_set(out, valuep, strlen(valuep), NULL);
113
62
}
114
115
/*
116
 * Curl_auth_create_external_message()
117
 *
118
 * This is used to generate an already encoded EXTERNAL message containing
119
 * the username ready for sending to the recipient.
120
 *
121
 * Parameters:
122
 *
123
 * user    [in]     - The username.
124
 * out     [out]    - The result storage.
125
 *
126
 * Returns void.
127
 */
128
void Curl_auth_create_external_message(const char *user,
129
                                       struct bufref *out)
130
0
{
131
  /* This is the same formatting as the login message */
132
0
  Curl_auth_create_login_message(user, out);
133
0
}
134
135
#endif /* if no users */