Exemplo n.º 1
0
static int
do_send_and_receive(struct ssh *from, struct ssh *to)
{
	u_char type;
	size_t len;
	const u_char *buf;
	int r;

	for (;;) {
		if ((r = ssh_packet_next(from, &type)) != 0) {
			fprintf(stderr, "ssh_packet_next: %s\n", ssh_err(r));
			return r;
		}
		if (type != 0)
			return 0;
		buf = ssh_output_ptr(from, &len);
		if (do_debug)
			printf("%zu", len);
		if (len == 0)
			return 0;
		if ((r = ssh_output_consume(from, len)) != 0 ||
		    (r = ssh_input_append(to, buf, len)) != 0)
			return r;
	}
}
Exemplo n.º 2
0
static int
do_send_and_receive(struct ssh *from, struct ssh *to, int mydirection,
    int *packet_count, int trigger_direction, int packet_index,
    const char *dump_path, struct sshbuf *replace_data)
{
	u_char type;
	size_t len, olen;
	const u_char *buf;
	int r;
	FILE *dumpfile;

	for (;;) {
		if ((r = ssh_packet_next(from, &type)) != 0) {
			fprintf(stderr, "ssh_packet_next: %s\n", ssh_err(r));
			return r;
		}
		if (type != 0)
			return 0;
		buf = ssh_output_ptr(from, &len);
		olen = len;
		if (do_debug) {
			printf("%s packet %d type %u len %zu:\n",
			    mydirection == S2C ? "s2c" : "c2s",
			    *packet_count, type, len);
			sshbuf_dump_data(buf, len, stdout);
		}
		if (mydirection == trigger_direction &&
		    packet_index == *packet_count) {
			if (replace_data != NULL) {
				buf = sshbuf_ptr(replace_data);
				len = sshbuf_len(replace_data);
				if (do_debug) {
					printf("***** replaced packet "
					    "len %zu\n", len);
					sshbuf_dump_data(buf, len, stdout);
				}
			} else if (dump_path != NULL) {
				if ((dumpfile = fopen(dump_path, "w+")) == NULL)
					err(1, "fopen %s", dump_path);
				if (len != 0 &&
				    fwrite(buf, len, 1, dumpfile) != 1)
					err(1, "fwrite %s", dump_path);
				if (do_debug)
					printf("***** dumped packet "
					    "len %zu\n", len);
				fclose(dumpfile);
				exit(0);
			}
		}
		(*packet_count)++;
		if (len == 0)
			return 0;
		if ((r = ssh_input_append(to, buf, len)) != 0 ||
		    (r = ssh_output_consume(from, olen)) != 0)
			return r;
	}
}