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