Sat, 15 Sep 2018 11:56:36 +0200
adds encrypted password store
new repo config element: <stored-user>
new dav command: add-user
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
364
3769ba002fd1
updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
33 | #include "sopt.h" |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | void cmd_args_free(CmdArgs *args) { |
219
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
36 | if(args) { |
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
37 | ucx_map_free(args->options); |
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
38 | free(args->argv); |
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
39 | free(args); |
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
40 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | CmdArgs* cmd_parse_args(int argc, char **argv) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | CmdArgs *a = malloc(sizeof(CmdArgs)); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | a->options = ucx_map_new(16); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | a->argv = calloc(argc, sizeof(char*)); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | a->argc = 0; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
49 | const char *NOARG = ""; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
50 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | char *option = NULL; |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
52 | char optchar = 0; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | for(int i=0;i<argc;i++) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | char *arg = argv[i]; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | size_t len = strlen(arg); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | if(len > 1 && arg[0] == '-') { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | for(int c=1;c<len;c++) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | switch(arg[c]) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | default: { |
219
9792cfe63b80
added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
60 | fprintf(stderr, "Unknown option -%c\n\n", arg[c]); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | cmd_args_free(a); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | return NULL; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | case 'c': { |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
65 | ucx_map_cstr_put(a->options, "conflict", NOARG); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | break; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
68 | case 'l': { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
69 | ucx_map_cstr_put(a->options, "lock", NOARG); |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
70 | break; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
71 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
72 | case 'd': { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
73 | ucx_map_cstr_put(a->options, "nolock", NOARG); |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
74 | break; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
75 | } |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
76 | case 'r': { |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
77 | ucx_map_cstr_put(a->options, "remove", NOARG); |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
78 | break; |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
79 | } |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
80 | case 'v': { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
53
diff
changeset
|
81 | ucx_map_cstr_put(a->options, "verbose", NOARG); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | break; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | } |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
84 | case 's': { |
443
2f019a4bc78a
fixes dav-sync -s option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
391
diff
changeset
|
85 | option = "syncdir"; |
2f019a4bc78a
fixes dav-sync -s option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
391
diff
changeset
|
86 | optchar = 's'; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
87 | break; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
364
diff
changeset
|
88 | } |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
89 | case 't': { |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
90 | option = "tags"; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
91 | optchar = 't'; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
92 | break; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
372
diff
changeset
|
93 | } |
445
c525f049c8b7
renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
94 | case 'R': { |
c525f049c8b7
renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
95 | ucx_map_cstr_put(a->options, "restore-removed", NOARG); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
96 | break; |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
97 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
98 | case 'M': { |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
99 | ucx_map_cstr_put(a->options, "restore-modified", NOARG); |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
100 | break; |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
443
diff
changeset
|
101 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | } else if(option) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | ucx_map_cstr_put(a->options, option, arg); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | option = NULL; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } else { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | a->argv[a->argc++] = arg; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | return a; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | char* cmd_getoption(CmdArgs *arg, char *name) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | return ucx_map_cstr_get(arg->options, name); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | } |