150 || !strcasecmp(cmd, "list-repos")) { |
151 || !strcasecmp(cmd, "list-repos")) { |
151 ret = list_repositories(); |
152 ret = list_repositories(); |
152 } else if(!strcasecmp(cmd, "repository-url") |
153 } else if(!strcasecmp(cmd, "repository-url") |
153 || !strcasecmp(cmd, "repo-url")) { |
154 || !strcasecmp(cmd, "repo-url")) { |
154 ret = cmd_repository_url(args); |
155 ret = cmd_repository_url(args); |
|
156 } else if(!strcasecmp(cmd, "add-user")) { |
|
157 ret = cmd_add_user(args); |
155 } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") |
158 } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version") |
156 || !strcasecmp(cmd, "--version")) { |
159 || !strcasecmp(cmd, "--version")) { |
157 fprintf(stderr, "dav %s\n", DAV_VERSION); |
160 fprintf(stderr, "dav %s\n", DAV_VERSION); |
158 } else if(!strcasecmp(cmd, "complete")) { |
161 } else if(!strcasecmp(cmd, "complete")) { |
159 if(args->argc < 2) { |
162 if(args->argc < 2) { |
400 dav_add_collection_lock(sn, "/", lock); |
403 dav_add_collection_lock(sn, "/", lock); |
401 } |
404 } |
402 } |
405 } |
403 |
406 |
404 static DavSession* connect_to_repo(Repository *repo, CmdArgs *a) { |
407 static DavSession* connect_to_repo(Repository *repo, CmdArgs *a) { |
405 DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); |
408 char *user = repo->user; |
|
409 char *password = repo->password; |
|
410 if(repo->stored_user) { |
|
411 PwdStore *pstore = get_pwdstore(); |
|
412 if(pstore) { |
|
413 char *ps_password = util_password_input("Unlock password store: "); |
|
414 if(ps_password) { |
|
415 if(!pwdstore_setpassword(pstore, ps_password)) { |
|
416 if(!pwdstore_decrypt(pstore)) { |
|
417 PwdEntry *stored_user = pwdstore_get(pstore, repo->stored_user); |
|
418 if(stored_user) { |
|
419 user = stored_user->user; |
|
420 password = stored_user->password; |
|
421 } else { |
|
422 fprintf(stderr, "Error: stored user '%s' not found\n", repo->stored_user); |
|
423 } |
|
424 } else { |
|
425 fprintf(stderr, "Error: cannot decrypt password store\n"); |
|
426 } |
|
427 } else { |
|
428 fprintf(stderr, "Error: cannot create key from password\n"); |
|
429 } |
|
430 } |
|
431 } else { |
|
432 fprintf(stderr, "Error: no password store available\n"); |
|
433 } |
|
434 } |
|
435 |
|
436 DavSession *sn = dav_session_new_auth(ctx, repo->url, user, password); |
406 sn->flags = get_repository_flags(repo); |
437 sn->flags = get_repository_flags(repo); |
407 sn->key = dav_context_get_key(ctx, repo->default_key); |
438 sn->key = dav_context_get_key(ctx, repo->default_key); |
408 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
439 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
409 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
440 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
410 if(repo->cert) { |
441 if(repo->cert) { |
2027 putchar('\n'); |
2058 putchar('\n'); |
2028 } else { |
2059 } else { |
2029 fprintf(stderr, "Repository %s does not exist.\n", reponame.ptr); |
2060 fprintf(stderr, "Repository %s does not exist.\n", reponame.ptr); |
2030 return -1; |
2061 return -1; |
2031 } |
2062 } |
|
2063 } |
|
2064 |
|
2065 int cmd_add_user(CmdArgs *args) { |
|
2066 char *user = assistant_getcfg("User"); |
|
2067 char *password = util_password_input("Password: "); |
|
2068 if(user && password) { |
|
2069 PwdStore *pstore = get_pwdstore(); |
|
2070 if(!pstore) { |
|
2071 pstore = pwdstore_new(); |
|
2072 } |
|
2073 pwdstore_put(pstore, user, password); |
|
2074 char *master_pw = util_password_input("Master password: "); |
|
2075 if(!master_pw) { |
|
2076 return 1; |
|
2077 } |
|
2078 if(pwdstore_setpassword(pstore, master_pw)) { |
|
2079 fprintf(stderr, "Error: Cannot generate key from password.\nAbort.\n"); |
|
2080 return 1; |
|
2081 } |
|
2082 int ret = pwdstore_save(pstore); |
|
2083 if(ret) { |
|
2084 fprintf(stderr, "Error: saving password store failed.\n"); |
|
2085 } |
|
2086 return ret; |
|
2087 } |
|
2088 return 1; |
2032 } |
2089 } |
2033 |
2090 |
2034 |
2091 |
2035 int shell_completion(CmdArgs *args, int index) { |
2092 int shell_completion(CmdArgs *args, int index) { |
2036 if(args->argc < 2 || args->argc < 3) { |
2093 if(args->argc < 2 || args->argc < 3) { |