OpenVAS Libraries
4.0+rc3.SVN
|
00001 /* 00002 Unix SMB/CIFS implementation. 00003 SMB parameters and setup, plus a whole lot more. 00004 00005 Copyright (C) Andrew Tridgell 1992-2000 00006 Copyright (C) John H Terpstra 1996-2002 00007 Copyright (C) Luke Kenneth Casson Leighton 1996-2000 00008 Copyright (C) Paul Ashton 1998-2000 00009 Copyright (C) Simo Sorce 2001-2002 00010 Copyright (C) Martin Pool 2002 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00025 */ 00026 00027 /* 00028 MODIFICATION: changes for OpenVAS 00029 1. declarations useful for OpenVAS are retained, others are removed 00030 2. malloc_ changes to malloc in SMB_MALLOC_P 00031 */ 00032 00033 #ifndef _SMB_H 00034 #define _SMB_H 00035 00036 #include <stdio.h> 00037 #include <stdlib.h> 00038 #include <string.h> 00039 #include <stdint.h> 00040 #include <ctype.h> 00041 #include <errno.h> 00042 #include "charset.h" 00043 00044 #define SMB_PORT1 445 00045 #define SMB_PORT2 139 00046 #define SMB_PORTS "445 139" 00047 00048 /* offsets into message for common items */ 00049 #define smb_com 8 00050 #define smb_rcls 9 00051 #define smb_reh 10 00052 #define smb_err 11 00053 #define smb_flg 13 00054 #define smb_flg2 14 00055 #define smb_pidhigh 16 00056 #define smb_ss_field 18 00057 #define smb_tid 28 00058 #define smb_pid 30 00059 #define smb_uid 32 00060 #define smb_mid 34 00061 #define smb_wct 36 00062 #define smb_vwv 37 00063 #define smb_vwv0 37 00064 #define smb_vwv1 39 00065 #define smb_vwv2 41 00066 #define smb_vwv3 43 00067 #define smb_vwv4 45 00068 #define smb_vwv5 47 00069 #define smb_vwv6 49 00070 #define smb_vwv7 51 00071 #define smb_vwv8 53 00072 #define smb_vwv9 55 00073 #define smb_vwv10 57 00074 #define smb_vwv11 59 00075 #define smb_vwv12 61 00076 #define smb_vwv13 63 00077 #define smb_vwv14 65 00078 #define smb_vwv15 67 00079 #define smb_vwv16 69 00080 #define smb_vwv17 71 00081 00082 /* generic iconv conversion structure */ 00083 typedef struct _smb_iconv_t { 00084 size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft, 00085 char **outbuf, size_t *outbytesleft); 00086 size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft, 00087 char **outbuf, size_t *outbytesleft); 00088 size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft, 00089 char **outbuf, size_t *outbytesleft); 00090 void *cd_direct, *cd_pull, *cd_push; 00091 char *from_name, *to_name; 00092 } *smb_iconv_t; 00093 00094 /* string manipulation flags - see clistr.c and srvstr.c */ 00095 #define STR_TERMINATE 1 00096 #define STR_UPPER 2 00097 #define STR_ASCII 4 00098 #define STR_UNICODE 8 00099 #define STR_NOALIGN 16 00100 #define STR_TERMINATE_ASCII 128 00101 00102 /* Sercurity mode bits. */ 00103 #define NEGOTIATE_SECURITY_USER_LEVEL 0x01 00104 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE 0x02 00105 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED 0x04 00106 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED 0x08 00107 00108 /* NT Flags2 bits - cifs6.txt section 3.1.2 */ 00109 00110 #define FLAGS2_LONG_PATH_COMPONENTS 0x0001 00111 #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002 00112 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004 00113 #define FLAGS2_UNKNOWN_BIT4 0x0010 00114 #define FLAGS2_IS_LONG_NAME 0x0040 00115 #define FLAGS2_EXTENDED_SECURITY 0x0800 00116 #define FLAGS2_DFS_PATHNAMES 0x1000 00117 #define FLAGS2_READ_PERMIT_EXECUTE 0x2000 00118 #define FLAGS2_32_BIT_ERROR_CODES 0x4000 00119 #define FLAGS2_UNICODE_STRINGS 0x8000 00120 00121 #define FLAGS2_WIN2K_SIGNATURE 0xC852 /* Hack alert ! For now... JRA. */ 00122 00123 /* TCONX Flag (smb_vwv2). */ 00124 #define TCONX_FLAG_EXTENDED_RESPONSE 0x8 00125 00126 /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */ 00127 00128 #define CAP_RAW_MODE 0x0001 00129 #define CAP_MPX_MODE 0x0002 00130 #define CAP_UNICODE 0x0004 00131 #define CAP_LARGE_FILES 0x0008 00132 #define CAP_NT_SMBS 0x0010 00133 #define CAP_RPC_REMOTE_APIS 0x0020 00134 #define CAP_STATUS32 0x0040 00135 #define CAP_LEVEL_II_OPLOCKS 0x0080 00136 #define CAP_LOCK_AND_READ 0x0100 00137 #define CAP_NT_FIND 0x0200 00138 #define CAP_DFS 0x1000 00139 #define CAP_W2K_SMBS 0x2000 00140 #define CAP_LARGE_READX 0x4000 00141 #define CAP_LARGE_WRITEX 0x8000 00142 #define CAP_UNIX 0x800000 /* Capabilities for UNIX extensions. Created by HP. */ 00143 #define CAP_EXTENDED_SECURITY 0x80000000 00144 00145 /* protocol types. It assumes that higher protocols include lower protocols 00146 * as subsets */ 00147 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1}; 00148 00149 #ifdef WORDS_BIGENDIAN 00150 #define UCS2_SHIFT 8 00151 #else 00152 #define UCS2_SHIFT 0 00153 #endif 00154 00155 /* turn a 7 bit character into a ucs2 character */ 00156 #define UCS2_CHAR(c) ((c) << UCS2_SHIFT) 00157 00158 /* return an ascii version of a ucs2 character */ 00159 #define UCS2_TO_CHAR(c) (((c) >> UCS2_SHIFT) & 0xff) 00160 00161 /* Copy into a smb_ucs2_tt from a possibly unaligned buffer. Return the copied smb_ucs2_tt */ 00162 #define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\ 00163 ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest)) 00164 00165 /* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */ 00166 typedef uint64_t NTTIME; 00167 00168 /*-------------------taken from samba's smb_macros.h-------------------------------*/ 00169 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0) 00170 00171 #define SMB_MALLOC_P(type) (type *)malloc(sizeof(type)) 00172 00173 #define SMB_REALLOC(p,s) Realloc((p),(s),True) /* Always frees p on error or s == 0 */ 00174 #ifndef SMB_MALLOC 00175 #define SMB_MALLOC(s) malloc(s) 00176 #endif 00177 00178 #define SMB_STRDUP(s) strdup(s) 00179 #define SMB_STRNDUP(s,n) strndup(s,n) 00180 00181 #define smb_len(buf) (PVAL(buf,3)|(PVAL(buf,2)<<8)|((PVAL(buf,1)&1)<<16)) 00182 00183 #ifndef MIN 00184 #define MIN(a,b) ((a)<(b)?(a):(b)) 00185 #endif 00186 /*---------------------------------------------------------------------------------*/ 00187 00188 #endif /* _SMB_H */