OpenVAS Libraries  9.0.1
smb.h
Go to the documentation of this file.
1 /*
2  Unix SMB/CIFS implementation.
3  SMB parameters and setup, plus a whole lot more.
4 
5  Copyright (C) Andrew Tridgell 1992-2000
6  Copyright (C) John H Terpstra 1996-2002
7  Copyright (C) Luke Kenneth Casson Leighton 1996-2000
8  Copyright (C) Paul Ashton 1998-2000
9  Copyright (C) Simo Sorce 2001-2002
10  Copyright (C) Martin Pool 2002
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26 
27 /*
28  MODIFICATION: changes for OpenVAS
29  1. declarations useful for OpenVAS are retained, others are removed
30  2. malloc_ changes to malloc in SMB_MALLOC_P
31 */
32 
33 #ifndef _SMB_H
34 #define _SMB_H
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <stdint.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include "charset.h"
43 
44 #define SMB_PORT1 445
45 #define SMB_PORT2 139
46 #define SMB_PORTS "445 139"
47 
48 /* offsets into message for common items */
49 #define smb_com 8
50 #define smb_rcls 9
51 #define smb_reh 10
52 #define smb_err 11
53 #define smb_flg 13
54 #define smb_flg2 14
55 #define smb_pidhigh 16
56 #define smb_ss_field 18
57 #define smb_tid 28
58 #define smb_pid 30
59 #define smb_uid 32
60 #define smb_mid 34
61 #define smb_wct 36
62 #define smb_vwv 37
63 #define smb_vwv0 37
64 #define smb_vwv1 39
65 #define smb_vwv2 41
66 #define smb_vwv3 43
67 #define smb_vwv4 45
68 #define smb_vwv5 47
69 #define smb_vwv6 49
70 #define smb_vwv7 51
71 #define smb_vwv8 53
72 #define smb_vwv9 55
73 #define smb_vwv10 57
74 #define smb_vwv11 59
75 #define smb_vwv12 61
76 #define smb_vwv13 63
77 #define smb_vwv14 65
78 #define smb_vwv15 67
79 #define smb_vwv16 69
80 #define smb_vwv17 71
81 
82 /* generic iconv conversion structure */
83 typedef struct _smb_iconv_t {
84  size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
85  char **outbuf, size_t *outbytesleft);
86  size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
87  char **outbuf, size_t *outbytesleft);
88  size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
89  char **outbuf, size_t *outbytesleft);
91  char *from_name, *to_name;
92 } *smb_iconv_t;
93 
94 /* string manipulation flags - see clistr.c and srvstr.c */
95 #define STR_TERMINATE 1
96 #define STR_UPPER 2
97 #define STR_ASCII 4
98 #define STR_UNICODE 8
99 #define STR_NOALIGN 16
100 #define STR_TERMINATE_ASCII 128
101 
102 /* Sercurity mode bits. */
103 #define NEGOTIATE_SECURITY_USER_LEVEL 0x01
104 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE 0x02
105 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED 0x04
106 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED 0x08
107 
108 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
109 
110 #define FLAGS2_LONG_PATH_COMPONENTS 0x0001
111 #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002
112 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
113 #define FLAGS2_UNKNOWN_BIT4 0x0010
114 #define FLAGS2_IS_LONG_NAME 0x0040
115 #define FLAGS2_EXTENDED_SECURITY 0x0800
116 #define FLAGS2_DFS_PATHNAMES 0x1000
117 #define FLAGS2_READ_PERMIT_EXECUTE 0x2000
118 #define FLAGS2_32_BIT_ERROR_CODES 0x4000
119 #define FLAGS2_UNICODE_STRINGS 0x8000
120 
121 #define FLAGS2_WIN2K_SIGNATURE 0xC852 /* Hack alert ! For now... JRA. */
122 
123 /* TCONX Flag (smb_vwv2). */
124 #define TCONX_FLAG_EXTENDED_RESPONSE 0x8
125 
126 /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
127 
128 #define CAP_RAW_MODE 0x0001
129 #define CAP_MPX_MODE 0x0002
130 #define CAP_UNICODE 0x0004
131 #define CAP_LARGE_FILES 0x0008
132 #define CAP_NT_SMBS 0x0010
133 #define CAP_RPC_REMOTE_APIS 0x0020
134 #define CAP_STATUS32 0x0040
135 #define CAP_LEVEL_II_OPLOCKS 0x0080
136 #define CAP_LOCK_AND_READ 0x0100
137 #define CAP_NT_FIND 0x0200
138 #define CAP_DFS 0x1000
139 #define CAP_W2K_SMBS 0x2000
140 #define CAP_LARGE_READX 0x4000
141 #define CAP_LARGE_WRITEX 0x8000
142 #define CAP_UNIX 0x800000 /* Capabilities for UNIX extensions. Created by HP. */
143 #define CAP_EXTENDED_SECURITY 0x80000000
144 
145 /* protocol types. It assumes that higher protocols include lower protocols
146  * as subsets */
148 
149 #ifdef WORDS_BIGENDIAN
150 #define UCS2_SHIFT 8
151 #else
152 #define UCS2_SHIFT 0
153 #endif
154 
155 /* turn a 7 bit character into a ucs2 character */
156 #define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
157 
158 /* return an ascii version of a ucs2 character */
159 #define UCS2_TO_CHAR(c) (((c) >> UCS2_SHIFT) & 0xff)
160 
161 /* Copy into a smb_ucs2_tt from a possibly unaligned buffer. Return the copied smb_ucs2_tt */
162 #define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\
163  ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest))
164 
165 /* 64 bit time (100 nanosec) 1601 - cifs6.txt, section 3.5, page 30, 4 byte aligned */
166 typedef uint64_t NTTIME;
167 
168 /*-------------------taken from samba's smb_macros.h-------------------------------*/
169 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
170 
171 #define SMB_MALLOC_P(type) (type *)malloc(sizeof(type))
172 
173 #define SMB_REALLOC(p,s) Realloc((p),(s),True) /* Always frees p on error or s == 0 */
174 #ifndef SMB_MALLOC
175 #define SMB_MALLOC(s) malloc(s)
176 #endif
177 
178 #define SMB_STRDUP(s) strdup(s)
179 #define SMB_STRNDUP(s,n) strndup(s,n)
180 
181 #define smb_len(buf) (PVAL(buf,3)|(PVAL(buf,2)<<8)|((PVAL(buf,1)&1)<<16))
182 
183 #ifndef MIN
184 #define MIN(a,b) ((a)<(b)?(a):(b))
185 #endif
186 /*---------------------------------------------------------------------------------*/
187 
188 #endif /* _SMB_H */
struct _smb_iconv_t * smb_iconv_t
void * cd_pull
Definition: smb.h:90
uint64_t NTTIME
Definition: smb.h:166
Definition: smb.h:147
char * to_name
Definition: smb.h:91
size_t(* pull)(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition: smb.h:86
size_t(* direct)(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition: smb.h:84
size_t(* push)(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Definition: smb.h:88
Definition: smb.h:147
Definition: smb.h:147
Definition: smb.h:147
Definition: smb.h:147
void * cd_direct
Definition: smb.h:90
protocol_types
Definition: smb.h:147
void * cd_push
Definition: smb.h:90
Definition: smb.h:83
Definition: smb.h:147
char * from_name
Definition: smb.h:91