34
credential_init(c);
35
}
36
37
+static void credential_set_capability(struct credential_capability *capa,
38
+ enum credential_op_type op_type)
39
+{
40
+ switch (op_type) {
41
+ case CREDENTIAL_OP_INITIAL:
42
+ capa->request_initial = 1;
43
+ break;
44
+ case CREDENTIAL_OP_HELPER:
45
+ capa->request_helper = 1;
46
+ break;
47
+ case CREDENTIAL_OP_RESPONSE:
48
+ capa->response = 1;
49
+ break;
50
+ }
51
+}
52
+
53
+
54
+void credential_set_all_capabilities(struct credential *c,
55
+ enum credential_op_type op_type)
56
+{
57
+ credential_set_capability(&c->capa_authtype, op_type);
58
+}
59
+
60
int credential_match(const struct credential *want,
61
const struct credential *have, int match_password)
62
{
233
PROMPT_ASKPASS);
234
}
235
213
-int credential_read(struct credential *c, FILE *fp)
236
+static int credential_has_capability(const struct credential_capability *capa,
237
+ enum credential_op_type op_type)
238
+{
239
+ /*
240
+ * We're checking here if each previous step indicated that we had the
241
+ * capability. If it did, then we want to pass it along; conversely, if
242
+ * it did not, we don't want to report that to our caller.
243
+ */
244
+ switch (op_type) {
245
+ case CREDENTIAL_OP_HELPER:
246
+ return capa->request_initial;
247
+ case CREDENTIAL_OP_RESPONSE:
248
+ return capa->request_initial && capa->request_helper;
249
+ default:
250
+ return 0;
251
+ }
252
+}
253
+
254
+int credential_read(struct credential *c, FILE *fp,
255
+ enum credential_op_type op_type)
256
{
257
struct strbuf line = STRBUF_INIT;
258
291
c->path = xstrdup(value);
292
} else if (!strcmp(key, "wwwauth[]")) {
293
strvec_push(&c->wwwauth_headers, value);
294
+ } else if (!strcmp(key, "capability[]") && !strcmp(value, "authtype")) {
295
+ credential_set_capability(&c->capa_authtype, op_type);
296
} else if (!strcmp(key, "password_expiry_utc")) {
297
errno = 0;
298
c->password_expiry_utc = parse_timestamp(value, NULL, 10);
332
fprintf(fp, "%s=%s\n", key, value);
333
}
334
291
-void credential_write(const struct credential *c, FILE *fp)
335
+void credential_write(const struct credential *c, FILE *fp,
336
+ enum credential_op_type op_type)
337
{
338
+ if (credential_has_capability(&c->capa_authtype, op_type)) {
339
+ credential_write_item(fp, "capability[]", "authtype", 0);
340
+ credential_write_item(fp, "authtype", c->authtype, 0);
341
+ credential_write_item(fp, "credential", c->credential, 0);
342
+ }
343
credential_write_item(fp, "protocol", c->protocol, 1);
344
credential_write_item(fp, "host", c->host, 1);
345
credential_write_item(fp, "path", c->path, 0);
346
credential_write_item(fp, "username", c->username, 0);
347
credential_write_item(fp, "password", c->password, 0);
298
- credential_write_item(fp, "credential", c->credential, 0);
348
credential_write_item(fp, "oauth_refresh_token", c->oauth_refresh_token, 0);
349
if (c->password_expiry_utc != TIME_MAX) {
350
char *s = xstrfmt("%"PRItime, c->password_expiry_utc);
353
}
354
for (size_t i = 0; i < c->wwwauth_headers.nr; i++)
355
credential_write_item(fp, "wwwauth[]", c->wwwauth_headers.v[i], 0);
307
- credential_write_item(fp, "authtype", c->authtype, 0);
356
}
357
358
static int run_credential_helper(struct credential *c,
375
376
fp = xfdopen(helper.in, "w");
377
sigchain_push(SIGPIPE, SIG_IGN);
330
- credential_write(c, fp);
378
+ credential_write(c, fp, want_output ? CREDENTIAL_OP_HELPER : CREDENTIAL_OP_RESPONSE);
379
fclose(fp);
380
sigchain_pop(SIGPIPE);
381
382
if (want_output) {
383
int r;
384
fp = xfdopen(helper.out, "r");
337
- r = credential_read(c, fp);
385
+ r = credential_read(c, fp, CREDENTIAL_OP_HELPER);
386
fclose(fp);
387
if (r < 0) {
388
finish_command(&helper);
415
return r;
416
}
417
370
-void credential_fill(struct credential *c)
418
+void credential_fill(struct credential *c, int all_capabilities)
419
{
420
int i;
421
423
return;
424
425
credential_apply_config(c);
426
+ if (all_capabilities)
427
+ credential_set_all_capabilities(c, CREDENTIAL_OP_INITIAL);
428
429
for (i = 0; i < c->helpers.nr; i++) {
430
credential_do(c, c->helpers.items[i].string, "get");