diff -r 29b979ca8750 -r fb69eae42ef0 dav/main.c --- a/dav/main.c Sat Oct 20 13:46:32 2018 +0200 +++ b/dav/main.c Sat Oct 27 12:16:26 2018 +0200 @@ -466,10 +466,21 @@ return 0; } -static int cmp_url_cred_entry(PwdIndexEntry *e1, PwdIndexEntry *e2, void *n) { +typedef struct CredLocation { + char *id; + char *location; +} CredLocation; + +static int cmp_url_cred_entry(CredLocation *e1, CredLocation *e2, void *n) { return strcmp(e2->location, e1->location); } +static void free_cred_location(CredLocation *c) { + // c->id is not a copy, therefore we don't have to free it + free(c->location); + free(c); +} + static int get_location_credentials(CmdArgs *a, Repository *repo, char *path, char **user, char **password) { PwdStore *secrets = get_pwdstore(); if(!secrets) { @@ -483,12 +494,15 @@ UcxList *locations = NULL; UCX_FOREACH(elm, secrets->locations) { PwdIndexEntry *e = elm->data; - char *path; - Repository *r = url2repo(e->location, &path); - PwdIndexEntry *urlentry = calloc(1, sizeof(PwdEntry)); - urlentry->id = strdup(e->id); - urlentry->location = util_concat_path(r->url, path); - locations = ucx_list_append(locations, urlentry); + + UCX_FOREACH(loc, e->locations) { + char *path; + Repository *r = url2repo(loc->data, &path); + CredLocation *urlentry = calloc(1, sizeof(CredLocation)); + urlentry->id = e->id; + urlentry->location = util_concat_path(r->url, path); + locations = ucx_list_append(locations, urlentry); + } } // the list must be sorted locations = ucx_list_sort(locations, (cmp_func)cmp_url_cred_entry, NULL); @@ -507,7 +521,7 @@ char *id = NULL; int ret = 0; UCX_FOREACH(elm, locations) { - PwdIndexEntry *cred = elm->data; + CredLocation *cred = elm->data; sstr_t cred_url = sstr(cred->location); // remove protocol prefix @@ -533,7 +547,8 @@ } free(req_url_proto.ptr); - ucx_list_free_content(locations, (ucx_destructor)pwdstore_free_entry); + ucx_list_free_content(locations, (ucx_destructor)free_cred_location); + ucx_list_free(locations); return ret; } @@ -2428,9 +2443,10 @@ char *user = assistant_getcfg("User"); char *password = util_password_input("Password: "); char *location = assistant_getoptcfg("Location"); + UcxList *locations = location ? ucx_list_append(NULL, location) : NULL; int ret = 1; if(user && password) { - pwdstore_put_index(secrets, id, location); + pwdstore_put_index(secrets, id, locations); pwdstore_put(secrets, id, user, password); int ret = pwdstore_save(secrets); if(ret) { @@ -2443,6 +2459,7 @@ if(user) free(user); if(password) free(password); if(location) free(location); + if(locations) ucx_list_free(locations); return ret; }