/src/PROJ/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 | 0 | { |
65 | 0 | size_t len; |
66 | 0 | char *auth; |
67 | |
|
68 | 0 | size_t zlen = (authzid == NULL ? 0 : strlen(authzid)); |
69 | 0 | size_t clen = strlen(authcid); |
70 | 0 | size_t plen = strlen(passwd); |
71 | |
|
72 | 0 | if((zlen > CURL_MAX_INPUT_LENGTH) || (clen > CURL_MAX_INPUT_LENGTH) || |
73 | 0 | (plen > CURL_MAX_INPUT_LENGTH)) |
74 | 0 | return CURLE_TOO_LARGE; |
75 | | |
76 | 0 | len = zlen + clen + plen + 2; |
77 | |
|
78 | 0 | auth = curl_maprintf("%s%c%s%c%s", authzid ? authzid : "", '\0', |
79 | 0 | authcid, '\0', passwd); |
80 | 0 | if(!auth) |
81 | 0 | return CURLE_OUT_OF_MEMORY; |
82 | 0 | Curl_bufref_set(out, auth, len, curl_free); |
83 | 0 | return CURLE_OK; |
84 | 0 | } |
85 | | |
86 | | /* |
87 | | * Curl_auth_create_login_message() |
88 | | * |
89 | | * This is used to generate an already encoded LOGIN message containing the |
90 | | * username or password ready for sending to the recipient. |
91 | | * |
92 | | * Parameters: |
93 | | * |
94 | | * valuep [in] - The username or user's password. |
95 | | * out [out] - The result storage. |
96 | | * |
97 | | * Returns void. |
98 | | */ |
99 | | void Curl_auth_create_login_message(const char *valuep, struct bufref *out) |
100 | 0 | { |
101 | 0 | Curl_bufref_set(out, valuep, strlen(valuep), NULL); |
102 | 0 | } |
103 | | |
104 | | /* |
105 | | * Curl_auth_create_external_message() |
106 | | * |
107 | | * This is used to generate an already encoded EXTERNAL message containing |
108 | | * the username ready for sending to the recipient. |
109 | | * |
110 | | * Parameters: |
111 | | * |
112 | | * user [in] - The username. |
113 | | * out [out] - The result storage. |
114 | | * |
115 | | * Returns void. |
116 | | */ |
117 | | void Curl_auth_create_external_message(const char *user, |
118 | | struct bufref *out) |
119 | 0 | { |
120 | | /* This is the same formatting as the login message */ |
121 | 0 | Curl_auth_create_login_message(user, out); |
122 | 0 | } |
123 | | |
124 | | #endif /* if no users */ |