Coverage Report

Created: 2026-12-01 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/creds.h
Line
Count
Source
1
#ifndef HEADER_CURL_CREDS_H
2
#define HEADER_CURL_CREDS_H
3
/***************************************************************************
4
 *                                  _   _ ____  _
5
 *  Project                     ___| | | |  _ \| |
6
 *                             / __| | | | |_) | |
7
 *                            | (__| |_| |  _ <| |___
8
 *                             \___|\___/|_| \_\_____|
9
 *
10
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11
 *
12
 * This software is licensed as described in the file COPYING, which
13
 * you should have received as part of this distribution. The terms
14
 * are also available at https://curl.se/docs/copyright.html.
15
 *
16
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17
 * copies of the Software, and permit persons to whom the Software is
18
 * furnished to do so, under the terms of the COPYING file.
19
 *
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
 * KIND, either express or implied.
22
 *
23
 * SPDX-License-Identifier: curl
24
 *
25
 ***************************************************************************/
26
#include "curl_refcount.h"
27
28
struct Curl_easy;
29
30
0
#define CREDS_NONE   0 /* used for default username/passwd */
31
9.96k
#define CREDS_URL    1 /* username/passwd from URL */
32
661
#define CREDS_OPTION 2 /* username/passwd set with a CURLOPT_ */
33
0
#define CREDS_NETRC  3 /* username/passwd found in netrc */
34
35
struct Curl_creds {
36
  const char *user; /* non-NULL, maybe empty string */
37
  const char *passwd; /* non-NULL, maybe empty string */
38
  const char *oauth_bearer; /* non-NULL, maybe empty string */
39
  const char *sasl_authzid; /* non-NULL, maybe empty string */
40
  const char *sasl_service; /* non-NULL, maybe empty string */
41
  curl_refcount refcount;
42
  uint8_t source; /* CREDS_* value */
43
  size_t bufsize; /* extra bytes added to sizeof(struct Curl_creds) */
44
  char buf[1];
45
};
46
47
CURLcode Curl_creds_create(const char *user,
48
                           const char *passwd,
49
                           const char *oauth_bearer,
50
                           const char *sasl_authzid,
51
                           const char *sasl_service,
52
                           uint8_t source,
53
                           struct Curl_creds **pcreds);
54
55
/* Create credentials by overriding `user` and/or `passwd` in `creds_in` */
56
CURLcode Curl_creds_merge(const char *user,
57
                          const char *passwd,
58
                          struct Curl_creds *creds_in,
59
                          uint8_t source,
60
                          struct Curl_creds **pcreds_out);
61
62
/* Unlink any creds in `*pdest`, assign src, increase src
63
 * refcount when not NULL. */
64
void Curl_creds_link(struct Curl_creds **pdest, struct Curl_creds *src);
65
66
/* Drop a reference, creds may be passed as NULL */
67
void Curl_creds_unlink(struct Curl_creds **pcreds);
68
69
/* TRUE if both creds are NULL or have same values, except source. */
70
bool Curl_creds_same(struct Curl_creds *c1, struct Curl_creds *c2);
71
72
/* TRUE if both creds are NULL or have all values equal. */
73
bool Curl_creds_equal(struct Curl_creds *c1, struct Curl_creds *c2);
74
75
/* Provides properties for creds or, if creds is NULL, the empty string */
76
644
#define Curl_creds_has_user(c)           ((c) && (c)->user[0])
77
0
#define Curl_creds_has_passwd(c)         ((c) && (c)->passwd[0])
78
#define Curl_creds_has_user_or_pass(c) \
79
584
    ((c) && ((c)->user[0] || (c)->passwd[0]))
80
22
#define Curl_creds_has_oauth_bearer(c)   ((c) && (c)->oauth_bearer[0])
81
0
#define Curl_creds_has_sasl_service(c)   ((c) && (c)->sasl_service[0])
82
1.77k
#define Curl_creds_user(c)               ((c) ? (c)->user : "")
83
1.77k
#define Curl_creds_passwd(c)             ((c) ? (c)->passwd : "")
84
539
#define Curl_creds_oauth_bearer(c)       ((c) ? (c)->oauth_bearer : "")
85
533
#define Curl_creds_sasl_authzid(c)       ((c) ? (c)->sasl_authzid : "")
86
533
#define Curl_creds_sasl_service(c)       ((c) ? (c)->sasl_service : "")
87
88
#ifdef CURLVERBOSE
89
void Curl_creds_trace(struct Curl_easy *data, struct Curl_creds *creds,
90
                      const char *msg);
91
#endif
92
93
#endif /* HEADER_CURL_CREDS_H */