xref: /titanic_50/usr/src/cmd/ssh/include/packet.h (revision cd7d5faf5bbb52336a6f85578a90b31a648ac3fa)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Author: Tatu Ylonen <ylo@cs.hut.fi>
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
47c478bd9Sstevel@tonic-gate  *                    All rights reserved
57c478bd9Sstevel@tonic-gate  * Interface for the packet protocol functions.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * As far as I am concerned, the code I have written for this software
87c478bd9Sstevel@tonic-gate  * can be used freely for any purpose.  Any derived versions of this
97c478bd9Sstevel@tonic-gate  * software must be clearly marked as such, and if the derived work is
107c478bd9Sstevel@tonic-gate  * incompatible with the protocol description in the RFC file, it must be
117c478bd9Sstevel@tonic-gate  * called by a name other than "ssh" or "Secure Shell".
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate /*
14*cd7d5fafSJan Pechanec  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
157c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
189a8058b5Sjp161948 #ifndef	_PACKET_H
199a8058b5Sjp161948 #define	_PACKET_H
209a8058b5Sjp161948 
219a8058b5Sjp161948 /*	$OpenBSD: packet.h,v 1.35 2002/06/19 18:01:00 markus Exp $	*/
229a8058b5Sjp161948 
239a8058b5Sjp161948 #ifdef __cplusplus
249a8058b5Sjp161948 extern "C" {
259a8058b5Sjp161948 #endif
269a8058b5Sjp161948 
279a8058b5Sjp161948 
287c478bd9Sstevel@tonic-gate #include <openssl/bn.h>
299a8058b5Sjp161948 #include "kex.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef ALTPRIVSEP
327c478bd9Sstevel@tonic-gate /* Monitor-side functions */
337c478bd9Sstevel@tonic-gate void	 packet_set_server(void);
347c478bd9Sstevel@tonic-gate void	 packet_set_no_monitor(void);
357c478bd9Sstevel@tonic-gate void	 packet_set_monitor(int pip_fd);
367c478bd9Sstevel@tonic-gate int	 packet_is_server(void);
377c478bd9Sstevel@tonic-gate int	 packet_is_monitor(void);
387c478bd9Sstevel@tonic-gate void	 packet_set_packet(const void *buf, u_int len);
39*cd7d5fafSJan Pechanec void	 packet_set_fds(int fd, int restore);
407c478bd9Sstevel@tonic-gate #endif /* ALTPRIVSEP */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate void     packet_set_connection(int, int);
437c478bd9Sstevel@tonic-gate void     packet_set_nonblocking(void);
447c478bd9Sstevel@tonic-gate int      packet_get_connection_in(void);
457c478bd9Sstevel@tonic-gate int      packet_get_connection_out(void);
467c478bd9Sstevel@tonic-gate void     packet_close(void);
477c478bd9Sstevel@tonic-gate void	 packet_set_encryption_key(const u_char *, u_int, int);
487c478bd9Sstevel@tonic-gate u_int	 packet_get_encryption_key(u_char *);
497c478bd9Sstevel@tonic-gate void     packet_set_protocol_flags(u_int);
507c478bd9Sstevel@tonic-gate u_int	 packet_get_protocol_flags(void);
517c478bd9Sstevel@tonic-gate void     packet_start_compression(int);
527c478bd9Sstevel@tonic-gate void     packet_set_interactive(int);
537c478bd9Sstevel@tonic-gate int      packet_is_interactive(void);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate void     packet_start(u_char);
567c478bd9Sstevel@tonic-gate void     packet_put_char(int ch);
577c478bd9Sstevel@tonic-gate void     packet_put_int(u_int value);
587c478bd9Sstevel@tonic-gate void     packet_put_bignum(BIGNUM * value);
597c478bd9Sstevel@tonic-gate void     packet_put_bignum2(BIGNUM * value);
607c478bd9Sstevel@tonic-gate void     packet_put_string(const void *buf, u_int len);
617c478bd9Sstevel@tonic-gate void     packet_put_cstring(const char *str);
627c478bd9Sstevel@tonic-gate void     packet_put_ascii_cstring(const char *str);
637c478bd9Sstevel@tonic-gate void     packet_put_utf8_cstring(const u_char *str);
647c478bd9Sstevel@tonic-gate void     packet_put_raw(const void *buf, u_int len);
657c478bd9Sstevel@tonic-gate void     packet_send(void);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #if 0
687c478bd9Sstevel@tonic-gate /* If these are needed, then get rid of the #if 0 and this comment */
697c478bd9Sstevel@tonic-gate void     packet_put_utf8_string(const u_char *buf, u_int len);
707c478bd9Sstevel@tonic-gate void     packet_put_ascii_string(const char *str, u_int len);
717c478bd9Sstevel@tonic-gate #endif
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate int      packet_read(void);
747c478bd9Sstevel@tonic-gate void     packet_read_expect(int type);
757c478bd9Sstevel@tonic-gate int      packet_read_poll(void);
767c478bd9Sstevel@tonic-gate void     packet_process_incoming(const char *buf, u_int len);
777c478bd9Sstevel@tonic-gate int      packet_read_seqnr(u_int32_t *seqnr_p);
787c478bd9Sstevel@tonic-gate int      packet_read_poll_seqnr(u_int32_t *seqnr_p);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate u_int	 packet_get_char(void);
817c478bd9Sstevel@tonic-gate u_int	 packet_get_int(void);
827c478bd9Sstevel@tonic-gate void     packet_get_bignum(BIGNUM * value);
837c478bd9Sstevel@tonic-gate void     packet_get_bignum2(BIGNUM * value);
847c478bd9Sstevel@tonic-gate void	*packet_get_raw(u_int *length_ptr);
857c478bd9Sstevel@tonic-gate void	*packet_get_string(u_int *length_ptr);
867c478bd9Sstevel@tonic-gate char	*packet_get_ascii_cstring();
877c478bd9Sstevel@tonic-gate u_char	*packet_get_utf8_cstring();
887c478bd9Sstevel@tonic-gate void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
897c478bd9Sstevel@tonic-gate void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate void	 set_newkeys(int mode);
929a8058b5Sjp161948 void	 free_keys(Newkeys *keys);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate void     packet_write_poll(void);
957c478bd9Sstevel@tonic-gate void     packet_write_wait(void);
967c478bd9Sstevel@tonic-gate int      packet_have_data_to_write(void);
977c478bd9Sstevel@tonic-gate int      packet_not_very_much_data_to_write(void);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate int	 packet_connection_is_on_socket(void);
1007c478bd9Sstevel@tonic-gate int	 packet_connection_is_ipv4(void);
1017c478bd9Sstevel@tonic-gate int	 packet_remaining(void);
1027c478bd9Sstevel@tonic-gate void	 packet_send_ignore(int);
1037c478bd9Sstevel@tonic-gate void	 packet_add_padding(u_char);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate void	 tty_make_modes(int, struct termios *);
1067c478bd9Sstevel@tonic-gate void	 tty_parse_modes(int, int *);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate extern int max_packet_size;
1097c478bd9Sstevel@tonic-gate int      packet_set_maxsize(int);
1107c478bd9Sstevel@tonic-gate #define  packet_get_maxsize() max_packet_size
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /* don't allow remaining bytes after the end of the message */
1137c478bd9Sstevel@tonic-gate #define packet_check_eom() \
1147c478bd9Sstevel@tonic-gate do { \
1157c478bd9Sstevel@tonic-gate 	int _len = packet_remaining(); \
1167c478bd9Sstevel@tonic-gate 	if (_len > 0) { \
1177c478bd9Sstevel@tonic-gate 		log("Packet integrity error (%d bytes remaining) at %s:%d", \
1187c478bd9Sstevel@tonic-gate 		    _len ,__FILE__, __LINE__); \
1197c478bd9Sstevel@tonic-gate 		packet_disconnect("Packet integrity error."); \
1207c478bd9Sstevel@tonic-gate 	} \
1217c478bd9Sstevel@tonic-gate } while (0)
1227c478bd9Sstevel@tonic-gate 
1239a8058b5Sjp161948 int	 packet_need_rekeying(void);
1249a8058b5Sjp161948 void     packet_set_rekey_limit(u_int32_t);
1259a8058b5Sjp161948 
126*cd7d5fafSJan Pechanec /* see a comment attached to will_daemonize in packet.c for more information */
127*cd7d5fafSJan Pechanec #define NOT_DAEMONIZING			0
128*cd7d5fafSJan Pechanec #define DAEMONIZING_REQUESTED		1
129*cd7d5fafSJan Pechanec #define FIRST_NEWKEYS_PROCESSED		2
130*cd7d5fafSJan Pechanec #define SECOND_NEWKEYS_PROCESSED	3
131*cd7d5fafSJan Pechanec 
1327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate #endif
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #endif /* _PACKET_H */
137