master
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 ***************************************************************************/
24#include "curl_setup.h"
26#include <stddef.h> /* for offsetof() */
28#include "creds.h"
29#include "curl_trc.h"
30#include "strcase.h"
31#include "urldata.h"
34CURLcode Curl_creds_create(const char *user,
35 const char *passwd,
36 const char *oauth_bearer,
37 const char *sasl_authzid,
38 const char *sasl_service,
39 uint8_t source,
40 struct Curl_creds **pcreds)
41{
42 struct Curl_creds *creds = NULL;
43 size_t ulen = user ? strlen(user) : 0;
44 size_t plen = passwd ? strlen(passwd) : 0;
45 size_t olen = oauth_bearer ? strlen(oauth_bearer) : 0;
46 size_t salen = sasl_authzid ? strlen(sasl_authzid) : 0;
47 size_t sslen = sasl_service ? strlen(sasl_service) : 0;
48 char *s, *buf;
49 size_t bufsize;
50 CURLcode result = CURLE_OK;
52 Curl_creds_unlink(pcreds);
54 /* Everything empty/NULL, this is the NULL credential */
55 if(!user && !passwd && !olen && !salen && !sslen)
56 goto out;
58 if((ulen > CURL_MAX_INPUT_LENGTH) ||
59 (plen > CURL_MAX_INPUT_LENGTH) ||
60 (olen > CURL_MAX_INPUT_LENGTH) ||
61 (salen > CURL_MAX_INPUT_LENGTH) ||
62 (sslen > CURL_MAX_INPUT_LENGTH)) {
63 result = CURLE_BAD_FUNCTION_ARGUMENT;
64 goto out;
65 }
67 /* null-terminator for user already part of struct */
68 bufsize = ulen + plen + 1 + olen + 1 + salen + 1 + sslen + 1;
69 creds = curlx_calloc(1, sizeof(*creds) + bufsize);
70 if(!creds) {
71 result = CURLE_OUT_OF_MEMORY;
72 goto out;
73 }
75 creds->bufsize = bufsize;
76 creds->refcount = 1;
77 creds->source = source;
78 /* Some compilers try to be too smart about our dynamic struct size */
79 buf = ((char *)creds) + offsetof(struct Curl_creds, buf);
80 creds->user = s = buf;
81 if(ulen)
82 memcpy(s, user, ulen + 1);
83 creds->passwd = s = buf + ulen + 1;
84 if(plen)
85 memcpy(s, passwd, plen + 1);
86 creds->oauth_bearer = s = buf + ulen + 1 + plen + 1;
87 if(olen)
88 memcpy(s, oauth_bearer, olen + 1);
89 creds->sasl_authzid = s = buf + ulen + 1 + plen + 1 + olen + 1;
90 if(salen)
91 memcpy(s, sasl_authzid, salen + 1);
92 creds->sasl_service = s = buf + ulen + 1 + plen + 1 + olen + 1 + salen + 1;
93 if(sslen)
94 memcpy(s, sasl_service, sslen + 1);
96out:
97 if(!result)
98 *pcreds = creds;
99 else
100 Curl_creds_unlink(&creds);
101 return result;
102}
104CURLcode Curl_creds_merge(const char *user,
105 const char *passwd,
106 struct Curl_creds *creds_in,
107 uint8_t source,
108 struct Curl_creds **pcreds_out)
109{
110 struct Curl_creds *creds_out = NULL;
111 CURLcode result;
113 if(!creds_in) {
114 result = Curl_creds_create(user, passwd, NULL, NULL, NULL,
115 source, &creds_out);
116 }
117 else {
118 result = Curl_creds_create(user ? user : Curl_creds_user(creds_in),
119 passwd ? passwd : Curl_creds_passwd(creds_in),
120 Curl_creds_oauth_bearer(creds_in),
121 Curl_creds_sasl_authzid(creds_in),
122 Curl_creds_sasl_service(creds_in),
123 source, &creds_out);
124 }
125 Curl_creds_link(pcreds_out, creds_out);
126 Curl_creds_unlink(&creds_out);
127 return result;
128}
130void Curl_creds_link(struct Curl_creds **pdest, struct Curl_creds *src)
131{
132 if(*pdest != src) {
133 Curl_creds_unlink(pdest);
134 *pdest = src;
135 if(src) {
136 DEBUGASSERT(src->refcount < UINT32_MAX);
137 src->refcount++;
138 }
139 }
140}
142void Curl_creds_unlink(struct Curl_creds **pcreds)
143{
144 if(*pcreds) {
145 struct Curl_creds *creds = *pcreds;
147 DEBUGASSERT(creds->refcount);
148 *pcreds = NULL;
149 if(creds->refcount)
150 creds->refcount--;
151 if(!creds->refcount) {
152 curlx_memzero(creds, sizeof(*creds) + creds->bufsize);
153 curlx_free(creds);
154 }
155 }
156}
158bool Curl_creds_same(struct Curl_creds *c1, struct Curl_creds *c2)
159{
160 return (c1 == c2) ||
161 (c1 && c2 &&
162 !Curl_timestrcmp(c1->user, c2->user) &&
163 !Curl_timestrcmp(c1->passwd, c2->passwd) &&
164 !Curl_timestrcmp(c1->oauth_bearer, c2->oauth_bearer) &&
165 !Curl_timestrcmp(c1->sasl_authzid, c2->sasl_authzid) &&
166 !Curl_timestrcmp(c1->sasl_service, c2->sasl_service));
167}
169bool Curl_creds_equal(struct Curl_creds *c1, struct Curl_creds *c2)
170{
171 return Curl_creds_same(c1, c2) &&
172 ((c1 == c2) || (c1 && c2 && (c1->source == c2->source)));
173}
175#ifdef CURLVERBOSE
176void Curl_creds_trace(struct Curl_easy *data, struct Curl_creds *creds,
177 const char *msg)
178{
179 if(creds) {
180 CURL_TRC_M(data, "%s: user=%s, passwd=%s, "
181 "sasl_authzid=%s, oauth_bearer=%s, source=%d",
182 msg,
183 Curl_creds_user(creds),
184 Curl_creds_has_passwd(creds) ? "***" : "",
185 Curl_creds_sasl_authzid(creds),
186 Curl_creds_has_oauth_bearer(creds) ? "***" : "",
187 creds->source);
188 }
189 else
190 CURL_TRC_M(data, "%s: -", msg);
191}
192#endif
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2001.9 KiB · hit29 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=29 git.response.bytes=1964 git.response.cache=HIT git.response.duration_ms=29 git.fetch.wants=5507ae86f6acead6b7349abb83cc0bb3bcd52275 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1964 git.pkt.payload.max=1943 git.sideband.band1.bytes=1942 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2d2e0fbeccf3a
- Request
- 7a807f2a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format