1122 static int file_seek(FILE *f, curl_off_t offset, int origin) { |
1122 static int file_seek(FILE *f, curl_off_t offset, int origin) { |
1123 int ret = fseek(f, offset, origin); |
1123 int ret = fseek(f, offset, origin); |
1124 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
1124 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
1125 } |
1125 } |
1126 |
1126 |
|
1127 static int check_encryption_key(CmdArgs *a, DavSession *sn) { |
|
1128 // override the session key if the -k option is specified |
|
1129 char *keyname = cmd_getoption(a, "key"); |
|
1130 if(keyname) { |
|
1131 DavKey *key = dav_context_get_key(ctx, keyname); |
|
1132 if(key) { |
|
1133 sn->key = key; |
|
1134 } else { |
|
1135 fprintf(stderr, "Key %s not found!\nAbort.\n", keyname); |
|
1136 return 1; |
|
1137 } |
|
1138 |
|
1139 /* |
|
1140 * If a key is explicitly specified, we can safely assume that the user |
|
1141 * wants to encrypt. For security reasons we report an error, if no |
|
1142 * encryption is enabled. |
|
1143 */ |
|
1144 if(!DAV_IS_ENCRYPTED(sn)) { |
|
1145 fprintf(stderr, "A key has been explicitly specified, but no " |
|
1146 "encryption is requested.\n" |
|
1147 "You have the following options:\n" |
|
1148 " - pass '-c' as command line argument to request encryption\n" |
|
1149 " - activate encryption in the config.xml\n" |
|
1150 " - don't use '-k <key>' " |
|
1151 "(warning: encryption will NOT happen)\n"); |
|
1152 return 1; |
|
1153 } |
|
1154 } |
|
1155 |
|
1156 // if encryption is requested, but we still don't know the key, report error |
|
1157 if(DAV_IS_ENCRYPTED(sn) && !(sn->key)) { |
|
1158 fprintf(stderr, "Encryption has been requested, " |
|
1159 "but no default key is configured.\n" |
|
1160 "You may specify a custom key with the '-k' option.\n"); |
|
1161 return 1; |
|
1162 } |
|
1163 |
|
1164 return 0; |
|
1165 } |
|
1166 |
1127 int cmd_edit(CmdArgs *a) { |
1167 int cmd_edit(CmdArgs *a) { |
1128 if(a->argc != 1) { |
1168 if(a->argc != 1) { |
1129 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
1169 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
1130 fprintf(stderr, "Usage: dav %s\n", find_usage_str("edit")); |
1170 fprintf(stderr, "Usage: dav %s\n", find_usage_str("edit")); |
1131 return -1; |
1171 return -1; |
1135 char *path = NULL; |
1175 char *path = NULL; |
1136 Repository *repo = url2repo(url, &path); |
1176 Repository *repo = url2repo(url, &path); |
1137 DavSession *sn = connect_to_repo(repo, path, a); |
1177 DavSession *sn = connect_to_repo(repo, path, a); |
1138 |
1178 |
1139 if(set_session_config(sn, a)) { |
1179 if(set_session_config(sn, a)) { |
|
1180 return -1; |
|
1181 } |
|
1182 // TODO: implement locking feature |
|
1183 |
|
1184 if(check_encryption_key(a, sn)) { |
1140 return -1; |
1185 return -1; |
1141 } |
1186 } |
1142 |
1187 |
1143 char *version = cmd_getoption(a, "version"); |
1188 char *version = cmd_getoption(a, "version"); |
1144 DavResource *res; |
1189 DavResource *res; |
1354 // download content |
1399 // download content |
1355 |
1400 |
1356 return tar_end_file(tar); |
1401 return tar_end_file(tar); |
1357 } |
1402 } |
1358 |
1403 |
1359 static int check_encryption_key(CmdArgs *a, DavSession *sn) { |
|
1360 // override the session key if the -k option is specified |
|
1361 char *keyname = cmd_getoption(a, "key"); |
|
1362 if(keyname) { |
|
1363 DavKey *key = dav_context_get_key(ctx, keyname); |
|
1364 if(key) { |
|
1365 sn->key = key; |
|
1366 } else { |
|
1367 fprintf(stderr, "Key %s not found!\nAbort.\n", keyname); |
|
1368 return 1; |
|
1369 } |
|
1370 |
|
1371 /* |
|
1372 * If a key is explicitly specified, we can safely assume that the user |
|
1373 * wants to encrypt. For security reasons we report an error, if no |
|
1374 * encryption is enabled. |
|
1375 */ |
|
1376 if(!DAV_IS_ENCRYPTED(sn)) { |
|
1377 fprintf(stderr, "A key has been explicitly specified, but no " |
|
1378 "encryption is requested.\n" |
|
1379 "You have the following options:\n" |
|
1380 " - pass '-c' as command line argument to request encryption\n" |
|
1381 " - activate encryption in the config.xml\n" |
|
1382 " - don't use '-k <key>' " |
|
1383 "(warning: encryption will NOT happen)\n"); |
|
1384 return 1; |
|
1385 } |
|
1386 } |
|
1387 |
|
1388 // if encryption is requested, but we still don't know the key, report error |
|
1389 if(DAV_IS_ENCRYPTED(sn) && !(sn->key)) { |
|
1390 fprintf(stderr, "Encryption has been requested, " |
|
1391 "but no default key is configured.\n" |
|
1392 "You may specify a custom key with the '-k' option.\n"); |
|
1393 return 1; |
|
1394 } |
|
1395 |
|
1396 return 0; |
|
1397 } |
|
1398 |
|
1399 int cmd_put(CmdArgs *a, DavBool import) { |
1404 int cmd_put(CmdArgs *a, DavBool import) { |
1400 if(a->argc < 2) { |
1405 if(a->argc < 2) { |
1401 fprintf(stderr, "Too few arguments\n"); |
1406 fprintf(stderr, "Too few arguments\n"); |
1402 fprintf(stderr, |
1407 fprintf(stderr, |
1403 "Usage: dav %s\n", |
1408 "Usage: dav %s\n", |