| 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 "common.h" |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "git2/credential.h" |
|
11
|
|
|
|
|
|
|
#include "git2/sys/credential.h" |
|
12
|
|
|
|
|
|
|
#include "git2/credential_helpers.h" |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
static int git_credential_ssh_key_type_new( |
|
15
|
|
|
|
|
|
|
git_credential **cred, |
|
16
|
|
|
|
|
|
|
const char *username, |
|
17
|
|
|
|
|
|
|
const char *publickey, |
|
18
|
|
|
|
|
|
|
const char *privatekey, |
|
19
|
|
|
|
|
|
|
const char *passphrase, |
|
20
|
|
|
|
|
|
|
git_credential_t credtype); |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
int git_credential_has_username(git_credential *cred) |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
0
|
0
|
|
|
|
|
if (cred->credtype == GIT_CREDENTIAL_DEFAULT) |
|
25
|
0
|
|
|
|
|
|
return 0; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
const char *git_credential_get_username(git_credential *cred) |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
0
|
|
|
|
|
|
switch (cred->credtype) { |
|
33
|
|
|
|
|
|
|
case GIT_CREDENTIAL_USERNAME: |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
0
|
|
|
|
|
|
git_credential_username *c = (git_credential_username *) cred; |
|
36
|
0
|
|
|
|
|
|
return c->username; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
case GIT_CREDENTIAL_USERPASS_PLAINTEXT: |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
0
|
|
|
|
|
|
git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *) cred; |
|
41
|
0
|
|
|
|
|
|
return c->username; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
case GIT_CREDENTIAL_SSH_KEY: |
|
44
|
|
|
|
|
|
|
case GIT_CREDENTIAL_SSH_MEMORY: |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
0
|
|
|
|
|
|
git_credential_ssh_key *c = (git_credential_ssh_key *) cred; |
|
47
|
0
|
|
|
|
|
|
return c->username; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
case GIT_CREDENTIAL_SSH_CUSTOM: |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
|
|
|
git_credential_ssh_custom *c = (git_credential_ssh_custom *) cred; |
|
52
|
0
|
|
|
|
|
|
return c->username; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
case GIT_CREDENTIAL_SSH_INTERACTIVE: |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
0
|
|
|
|
|
|
git_credential_ssh_interactive *c = (git_credential_ssh_interactive *) cred; |
|
57
|
0
|
|
|
|
|
|
return c->username; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
default: |
|
61
|
0
|
|
|
|
|
|
return NULL; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
static void plaintext_free(struct git_credential *cred) |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
0
|
|
|
|
|
|
git_credential_userpass_plaintext *c = (git_credential_userpass_plaintext *)cred; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
git__free(c->username); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
/* Zero the memory which previously held the password */ |
|
72
|
0
|
0
|
|
|
|
|
if (c->password) { |
|
73
|
0
|
|
|
|
|
|
size_t pass_len = strlen(c->password); |
|
74
|
0
|
|
|
|
|
|
git__memzero(c->password, pass_len); |
|
75
|
0
|
|
|
|
|
|
git__free(c->password); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
git__free(c); |
|
79
|
0
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
int git_credential_userpass_plaintext_new( |
|
82
|
|
|
|
|
|
|
git_credential **cred, |
|
83
|
|
|
|
|
|
|
const char *username, |
|
84
|
|
|
|
|
|
|
const char *password) |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
|
|
|
|
|
|
git_credential_userpass_plaintext *c; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
assert(cred && username && password); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
c = git__malloc(sizeof(git_credential_userpass_plaintext)); |
|
91
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
c->parent.credtype = GIT_CREDENTIAL_USERPASS_PLAINTEXT; |
|
94
|
0
|
|
|
|
|
|
c->parent.free = plaintext_free; |
|
95
|
0
|
|
|
|
|
|
c->username = git__strdup(username); |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (!c->username) { |
|
98
|
0
|
|
|
|
|
|
git__free(c); |
|
99
|
0
|
|
|
|
|
|
return -1; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
c->password = git__strdup(password); |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if (!c->password) { |
|
105
|
0
|
|
|
|
|
|
git__free(c->username); |
|
106
|
0
|
|
|
|
|
|
git__free(c); |
|
107
|
0
|
|
|
|
|
|
return -1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
*cred = &c->parent; |
|
111
|
0
|
|
|
|
|
|
return 0; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
static void ssh_key_free(struct git_credential *cred) |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
0
|
|
|
|
|
|
git_credential_ssh_key *c = |
|
117
|
|
|
|
|
|
|
(git_credential_ssh_key *)cred; |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
git__free(c->username); |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
if (c->privatekey) { |
|
122
|
|
|
|
|
|
|
/* Zero the memory which previously held the private key */ |
|
123
|
0
|
|
|
|
|
|
size_t key_len = strlen(c->privatekey); |
|
124
|
0
|
|
|
|
|
|
git__memzero(c->privatekey, key_len); |
|
125
|
0
|
|
|
|
|
|
git__free(c->privatekey); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if (c->passphrase) { |
|
129
|
|
|
|
|
|
|
/* Zero the memory which previously held the passphrase */ |
|
130
|
0
|
|
|
|
|
|
size_t pass_len = strlen(c->passphrase); |
|
131
|
0
|
|
|
|
|
|
git__memzero(c->passphrase, pass_len); |
|
132
|
0
|
|
|
|
|
|
git__free(c->passphrase); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if (c->publickey) { |
|
136
|
|
|
|
|
|
|
/* Zero the memory which previously held the public key */ |
|
137
|
0
|
|
|
|
|
|
size_t key_len = strlen(c->publickey); |
|
138
|
0
|
|
|
|
|
|
git__memzero(c->publickey, key_len); |
|
139
|
0
|
|
|
|
|
|
git__free(c->publickey); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
git__free(c); |
|
143
|
0
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
static void ssh_interactive_free(struct git_credential *cred) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
0
|
|
|
|
|
|
git_credential_ssh_interactive *c = (git_credential_ssh_interactive *)cred; |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
git__free(c->username); |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
git__free(c); |
|
152
|
0
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
static void ssh_custom_free(struct git_credential *cred) |
|
155
|
|
|
|
|
|
|
{ |
|
156
|
0
|
|
|
|
|
|
git_credential_ssh_custom *c = (git_credential_ssh_custom *)cred; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
git__free(c->username); |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
if (c->publickey) { |
|
161
|
|
|
|
|
|
|
/* Zero the memory which previously held the publickey */ |
|
162
|
0
|
|
|
|
|
|
size_t key_len = strlen(c->publickey); |
|
163
|
0
|
|
|
|
|
|
git__memzero(c->publickey, key_len); |
|
164
|
0
|
|
|
|
|
|
git__free(c->publickey); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
git__free(c); |
|
168
|
0
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
static void default_free(struct git_credential *cred) |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
0
|
|
|
|
|
|
git_credential_default *c = (git_credential_default *)cred; |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
git__free(c); |
|
175
|
0
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
static void username_free(struct git_credential *cred) |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
0
|
|
|
|
|
|
git__free(cred); |
|
180
|
0
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
int git_credential_ssh_key_new( |
|
183
|
|
|
|
|
|
|
git_credential **cred, |
|
184
|
|
|
|
|
|
|
const char *username, |
|
185
|
|
|
|
|
|
|
const char *publickey, |
|
186
|
|
|
|
|
|
|
const char *privatekey, |
|
187
|
|
|
|
|
|
|
const char *passphrase) |
|
188
|
|
|
|
|
|
|
{ |
|
189
|
0
|
|
|
|
|
|
return git_credential_ssh_key_type_new( |
|
190
|
|
|
|
|
|
|
cred, |
|
191
|
|
|
|
|
|
|
username, |
|
192
|
|
|
|
|
|
|
publickey, |
|
193
|
|
|
|
|
|
|
privatekey, |
|
194
|
|
|
|
|
|
|
passphrase, |
|
195
|
|
|
|
|
|
|
GIT_CREDENTIAL_SSH_KEY); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
int git_credential_ssh_key_memory_new( |
|
199
|
|
|
|
|
|
|
git_credential **cred, |
|
200
|
|
|
|
|
|
|
const char *username, |
|
201
|
|
|
|
|
|
|
const char *publickey, |
|
202
|
|
|
|
|
|
|
const char *privatekey, |
|
203
|
|
|
|
|
|
|
const char *passphrase) |
|
204
|
|
|
|
|
|
|
{ |
|
205
|
|
|
|
|
|
|
#ifdef GIT_SSH_MEMORY_CREDENTIALS |
|
206
|
|
|
|
|
|
|
return git_credential_ssh_key_type_new( |
|
207
|
|
|
|
|
|
|
cred, |
|
208
|
|
|
|
|
|
|
username, |
|
209
|
|
|
|
|
|
|
publickey, |
|
210
|
|
|
|
|
|
|
privatekey, |
|
211
|
|
|
|
|
|
|
passphrase, |
|
212
|
|
|
|
|
|
|
GIT_CREDENTIAL_SSH_MEMORY); |
|
213
|
|
|
|
|
|
|
#else |
|
214
|
|
|
|
|
|
|
GIT_UNUSED(cred); |
|
215
|
|
|
|
|
|
|
GIT_UNUSED(username); |
|
216
|
|
|
|
|
|
|
GIT_UNUSED(publickey); |
|
217
|
|
|
|
|
|
|
GIT_UNUSED(privatekey); |
|
218
|
|
|
|
|
|
|
GIT_UNUSED(passphrase); |
|
219
|
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, |
|
221
|
|
|
|
|
|
|
"this version of libgit2 was not built with ssh memory credentials."); |
|
222
|
0
|
|
|
|
|
|
return -1; |
|
223
|
|
|
|
|
|
|
#endif |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
static int git_credential_ssh_key_type_new( |
|
227
|
|
|
|
|
|
|
git_credential **cred, |
|
228
|
|
|
|
|
|
|
const char *username, |
|
229
|
|
|
|
|
|
|
const char *publickey, |
|
230
|
|
|
|
|
|
|
const char *privatekey, |
|
231
|
|
|
|
|
|
|
const char *passphrase, |
|
232
|
|
|
|
|
|
|
git_credential_t credtype) |
|
233
|
|
|
|
|
|
|
{ |
|
234
|
|
|
|
|
|
|
git_credential_ssh_key *c; |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
0
|
|
|
|
|
assert(username && cred && privatekey); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
c = git__calloc(1, sizeof(git_credential_ssh_key)); |
|
239
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
c->parent.credtype = credtype; |
|
242
|
0
|
|
|
|
|
|
c->parent.free = ssh_key_free; |
|
243
|
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
c->username = git__strdup(username); |
|
245
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->username); |
|
246
|
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
c->privatekey = git__strdup(privatekey); |
|
248
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->privatekey); |
|
249
|
|
|
|
|
|
|
|
|
250
|
0
|
0
|
|
|
|
|
if (publickey) { |
|
251
|
0
|
|
|
|
|
|
c->publickey = git__strdup(publickey); |
|
252
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->publickey); |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
0
|
0
|
|
|
|
|
if (passphrase) { |
|
256
|
0
|
|
|
|
|
|
c->passphrase = git__strdup(passphrase); |
|
257
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->passphrase); |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
*cred = &c->parent; |
|
261
|
0
|
|
|
|
|
|
return 0; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
int git_credential_ssh_interactive_new( |
|
265
|
|
|
|
|
|
|
git_credential **out, |
|
266
|
|
|
|
|
|
|
const char *username, |
|
267
|
|
|
|
|
|
|
git_credential_ssh_interactive_cb prompt_callback, |
|
268
|
|
|
|
|
|
|
void *payload) |
|
269
|
|
|
|
|
|
|
{ |
|
270
|
|
|
|
|
|
|
git_credential_ssh_interactive *c; |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
assert(out && username && prompt_callback); |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
c = git__calloc(1, sizeof(git_credential_ssh_interactive)); |
|
275
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
c->parent.credtype = GIT_CREDENTIAL_SSH_INTERACTIVE; |
|
278
|
0
|
|
|
|
|
|
c->parent.free = ssh_interactive_free; |
|
279
|
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
c->username = git__strdup(username); |
|
281
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->username); |
|
282
|
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
c->prompt_callback = prompt_callback; |
|
284
|
0
|
|
|
|
|
|
c->payload = payload; |
|
285
|
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
*out = &c->parent; |
|
287
|
0
|
|
|
|
|
|
return 0; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) { |
|
291
|
|
|
|
|
|
|
git_credential_ssh_key *c; |
|
292
|
|
|
|
|
|
|
|
|
293
|
0
|
0
|
|
|
|
|
assert(username && cred); |
|
|
|
0
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
c = git__calloc(1, sizeof(git_credential_ssh_key)); |
|
296
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
297
|
|
|
|
|
|
|
|
|
298
|
0
|
|
|
|
|
|
c->parent.credtype = GIT_CREDENTIAL_SSH_KEY; |
|
299
|
0
|
|
|
|
|
|
c->parent.free = ssh_key_free; |
|
300
|
|
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
c->username = git__strdup(username); |
|
302
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->username); |
|
303
|
|
|
|
|
|
|
|
|
304
|
0
|
|
|
|
|
|
c->privatekey = NULL; |
|
305
|
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
*cred = &c->parent; |
|
307
|
0
|
|
|
|
|
|
return 0; |
|
308
|
|
|
|
|
|
|
} |
|
309
|
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
int git_credential_ssh_custom_new( |
|
311
|
|
|
|
|
|
|
git_credential **cred, |
|
312
|
|
|
|
|
|
|
const char *username, |
|
313
|
|
|
|
|
|
|
const char *publickey, |
|
314
|
|
|
|
|
|
|
size_t publickey_len, |
|
315
|
|
|
|
|
|
|
git_credential_sign_cb sign_callback, |
|
316
|
|
|
|
|
|
|
void *payload) |
|
317
|
|
|
|
|
|
|
{ |
|
318
|
|
|
|
|
|
|
git_credential_ssh_custom *c; |
|
319
|
|
|
|
|
|
|
|
|
320
|
0
|
0
|
|
|
|
|
assert(username && cred); |
|
|
|
0
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
c = git__calloc(1, sizeof(git_credential_ssh_custom)); |
|
323
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
324
|
|
|
|
|
|
|
|
|
325
|
0
|
|
|
|
|
|
c->parent.credtype = GIT_CREDENTIAL_SSH_CUSTOM; |
|
326
|
0
|
|
|
|
|
|
c->parent.free = ssh_custom_free; |
|
327
|
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
c->username = git__strdup(username); |
|
329
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->username); |
|
330
|
|
|
|
|
|
|
|
|
331
|
0
|
0
|
|
|
|
|
if (publickey_len > 0) { |
|
332
|
0
|
|
|
|
|
|
c->publickey = git__malloc(publickey_len); |
|
333
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c->publickey); |
|
334
|
|
|
|
|
|
|
|
|
335
|
0
|
|
|
|
|
|
memcpy(c->publickey, publickey, publickey_len); |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
0
|
|
|
|
|
|
c->publickey_len = publickey_len; |
|
339
|
0
|
|
|
|
|
|
c->sign_callback = sign_callback; |
|
340
|
0
|
|
|
|
|
|
c->payload = payload; |
|
341
|
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
|
*cred = &c->parent; |
|
343
|
0
|
|
|
|
|
|
return 0; |
|
344
|
|
|
|
|
|
|
} |
|
345
|
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
int git_credential_default_new(git_credential **cred) |
|
347
|
|
|
|
|
|
|
{ |
|
348
|
|
|
|
|
|
|
git_credential_default *c; |
|
349
|
|
|
|
|
|
|
|
|
350
|
0
|
0
|
|
|
|
|
assert(cred); |
|
351
|
|
|
|
|
|
|
|
|
352
|
0
|
|
|
|
|
|
c = git__calloc(1, sizeof(git_credential_default)); |
|
353
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
354
|
|
|
|
|
|
|
|
|
355
|
0
|
|
|
|
|
|
c->credtype = GIT_CREDENTIAL_DEFAULT; |
|
356
|
0
|
|
|
|
|
|
c->free = default_free; |
|
357
|
|
|
|
|
|
|
|
|
358
|
0
|
|
|
|
|
|
*cred = c; |
|
359
|
0
|
|
|
|
|
|
return 0; |
|
360
|
|
|
|
|
|
|
} |
|
361
|
|
|
|
|
|
|
|
|
362
|
0
|
|
|
|
|
|
int git_credential_username_new(git_credential **cred, const char *username) |
|
363
|
|
|
|
|
|
|
{ |
|
364
|
|
|
|
|
|
|
git_credential_username *c; |
|
365
|
|
|
|
|
|
|
size_t len, allocsize; |
|
366
|
|
|
|
|
|
|
|
|
367
|
0
|
0
|
|
|
|
|
assert(cred); |
|
368
|
|
|
|
|
|
|
|
|
369
|
0
|
|
|
|
|
|
len = strlen(username); |
|
370
|
|
|
|
|
|
|
|
|
371
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_credential_username), len); |
|
|
|
0
|
|
|
|
|
|
|
372
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1); |
|
|
|
0
|
|
|
|
|
|
|
373
|
0
|
|
|
|
|
|
c = git__malloc(allocsize); |
|
374
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(c); |
|
375
|
|
|
|
|
|
|
|
|
376
|
0
|
|
|
|
|
|
c->parent.credtype = GIT_CREDENTIAL_USERNAME; |
|
377
|
0
|
|
|
|
|
|
c->parent.free = username_free; |
|
378
|
0
|
|
|
|
|
|
memcpy(c->username, username, len + 1); |
|
379
|
|
|
|
|
|
|
|
|
380
|
0
|
|
|
|
|
|
*cred = (git_credential *) c; |
|
381
|
0
|
|
|
|
|
|
return 0; |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
|
|
384
|
0
|
|
|
|
|
|
void git_credential_free(git_credential *cred) |
|
385
|
|
|
|
|
|
|
{ |
|
386
|
0
|
0
|
|
|
|
|
if (!cred) |
|
387
|
0
|
|
|
|
|
|
return; |
|
388
|
|
|
|
|
|
|
|
|
389
|
0
|
|
|
|
|
|
cred->free(cred); |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
/* Deprecated credential functions */ |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
#ifndef GIT_DEPRECATE_HARD |
|
395
|
0
|
|
|
|
|
|
int git_cred_has_username(git_credential *cred) |
|
396
|
|
|
|
|
|
|
{ |
|
397
|
0
|
|
|
|
|
|
return git_credential_has_username(cred); |
|
398
|
|
|
|
|
|
|
} |
|
399
|
|
|
|
|
|
|
|
|
400
|
0
|
|
|
|
|
|
const char *git_cred_get_username(git_credential *cred) |
|
401
|
|
|
|
|
|
|
{ |
|
402
|
0
|
|
|
|
|
|
return git_credential_get_username(cred); |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
int git_cred_userpass_plaintext_new( |
|
406
|
|
|
|
|
|
|
git_credential **out, |
|
407
|
|
|
|
|
|
|
const char *username, |
|
408
|
|
|
|
|
|
|
const char *password) |
|
409
|
|
|
|
|
|
|
{ |
|
410
|
0
|
|
|
|
|
|
return git_credential_userpass_plaintext_new(out,username, password); |
|
411
|
|
|
|
|
|
|
} |
|
412
|
|
|
|
|
|
|
|
|
413
|
0
|
|
|
|
|
|
int git_cred_default_new(git_credential **out) |
|
414
|
|
|
|
|
|
|
{ |
|
415
|
0
|
|
|
|
|
|
return git_credential_default_new(out); |
|
416
|
|
|
|
|
|
|
} |
|
417
|
|
|
|
|
|
|
|
|
418
|
0
|
|
|
|
|
|
int git_cred_username_new(git_credential **out, const char *username) |
|
419
|
|
|
|
|
|
|
{ |
|
420
|
0
|
|
|
|
|
|
return git_credential_username_new(out, username); |
|
421
|
|
|
|
|
|
|
} |
|
422
|
|
|
|
|
|
|
|
|
423
|
0
|
|
|
|
|
|
int git_cred_ssh_key_new( |
|
424
|
|
|
|
|
|
|
git_credential **out, |
|
425
|
|
|
|
|
|
|
const char *username, |
|
426
|
|
|
|
|
|
|
const char *publickey, |
|
427
|
|
|
|
|
|
|
const char *privatekey, |
|
428
|
|
|
|
|
|
|
const char *passphrase) |
|
429
|
|
|
|
|
|
|
{ |
|
430
|
0
|
|
|
|
|
|
return git_credential_ssh_key_new(out, username, |
|
431
|
|
|
|
|
|
|
publickey, privatekey, passphrase); |
|
432
|
|
|
|
|
|
|
} |
|
433
|
|
|
|
|
|
|
|
|
434
|
0
|
|
|
|
|
|
int git_cred_ssh_key_memory_new( |
|
435
|
|
|
|
|
|
|
git_credential **out, |
|
436
|
|
|
|
|
|
|
const char *username, |
|
437
|
|
|
|
|
|
|
const char *publickey, |
|
438
|
|
|
|
|
|
|
const char *privatekey, |
|
439
|
|
|
|
|
|
|
const char *passphrase) |
|
440
|
|
|
|
|
|
|
{ |
|
441
|
0
|
|
|
|
|
|
return git_credential_ssh_key_memory_new(out, username, |
|
442
|
|
|
|
|
|
|
publickey, privatekey, passphrase); |
|
443
|
|
|
|
|
|
|
} |
|
444
|
|
|
|
|
|
|
|
|
445
|
0
|
|
|
|
|
|
int git_cred_ssh_interactive_new( |
|
446
|
|
|
|
|
|
|
git_credential **out, |
|
447
|
|
|
|
|
|
|
const char *username, |
|
448
|
|
|
|
|
|
|
git_credential_ssh_interactive_cb prompt_callback, |
|
449
|
|
|
|
|
|
|
void *payload) |
|
450
|
|
|
|
|
|
|
{ |
|
451
|
0
|
|
|
|
|
|
return git_credential_ssh_interactive_new(out, username, |
|
452
|
|
|
|
|
|
|
prompt_callback, payload); |
|
453
|
|
|
|
|
|
|
} |
|
454
|
|
|
|
|
|
|
|
|
455
|
0
|
|
|
|
|
|
int git_cred_ssh_key_from_agent( |
|
456
|
|
|
|
|
|
|
git_credential **out, |
|
457
|
|
|
|
|
|
|
const char *username) |
|
458
|
|
|
|
|
|
|
{ |
|
459
|
0
|
|
|
|
|
|
return git_credential_ssh_key_from_agent(out, username); |
|
460
|
|
|
|
|
|
|
} |
|
461
|
|
|
|
|
|
|
|
|
462
|
0
|
|
|
|
|
|
int git_cred_ssh_custom_new( |
|
463
|
|
|
|
|
|
|
git_credential **out, |
|
464
|
|
|
|
|
|
|
const char *username, |
|
465
|
|
|
|
|
|
|
const char *publickey, |
|
466
|
|
|
|
|
|
|
size_t publickey_len, |
|
467
|
|
|
|
|
|
|
git_credential_sign_cb sign_callback, |
|
468
|
|
|
|
|
|
|
void *payload) |
|
469
|
|
|
|
|
|
|
{ |
|
470
|
0
|
|
|
|
|
|
return git_credential_ssh_custom_new(out, username, |
|
471
|
|
|
|
|
|
|
publickey, publickey_len, sign_callback, payload); |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
|
void git_cred_free(git_credential *cred) |
|
475
|
|
|
|
|
|
|
{ |
|
476
|
0
|
|
|
|
|
|
git_credential_free(cred); |
|
477
|
0
|
|
|
|
|
|
} |
|
478
|
|
|
|
|
|
|
#endif |