Coverage Report

Created: 2025-12-04 06:52

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
36
#include "vauth.h"
37
#include "../curlx/warnless.h"
38
#include "../sendf.h"
39
40
/*
41
 * Curl_auth_create_plain_message()
42
 *
43
 * This is used to generate an already encoded PLAIN message ready
44
 * for sending to the recipient.
45
 *
46
 * Parameters:
47
 *
48
 * authzid [in]     - The authorization identity.
49
 * authcid [in]     - The authentication identity.
50
 * passwd  [in]     - The password.
51
 * out     [out]    - The result storage.
52
 *
53
 * Returns CURLE_OK on success.
54
 */
55
CURLcode Curl_auth_create_plain_message(const char *authzid,
56
                                        const char *authcid,
57
                                        const char *passwd,
58
                                        struct bufref *out)
59
0
{
60
0
  size_t len;
61
0
  char *auth;
62
63
0
  size_t zlen = (authzid == NULL ? 0 : strlen(authzid));
64
0
  size_t clen = strlen(authcid);
65
0
  size_t plen = strlen(passwd);
66
67
0
  if((zlen > CURL_MAX_INPUT_LENGTH) || (clen > CURL_MAX_INPUT_LENGTH) ||
68
0
     (plen > CURL_MAX_INPUT_LENGTH))
69
0
    return CURLE_TOO_LARGE;
70
71
0
  len = zlen + clen + plen + 2;
72
73
0
  auth = curl_maprintf("%s%c%s%c%s", authzid ? authzid : "", '\0',
74
0
                       authcid, '\0', passwd);
75
0
  if(!auth)
76
0
    return CURLE_OUT_OF_MEMORY;
77
0
  Curl_bufref_set(out, auth, len, curl_free);
78
0
  return CURLE_OK;
79
0
}
80
81
/*
82
 * Curl_auth_create_login_message()
83
 *
84
 * This is used to generate an already encoded LOGIN message containing the
85
 * username or password ready for sending to the recipient.
86
 *
87
 * Parameters:
88
 *
89
 * valuep  [in]     - The username or user's password.
90
 * out     [out]    - The result storage.
91
 *
92
 * Returns void.
93
 */
94
void Curl_auth_create_login_message(const char *valuep, struct bufref *out)
95
0
{
96
0
  Curl_bufref_set(out, valuep, strlen(valuep), NULL);
97
0
}
98
99
/*
100
 * Curl_auth_create_external_message()
101
 *
102
 * This is used to generate an already encoded EXTERNAL message containing
103
 * the username ready for sending to the recipient.
104
 *
105
 * Parameters:
106
 *
107
 * user    [in]     - The username.
108
 * out     [out]    - The result storage.
109
 *
110
 * Returns void.
111
 */
112
void Curl_auth_create_external_message(const char *user, struct bufref *out)
113
0
{
114
  /* This is the same formatting as the login message */
115
0
  Curl_auth_create_login_message(user, out);
116
0
}
117
118
#endif /* if no users */