aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2015-05-15 10:25:18 +0200
committerBjørn Mork <bjorn@mork.no>2015-05-15 10:25:18 +0200
commitb1b227fa5e00d08af047ab9a012211b66c6b0f13 (patch)
tree5d891e417ab726a2627dccc40586c43f64b87e55 /networking
parentc9c35747c0d20cff54561c0b8fe15813c7a8e0ff (diff)
ripe-atlas-fw: imported version 46104610
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Diffstat (limited to 'networking')
-rw-r--r--networking/httppost.c61
-rw-r--r--networking/sslgetcert.c13
-rw-r--r--networking/telnetd.c31
3 files changed, 70 insertions, 35 deletions
diff --git a/networking/httppost.c b/networking/httppost.c
index 6b8b533..24f1430 100644
--- a/networking/httppost.c
+++ b/networking/httppost.c
@@ -50,6 +50,7 @@ char *do_dir(char *dir_name, off_t curr_size, off_t max_size, off_t *lenp);
static int copy_chunked(FILE *in_file, FILE *out_file, int *found_okp);
static int copy_bytes(FILE *in_file, FILE *out_file, size_t len,
int *found_okp);
+static int copy_all(FILE *in_file, FILE *out_file, int *found_okp);
static void fatal(const char *fmt, ...);
// static void fatal_err(const char *fmt, ...);
static void report(const char *fmt, ...);
@@ -398,6 +399,7 @@ int httppost_main(int argc, char *argv[])
goto err;
fprintf(stderr, "httppost: getting reply headers \n");
server_time= 0;
+ content_length= -1;
if (!eat_headers(tcp_file, &chunked, &content_length, &server_time))
goto err;
@@ -464,16 +466,24 @@ int httppost_main(int argc, char *argv[])
else
out_file= stdout;
+ fprintf(stderr, "httppost: chunked %d, content_length %d\n",
+ chunked, content_length);
+ found_ok= 0;
if (chunked)
{
if (!copy_chunked(tcp_file, out_file, &found_ok))
goto err;
}
- else if (content_length)
+ else if (content_length >= 0)
{
if (!copy_bytes(tcp_file, out_file, content_length, &found_ok))
goto err;
}
+ else
+ {
+ if (!copy_all(tcp_file, out_file, &found_ok))
+ goto err;
+ }
if (!found_ok)
fprintf(stderr, "httppost: reply text was not equal to OK\n");
if ( opt_delete_file == 1 && found_ok)
@@ -764,7 +774,6 @@ static int eat_headers(FILE *tcp_file, int *chunked, int *content_length, time_t
char buffer[1024];
*chunked= 0;
- *content_length= 0;
while (fgets(buffer, sizeof(buffer), tcp_file) != NULL)
{
line= buffer;
@@ -1086,6 +1095,8 @@ static int copy_chunked(FILE *in_file, FILE *out_file, int *found_okp)
}
offset += size;
+ fprintf(stderr, "httppost: chunk data '%.*s'\n",
+ (int)size, buffer);
for (i= 0; i<size; i++)
{
if (!okp)
@@ -1179,6 +1190,9 @@ static int copy_bytes(FILE *in_file, FILE *out_file, size_t len, int *found_okp)
}
offset += size;
+ fprintf(stderr, "httppost: normal data '%.*s'\n",
+ (int)size, buffer);
+
for (i= 0; i<size; i++)
{
if (!okp)
@@ -1195,6 +1209,49 @@ static int copy_bytes(FILE *in_file, FILE *out_file, size_t len, int *found_okp)
return 1;
}
+static int copy_all(FILE *in_file, FILE *out_file, int *found_okp)
+{
+ int i, size;
+ const char *okp;
+ char buffer[1024];
+
+ okp= OK_STR;
+
+ while (!feof(in_file) && !ferror(in_file))
+ {
+ size= fread(buffer, 1, sizeof(buffer), in_file);
+ if (size <= 0)
+ break;
+ if (fwrite(buffer, size, 1, out_file) != 1)
+ {
+ report_err("error writing output");
+ return 0;
+ }
+
+ fprintf(stderr, "httppost: all data '%.*s'\n",
+ (int)size, buffer);
+
+ for (i= 0; i<size; i++)
+ {
+ if (!okp)
+ break;
+ if (*okp != buffer[i] || *okp == '\0')
+ {
+ okp= NULL;
+ break;
+ }
+ okp++;
+ }
+ }
+ if (ferror(in_file))
+ {
+ report_err("error reading input");
+ return 0;
+ }
+ *found_okp= (okp != NULL && *okp == '\0');
+ return 1;
+}
+
static void skip_spaces(const char *cp, char **ncp)
{
const unsigned char *ucp;
diff --git a/networking/sslgetcert.c b/networking/sslgetcert.c
index a0fbf3c..a443b32 100644
--- a/networking/sslgetcert.c
+++ b/networking/sslgetcert.c
@@ -548,7 +548,7 @@ static int Xeat_server_hello(struct msgbuf *msgbuf)
static int Xeat_certificate(struct msgbuf *msgbuf)
{
- int i, n, r, first, slen;
+ int i, n, r, first, slen, need_nl;
size_t o, len;
uint8_t *p;
struct buf tmpbuf;
@@ -597,14 +597,23 @@ static int Xeat_certificate(struct msgbuf *msgbuf)
buf_add_b64(&tmpbuf, p+o+3, slen);
printf("%s\"-----BEGIN CERTIFICATE-----\\n",
!first ? ", " : "");
+ need_nl=0;
for (i= tmpbuf.offset; i<tmpbuf.size; i++)
{
if (tmpbuf.buf[i] == '\n')
+ {
fputs("\\n", stdout);
+ need_nl=0;
+ }
else
+ {
putchar(tmpbuf.buf[i]);
+ need_nl=1;
+ }
}
- printf("\\n-----END CERTIFICATE-----\"");
+ if (need_nl)
+ fputs("\\n", stdout);
+ printf("-----END CERTIFICATE-----\"");
tmpbuf.size= tmpbuf.offset;
o += 3+slen;
first= 0;
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 03d6d27..778156c 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -115,7 +115,6 @@ static int start_crontab(struct tsession *ts, char *line);
static void add_to_crontab(struct tsession *ts, char *line);
static void end_crontab(struct tsession *ts);
static void do_oneoff(struct tsession *ts, char *line);
-static int get_probe_id(void);
int validate_filename(const char *path, const char *prefix);
#endif
@@ -1365,34 +1364,4 @@ static void do_oneoff(struct tsession *ts, char *line)
rename(filename_new, filename);
}
-static int get_probe_id(void)
-{
- int probe_id;
- size_t len;
- char *check;
- const char *key;
- FILE *fp;
- char buf[80];
-
- fp= fopen("/home/atlas/status/reg_init_reply.txt", "r");
- if (!fp)
- return -1;
-
- probe_id= -1;
- while (fgets(buf, sizeof(buf), fp) != NULL)
- {
- if (strchr(buf, '\n') == NULL)
- continue;
- key= "PROBE_ID ";
- len= strlen(key);
-
- if (strncmp(buf, key, len) != 0 || strlen(buf) <= len)
- continue;
- probe_id= strtol(buf+len, &check, 10);
- break;
- }
- fclose(fp);
- return probe_id;
-}
-
#endif /* ATLAS */