Skip to content

Commit

Permalink
upstream: client: switch to sshbuf API; ok djm@
Browse files Browse the repository at this point in the history
OpenBSD-Commit-ID: 60cb0356114acc7625ab85105f6f6a7cd44a8d05
  • Loading branch information
mfriedl authored and djmdjm committed Jul 10, 2018
1 parent ff55f4a commit cecee2d
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 328 deletions.
202 changes: 113 additions & 89 deletions clientloop.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions clientloop.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: clientloop.h,v 1.35 2017/10/23 05:08:00 djm Exp $ */
/* $OpenBSD: clientloop.h,v 1.36 2018/07/09 21:03:30 markus Exp $ */

/*
* Author: Tatu Ylonen <[email protected]>
Expand Down Expand Up @@ -45,7 +45,7 @@ int client_x11_get_proto(struct ssh *, const char *, const char *,
u_int, u_int, char **, char **);
void client_global_request_reply_fwd(int, u_int32_t, void *);
void client_session2_setup(struct ssh *, int, int, int,
const char *, struct termios *, int, Buffer *, char **);
const char *, struct termios *, int, struct sshbuf *, char **);
char *client_request_tun_fwd(struct ssh *, int, int, int);
void client_stop_mux(void);

Expand Down
3 changes: 1 addition & 2 deletions compat.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: compat.c,v 1.110 2018/07/04 13:49:31 djm Exp $ */
/* $OpenBSD: compat.c,v 1.111 2018/07/09 21:03:30 markus Exp $ */
/*
* Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
*
Expand Down Expand Up @@ -32,7 +32,6 @@
#include <stdarg.h>

#include "xmalloc.h"
#include "buffer.h"
#include "packet.h"
#include "compat.h"
#include "log.h"
Expand Down
6 changes: 3 additions & 3 deletions mux.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: mux.c,v 1.71 2018/06/09 03:01:12 djm Exp $ */
/* $OpenBSD: mux.c,v 1.72 2018/07/09 21:03:30 markus Exp $ */
/*
* Copyright (c) 2002-2008 Damien Miller <[email protected]>
*
Expand Down Expand Up @@ -87,7 +87,7 @@ extern Options options;
extern int stdin_null_flag;
extern char *host;
extern int subsystem_flag;
extern Buffer command;
extern struct sshbuf *command;
extern volatile sig_atomic_t quit_pending;

/* Context for session open confirmation callback */
Expand Down Expand Up @@ -1887,7 +1887,7 @@ mux_client_request_session(int fd)
buffer_put_int(&m, options.escape_char == SSH_ESCAPECHAR_NONE ?
0xffffffff : (u_int)options.escape_char);
buffer_put_cstring(&m, term == NULL ? "" : term);
buffer_put_string(&m, buffer_ptr(&command), buffer_len(&command));
buffer_put_string(&m, buffer_ptr(command), buffer_len(command));

