Skip to content

Commit edb7225

Browse files
committed
casync: propagate --trust-peer option to helpers
Currently, casync-http handles the option --trust-peer but casync does not propagate it to its protocol helpers. This commit propagates the --trust-peer the protocol helpers as it is done for option --rate-limit-bps.
1 parent 3907d67 commit edb7225

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

doc/casync.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ General options:
166166
--rate-limit-bps=<LIMIT> Maximum bandwidth in bytes/s for remote communication
167167
--max-active-chunks=<MAX> Maximum number of simultaneously active chunks for remote communication
168168
--max-host-connections=<MAX> Maximum number of connections to a single host for remote communication
169+
--ssl-trust-peer Trust the peer's SSL certificate
169170
--exclude-nodump=no Don't exclude files with chattr(1)'s +d **nodump** flag when creating archive
170171
--exclude-submounts=yes Exclude submounts when creating archive
171172
--exclude-file=no Don't respect .caexclude files in the file tree

src/caremote.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct CaRemote {
6262
uint64_t rate_limit_bps;
6363
unsigned max_active_chunks;
6464
unsigned max_host_connections;
65+
bool ssl_trust_peer;
6566

6667
ReallocBuffer input_buffer;
6768
ReallocBuffer output_buffer;
@@ -268,6 +269,15 @@ int ca_remote_set_max_host_connections(CaRemote *rr, unsigned max_host_connectio
268269
return 0;
269270
}
270271

272+
int ca_remote_set_ssl_trust_peer(CaRemote *rr, bool ssl_trust_peer) {
273+
if (!rr)
274+
return -EINVAL;
275+
276+
rr->ssl_trust_peer = ssl_trust_peer;
277+
278+
return 0;
279+
}
280+
271281
int ca_remote_set_local_feature_flags(CaRemote *rr, uint64_t flags) {
272282
if (!rr)
273283
return -EINVAL;
@@ -1027,6 +1037,9 @@ static int ca_remote_start(CaRemote *rr) {
10271037
if (rr->max_host_connections)
10281038
argc++;
10291039

1040+
if (rr->ssl_trust_peer)
1041+
argc++;
1042+
10301043
args = newa(char*, argc + 1);
10311044

10321045
if (rr->callout) {
@@ -1088,6 +1101,9 @@ static int ca_remote_start(CaRemote *rr) {
10881101
i++;
10891102
}
10901103

1104+
if (rr->ssl_trust_peer)
1105+
args[i++] = (char*) "--ssl-trust-peer";
1106+
10911107
args[i + CA_REMOTE_ARG_OPERATION] = (char*) ((rr->local_feature_flags & (CA_PROTOCOL_PUSH_CHUNKS|CA_PROTOCOL_PUSH_INDEX|CA_PROTOCOL_PUSH_ARCHIVE)) ? "push" : "pull");
10921108
args[i + CA_REMOTE_ARG_BASE_URL] = /* rr->base_url ? rr->base_url + skip :*/ (char*) "-";
10931109
args[i + CA_REMOTE_ARG_ARCHIVE_URL] = rr->archive_url ? rr->archive_url + skip : (char*) "-";

src/caremote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int ca_remote_set_log_level(CaRemote *rr, int log_level);
5454
int ca_remote_set_rate_limit_bps(CaRemote *rr, uint64_t rate_limit_bps);
5555
int ca_remote_set_max_active_chunks(CaRemote *rr, unsigned max_active_chunks);
5656
int ca_remote_set_max_host_connections(CaRemote *rr, unsigned max_max_connections);
57+
int ca_remote_set_ssl_trust_peer(CaRemote *rr, bool ssl_trust_peer);
5758

5859
int ca_remote_set_io_fds(CaRemote *rr, int input_fd, int output_fd);
5960
int ca_remote_get_io_fds(CaRemote *rr, int *ret_input_fd, int *ret_output_fd);

src/casync-tool.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static size_t arg_chunk_size_max = 0;
6868
static uint64_t arg_rate_limit_bps = UINT64_MAX;
6969
static unsigned arg_max_active_chunks = 0;
7070
static unsigned arg_max_host_connections = 0;
71+
static bool arg_ssl_trust_peer = false;
7172
static uint64_t arg_with = 0;
7273
static uint64_t arg_without = 0;
7374
static uid_t arg_uid_shift = 0, arg_uid_range = 0x10000U;
@@ -114,6 +115,7 @@ static void help(void) {
114115
" --max-host-connections=MAX\n"
115116
" Maximum number of connections to a single host for\n"
116117
" remote communication\n"
118+
" --ssl-trust-peer Trust the peer's SSL certificate\n"
117119
" --exclude-nodump=no Don't exclude files with chattr(1)'s +d 'nodump'\n"
118120
" flag when creating archive\n"
119121
" --exclude-submounts=yes Exclude submounts when creating archive\n"
@@ -337,6 +339,7 @@ static int parse_argv(int argc, char *argv[]) {
337339
ARG_RATE_LIMIT_BPS,
338340
ARG_MAX_ACTIVE_CHUNKS,
339341
ARG_MAX_HOST_CONNECTIONS,
342+
ARG_SSL_TRUST_PEER,
340343
ARG_WITH,
341344
ARG_WITHOUT,
342345
ARG_WHAT,
@@ -373,6 +376,7 @@ static int parse_argv(int argc, char *argv[]) {
373376
{ "rate-limit-bps", required_argument, NULL, ARG_RATE_LIMIT_BPS },
374377
{ "max-active-chunks", required_argument, NULL, ARG_MAX_ACTIVE_CHUNKS },
375378
{ "max-host-connections", required_argument, NULL, ARG_MAX_HOST_CONNECTIONS },
379+
{ "ssl-trust-peer", no_argument, NULL, ARG_SSL_TRUST_PEER },
376380
{ "with", required_argument, NULL, ARG_WITH },
377381
{ "without", required_argument, NULL, ARG_WITHOUT },
378382
{ "what", required_argument, NULL, ARG_WHAT },
@@ -502,6 +506,10 @@ static int parse_argv(int argc, char *argv[]) {
502506
}
503507
break;
504508

509+
case ARG_SSL_TRUST_PEER:
510+
arg_ssl_trust_peer = true;
511+
break;
512+
505513
case ARG_WITH: {
506514
uint64_t u;
507515

@@ -1369,6 +1377,12 @@ static int verb_make(int argc, char *argv[]) {
13691377
return log_error_errno(r, "Failed to set max host connections: %m");
13701378
}
13711379

1380+
if (arg_ssl_trust_peer) {
1381+
r = ca_sync_set_ssl_trust_peer(s, arg_ssl_trust_peer);
1382+
if (r < 0)
1383+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
1384+
}
1385+
13721386
r = ca_sync_set_base_fd(s, input_fd);
13731387
if (r < 0)
13741388
return log_error_errno(r, "Failed to set sync base: %m");
@@ -1686,6 +1700,12 @@ static int verb_extract(int argc, char *argv[]) {
16861700
return log_error_errno(r, "Failed to set max host connections: %m");
16871701
}
16881702

1703+
if (arg_ssl_trust_peer) {
1704+
r = ca_sync_set_ssl_trust_peer(s, arg_ssl_trust_peer);
1705+
if (r < 0)
1706+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
1707+
}
1708+
16891709
if (seek_path) {
16901710
if (output_fd >= 0)
16911711
r = ca_sync_set_boundary_fd(s, output_fd);
@@ -2859,6 +2879,12 @@ static int verb_mount(int argc, char *argv[]) {
28592879
return log_error_errno(r, "Failed to set max host connections: %m");
28602880
}
28612881

2882+
if (arg_ssl_trust_peer) {
2883+
r = ca_sync_set_ssl_trust_peer(s, arg_ssl_trust_peer);
2884+
if (r < 0)
2885+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
2886+
}
2887+
28622888
if (operation == MOUNT_ARCHIVE) {
28632889
if (input_fd >= 0)
28642890
r = ca_sync_set_archive_fd(s, input_fd);
@@ -2997,6 +3023,12 @@ static int verb_mkdev(int argc, char *argv[]) {
29973023
return log_error_errno(r, "Failed to set max host connections: %m");
29983024
}
29993025

3026+
if (arg_ssl_trust_peer) {
3027+
r = ca_sync_set_ssl_trust_peer(s, arg_ssl_trust_peer);
3028+
if (r < 0)
3029+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
3030+
}
3031+
30003032
if (operation == MKDEV_BLOB) {
30013033
if (input_fd >= 0)
30023034
r = ca_sync_set_archive_fd(s, input_fd);
@@ -3576,6 +3608,12 @@ static int verb_pull(int argc, char *argv[]) {
35763608
return log_error_errno(r, "Failed to set max host connections: %m");
35773609
}
35783610

3611+
if (arg_ssl_trust_peer) {
3612+
r = ca_remote_set_ssl_trust_peer(rr, arg_ssl_trust_peer);
3613+
if (r < 0)
3614+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
3615+
}
3616+
35793617
r = ca_remote_set_io_fds(rr, STDIN_FILENO, STDOUT_FILENO);
35803618
if (r < 0)
35813619
return log_error_errno(r, "Failed to set I/O file descriptors: %m");
@@ -3747,6 +3785,12 @@ static int verb_push(int argc, char *argv[]) {
37473785
return log_error_errno(r, "Failed to set max host connections: %m");
37483786
}
37493787

3788+
if (arg_ssl_trust_peer) {
3789+
r = ca_remote_set_ssl_trust_peer(rr, arg_ssl_trust_peer);
3790+
if (r < 0)
3791+
return log_error_errno(r, "Failed to set SSL trust peer: %m");
3792+
}
3793+
37503794
r = ca_remote_set_io_fds(rr, STDIN_FILENO, STDOUT_FILENO);
37513795
if (r < 0)
37523796
log_error_errno(r, "Failed to set I/O file descriptors: %m");

src/casync.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct CaSync {
114114
size_t rate_limit_bps;
115115
unsigned max_active_chunks;
116116
unsigned max_host_connections;
117+
bool ssl_trust_peer;
117118

118119
uint64_t feature_flags;
119120
uint64_t feature_flags_mask;
@@ -542,6 +543,15 @@ int ca_sync_set_max_host_connections(CaSync *s, unsigned max_host_connections) {
542543
return 0;
543544
}
544545

546+
int ca_sync_set_ssl_trust_peer(CaSync *s, bool ssl_trust_peer) {
547+
if (!s)
548+
return -EINVAL;
549+
550+
s->ssl_trust_peer = ssl_trust_peer;
551+
552+
return 0;
553+
}
554+
545555
int ca_sync_set_rate_limit_bps(CaSync *s, uint64_t rate_limit_bps) {
546556
if (!s)
547557
return -EINVAL;

src/casync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int ca_sync_set_log_level(CaSync *s, int log_level);
3535
int ca_sync_set_rate_limit_bps(CaSync *s, uint64_t rate_limit_bps);
3636
int ca_sync_set_max_active_chunks(CaSync *s, unsigned max_active_chunks);
3737
int ca_sync_set_max_host_connections(CaSync *s, unsigned max_host_connection);
38+
int ca_sync_set_ssl_trust_peer(CaSync *s, bool ssl_trust_peer);
3839

3940
int ca_sync_set_feature_flags(CaSync *s, uint64_t flags);
4041
int ca_sync_get_feature_flags(CaSync *s, uint64_t *ret);

0 commit comments

Comments
 (0)