line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "auth.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "git2.h" |
11
|
|
|
|
|
|
|
#include "buffer.h" |
12
|
|
|
|
|
|
|
#include "git2/sys/credential.h" |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
static int basic_next_token( |
15
|
|
|
|
|
|
|
git_buf *out, |
16
|
|
|
|
|
|
|
git_http_auth_context *ctx, |
17
|
|
|
|
|
|
|
git_credential *c) |
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
git_credential_userpass_plaintext *cred; |
20
|
0
|
|
|
|
|
|
git_buf raw = GIT_BUF_INIT; |
21
|
0
|
|
|
|
|
|
int error = -1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
GIT_UNUSED(ctx); |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if (c->credtype != GIT_CREDENTIAL_USERPASS_PLAINTEXT) { |
26
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "invalid credential type for basic auth"); |
27
|
0
|
|
|
|
|
|
goto on_error; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
cred = (git_credential_userpass_plaintext *)c; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
git_buf_printf(&raw, "%s:%s", cred->username, cred->password); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
if (git_buf_oom(&raw) || |
35
|
0
|
0
|
|
|
|
|
git_buf_puts(out, "Basic ") < 0 || |
36
|
0
|
|
|
|
|
|
git_buf_encode_base64(out, git_buf_cstr(&raw), raw.size) < 0) |
37
|
|
|
|
|
|
|
goto on_error; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
error = 0; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
on_error: |
42
|
0
|
0
|
|
|
|
|
if (raw.size) |
43
|
0
|
|
|
|
|
|
git__memzero(raw.ptr, raw.size); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
git_buf_dispose(&raw); |
46
|
0
|
|
|
|
|
|
return error; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
static git_http_auth_context basic_context = { |
50
|
|
|
|
|
|
|
GIT_HTTP_AUTH_BASIC, |
51
|
|
|
|
|
|
|
GIT_CREDENTIAL_USERPASS_PLAINTEXT, |
52
|
|
|
|
|
|
|
0, |
53
|
|
|
|
|
|
|
NULL, |
54
|
|
|
|
|
|
|
basic_next_token, |
55
|
|
|
|
|
|
|
NULL, |
56
|
|
|
|
|
|
|
NULL |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
int git_http_auth_basic( |
60
|
|
|
|
|
|
|
git_http_auth_context **out, const git_net_url *url) |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
GIT_UNUSED(url); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
*out = &basic_context; |
65
|
0
|
|
|
|
|
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
int git_http_auth_dummy( |
69
|
|
|
|
|
|
|
git_http_auth_context **out, const git_net_url *url) |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
GIT_UNUSED(url); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
*out = NULL; |
74
|
0
|
|
|
|
|
|
return GIT_PASSTHROUGH; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|