type.data is malloc'd by everyone BUT radeapclient, which
[freeradius.git] / src / modules / rlm_smb / smblib-priv.h
1 /* UNIX SMBlib NetBIOS implementation
2
3    Version 1.0
4    SMBlib private Defines
5
6    Copyright (C) Richard Sharpe 1996
7
8 */
9
10 /*
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 2 of the License, or
14    (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #include "std-includes.h"
27 #include "smblib-common.h"
28
29 typedef unsigned short uint16;
30 typedef unsigned int   uint32;
31
32 #include "byteorder.h"     /* Hmmm ... hot good */
33
34 #define max(a,b) (a < b ? b : a)
35
36 #define SMB_DEF_IDF 0x424D53FF        /* "\377SMB" */
37
38 /* Core protocol commands */
39
40 #define SMBmkdir      0x00   /* create directory */
41 #define SMBrmdir      0x01   /* delete directory */
42 #define SMBopen       0x02   /* open file */
43 #define SMBcreate     0x03   /* create file */
44 #define SMBclose      0x04   /* close file */
45 #define SMBflush      0x05   /* flush file */
46 #define SMBunlink     0x06   /* delete file */
47 #define SMBmv         0x07   /* rename file */
48 #define SMBgetatr     0x08   /* get file attributes */
49 #define SMBsetatr     0x09   /* set file attributes */
50 #define SMBread       0x0A   /* read from file */
51 #define SMBwrite      0x0B   /* write to file */
52 #define SMBlock       0x0C   /* lock byte range */
53 #define SMBunlock     0x0D   /* unlock byte range */
54 #define SMBctemp      0x0E   /* create temporary file */
55 #define SMBmknew      0x0F   /* make new file */
56 #define SMBchkpth     0x10   /* check directory path */
57 #define SMBexit       0x11   /* process exit */
58 #define SMBlseek      0x12   /* seek */
59 #define SMBtcon       0x70   /* tree connect */
60 #define SMBtdis       0x71   /* tree disconnect */
61 #define SMBnegprot    0x72   /* negotiate protocol */
62 #define SMBdskattr    0x80   /* get disk attributes */
63 #define SMBsearch     0x81   /* search directory */
64 #define SMBsplopen    0xC0   /* open print spool file */
65 #define SMBsplwr      0xC1   /* write to print spool file */
66 #define SMBsplclose   0xC2   /* close print spool file */
67 #define SMBsplretq    0xC3   /* return print queue */
68 #define SMBsends      0xD0   /* send single block message */
69 #define SMBsendb      0xD1   /* send broadcast message */
70 #define SMBfwdname    0xD2   /* forward user name */
71 #define SMBcancelf    0xD3   /* cancel forward */
72 #define SMBgetmac     0xD4   /* get machine name */
73 #define SMBsendstrt   0xD5   /* send start of multi-block message */
74 #define SMBsendend    0xD6   /* send end of multi-block message */
75 #define SMBsendtxt    0xD7   /* send text of multi-block message */
76
77 /* CorePlus protocol                                        */
78
79 #define SMBlockread   0x13  /* Lock a range and read it */
80 #define SMBwriteunlock 0x14 /* Unlock a range and then write */
81 #define SMBreadbraw   0x1a  /* read a block of data without smb header ohead*/
82 #define SMBwritebraw  0x1d  /* write a block of data without smb header ohead*/
83 #define SMBwritec     0x20  /* secondary write request */
84 #define SMBwriteclose 0x2c  /* write a file and then close it */
85
86 /* DOS Extended Protocol                                    */
87
88 #define SMBreadBraw      0x1A   /* read block raw */
89 #define SMBreadBmpx      0x1B   /* read block multiplexed */
90 #define SMBreadBs        0x1C   /* read block (secondary response) */
91 #define SMBwriteBraw     0x1D   /* write block raw */
92 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
93 #define SMBwriteBs       0x1F   /* write block (secondary request) */
94 #define SMBwriteC        0x20   /* write complete response */
95 #define SMBsetattrE      0x22   /* set file attributes expanded */
96 #define SMBgetattrE      0x23   /* get file attributes expanded */
97 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
98 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
99 #define SMBtranss        0x26   /* transaction (secondary request/response) */
100 #define SMBioctl         0x27   /* IOCTL */
101 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
102 #define SMBcopy          0x29   /* copy */
103 #define SMBmove          0x2A   /* move */
104 #define SMBecho          0x2B   /* echo */
105 #define SMBopenX         0x2D   /* open and X */
106 #define SMBreadX         0x2E   /* read and X */
107 #define SMBwriteX        0x2F   /* write and X */
108 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
109 #define SMBtconX         0x75   /* tree connect and X */
110 #define SMBffirst        0x82   /* find first */
111 #define SMBfunique       0x83   /* find unique */
112 #define SMBfclose        0x84   /* find close */
113 #define SMBinvalid       0xFE   /* invalid command */
114
115 /* Any more ? */
116
117 #define SMBdatablockID     0x01  /* A data block identifier */
118 #define SMBdialectID       0x02  /* A dialect id            */
119 #define SMBpathnameID      0x03  /* A pathname ID           */
120 #define SMBasciiID         0x04  /* An ascii string ID      */
121 #define SMBvariableblockID 0x05  /* A variable block ID     */
122
123 /* some other defines we need */
124
125 /* Flags defines ... */
126
127 #define SMB_FLG2_NON_DOS    0x01 /* We know non dos names             */
128 #define SMB_FLG2_EXT_ATR    0x02 /* We know about Extended Attributes */
129 #define SMB_FLG2_LNG_NAM    0x04 /* Long names ?                      */
130
131 typedef unsigned short WORD;
132 typedef unsigned short UWORD;
133 typedef unsigned int ULONG;
134 typedef unsigned char BYTE;
135 typedef unsigned char UCHAR;
136
137 /* Some macros to allow access to actual packet data so that we */
138 /* can change the underlying representation of packets.         */
139 /*                                                              */
140 /* The current formats vying for attention are a fragment       */
141 /* approach where the SMB header is a fragment linked to the    */
142 /* data portion with the transport protocol (rfcnb or whatever) */
143 /* being linked on the front.                                   */
144 /*                                                              */
145 /* The other approach is where the whole packet is one array    */
146 /* of bytes with space allowed on the front for the packet      */
147 /* headers.                                                     */
148
149 #define SMB_Hdr(p) (char *)(p -> data)
150
151 /* SMB Hdr def for File Sharing Protocol? From MS and Intel,    */
152 /* Intel PN 138446 Doc Version 2.0, Nov 7, 1988. This def also  */
153 /* applies to LANMAN1.0 as well as the Core Protocol            */
154 /* The spec states that wct and bcc must be present, even if 0  */
155
156 /* We define these as offsets into a char SMB[] array for the   */
157 /* sake of portability                                          */
158
159 /* NOTE!. Some of the lenght defines, SMB_<protreq>_len do not include */
160 /* the data that follows in the SMB packet, so the code will have to   */
161 /* take that into account.                                             */
162
163 #define SMB_hdr_idf_offset    0          /* 0xFF,'SMB' 0-3 */
164 #define SMB_hdr_com_offset    4          /* BYTE       4   */
165 #define SMB_hdr_rcls_offset   5          /* BYTE       5   */
166 #define SMB_hdr_reh_offset    6          /* BYTE       6   */
167 #define SMB_hdr_err_offset    7          /* WORD       7   */
168 #define SMB_hdr_reb_offset    9          /* BYTE       9   */
169 #define SMB_hdr_flg_offset    9          /* same as reb ...*/
170 #define SMB_hdr_res_offset    10         /* 7 WORDs    10  */
171 #define SMB_hdr_res0_offset   10         /* WORD       10  */
172 #define SMB_hdr_flg2_offset   10         /* WORD           */
173 #define SMB_hdr_res1_offset   12         /* WORD       12  */
174 #define SMB_hdr_res2_offset   14
175 #define SMB_hdr_res3_offset   16
176 #define SMB_hdr_res4_offset   18
177 #define SMB_hdr_res5_offset   20
178 #define SMB_hdr_res6_offset   22
179 #define SMB_hdr_tid_offset    24
180 #define SMB_hdr_pid_offset    26
181 #define SMB_hdr_uid_offset    28
182 #define SMB_hdr_mid_offset    30
183 #define SMB_hdr_wct_offset    32
184
185 #define SMB_hdr_len           33        /* 33 byte header?      */
186
187 #define SMB_hdr_axc_offset    33        /* AndX Command         */
188 #define SMB_hdr_axr_offset    34        /* AndX Reserved        */
189 #define SMB_hdr_axo_offset    35     /* Offset from start to WCT of AndX cmd */
190
191 /* Format of the Negotiate Protocol SMB */
192
193 #define SMB_negp_bcc_offset   33
194 #define SMB_negp_buf_offset   35        /* Where the buffer starts   */
195 #define SMB_negp_len          35        /* plus the data             */
196
197 /* Format of the Negotiate Response SMB, for CoreProtocol, LM1.2 and */
198 /* NT LM 0.12. wct will be 1 for CoreProtocol, 13 for LM 1.2, and 17 */
199 /* for NT LM 0.12                                                    */
200
201 #define SMB_negrCP_idx_offset   33        /* Response to the neg req */
202 #define SMB_negrCP_bcc_offset   35
203 #define SMB_negrLM_idx_offset   33        /* dialect index           */
204 #define SMB_negrLM_sec_offset   35        /* Security mode           */
205 #define SMB_sec_user_mask       0x01      /* 0 = share, 1 = user     */
206 #define SMB_sec_encrypt_mask    0x02      /* pick out encrypt        */
207 #define SMB_negrLM_mbs_offset   37        /* max buffer size         */
208 #define SMB_negrLM_mmc_offset   39        /* max mpx count           */
209 #define SMB_negrLM_mnv_offset   41        /* max number of VCs       */
210 #define SMB_negrLM_rm_offset    43        /* raw mode support bit vec*/
211 #define SMB_read_raw_mask       0x01
212 #define SMB_write_raw_mask      0x02
213 #define SMB_negrLM_sk_offset    45        /* session key, 32 bits    */
214 #define SMB_negrLM_st_offset    49        /* Current server time     */
215 #define SMB_negrLM_sd_offset    51        /* Current server date     */
216 #define SMB_negrLM_stz_offset   53        /* Server Time Zone        */
217 #define SMB_negrLM_ekl_offset   55        /* encryption key length   */
218 #define SMB_negrLM_res_offset   57        /* reserved                */
219 #define SMB_negrLM_bcc_offset   59        /* bcc                     */
220 #define SMB_negrLM_len          61        /* 61 bytes ?              */
221 #define SMB_negrLM_buf_offset   61        /* Where the fun begins    */
222
223 #define SMB_negrNTLM_idx_offset 33        /* Selected protocol       */
224 #define SMB_negrNTLM_sec_offset 35        /* Security more           */
225 #define SMB_negrNTLM_mmc_offset 36        /* Different format above  */
226 #define SMB_negrNTLM_mnv_offset 38        /* Max VCs                 */
227 #define SMB_negrNTLM_mbs_offset 40        /* MBS now a long          */
228 #define SMB_negrNTLM_mrs_offset 44        /* Max raw size            */
229 #define SMB_negrNTLM_sk_offset  48        /* Session Key             */
230 #define SMB_negrNTLM_cap_offset 52        /* Capabilities            */
231 #define SMB_negrNTLM_stl_offset 56        /* Server time low         */
232 #define SMB_negrNTLM_sth_offset 60        /* Server time high        */
233 #define SMB_negrNTLM_stz_offset 64        /* Server time zone        */
234 #define SMB_negrNTLM_ekl_offset 66        /* Encrypt key len         */
235 #define SMB_negrNTLM_bcc_offset 67        /* Bcc                     */
236 #define SMB_negrNTLM_len        69
237 #define SMB_negrNTLM_buf_offset 69
238
239 /* Offsets related to Tree Connect                                      */
240
241 #define SMB_tcon_bcc_offset     33
242 #define SMB_tcon_buf_offset     35        /* where the data is for tcon */
243 #define SMB_tcon_len            35        /* plus the data              */
244
245 #define SMB_tconr_mbs_offset    33        /* max buffer size         */
246 #define SMB_tconr_tid_offset    35        /* returned tree id        */
247 #define SMB_tconr_bcc_offset    37
248 #define SMB_tconr_len           39
249
250 #define SMB_tconx_axc_offset    33        /* And X Command                */
251 #define SMB_tconx_axr_offset    34        /* reserved                     */
252 #define SMB_tconx_axo_offset    35        /* Next command offset          */
253 #define SMB_tconx_flg_offset    37        /* Flags, bit0=1 means disc TID */
254 #define SMB_tconx_pwl_offset    39        /* Password length              */
255 #define SMB_tconx_bcc_offset    41        /* bcc                          */
256 #define SMB_tconx_buf_offset    43        /* buffer                       */
257 #define SMB_tconx_len           43        /* up to data ...               */
258
259 #define SMB_tconxr_axc_offset   33        /* Where the AndX Command is    */
260 #define SMB_tconxr_axr_offset   34        /* Reserved                     */
261 #define SMB_tconxr_axo_offset   35        /* AndX offset location         */
262
263 /* Offsets related to tree_disconnect                                  */
264
265 #define SMB_tdis_bcc_offset     33        /* bcc                     */
266 #define SMB_tdis_len            35        /* total len               */
267
268 #define SMB_tdisr_bcc_offset    33        /* bcc                     */
269 #define SMB_tdisr_len           35
270
271 /* Offsets related to Open Request                                     */
272
273 #define SMB_open_mod_offset     33        /* Mode to open with       */
274 #define SMB_open_atr_offset     35        /* Attributes of file      */
275 #define SMB_open_bcc_offset     37        /* bcc                     */
276 #define SMB_open_buf_offset     39        /* File name               */
277 #define SMB_open_len            39        /* Plus the file name      */
278
279 #define SMB_openx_axc_offset    33        /* Next command            */
280 #define SMB_openx_axr_offset    34        /* Reserved                */
281 #define SMB_openx_axo_offset    35        /* offset of next wct      */
282 #define SMB_openx_flg_offset    37        /* Flags, bit0 = need more info */
283                                           /* bit1 = exclusive oplock */
284                                           /* bit2 = batch oplock     */
285 #define SMB_openx_mod_offset    39        /* mode to open with       */
286 #define SMB_openx_atr_offset    41        /* search attributes       */
287 #define SMB_openx_fat_offset    43        /* File attributes         */
288 #define SMB_openx_tim_offset    45        /* time and date of creat  */
289 #define SMB_openx_ofn_offset    49        /* Open function           */
290 #define SMB_openx_als_offset    51        /* Space to allocate on    */
291 #define SMB_openx_res_offset    55        /* reserved                */
292 #define SMB_openx_bcc_offset    63        /* bcc                     */
293 #define SMB_openx_buf_offset    65        /* Where file name goes    */
294 #define SMB_openx_len           65
295
296 #define SMB_openr_fid_offset    33        /* FID returned            */
297 #define SMB_openr_atr_offset    35        /* Attributes opened with  */
298 #define SMB_openr_tim_offset    37        /* Last mod time of file   */
299 #define SMB_openr_fsz_offset    41        /* File size 4 bytes       */
300 #define SMB_openr_acc_offset    45        /* Access allowed          */
301 #define SMB_openr_bcc_offset    47
302 #define SMB_openr_len           49
303
304 #define SMB_openxr_axc_offset   33        /* And X command           */
305 #define SMB_openxr_axr_offset   34        /* reserved                */
306 #define SMB_openxr_axo_offset   35        /* offset to next command  */
307 #define SMB_openxr_fid_offset   37        /* FID returned            */
308 #define SMB_openxr_fat_offset   39        /* File attributes returned*/
309 #define SMB_openxr_tim_offset   41        /* File creation date etc  */
310 #define SMB_openxr_fsz_offset   45        /* Size of file            */
311 #define SMB_openxr_acc_offset   49        /* Access granted          */
312
313 #define SMB_clos_fid_offset     33        /* FID to close            */
314 #define SMB_clos_tim_offset     35        /* Last mod time           */
315 #define SMB_clos_bcc_offset     39        /* bcc                     */
316 #define SMB_clos_len            41
317
318 /* Offsets related to Write requests                                 */
319
320 #define SMB_write_fid_offset    33        /* FID to write            */
321 #define SMB_write_cnt_offset    35        /* bytes to write          */
322 #define SMB_write_ofs_offset    37        /* location to write to    */
323 #define SMB_write_clf_offset    41        /* advisory count left     */
324 #define SMB_write_bcc_offset    43        /* bcc = data bytes + 3    */
325 #define SMB_write_buf_offset    45        /* Data=0x01, len, data    */
326 #define SMB_write_len           45        /* plus the data ...       */
327
328 #define SMB_writr_cnt_offset    33        /* Count of bytes written  */
329 #define SMB_writr_bcc_offset    35        /* bcc                     */
330 #define SMB_writr_len           37
331
332 /* Offsets related to read requests */
333
334 #define SMB_read_fid_offset     33        /* FID of file to read     */
335 #define SMB_read_cnt_offset     35        /* count of words to read  */
336 #define SMB_read_ofs_offset     37        /* Where to read from      */
337 #define SMB_read_clf_offset     41        /* Advisory count to go    */
338 #define SMB_read_bcc_offset     43
339 #define SMB_read_len            45
340
341 #define SMB_readr_cnt_offset    33        /* Count of bytes returned */
342 #define SMB_readr_res_offset    35        /* 4 shorts reserved, 8 bytes */
343 #define SMB_readr_bcc_offset    43        /* bcc                     */
344 #define SMB_readr_bff_offset    45        /* buffer format char = 0x01 */
345 #define SMB_readr_len_offset    46        /* buffer len              */
346 #define SMB_readr_len           45        /* length of the readr before data */
347
348 /* Offsets for Create file                                           */
349
350 #define SMB_creat_atr_offset    33        /* Attributes of new file ... */
351 #define SMB_creat_tim_offset    35        /* Time of creation           */
352 #define SMB_creat_dat_offset    37        /* 4004BCE :-)                */
353 #define SMB_creat_bcc_offset    39        /* bcc                        */
354 #define SMB_creat_buf_offset    41
355 #define SMB_creat_len           41        /* Before the data            */
356
357 #define SMB_creatr_fid_offset   33        /* FID of created file        */
358
359 /* Offsets for Delete file                                           */
360
361 #define SMB_delet_sat_offset    33        /* search attribites          */
362 #define SMB_delet_bcc_offset    35        /* bcc                        */
363 #define SMB_delet_buf_offset    37
364 #define SMB_delet_len           37
365
366 /* Offsets for SESSION_SETUP_ANDX for both LM and NT LM protocols    */
367
368 #define SMB_ssetpLM_mbs_offset  37        /* Max buffer Size, allow for AndX */
369 #define SMB_ssetpLM_mmc_offset  39        /* max multiplex count             */
370 #define SMB_ssetpLM_vcn_offset  41        /* VC number if new VC             */
371 #define SMB_ssetpLM_snk_offset  43        /* Session Key                     */
372 #define SMB_ssetpLM_pwl_offset  47        /* password length                 */
373 #define SMB_ssetpLM_res_offset  49        /* reserved                        */
374 #define SMB_ssetpLM_bcc_offset  53        /* bcc                             */
375 #define SMB_ssetpLM_len         55        /* before data ...                 */
376 #define SMB_ssetpLM_buf_offset  55
377
378 #define SMB_ssetpNTLM_mbs_offset 37       /* Max Buffer Size for NT LM 0.12  */
379                                           /* and above                       */
380 #define SMB_ssetpNTLM_mmc_offset 39       /* Max Multiplex count             */
381 #define SMB_ssetpNTLM_vcn_offset 41       /* VC Number                       */
382 #define SMB_ssetpNTLM_snk_offset 43       /* Session key                     */
383 #define SMB_ssetpNTLM_cipl_offset 47      /* Case Insensitive PW Len         */
384 #define SMB_ssetpNTLM_cspl_offset 49      /* Unicode pw len                  */
385 #define SMB_ssetpNTLM_res_offset 51       /* reserved                        */
386 #define SMB_ssetpNTLM_cap_offset 55       /* server capabilities             */
387 #define SMB_ssetpNTLM_bcc_offset 59       /* bcc                             */
388 #define SMB_ssetpNTLM_len        61       /* before data                     */
389 #define SMB_ssetpNTLM_buf_offset 61
390
391 #define SMB_ssetpr_axo_offset  35         /* Offset of next response ...    */
392 #define SMB_ssetpr_act_offset  37         /* action, bit 0 = 1 => guest     */
393 #define SMB_ssetpr_bcc_offset  39         /* bcc                            */
394 #define SMB_ssetpr_buf_offset  41         /* Native OS etc                  */
395
396 /* Offsets for SMB create directory                                         */
397
398 #define SMB_creatdir_bcc_offset 33        /* only a bcc here                */
399 #define SMB_creatdir_buf_offset 35        /* Where things start             */
400 #define SMB_creatdir_len        35
401
402 /* Offsets for SMB delete directory                                         */
403
404 #define SMB_deletdir_bcc_offset 33        /* only a bcc here                */
405 #define SMB_deletdir_buf_offset 35        /* where things start             */
406 #define SMB_deletdir_len        35
407
408 /* Offsets for SMB check directory                                          */
409
410 #define SMB_checkdir_bcc_offset 33        /* Only a bcc here                */
411 #define SMB_checkdir_buf_offset 35        /* where things start             */
412 #define SMB_checkdir_len        35
413
414 /* Offsets for SMB search                                                   */
415
416 #define SMB_search_mdc_offset   33        /* Max Dir ents to return         */
417 #define SMB_search_atr_offset   35        /* Search attributes              */
418 #define SMB_search_bcc_offset   37        /* bcc                            */
419 #define SMB_search_buf_offset   39        /* where the action is            */
420 #define SMB_search_len          39
421
422 #define SMB_searchr_dec_offset  33        /* Dir ents returned              */
423 #define SMB_searchr_bcc_offset  35        /* bcc                            */
424 #define SMB_searchr_buf_offset  37        /* Where the action starts        */
425 #define SMB_searchr_len         37        /* before the dir ents            */
426
427 #define SMB_searchr_dirent_len  43        /* 53 bytes                       */
428
429 /* Defines for SMB transact and transact2 calls                             */
430
431 #define SMB_trans_tpc_offset    33        /* Total param count              */
432 #define SMB_trans_tdc_offset    35        /* total Data count               */
433 #define SMB_trans_mpc_offset    37        /* Max params bytes to return     */
434 #define SMB_trans_mdc_offset    39        /* Max data bytes to return       */
435 #define SMB_trans_msc_offset    41        /* Max setup words to return      */
436 #define SMB_trans_rs1_offset    42        /* Reserved byte                  */
437 #define SMB_trans_flg_offset    43        /* flags                          */
438 #define SMB_trans_tmo_offset    45        /* Timeout, long                  */
439 #define SMB_trans_rs2_offset    49        /* Next reserved                  */
440 #define SMB_trans_pbc_offset    51        /* Param Byte count in buf        */
441 #define SMB_trans_pbo_offset    53        /* Offset to param bytes          */
442 #define SMB_trans_dbc_offset    55        /* Data byte count in buf         */
443 #define SMB_trans_dbo_offset    57        /* Data byte offset               */
444 #define SMB_trans_suc_offset    59        /* Setup count - byte             */
445 #define SMB_trans_rs3_offset    60        /* Reserved to pad ...            */
446 #define SMB_trans_len           61        /* Up to setup, still need bcc    */
447
448 #define SMB_transr_tpc_offset   33        /* Total param bytes returned     */
449 #define SMB_transr_tdc_offset   35
450 #define SMB_transr_rs1_offset   37
451 #define SMB_transr_pbc_offset   39
452 #define SMB_transr_pbo_offset   41
453 #define SMB_transr_pdi_offset   43        /* parameter displacement         */
454 #define SMB_transr_dbc_offset   45
455 #define SMB_transr_dbo_offset   47
456 #define SMB_transr_ddi_offset   49
457 #define SMB_transr_suc_offset   51
458 #define SMB_transr_rs2_offset   52
459 #define SMB_transr_len          53
460
461 /* Bit masks for SMB Capabilities ...                       */
462
463 #define SMB_cap_raw_mode         0x0001
464 #define SMB_cap_mpx_mode         0x0002
465 #define SMB_cap_unicode          0x0004
466 #define SMB_cap_large_files      0x0008
467 #define SMB_cap_nt_smbs          0x0010
468 #define SMB_rpc_remote_apis      0x0020
469 #define SMB_cap_nt_status        0x0040
470 #define SMB_cap_level_II_oplocks 0x0080
471 #define SMB_cap_lock_and_read    0x0100
472 #define SMB_cap_nt_find          0x0200
473
474 /* SMB LANMAN api call defines */
475
476 #define SMB_LMapi_SetUserInfo     0x0072
477 #define SMB_LMapi_UserPasswordSet 0x0073
478
479 /* Structures and defines we use in the client interface */
480
481 /* The protocols we might support. Perhaps a bit ambitious, as only RFCNB */
482 /* has any support so far 0(sometimes called NBT)                         */
483
484 typedef enum {SMB_RFCNB, SMB_IPXNB, SMB_NETBEUI, SMB_X25} SMB_Transport_Types;
485
486 typedef enum {SMB_Con_FShare, SMB_Con_PShare, SMB_Con_IPC} SMB_Con_Types;
487
488 typedef enum {SMB_State_NoState, SMB_State_Stopped, SMB_State_Started} SMB_State_Types;
489
490 /* The following two arrays need to be in step!              */
491 /* We must make it possible for callers to specify these ... */
492
493
494 static const char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0",
495                             "MICROSOFT NETWORKS 1.03",
496                             "MICROSOFT NETWORKS 3.0",
497                             "DOS LANMAN1.0",
498                             "LANMAN1.0",
499                             "DOS LM1.2X002",
500                             "LM1.2X002",
501                             "DOS LANMAN2.1",
502                             "LANMAN2.1",
503                             "Samba",
504                             "NT LM 0.12",
505                             "NT LANMAN 1.0",
506                             NULL};
507
508 static const int SMB_Types[] = {SMB_P_Core,
509                           SMB_P_CorePlus,
510                           SMB_P_DOSLanMan1,
511                           SMB_P_DOSLanMan1,
512                           SMB_P_LanMan1,
513                           SMB_P_DOSLanMan2,
514                           SMB_P_LanMan2,
515                           SMB_P_LanMan2_1,
516                           SMB_P_LanMan2_1,
517                           SMB_P_NT1,
518                           SMB_P_NT1,
519                           SMB_P_NT1,
520                           -1};
521
522 typedef struct SMB_Status {
523
524   union {
525     struct {
526       unsigned char ErrorClass;
527       unsigned char Reserved;
528       unsigned short Error;
529     } DosError;
530     unsigned int NtStatus;
531   } status;
532 } SMB_Status;
533
534 typedef struct SMB_Tree_Structure * SMB_Tree_Handle;
535
536 typedef struct SMB_Connect_Def * SMB_Handle_Type;
537
538 struct SMB_Connect_Def {
539
540   SMB_Handle_Type Next_Con, Prev_Con;          /* Next and previous conn */
541   int protocol;                                /* What is the protocol   */
542   int prot_IDX;                                /* And what is the index  */
543   void *Trans_Connect;                         /* The connection         */
544
545   /* All these strings should be malloc'd */
546
547   char service[80], username[80], password[80], desthost[80], sock_options[80];
548   char address[80], myname[80];
549
550   SMB_Tree_Handle first_tree, last_tree;  /* List of trees on this server */
551
552   int gid;         /* Group ID, do we need it?                      */
553   int mid;         /* Multiplex ID? We might need one per con       */
554   int pid;         /* Process ID                                    */
555
556   int uid;         /* Authenticated user id.                        */
557
558                    /* It is pretty clear that we need to bust some of */
559                    /* these out into a per TCon record, as there may  */
560                    /* be multiple TCon's per server, etc ... later    */
561
562   int port;        /* port to use in case not default, this is a TCPism! */
563
564   int max_xmit;    /* Max xmit permitted by server                  */
565   int Security;    /* 0 = share, 1 = user                           */
566   int Raw_Support; /* bit 0 = 1 = Read Raw supported, 1 = 1 Write raw */
567   BOOL encrypt_passwords; /* FALSE = don't                          */
568   int MaxMPX, MaxVC, MaxRaw;
569   unsigned int SessionKey, Capabilities;
570   int SvrTZ;                                 /* Server Time Zone */
571   int Encrypt_Key_Len;
572   char Encrypt_Key[80], Domain[80], PDomain[80], OSName[80], LMType[40];
573   char Svr_OS[80], Svr_LMType[80], Svr_PDom[80];
574
575 };
576
577 #define SMBLIB_DEFAULT_DOMAIN "STAFF"
578 #define SMBLIB_DEFAULT_OSNAME "UNIX of some type"
579 #define SMBLIB_DEFAULT_LMTYPE "SMBlib LM2.1 minus a bit"
580 #define SMBLIB_MAX_XMIT 65535
581
582 #define SMB_Sec_Mode_Share 0
583 #define SMB_Sec_Mode_User  1
584
585 /* A Tree_Structure                       */
586
587 struct SMB_Tree_Structure {
588
589   SMB_Tree_Handle next, prev;
590   SMB_Handle_Type con;
591   char path[129];
592   char device_type[20];
593   int mbs;                   /* Local MBS */
594   int tid;
595
596 };
597
598 typedef struct SMB_File_Def SMB_File;
599
600 struct SMB_File_Def {
601
602   SMB_Tree_Handle tree;
603   char filename[256];          /* We should malloc this ... */
604   UWORD fid;
605   unsigned int lastmod;
606   unsigned int size;           /* Could blow up if 64bit files supported */
607   UWORD access;
608   off_t fileloc;
609
610 };
611
612 /* global Variables for the library */
613
614 extern SMB_State_Types SMBlib_State;
615
616 #ifndef SMBLIB_ERRNO
617 extern int SMBlib_errno;
618 extern int SMBlib_SMB_Error;          /* last Error             */
619 #endif
620
621 SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con, SMB_Tree_Handle tree,
622                                 char *path, char *password, char *dev);