From 3dde9d53448c7a18a31d3ae8008106a801aaf101 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 8 Feb 2019 18:17:42 +0100 Subject: [PATCH] Onion Services should perfectly work now --- src/tor_ctl.c | 7 +++++-- src/tor_os.c | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tor_ctl.c b/src/tor_ctl.c index 51261be..d0fdda6 100644 --- a/src/tor_ctl.c +++ b/src/tor_ctl.c @@ -39,9 +39,12 @@ int tor_ctl_add_onion(struct tor_ctl* ctx, struct tor_os_str* tos, int* port) { for (int i = 0; i < tos->filled; i++) { fprintf(ctx->wsock, "add_onion %s Port=%d\n", tos->list[i], port[i]); fscanf(ctx->rsock, "%d", &err); - if (err != 250) return -1; + if (err != 250) { + printf("err: %d\n", err); + return -1; + } fscanf(ctx->rsock, "-ServiceID=%s", buffer); - printf("Added onion service %s from file", buffer); + printf("Added onion service %s from file\n", buffer); fscanf(ctx->rsock, "250 OK"); } diff --git a/src/tor_os.c b/src/tor_os.c index f57db39..effcef6 100644 --- a/src/tor_os.c +++ b/src/tor_os.c @@ -34,11 +34,17 @@ void tor_os_read (struct tor_os_str* os) { return; } size_t len = 0; + size_t str_len = 0; int n = 0; while (1) { char** dst = tor_os_append_cursor(os); if (dst == NULL) break; if (getline(dst,&len,fd) == -1) break; + str_len = strlen(*dst); + if (str_len < 1) break; + if ((*dst)[str_len - 1] == '\n') { + (*dst)[str_len - 1] = '\0'; + } } fclose(fd); } @@ -60,7 +66,6 @@ void tor_os_persist(struct tor_os_str* os) { } for (int i = 0; i < os->filled; i++) { - printf("%s\n", os->list[i]); fprintf(fd, "%s\n", os->list[i]); }