# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / sshd / session.h
1 /*
2  * Dropbear - a SSH2 server
3  * 
4  * Copyright (c) 2002,2003 Matt Johnston
5  * All rights reserved.
6  * 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  * 
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  * 
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE. */
24
25 #ifndef _SESSION_H_
26 #define _SESSION_H_
27
28 #include "includes.h"
29 #include "buffer.h"
30 #include "signkey.h"
31 #include "kex.h"
32 #include "auth.h"
33 #include "channel.h"
34 #include "queue.h"
35 #include "runopts.h"
36
37 extern int sessinitdone;
38 extern int exitflag;
39
40 void session_cleanup();
41 void child_session(int sock, runopts *opts, int childpipe,
42                 struct sockaddr *remoteaddr);
43
44 struct key_context {
45
46         const struct dropbear_cipher *recv_algo_crypt; /* NULL for none */
47         const struct dropbear_cipher *trans_algo_crypt; /* NULL for none */
48         const struct dropbear_hash *recv_algo_mac; /* NULL for none */
49         const struct dropbear_hash *trans_algo_mac; /* NULL for none */
50         char algo_kex;
51         char algo_hostkey;
52
53         char recv_algo_comp; /* compression */
54         char trans_algo_comp;
55 #ifndef DISABLE_ZLIB
56         z_streamp recv_zstream;
57         z_streamp trans_zstream;
58 #endif
59
60         /* actual keys */
61         symmetric_CBC recv_symmetric_struct;
62         symmetric_CBC trans_symmetric_struct;
63         unsigned char recvmackey[MAX_MAC_KEY];
64         unsigned char transmackey[MAX_MAC_KEY];
65
66 };
67
68 struct sshsession {
69
70         runopts * opts; /* runtime options, incl hostkey, banner etc */
71         int sock;
72         int childpipe; /* kept open until we successfully authenticate */
73         long connecttime; /* time of initial connection */
74
75         struct sockaddr *remoteaddr; /* the host and port of the client */
76         unsigned char *addrstring; /* the text version of remoteaddr */
77         unsigned char *hostname; /* the remote hostname */
78
79         int maxfd; /* the maximum file descriptor to check with select() */
80         unsigned char *remoteident;
81
82         struct KEXState kexstate;
83
84         /* flags */
85         unsigned dataallowed : 1; /* whether we can send data packets or we are in
86                                                                  the middle of a KEX or something */
87
88         unsigned char expecting; /* byte indicating what packet we expect next, 
89                                                                 or 0x00 for any */
90         
91         /* unencrypted write payload */
92         buffer *writepayload; /* this will actually refer to within clearwritebuf */
93         unsigned int transseq; /* sequence number */
94         /* encrypted write packet buffer queue */
95         struct Queue writequeue;
96
97         /* read packet buffer */
98         buffer *readbuf;
99         /* decrypted read buffer */
100         buffer *decryptreadbuf;
101         buffer *payload; /* this actually refers to within decryptreadbuf */
102         unsigned int recvseq; /* sequence number */
103
104         struct key_context *keys;
105         struct key_context *newkeys;
106         
107         unsigned char *session_id; /*this is the hash from the first kex*/
108
109         /* the following are for key exchange */
110         unsigned char hash[SHA1_HASH_SIZE]; /* the hash*/
111         /* these are used temorarily during kex, are freed after use */
112         mp_int * dh_K; /* SSH_MSG_KEXDH_REPLY and sending SSH_MSH_NEWKEYS */
113         buffer* kexhashbuf; /* session hash buffer calculated from various packets*/
114         buffer* transkexinit; /* the kexinit payload we send */
115
116         /* userauth */
117         struct AuthState authstate;
118
119         /* channels */
120         struct Channel ** channels; /* these pointers may be null */
121         unsigned int chansize; /* the number of Channel*s allocated for channels */
122
123         struct ChildPid * childpids; /* array of mappings childpid<->channel */
124         unsigned int childpidsize;
125
126 };
127
128 /* global struct storing the state */
129 extern struct sshsession ses;
130
131 #endif /* _SESSION_H_ */