application/config.c

changeset 85
44ebbb4c8a13
parent 76
641dcc79e0ef
equal deleted inserted replaced
84:57a359c52617 85:44ebbb4c8a13
298 // c->id is not a copy, therefore we don't have to free it 298 // c->id is not a copy, therefore we don't have to free it
299 free(c->location); 299 free(c->location);
300 free(c); 300 free(c);
301 } 301 }
302 302
303 int get_stored_credentials(char *credid, char **user, char **password) { 303 int get_stored_credentials(const char *credid, char **user, char **password) {
304 if(!credid) { 304 if(!credid) {
305 return 0; 305 return 0;
306 } 306 }
307 307
308 PwdStore *secrets = get_pwdstore(); 308 PwdStore *secrets = get_pwdstore();
330 330
331 return 0; 331 return 0;
332 } 332 }
333 333
334 334
335 int get_location_credentials(DavCfgRepository *repo, const char *path, char **user, char **password) { 335 const char* get_location_credentials(DavCfgRepository *repo, const char *path) {
336 PwdStore *secrets = get_pwdstore(); 336 PwdStore *secrets = get_pwdstore();
337 if(!secrets) { 337 if(!secrets) {
338 return 0; 338 return NULL;
339 } 339 }
340 340
341 /* 341 /*
342 * The list secrets->location contains urls or repo names as 342 * The list secrets->location contains urls or repo names as
343 * location strings. We need a list, that contains only urls 343 * location strings. We need a list, that contains only urls
369 req_url = cx_strsubs(req_url, 8); 369 req_url = cx_strsubs(req_url, 8);
370 } 370 }
371 371
372 // iterate over sorted locations and check if a location is a prefix 372 // iterate over sorted locations and check if a location is a prefix
373 // of the requested url 373 // of the requested url
374 char *id = NULL; 374 const char *id = NULL;
375 int ret = 0;
376 i = cxListIterator(locations); 375 i = cxListIterator(locations);
377 cx_foreach(CredLocation*, cred, i) { 376 cx_foreach(CredLocation*, cred, i) {
378 cxstring cred_url = cx_str(cred->location); 377 cxstring cred_url = cx_str(cred->location);
379 378
380 // remove protocol prefix 379 // remove protocol prefix
388 id = cred->id; 387 id = cred->id;
389 break; 388 break;
390 } 389 }
391 } 390 }
392 391
393 // if an id is found and we can access the decrypted secret store
394 // we can set the user/password
395 if(id && (secrets->isdecrypted || !pwdstore_decrypt_secrets(secrets))) {
396 PwdEntry *cred = pwdstore_get(secrets, id);
397 if(cred) {
398 *user = cred->user;
399 *password = cred->password;
400 ret = 1;
401 }
402 }
403
404 free(req_url_proto.ptr); 392 free(req_url_proto.ptr);
405 cxListDestroy(locations); 393 cxListDestroy(locations);
406 394
407 return ret; 395 return id;
408 } 396 }

mercurial