From 410f10096828e84b26c79155b43244702293d52b Mon Sep 17 00:00:00 2001 From: Jon Simons Date: Wed, 24 Apr 2019 09:01:36 -0700 Subject: [PATCH] tests/pkd: input test payload buffer Move the pkd test payload buffer into the arguments struct, to make way for parameterizing the payload using command-line options. Signed-off-by: Jon Simons Reviewed-by: Andreas Schneider --- tests/pkd/pkd_daemon.c | 6 +++--- tests/pkd/pkd_daemon.h | 5 +++++ tests/pkd/pkd_hello.c | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/pkd/pkd_daemon.c b/tests/pkd/pkd_daemon.c index c32c0636..29948d88 100644 --- a/tests/pkd/pkd_daemon.c +++ b/tests/pkd/pkd_daemon.c @@ -368,9 +368,9 @@ static int pkd_exec_hello(int fd, struct pkd_daemon_args *args) goto out; } - rc = ssh_channel_write(c, "hello\n", 6); /* XXX: customizable payloads */ - if (rc != 6) { - pkderr("ssh_channel_write partial (%d)\n", rc); + rc = ssh_channel_write(c, args->payload.buf, args->payload.len); + if (rc != args->payload.len) { + pkderr("ssh_channel_write partial (%d != %zd)\n", rc, args->payload.len); } rc = ssh_channel_request_send_exit_status(c, 0); diff --git a/tests/pkd/pkd_daemon.h b/tests/pkd/pkd_daemon.h index 3b37bc5d..ffc36c6c 100644 --- a/tests/pkd/pkd_daemon.h +++ b/tests/pkd/pkd_daemon.h @@ -23,6 +23,11 @@ struct pkd_daemon_args { enum pkd_hostkey_type_e type; const char *hostkeypath; + struct { + const uint8_t *buf; + size_t len; + } payload; + struct { int list; diff --git a/tests/pkd/pkd_hello.c b/tests/pkd/pkd_hello.c index f493703b..e7d36392 100644 --- a/tests/pkd/pkd_hello.c +++ b/tests/pkd/pkd_hello.c @@ -22,6 +22,12 @@ #define DEFAULT_ITERATIONS 10 static struct pkd_daemon_args pkd_dargs; +static uint8_t default_payload_buf[] = { + 'h', 'e', 'l', 'l', 'o', '\n', +}; + +static size_t default_payload_len = sizeof(default_payload_buf); + #ifdef HAVE_ARGP_H #include #define PROGNAME "pkd_hello" @@ -957,6 +963,9 @@ int main(int argc, char **argv) { unsetenv("SSH_AUTH_SOCK"); + pkd_dargs.payload.buf = default_payload_buf; + pkd_dargs.payload.len = default_payload_len; + rc = ssh_init(); if (rc != 0) { rc = SSH_ERROR;