File rgfs.c changed (mode: 100644) (index b6c9e23..0040171) |
25 |
25 |
|
|
26 |
26 |
// a way to distinguish between clients |
// a way to distinguish between clients |
27 |
27 |
static char *rgfs_name = "unk"; |
static char *rgfs_name = "unk"; |
28 |
|
static unsigned int rgfs_pkg_repo_id = 0; |
|
|
28 |
|
static char *rgfs_pkg_repo_id = ""; |
|
29 |
|
static char *rgfs_pkg_subrepo_id = ""; |
29 |
30 |
static char *rgfs_key = ""; |
static char *rgfs_key = ""; |
30 |
31 |
static int rgfs_port = 443; |
static int rgfs_port = 443; |
31 |
32 |
static char *rgfs_server = "rgfs.rocketgit.com"; |
static char *rgfs_server = "rgfs.rocketgit.com"; |
|
... |
... |
static ssize_t rgfs_send(const char *op, const void *buf, size_t buf_len) |
97 |
98 |
|
|
98 |
99 |
if (rgfs_debug > 10) { |
if (rgfs_debug > 10) { |
99 |
100 |
char debug[4096 * 2 + 1]; |
char debug[4096 * 2 + 1]; |
100 |
|
short max = buf_len > 4096 ? 4096 : buf_len; |
|
101 |
|
for (unsigned int i = 0; i < max; i++) |
|
|
101 |
|
|
|
102 |
|
uint16_t max = buf_len > 4096 ? 4096 : buf_len; |
|
103 |
|
for (uint16_t i = 0; i < max; i++) |
102 |
104 |
sprintf(debug + i * 2, "%02hhx", * (unsigned char *) (buf + i)); |
sprintf(debug + i * 2, "%02hhx", * (unsigned char *) (buf + i)); |
103 |
105 |
xlog(" %s: SEND %u: %s\n", op, buf_len, debug); |
xlog(" %s: SEND %u: %s\n", op, buf_len, debug); |
104 |
106 |
} |
} |
|
... |
... |
static int rgfs_tls(void) |
227 |
229 |
int r, ret = -1, off; |
int r, ret = -1, off; |
228 |
230 |
char buf[8192], *desc; |
char buf[8192], *desc; |
229 |
231 |
int type; |
int type; |
230 |
|
unsigned status, len; |
|
|
232 |
|
unsigned status; |
231 |
233 |
|
|
232 |
234 |
do { |
do { |
233 |
235 |
/* Destroy session */ |
/* Destroy session */ |
|
... |
... |
static int rgfs_tls(void) |
328 |
330 |
break; |
break; |
329 |
331 |
} |
} |
330 |
332 |
|
|
331 |
|
xlog("Sending version...\n"); |
|
332 |
|
buf[0] = 0x01; // type=SEND_VERSION |
|
333 |
|
buf[1] = 0; // len H |
|
334 |
|
buf[2] = 1; // len L |
|
335 |
|
buf[3] = RGFS_PROTOCOL_VERSION; |
|
336 |
|
r = rgfs_send("send ver", buf, 4); |
|
|
333 |
|
r = rgfs_send_gen_var("ver", RGFS_PROTOCOL_VERSION); |
337 |
334 |
if (r <= 0) |
if (r <= 0) |
338 |
335 |
break; |
break; |
339 |
336 |
|
|
340 |
|
xlog("Receiving version...\n"); |
|
341 |
|
r = rgfs_recv(buf, sizeof(buf)); |
|
342 |
|
if (r <= 0) |
|
343 |
|
break; |
|
344 |
|
xlog("Server version: %hhu.\n", buf[4]); |
|
345 |
|
|
|
346 |
|
xlog("Sending name...\n"); |
|
347 |
|
len = strlen(rgfs_name); |
|
348 |
|
buf[0] = 0xFE; // type=SEND_NAME |
|
349 |
|
buf[1] = len >> 8; // len H |
|
350 |
|
buf[2] = len; // len L |
|
351 |
|
memcpy(buf + 3, rgfs_name, len); |
|
352 |
|
r = rgfs_send("name", buf, 3 + len); |
|
|
337 |
|
r = rgfs_send_gen_var("name", rgfs_name); |
353 |
338 |
if (r <= 0) |
if (r <= 0) |
354 |
339 |
break; |
break; |
355 |
340 |
|
|
356 |
|
xlog("Sending pkg_repo_id and key...\n"); |
|
357 |
|
len = strlen(rgfs_key); |
|
358 |
|
buf[0] = 0xFF; // type=SEND_KEY |
|
359 |
|
buf[1] = (4 + len) >> 8; // len H |
|
360 |
|
buf[2] = 4 + len; // len L |
|
361 |
|
buf[3] = rgfs_pkg_repo_id >> 24; |
|
362 |
|
buf[4] = rgfs_pkg_repo_id >> 16; |
|
363 |
|
buf[5] = rgfs_pkg_repo_id >> 8; |
|
364 |
|
buf[6] = rgfs_pkg_repo_id; |
|
365 |
|
memcpy(buf + 7, rgfs_key, len); |
|
366 |
|
r = rgfs_send("repo&key", buf, 7 + len); |
|
367 |
|
if (r <= 0) |
|
368 |
|
break; |
|
|
341 |
|
if (rgfs_pkg_repo_id) { |
|
342 |
|
r = rgfs_send_gen_var("pkg_repo_id", rgfs_pkg_repo_id); |
|
343 |
|
if (r <= 0) |
|
344 |
|
break; |
|
345 |
|
} |
369 |
346 |
|
|
370 |
|
xlog("Receiving send_key confirmation...\n"); |
|
371 |
|
r = rgfs_recv(buf, sizeof(buf)); |
|
372 |
|
if (r <= 0) |
|
373 |
|
break; |
|
374 |
|
if ((r < 5) || (buf[4] != 0x00)) { |
|
375 |
|
xlog("Buffer too small (%d/5) or buf[4] != 0 (0x%02hhx)!", r, buf[4]); |
|
376 |
|
ret = 1; |
|
377 |
|
break; |
|
|
347 |
|
if (rgfs_pkg_subrepo_id) { |
|
348 |
|
r = rgfs_send_gen_var("pkg_subrepo_id", rgfs_pkg_subrepo_id); |
|
349 |
|
if (r <= 0) |
|
350 |
|
break; |
|
351 |
|
} |
|
352 |
|
|
|
353 |
|
if (rgfs_key) { |
|
354 |
|
r = rgfs_send_gen_var("key", rgfs_key); |
|
355 |
|
if (r <= 0) |
|
356 |
|
break; |
378 |
357 |
} |
} |
379 |
358 |
|
|
380 |
359 |
if (rgfs_uid) { |
if (rgfs_uid) { |
|
... |
... |
static int rgfs_recv_hl(const char *op, void *buf, size_t buf_size) |
453 |
432 |
|
|
454 |
433 |
if (rgfs_debug > 10) { |
if (rgfs_debug > 10) { |
455 |
434 |
char debug[4096 * 2 + 1]; |
char debug[4096 * 2 + 1]; |
456 |
|
short max = off > 4096 ? 4096 : off; |
|
457 |
|
for (unsigned int i = 0; i < max; i++) |
|
|
435 |
|
uint16_t max = off > 4096 ? 4096 : off; |
|
436 |
|
for (uint16_t i = 0; i < max; i++) |
458 |
437 |
sprintf(debug + i * 2, "%02hhx", * (unsigned char *) (buf + i)); |
sprintf(debug + i * 2, "%02hhx", * (unsigned char *) (buf + i)); |
459 |
438 |
xlog(" %s: RECV %u: %s\n", op, off, debug); |
xlog(" %s: RECV %u: %s\n", op, off, debug); |
460 |
439 |
} |
} |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
636 |
615 |
size = sizeof(buf) - 1 - 4; |
size = sizeof(buf) - 1 - 4; |
637 |
616 |
|
|
638 |
617 |
path_len = strlen(path); |
path_len = strlen(path); |
639 |
|
len = 1 + 2 + 8 + 8 + path_len; |
|
640 |
|
if (len > sizeof(buf)) { |
|
|
618 |
|
len = 1 + 2 + 8 + 8; |
|
619 |
|
if (path_len > sizeof(buf) - len) { |
641 |
620 |
xlog(" buffer too small\n"); |
xlog(" buffer too small\n"); |
642 |
621 |
return -EIO; |
return -EIO; |
643 |
622 |
} |
} |
|
623 |
|
len += path_len; |
644 |
624 |
|
|
645 |
625 |
i = 0; |
i = 0; |
646 |
626 |
buf[i++] = 0x04; |
buf[i++] = 0x04; |
|
... |
... |
int main(int argc, char *argv[]) |
1254 |
1234 |
|
|
1255 |
1235 |
s = getenv("RGFS_PKG_REPO_ID"); |
s = getenv("RGFS_PKG_REPO_ID"); |
1256 |
1236 |
if (s) |
if (s) |
1257 |
|
rgfs_pkg_repo_id = atol(s); |
|
|
1237 |
|
rgfs_pkg_repo_id = s; |
|
1238 |
|
|
|
1239 |
|
s = getenv("RGFS_PKG_SUBREPO_ID"); |
|
1240 |
|
if (s) |
|
1241 |
|
rgfs_pkg_subrepo_id = s; |
1258 |
1242 |
|
|
1259 |
1243 |
s = getenv("RGFS_KEY"); |
s = getenv("RGFS_KEY"); |
1260 |
1244 |
if (s) |
if (s) |
|
... |
... |
int main(int argc, char *argv[]) |
1299 |
1283 |
if (s) |
if (s) |
1300 |
1284 |
rgfs_job_id = s; |
rgfs_job_id = s; |
1301 |
1285 |
|
|
1302 |
|
xlog("name=%s server=%s port=%d url=%s pkg_repo_id=%u uid=%s repo_id=%s" |
|
1303 |
|
" head=%s job_id=%s\n", |
|
|
1286 |
|
xlog("name=%s server=%s port=%d url=%s pkg_repo_id=%s pkg_subrepo_id=%s" |
|
1287 |
|
" uid=%s repo_id=%s head=%s job_id=%s\n", |
1304 |
1288 |
rgfs_name, rgfs_server, rgfs_port, rgfs_url, rgfs_pkg_repo_id, |
rgfs_name, rgfs_server, rgfs_port, rgfs_url, rgfs_pkg_repo_id, |
|
1289 |
|
rgfs_pkg_subrepo_id, |
1305 |
1290 |
rgfs_uid, rgfs_repo_id, rgfs_head, rgfs_job_id); |
rgfs_uid, rgfs_repo_id, rgfs_head, rgfs_job_id); |
1306 |
1291 |
|
|
1307 |
1292 |
if (gnutls_check_version("3.4.6") == NULL) { |
if (gnutls_check_version("3.4.6") == NULL) { |