2 Unix SMB/Netbios implementation.
4 SMB parameters and setup
5 Copyright (C) Andrew Tridgell 1992-1997
6 Copyright (C) John H Terpstra 1996-1997
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
8 Copyright (C) Paul Ashton 1997
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define BUFFER_SIZE (0xFFFF)
28 #define SAFETY_MARGIN 1024
30 /* Default size of shared memory used for share mode locking */
32 #define SHMEM_SIZE 102400
36 #define DGRAM_PORT 138
41 #define BOOLSTR(b) ((b) ? "Yes" : "No")
42 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
43 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
44 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
48 /* limiting size of ipc replies */
49 #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
52 Samba needs type definitions for int16, int32, uint16 and uint32.
54 Normally these are signed and unsigned 16 and 32 bit integers, but
55 they actually only need to be at least 16 and 32 bits
56 respectively. Thus if your word size is 8 bytes just defining them
57 as signed and unsigned int will work.
60 /* afs/stds.h defines int16 and int32 */
67 typedef unsigned char uint8;
71 typedef unsigned short uint16;
75 typedef unsigned int uint32;
79 #define uchar unsigned char
85 #define uint16 unsigned short
88 #define uint32 unsigned int
93 #ifndef DEF_CREATE_MASK
94 #define DEF_CREATE_MASK (0755)
97 /* how long to wait for secondary SMB packets (milli-seconds) */
98 #define SMB_SECONDARY_WAIT (60*1000)
102 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
104 extern int syslog_level;
106 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? (syslog_level = (level), Debug1 body):0)
109 /* this defines the error codes that receive_smb can put in smb_read_error */
110 #define READ_TIMEOUT 1
115 #define DIR_STRUCT_SIZE 43
117 /* these define all the command types recognised by the server - there
118 are lots of gaps so probably there are some rare commands that are not
121 #define pSETDIR '\377'
123 /* these define the attribute byte as seen by DOS */
124 #define aRONLY (1L<<0)
125 #define aHIDDEN (1L<<1)
126 #define aSYSTEM (1L<<2)
127 #define aVOLID (1L<<3)
129 #define aARCH (1L<<5)
140 #define STYPE_DISKTREE 0 /* Disk drive */
141 #define STYPE_PRINTQ 1 /* Spooler queue */
142 #define STYPE_DEVICE 2 /* Serial device */
143 #define STYPE_IPC 3 /* Interprocess communication (IPC) */
144 #define STYPE_HIDDEN 0x80000000 /* share is a hidden one (ends with $) */
146 /* SMB X/Open error codes for the ERRdos error class */
147 #define ERRbadfunc 1 /* Invalid function (or system call) */
148 #define ERRbadfile 2 /* File not found (pathname error) */
149 #define ERRbadpath 3 /* Directory not found */
150 #define ERRnofids 4 /* Too many open files */
151 #define ERRnoaccess 5 /* Access denied */
152 #define ERRbadfid 6 /* Invalid fid */
153 #define ERRnomem 8 /* Out of memory */
154 #define ERRbadmem 9 /* Invalid memory block address */
155 #define ERRbadenv 10 /* Invalid environment */
156 #define ERRbadaccess 12 /* Invalid open mode */
157 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
158 #define ERRres 14 /* reserved */
159 #define ERRbaddrive 15 /* Invalid drive */
160 #define ERRremcd 16 /* Attempt to delete current directory */
161 #define ERRdiffdevice 17 /* rename/move across different filesystems */
162 #define ERRnofiles 18 /* no more files found in file search */
163 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
164 #define ERRlock 33 /* Lock request conflicts with existing lock */
165 #define ERRfilexists 80 /* File in operation already exists */
166 #define ERRcannotopen 110 /* Cannot open the file specified */
167 #define ERRunknownlevel 124
168 #define ERRbadpipe 230 /* Named pipe invalid */
169 #define ERRpipebusy 231 /* All instances of pipe are busy */
170 #define ERRpipeclosing 232 /* named pipe close in progress */
171 #define ERRnotconnected 233 /* No process on other end of named pipe */
172 #define ERRmoredata 234 /* More data to be returned */
173 #define ERRbaddirectory 267 /* Invalid directory name in a path. */
174 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
175 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
176 #define ERRunknownipc 2142
179 /* here's a special one from observing NT */
180 #define ERRnoipc 66 /* don't support ipc */
182 /* Error codes for the ERRSRV class */
184 #define ERRerror 1 /* Non specific error code */
185 #define ERRbadpw 2 /* Bad password */
186 #define ERRbadtype 3 /* reserved */
187 #define ERRaccess 4 /* No permissions to do the requested operation */
188 #define ERRinvnid 5 /* tid invalid */
189 #define ERRinvnetname 6 /* Invalid servername */
190 #define ERRinvdevice 7 /* Invalid device */
191 #define ERRqfull 49 /* Print queue full */
192 #define ERRqtoobig 50 /* Queued item too big */
193 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
194 #define ERRsmbcmd 64 /* Unrecognised command */
195 #define ERRsrverror 65 /* smb server internal error */
196 #define ERRfilespecs 67 /* fid and pathname invalid combination */
197 #define ERRbadlink 68 /* reserved */
198 #define ERRbadpermits 69 /* Access specified for a file is not valid */
199 #define ERRbadpid 70 /* reserved */
200 #define ERRsetattrmode 71 /* attribute mode invalid */
201 #define ERRpaused 81 /* Message server paused */
202 #define ERRmsgoff 82 /* Not receiving messages */
203 #define ERRnoroom 83 /* No room for message */
204 #define ERRrmuns 87 /* too many remote usernames */
205 #define ERRtimeout 88 /* operation timed out */
206 #define ERRnoresource 89 /* No resources currently available for request. */
207 #define ERRtoomanyuids 90 /* too many userids */
208 #define ERRbaduid 91 /* bad userid */
209 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
210 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
211 #define ERRcontMPX 252 /* resume MPX mode */
212 #define ERRbadPW /* reserved */
213 #define ERRnosupport 0xFFFF
214 #define ERRunknownsmb 22 /* from NT 3.5 response */
217 /* Error codes for the ERRHRD class */
219 #define ERRnowrite 19 /* read only media */
220 #define ERRbadunit 20 /* Unknown device */
221 #define ERRnotready 21 /* Drive not ready */
222 #define ERRbadcmd 22 /* Unknown command */
223 #define ERRdata 23 /* Data (CRC) error */
224 #define ERRbadreq 24 /* Bad request structure length */
226 #define ERRbadmedia 26
227 #define ERRbadsector 27
228 #define ERRnopaper 28
229 #define ERRwrite 29 /* write fault */
230 #define ERRread 30 /* read fault */
231 #define ERRgeneral 31 /* General hardware failure */
232 #define ERRwrongdisk 34
233 #define ERRFCBunavail 35
234 #define ERRsharebufexc 36 /* share buffer exceeded */
235 #define ERRdiskfull 39
238 typedef char pstring[1024];
239 typedef char fstring[128];
240 typedef fstring string;
244 #define PIPE_LANMAN "\\PIPE\\LANMAN"
245 #define PIPE_SRVSVC "\\PIPE\\srvsvc"
246 #define PIPE_SAMR "\\PIPE\\samr"
247 #define PIPE_WKSSVC "\\PIPE\\wkssvc"
248 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
249 #define PIPE_NTLSA "\\PIPE\\ntlsa"
250 #define PIPE_NTSVCS "\\PIPE\\ntsvcs"
251 #define PIPE_LSASS "\\PIPE\\lsass"
252 #define PIPE_LSARPC "\\PIPE\\lsarpc"
254 /* NETLOGON opcodes and data structures */
264 #define NET_QUERYFORPDC 7 /* Query for PDC */
265 #define NET_QUERYFORPDC_R 12 /* Response to Query for PDC */
266 #define NET_SAMLOGON 18
267 #define NET_SAMLOGON_R 19
269 /* Allowable account control bits */
270 #define ACB_DISABLED 1 /* 1 = User account disabled */
271 #define ACB_HOMDIRREQ 2 /* 1 = Home directory required */
272 #define ACB_PWNOTREQ 4 /* 1 = User password not required */
273 #define ACB_TEMPDUP /* 1 = Temporary duplicate account */
274 #define ACB_NORMAL /* 1 = Normal user account */
275 #define ACB_MNS /* 1 = MNS logon user account */
276 #define ACB_DOMTRUST /* 1 = Interdomain trust account */
277 #define ACB_WSTRUST /* 1 = Workstation trust account */
278 #define ACB_SVRTRUST /* 1 = Server trust account */
279 #define ACB_PWNOEXP /* 1 = User password does not expire */
280 #define ACB_AUTOLOCK /* 1 = Account auto locked */
282 #define SAMR_CLOSE 0x01
283 #define SAMR_OPEN_SECRET 0x07
284 #define SAMR_LOOKUP_RIDS 0x11
285 #define SAMR_UNKNOWN_3 0x03
286 #define SAMR_UNKNOWN_22 0x22
287 #define SAMR_UNKNOWN_24 0x24
288 #define SAMR_UNKNOWN_34 0x34
289 #define SAMR_OPEN_POLICY 0x39
291 #define LSA_OPENPOLICY 0x2c
292 #define LSA_QUERYINFOPOLICY 0x07
293 #define LSA_ENUMTRUSTDOM 0x0d
294 #define LSA_REQCHAL 0x04
295 #define LSA_SRVPWSET 0x06
296 #define LSA_SAMLOGON 0x02
297 #define LSA_SAMLOGOFF 0x03
298 #define LSA_AUTH2 0x0f
299 #define LSA_CLOSE 0x00
301 /* XXXX these are here to get a compile! */
303 #define LSA_OPENSECRET 0xFF
304 #define LSA_LOOKUPSIDS 0xFE
305 #define LSA_LOOKUPRIDS 0xFD
306 #define LSA_LOOKUPNAMES 0xFC
309 #define NETSERVERGETINFO 0x15
310 #define NETSHAREENUM 0x0f
312 /* well-known RIDs - Relative IDs */
314 /* RIDs - Well-known users ... */
315 #define DOMAIN_USER_RID_ADMIN (0x000001F4L)
316 #define DOMAIN_USER_RID_GUEST (0x000001F5L)
318 /* RIDs - well-known groups ... */
319 #define DOMAIN_GROUP_RID_ADMINS (0x00000200L)
320 #define DOMAIN_GROUP_RID_USERS (0x00000201L)
321 #define DOMAIN_GROUP_RID_GUESTS (0x00000202L)
323 /* RIDs - well-known aliases ... */
324 #define DOMAIN_ALIAS_RID_ADMINS (0x00000220L)
325 #define DOMAIN_ALIAS_RID_USERS (0x00000221L)
326 #define DOMAIN_ALIAS_RID_GUESTS (0x00000222L)
327 #define DOMAIN_ALIAS_RID_POWER_USERS (0x00000223L)
329 #define DOMAIN_ALIAS_RID_ACCOUNT_OPS (0x00000224L)
330 #define DOMAIN_ALIAS_RID_SYSTEM_OPS (0x00000225L)
331 #define DOMAIN_ALIAS_RID_PRINT_OPS (0x00000226L)
332 #define DOMAIN_ALIAS_RID_BACKUP_OPS (0x00000227L)
334 #define DOMAIN_ALIAS_RID_REPLICATOR (0x00000228L)
338 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
339 typedef struct time_info
345 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
346 typedef struct nttime_info
354 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
356 /* DOM_SID - security id */
357 typedef struct sid_info
359 uint8 sid_rev_num; /* SID revision number */
360 uint8 num_auths; /* number of sub-authorities */
361 uint8 id_auth[6]; /* Identifier Authority */
362 uint32 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */
366 /* UNIHDR - unicode string header */
367 typedef struct unihdr_info
371 uint32 undoc; /* usually has a value of 4 */
375 /* UNIHDR2 - unicode string header and undocumented buffer */
376 typedef struct unihdr2_info
379 uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */
383 /* clueless as to what maximum length should be */
384 #define MAX_UNISTRLEN 1024
386 /* UNISTR - unicode string size and buffer */
387 typedef struct unistr_info
389 uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */
393 /* UNISTR2 - unicode string size and buffer */
394 typedef struct unistr2_info
399 uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */
403 /* DOM_SID2 - domain SID structure - SIDs stored in unicode */
404 typedef struct domsid2_info
406 uint32 type; /* value is 5 */
407 uint32 undoc; /* value is 0 */
409 UNIHDR2 hdr; /* XXXX conflict between hdr and str for length */
410 UNISTR str; /* XXXX conflict between hdr and str for length */
414 /* DOM_RID2 - domain RID structure for ntlsa pipe */
415 typedef struct domrid2_info
417 uint32 type; /* value is 5 */
418 uint32 undoc; /* value is non-zero */
420 uint32 rid_idx; /* don't know what this is */
424 /* DOM_RID3 - domain RID structure for samr pipe */
425 typedef struct domrid3_info
427 uint32 rid; /* domain-relative (to a SID) id */
428 uint32 type1; /* value is 0x1 */
429 uint32 ptr_type; /* undocumented pointer */
430 uint32 type2; /* value is 0x1 */
434 /* DOM_CLNT_SRV - client / server names */
435 typedef struct clnt_srv_info
437 uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */
438 UNISTR2 uni_logon_srv; /* logon server name */
439 uint32 undoc_buffer2; /* undocumented 32 bit buffer pointer */
440 UNISTR2 uni_comp_name; /* client machine name */
444 /* DOM_LOG_INFO - login info */
445 typedef struct log_info
447 uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */
448 UNISTR2 uni_logon_srv; /* logon server name */
449 UNISTR2 uni_acct_name; /* account name */
450 uint16 sec_chan; /* secure channel type */
451 UNISTR2 uni_comp_name; /* client machine name */
455 /* DOM_CHAL - challenge info */
456 typedef struct chal_info
458 uchar data[8]; /* credentials */
461 /* DOM_CREDs - timestamped client or server credentials */
462 typedef struct cred_info
464 DOM_CHAL challenge; /* credentials */
465 UTIME timestamp; /* credential time-stamp */
469 /* DOM_CLNT_INFO - client info */
470 typedef struct clnt_info
477 /* DOM_CLNT_INFO2 - client info */
478 typedef struct clnt_info2
486 /* DOM_LOGON_ID - logon id */
487 typedef struct logon_info
495 typedef struct arc4_owf_info
503 typedef struct id_info_1
505 uint32 ptr_id_info1; /* pointer to id_info_1 */
506 UNIHDR hdr_domain_name; /* domain name unicode header */
507 uint32 param_ctrl; /* param control */
508 DOM_LOGON_ID logon_id; /* logon ID */
509 UNIHDR hdr_user_name; /* user name unicode header */
510 UNIHDR hdr_wksta_name; /* workgroup name unicode header */
511 ARC4_OWF arc4_lm_owf; /* arc4 LM OWF Password */
512 ARC4_OWF arc4_nt_owf; /* arc4 NT OWF Password */
513 UNISTR2 uni_domain_name; /* domain name unicode string */
514 UNISTR2 uni_user_name; /* user name unicode string */
515 UNISTR2 uni_wksta_name; /* workgroup name unicode string */
519 /* SAM_INFO - sam logon/off id structure */
520 typedef struct sam_info
522 DOM_CLNT_INFO2 client;
523 uint32 ptr_rtn_cred; /* pointer to return credentials */
524 DOM_CRED rtn_cred; /* return credentials */
530 DOM_ID_INFO_1 *id1; /* auth-level 1 */
536 /* DOM_GID - group id + user attributes */
537 typedef struct gid_info
539 uint32 g_rid; /* a group RID */
544 /* RPC_HDR - ms rpc header */
545 typedef struct rpc_hdr_info
547 uint8 major; /* 5 - RPC major version */
548 uint8 minor; /* 0 - RPC minor version */
549 uint8 pkt_type; /* 2 - RPC response packet */
550 uint8 frag; /* 3 - first frag + last frag */
551 uint32 pack_type; /* 0x1000 0000 - packed data representation */
552 uint16 frag_len; /* fragment length - data size (bytes) inc header and tail. */
553 uint16 auth_len; /* 0 - authentication length */
554 uint32 call_id; /* call identifier. matches 12th uint32 of incoming RPC data. */
558 /* RPC_HDR_RR - ms request / response rpc header */
559 typedef struct rpc_hdr_rr_info
563 uint32 alloc_hint; /* allocation hint - data size (bytes) minus header and tail. */
564 uint16 context_id; /* 0 - presentation context identifier */
565 uint8 cancel_count; /* 0 - cancel count */
566 uint8 opnum; /* request: 0 - reserved. response: opnum */
570 /* the interfaces are numbered. as yet I haven't seen more than one interface
571 * used on the same pipe name
573 * abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
574 * transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
577 typedef struct rpc_iface_info
579 uint8 data[16]; /* 16 bytes of number */
580 uint32 version; /* the interface number */
585 /* this seems to be the same string name depending on the name of the pipe,
586 * but is more likely to be linked to the interface name
587 * "srvsvc", "\\PIPE\\ntsvcs"
588 * "samr", "\\PIPE\\lsass"
589 * "wkssvc", "\\PIPE\\wksvcs"
590 * "NETLOGON", "\\PIPE\\NETLOGON"
593 typedef struct rpc_addr_info
595 uint16 len; /* length of the string including null terminator */
596 fstring str; /* the string above in single byte, null terminated form */
601 typedef struct rpc_hdr_bba_info
603 uint16 max_tsize; /* maximum transmission fragment size (0x1630) */
604 uint16 max_rsize; /* max receive fragment size (0x1630) */
605 uint32 assoc_gid; /* associated group id (0x0) */
609 /* RPC_BIND_REQ - ms req bind */
610 typedef struct rpc_bind_req_info
614 uint32 num_elements; /* the number of elements (0x1) */
615 uint16 context_id; /* presentation context identifier (0x0) */
616 uint8 num_syntaxes; /* the number of syntaxes (has always been 1?)(0x1) */
618 RPC_IFACE abstract; /* num and vers. of interface client is using */
619 RPC_IFACE transfer; /* num and vers. of interface to use for replies */
623 /* RPC_RESULTS - can only cope with one reason, right now... */
624 typedef struct rpc_results_info
626 /* uint8[] # 4-byte alignment padding, against SMB header */
628 uint8 num_results; /* the number of results (0x01) */
630 /* uint8[] # 4-byte alignment padding, against SMB header */
632 uint16 result; /* result (0x00 = accept) */
633 uint16 reason; /* reason (0x00 = no reason specified) */
638 typedef struct rpc_hdr_ba_info
642 RPC_ADDR_STR addr ; /* the secondary address string, as described earlier */
643 RPC_RESULTS res ; /* results and reasons */
644 RPC_IFACE transfer; /* the transfer syntax from the request */
649 /* DOM_QUERY - info class 3 and 5 LSA Query response */
650 typedef struct dom_query_info
652 uint16 uni_dom_max_len; /* domain name string length * 2 */
653 uint16 uni_dom_str_len; /* domain name string length * 2 */
654 uint32 buffer_dom_name; /* undocumented domain name string buffer pointer */
655 uint32 buffer_dom_sid; /* undocumented domain SID string buffer pointer */
656 UNISTR2 uni_domain_name; /* domain name (unicode string) */
657 DOM_SID dom_sid; /* domain SID */
661 /* level 5 is same as level 3. we hope. */
662 typedef DOM_QUERY DOM_QUERY_3;
663 typedef DOM_QUERY DOM_QUERY_5;
665 #define POL_HND_SIZE 20
668 typedef struct lsa_policy_info
670 uint8 data[POL_HND_SIZE]; /* policy handle */
674 /* OBJ_ATTR (object attributes) */
675 typedef struct object_attributes_info
677 uint32 len; /* 0x18 - length (in bytes) inc. the length field. */
678 uint32 ptr_root_dir; /* 0 - root directory (pointer) */
679 uint32 ptr_obj_name; /* 0 - object name (pointer) */
680 uint32 attributes; /* 0 - attributes (undocumented) */
681 uint32 ptr_sec_desc; /* 0 - security descriptior (pointer) */
682 uint32 sec_qos; /* 0 - security quality of service */
686 /* LSA_Q_OPEN_POL - LSA Query Open Policy */
687 typedef struct lsa_q_open_pol_info
689 uint32 ptr; /* undocumented buffer pointer */
690 UNISTR2 uni_server_name; /* server name, starting with two '\'s */
691 LSA_OBJ_ATTR attr ; /* object attributes */
693 uint32 des_access; /* desired access attributes */
697 /* LSA_R_OPEN_POL - response to LSA Open Policy */
698 typedef struct lsa_r_open_pol_info
700 LSA_POL_HND pol; /* policy handle */
702 uint32 status; /* return code */
706 /* LSA_Q_QUERY_INFO - LSA query info policy */
707 typedef struct lsa_query_info
709 LSA_POL_HND pol; /* policy handle */
710 uint16 info_class; /* info class */
714 /* LSA_R_QUERY_INFO - response to LSA query info policy */
715 typedef struct lsa_r_query_info
717 uint32 undoc_buffer; /* undocumented buffer pointer */
718 uint16 info_class; /* info class (same as info class in request) */
727 uint32 status; /* return code */
731 /* LSA_Q_ENUM_TRUST_DOM - LSA enumerate trusted domains */
732 typedef struct lsa_enum_trust_dom_info
734 LSA_POL_HND pol; /* policy handle */
735 uint32 enum_context; /* enumeration context handle */
736 uint32 preferred_len; /* preferred maximum length */
738 } LSA_Q_ENUM_TRUST_DOM;
740 /* LSA_R_ENUM_TRUST_DOM - response to LSA enumerate trusted domains */
741 typedef struct lsa_r_enum_trust_dom_info
743 LSA_POL_HND pol; /* policy handle */
745 uint32 status; /* return code */
747 } LSA_R_ENUM_TRUST_DOM;
750 typedef struct lsa_q_close_info
752 LSA_POL_HND pol; /* policy handle */
757 typedef struct lsa_r_close_info
759 LSA_POL_HND pol; /* policy handle. should be all zeros. */
761 uint32 status; /* return code */
766 #define MAX_REF_DOMAINS 10
769 typedef struct dom_ref_info
771 uint32 undoc_buffer; /* undocumented buffer pointer. */
772 uint32 num_ref_doms_1; /* num referenced domains? */
773 uint32 buffer_dom_name; /* undocumented domain name buffer pointer. */
774 uint32 max_entries; /* 32 - max number of entries */
775 uint32 num_ref_doms_2; /* 4 - num referenced domains? */
777 UNIHDR2 hdr_dom_name; /* domain name unicode string header */
778 UNIHDR2 hdr_ref_dom[MAX_REF_DOMAINS]; /* referenced domain unicode string headers */
780 UNISTR uni_dom_name; /* domain name unicode string */
781 DOM_SID ref_dom[MAX_REF_DOMAINS]; /* referenced domain SIDs */
785 #define MAX_LOOKUP_SIDS 10
787 /* LSA_Q_LOOKUP_SIDS - LSA Lookup SIDs */
788 typedef struct lsa_q_lookup_sids
790 LSA_POL_HND pol_hnd; /* policy handle */
792 uint32 buffer_dom_sid; /* undocumented domain SID buffer pointer */
793 uint32 buffer_dom_name; /* undocumented domain name buffer pointer */
794 uint32 buffer_lookup_sids[MAX_LOOKUP_SIDS]; /* undocumented domain SID pointers to be looked up. */
795 DOM_SID dom_sids[MAX_LOOKUP_SIDS]; /* domain SIDs to be looked up. */
796 uint8 undoc[16]; /* completely undocumented 16 bytes */
800 /* LSA_R_LOOKUP_SIDS - response to LSA Lookup SIDs */
801 typedef struct lsa_r_lookup_sids
803 DOM_R_REF dom_ref; /* domain reference info */
806 uint32 undoc_buffer; /* undocumented buffer pointer */
809 DOM_SID2 dom_sid[MAX_LOOKUP_SIDS]; /* domain SIDs being looked up */
813 uint32 status; /* return code */
817 /* DOM_NAME - XXXX not sure about this structure */
818 typedef struct dom_name_info
826 #define UNKNOWN_LEN 1
828 /* LSA_Q_LOOKUP_RIDS - LSA Lookup RIDs */
829 typedef struct lsa_q_lookup_rids
832 LSA_POL_HND pol_hnd; /* policy handle */
835 uint32 buffer_dom_sid; /* undocumented domain SID buffer pointer */
836 uint32 buffer_dom_name; /* undocumented domain name buffer pointer */
837 DOM_NAME lookup_name[MAX_LOOKUP_SIDS]; /* names to be looked up */
838 uint8 undoc[UNKNOWN_LEN]; /* completely undocumented bytes of unknown length */
842 /* LSA_R_LOOKUP_RIDS - response to LSA Lookup RIDs by name */
843 typedef struct lsa_r_lookup_rids
845 DOM_R_REF dom_ref; /* domain reference info */
848 uint32 undoc_buffer; /* undocumented buffer pointer */
851 DOM_RID2 dom_rid[MAX_LOOKUP_SIDS]; /* domain RIDs being looked up */
855 uint32 status; /* return code */
862 typedef struct lsa_neg_flags_info
864 uint32 neg_flags; /* negotiated flags */
870 typedef struct lsa_q_req_chal_info
872 uint32 undoc_buffer; /* undocumented buffer pointer */
873 UNISTR2 uni_logon_srv; /* logon server unicode string */
874 UNISTR2 uni_logon_clnt; /* logon client unicode string */
875 DOM_CHAL clnt_chal; /* client challenge */
881 typedef struct lsa_r_req_chal_info
883 DOM_CHAL srv_chal; /* server challenge */
885 uint32 status; /* return code */
892 typedef struct lsa_q_auth2_info
894 DOM_LOG_INFO clnt_id; /* client identification info */
895 DOM_CHAL clnt_chal; /* client-calculated credentials */
897 NEG_FLAGS clnt_flgs; /* usually 0x0000 01ff */
903 typedef struct lsa_r_auth2_info
905 DOM_CHAL srv_chal; /* server-calculated credentials */
906 NEG_FLAGS srv_flgs; /* usually 0x0000 01ff */
908 uint32 status; /* return code */
913 /* LSA_Q_SRV_PWSET */
914 typedef struct lsa_q_srv_pwset_info
916 DOM_CLNT_INFO clnt_id; /* client identification/authentication info */
917 char pwd[16]; /* new password - undocumented. */
921 /* LSA_R_SRV_PWSET */
922 typedef struct lsa_r_srv_pwset_info
924 DOM_CRED srv_cred; /* server-calculated credentials */
926 uint32 status; /* return code */
930 #define LSA_MAX_GROUPS 32
931 #define LSA_MAX_SIDS 32
934 typedef struct lsa_q_user_info
936 uint32 ptr_user_info;
938 NTTIME logon_time; /* logon time */
939 NTTIME logoff_time; /* logoff time */
940 NTTIME kickoff_time; /* kickoff time */
941 NTTIME pass_last_set_time; /* password last set time */
942 NTTIME pass_can_change_time; /* password can change time */
943 NTTIME pass_must_change_time; /* password must change time */
945 UNIHDR hdr_user_name; /* username unicode string header */
946 UNIHDR hdr_full_name; /* user's full name unicode string header */
947 UNIHDR hdr_logon_script; /* logon script unicode string header */
948 UNIHDR hdr_profile_path; /* profile path unicode string header */
949 UNIHDR hdr_home_dir; /* home directory unicode string header */
950 UNIHDR hdr_dir_drive; /* home directory drive unicode string header */
952 uint16 logon_count; /* logon count */
953 uint16 bad_pw_count; /* bad password count */
955 uint32 user_id; /* User ID */
956 uint32 group_id; /* Group ID */
957 uint32 num_groups; /* num groups */
958 uint32 buffer_groups; /* undocumented buffer pointer to groups. */
959 uint32 user_flgs; /* user flags */
961 char user_sess_key[16]; /* unused user session key */
963 UNIHDR hdr_logon_srv; /* logon server unicode string header */
964 UNIHDR hdr_logon_dom; /* logon domain unicode string header */
966 uint32 buffer_dom_id; /* undocumented logon domain id pointer */
967 char padding[40]; /* unused padding bytes. expansion room */
969 uint32 num_other_sids; /* 0 - num_sids */
970 uint32 buffer_other_sids; /* NULL - undocumented pointer to SIDs. */
972 UNISTR2 uni_user_name; /* username unicode string */
973 UNISTR2 uni_full_name; /* user's full name unicode string */
974 UNISTR2 uni_logon_script; /* logon script unicode string */
975 UNISTR2 uni_profile_path; /* profile path unicode string */
976 UNISTR2 uni_home_dir; /* home directory unicode string */
977 UNISTR2 uni_dir_drive; /* home directory drive unicode string */
979 uint32 num_groups2; /* num groups */
980 DOM_GID gids[LSA_MAX_GROUPS]; /* group info */
982 UNISTR2 uni_logon_srv; /* logon server unicode string */
983 UNISTR2 uni_logon_dom; /* logon domain unicode string */
985 DOM_SID dom_sid; /* domain SID */
986 DOM_SID other_sids[LSA_MAX_SIDS]; /* undocumented - domain SIDs */
991 /* LSA_Q_SAM_LOGON */
992 typedef struct lsa_q_sam_logon_info
998 /* LSA_R_SAM_LOGON */
999 typedef struct lsa_r_sam_logon_info
1001 uint32 buffer_creds; /* undocumented buffer pointer */
1002 DOM_CRED srv_creds; /* server credentials. server time stamp appears to be ignored. */
1004 uint16 switch_value; /* 3 - indicates type of USER INFO */
1005 LSA_USER_INFO *user;
1007 uint32 auth_resp; /* 1 - Authoritative response; 0 - Non-Auth? */
1009 uint32 status; /* return code */
1014 /* LSA_Q_SAM_LOGOFF */
1015 typedef struct lsa_q_sam_logoff_info
1017 DOM_SAM_INFO sam_id;
1021 /* LSA_R_SAM_LOGOFF */
1022 typedef struct lsa_r_sam_logoff_info
1024 uint32 buffer_creds; /* undocumented buffer pointer */
1025 DOM_CRED srv_creds; /* server credentials. server time stamp appears to be ignored. */
1027 uint32 status; /* return code */
1032 /* SH_INFO_1 (pointers to level 1 share info strings) */
1033 typedef struct ptr_share_info1
1035 uint32 ptr_netname; /* pointer to net name. */
1036 uint32 type; /* type of share. 0 - undocumented. */
1037 uint32 ptr_remark; /* pointer to comment. */
1041 /* SH_INFO_1_STR (level 1 share info strings) */
1042 typedef struct str_share_info1
1044 UNISTR2 uni_netname; /* unicode string of net name */
1045 UNISTR2 uni_remark; /* unicode string of comment. */
1049 /* oops - this is going to take up a *massive* amount of stack. */
1050 /* the UNISTR2s already have 1024 uint16 chars in them... */
1051 #define MAX_SHARE_ENTRIES 32
1053 /* SHARE_INFO_1_CONTAINER */
1054 typedef struct share_info_ctr
1056 uint32 num_entries_read; /* EntriesRead */
1057 uint32 ptr_share_info; /* Buffer */
1058 uint32 num_entries_read2; /* EntriesRead */
1059 SH_INFO_1 info_1 [MAX_SHARE_ENTRIES]; /* share entry pointers */
1060 SH_INFO_1_STR info_1_str[MAX_SHARE_ENTRIES]; /* share entry strings */
1061 uint32 num_entries_read3; /* EntriesRead2 */
1062 uint32 padding; /* padding */
1067 /* SRV_Q_NET_SHARE_ENUM */
1068 typedef struct q_net_share_enum_info
1070 uint32 ptr_srv_name; /* pointer (to server name?) */
1071 UNISTR2 uni_srv_name; /* server name */
1073 uint32 share_level; /* share level */
1074 uint32 switch_value; /* switch value */
1076 uint32 ptr_share_info; /* pointer to SHARE_INFO_1_CTR */
1080 SHARE_INFO_1_CTR info1; /* share info with 0 entries */
1084 uint32 preferred_len; /* preferred maximum length (0xffff ffff) */
1086 } SRV_Q_NET_SHARE_ENUM;
1089 /* SRV_R_NET_SHARE_ENUM */
1090 typedef struct r_net_share_enum_info
1092 uint32 share_level; /* share level */
1093 uint32 switch_value; /* switch value */
1095 uint32 ptr_share_info; /* pointer to SHARE_INFO_1_CTR */
1098 SHARE_INFO_1_CTR info1; /* share info container */
1102 uint32 status; /* return status */
1104 } SRV_R_NET_SHARE_ENUM;
1107 /* SAMR_Q_CLOSE - probably a policy handle close */
1108 typedef struct q_samr_close_info
1110 LSA_POL_HND pol; /* policy handle */
1115 /* SAMR_R_CLOSE - probably a policy handle close */
1116 typedef struct r_samr_close_info
1118 LSA_POL_HND pol; /* policy handle */
1119 uint32 status; /* return status */
1124 /****************************************************************************
1125 SAMR_Q_OPEN_SECRET - unknown_0 values seen associated with SIDs:
1127 0x0000 0200 and a specific domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
1128 0x0000 0280 and a well-known domain sid - S-1-5-20
1129 0x2000 0000 and a well-known domain sid - S-1-5-20
1130 0x2000 0000 and a specific domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
1131 *****************************************************************************/
1133 /* SAMR_Q_OPEN_SECRET - probably an open secret */
1134 typedef struct q_samr_open_secret_info
1136 LSA_POL_HND pol; /* policy handle */
1137 uint32 unknown_0; /* 0x2000 0000; 0x0000 0211; 0x0000 0280; 0x0000 0200 - unknown */
1138 DOM_SID dom_sid; /* domain SID */
1140 } SAMR_Q_OPEN_SECRET;
1143 /* SAMR_R_OPEN_SECRET - probably an open */
1144 typedef struct r_samr_open_secret_info
1146 LSA_POL_HND pol; /* policy handle associated with the SID */
1147 uint32 status; /* return status */
1149 } SAMR_R_OPEN_SECRET;
1152 /****************************************************************************
1153 SAMR_Q_LOOKUP_RIDS - do a conversion (only one!) from name to RID.
1155 the policy handle allocated by an "samr open secret" call is associated
1156 with a SID. this policy handle is what is queried here, *not* the SID
1157 itself. the response to the lookup rids is relative to this SID.
1158 *****************************************************************************/
1159 /* SAMR_Q_LOOKUP_RIDS - probably a "read SAM entry" */
1160 typedef struct q_samr_lookup_names_info
1162 LSA_POL_HND pol; /* policy handle */
1164 uint32 num_rids1; /* 1 - number of rids being looked up */
1165 uint32 rid; /* 0000 03e8 - RID of the server being queried? */
1166 uint32 ptr; /* 0 - 32 bit unknown */
1167 uint32 num_rids2; /* 1 - number of rids being looked up */
1169 UNIHDR hdr_mach_acct; /* unicode machine account name header */
1170 UNISTR2 uni_mach_acct; /* unicode machine account name */
1172 } SAMR_Q_LOOKUP_RIDS;
1175 /* SAMR_R_LOOKUP_RIDS - probably an open */
1176 typedef struct r_samr_lookup_names_info
1179 uint32 undoc_buffer; /* undocumented buffer pointer */
1181 uint32 num_entries2;
1182 DOM_RID3 dom_rid[MAX_LOOKUP_SIDS]; /* domain RIDs being looked up */
1184 uint32 num_entries3;
1186 uint32 status; /* return code */
1188 } SAMR_R_LOOKUP_RIDS;
1191 /* SAMR_Q_UNKNOWN_22 - probably an open */
1192 typedef struct q_samr_unknown_22_info
1194 LSA_POL_HND pol; /* policy handle */
1195 uint32 unknown_id_0; /* 0x0000 03E8 - 32 bit unknown id */
1197 } SAMR_Q_UNKNOWN_22;
1200 /* SAMR_R_UNKNOWN_22 - probably an open */
1201 typedef struct r_samr_unknown_22_info
1203 LSA_POL_HND pol; /* policy handle associated with unknown id */
1204 uint32 status; /* return status */
1206 } SAMR_R_UNKNOWN_22;
1209 /* SAMR_Q_UNKNOWN_24 - probably a get sam info */
1210 typedef struct q_samr_unknown_24_info
1212 LSA_POL_HND pol; /* policy handle associated with unknown id */
1213 uint16 unknown_0; /* 0x0015 or 0x0011 - 16 bit unknown */
1215 } SAMR_Q_UNKNOWN_24;
1218 /* SAMR_R_UNKNOWN_24 - probably a get sam info */
1219 typedef struct r_samr_unknown_24_info
1221 uint32 ptr; /* pointer */
1222 uint16 unknown_0; /* 0x0015 or 0x0011 - 16 bit unknown (same as above) */
1223 uint16 unknown_1; /* 0x8b73 - 16 bit unknown */
1224 uint8 padding_0[16]; /* 0 - padding 16 bytes */
1225 NTTIME expiry; /* expiry time or something? */
1226 uint8 padding_1[24]; /* 0 - padding 24 bytes */
1228 UNIHDR hdr_mach_acct; /* unicode header for machine account */
1229 uint32 padding_2; /* 0 - padding 4 bytes */
1231 uint32 ptr_1; /* pointer */
1232 uint8 padding_3[32]; /* 0 - padding 32 bytes */
1233 uint32 padding_4; /* 0 - padding 4 bytes */
1235 uint32 ptr_2; /* pointer */
1236 uint32 padding_5; /* 0 - padding 4 bytes */
1238 uint32 ptr_3; /* pointer */
1239 uint8 padding_6[32]; /* 0 - padding 32 bytes */
1241 uint32 unknown_id_0; /* unknown id associated with policy handle */
1242 uint16 unknown_2; /* 0x0201 - 16 bit unknown */
1243 uint32 unknown_3; /* 0x0000 0080 - 32 bit unknown */
1244 uint16 unknown_4; /* 0x003f - 16 bit unknown */
1245 uint16 unknown_5; /* 0x003c - 16 bit unknown */
1247 uint8 padding_7[16]; /* 0 - padding 16 bytes */
1248 uint32 padding_8; /* 0 - padding 4 bytes */
1250 UNISTR2 uni_mach_acct; /* unicode string for machine account */
1252 uint8 padding_9[48]; /* 0 - padding 48 bytes */
1254 uint32 status; /* return status */
1256 } SAMR_R_UNKNOWN_24;
1259 /* SAMR_Q_UNKNOWN_32 - probably a "create SAM entry" */
1260 typedef struct q_samr_unknown_32_info
1262 LSA_POL_HND pol; /* policy handle */
1264 UNIHDR hdr_mach_acct; /* unicode machine account name header */
1265 UNISTR2 uni_mach_acct; /* unicode machine account name */
1267 uint32 unknown_0; /* 32 bit unknown */
1268 uint16 unknown_1; /* 16 bit unknown */
1269 uint16 unknown_2; /* 16 bit unknown */
1271 } SAMR_Q_UNKNOWN_32;
1274 /* SAMR_R_UNKNOWN_32 - probably a "create SAM entry" */
1275 typedef struct r_samr_unknown_32_info
1277 LSA_POL_HND pol; /* policy handle */
1278 uint32 unknown_0; /* 0x0000 0030 - 32 bit unknown */
1279 uint32 padding; /* 0 - 4 byte padding */
1281 uint32 status; /* return status - 0xC000 0099: user exists */
1283 } SAMR_R_UNKNOWN_32;
1286 /* SAMR_Q_OPEN_POLICY - probably an open */
1287 typedef struct q_samr_open_policy_info
1289 uint32 ptr_srv_name; /* pointer (to server name?) */
1290 UNISTR2 uni_srv_name; /* unicode server name starting with '\\' */
1292 uint32 unknown_0; /* 32 bit unknown */
1294 } SAMR_Q_OPEN_POLICY;
1297 /* SAMR_R_OPEN_POLICY - probably an open */
1298 typedef struct r_samr_open_policy_info
1300 LSA_POL_HND pol; /* policy handle */
1301 uint32 status; /* return status */
1303 } SAMR_R_OPEN_POLICY;
1306 /* WKS_Q_UNKNOWN_0 - probably a capabilities request */
1307 typedef struct q_wks_unknown_0_info
1309 uint32 ptr_srv_name; /* pointer (to server name?) */
1310 UNISTR2 uni_srv_name; /* unicode server name starting with '\\' */
1312 uint32 unknown_0; /* 0x64 - 32 bit unknown */
1313 uint16 unknown_1; /* 16 bit unknown */
1318 /* WKS_R_UNKNOWN_0 - probably a capabilities request */
1319 typedef struct r_wks_unknown_0_info
1321 uint32 unknown_0; /* 64 - unknown */
1322 uint32 ptr_1; /* pointer 1 */
1323 uint32 unknown_1; /* 0x0000 01f4 - unknown */
1324 uint32 ptr_srv_name; /* pointer to server name */
1325 uint32 ptr_dom_name; /* pointer to domain name */
1326 uint32 unknown_2; /* 4 - unknown */
1327 uint32 unknown_3; /* 0 - unknown */
1329 UNISTR2 uni_srv_name; /* unicode server name */
1330 UNISTR2 uni_dom_name; /* unicode domainn name */
1331 uint32 status; /* return status */
1340 unsigned char *smb_passwd; /* Null if no password */
1341 unsigned char *smb_nt_passwd; /* Null if no password */
1342 /* Other fields / flags may be added later */
1361 int readbraw_supported;
1362 int writebraw_supported;
1388 /* these times are normally kept in GMT */
1397 /* Structure used when SMBwritebmpx is active */
1400 int wr_total_written; /* So we know when to discard this */
1403 int32 wr_error; /* Cached errors */
1404 BOOL wr_mode; /* write through mode) */
1405 BOOL wr_discard; /* discard all further data */
1406 } write_bmpx_struct;
1409 * Structure used to indirect fd's from the files_struct.
1410 * Needed as POSIX locking is based on file and process, not
1411 * file descriptor and process.
1422 int real_open_flags;
1428 file_fd_struct *fd_ptr;
1435 write_bmpx_struct *wbmpx_ptr;
1436 struct timeval open_time;
1444 BOOL granted_oplock;
1445 BOOL sent_oplock_break;
1453 int list[UID_CACHE_SIZE];
1460 } name_compare_entry;
1466 struct uid_cache uid_cache;
1476 char *user; /* name of user who *opened* this connection */
1477 int uid; /* uid of user who *opened* this connection */
1478 int gid; /* gid of user who *opened* this connection */
1480 uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
1482 /* following groups stuff added by ih */
1484 /* This groups info is valid for the user that *opened* the connection */
1487 int *igroups; /* an integer version - some OSes are broken :-( */
1493 name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
1494 name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
1495 name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
1497 } connection_struct;
1499 /* Domain controller authentication protocol info */
1502 DOM_CHAL clnt_chal; /* Initial challenge received from client */
1503 DOM_CHAL srv_chal; /* Initial server challenge */
1504 DOM_CRED clnt_cred; /* Last client credential */
1505 DOM_CRED srv_cred; /* Last server credential */
1507 uchar sess_key[8]; /* Session key */
1508 uchar md4pw[16]; /* md4(machine password) */
1513 int uid; /* uid of a validated user */
1514 int gid; /* gid of a validated user */
1516 fstring name; /* name of a validated user */
1517 fstring real_name; /* to store real name from password file - simeon */
1520 /* following groups stuff added by ih */
1521 /* This groups info is needed for when we become_user() for this uid */
1524 int *igroups; /* an integer version - some OSes are broken :-( */
1525 int *attrs; /* attributes associated with each gid */
1530 /* per-user authentication information on NT RPCs */
1536 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
1547 } print_queue_struct;
1549 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
1555 } print_status_struct;
1557 /* used for server information: client, nameserv and ipc */
1558 struct server_info_struct
1563 fstring domain; /* used ONLY in ipc.c NOT namework.c */
1564 BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
1568 /* used for network interfaces */
1571 struct interface *next;
1573 struct in_addr bcast;
1574 struct in_addr nmask;
1577 /* struct returned by get_share_modes */
1584 struct timeval time;
1588 /* each implementation of the share mode code needs
1589 to support the following operations */
1591 BOOL (*stop_mgmt)(void);
1592 BOOL (*lock_entry)(int , uint32 , uint32 , int *);
1593 BOOL (*unlock_entry)(int , uint32 , uint32 , int );
1594 int (*get_entries)(int , int , uint32 , uint32 , share_mode_entry **);
1595 void (*del_entry)(int , int );
1596 BOOL (*set_entry)(int , int , uint16 , uint16 );
1597 BOOL (*remove_oplock)(int , int);
1598 int (*forall)(void (*)(share_mode_entry *, char *));
1599 void (*status)(FILE *);
1602 /* each implementation of the shared memory code needs
1603 to support the following operations */
1605 BOOL (*shm_close)( void );
1606 int (*shm_alloc)(int );
1607 BOOL (*shm_free)(int );
1608 int (*get_userdef_off)(void);
1609 void *(*offset2addr)(int );
1610 int (*addr2offset)(void *addr);
1611 BOOL (*lock_hash_entry)(unsigned int);
1612 BOOL (*unlock_hash_entry)( unsigned int );
1613 BOOL (*get_usage)(int *,int *,int *);
1614 unsigned (*hash_size)(void);
1618 /* this is used for smbstatus */
1619 struct connect_record
1632 /* This is used by smbclient to send it to a smbfs mount point */
1633 struct connection_options {
1635 /* Connection-Options */
1639 /* The following are LANMAN 1.0 options */
1645 /* The following are NT LM 0.12 options */
1647 uint32 capabilities;
1651 #ifndef LOCKING_VERSION
1652 #define LOCKING_VERSION 4
1653 #endif /* LOCKING_VERSION */
1655 /* these are useful macros for checking validity of handles */
1656 #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
1657 #define OPEN_FNUM(fnum) (VALID_FNUM(fnum) && Files[fnum].open)
1658 #define VALID_CNUM(cnum) (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
1659 #define OPEN_CNUM(cnum) (VALID_CNUM(cnum) && Connections[cnum].open)
1660 #define IS_IPC(cnum) (VALID_CNUM(cnum) && Connections[cnum].ipc)
1661 #define IS_PRINT(cnum) (VALID_CNUM(cnum) && Connections[cnum].printer)
1662 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
1664 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
1665 return(ERROR(ERRDOS,ERRbadfid))
1666 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
1667 return(ERROR(ERRDOS,ERRbadaccess))
1668 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
1669 return(ERROR(ERRDOS,ERRbadaccess))
1670 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
1671 return(CACHED_ERROR(fnum))
1673 /* translates a connection number into a service number */
1674 #define SNUM(cnum) (Connections[cnum].service)
1676 /* access various service details */
1677 #define SERVICE(snum) (lp_servicename(snum))
1678 #define PRINTCAP (lp_printcapname())
1679 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
1680 #define PRINTERNAME(snum) (lp_printername(snum))
1681 #define CAN_WRITE(cnum) (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
1682 #define VALID_SNUM(snum) (lp_snum_ok(snum))
1683 #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum))
1684 #define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum))
1685 #define CAN_SETDIR(snum) (!lp_no_set_dir(snum))
1686 #define CAN_PRINT(cnum) (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
1687 #define POSTSCRIPT(cnum) (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
1688 #define MAP_HIDDEN(cnum) (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
1689 #define MAP_SYSTEM(cnum) (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
1690 #define MAP_ARCHIVE(cnum) (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
1691 #define IS_HIDDEN_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].hide_list))
1692 #define IS_VETO_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].veto_list))
1693 #define IS_VETO_OPLOCK_PATH(cnum,path) (is_in_path((path),Connections[(cnum)].veto_oplock_list))
1695 #define SMBENCRYPT() (lp_encrypted_passwords())
1697 /* the basic packet size, assuming no words or bytes */
1700 /* offsets into message for common items */
1724 #define smb_vwv10 57
1725 #define smb_vwv11 59
1726 #define smb_vwv12 61
1727 #define smb_vwv13 63
1728 #define smb_vwv14 65
1729 #define smb_vwv15 67
1730 #define smb_vwv16 69
1731 #define smb_vwv17 71
1735 #define SMBmkdir 0x00 /* create directory */
1736 #define SMBrmdir 0x01 /* delete directory */
1737 #define SMBopen 0x02 /* open file */
1738 #define SMBcreate 0x03 /* create file */
1739 #define SMBclose 0x04 /* close file */
1740 #define SMBflush 0x05 /* flush file */
1741 #define SMBunlink 0x06 /* delete file */
1742 #define SMBmv 0x07 /* rename file */
1743 #define SMBgetatr 0x08 /* get file attributes */
1744 #define SMBsetatr 0x09 /* set file attributes */
1745 #define SMBread 0x0A /* read from file */
1746 #define SMBwrite 0x0B /* write to file */
1747 #define SMBlock 0x0C /* lock byte range */
1748 #define SMBunlock 0x0D /* unlock byte range */
1749 #define SMBctemp 0x0E /* create temporary file */
1750 #define SMBmknew 0x0F /* make new file */
1751 #define SMBchkpth 0x10 /* check directory path */
1752 #define SMBexit 0x11 /* process exit */
1753 #define SMBlseek 0x12 /* seek */
1754 #define SMBtcon 0x70 /* tree connect */
1755 #define SMBtconX 0x75 /* tree connect and X*/
1756 #define SMBtdis 0x71 /* tree disconnect */
1757 #define SMBnegprot 0x72 /* negotiate protocol */
1758 #define SMBdskattr 0x80 /* get disk attributes */
1759 #define SMBsearch 0x81 /* search directory */
1760 #define SMBsplopen 0xC0 /* open print spool file */
1761 #define SMBsplwr 0xC1 /* write to print spool file */
1762 #define SMBsplclose 0xC2 /* close print spool file */
1763 #define SMBsplretq 0xC3 /* return print queue */
1764 #define SMBsends 0xD0 /* send single block message */
1765 #define SMBsendb 0xD1 /* send broadcast message */
1766 #define SMBfwdname 0xD2 /* forward user name */
1767 #define SMBcancelf 0xD3 /* cancel forward */
1768 #define SMBgetmac 0xD4 /* get machine name */
1769 #define SMBsendstrt 0xD5 /* send start of multi-block message */
1770 #define SMBsendend 0xD6 /* send end of multi-block message */
1771 #define SMBsendtxt 0xD7 /* send text of multi-block message */
1773 /* Core+ protocol */
1774 #define SMBlockread 0x13 /* Lock a range and read */
1775 #define SMBwriteunlock 0x14 /* Unlock a range then write */
1776 #define SMBreadbraw 0x1a /* read a block of data with no smb header */
1777 #define SMBwritebraw 0x1d /* write a block of data with no smb header */
1778 #define SMBwritec 0x20 /* secondary write request */
1779 #define SMBwriteclose 0x2c /* write a file then close it */
1781 /* dos extended protocol */
1782 #define SMBreadBraw 0x1A /* read block raw */
1783 #define SMBreadBmpx 0x1B /* read block multiplexed */
1784 #define SMBreadBs 0x1C /* read block (secondary response) */
1785 #define SMBwriteBraw 0x1D /* write block raw */
1786 #define SMBwriteBmpx 0x1E /* write block multiplexed */
1787 #define SMBwriteBs 0x1F /* write block (secondary request) */
1788 #define SMBwriteC 0x20 /* write complete response */
1789 #define SMBsetattrE 0x22 /* set file attributes expanded */
1790 #define SMBgetattrE 0x23 /* get file attributes expanded */
1791 #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */
1792 #define SMBtrans 0x25 /* transaction - name, bytes in/out */
1793 #define SMBtranss 0x26 /* transaction (secondary request/response) */
1794 #define SMBioctl 0x27 /* IOCTL */
1795 #define SMBioctls 0x28 /* IOCTL (secondary request/response) */
1796 #define SMBcopy 0x29 /* copy */
1797 #define SMBmove 0x2A /* move */
1798 #define SMBecho 0x2B /* echo */
1799 #define SMBopenX 0x2D /* open and X */
1800 #define SMBreadX 0x2E /* read and X */
1801 #define SMBwriteX 0x2F /* write and X */
1802 #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */
1803 #define SMBffirst 0x82 /* find first */
1804 #define SMBfunique 0x83 /* find unique */
1805 #define SMBfclose 0x84 /* find close */
1806 #define SMBinvalid 0xFE /* invalid command */
1808 /* Extended 2.0 protocol */
1809 #define SMBtrans2 0x32 /* TRANS2 protocol set */
1810 #define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */
1811 #define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */
1812 #define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
1813 #define SMBulogoffX 0x74 /* user logoff */
1815 /* NT SMB extensions. */
1816 #define SMBnttrans 0xA0 /* NT transact */
1817 #define SMBnttranss 0xA1 /* NT transact secondary */
1818 #define SMBntcreateX 0xA2 /* NT create and X */
1819 #define SMBntcancel 0xA4 /* NT cancel */
1821 /* These are the TRANS2 sub commands */
1822 #define TRANSACT2_OPEN 0
1823 #define TRANSACT2_FINDFIRST 1
1824 #define TRANSACT2_FINDNEXT 2
1825 #define TRANSACT2_QFSINFO 3
1826 #define TRANSACT2_SETFSINFO 4
1827 #define TRANSACT2_QPATHINFO 5
1828 #define TRANSACT2_SETPATHINFO 6
1829 #define TRANSACT2_QFILEINFO 7
1830 #define TRANSACT2_SETFILEINFO 8
1831 #define TRANSACT2_FSCTL 9
1832 #define TRANSACT2_IOCTL 0xA
1833 #define TRANSACT2_FINDNOTIFYFIRST 0xB
1834 #define TRANSACT2_FINDNOTIFYNEXT 0xC
1835 #define TRANSACT2_MKDIR 0xD
1836 #define TRANSACT2_SESSION_SETUP 0xE
1837 #define TRANSACT2_GET_DFS_REFERRAL 0x10
1838 #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
1840 /* These are the NT transact sub commands. */
1841 #define NT_TRANSACT_CREATE 1
1842 #define NT_TRANSACT_IOCTL 2
1843 #define NT_TRANSACT_SET_SECURITY_DESC 3
1844 #define NT_TRANSACT_NOTIFY_CHANGE 4
1845 #define NT_TRANSACT_RENAME 5
1846 #define NT_TRANSACT_QUERY_SECURITY_DESC 6
1848 /* these are the trans2 sub fields for primary requests */
1849 #define smb_tpscnt smb_vwv0
1850 #define smb_tdscnt smb_vwv1
1851 #define smb_mprcnt smb_vwv2
1852 #define smb_mdrcnt smb_vwv3
1853 #define smb_msrcnt smb_vwv4
1854 #define smb_flags smb_vwv5
1855 #define smb_timeout smb_vwv6
1856 #define smb_pscnt smb_vwv9
1857 #define smb_psoff smb_vwv10
1858 #define smb_dscnt smb_vwv11
1859 #define smb_dsoff smb_vwv12
1860 #define smb_suwcnt smb_vwv13
1861 #define smb_setup smb_vwv14
1862 #define smb_setup0 smb_setup
1863 #define smb_setup1 (smb_setup+2)
1864 #define smb_setup2 (smb_setup+4)
1866 /* these are for the secondary requests */
1867 #define smb_spscnt smb_vwv2
1868 #define smb_spsoff smb_vwv3
1869 #define smb_spsdisp smb_vwv4
1870 #define smb_sdscnt smb_vwv5
1871 #define smb_sdsoff smb_vwv6
1872 #define smb_sdsdisp smb_vwv7
1873 #define smb_sfid smb_vwv8
1875 /* and these for responses */
1876 #define smb_tprcnt smb_vwv0
1877 #define smb_tdrcnt smb_vwv1
1878 #define smb_prcnt smb_vwv3
1879 #define smb_proff smb_vwv4
1880 #define smb_prdisp smb_vwv5
1881 #define smb_drcnt smb_vwv6
1882 #define smb_droff smb_vwv7
1883 #define smb_drdisp smb_vwv8
1885 /* where to find the base of the SMB packet proper */
1886 #define smb_base(buf) (((char *)(buf))+4)
1889 #define SUCCESS 0 /* The request was successful. */
1890 #define ERRDOS 0x01 /* Error is from the core DOS operating system set. */
1891 #define ERRSRV 0x02 /* Error is generated by the server network file manager.*/
1892 #define ERRHRD 0x03 /* Error is an hardware error. */
1893 #define ERRCMD 0xFF /* Command was not in the "SMB" format. */
1896 int Debug1(char *, ...);
1902 void dfs_unlogin(void);
1903 extern int dcelogin_atmost_once;
1907 void ajt_panic(void);
1911 char *strdup(char *s);
1914 #ifdef REPLACE_STRLEN
1918 #ifdef REPLACE_STRSTR
1919 char *Strstr(char *s, char *p);
1923 #define MIN(a,b) ((a)<(b)?(a):(b))
1926 #define MAX(a,b) ((a)>(b)?(a):(b))
1930 #define ABS(a) ((a)>0?(a):(-(a)))
1942 /* Some POSIX definitions for those without */
1945 #define S_IFDIR 0x4000
1948 #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
1951 #define S_IRWXU 00700 /* read, write, execute: owner */
1954 #define S_IRUSR 00400 /* read permission: owner */
1957 #define S_IWUSR 00200 /* write permission: owner */
1960 #define S_IXUSR 00100 /* execute permission: owner */
1963 #define S_IRWXG 00070 /* read, write, execute: group */
1966 #define S_IRGRP 00040 /* read permission: group */
1969 #define S_IWGRP 00020 /* write permission: group */
1972 #define S_IXGRP 00010 /* execute permission: group */
1975 #define S_IRWXO 00007 /* read, write, execute: other */
1978 #define S_IROTH 00004 /* read permission: other */
1981 #define S_IWOTH 00002 /* write permission: other */
1984 #define S_IXOTH 00001 /* execute permission: other */
1988 /* these are used in NetServerEnum to choose what to receive */
1989 #define SV_TYPE_WORKSTATION 0x00000001
1990 #define SV_TYPE_SERVER 0x00000002
1991 #define SV_TYPE_SQLSERVER 0x00000004
1992 #define SV_TYPE_DOMAIN_CTRL 0x00000008
1993 #define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
1994 #define SV_TYPE_TIME_SOURCE 0x00000020
1995 #define SV_TYPE_AFP 0x00000040
1996 #define SV_TYPE_NOVELL 0x00000080
1997 #define SV_TYPE_DOMAIN_MEMBER 0x00000100
1998 #define SV_TYPE_PRINTQ_SERVER 0x00000200
1999 #define SV_TYPE_DIALIN_SERVER 0x00000400
2000 #define SV_TYPE_SERVER_UNIX 0x00000800
2001 #define SV_TYPE_NT 0x00001000
2002 #define SV_TYPE_WFW 0x00002000
2003 #define SV_TYPE_SERVER_MFPN 0x00004000
2004 #define SV_TYPE_SERVER_NT 0x00008000
2005 #define SV_TYPE_POTENTIAL_BROWSER 0x00010000
2006 #define SV_TYPE_BACKUP_BROWSER 0x00020000
2007 #define SV_TYPE_MASTER_BROWSER 0x00040000
2008 #define SV_TYPE_DOMAIN_MASTER 0x00080000
2009 #define SV_TYPE_SERVER_OSF 0x00100000
2010 #define SV_TYPE_SERVER_VMS 0x00200000
2011 #define SV_TYPE_WIN95_PLUS 0x00400000
2012 #define SV_TYPE_ALTERNATE_XPORT 0x20000000
2013 #define SV_TYPE_LOCAL_LIST_ONLY 0x40000000
2014 #define SV_TYPE_DOMAIN_ENUM 0x80000000
2015 #define SV_TYPE_ALL 0xFFFFFFFF
2017 /* what server type are we currently - JHT Says we ARE 4.20 */
2018 /* this was set by JHT in liaison with Jeremy Allison early 1997 */
2019 /* setting to 4.20 at same time as announcing ourselves as NT Server */
2021 /* Version 4.0 - never made public */
2022 /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
2023 /* - Reappeared in 1.9.16p11 with fixed smbd services */
2024 /* Version 4.20 - To indicate that nmbd and browsing now works better */
2026 #define DEFAULT_MAJOR_VERSION 0x04
2027 #define DEFAULT_MINOR_VERSION 0x02
2029 /* Browser Election Values */
2030 #define BROWSER_ELECTION_VERSION 0x010f
2031 #define BROWSER_CONSTANT 0xaa55
2034 /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
2036 #define CAP_RAW_MODE 0x0001
2037 #define CAP_MPX_MODE 0x0002
2038 #define CAP_UNICODE 0x0004
2039 #define CAP_LARGE_FILES 0x0008
2040 #define CAP_NT_SMBS 0x0010
2041 #define CAP_RPC_REMOTE_APIS 0x0020
2042 #define CAP_STATUS32 0x0040
2043 #define CAP_LEVEL_II_OPLOCKS 0x0080
2044 #define CAP_LOCK_AND_READ 0x0100
2045 #define CAP_NT_FIND 0x0200
2046 #define CAP_DFS 0x1000
2047 #define CAP_LARGE_READX 0x4000
2049 /* protocol types. It assumes that higher protocols include lower protocols
2051 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
2053 /* security levels */
2054 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
2056 /* printing types */
2057 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
2058 PRINT_QNX,PRINT_PLP,PRINT_LPRNG};
2060 /* Remote architectures we know about. */
2061 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
2064 enum case_handling {CASE_LOWER,CASE_UPPER};
2067 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
2068 structures. We cannot define these as actual structures
2069 due to possible differences in structure packing
2070 on different machines/compilers. */
2072 #define SMB_LPID_OFFSET(indx) (10 * (indx))
2073 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
2074 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
2076 /* Macro to cache an error in a write_bmpx_struct */
2077 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
2078 w->wr_discard = True, -1)
2079 /* Macro to test if an error has been cached for this fnum */
2080 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
2081 Files[(fnum)].wbmpx_ptr && \
2082 Files[(fnum)].wbmpx_ptr->wr_discard)
2083 /* Macro to turn the cached error into an error packet */
2084 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
2086 /* these are the datagram types */
2087 #define DGRAM_DIRECT_UNIQUE 0x10
2089 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
2091 /* this is how errors are generated */
2092 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
2094 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
2097 * Global value meaing that the smb_uid field should be
2098 * ingored (in share level security and protocol level == CORE)
2101 #define UID_FIELD_INVALID 0
2102 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
2106 /* Defines needed for multi-codepage support. */
2107 #define KANJI_CODEPAGE 932
2111 * Default client code page - Japanese
2113 #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
2116 * Default client code page - 850 - Western European
2118 #define DEFAULT_CLIENT_CODE_PAGE 850
2122 * Size of buffer to use when moving files across filesystems.
2124 #define COPYBUF_SIZE (8*1024)
2127 * Integers used to override error codes.
2129 extern int unix_ERR_class;
2130 extern int unix_ERR_code;
2133 * Map the Core and Extended Oplock requesst bits down
2134 * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
2140 #define CORE_OPLOCK_REQUEST(inbuf) ((CVAL(inbuf,smb_flg)&((1<<5)|(1<<6)))>>5)
2143 * Extended protocol.
2145 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
2148 #define LOCKING_ANDX_SHARED_LOCK 0x1
2149 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
2150 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
2151 #define LOCKING_ANDX_CANCEL_LOCK 0x8
2152 #define LOCKING_ANDX_LARGE_FILES 0x10
2155 #define OPLOCKLEVEL_NONE 0
2156 #define OPLOCKLEVEL_II 1
2159 * Bits we test with.
2161 #define EXCLUSIVE_OPLOCK 1
2162 #define BATCH_OPLOCK 2
2164 #define CORE_OPLOCK_GRANTED (1<<5)
2165 #define EXTENDED_OPLOCK_GRANTED (1<<15)
2168 * Loopback command offsets.
2171 #define UDP_CMD_LEN_OFFSET 0
2172 #define UDP_CMD_PORT_OFFSET 4
2173 #define UDP_CMD_HEADER_LEN 6
2175 #define UDP_MESSAGE_CMD_OFFSET 0
2178 * Oplock break command code to send over the udp socket.
2183 * +----+--------+--------+--------+-------+--------+
2184 * | cmd| pid | dev | inode | sec | usec |
2185 * +----+--------+--------+--------+-------+--------+
2188 #define OPLOCK_BREAK_CMD 0x1
2189 #define OPLOCK_BREAK_PID_OFFSET 2
2190 #define OPLOCK_BREAK_DEV_OFFSET 6
2191 #define OPLOCK_BREAK_INODE_OFFSET 10
2192 #define OPLOCK_BREAK_SEC_OFFSET 14
2193 #define OPLOCK_BREAK_USEC_OFFSET 18
2194 #define OPLOCK_BREAK_MSG_LEN 22
2197 #define CMD_REPLY 0x8000