453 } |
453 } |
454 |
454 |
455 return 0; |
455 return 0; |
456 } |
456 } |
457 |
457 |
458 static int cmp_url_cred_entry(PwdEntry *e1, PwdEntry *e2, void *n) { |
458 static int cmp_url_cred_entry(PwdIndexEntry *e1, PwdIndexEntry *e2, void *n) { |
459 return strcmp(e2->location, e1->location); |
459 return strcmp(e2->location, e1->location); |
460 } |
460 } |
461 |
461 |
462 static int get_location_credentials(CmdArgs *a, Repository *repo, char *path, char **user, char **password) { |
462 static int get_location_credentials(CmdArgs *a, Repository *repo, char *path, char **user, char **password) { |
463 PwdStore *secrets = get_pwdstore(); |
463 PwdStore *secrets = get_pwdstore(); |
469 * The list secrets->location contains urls or repo names as |
469 * The list secrets->location contains urls or repo names as |
470 * location strings. We need a list, that contains only urls |
470 * location strings. We need a list, that contains only urls |
471 */ |
471 */ |
472 UcxList *locations = NULL; |
472 UcxList *locations = NULL; |
473 UCX_FOREACH(elm, secrets->locations) { |
473 UCX_FOREACH(elm, secrets->locations) { |
474 PwdEntry *e = elm->data; |
474 PwdIndexEntry *e = elm->data; |
475 char *path; |
475 char *path; |
476 Repository *r = url2repo(e->location, &path); |
476 Repository *r = url2repo(e->location, &path); |
477 PwdEntry *urlentry = calloc(1, sizeof(PwdEntry)); |
477 PwdIndexEntry *urlentry = calloc(1, sizeof(PwdEntry)); |
478 urlentry->id = strdup(e->id); |
478 urlentry->id = strdup(e->id); |
479 urlentry->location = util_concat_path(r->url, path); |
479 urlentry->location = util_concat_path(r->url, path); |
480 locations = ucx_list_append(locations, urlentry); |
480 locations = ucx_list_append(locations, urlentry); |
481 } |
481 } |
482 // the list must be sorted |
482 // the list must be sorted |
494 // iterate over sorted locations and check if a location is a prefix |
494 // iterate over sorted locations and check if a location is a prefix |
495 // of the requested url |
495 // of the requested url |
496 char *id = NULL; |
496 char *id = NULL; |
497 int ret = 0; |
497 int ret = 0; |
498 UCX_FOREACH(elm, locations) { |
498 UCX_FOREACH(elm, locations) { |
499 PwdEntry *cred = elm->data; |
499 PwdIndexEntry *cred = elm->data; |
500 sstr_t cred_url = sstr(cred->location); |
500 sstr_t cred_url = sstr(cred->location); |
501 |
501 |
502 // remove protocol prefix |
502 // remove protocol prefix |
503 if(sstrprefix(cred_url, S("http://"))) { |
503 if(sstrprefix(cred_url, S("http://"))) { |
504 cred_url = sstrsubs(cred_url, 7); |
504 cred_url = sstrsubs(cred_url, 7); |
2196 char *user = assistant_getcfg("User"); |
2196 char *user = assistant_getcfg("User"); |
2197 char *password = util_password_input("Password: "); |
2197 char *password = util_password_input("Password: "); |
2198 char *location = assistant_getoptcfg("Location"); |
2198 char *location = assistant_getoptcfg("Location"); |
2199 int ret = 1; |
2199 int ret = 1; |
2200 if(user && password) { |
2200 if(user && password) { |
2201 pwdstore_put(secrets, id, location, user, password); |
2201 pwdstore_put_index(secrets, id, location); |
|
2202 pwdstore_put(secrets, id, user, password); |
2202 int ret = pwdstore_save(secrets); |
2203 int ret = pwdstore_save(secrets); |
2203 if(ret) { |
2204 if(ret) { |
2204 fprintf(stderr, "Error: saving srcrets store failed.\n"); |
2205 fprintf(stderr, "Error: saving srcrets store failed.\n"); |
2205 } |
2206 } |
2206 } |
2207 } |