| 312 | } |
| 313 | |
| 314 | int credential_read(struct credential *c, FILE *fp, |
| 315 | enum credential_op_type op_type) |
| 316 | { |
| 317 | struct strbuf line = STRBUF_INIT; |
| 318 | |
| 319 | while (strbuf_getline(&line, fp) != EOF) { |
| 320 | char *key = line.buf; |
| 321 | char *value = strchr(key, '='); |
| 322 | |
| 323 | if (!line.len) |
| 324 | break; |
| 325 | |
| 326 | if (!value) { |
| 327 | warning("invalid credential line: %s", key); |
| 328 | strbuf_release(&line); |
| 329 | return -1; |
| 330 | } |
| 331 | *value++ = '\0'; |
| 332 | |
| 333 | if (!strcmp(key, "username")) { |
| 334 | free(c->username); |
| 335 | c->username = xstrdup(value); |
| 336 | c->username_from_proto = 1; |
| 337 | } else if (!strcmp(key, "password")) { |
| 338 | free(c->password); |
| 339 | c->password = xstrdup(value); |
| 340 | } else if (!strcmp(key, "credential")) { |
| 341 | free(c->credential); |
| 342 | c->credential = xstrdup(value); |
| 343 | } else if (!strcmp(key, "protocol")) { |
| 344 | free(c->protocol); |
| 345 | c->protocol = xstrdup(value); |
| 346 | } else if (!strcmp(key, "host")) { |
| 347 | free(c->host); |
| 348 | c->host = xstrdup(value); |
| 349 | } else if (!strcmp(key, "path")) { |
| 350 | free(c->path); |
| 351 | c->path = xstrdup(value); |
| 352 | } else if (!strcmp(key, "ephemeral")) { |
| 353 | c->ephemeral = !!git_config_bool("ephemeral", value); |
| 354 | } else if (!strcmp(key, "wwwauth[]")) { |
| 355 | strvec_push(&c->wwwauth_headers, value); |
| 356 | } else if (!strcmp(key, "state[]")) { |
| 357 | strvec_push(&c->state_headers, value); |
| 358 | } else if (!strcmp(key, "capability[]")) { |
| 359 | if (!strcmp(value, "authtype")) |
| 360 | credential_set_capability(&c->capa_authtype, op_type); |
| 361 | else if (!strcmp(value, "state")) |
| 362 | credential_set_capability(&c->capa_state, op_type); |
| 363 | } else if (!strcmp(key, "continue")) { |
| 364 | c->multistage = !!git_config_bool("continue", value); |
| 365 | } else if (!strcmp(key, "password_expiry_utc")) { |
| 366 | errno = 0; |
| 367 | c->password_expiry_utc = parse_timestamp(value, NULL, 10); |
| 368 | if (c->password_expiry_utc == 0 || errno == ERANGE) |
| 369 | c->password_expiry_utc = TIME_MAX; |
| 370 | } else if (!strcmp(key, "oauth_refresh_token")) { |
| 371 | free(c->oauth_refresh_token); |
no test coverage detected