chiark / gitweb /
get sense of ferror check right
[inn-innduct.git] / authprogs / smbval / 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 "smblib-common.h"
27 #include <sys/types.h>
28 #include <unistd.h>
29
30 typedef unsigned short uint16;
31 typedef unsigned int   uint32;
32
33 #include "byteorder.h"     /* Hmmm ... hot good */
34
35 #define SMB_DEF_IDF 0x424D53FF        /* "\377SMB" */
36  
37 /* The protocol commands and constants we need */
38 #define SMBnegprot    0x72   /* negotiate protocol */
39 #define SMBsesssetupX 0x73   /* Session Set Up & X (including User Logon) */
40 #define SMBdialectID  0x02   /* a dialect id */
41
42 typedef unsigned short WORD;
43 typedef unsigned short UWORD;
44 typedef unsigned int ULONG;
45 typedef unsigned char BYTE;
46 typedef unsigned char UCHAR;
47
48 /* Some macros to allow access to actual packet data so that we */
49 /* can change the underlying representation of packets.         */
50 /*                                                              */
51 /* The current formats vying for attention are a fragment       */
52 /* approach where the SMB header is a fragment linked to the    */
53 /* data portion with the transport protocol (rfcnb or whatever) */
54 /* being linked on the front.                                   */
55 /*                                                              */
56 /* The other approach is where the whole packet is one array    */
57 /* of bytes with space allowed on the front for the packet      */
58 /* headers.                                                     */
59
60 #define SMB_Hdr(p) (char *)(p -> data)
61
62 /* SMB Hdr def for File Sharing Protocol? From MS and Intel,    */
63 /* Intel PN 138446 Doc Version 2.0, Nov 7, 1988. This def also  */
64 /* applies to LANMAN1.0 as well as the Core Protocol            */
65 /* The spec states that wct and bcc must be present, even if 0  */
66
67 /* We define these as offsets into a char SMB[] array for the   */
68 /* sake of portability                                          */
69
70 /* NOTE!. Some of the lenght defines, SMB_<protreq>_len do not include */
71 /* the data that follows in the SMB packet, so the code will have to   */
72 /* take that into account.                                             */
73
74 #define SMB_hdr_idf_offset    0          /* 0xFF,'SMB' 0-3 */
75 #define SMB_hdr_com_offset    4          /* BYTE       4   */
76 #define SMB_hdr_rcls_offset   5          /* BYTE       5   */
77 #define SMB_hdr_reh_offset    6          /* BYTE       6   */
78 #define SMB_hdr_err_offset    7          /* WORD       7   */
79 #define SMB_hdr_reb_offset    9          /* BYTE       9   */
80 #define SMB_hdr_flg_offset    9          /* same as reb ...*/
81 #define SMB_hdr_res_offset    10         /* 7 WORDs    10  */
82 #define SMB_hdr_res0_offset   10         /* WORD       10  */
83 #define SMB_hdr_flg2_offset   10         /* WORD           */
84 #define SMB_hdr_res1_offset   12         /* WORD       12  */
85 #define SMB_hdr_res2_offset   14
86 #define SMB_hdr_res3_offset   16
87 #define SMB_hdr_res4_offset   18
88 #define SMB_hdr_res5_offset   20
89 #define SMB_hdr_res6_offset   22
90 #define SMB_hdr_tid_offset    24
91 #define SMB_hdr_pid_offset    26
92 #define SMB_hdr_uid_offset    28
93 #define SMB_hdr_mid_offset    30
94 #define SMB_hdr_wct_offset    32
95
96 #define SMB_hdr_len           33        /* 33 byte header?      */
97
98 #define SMB_hdr_axc_offset    33        /* AndX Command         */
99 #define SMB_hdr_axr_offset    34        /* AndX Reserved        */
100 #define SMB_hdr_axo_offset    35     /* Offset from start to WCT of AndX cmd */
101
102 /* Format of the Negotiate Protocol SMB */
103
104 #define SMB_negp_bcc_offset   33
105 #define SMB_negp_buf_offset   35        /* Where the buffer starts   */
106 #define SMB_negp_len          35        /* plus the data             */
107
108 /* Format of the Negotiate Response SMB, for CoreProtocol, LM1.2 and */
109 /* NT LM 0.12. wct will be 1 for CoreProtocol, 13 for LM 1.2, and 17 */
110 /* for NT LM 0.12                                                    */
111
112 #define SMB_negrCP_idx_offset   33        /* Response to the neg req */
113 #define SMB_negrCP_bcc_offset   35
114 #define SMB_negrLM_idx_offset   33        /* dialect index           */
115 #define SMB_negrLM_sec_offset   35        /* Security mode           */
116 #define SMB_sec_user_mask       0x01      /* 0 = share, 1 = user     */
117 #define SMB_sec_encrypt_mask    0x02      /* pick out encrypt        */
118 #define SMB_negrLM_mbs_offset   37        /* max buffer size         */
119 #define SMB_negrLM_mmc_offset   39        /* max mpx count           */
120 #define SMB_negrLM_mnv_offset   41        /* max number of VCs       */
121 #define SMB_negrLM_rm_offset    43        /* raw mode support bit vec*/
122 #define SMB_negrLM_sk_offset    45        /* session key, 32 bits    */
123 #define SMB_negrLM_st_offset    49        /* Current server time     */
124 #define SMB_negrLM_sd_offset    51        /* Current server date     */
125 #define SMB_negrLM_stz_offset   53        /* Server Time Zone        */
126 #define SMB_negrLM_ekl_offset   55        /* encryption key length   */
127 #define SMB_negrLM_res_offset   57        /* reserved                */
128 #define SMB_negrLM_bcc_offset   59        /* bcc                     */
129 #define SMB_negrLM_len          61        /* 61 bytes ?              */
130 #define SMB_negrLM_buf_offset   61        /* Where the fun begins    */
131
132 #define SMB_negrNTLM_idx_offset 33        /* Selected protocol       */
133 #define SMB_negrNTLM_sec_offset 35        /* Security more           */
134 #define SMB_negrNTLM_mmc_offset 36        /* Different format above  */
135 #define SMB_negrNTLM_mnv_offset 38        /* Max VCs                 */
136 #define SMB_negrNTLM_mbs_offset 40        /* MBS now a long          */
137 #define SMB_negrNTLM_mrs_offset 44        /* Max raw size            */
138 #define SMB_negrNTLM_sk_offset  48        /* Session Key             */
139 #define SMB_negrNTLM_cap_offset 52        /* Capabilities            */
140 #define SMB_negrNTLM_stl_offset 56        /* Server time low         */
141 #define SMB_negrNTLM_sth_offset 60        /* Server time high        */
142 #define SMB_negrNTLM_stz_offset 64        /* Server time zone        */
143 #define SMB_negrNTLM_ekl_offset 66        /* Encrypt key len         */
144 #define SMB_negrNTLM_bcc_offset 67        /* Bcc                     */
145 #define SMB_negrNTLM_len        69
146 #define SMB_negrNTLM_buf_offset 69
147
148 /* Offsets for Delete file                                           */
149
150 #define SMB_delet_sat_offset    33        /* search attribites          */
151 #define SMB_delet_bcc_offset    35        /* bcc                        */
152 #define SMB_delet_buf_offset    37
153 #define SMB_delet_len           37
154
155 /* Offsets for SESSION_SETUP_ANDX for both LM and NT LM protocols    */
156
157 #define SMB_ssetpLM_mbs_offset  37        /* Max buffer Size, allow for AndX */
158 #define SMB_ssetpLM_mmc_offset  39        /* max multiplex count             */
159 #define SMB_ssetpLM_vcn_offset  41        /* VC number if new VC             */
160 #define SMB_ssetpLM_snk_offset  43        /* Session Key                     */
161 #define SMB_ssetpLM_pwl_offset  47        /* password length                 */
162 #define SMB_ssetpLM_res_offset  49        /* reserved                        */
163 #define SMB_ssetpLM_bcc_offset  53        /* bcc                             */
164 #define SMB_ssetpLM_len         55        /* before data ...                 */
165 #define SMB_ssetpLM_buf_offset  55
166
167 #define SMB_ssetpNTLM_mbs_offset 37       /* Max Buffer Size for NT LM 0.12  */
168                                           /* and above                       */
169 #define SMB_ssetpNTLM_mmc_offset 39       /* Max Multiplex count             */
170 #define SMB_ssetpNTLM_vcn_offset 41       /* VC Number                       */
171 #define SMB_ssetpNTLM_snk_offset 43       /* Session key                     */
172 #define SMB_ssetpNTLM_cipl_offset 47      /* Case Insensitive PW Len         */
173 #define SMB_ssetpNTLM_cspl_offset 49      /* Unicode pw len                  */
174 #define SMB_ssetpNTLM_res_offset 51       /* reserved                        */
175 #define SMB_ssetpNTLM_cap_offset 55       /* server capabilities             */
176 #define SMB_ssetpNTLM_bcc_offset 59       /* bcc                             */
177 #define SMB_ssetpNTLM_len        61       /* before data                     */
178 #define SMB_ssetpNTLM_buf_offset 61
179
180 #define SMB_ssetpr_axo_offset  35         /* Offset of next response ...    */
181 #define SMB_ssetpr_act_offset  37         /* action, bit 0 = 1 => guest     */
182 #define SMB_ssetpr_bcc_offset  39         /* bcc                            */
183 #define SMB_ssetpr_buf_offset  41         /* Native OS etc                  */
184
185 /* The following two arrays need to be in step!              */
186 /* We must make it possible for callers to specify these ... */
187
188 extern const char *SMB_Prots[];
189 extern int SMB_Types[];
190
191 typedef struct SMB_Connect_Def * SMB_Handle_Type;
192
193 struct SMB_Connect_Def {
194
195   SMB_Handle_Type Next_Con, Prev_Con;          /* Next and previous conn */
196   int protocol;                                /* What is the protocol   */
197   int prot_IDX;                                /* And what is the index  */
198   void *Trans_Connect;                         /* The connection         */
199
200   /* All these strings should be malloc'd */
201
202   char service[80], username[80], password[80], desthost[80], sock_options[80];
203   char address[80], myname[80];
204
205   int gid;         /* Group ID, do we need it?                      */
206   int mid;         /* Multiplex ID? We might need one per con       */
207   int pid;         /* Process ID                                    */
208
209   int uid;         /* Authenticated user id.                        */
210
211                    /* It is pretty clear that we need to bust some of */
212                    /* these out into a per TCon record, as there may  */
213                    /* be multiple TCon's per server, etc ... later    */
214
215   int port;        /* port to use in case not default, this is a TCPism! */
216
217   int max_xmit;    /* Max xmit permitted by server                  */
218   int Security;    /* 0 = share, 1 = user                           */
219   int Raw_Support; /* bit 0 = 1 = Read Raw supported, 1 = 1 Write raw */
220   bool encrypt_passwords; /* false = don't                          */ 
221   int MaxMPX, MaxVC, MaxRaw;
222   unsigned int SessionKey, Capabilities;
223   int SvrTZ;                                 /* Server Time Zone */
224   int Encrypt_Key_Len;
225   char Encrypt_Key[80], Domain[80], PDomain[80], OSName[80], LMType[40];
226   char Svr_OS[80], Svr_LMType[80], Svr_PDom[80];
227
228 };
229
230 #define SMBLIB_DEFAULT_OSNAME "UNIX of some type"
231 #define SMBLIB_DEFAULT_LMTYPE "SMBlib LM2.1 minus a bit"
232 #define SMBLIB_MAX_XMIT 65535
233
234 /* global Variables for the library */
235
236 #ifndef SMBLIB_ERRNO
237 extern int SMBlib_errno;
238 extern int SMBlib_SMB_Error;          /* last Error             */
239 #endif
240
241 /* From smbdes.c. */
242 void E_P16(unsigned char *, unsigned char *);
243 void E_P24(unsigned char *, unsigned char *, unsigned char *);
244
245 /* From smblib-util.c. */
246 void SMB_Get_My_Name(char *name, int len);
247
248 /* From smbencrypt.c. */
249 void SMBencrypt(unsigned char *passwd, unsigned char *, unsigned char *);