1 | /*
|
---|
2 | rdesktop: A Remote Desktop Protocol client.
|
---|
3 | Master include file
|
---|
4 | Copyright (C) Matthew Chapman 1999-2008
|
---|
5 |
|
---|
6 | This program is free software: you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation, either version 3 of the License, or
|
---|
9 | (at your option) any later version.
|
---|
10 |
|
---|
11 | This program is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
22 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
23 | * the General Public License version 2 (GPLv2) at this time for any software where
|
---|
24 | * a choice of GPL license versions is made available with the language indicating
|
---|
25 | * that GPLv2 or any later version may be used, or where a choice of which version
|
---|
26 | * of the GPL is applied is otherwise unspecified.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <stdlib.h>
|
---|
30 | #include <stdio.h>
|
---|
31 | #include <string.h>
|
---|
32 | #ifdef _WIN32
|
---|
33 | #define WINVER 0x0400
|
---|
34 | #include <windows.h>
|
---|
35 | #include <winsock.h>
|
---|
36 | #include <time.h>
|
---|
37 | #define DIR int
|
---|
38 | #else
|
---|
39 | #include <dirent.h>
|
---|
40 | #include <sys/time.h>
|
---|
41 | #ifdef HAVE_SYS_SELECT_H
|
---|
42 | #include <sys/select.h>
|
---|
43 | #else
|
---|
44 | #include <sys/types.h>
|
---|
45 | #include <unistd.h>
|
---|
46 | #endif
|
---|
47 | #endif
|
---|
48 | #include <limits.h> /* PATH_MAX */
|
---|
49 | #ifdef HAVE_SYSEXITS_H
|
---|
50 | #include <sysexits.h>
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | /* standard exit codes */
|
---|
54 | #ifndef EX_OK
|
---|
55 | #define EX_OK 0
|
---|
56 | #endif
|
---|
57 | #ifndef EX_USAGE
|
---|
58 | #define EX_USAGE 64
|
---|
59 | #endif
|
---|
60 | #ifndef EX_DATAERR
|
---|
61 | #define EX_DATAERR 65
|
---|
62 | #endif
|
---|
63 | #ifndef EX_NOINPUT
|
---|
64 | #define EX_NOINPUT 66
|
---|
65 | #endif
|
---|
66 | #ifndef EX_NOUSER
|
---|
67 | #define EX_NOUSER 67
|
---|
68 | #endif
|
---|
69 | #ifndef EX_NOHOST
|
---|
70 | #define EX_NOHOST 68
|
---|
71 | #endif
|
---|
72 | #ifndef EX_UNAVAILABLE
|
---|
73 | #define EX_UNAVAILABLE 69
|
---|
74 | #endif
|
---|
75 | #ifndef EX_SOFTWARE
|
---|
76 | #define EX_SOFTWARE 70
|
---|
77 | #endif
|
---|
78 | #ifndef EX_OSERR
|
---|
79 | #define EX_OSERR 71
|
---|
80 | #endif
|
---|
81 | #ifndef EX_OSFILE
|
---|
82 | #define EX_OSFILE 72
|
---|
83 | #endif
|
---|
84 | #ifndef EX_CANTCREAT
|
---|
85 | #define EX_CANTCREAT 73
|
---|
86 | #endif
|
---|
87 | #ifndef EX_IOERR
|
---|
88 | #define EX_IOERR 74
|
---|
89 | #endif
|
---|
90 | #ifndef EX_TEMPFAIL
|
---|
91 | #define EX_TEMPFAIL 75
|
---|
92 | #endif
|
---|
93 | #ifndef EX_PROTOCOL
|
---|
94 | #define EX_PROTOCOL 76
|
---|
95 | #endif
|
---|
96 | #ifndef EX_NOPERM
|
---|
97 | #define EX_NOPERM 77
|
---|
98 | #endif
|
---|
99 | #ifndef EX_CONFIG
|
---|
100 | #define EX_CONFIG 78
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /* rdesktop specific exit codes, lined up with disconnect PDU reasons */
|
---|
104 | #define EXRD_API_DISCONNECT 1
|
---|
105 | #define EXRD_API_LOGOFF 2
|
---|
106 | #define EXRD_IDLE_TIMEOUT 3
|
---|
107 | #define EXRD_LOGON_TIMEOUT 4
|
---|
108 | #define EXRD_REPLACED 5
|
---|
109 | #define EXRD_OUT_OF_MEM 6
|
---|
110 | #define EXRD_DENIED 7
|
---|
111 | #define EXRD_DENIED_FIPS 8
|
---|
112 | #define EXRD_LIC_INTERNAL 16
|
---|
113 | #define EXRD_LIC_NOSERVER 17
|
---|
114 | #define EXRD_LIC_NOLICENSE 18
|
---|
115 | #define EXRD_LIC_MSG 19
|
---|
116 | #define EXRD_LIC_HWID 20
|
---|
117 | #define EXRD_LIC_CLIENT 21
|
---|
118 | #define EXRD_LIC_NET 22
|
---|
119 | #define EXRD_LIC_PROTO 23
|
---|
120 | #define EXRD_LIC_ENC 24
|
---|
121 | #define EXRD_LIC_UPGRADE 25
|
---|
122 | #define EXRD_LIC_NOREMOTE 26
|
---|
123 |
|
---|
124 | /* other exit codes */
|
---|
125 | #define EXRD_WINDOW_CLOSED 62
|
---|
126 | #define EXRD_UNKNOWN 63
|
---|
127 |
|
---|
128 | #ifdef VBOX
|
---|
129 | #undef DEBUG
|
---|
130 | #endif
|
---|
131 |
|
---|
132 | #ifdef WITH_DEBUG
|
---|
133 | #define DEBUG(args) printf args;
|
---|
134 | #else
|
---|
135 | #define DEBUG(args)
|
---|
136 | #endif
|
---|
137 |
|
---|
138 | #ifdef WITH_DEBUG_KBD
|
---|
139 | #define DEBUG_KBD(args) printf args;
|
---|
140 | #else
|
---|
141 | #define DEBUG_KBD(args)
|
---|
142 | #endif
|
---|
143 |
|
---|
144 | #ifdef WITH_DEBUG_RDP5
|
---|
145 | #define DEBUG_RDP5(args) printf args;
|
---|
146 | #else
|
---|
147 | #define DEBUG_RDP5(args)
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | #ifdef WITH_DEBUG_CLIPBOARD
|
---|
151 | #define DEBUG_CLIPBOARD(args) printf args;
|
---|
152 | #else
|
---|
153 | #define DEBUG_CLIPBOARD(args)
|
---|
154 | #endif
|
---|
155 |
|
---|
156 | #ifdef WITH_DEBUG_SOUND
|
---|
157 | #define DEBUG_SOUND(args) printf args;
|
---|
158 | #else
|
---|
159 | #define DEBUG_SOUND(args)
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | #ifdef WITH_DEBUG_CHANNEL
|
---|
163 | #define DEBUG_CHANNEL(args) printf args;
|
---|
164 | #else
|
---|
165 | #define DEBUG_CHANNEL(args)
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #ifdef WITH_DEBUG_SCARD
|
---|
169 | #define DEBUG_SCARD(args) printf args;
|
---|
170 | #else
|
---|
171 | #define DEBUG_SCARD(args)
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | #define STRNCPY(dst,src,n) { strncpy(dst,src,n-1); dst[n-1] = 0; }
|
---|
175 |
|
---|
176 | #ifndef MIN
|
---|
177 | #define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #ifndef MAX
|
---|
181 | #define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | /* timeval macros */
|
---|
185 | #ifndef timerisset
|
---|
186 | #define timerisset(tvp)\
|
---|
187 | ((tvp)->tv_sec || (tvp)->tv_usec)
|
---|
188 | #endif
|
---|
189 | #ifndef timercmp
|
---|
190 | #define timercmp(tvp, uvp, cmp)\
|
---|
191 | ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
|
---|
192 | (tvp)->tv_sec == (uvp)->tv_sec &&\
|
---|
193 | (tvp)->tv_usec cmp (uvp)->tv_usec)
|
---|
194 | #endif
|
---|
195 | #ifndef timerclear
|
---|
196 | #define timerclear(tvp)\
|
---|
197 | ((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
---|
198 | #endif
|
---|
199 |
|
---|
200 | /* If configure does not define the endianess, try
|
---|
201 | to find it out */
|
---|
202 | #if !defined(L_ENDIAN) && !defined(B_ENDIAN)
|
---|
203 | #if __BYTE_ORDER == __LITTLE_ENDIAN
|
---|
204 | #define L_ENDIAN
|
---|
205 | #elif __BYTE_ORDER == __BIG_ENDIAN
|
---|
206 | #define B_ENDIAN
|
---|
207 | #else
|
---|
208 | #error Unknown endianness. Edit rdesktop.h.
|
---|
209 | #endif
|
---|
210 | #endif /* B_ENDIAN, L_ENDIAN from configure */
|
---|
211 |
|
---|
212 | /* No need for alignment on x86 and amd64 */
|
---|
213 | #if !defined(NEED_ALIGN)
|
---|
214 | #if !(defined(__x86__) || defined(__x86_64__) || \
|
---|
215 | defined(__AMD64__) || defined(_M_IX86) || \
|
---|
216 | defined(__i386__))
|
---|
217 | #define NEED_ALIGN
|
---|
218 | #endif
|
---|
219 | #endif
|
---|
220 |
|
---|
221 | #include "parse.h"
|
---|
222 | #include "constants.h"
|
---|
223 | #include "types.h"
|
---|
224 |
|
---|
225 | #ifndef MAKE_PROTO
|
---|
226 | #include "proto.h"
|
---|
227 | #endif
|
---|