/* Pass environment */
if (options.num_send_env > 0 && environ != NULL) {
Expand Down
5 changes: 1 addition & 4 deletions packet.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: packet.c,v 1.275 2018/07/09 13:37:10 sf Exp $ */
/* $OpenBSD: packet.c,v 1.276 2018/07/09 21:03:30 markus Exp $ */
/*
* Author: Tatu Ylonen <[email protected]>
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
Expand Down Expand Up @@ -63,9 +63,6 @@

#include <zlib.h>

#include "buffer.h" /* typedefs XXX */
#include "key.h" /* typedefs XXX */

#include "xmalloc.h"
#include "crc32.h"
#include "compat.h"
Expand Down
29 changes: 16 additions & 13 deletions ssh.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: ssh.c,v 1.481 2018/06/08 03:35:36 djm Exp $ */
/* $OpenBSD: ssh.c,v 1.482 2018/07/09 21:03:30 markus Exp $ */
/*
* Author: Tatu Ylonen <[email protected]>
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
Expand Down Expand Up @@ -87,7 +87,7 @@
#include "cipher.h"
#include "digest.h"
#include "packet.h"
#include "buffer.h"
#include "sshbuf.h"
#include "channels.h"
#include "key.h"
#include "authfd.h"
Expand Down Expand Up @@ -183,7 +183,7 @@ uid_t original_real_uid;
uid_t original_effective_uid;

/* command to be executed */
Buffer command;
struct sshbuf *command;

/* Should we execute a command or invoke a subsystem? */
int subsystem_flag = 0;
Expand Down Expand Up @@ -1042,7 +1042,8 @@ main(int ac, char **av)
#endif

/* Initialize the command to execute on remote host. */
buffer_init(&command);
if ((command = sshbuf_new()) == NULL)
fatal("sshbuf_new failed");

/*
* Save the command to execute on the remote host in a buffer. There
Expand All @@ -1059,9 +1060,10 @@ main(int ac, char **av)
} else {
/* A command has been specified. Store it into the buffer. */
for (i = 0; i < ac; i++) {
if (i)
buffer_append(&command, " ", 1);
buffer_append(&command, av[i], strlen(av[i]));
if ((r = sshbuf_putf(command, "%s%s",
i ? " " : "", av[i])) != 0)
fatal("%s: buffer error: %s",
__func__, ssh_err(r));
}
}

Expand Down Expand Up @@ -1234,11 +1236,11 @@ main(int ac, char **av)
options.use_privileged_port = 0;
#endif

if (buffer_len(&command) != 0 && options.remote_command != NULL)
if (sshbuf_len(command) != 0 && options.remote_command != NULL)
fatal("Cannot execute command-line and remote command.");

/* Cannot fork to background if no command. */
if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
if (fork_after_authentication_flag && sshbuf_len(command) == 0 &&
options.remote_command == NULL && !no_shell_flag)
fatal("Cannot fork into background without a command "
"to execute.");
Expand All @@ -1251,7 +1253,7 @@ main(int ac, char **av)
tty_flag = 1;

/* Allocate a tty by default if no command specified. */
if (buffer_len(&command) == 0 && options.remote_command == NULL)
if (sshbuf_len(command) == 0 && options.remote_command == NULL)
tty_flag = options.request_tty != REQUEST_TTY_NO;

/* Force no tty */
Expand Down Expand Up @@ -1313,8 +1315,9 @@ main(int ac, char **av)
(char *)NULL);
debug3("expanded RemoteCommand: %s", options.remote_command);
free(cp);
buffer_append(&command, options.remote_command,
strlen(options.remote_command));
if ((r = sshbuf_put(command, options.remote_command,
strlen(options.remote_command))) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
}

if (options.control_path != NULL) {
Expand Down Expand Up @@ -1846,7 +1849,7 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
options.ip_qos_interactive, options.ip_qos_bulk);

client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"),
NULL, fileno(stdin), &command, environ);
NULL, fileno(stdin), command, environ);
}

/* open new channel for a session */
Expand Down
6 changes: 3 additions & 3 deletions sshconnect.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: sshconnect.c,v 1.298 2018/04/10 00:10:49 djm Exp $ */
/* $OpenBSD: sshconnect.c,v 1.299 2018/07/09 21:03:30 markus Exp $ */
/*
* Author: Tatu Ylonen <[email protected]>
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
Expand Down Expand Up @@ -52,7 +52,7 @@
#include "key.h"
#include "hostfile.h"
#include "ssh.h"
#include "buffer.h"
#include "sshbuf.h"
#include "packet.h"
#include "uidswap.h"
#include "compat.h"
Expand Down Expand Up @@ -771,7 +771,7 @@ check_host_cert(const char *host, const struct sshkey *host_key)
error("%s", reason);
return 0;
}
if (buffer_len(host_key->cert->critical) != 0) {
if (sshbuf_len(host_key->cert->critical) != 0) {
error("Certificate for %s contains unsupported "
"critical options(s)", host);
return 0;
Expand Down
Loading

0 comments on commit cecee2d

Please sign in to comment.