diff options
author | Xiang Xiao <xiaoxiang@xiaomi.com> | 2021-05-08 00:26:24 -0700 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2021-05-12 16:01:18 +0200 |
commit | 9bff4cb9b9e2c91a288333abe509fddb7e2c7927 (patch) | |
tree | 832360be74b035d2bdd5913fbcca3358c2b504e4 /examples | |
parent | 43a31b81f20e5de401d5c0731bde7880367b0cec (diff) | |
download | libssh-9bff4cb9b9e2c91a288333abe509fddb7e2c7927.tar.gz libssh-9bff4cb9b9e2c91a288333abe509fddb7e2c7927.tar.xz libssh-9bff4cb9b9e2c91a288333abe509fddb7e2c7927.zip |
examples/ssh_server: Add -u and -P option
enable pass username and password from command line
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Change-Id: I6404b90a99253d3240f7a28827635b159ff6a574
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ssh_server_fork.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/examples/ssh_server_fork.c b/examples/ssh_server_fork.c index c9892d86..e0d0a764 100644 --- a/examples/ssh_server_fork.c +++ b/examples/ssh_server_fork.c @@ -48,8 +48,6 @@ The goal is to show the API in action. #endif #endif -#define USER "myuser" -#define PASS "mypassword" #define BUF_SIZE 1048576 #define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR) #define SFTP_SERVER_PATH "/usr/lib/sftp-server" @@ -75,6 +73,8 @@ static void set_default_keys(ssh_bind sshbind, } #define DEF_STR_SIZE 1024 char authorizedkeys[DEF_STR_SIZE] = {0}; +char username[128] = "myuser"; +char password[128] = "mypassword"; #ifdef HAVE_ARGP_H const char *argp_program_version = "libssh server example " SSH_STRINGIFY(LIBSSH_VERSION); @@ -138,6 +138,22 @@ static struct argp_option options[] = { .group = 0 }, { + .name = "user", + .key = 'u', + .arg = "USERNAME", + .flags = 0, + .doc = "Set expected username.", + .group = 0 + }, + { + .name = "pass", + .key = 'P', + .arg = "PASSWORD", + .flags = 0, + .doc = "Set expected password.", + .group = 0 + }, + { .name = "no-default-keys", .key = 'n', .arg = NULL, @@ -193,6 +209,12 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { case 'a': strncpy(authorizedkeys, arg, DEF_STR_SIZE-1); break; + case 'u': + strncpy(username, arg, sizeof(username) - 1); + break; + case 'P': + strncpy(password, arg, sizeof(password) - 1); + break; case 'v': ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3"); @@ -440,7 +462,7 @@ static int auth_password(ssh_session session, const char *user, (void) session; - if (strcmp(user, USER) == 0 && strcmp(pass, PASS) == 0) { + if (strcmp(user, username) == 0 && strcmp(pass, password) == 0) { sdata->authenticated = 1; return SSH_AUTH_SUCCESS; } |