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 #include <stdlib.h> 21 #include <stdio.h> 22 #include <string.h> 23 #ifdef _WIN32 24 #define WINVER 0x0400 25 #include <windows.h> 26 #include <winsock.h> 27 #include <time.h> 28 #define DIR int 29 #else 30 #include <dirent.h> 31 #include <sys/time.h> 32 #ifdef HAVE_SYS_SELECT_H 33 #include <sys/select.h> 34 #else 35 #include <sys/types.h> 36 #include <unistd.h> 37 #endif 38 #endif 39 #include <limits.h> /* PATH_MAX */ 40 #ifdef HAVE_SYSEXITS_H 41 #include <sysexits.h> 42 #endif 43 44 /* standard exit codes */ 45 #ifndef EX_OK 46 #define EX_OK 0 47 #endif 48 #ifndef EX_USAGE 49 #define EX_USAGE 64 50 #endif 51 #ifndef EX_DATAERR 52 #define EX_DATAERR 65 53 #endif 54 #ifndef EX_NOINPUT 55 #define EX_NOINPUT 66 56 #endif 57 #ifndef EX_NOUSER 58 #define EX_NOUSER 67 59 #endif 60 #ifndef EX_NOHOST 61 #define EX_NOHOST 68 62 #endif 63 #ifndef EX_UNAVAILABLE 64 #define EX_UNAVAILABLE 69 65 #endif 66 #ifndef EX_SOFTWARE 67 #define EX_SOFTWARE 70 68 #endif 69 #ifndef EX_OSERR 70 #define EX_OSERR 71 71 #endif 72 #ifndef EX_OSFILE 73 #define EX_OSFILE 72 74 #endif 75 #ifndef EX_CANTCREAT 76 #define EX_CANTCREAT 73 77 #endif 78 #ifndef EX_IOERR 79 #define EX_IOERR 74 80 #endif 81 #ifndef EX_TEMPFAIL 82 #define EX_TEMPFAIL 75 83 #endif 84 #ifndef EX_PROTOCOL 85 #define EX_PROTOCOL 76 86 #endif 87 #ifndef EX_NOPERM 88 #define EX_NOPERM 77 89 #endif 90 #ifndef EX_CONFIG 91 #define EX_CONFIG 78 92 #endif 93 94 /* rdesktop specific exit codes, lined up with disconnect PDU reasons */ 95 #define EXRD_DISCONNECT_BY_ADMIN 1 96 #define EXRD_LOGOFF_BY_ADMIN 2 97 #define EXRD_IDLE_TIMEOUT 3 98 #define EXRD_LOGON_TIMEOUT 4 99 #define EXRD_REPLACED 5 100 #define EXRD_OUT_OF_MEM 6 101 #define EXRD_DENIED 7 102 #define EXRD_DENIED_FIPS 8 103 #define EXRD_INSUFFICIENT_PRIVILEGES 9 104 #define EXRD_FRESH_CREDENTIALS_REQUIRED 10 105 #define EXRD_DISCONNECT_BY_USER 11 106 #define EXRD_LOGOFF_BY_USER 12 107 108 #define EXRD_LIC_INTERNAL 16 109 #define EXRD_LIC_NOSERVER 17 110 #define EXRD_LIC_NOLICENSE 18 111 #define EXRD_LIC_MSG 19 112 #define EXRD_LIC_HWID 20 113 #define EXRD_LIC_CLIENT 21 114 #define EXRD_LIC_NET 22 115 #define EXRD_LIC_PROTO 23 116 #define EXRD_LIC_ENC 24 117 #define EXRD_LIC_UPGRADE 25 118 #define EXRD_LIC_NOREMOTE 26 119 120 #define EXRD_CB_DEST_NOT_FOUND 30 121 #define EXRD_CB_DEST_LOADING 32 122 #define EXRD_CB_REDIR_DEST 34 123 #define EXRD_CB_VM_WAKE 35 124 #define EXRD_CB_VM_BOOT 36 125 #define EXRD_CB_VM_NODNS 37 126 #define EXRD_CB_DEST_POOL_NOT_FREE 38 127 #define EXRD_CB_CONNECTION_CANCELLED 39 128 #define EXRD_CB_INVALID_SETTINGS 40 129 #define EXRD_CB_VM_BOOT_TIMEOUT 41 130 #define EXRD_CB_VM_BOOT_SESSMON_FAILED 42 131 132 #define EXRD_RDP_REMOTEAPPSNOTENABLED 50 133 #define EXRD_RDP_UPDATESESSIONKEYFAILED 51 134 #define EXRD_RDP_DECRYPTFAILED 52 135 #define EXRD_RDP_ENCRYPTFAILED 53 136 137 /* other exit codes */ 138 #define EXRD_WINDOW_CLOSED 62 139 #define EXRD_UNKNOWN 63 140 141 #define STRNCPY(dst,src,n) { strncpy(dst,src,n-1); dst[n-1] = 0; } 142 143 #ifndef MIN 144 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 145 #endif 146 147 #ifndef MAX 148 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 149 #endif 150 151 /* timeval macros */ 152 #ifndef timerisset 153 #define timerisset(tvp)\ 154 ((tvp)->tv_sec || (tvp)->tv_usec) 155 #endif 156 #ifndef timercmp 157 #define timercmp(tvp, uvp, cmp)\ 158 ((tvp)->tv_sec cmp (uvp)->tv_sec ||\ 159 (tvp)->tv_sec == (uvp)->tv_sec &&\ 160 (tvp)->tv_usec cmp (uvp)->tv_usec) 161 #endif 162 #ifndef timerclear 163 #define timerclear(tvp)\ 164 ((tvp)->tv_sec = (tvp)->tv_usec = 0) 165 #endif 166 167 /* If configure does not define the endianness, try 168 to find it out */ 169 #if !defined(L_ENDIAN) && !defined(B_ENDIAN) 170 #if __BYTE_ORDER == __LITTLE_ENDIAN 171 #define L_ENDIAN 172 #elif __BYTE_ORDER == __BIG_ENDIAN 173 #define B_ENDIAN 174 #else 175 #error Unknown endianness. Edit rdesktop.h. 176 #endif 177 #endif /* B_ENDIAN, L_ENDIAN from configure */ 178 179 /* No need for alignment on x86 and amd64 */ 180 #if !defined(NEED_ALIGN) 181 #if !(defined(__x86__) || defined(__x86_64__) || \ 182 defined(__AMD64__) || defined(_M_IX86) || \ 183 defined(__i386__)) 184 #define NEED_ALIGN 185 #endif 186 #endif 187 188 #include "utils.h" 189 #include "stream.h" 190 #include "constants.h" 191 #include "types.h" 192 #include "proto.h" 193