Add data structures for initial dcerpc support.
[sfrench/samba-autobuild/.git] / source4 / include / smb.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB parameters and setup, plus a whole lot more.
4    
5    Copyright (C) Andrew Tridgell              1992-2000
6    Copyright (C) John H Terpstra              1996-2002
7    Copyright (C) Luke Kenneth Casson Leighton 1996-2000
8    Copyright (C) Paul Ashton                  1998-2000
9    Copyright (C) Simo Sorce                   2001-2002
10    Copyright (C) Martin Pool                  2002
11    
12    This program is free software; you can redistribute it and/or modify
13    it under the terms of the GNU General Public License as published by
14    the Free Software Foundation; either version 2 of the License, or
15    (at your option) any later version.
16    
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21    
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27 #ifndef _SMB_H
28 #define _SMB_H
29
30 #define NMB_PORT 137
31 #define DGRAM_PORT 138
32 #define SMB_PORT1 445
33 #define SMB_PORT2 139
34 #define SMB_PORTS "445 139"
35
36 #define False (0)
37 #define True (1)
38 #define Auto (2)
39
40 #ifndef _BOOL
41 typedef int BOOL;
42 #define _BOOL       /* So we don't typedef BOOL again in vfs.h */
43 #endif
44
45 #define SIZEOFWORD 2
46
47 #ifndef DEF_CREATE_MASK
48 #define DEF_CREATE_MASK (0755)
49 #endif
50
51 /* string manipulation flags - see clistr.c and srvstr.c */
52 #define STR_TERMINATE 1
53 #define STR_UPPER 2
54 #define STR_ASCII 4
55 #define STR_UNICODE 8
56 #define STR_NOALIGN 16
57 #define STR_NO_RANGE_CHECK 32
58 #define STR_LEN8BIT 64
59 #define STR_TERMINATE_ASCII 128 /* only terminate if ascii */
60 #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */
61
62 /* Debugging stuff */
63 #include "debug.h"
64
65 /* types of socket errors */
66 enum socket_error {SOCKET_READ_TIMEOUT,
67                    SOCKET_READ_EOF,
68                    SOCKET_READ_ERROR,
69                    SOCKET_WRITE_ERROR,
70                    SOCKET_READ_BAD_SIG};
71
72 /* deny modes */
73 #define DENY_DOS 0
74 #define DENY_ALL 1
75 #define DENY_WRITE 2
76 #define DENY_READ 3
77 #define DENY_NONE 4
78 #define DENY_FCB 7
79
80 /* open modes */
81 #define DOS_OPEN_RDONLY 0
82 #define DOS_OPEN_WRONLY 1
83 #define DOS_OPEN_RDWR 2
84 #define DOS_OPEN_FCB 0xF
85
86
87 /**********************************/
88 /* SMBopen field definitions      */
89 #define OPEN_FLAGS_DENY_MASK  0x70
90 #define OPEN_FLAGS_DENY_DOS   0x00
91 #define OPEN_FLAGS_DENY_ALL   0x10
92 #define OPEN_FLAGS_DENY_WRITE 0x20
93 #define OPEN_FLAGS_DENY_READ  0x30
94 #define OPEN_FLAGS_DENY_NONE  0x40
95
96 #define OPEN_FLAGS_MODE_MASK  0x0F
97 #define OPEN_FLAGS_OPEN_READ     0
98 #define OPEN_FLAGS_OPEN_WRITE    1
99 #define OPEN_FLAGS_OPEN_RDWR     2
100 #define OPEN_FLAGS_FCB        0xFF
101
102
103 /**********************************/
104 /* SMBopenX field definitions     */
105
106 /* OpenX Flags field. */
107 #define OPENX_FLAGS_ADDITIONAL_INFO      0x01
108 #define OPENX_FLAGS_REQUEST_OPLOCK       0x02
109 #define OPENX_FLAGS_REQUEST_BATCH_OPLOCK 0x04
110 #define OPENX_FLAGS_EA_LEN               0x08
111 #define OPENX_FLAGS_EXTENDED_RETURN      0x10
112
113 /* desired access (open_mode), split info 4 4-bit nibbles */
114 #define OPENX_MODE_ACCESS_MASK   0x000F
115 #define OPENX_MODE_ACCESS_READ   0x0000
116 #define OPENX_MODE_ACCESS_WRITE  0x0001
117 #define OPENX_MODE_ACCESS_RDWR   0x0002
118 #define OPENX_MODE_ACCESS_EXEC   0x0003
119 #define OPENX_MODE_ACCESS_FCB    0x000F
120
121 #define OPENX_MODE_DENY_SHIFT    4
122 #define OPENX_MODE_DENY_MASK     (0xF        << OPENX_MODE_DENY_SHIFT)
123 #define OPENX_MODE_DENY_DOS      (DENY_DOS   << OPENX_MODE_DENY_SHIFT)
124 #define OPENX_MODE_DENY_ALL      (DENY_ALL   << OPENX_MODE_DENY_SHIFT)
125 #define OPENX_MODE_DENY_WRITE    (DENY_WRITE << OPENX_MODE_DENY_SHIFT)
126 #define OPENX_MODE_DENY_READ     (DENY_READ  << OPENX_MODE_DENY_SHIFT)
127 #define OPENX_MODE_DENY_NONE     (DENY_NONE  << OPENX_MODE_DENY_SHIFT)
128 #define OPENX_MODE_DENY_FCB      (0xF        << OPENX_MODE_DENY_SHIFT)
129
130 #define OPENX_MODE_LOCALITY_MASK 0x0F00 /* what does this do? */
131
132 #define OPENX_MODE_NO_CACHE      0x1000
133 #define OPENX_MODE_WRITE_THRU    0x4000
134
135 /* open function values */
136 #define OPENX_OPEN_FUNC_MASK  0x3
137 #define OPENX_OPEN_FUNC_FAIL  0x0
138 #define OPENX_OPEN_FUNC_OPEN  0x1
139 #define OPENX_OPEN_FUNC_TRUNC 0x2
140
141 /* The above can be OR'ed with... */
142 #define OPENX_OPEN_FUNC_CREATE 0x10
143
144 /* openx action in reply */
145 #define OPENX_ACTION_EXISTED    1
146 #define OPENX_ACTION_CREATED    2
147 #define OPENX_ACTION_TRUNCATED  3
148
149
150 /**********************************/
151 /* SMBntcreateX field definitions */
152
153 /* ntcreatex flags field. */
154 #define NTCREATEX_FLAGS_REQUEST_OPLOCK       0x02
155 #define NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK 0x04
156 #define NTCREATEX_FLAGS_OPEN_DIRECTORY       0x08
157 #define NTCREATEX_FLAGS_EXTENDED             0x10
158
159 /* the ntcreatex access_mask field 
160    this is split into 4 pieces
161    AAAABBBBCCCCCCCCDDDDDDDDDDDDDDDD
162    A -> GENERIC_RIGHT_*
163    B -> SEC_RIGHT_*
164    C -> STD_RIGHT_*
165    D -> SA_RIGHT_*
166    
167    which set of SA_RIGHT_* bits is applicable depends on the type
168    of object.
169 */
170
171
172
173 /* ntcreatex share_access field */
174 #define NTCREATEX_SHARE_ACCESS_NONE   0
175 #define NTCREATEX_SHARE_ACCESS_READ   1
176 #define NTCREATEX_SHARE_ACCESS_WRITE  2
177 #define NTCREATEX_SHARE_ACCESS_DELETE 4
178
179 /* ntcreatex open_disposition field */
180 #define NTCREATEX_DISP_SUPERSEDE 0     /* supersede existing file (if it exists) */
181 #define NTCREATEX_DISP_OPEN 1          /* if file exists open it, else fail */
182 #define NTCREATEX_DISP_CREATE 2        /* if file exists fail, else create it */
183 #define NTCREATEX_DISP_OPEN_IF 3       /* if file exists open it, else create it */
184 #define NTCREATEX_DISP_OVERWRITE 4     /* if exists overwrite, else fail */
185 #define NTCREATEX_DISP_OVERWRITE_IF 5  /* if exists overwrite, else create */
186
187 /* ntcreatex create_options field */
188 #define NTCREATEX_OPTIONS_DIRECTORY            0x0001
189 #define NTCREATEX_OPTIONS_WRITE_THROUGH        0x0002
190 #define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY      0x0004
191 #define NTCREATEX_OPTIONS_SYNC_ALERT           0x0010
192 #define NTCREATEX_OPTIONS_ASYNC_ALERT          0x0020
193 #define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE   0x0040
194 #define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE      0x0200
195 #define NTCREATEX_OPTIONS_EIGHT_DOT_THREE_ONLY 0x0400
196 #define NTCREATEX_OPTIONS_RANDOM_ACCESS        0x0800
197 #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE      0x1000
198 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID      0x2000
199
200 /* ntcreatex impersonation field */
201 #define NTCREATEX_IMPERSONATION_ANONYMOUS      0
202 #define NTCREATEX_IMPERSONATION_IDENTIFICATION 1
203 #define NTCREATEX_IMPERSONATION_IMPERSONATION  2
204 #define NTCREATEX_IMPERSONATION_DELEGATION     3
205
206 /* ntcreatex security flags bit field */
207 #define NTCREATEX_SECURITY_DYNAMIC             1
208 #define NTCREATEX_SECURITY_ALL                 2
209
210 /* ntcreatex create_action in reply */
211 #define NTCREATEX_ACTION_EXISTED     1
212 #define NTCREATEX_ACTION_CREATED     2
213 #define NTCREATEX_ACTION_TRUNCATED   3
214 /* the value 5 can also be returned when you try to create a directory with
215    incorrect parameters - what does it mean? maybe created temporary file? */
216 #define NTCREATEX_ACTION_UNKNOWN 5
217
218
219
220 /* share types */
221 #define STYPE_DISKTREE  0       /* Disk drive */
222 #define STYPE_PRINTQ    1       /* Spooler queue */
223 #define STYPE_DEVICE    2       /* Serial device */
224 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
225 #define STYPE_HIDDEN    0x80000000 /* share is a hidden one (ends with $) */
226
227 #include "doserr.h"
228
229 /* this is a trade with jeremy - I agreed to use uint_t instead of
230  * bare unsigned if he agreed to not use non-braced if statements
231  * (13/4/2003 - train to gottenginen) */
232 #ifndef IRIX
233 typedef unsigned int uint_t;
234 #endif
235
236 /*
237  * SMB UCS2 (16-bit unicode) internal type.
238  */
239
240 typedef uint16 smb_ucs2_t;
241
242 /* ucs2 string types. */
243 typedef smb_ucs2_t wpstring[PSTRING_LEN];
244 typedef smb_ucs2_t wfstring[FSTRING_LEN];
245
246 /* This error code can go into the client smb_rw_error. */
247 #define WRITE_ERROR 4
248
249 #ifdef WORDS_BIGENDIAN
250 #define UCS2_SHIFT 8
251 #else
252 #define UCS2_SHIFT 0
253 #endif
254
255 /* turn a 7 bit character into a ucs2 character */
256 #define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
257
258 /* pipe string names */
259 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
260 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
261 #define PIPE_SAMR     "\\PIPE\\samr"
262 #define PIPE_WINREG   "\\PIPE\\winreg"
263 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
264 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
265 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
266 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
267 #define PIPE_LSASS    "\\PIPE\\lsass"
268 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
269 #define PIPE_SPOOLSS  "\\PIPE\\spoolss"
270 #define PIPE_NETDFS   "\\PIPE\\netdfs"
271
272 #define PI_LSARPC               0
273 #define PI_LSARPC_DS            1
274 #define PI_SAMR                 2
275 #define PI_NETLOGON             3
276 #define PI_SRVSVC               4
277 #define PI_WKSSVC               5
278 #define PI_WINREG               6
279 #define PI_SPOOLSS              7
280 #define PI_NETDFS               8
281 #define PI_MAX_PIPES            9
282
283 /* Allowable account control bits */
284 #define ACB_DISABLED   0x0001  /* 1 = User account disabled */
285 #define ACB_HOMDIRREQ  0x0002  /* 1 = Home directory required */
286 #define ACB_PWNOTREQ   0x0004  /* 1 = User password not required */
287 #define ACB_TEMPDUP    0x0008  /* 1 = Temporary duplicate account */
288 #define ACB_NORMAL     0x0010  /* 1 = Normal user account */
289 #define ACB_MNS        0x0020  /* 1 = MNS logon user account */
290 #define ACB_DOMTRUST   0x0040  /* 1 = Interdomain trust account */
291 #define ACB_WSTRUST    0x0080  /* 1 = Workstation trust account */
292 #define ACB_SVRTRUST   0x0100  /* 1 = Server trust account */
293 #define ACB_PWNOEXP    0x0200  /* 1 = User password does not expire */
294 #define ACB_AUTOLOCK   0x0400  /* 1 = Account auto locked */
295  
296 #define MAX_HOURS_LEN 32
297
298 #ifndef MAXSUBAUTHS
299 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
300 #endif
301
302 /* SID Types */
303 enum SID_NAME_USE
304 {
305         SID_NAME_USE_NONE = 0,/* NOTUSED */
306         SID_NAME_USER    = 1, /* user */
307         SID_NAME_DOM_GRP = 2, /* domain group */
308         SID_NAME_DOMAIN  = 3, /* domain: don't know what this is */
309         SID_NAME_ALIAS   = 4, /* local group */
310         SID_NAME_WKN_GRP = 5, /* well-known group */
311         SID_NAME_DELETED = 6, /* deleted account: needed for c2 rating */
312         SID_NAME_INVALID = 7, /* invalid account */
313         SID_NAME_UNKNOWN = 8  /* oops. */
314 };
315
316 /**
317  * @brief Security Identifier
318  *
319  * @sa http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/accctrl_38yn.asp
320  **/
321 typedef struct sid_info
322 {
323   uint8  sid_rev_num;             /**< SID revision number */
324   uint8  num_auths;               /**< Number of sub-authorities */
325   uint8  id_auth[6];              /**< Identifier Authority */
326   /*
327    *  Pointer to sub-authorities.
328    *
329    * @note The values in these uint32's are in *native* byteorder, not
330    * neccessarily little-endian...... JRA.
331    */
332   uint32 sub_auths[MAXSUBAUTHS];  
333
334 } DOM_SID;
335
336 /*
337  * The complete list of SIDS belonging to this user.
338  * Created when a vuid is registered.
339  * The definition of the user_sids array is as follows :
340  *
341  * token->user_sids[0] = primary user SID.
342  * token->user_sids[1] = primary group SID.
343  * token->user_sids[2..num_sids] = supplementary group SIDS.
344  */
345
346 #define PRIMARY_USER_SID_INDEX 0
347 #define PRIMARY_GROUP_SID_INDEX 1
348
349 typedef struct _nt_user_token {
350         size_t num_sids;
351         DOM_SID *user_sids;
352 } NT_USER_TOKEN;
353
354 /*** query a local group, get a list of these: shows who is in that group ***/
355
356 /* local group member info */
357 typedef struct local_grp_member_info
358 {
359         DOM_SID sid    ; /* matches with name */
360         uint8   sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
361         fstring name   ; /* matches with sid: must be of the form "DOMAIN\account" */
362
363 } LOCAL_GRP_MEMBER;
364
365 /* enumerate these to get list of local groups */
366
367 /* local group info */
368 typedef struct local_grp_info
369 {
370         fstring name;
371         fstring comment;
372
373 } LOCAL_GRP;
374
375 /*** enumerate these to get list of domain groups ***/
376
377 /* domain group member info */
378 typedef struct domain_grp_info
379 {
380         fstring name;
381         fstring comment;
382         uint32  rid; /* group rid */
383         uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
384
385 } DOMAIN_GRP;
386
387 /*** query a domain group, get a list of these: shows who is in that group ***/
388
389 /* domain group info */
390 typedef struct domain_grp_member_info
391 {
392         fstring name;
393         uint8   attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
394
395 } DOMAIN_GRP_MEMBER;
396
397 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
398 typedef struct time_info
399 {
400   uint32 time;
401 } UTIME;
402
403 /* used to hold an arbitrary blob of data */
404 typedef struct data_blob {
405         uint8 *data;
406         size_t length;
407         void (*free)(struct data_blob *data_blob);
408 } DATA_BLOB;
409
410 /*
411  * Structure used to keep directory state information around.
412  * Used in NT change-notify code.
413  */
414
415 typedef struct
416 {
417   time_t modify_time;
418   time_t status_time;
419 } dir_status_struct;
420
421 struct vuid_cache {
422   unsigned int entries;
423   uint16 list[VUID_CACHE_SIZE];
424 };
425
426 /* Include VFS stuff */
427
428 #include "smb_acls.h"
429 #include "enums.h"
430 #include "events.h"
431 #include "context.h"
432 #include "smb_interfaces.h"
433 #include "dcerpc_interfaces.h"
434 #include "ntvfs.h"
435
436 typedef struct smb_vfs_handle_struct
437 {
438     void *data;
439     /* Handle on dlopen() call */
440     void *handle;
441     struct smb_vfs_handle_struct  *next, *prev;
442     
443 } smb_vfs_handle_struct;
444
445 struct tcon_context {
446         struct tcon_context *next, *prev;
447
448         /* the server context that this was created on */
449         struct server_context *smb;
450
451         /* a talloc context for all data in this structure */
452         TALLOC_CTX *mem_ctx;
453
454         /* a private structure used by the active NTVFS backend */
455         void *ntvfs_private;
456
457         uint16 cnum; /* an index passed over the wire (the TID) */
458         int service;
459         enum ntvfs_type type;
460         BOOL read_only;
461         BOOL admin_user;
462
463         /* the NTVFS operations - see source/ntvfs/ and include/ntvfs.h for details */
464         struct ntvfs_ops *ntvfs_ops;
465
466         /* the reported filesystem type */
467         char *fs_type;
468
469         /* the reported device type */
470         char *dev_type;
471 };
472
473 struct current_user
474 {
475         struct tcon_context *conn;
476         uint16 vuid;
477         uid_t uid;
478         gid_t gid;
479         int ngroups;
480         gid_t *groups;
481         NT_USER_TOKEN *nt_user_token;
482 };
483
484 /* Defines for the sent_oplock_break field above. */
485 #define NO_BREAK_SENT 0
486 #define EXCLUSIVE_BREAK_SENT 1
487 #define LEVEL_II_BREAK_SENT 2
488
489 typedef struct userdom_struct {
490         fstring smb_name; /* user name from the client */
491         fstring unix_name; /* unix user name of a validated user */
492         fstring full_name; /* to store full name (such as "Joe Bloggs") from gecos field of password file */
493         fstring domain; /* domain that the client specified */
494 } userdom_struct;
495
496 /* used for server information: client, nameserv and ipc */
497 struct server_info_struct
498 {
499   fstring name;
500   uint32 type;
501   fstring comment;
502   fstring domain; /* used ONLY in ipc.c NOT namework.c */
503   BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
504 };
505
506
507 /* used for network interfaces */
508 struct interface
509 {
510         struct interface *next, *prev;
511         struct in_addr ip;
512         struct in_addr bcast;
513         struct in_addr nmask;
514 };
515
516 /* struct returned by get_share_modes */
517 typedef struct {
518         pid_t pid;
519         uint16 op_port;
520         uint16 op_type;
521         int share_mode;
522         uint32 desired_access;
523         struct timeval time;
524         SMB_DEV_T dev;
525         SMB_INO_T inode;
526         unsigned long share_file_id;
527 } share_mode_entry;
528
529
530 #define SHAREMODE_FN_CAST() \
531         void (*)(share_mode_entry *, char*)
532
533 #define SHAREMODE_FN(fn) \
534         void (*fn)(share_mode_entry *, char*)
535
536 #define NT_HASH_LEN 16
537 #define LM_HASH_LEN 16
538
539 /*
540  * bit flags representing initialized fields in SAM_ACCOUNT
541  */
542 enum pdb_elements {
543         PDB_UNINIT,
544         PDB_UID,
545         PDB_GID,
546         PDB_SMBHOME,
547         PDB_PROFILE,
548         PDB_DRIVE,
549         PDB_LOGONSCRIPT,
550         PDB_LOGONTIME,
551         PDB_LOGOFFTIME,
552         PDB_KICKOFFTIME,
553         PDB_CANCHANGETIME,
554         PDB_MUSTCHANGETIME,
555         PDB_PLAINTEXT_PW,
556         PDB_USERNAME,
557         PDB_FULLNAME,
558         PDB_DOMAIN,
559         PDB_NTUSERNAME,
560         PDB_HOURSLEN,
561         PDB_LOGONDIVS,
562         PDB_USERSID,
563         PDB_GROUPSID,
564         PDB_ACCTCTRL,
565         PDB_PASSLASTSET,
566         PDB_UNIXHOMEDIR,
567         PDB_ACCTDESC,
568         PDB_WORKSTATIONS,
569         PDB_UNKNOWNSTR,
570         PDB_MUNGEDDIAL,
571         PDB_HOURS,
572         PDB_UNKNOWN3,
573         PDB_UNKNOWN5,
574         PDB_UNKNOWN6,
575         PDB_LMPASSWD,
576         PDB_NTPASSWD,
577
578         /* this must be the last element */
579         PDB_COUNT,
580 };
581
582 enum pdb_value_state {
583         PDB_DEFAULT=0,
584         PDB_SET,
585         PDB_CHANGED
586 };
587
588 #define IS_SAM_UNIX_USER(x) \
589         (( pdb_get_init_flags(x, PDB_UID) != PDB_DEFAULT ) \
590          && ( pdb_get_init_flags(x,PDB_GID) != PDB_DEFAULT ))
591
592 #define IS_SAM_SET(x, flag)     (pdb_get_init_flags(x, flag) == PDB_SET)
593 #define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
594 #define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
595                 
596 typedef struct sam_passwd
597 {
598         TALLOC_CTX *mem_ctx;
599         
600         void (*free_fn)(struct sam_passwd **);
601
602         struct pdb_methods *methods;
603
604         struct user_data {
605                 /* initiailization flags */
606                 struct bitmap *change_flags;
607                 struct bitmap *set_flags;
608
609                 time_t logon_time;            /* logon time */
610                 time_t logoff_time;           /* logoff time */
611                 time_t kickoff_time;          /* kickoff time */
612                 time_t pass_last_set_time;    /* password last set time */
613                 time_t pass_can_change_time;  /* password can change time */
614                 time_t pass_must_change_time; /* password must change time */
615                 
616                 const char * username;     /* UNIX username string */
617                 const char * domain;       /* Windows Domain name */
618                 const char * nt_username;  /* Windows username string */
619                 const char * full_name;    /* user's full name string */
620                 const char * unix_home_dir;     /* UNIX home directory string */
621                 const char * home_dir;     /* home directory string */
622                 const char * dir_drive;    /* home directory drive string */
623                 const char * logon_script; /* logon script string */
624                 const char * profile_path; /* profile path string */
625                 const char * acct_desc  ;  /* user description string */
626                 const char * workstations; /* login from workstations string */
627                 const char * unknown_str ; /* don't know what this is, yet. */
628                 const char * munged_dial ; /* munged path name and dial-back tel number */
629                 
630                 uid_t uid;          /* this is a unix uid_t */
631                 gid_t gid;          /* this is a unix gid_t */
632                 DOM_SID user_sid;    /* Primary User SID */
633                 DOM_SID group_sid;   /* Primary Group SID */
634                 
635                 DATA_BLOB lm_pw; /* .data is Null if no password */
636                 DATA_BLOB nt_pw; /* .data is Null if no password */
637                 char* plaintext_pw; /* is Null if not available */
638                 
639                 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
640                 uint32 unknown_3; /* 0x00ff ffff */
641                 
642                 uint16 logon_divs; /* 168 - number of hours in a week */
643                 uint32 hours_len; /* normally 21 bytes */
644                 uint8 hours[MAX_HOURS_LEN];
645                 
646                 uint32 unknown_5; /* 0x0002 0000 */
647                 uint32 unknown_6; /* 0x0000 04ec */
648         } private;
649
650         /* Lets see if the remaining code can get the hint that you
651            are meant to use the pdb_...() functions. */
652         
653 } SAM_ACCOUNT;
654
655 /*
656  * Flags for account policy.
657  */
658 #define AP_MIN_PASSWORD_LEN             1
659 #define AP_PASSWORD_HISTORY             2
660 #define AP_USER_MUST_LOGON_TO_CHG_PASS  3
661 #define AP_MAX_PASSWORD_AGE             4
662 #define AP_MIN_PASSWORD_AGE             5
663 #define AP_LOCK_ACCOUNT_DURATION        6
664 #define AP_RESET_COUNT_TIME             7
665 #define AP_BAD_ATTEMPT_LOCKOUT          8
666 #define AP_TIME_TO_LOGOUT               9
667
668
669 /*
670  * Flags for local user manipulation.
671  */
672
673 #define LOCAL_ADD_USER 0x1
674 #define LOCAL_DELETE_USER 0x2
675 #define LOCAL_DISABLE_USER 0x4
676 #define LOCAL_ENABLE_USER 0x8
677 #define LOCAL_TRUST_ACCOUNT 0x10
678 #define LOCAL_SET_NO_PASSWORD 0x20
679 #define LOCAL_SET_PASSWORD 0x40
680 #define LOCAL_SET_LDAP_ADMIN_PW 0x80
681 #define LOCAL_INTERDOM_ACCOUNT 0x100
682 #define LOCAL_AM_ROOT 0x200  /* Act as root */
683
684 /* key and data in the connections database - used in smbstatus and smbd */
685 struct connections_key {
686         pid_t pid;
687         int cnum;
688         fstring name;
689 };
690
691 struct connections_data {
692         int magic;
693         pid_t pid;
694         int cnum;
695         uid_t uid;
696         gid_t gid;
697         char name[24];
698         char addr[24];
699         char machine[FSTRING_LEN];
700         time_t start;
701         uint32 bcast_msg_flags;
702 };
703
704 /* the following are used by loadparm for option lists */
705 typedef enum
706 {
707   P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_LIST,
708   P_STRING,P_USTRING,P_ENUM,P_SEP
709 } parm_type;
710
711 typedef enum
712 {
713   P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
714 } parm_class;
715
716 struct enum_list {
717         int value;
718         const char *name;
719 };
720
721 struct parm_struct
722 {
723         const char *label;
724         parm_type type;
725         parm_class class;
726         void *ptr;
727         BOOL (*special)(const char *, char **);
728         const struct enum_list *enum_list;
729         unsigned flags;
730         union {
731                 BOOL bvalue;
732                 int ivalue;
733                 char *svalue;
734                 char cvalue;
735                 char **lvalue;
736         } def;
737 };
738
739 struct bitmap {
740         uint32 *b;
741         unsigned int n;
742 };
743
744 #define FLAG_BASIC      0x0001 /* fundamental options */
745 #define FLAG_SHARE      0x0002 /* file sharing options */
746 #define FLAG_PRINT      0x0004 /* printing options */
747 #define FLAG_GLOBAL     0x0008 /* local options that should be globally settable in SWAT */
748 #define FLAG_WIZARD     0x0010 /* Parameters that the wizard will operate on */
749 #define FLAG_ADVANCED   0x0020 /* Parameters that the wizard will operate on */
750 #define FLAG_DEVELOPER  0x0040 /* Parameters that the wizard will operate on */
751 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
752 #define FLAG_HIDE       0x2000 /* options that should be hidden in SWAT */
753 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
754 #define FLAG_CMDLINE    0x8000 /* this option was set from the command line */
755
756 #ifndef LOCKING_VERSION
757 #define LOCKING_VERSION 4
758 #endif /* LOCKING_VERSION */
759
760
761 /* the basic packet size, assuming no words or bytes. Does not include the NBT header */
762 #define MIN_SMB_SIZE 35
763
764 /* when using NBT encapsulation every packet has a 4 byte header */
765 #define NBT_HDR_SIZE 4
766
767 /* offsets into message header for common items - NOTE: These have
768    changed from being offsets from the base of the NBT packet to the base of the SMB packet.
769    this has reduced all these values by 4
770 */
771 #define HDR_COM 4
772 #define HDR_RCLS 5
773 #define HDR_REH 6
774 #define HDR_ERR 7
775 #define HDR_FLG 9
776 #define HDR_FLG2 10
777 #define HDR_PIDHIGH 12
778 #define HDR_SS_FIELD 14
779 #define HDR_TID 24
780 #define HDR_PID 26
781 #define HDR_UID 28
782 #define HDR_MID 30
783 #define HDR_WCT 32
784 #define HDR_VWV 33
785
786
787 /* types of buffers in core SMB protocol */
788 #define SMB_DATA_BLOCK 0x1
789 #define SMB_ASCII4     0x4
790
791
792 /* flag defines. CIFS spec 3.1.1 */
793 #define FLAG_SUPPORT_LOCKREAD       0x01
794 #define FLAG_CLIENT_BUF_AVAIL       0x02
795 #define FLAG_RESERVED               0x04
796 #define FLAG_CASELESS_PATHNAMES     0x08
797 #define FLAG_CANONICAL_PATHNAMES    0x10
798 #define FLAG_REQUEST_OPLOCK         0x20
799 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
800 #define FLAG_REPLY                  0x80
801
802 /* the complete */
803 #define SMBmkdir      0x00   /* create directory */
804 #define SMBrmdir      0x01   /* delete directory */
805 #define SMBopen       0x02   /* open file */
806 #define SMBcreate     0x03   /* create file */
807 #define SMBclose      0x04   /* close file */
808 #define SMBflush      0x05   /* flush file */
809 #define SMBunlink     0x06   /* delete file */
810 #define SMBmv         0x07   /* rename file */
811 #define SMBgetatr     0x08   /* get file attributes */
812 #define SMBsetatr     0x09   /* set file attributes */
813 #define SMBread       0x0A   /* read from file */
814 #define SMBwrite      0x0B   /* write to file */
815 #define SMBlock       0x0C   /* lock byte range */
816 #define SMBunlock     0x0D   /* unlock byte range */
817 #define SMBctemp      0x0E   /* create temporary file */
818 #define SMBmknew      0x0F   /* make new file */
819 #define SMBchkpth     0x10   /* check directory path */
820 #define SMBexit       0x11   /* process exit */
821 #define SMBlseek      0x12   /* seek */
822 #define SMBtcon       0x70   /* tree connect */
823 #define SMBtconX      0x75   /* tree connect and X*/
824 #define SMBtdis       0x71   /* tree disconnect */
825 #define SMBnegprot    0x72   /* negotiate protocol */
826 #define SMBdskattr    0x80   /* get disk attributes */
827 #define SMBsearch     0x81   /* search directory */
828 #define SMBsplopen    0xC0   /* open print spool file */
829 #define SMBsplwr      0xC1   /* write to print spool file */
830 #define SMBsplclose   0xC2   /* close print spool file */
831 #define SMBsplretq    0xC3   /* return print queue */
832 #define SMBsends      0xD0   /* send single block message */
833 #define SMBsendb      0xD1   /* send broadcast message */
834 #define SMBfwdname    0xD2   /* forward user name */
835 #define SMBcancelf    0xD3   /* cancel forward */
836 #define SMBgetmac     0xD4   /* get machine name */
837 #define SMBsendstrt   0xD5   /* send start of multi-block message */
838 #define SMBsendend    0xD6   /* send end of multi-block message */
839 #define SMBsendtxt    0xD7   /* send text of multi-block message */
840
841 /* Core+ protocol */
842 #define SMBlockread       0x13   /* Lock a range and read */
843 #define SMBwriteunlock 0x14 /* write then range then unlock it */
844 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
845 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
846 #define SMBwritec     0x20  /* secondary write request */
847 #define SMBwriteclose 0x2c  /* write a file then close it */
848
849 /* dos extended protocol */
850 #define SMBreadBraw      0x1A   /* read block raw */
851 #define SMBreadBmpx      0x1B   /* read block multiplexed */
852 #define SMBreadBs        0x1C   /* read block (secondary response) */
853 #define SMBwriteBraw     0x1D   /* write block raw */
854 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
855 #define SMBwriteBs       0x1F   /* write block (secondary request) */
856 #define SMBwriteC        0x20   /* write complete response */
857 #define SMBsetattrE      0x22   /* set file attributes expanded */
858 #define SMBgetattrE      0x23   /* get file attributes expanded */
859 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
860 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
861 #define SMBtranss        0x26   /* transaction (secondary request/response) */
862 #define SMBioctl         0x27   /* IOCTL */
863 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
864 #define SMBcopy          0x29   /* copy */
865 #define SMBmove          0x2A   /* move */
866 #define SMBecho          0x2B   /* echo */
867 #define SMBopenX         0x2D   /* open and X */
868 #define SMBreadX         0x2E   /* read and X */
869 #define SMBwriteX        0x2F   /* write and X */
870 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
871 #define SMBffirst        0x82   /* find first */
872 #define SMBfunique       0x83   /* find unique */
873 #define SMBfclose        0x84   /* find close */
874 #define SMBkeepalive     0x85   /* keepalive */
875 #define SMBinvalid       0xFE   /* invalid command */
876
877 /* Extended 2.0 protocol */
878 #define SMBtrans2        0x32   /* TRANS2 protocol set */
879 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
880 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
881 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
882 #define SMBulogoffX      0x74   /* user logoff */
883
884 /* NT SMB extensions. */
885 #define SMBnttrans       0xA0   /* NT transact */
886 #define SMBnttranss      0xA1   /* NT transact secondary */
887 #define SMBntcreateX     0xA2   /* NT create and X */
888 #define SMBntcancel      0xA4   /* NT cancel */
889 #define SMBntrename      0xA5   /* NT rename */
890
891 /* used to indicate end of chain */
892 #define SMB_CHAIN_NONE   0xFF
893
894 /* These are the trans subcommands */
895 #define TRANSACT_SETNAMEDPIPEHANDLESTATE  0x01 
896 #define TRANSACT_DCERPCCMD                0x26
897 #define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53
898
899 /* These are the NT transact sub commands. */
900 #define NT_TRANSACT_CREATE                1
901 #define NT_TRANSACT_IOCTL                 2
902 #define NT_TRANSACT_SET_SECURITY_DESC     3
903 #define NT_TRANSACT_NOTIFY_CHANGE         4
904 #define NT_TRANSACT_RENAME                5
905 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
906
907 /* this is used on a TConX. I'm not sure the name is very helpful though */
908 #define SMB_SUPPORT_SEARCH_BITS        0x0001
909 #define SMB_SHARE_IN_DFS               0x0002
910
911 /* Named pipe write mode flags. Used in writeX calls. */
912 #define PIPE_RAW_MODE 0x4
913 #define PIPE_START_MESSAGE 0x8
914
915 /* the desired access to use when opening a pipe */
916 #define DESIRED_ACCESS_PIPE 0x2019f
917  
918
919 /* Mapping of generic access rights for files to specific rights. */
920 #define FILE_GENERIC_ALL (STANDARD_RIGHTS_REQUIRED_ACCESS| NT_ACCESS_SYNCHRONIZE_ACCESS|FILE_ALL_ACCESS)
921
922 #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ_ACCESS|FILE_READ_DATA|FILE_READ_ATTRIBUTES|\
923                                                         FILE_READ_EA|NT_ACCESS_SYNCHRONIZE_ACCESS)
924
925 #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE_ACCESS|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|\
926                             FILE_WRITE_EA|FILE_APPEND_DATA|NT_ACCESS_SYNCHRONIZE_ACCESS)
927
928 #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE_ACCESS|FILE_READ_ATTRIBUTES|\
929                             FILE_EXECUTE|NT_ACCESS_SYNCHRONIZE_ACCESS)
930
931
932 /* FileAttributes (search attributes) field */
933 #define FILE_ATTRIBUTE_READONLY         0x0001
934 #define FILE_ATTRIBUTE_HIDDEN           0x0002
935 #define FILE_ATTRIBUTE_SYSTEM           0x0004
936 #define FILE_ATTRIBUTE_VOLUME           0x0008
937 #define FILE_ATTRIBUTE_DIRECTORY        0x0010
938 #define FILE_ATTRIBUTE_ARCHIVE          0x0020
939 #define FILE_ATTRIBUTE_DEVICE           0x0040
940 #define FILE_ATTRIBUTE_NORMAL           0x0080
941 #define FILE_ATTRIBUTE_TEMPORARY        0x0100
942 #define FILE_ATTRIBUTE_SPARSE           0x0200
943 #define FILE_ATTRIBUTE_REPARSE_POINT    0x0400
944 #define FILE_ATTRIBUTE_COMPRESSED       0x0800
945 #define FILE_ATTRIBUTE_OFFLINE          0x1000
946 #define FILE_ATTRIBUTE_NONINDEXED       0x2000
947 #define FILE_ATTRIBUTE_ENCRYPTED        0x4000
948
949 /* Flags - combined with attributes. */
950 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
951 #define FILE_FLAG_NO_BUFFERING     0x20000000L
952 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
953 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
954 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
955 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
956 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
957
958 /* Responses when opening a file. */
959 #define FILE_WAS_SUPERSEDED 0
960 #define FILE_WAS_OPENED 1
961 #define FILE_WAS_CREATED 2
962 #define FILE_WAS_OVERWRITTEN 3
963
964 /* File type flags */
965 #define FILE_TYPE_DISK  0
966 #define FILE_TYPE_BYTE_MODE_PIPE 1
967 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
968 #define FILE_TYPE_PRINTER 3
969 #define FILE_TYPE_COMM_DEVICE 4
970 #define FILE_TYPE_UNKNOWN 0xFFFF
971
972 /* Flag for NT transact rename call. */
973 #define RENAME_REPLACE_IF_EXISTS 1
974
975 /* flags for SMBntrename call */
976 #define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */
977 #define RENAME_FLAG_HARD_LINK                0x103
978 #define RENAME_FLAG_RENAME                   0x104
979 #define RENAME_FLAG_COPY                     0x105
980
981 /* Filesystem Attributes. */
982 #define FILE_CASE_SENSITIVE_SEARCH 0x01
983 #define FILE_CASE_PRESERVED_NAMES 0x02
984 #define FILE_UNICODE_ON_DISK 0x04
985 /* According to cifs9f, this is 4, not 8 */
986 /* Acconding to testing, this actually sets the security attribute! */
987 #define FILE_PERSISTENT_ACLS 0x08
988 /* These entries added from cifs9f --tsb */
989 #define FILE_FILE_COMPRESSION 0x10
990 #define FILE_VOLUME_QUOTAS 0x20
991 /* I think this is wrong. JRA #define FILE_DEVICE_IS_MOUNTED 0x20 */
992 #define FILE_VOLUME_SPARSE_FILE 0x40
993 #define FILE_VOLUME_IS_COMPRESSED 0x8000
994
995 /* ChangeNotify flags. */
996 #define FILE_NOTIFY_CHANGE_FILE        0x001
997 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
998 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
999 #define FILE_NOTIFY_CHANGE_SIZE        0x008
1000 #define FILE_NOTIFY_CHANGE_LAST_WRITE  0x010
1001 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1002 #define FILE_NOTIFY_CHANGE_CREATION    0x040
1003 #define FILE_NOTIFY_CHANGE_EA          0x080
1004 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
1005 #define FILE_NOTIFY_CHANGE_FILE_NAME   0x200
1006
1007 /* change notify action results */
1008 #define NOTIFY_ACTION_ADDED 1
1009 #define NOTIFY_ACTION_REMOVED 2
1010 #define NOTIFY_ACTION_MODIFIED 3
1011 #define NOTIFY_ACTION_OLD_NAME 4
1012 #define NOTIFY_ACTION_NEW_NAME 5
1013 #define NOTIFY_ACTION_ADDED_STREAM 6
1014 #define NOTIFY_ACTION_REMOVED_STREAM 7
1015 #define NOTIFY_ACTION_MODIFIED_STREAM 8
1016
1017 /* seek modes for smb_seek */
1018 #define SEEK_MODE_START   0
1019 #define SEEK_MODE_CURRENT 1
1020 #define SEEK_MODE_END     2
1021
1022 /* where to find the base of the SMB packet proper */
1023 /* REWRITE TODO: smb_base needs to be removed */
1024 #define smb_base(buf) (((char *)(buf))+4)
1025
1026 /* we don't allow server strings to be longer than 48 characters as
1027    otherwise NT will not honour the announce packets */
1028 #define MAX_SERVER_STRING_LENGTH 48
1029
1030
1031 #define SMB_SUCCESS 0  /* The request was successful. */
1032
1033 #ifdef WITH_DFS
1034 void dfs_unlogin(void);
1035 extern int dcelogin_atmost_once;
1036 #endif
1037
1038 #ifdef NOSTRDUP
1039 char *strdup(char *s);
1040 #endif
1041
1042 #ifndef SIGNAL_CAST
1043 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
1044 #endif
1045
1046 #ifndef SELECT_CAST
1047 #define SELECT_CAST
1048 #endif
1049
1050 /* these are used in NetServerEnum to choose what to receive */
1051 #define SV_TYPE_WORKSTATION         0x00000001
1052 #define SV_TYPE_SERVER              0x00000002
1053 #define SV_TYPE_SQLSERVER           0x00000004
1054 #define SV_TYPE_DOMAIN_CTRL         0x00000008
1055 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
1056 #define SV_TYPE_TIME_SOURCE         0x00000020
1057 #define SV_TYPE_AFP                 0x00000040
1058 #define SV_TYPE_NOVELL              0x00000080
1059 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
1060 #define SV_TYPE_PRINTQ_SERVER       0x00000200
1061 #define SV_TYPE_DIALIN_SERVER       0x00000400
1062 #define SV_TYPE_SERVER_UNIX         0x00000800
1063 #define SV_TYPE_NT                  0x00001000
1064 #define SV_TYPE_WFW                 0x00002000
1065 #define SV_TYPE_SERVER_MFPN         0x00004000
1066 #define SV_TYPE_SERVER_NT           0x00008000
1067 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
1068 #define SV_TYPE_BACKUP_BROWSER      0x00020000
1069 #define SV_TYPE_MASTER_BROWSER      0x00040000
1070 #define SV_TYPE_DOMAIN_MASTER       0x00080000
1071 #define SV_TYPE_SERVER_OSF          0x00100000
1072 #define SV_TYPE_SERVER_VMS          0x00200000
1073 #define SV_TYPE_WIN95_PLUS          0x00400000
1074 #define SV_TYPE_DFS_SERVER          0x00800000
1075 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
1076 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
1077 #define SV_TYPE_DOMAIN_ENUM         0x80000000
1078 #define SV_TYPE_ALL                 0xFFFFFFFF  
1079
1080 /* This was set by JHT in liaison with Jeremy Allison early 1997
1081  * History:
1082  * Version 4.0 - never made public
1083  * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9
1084  *              - Reappeared in 1.9.16p11 with fixed smbd services
1085  * Version 4.20 - To indicate that nmbd and browsing now works better
1086  * Version 4.50 - Set at release of samba-2.2.0 by JHT
1087  *
1088  *  Note: In the presence of NT4.X do not set above 4.9
1089  *        Setting this above 4.9 can have undesired side-effects.
1090  *        This may change again in Samba-3.0 after further testing. JHT
1091  */
1092  
1093 #define DEFAULT_MAJOR_VERSION 0x04
1094 #define DEFAULT_MINOR_VERSION 0x09
1095
1096 /* Browser Election Values */
1097 #define BROWSER_ELECTION_VERSION        0x010f
1098 #define BROWSER_CONSTANT        0xaa55
1099
1100 /* Sercurity mode bits. */
1101 #define NEGOTIATE_SECURITY_USER_LEVEL           0x01
1102 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE   0x02
1103 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED   0x04
1104 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED  0x08
1105
1106 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1107    
1108 #define FLAGS2_LONG_PATH_COMPONENTS    0x0001
1109 #define FLAGS2_EXTENDED_ATTRIBUTES     0x0002
1110 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
1111 #define FLAGS2_IS_LONG_NAME            0x0040
1112 #define FLAGS2_EXTENDED_SECURITY       0x0800 
1113 #define FLAGS2_DFS_PATHNAMES           0x1000
1114 #define FLAGS2_READ_PERMIT_NO_EXECUTE  0x2000
1115 #define FLAGS2_32_BIT_ERROR_CODES      0x4000 
1116 #define FLAGS2_UNICODE_STRINGS         0x8000
1117
1118 #define FLAGS2_WIN2K_SIGNATURE         0xC852 /* Hack alert ! For now... JRA. */
1119
1120 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1121
1122 #define CAP_RAW_MODE         0x0001
1123 #define CAP_MPX_MODE         0x0002
1124 #define CAP_UNICODE          0x0004
1125 #define CAP_LARGE_FILES      0x0008
1126 #define CAP_NT_SMBS          0x0010
1127 #define CAP_RPC_REMOTE_APIS  0x0020
1128 #define CAP_STATUS32         0x0040
1129 #define CAP_LEVEL_II_OPLOCKS 0x0080
1130 #define CAP_LOCK_AND_READ    0x0100
1131 #define CAP_NT_FIND          0x0200
1132 #define CAP_DFS              0x1000
1133 #define CAP_W2K_SMBS         0x2000
1134 #define CAP_LARGE_READX      0x4000
1135 #define CAP_LARGE_WRITEX     0x8000
1136 #define CAP_UNIX             0x800000 /* Capabilities for UNIX extensions. Created by HP. */
1137 #define CAP_EXTENDED_SECURITY 0x80000000
1138
1139 /*
1140  * Global value meaing that the smb_uid field should be
1141  * ingored (in share level security and protocol level == CORE)
1142  */
1143
1144 #define UID_FIELD_INVALID 0
1145 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1146
1147 /* Lock types. */
1148 #define LOCKING_ANDX_SHARED_LOCK 0x1
1149 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1150 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1151 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1152 #define LOCKING_ANDX_LARGE_FILES 0x10
1153
1154 /* Oplock levels */
1155 #define OPLOCKLEVEL_NONE 0
1156 #define OPLOCKLEVEL_II 1
1157
1158 /*
1159  * Bits we test with.
1160  */
1161
1162 #define NO_OPLOCK 0
1163 #define EXCLUSIVE_OPLOCK 1
1164 #define BATCH_OPLOCK 2
1165 #define LEVEL_II_OPLOCK 4
1166
1167 #define CORE_OPLOCK_GRANTED (1<<5)
1168 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1169
1170 /*
1171  * Return values for oplock types.
1172  */
1173
1174 #define NO_OPLOCK_RETURN 0
1175 #define EXCLUSIVE_OPLOCK_RETURN 1
1176 #define BATCH_OPLOCK_RETURN 2
1177 #define LEVEL_II_OPLOCK_RETURN 3
1178
1179 /*
1180  * Loopback command offsets.
1181  */
1182
1183 #define OPBRK_CMD_LEN_OFFSET 0
1184 #define OPBRK_CMD_PORT_OFFSET 4
1185 #define OPBRK_CMD_HEADER_LEN 6
1186
1187 #define OPBRK_MESSAGE_CMD_OFFSET 0
1188
1189 /* Message types */
1190 #define OPLOCK_BREAK_CMD 0x1
1191 #define KERNEL_OPLOCK_BREAK_CMD 0x2
1192 #define LEVEL_II_OPLOCK_BREAK_CMD 0x3
1193 #define ASYNC_LEVEL_II_OPLOCK_BREAK_CMD 0x4
1194
1195 /*
1196  * Capabilities abstracted for different systems.
1197  */
1198
1199 #define KERNEL_OPLOCK_CAPABILITY 0x1
1200
1201 /*
1202  * Oplock break command code sent via the kernel interface (if it exists).
1203  *
1204  * Form of this is :
1205  *
1206  *  0     2       2+devsize 2+devsize+inodesize
1207  *  +----+--------+--------+----------+
1208  *  | cmd| dev    |  inode |  fileid  |
1209  *  +----+--------+--------+----------+
1210  */
1211 #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
1212 #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
1213 #define KERNEL_OPLOCK_BREAK_FILEID_OFFSET (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
1214 #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_FILEID_OFFSET + sizeof(unsigned long))
1215
1216
1217 #define CMD_REPLY 0x8000
1218
1219 #include "smb_macros.h"
1220
1221 /* A netbios name structure. */
1222 struct nmb_name {
1223         char         name[17];
1224         char         scope[64];
1225         unsigned int name_type;
1226 };
1227
1228
1229 /* A netbios node status array element. */
1230 struct node_status {
1231         char name[16];
1232         unsigned char type;
1233         unsigned char flags;
1234 };
1235
1236 struct pwd_info
1237 {
1238         BOOL null_pwd;
1239         BOOL cleartext;
1240         BOOL crypted;
1241
1242         fstring password;
1243
1244         uchar smb_lm_pwd[16];
1245         uchar smb_nt_pwd[16];
1246
1247         uchar smb_lm_owf[24];
1248         uchar smb_nt_owf[128];
1249         size_t nt_owf_len;
1250
1251         uchar lm_cli_chal[8];
1252         uchar nt_cli_chal[128];
1253         size_t nt_cli_chal_len;
1254
1255         uchar sess_key[16];
1256 };
1257
1258 #include "rpc_creds.h"
1259 #include "rpc_misc.h"
1260 #include "rpc_secdes.h"
1261 #include "nt_printing.h"
1262
1263 typedef struct user_struct
1264 {
1265         struct user_struct *next, *prev;
1266         uint16 vuid; /* Tag for this entry. */
1267         uid_t uid; /* uid of a validated user */
1268         gid_t gid; /* gid of a validated user */
1269
1270         userdom_struct user;
1271         char *homedir;
1272         char *unix_homedir;
1273         char *logon_script;
1274         
1275         BOOL guest;
1276
1277         /* following groups stuff added by ih */
1278         /* This groups info is needed for when we become_user() for this uid */
1279         int n_groups;
1280         gid_t *groups;
1281
1282         NT_USER_TOKEN *nt_user_token;
1283
1284         uint8 session_key[16];
1285
1286         char *session_keystr; /* used by utmp and pam session code.  
1287                                  TDB key string */
1288         int homes_snum;
1289
1290         struct auth_serversupplied_info *server_info;
1291
1292 } user_struct;
1293
1294
1295 struct unix_error_map {
1296         int unix_error;
1297         int dos_class;
1298         int dos_code;
1299         NTSTATUS nt_error;
1300 };
1301
1302 #include "ntdomain.h"
1303
1304 #include "client.h"
1305
1306 /*
1307  * Size of new password account encoding string.  This is enough space to
1308  * hold 11 ACB characters, plus the surrounding [] and a terminating null.
1309  * Do not change unless you are adding new ACB bits!
1310  */
1311
1312 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
1313
1314 /*
1315    Do you want session setups at user level security with a invalid
1316    password to be rejected or allowed in as guest? WinNT rejects them
1317    but it can be a pain as it means "net view" needs to use a password
1318
1319    You have 3 choices in the setting of map_to_guest:
1320
1321    "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1322    are rejected. This is the default.
1323
1324    "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1325    are rejected, unless the username does not exist, in which case it
1326    is treated as a guest login
1327
1328    "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1329    are treated as a guest login
1330
1331    Note that map_to_guest only has an effect in user or server
1332    level security.
1333 */
1334
1335 #define NEVER_MAP_TO_GUEST 0
1336 #define MAP_TO_GUEST_ON_BAD_USER 1
1337 #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
1338
1339 #define SAFE_NETBIOS_CHARS ". -_"
1340
1341 /* generic iconv conversion structure */
1342 typedef struct {
1343         size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
1344                          char **outbuf, size_t *outbytesleft);
1345         size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
1346                        char **outbuf, size_t *outbytesleft);
1347         size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
1348                        char **outbuf, size_t *outbytesleft);
1349         void *cd_direct, *cd_pull, *cd_push;
1350         char *from_name, *to_name;
1351 } *smb_iconv_t;
1352
1353 /* The maximum length of a trust account password.
1354    Used when we randomly create it, 15 char passwords
1355    exceed NT4's max password length */
1356
1357 #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
1358
1359 /* Module support */
1360 typedef int (init_module_function) (void);
1361
1362
1363 /* a set of flags to control handling of request structures */
1364 #define REQ_CONTROL_PROTECTED (1<<0) /* don't destroy this request */
1365 #define REQ_CONTROL_LARGE     (1<<1) /* allow replies larger than max_xmit */
1366 #define REQ_CONTROL_ASYNC     (1<<2) /* the backend will answer this one later */
1367
1368 /* passed to br lock code */
1369 enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_LOCK};
1370
1371 #include "popt_common.h"
1372
1373 #endif /* _SMB_H */