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
|
0
|
|
|
|
|
|
int git_cred_has_username(git_credential *cred) |
395
|
|
|
|
|
|
|
{ |
396
|
0
|
|
|
|
|
|
return git_credential_has_username(cred); |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
0
|
|
|
|
|
|
const char *git_cred_get_username(git_credential *cred) |
400
|
|
|
|
|
|
|
{ |
401
|
0
|
|
|
|
|
|
return git_credential_get_username(cred); |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
0
|
|
|
|
|
|
int git_cred_userpass_plaintext_new( |
405
|
|
|
|
|
|
|
git_credential **out, |
406
|
|
|
|
|
|
|
const char *username, |
407
|
|
|
|
|
|
|
const char *password) |
408
|
|
|
|
|
|
|
{ |
409
|
0
|
|
|
|
|
|
return git_credential_userpass_plaintext_new(out,username, password); |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
|
412
|
0
|
|
|
|
|
|
int git_cred_default_new(git_credential **out) |
413
|
|
|
|
|
|
|
{ |
414
|
0
|
|
|
|
|
|
return git_credential_default_new(out); |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
int git_cred_username_new(git_credential **out, const char *username) |
418
|
|
|
|
|
|
|
{ |
419
|
0
|
|
|
|
|
|
return git_credential_username_new(out, username); |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
0
|
|
|
|
|
|
int git_cred_ssh_key_new( |
423
|
|
|
|
|
|
|
git_credential **out, |
424
|
|
|
|
|
|
|
const char *username, |
425
|
|
|
|
|
|
|
const char *publickey, |
426
|
|
|
|
|
|
|
const char *privatekey, |
427
|
|
|
|
|
|
|
const char *passphrase) |
428
|
|
|
|
|
|
|
{ |
429
|
0
|
|
|
|
|
|
return git_credential_ssh_key_new(out, username, |
430
|
|
|
|
|
|
|
publickey, privatekey, passphrase); |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
|
int git_cred_ssh_key_memory_new( |
434
|
|
|
|
|
|
|
git_credential **out, |
435
|
|
|
|
|
|
|
const char *username, |
436
|
|
|
|
|
|
|
const char *publickey, |
437
|
|
|
|
|
|
|
const char *privatekey, |
438
|
|
|
|
|
|
|
const char *passphrase) |
439
|
|
|
|
|
|
|
{ |
440
|
0
|
|
|
|
|
|
return git_credential_ssh_key_memory_new(out, username, |
441
|
|
|
|
|
|
|
publickey, privatekey, passphrase); |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
|
int git_cred_ssh_interactive_new( |
445
|
|
|
|
|
|
|
git_credential **out, |
446
|
|
|
|
|
|
|
const char *username, |
447
|
|
|
|
|
|
|
git_credential_ssh_interactive_cb prompt_callback, |
448
|
|
|
|
|
|
|
void *payload) |
449
|
|
|
|
|
|
|
{ |
450
|
0
|
|
|
|
|
|
return git_credential_ssh_interactive_new(out, username, |
451
|
|
|
|
|
|
|
prompt_callback, payload); |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
0
|
|
|
|
|
|
int git_cred_ssh_key_from_agent( |
455
|
|
|
|
|
|
|
git_credential **out, |
456
|
|
|
|
|
|
|
const char *username) |
457
|
|
|
|
|
|
|
{ |
458
|
0
|
|
|
|
|
|
return git_credential_ssh_key_from_agent(out, username); |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
|
461
|
0
|
|
|
|
|
|
int git_cred_ssh_custom_new( |
462
|
|
|
|
|
|
|
git_credential **out, |
463
|
|
|
|
|
|
|
const char *username, |
464
|
|
|
|
|
|
|
const char *publickey, |
465
|
|
|
|
|
|
|
size_t publickey_len, |
466
|
|
|
|
|
|
|
git_credential_sign_cb sign_callback, |
467
|
|
|
|
|
|
|
void *payload) |
468
|
|
|
|
|
|
|
{ |
469
|
0
|
|
|
|
|
|
return git_credential_ssh_custom_new(out, username, |
470
|
|
|
|
|
|
|
publickey, publickey_len, sign_callback, payload); |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
0
|
|
|
|
|
|
void git_cred_free(git_credential *cred) |
474
|
|
|
|
|
|
|
{ |
475
|
0
|
|
|
|
|
|
git_credential_free(cred); |
476
|
0
|
|
|
|
|
|
} |