r18717: remove old defines in preference of the flags in librpc/gen_ndr/srvsvc.h
[abartlet/samba.git/.git] / source3 / 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 /* logged when starting the various Samba daemons */
31 #define COPYRIGHT_STARTUP_MESSAGE       "Copyright Andrew Tridgell and the Samba Team 1992-2006"
32
33
34 #if defined(LARGE_SMB_OFF_T)
35 #define BUFFER_SIZE (128*1024)
36 #else /* no large readwrite possible */
37 #define BUFFER_SIZE (0xFFFF)
38 #endif
39
40 #define SAFETY_MARGIN 1024
41 #define LARGE_WRITEX_HDR_SIZE 65
42
43 #define NMB_PORT 137
44 #define DGRAM_PORT 138
45 #define SMB_PORT1 445
46 #define SMB_PORT2 139
47 #define SMB_PORTS "445 139"
48
49 #define Undefined (-1)
50 #define False (0)
51 #define True (1)
52 #define Auto (2)
53 #define Required (3)
54
55 #define SIZEOFWORD 2
56
57 #ifndef DEF_CREATE_MASK
58 #define DEF_CREATE_MASK (0755)
59 #endif
60
61 /* string manipulation flags - see clistr.c and srvstr.c */
62 #define STR_TERMINATE 1
63 #define STR_UPPER 2
64 #define STR_ASCII 4
65 #define STR_UNICODE 8
66 #define STR_NOALIGN 16
67 #define STR_TERMINATE_ASCII 128
68
69 /* how long to wait for secondary SMB packets (milli-seconds) */
70 #define SMB_SECONDARY_WAIT (60*1000)
71
72 /* Debugging stuff */
73 #include "debug.h"
74
75 /* this defines the error codes that receive_smb can put in smb_read_error */
76 #define READ_TIMEOUT 1
77 #define READ_EOF 2
78 #define READ_ERROR 3
79 #define WRITE_ERROR 4 /* This error code can go into the client smb_rw_error. */
80 #define READ_BAD_SIG 5
81 #define DO_NOT_DO_TDIS 6 /* cli_close_connection() check for this when smbfs wants to keep tree connected */
82
83 #define DIR_STRUCT_SIZE 43
84
85 /* these define the attribute byte as seen by DOS */
86 #define aRONLY (1L<<0)          /* 0x01 */
87 #define aHIDDEN (1L<<1)         /* 0x02 */
88 #define aSYSTEM (1L<<2)         /* 0x04 */
89 #define aVOLID (1L<<3)          /* 0x08 */
90 #define aDIR (1L<<4)            /* 0x10 */
91 #define aARCH (1L<<5)           /* 0x20 */
92
93 /* deny modes */
94 #define DENY_DOS 0
95 #define DENY_ALL 1
96 #define DENY_WRITE 2
97 #define DENY_READ 3
98 #define DENY_NONE 4
99 #define DENY_FCB 7
100
101 /* open modes */
102 #define DOS_OPEN_RDONLY 0
103 #define DOS_OPEN_WRONLY 1
104 #define DOS_OPEN_RDWR 2
105 #define DOS_OPEN_EXEC 3
106 #define DOS_OPEN_FCB 0xF
107
108 /* define shifts and masks for share and open modes. */
109 #define OPENX_MODE_MASK 0xF
110 #define DENY_MODE_SHIFT 4
111 #define DENY_MODE_MASK 0x7
112 #define GET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
113 #define SET_OPENX_MODE(x) ((x) & OPENX_MODE_MASK)
114 #define GET_DENY_MODE(x) (((x)>>DENY_MODE_SHIFT) & DENY_MODE_MASK)
115 #define SET_DENY_MODE(x) (((x) & DENY_MODE_MASK) <<DENY_MODE_SHIFT)
116
117 /* Sync on open file (not sure if used anymore... ?) */
118 #define FILE_SYNC_OPENMODE (1<<14)
119 #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
120
121 /* open disposition values */
122 #define OPENX_FILE_EXISTS_FAIL 0
123 #define OPENX_FILE_EXISTS_OPEN 1
124 #define OPENX_FILE_EXISTS_TRUNCATE 2
125
126 /* mask for open disposition. */
127 #define OPENX_FILE_OPEN_MASK 0x3
128
129 #define GET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
130 #define SET_FILE_OPENX_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
131
132 /* The above can be OR'ed with... */
133 #define OPENX_FILE_CREATE_IF_NOT_EXIST 0x10
134 #define OPENX_FILE_FAIL_IF_NOT_EXIST 0
135
136 /* share types */
137 /* defined in librpc/gen_ndr/srvsvc.h */
138
139 #include "doserr.h"
140
141 typedef union unid_t {
142         uid_t uid;
143         gid_t gid;
144 } unid_t;
145
146 /*
147  * SMB UCS2 (16-bit unicode) internal type.
148  * smb_ucs2_t is *always* in little endian format.
149  */
150
151 typedef uint16 smb_ucs2_t;
152
153 /* ucs2 string types. */
154 typedef smb_ucs2_t wpstring[PSTRING_LEN];
155 typedef smb_ucs2_t wfstring[FSTRING_LEN];
156
157 #ifdef WORDS_BIGENDIAN
158 #define UCS2_SHIFT 8
159 #else
160 #define UCS2_SHIFT 0
161 #endif
162
163 /* turn a 7 bit character into a ucs2 character */
164 #define UCS2_CHAR(c) ((c) << UCS2_SHIFT)
165
166 /* return an ascii version of a ucs2 character */
167 #define UCS2_TO_CHAR(c) (((c) >> UCS2_SHIFT) & 0xff)
168
169 /* Copy into a smb_ucs2_t from a possibly unaligned buffer. Return the copied smb_ucs2_t */
170 #define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\
171                                 ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest))
172
173 /* pipe string names */
174 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
175 #define PIPE_SRVSVC   "\\PIPE\\srvsvc"
176 #define PIPE_SAMR     "\\PIPE\\samr"
177 #define PIPE_WINREG   "\\PIPE\\winreg"
178 #define PIPE_WKSSVC   "\\PIPE\\wkssvc"
179 #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
180 #define PIPE_NTLSA    "\\PIPE\\ntlsa"
181 #define PIPE_NTSVCS   "\\PIPE\\ntsvcs"
182 #define PIPE_LSASS    "\\PIPE\\lsass"
183 #define PIPE_LSARPC   "\\PIPE\\lsarpc"
184 #define PIPE_SPOOLSS  "\\PIPE\\spoolss"
185 #define PIPE_NETDFS   "\\PIPE\\netdfs"
186 #define PIPE_ECHO     "\\PIPE\\rpcecho"
187 #define PIPE_SHUTDOWN "\\PIPE\\initshutdown"
188 #define PIPE_EPM      "\\PIPE\\epmapper"
189 #define PIPE_SVCCTL   "\\PIPE\\svcctl"
190 #define PIPE_EVENTLOG "\\PIPE\\eventlog"
191 #define PIPE_UNIXINFO    "\\PIPE\\unixinfo"
192
193 #define PIPE_NETLOGON_PLAIN "\\NETLOGON"
194
195 #define PI_LSARPC               0
196 #define PI_LSARPC_DS            1
197 #define PI_SAMR                 2
198 #define PI_NETLOGON             3
199 #define PI_SRVSVC               4
200 #define PI_WKSSVC               5
201 #define PI_WINREG               6
202 #define PI_SPOOLSS              7
203 #define PI_NETDFS               8
204 #define PI_RPCECHO              9
205 #define PI_INITSHUTDOWN         10
206 #define PI_SVCCTL               11
207 #define PI_EVENTLOG             12
208 #define PI_UNIXINFO             13
209 #define PI_NTSVCS               14
210 #define PI_MAX_PIPES            15
211
212 /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
213 typedef uint64_t NTTIME;
214
215
216 /* Allowable account control bits */
217 #define ACB_DISABLED                    0x00000001  /* 1 = User account disabled */
218 #define ACB_HOMDIRREQ                   0x00000002  /* 1 = Home directory required */
219 #define ACB_PWNOTREQ                    0x00000004  /* 1 = User password not required */
220 #define ACB_TEMPDUP                     0x00000008  /* 1 = Temporary duplicate account */
221 #define ACB_NORMAL                      0x00000010  /* 1 = Normal user account */
222 #define ACB_MNS                         0x00000020  /* 1 = MNS logon user account */
223 #define ACB_DOMTRUST                    0x00000040  /* 1 = Interdomain trust account */
224 #define ACB_WSTRUST                     0x00000080  /* 1 = Workstation trust account */
225 #define ACB_SVRTRUST                    0x00000100  /* 1 = Server trust account (BDC) */
226 #define ACB_PWNOEXP                     0x00000200  /* 1 = User password does not expire */
227 #define ACB_AUTOLOCK                    0x00000400  /* 1 = Account auto locked */
228
229 /* only valid for > Windows 2000 */
230 #define ACB_ENC_TXT_PWD_ALLOWED         0x00000800  /* 1 = Text password encryped */
231 #define ACB_SMARTCARD_REQUIRED          0x00001000  /* 1 = Smart Card required */
232 #define ACB_TRUSTED_FOR_DELEGATION      0x00002000  /* 1 = Trusted for Delegation */
233 #define ACB_NOT_DELEGATED               0x00004000  /* 1 = Not delegated */
234 #define ACB_USE_DES_KEY_ONLY            0x00008000  /* 1 = Use DES key only */
235 #define ACB_DONT_REQUIRE_PREAUTH        0x00010000  /* 1 = Preauth not required */
236 #define ACB_PWEXPIRED                   0x00020000  /* 1 = Password is expired */
237 #define ACB_NO_AUTH_DATA_REQD           0x00080000  /* 1 = No authorization data required */
238
239 #define MAX_HOURS_LEN 32
240
241 #ifndef MAXSUBAUTHS
242 #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
243 #endif
244
245 #define SID_MAX_SIZE ((size_t)(8+(MAXSUBAUTHS*4)))
246
247 #define LOOKUP_NAME_ISOLATED 1  /* Look up unqualified names */
248 #define LOOKUP_NAME_REMOTE   2  /* Ask others */
249 #define LOOKUP_NAME_ALL (LOOKUP_NAME_ISOLATED|LOOKUP_NAME_REMOTE)
250
251 #define LOOKUP_NAME_GROUP    4  /* (unused) This is a NASTY hack for valid users = @foo
252                                  * where foo also exists in as user. */
253
254 /**
255  * @brief Security Identifier
256  *
257  * @sa http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/accctrl_38yn.asp
258  **/
259 typedef struct dom_sid {
260         uint8  sid_rev_num;             /**< SID revision number */
261         uint8  num_auths;               /**< Number of sub-authorities */
262         uint8  id_auth[6];              /**< Identifier Authority */
263         /*
264          *  Pointer to sub-authorities.
265          *
266          * @note The values in these uint32's are in *native* byteorder, not
267          * neccessarily little-endian...... JRA.
268          */
269         uint32 sub_auths[MAXSUBAUTHS];  
270 } DOM_SID;
271
272 #define dom_sid2 dom_sid
273 #define dom_sid28 dom_sid
274
275 #include "librpc/ndr/misc.h"
276 #include "librpc/ndr/security.h"
277 #include "librpc/ndr/libndr.h"
278 #include "librpc/gen_ndr/unixinfo.h"
279 #include "librpc/gen_ndr/lsa.h"
280 #include "librpc/gen_ndr/dfs.h"
281 #include "librpc/gen_ndr/initshutdown.h"
282 #include "librpc/gen_ndr/winreg.h"
283 #include "librpc/gen_ndr/eventlog.h"
284 #include "librpc/gen_ndr/srvsvc.h"
285 #include "librpc/gen_ndr/wkssvc.h"
286
287 struct lsa_dom_info {
288         BOOL valid;
289         DOM_SID sid;
290         const char *name;
291         int num_idxs;
292         int *idxs;
293 };
294
295 struct lsa_name_info {
296         uint32 rid;
297         enum lsa_SidType type;
298         const char *name;
299         int dom_idx;
300 };
301
302 /* Some well-known SIDs */
303 extern const DOM_SID global_sid_World_Domain;
304 extern const DOM_SID global_sid_World;
305 extern const DOM_SID global_sid_Creator_Owner_Domain;
306 extern const DOM_SID global_sid_NT_Authority;
307 extern const DOM_SID global_sid_System;
308 extern const DOM_SID global_sid_NULL;
309 extern const DOM_SID global_sid_Authenticated_Users;
310 extern const DOM_SID global_sid_Network;
311 extern const DOM_SID global_sid_Creator_Owner;
312 extern const DOM_SID global_sid_Creator_Group;
313 extern const DOM_SID global_sid_Anonymous;
314 extern const DOM_SID global_sid_Builtin;
315 extern const DOM_SID global_sid_Builtin_Administrators;
316 extern const DOM_SID global_sid_Builtin_Users;
317 extern const DOM_SID global_sid_Builtin_Guests;
318 extern const DOM_SID global_sid_Builtin_Power_Users;
319 extern const DOM_SID global_sid_Builtin_Account_Operators;
320 extern const DOM_SID global_sid_Builtin_Server_Operators;
321 extern const DOM_SID global_sid_Builtin_Print_Operators;
322 extern const DOM_SID global_sid_Builtin_Backup_Operators;
323 extern const DOM_SID global_sid_Builtin_Replicator;
324 extern const DOM_SID global_sid_Builtin_PreWin2kAccess;
325 extern const DOM_SID global_sid_Unix_Users;
326 extern const DOM_SID global_sid_Unix_Groups;
327
328 /*
329  * The complete list of SIDS belonging to this user.
330  * Created when a vuid is registered.
331  * The definition of the user_sids array is as follows :
332  *
333  * token->user_sids[0] = primary user SID.
334  * token->user_sids[1] = primary group SID.
335  * token->user_sids[2..num_sids] = supplementary group SIDS.
336  */
337
338 #define PRIMARY_USER_SID_INDEX 0
339 #define PRIMARY_GROUP_SID_INDEX 1
340
341 typedef struct nt_user_token {
342         size_t num_sids;
343         DOM_SID *user_sids;
344         SE_PRIV privileges;
345 } NT_USER_TOKEN;
346
347 typedef struct _unix_token {
348         uid_t uid;
349         gid_t gid;
350         int ngroups;
351         gid_t *groups;
352 } UNIX_USER_TOKEN;
353
354 /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
355 typedef struct time_info {
356         uint32 time;
357 } UTIME;
358
359 /* Structure used when SMBwritebmpx is active */
360 typedef struct {
361         size_t wr_total_written; /* So we know when to discard this */
362         int32 wr_timeout;
363         int32 wr_errclass; /* Cached errors */
364         int32 wr_error; /* Cached errors */
365         NTSTATUS wr_status; /* Cached errors */
366         BOOL  wr_mode; /* write through mode) */
367         BOOL  wr_discard; /* discard all further data */
368 } write_bmpx_struct;
369
370 typedef struct write_cache {
371         SMB_OFF_T file_size;
372         SMB_OFF_T offset;
373         size_t alloc_size;
374         size_t data_size;
375         char *data;
376 } write_cache;
377
378 typedef struct {
379         smb_ucs2_t *origname;
380         smb_ucs2_t *filename;
381         SMB_STRUCT_STAT *statinfo;
382 } smb_filename;
383
384 #include "fake_file.h"
385
386 struct fd_handle {
387         size_t ref_count;
388         int fd;
389         SMB_BIG_UINT position_information;
390         SMB_OFF_T pos;
391         uint32 private_options; /* NT Create options, but we only look at
392                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_DOS and
393                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_FCB (Except
394                                  * for print files *only*, where
395                                  * DELETE_ON_CLOSE is not stored in the share
396                                  * mode database.
397                                  */
398         unsigned long file_id;
399 };
400
401 struct timed_event;
402 struct idle_event;
403 struct share_mode_entry;
404 struct uuid;
405
406 struct vfs_fsp_data {
407     struct vfs_fsp_data *next;
408     struct vfs_handle_struct *owner;
409     /* NOTE: This structure contains two pointers so that we can guarantee
410      * that the end of the structure is always both 4-byte and 8-byte aligned.
411      */
412 };
413
414 typedef struct files_struct {
415         struct files_struct *next, *prev;
416         int fnum;
417         struct connection_struct *conn;
418         struct fd_handle *fh;
419         unsigned int num_smb_operations;
420         uint16 rap_print_jobid;
421         SMB_DEV_T dev;
422         SMB_INO_T inode;
423         SMB_BIG_UINT initial_allocation_size; /* Faked up initial allocation on disk. */
424         mode_t mode;
425         uint16 file_pid;
426         uint16 vuid;
427         write_bmpx_struct *wbmpx_ptr;
428         write_cache *wcp;
429         struct timeval open_time;
430         uint32 access_mask;             /* NTCreateX access bits (FILE_READ_DATA etc.) */
431         uint32 share_access;            /* NTCreateX share constants (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE). */
432         BOOL pending_modtime_owner;
433         time_t pending_modtime;
434         time_t last_write_time;
435         int oplock_type;
436         int sent_oplock_break;
437         struct timed_event *oplock_timeout;
438         struct lock_struct last_lock_failure;
439
440         struct share_mode_entry *pending_break_messages;
441         int num_pending_break_messages;
442
443         BOOL can_lock;
444         BOOL can_read;
445         BOOL can_write;
446         BOOL print_file;
447         BOOL modified;
448         BOOL is_directory;
449         BOOL is_stat;
450         BOOL aio_write_behind;
451         BOOL lockdb_clean;
452         char *fsp_name;
453
454         struct vfs_fsp_data *vfs_extension;
455         FAKE_FILE_HANDLE *fake_file_handle;
456 } files_struct;
457
458 #include "ntquotas.h"
459 #include "sysquotas.h"
460
461 /* used to hold an arbitrary blob of data */
462 typedef struct data_blob_ {
463         uint8 *data;
464         size_t length;
465         void (*free)(struct data_blob_ *data_blob);
466 } DATA_BLOB;
467
468 /*
469  * Structure used to keep directory state information around.
470  * Used in NT change-notify code.
471  */
472
473 typedef struct {
474         time_t modify_time;
475         time_t status_time;
476 } dir_status_struct;
477
478 struct vuid_cache_entry {
479         uint16 vuid;
480         BOOL read_only;
481         BOOL admin_user;
482 };
483
484 struct vuid_cache {
485         unsigned int entries;
486         struct vuid_cache_entry array[VUID_CACHE_SIZE];
487 };
488
489 typedef struct {
490         char *name;
491         BOOL is_wild;
492 } name_compare_entry;
493
494 struct trans_state {
495         struct trans_state *next, *prev;
496         uint16 vuid;
497         uint16 mid;
498
499         uint32 max_param_return;
500         uint32 max_data_return;
501         uint32 max_setup_return;
502
503         uint8 cmd;              /* SMBtrans or SMBtrans2 */
504
505         fstring name;           /* for trans requests */
506         uint16 call;            /* for trans2 and nttrans requests */
507
508         BOOL close_on_completion;
509         BOOL one_way;
510
511         unsigned int setup_count;
512         uint16 *setup;
513
514         size_t received_data;
515         size_t received_param;
516
517         size_t total_param;
518         char *param;
519
520         size_t total_data;
521         char *data;
522 };
523
524 /* Include VFS stuff */
525
526 #include "smb_acls.h"
527 #include "vfs.h"
528
529 struct dfree_cached_info {
530         time_t last_dfree_time;
531         SMB_BIG_UINT dfree_ret;
532         SMB_BIG_UINT bsize;
533         SMB_BIG_UINT dfree;
534         SMB_BIG_UINT dsize;
535 };
536
537 struct dptr_struct;
538
539 struct share_params {
540         int service;
541 };
542
543 struct share_iterator {
544         int next_id;
545 };
546
547 typedef struct connection_struct {
548         struct connection_struct *next, *prev;
549         TALLOC_CTX *mem_ctx;
550         unsigned cnum; /* an index passed over the wire */
551         struct share_params *params;
552         BOOL force_user;
553         BOOL force_group;
554         struct vuid_cache vuid_cache;
555         struct dptr_struct *dirptr;
556         BOOL printer;
557         BOOL ipc;
558         BOOL read_only; /* Attributes for the current user of the share. */
559         BOOL admin_user; /* Attributes for the current user of the share. */
560         char *dirpath;
561         char *connectpath;
562         char *origpath;
563
564         struct vfs_ops vfs;                   /* Filesystem operations */
565         struct vfs_ops vfs_opaque;                      /* OPAQUE Filesystem operations */
566         struct vfs_handle_struct *vfs_handles;          /* for the new plugins */
567
568         char *user; /* name of user who *opened* this connection */
569         uid_t uid; /* uid of user who *opened* this connection */
570         gid_t gid; /* gid of user who *opened* this connection */
571         char client_address[18]; /* String version of client IP address. */
572
573         uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
574
575         /* following groups stuff added by ih */
576
577         /* This groups info is valid for the user that *opened* the connection */
578         size_t ngroups;
579         gid_t *groups;
580         NT_USER_TOKEN *nt_user_token;
581         
582         time_t lastused;
583         time_t lastused_count;
584         BOOL used;
585         int num_files_open;
586         unsigned int num_smb_operations; /* Count of smb operations on this tree. */
587
588         BOOL case_sensitive;
589         BOOL case_preserve;
590         BOOL short_case_preserve;
591
592         name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
593         name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
594         name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */       
595         name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */       
596         struct dfree_cached_info *dfree_info;
597         struct trans_state *pending_trans;
598 } connection_struct;
599
600 struct current_user {
601         connection_struct *conn;
602         uint16 vuid;
603         UNIX_USER_TOKEN ut;
604         NT_USER_TOKEN *nt_user_token;
605 };
606
607 /* Defines for the sent_oplock_break field above. */
608 #define NO_BREAK_SENT 0
609 #define BREAK_TO_NONE_SENT 1
610 #define LEVEL_II_BREAK_SENT 2
611
612 typedef struct {
613         fstring smb_name; /* user name from the client */
614         fstring unix_name; /* unix user name of a validated user */
615         fstring full_name; /* to store full name (such as "Joe Bloggs") from gecos field of password file */
616         fstring domain; /* domain that the client specified */
617 } userdom_struct;
618
619 /* Extra fields above "LPQ_PRINTING" are used to map extra NT status codes. */
620
621 enum {LPQ_QUEUED=0,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING,LPQ_ERROR,LPQ_DELETING,
622       LPQ_OFFLINE,LPQ_PAPEROUT,LPQ_PRINTED,LPQ_DELETED,LPQ_BLOCKED,LPQ_USER_INTERVENTION};
623
624 typedef struct _print_queue_struct {
625         int job;                /* normally the UNIX jobid -- see note in 
626                                    printing.c:traverse_fn_delete() */
627         int size;
628         int page_count;
629         int status;
630         int priority;
631         time_t time;
632         fstring fs_user;
633         fstring fs_file;
634 } print_queue_struct;
635
636 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
637
638 typedef struct {
639         fstring message;
640         int qcount;
641         int status;
642 }  print_status_struct;
643
644 /* used for server information: client, nameserv and ipc */
645 struct server_info_struct {
646         fstring name;
647         uint32 type;
648         fstring comment;
649         fstring domain; /* used ONLY in ipc.c NOT namework.c */
650         BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
651 };
652
653 /* used for network interfaces */
654 struct interface {
655         struct interface *next, *prev;
656         struct in_addr ip;
657         struct in_addr bcast;
658         struct in_addr nmask;
659 };
660
661 /* Internal message queue for deferred opens. */
662 struct pending_message_list {
663         struct pending_message_list *next, *prev;
664         struct timeval request_time; /* When was this first issued? */
665         struct timeval end_time; /* When does this time out? */
666         DATA_BLOB buf;
667         DATA_BLOB private_data;
668 };
669
670 /* struct returned by get_share_modes */
671 struct share_mode_entry {
672         struct process_id pid;
673         uint16 op_mid;
674         uint16 op_type;
675         uint32 access_mask;             /* NTCreateX access bits (FILE_READ_DATA etc.) */
676         uint32 share_access;            /* NTCreateX share constants (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE). */
677         uint32 private_options; /* NT Create options, but we only look at
678                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_DOS and
679                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_FCB for
680                                  * smbstatus and swat */
681         struct timeval time;
682         SMB_DEV_T dev;
683         SMB_INO_T inode;
684         unsigned long share_file_id;
685         uint32 uid;             /* uid of file opener. */
686 };
687
688 /* oplock break message definition - linearization of share_mode_entry.
689
690 Offset  Data                    length.
691 0       struct process_id pid   4
692 4       uint16 op_mid           2
693 6       uint16 op_type          2
694 8       uint32 access_mask      4
695 12      uint32 share_access     4
696 16      uint32 private_options  4
697 20      uint32 time sec         4
698 24      uint32 time usec        4
699 28      SMB_DEV_T dev           8 bytes.
700 36      SMB_INO_T inode         8 bytes
701 44      unsigned long file_id   4 bytes
702 48      uint32 uid              4 bytes
703 52
704
705 */
706 #define MSG_SMB_SHARE_MODE_ENTRY_SIZE 52
707
708 struct share_mode_lock {
709         const char *servicepath; /* canonicalized. */
710         const char *filename;
711         SMB_DEV_T dev;
712         SMB_INO_T ino;
713         int num_share_modes;
714         struct share_mode_entry *share_modes;
715         UNIX_USER_TOKEN *delete_token;
716         BOOL delete_on_close;
717         BOOL initial_delete_on_close;
718         BOOL fresh;
719         BOOL modified;
720 };
721
722 /*
723  * Internal structure of locking.tdb share mode db.
724  * Used by locking.c and libsmbsharemodes.c
725  */
726
727 struct locking_data {
728         union {
729                 struct {
730                         int num_share_mode_entries;
731                         BOOL delete_on_close;
732                         BOOL initial_delete_on_close; /* Only set at NTCreateX if file was created. */
733                         uint32 delete_token_size; /* Only valid if either of
734                                                      the two previous fields
735                                                      are True. */
736                 } s;
737                 struct share_mode_entry dummy; /* Needed for alignment. */
738         } u;
739         /* The following four entries are implicit
740            struct share_mode_entry modes[num_share_mode_entries];
741            char unix_token[delete_token_size] (divisible by 4).
742            char share_name[];
743            char file_name[];
744         */
745 };
746
747 /* Used to store pipe open records for NetFileEnum() */
748
749 struct pipe_open_rec {
750         struct process_id pid;
751         uid_t uid;
752         int pnum;
753         fstring name;
754 };
755
756
757 #define NT_HASH_LEN 16
758 #define LM_HASH_LEN 16
759
760 /* Password history contants. */
761 #define PW_HISTORY_SALT_LEN 16
762 #define SALTED_MD5_HASH_LEN 16
763 #define PW_HISTORY_ENTRY_LEN (PW_HISTORY_SALT_LEN+SALTED_MD5_HASH_LEN)
764 #define MAX_PW_HISTORY_LEN 24
765
766 /*
767  * Flags for account policy.
768  */
769 #define AP_MIN_PASSWORD_LEN             1
770 #define AP_PASSWORD_HISTORY             2
771 #define AP_USER_MUST_LOGON_TO_CHG_PASS  3
772 #define AP_MAX_PASSWORD_AGE             4
773 #define AP_MIN_PASSWORD_AGE             5
774 #define AP_LOCK_ACCOUNT_DURATION        6
775 #define AP_RESET_COUNT_TIME             7
776 #define AP_BAD_ATTEMPT_LOCKOUT          8
777 #define AP_TIME_TO_LOGOUT               9
778 #define AP_REFUSE_MACHINE_PW_CHANGE     10
779
780 /*
781  * Flags for local user manipulation.
782  */
783
784 #define LOCAL_ADD_USER 0x1
785 #define LOCAL_DELETE_USER 0x2
786 #define LOCAL_DISABLE_USER 0x4
787 #define LOCAL_ENABLE_USER 0x8
788 #define LOCAL_TRUST_ACCOUNT 0x10
789 #define LOCAL_SET_NO_PASSWORD 0x20
790 #define LOCAL_SET_PASSWORD 0x40
791 #define LOCAL_SET_LDAP_ADMIN_PW 0x80
792 #define LOCAL_INTERDOM_ACCOUNT 0x100
793 #define LOCAL_AM_ROOT 0x200  /* Act as root */
794
795 /* key and data in the connections database - used in smbstatus and smbd */
796 struct connections_key {
797         struct process_id pid;
798         int cnum;
799         fstring name;
800 };
801
802 struct connections_data {
803         int magic;
804         struct process_id pid;
805         int cnum;
806         uid_t uid;
807         gid_t gid;
808         char name[24];
809         char addr[24];
810         char machine[FSTRING_LEN];
811         time_t start;
812         uint32 bcast_msg_flags;
813 };
814
815
816 /* the following are used by loadparm for option lists */
817 typedef enum {
818         P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_LIST,
819         P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
820 } parm_type;
821
822 typedef enum {
823         P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
824 } parm_class;
825
826 struct enum_list {
827         int value;
828         const char *name;
829 };
830
831 struct parm_struct {
832         const char *label;
833         parm_type type;
834         parm_class p_class;
835         void *ptr;
836         BOOL (*special)(int snum, const char *, char **);
837         const struct enum_list *enum_list;
838         unsigned flags;
839         union {
840                 BOOL bvalue;
841                 int ivalue;
842                 char *svalue;
843                 char cvalue;
844                 char **lvalue;
845         } def;
846 };
847
848 /* The following flags are used in SWAT */
849 #define FLAG_BASIC      0x0001 /* Display only in BASIC view */
850 #define FLAG_SHARE      0x0002 /* file sharing options */
851 #define FLAG_PRINT      0x0004 /* printing options */
852 #define FLAG_GLOBAL     0x0008 /* local options that should be globally settable in SWAT */
853 #define FLAG_WIZARD     0x0010 /* Parameters that the wizard will operate on */
854 #define FLAG_ADVANCED   0x0020 /* Parameters that will be visible in advanced view */
855 #define FLAG_DEVELOPER  0x0040 /* No longer used */
856 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
857 #define FLAG_HIDE       0x2000 /* options that should be hidden in SWAT */
858 #define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
859
860 struct bitmap {
861         uint32 *b;
862         unsigned int n;
863 };
864
865 /* the basic packet size, assuming no words or bytes */
866 #define smb_size 39
867
868 /* offsets into message for common items */
869 #define smb_com 8
870 #define smb_rcls 9
871 #define smb_reh 10
872 #define smb_err 11
873 #define smb_flg 13
874 #define smb_flg2 14
875 #define smb_pidhigh 16
876 #define smb_ss_field 18
877 #define smb_tid 28
878 #define smb_pid 30
879 #define smb_uid 32
880 #define smb_mid 34
881 #define smb_wct 36
882 #define smb_vwv 37
883 #define smb_vwv0 37
884 #define smb_vwv1 39
885 #define smb_vwv2 41
886 #define smb_vwv3 43
887 #define smb_vwv4 45
888 #define smb_vwv5 47
889 #define smb_vwv6 49
890 #define smb_vwv7 51
891 #define smb_vwv8 53
892 #define smb_vwv9 55
893 #define smb_vwv10 57
894 #define smb_vwv11 59
895 #define smb_vwv12 61
896 #define smb_vwv13 63
897 #define smb_vwv14 65
898 #define smb_vwv15 67
899 #define smb_vwv16 69
900 #define smb_vwv17 71
901
902 /* flag defines. CIFS spec 3.1.1 */
903 #define FLAG_SUPPORT_LOCKREAD       0x01
904 #define FLAG_CLIENT_BUF_AVAIL       0x02
905 #define FLAG_RESERVED               0x04
906 #define FLAG_CASELESS_PATHNAMES     0x08
907 #define FLAG_CANONICAL_PATHNAMES    0x10
908 #define FLAG_REQUEST_OPLOCK         0x20
909 #define FLAG_REQUEST_BATCH_OPLOCK   0x40
910 #define FLAG_REPLY                  0x80
911
912 /* the complete */
913 #define SMBmkdir      0x00   /* create directory */
914 #define SMBrmdir      0x01   /* delete directory */
915 #define SMBopen       0x02   /* open file */
916 #define SMBcreate     0x03   /* create file */
917 #define SMBclose      0x04   /* close file */
918 #define SMBflush      0x05   /* flush file */
919 #define SMBunlink     0x06   /* delete file */
920 #define SMBmv         0x07   /* rename file */
921 #define SMBgetatr     0x08   /* get file attributes */
922 #define SMBsetatr     0x09   /* set file attributes */
923 #define SMBread       0x0A   /* read from file */
924 #define SMBwrite      0x0B   /* write to file */
925 #define SMBlock       0x0C   /* lock byte range */
926 #define SMBunlock     0x0D   /* unlock byte range */
927 #define SMBctemp      0x0E   /* create temporary file */
928 #define SMBmknew      0x0F   /* make new file */
929 #define SMBchkpth     0x10   /* check directory path */
930 #define SMBexit       0x11   /* process exit */
931 #define SMBlseek      0x12   /* seek */
932 #define SMBtcon       0x70   /* tree connect */
933 #define SMBtconX      0x75   /* tree connect and X*/
934 #define SMBtdis       0x71   /* tree disconnect */
935 #define SMBnegprot    0x72   /* negotiate protocol */
936 #define SMBdskattr    0x80   /* get disk attributes */
937 #define SMBsearch     0x81   /* search directory */
938 #define SMBsplopen    0xC0   /* open print spool file */
939 #define SMBsplwr      0xC1   /* write to print spool file */
940 #define SMBsplclose   0xC2   /* close print spool file */
941 #define SMBsplretq    0xC3   /* return print queue */
942 #define SMBsends      0xD0   /* send single block message */
943 #define SMBsendb      0xD1   /* send broadcast message */
944 #define SMBfwdname    0xD2   /* forward user name */
945 #define SMBcancelf    0xD3   /* cancel forward */
946 #define SMBgetmac     0xD4   /* get machine name */
947 #define SMBsendstrt   0xD5   /* send start of multi-block message */
948 #define SMBsendend    0xD6   /* send end of multi-block message */
949 #define SMBsendtxt    0xD7   /* send text of multi-block message */
950
951 /* Core+ protocol */
952 #define SMBlockread       0x13   /* Lock a range and read */
953 #define SMBwriteunlock 0x14 /* Unlock a range then write */
954 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
955 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
956 #define SMBwritec     0x20  /* secondary write request */
957 #define SMBwriteclose 0x2c  /* write a file then close it */
958
959 /* dos extended protocol */
960 #define SMBreadBraw      0x1A   /* read block raw */
961 #define SMBreadBmpx      0x1B   /* read block multiplexed */
962 #define SMBreadBs        0x1C   /* read block (secondary response) */
963 #define SMBwriteBraw     0x1D   /* write block raw */
964 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
965 #define SMBwriteBs       0x1F   /* write block (secondary request) */
966 #define SMBwriteC        0x20   /* write complete response */
967 #define SMBsetattrE      0x22   /* set file attributes expanded */
968 #define SMBgetattrE      0x23   /* get file attributes expanded */
969 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
970 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
971 #define SMBtranss        0x26   /* transaction (secondary request/response) */
972 #define SMBioctl         0x27   /* IOCTL */
973 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
974 #define SMBcopy          0x29   /* copy */
975 #define SMBmove          0x2A   /* move */
976 #define SMBecho          0x2B   /* echo */
977 #define SMBopenX         0x2D   /* open and X */
978 #define SMBreadX         0x2E   /* read and X */
979 #define SMBwriteX        0x2F   /* write and X */
980 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
981 #define SMBffirst        0x82   /* find first */
982 #define SMBfunique       0x83   /* find unique */
983 #define SMBfclose        0x84   /* find close */
984 #define SMBkeepalive     0x85   /* keepalive */
985 #define SMBinvalid       0xFE   /* invalid command */
986
987 /* Extended 2.0 protocol */
988 #define SMBtrans2        0x32   /* TRANS2 protocol set */
989 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
990 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
991 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
992 #define SMBulogoffX      0x74   /* user logoff */
993
994 /* NT SMB extensions. */
995 #define SMBnttrans       0xA0   /* NT transact */
996 #define SMBnttranss      0xA1   /* NT transact secondary */
997 #define SMBntcreateX     0xA2   /* NT create and X */
998 #define SMBntcancel      0xA4   /* NT cancel */
999 #define SMBntrename      0xA5   /* NT rename */
1000
1001 /* These are the trans subcommands */
1002 #define TRANSACT_SETNAMEDPIPEHANDLESTATE  0x01 
1003 #define TRANSACT_DCERPCCMD                0x26
1004 #define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53
1005
1006 /* These are the TRANS2 sub commands */
1007 #define TRANSACT2_OPEN                          0x00
1008 #define TRANSACT2_FINDFIRST                     0x01
1009 #define TRANSACT2_FINDNEXT                      0x02
1010 #define TRANSACT2_QFSINFO                       0x03
1011 #define TRANSACT2_SETFSINFO                     0x04
1012 #define TRANSACT2_QPATHINFO                     0x05
1013 #define TRANSACT2_SETPATHINFO                   0x06
1014 #define TRANSACT2_QFILEINFO                     0x07
1015 #define TRANSACT2_SETFILEINFO                   0x08
1016 #define TRANSACT2_FSCTL                         0x09
1017 #define TRANSACT2_IOCTL                         0x0A
1018 #define TRANSACT2_FINDNOTIFYFIRST               0x0B
1019 #define TRANSACT2_FINDNOTIFYNEXT                0x0C
1020 #define TRANSACT2_MKDIR                         0x0D
1021 #define TRANSACT2_SESSION_SETUP                 0x0E
1022 #define TRANSACT2_GET_DFS_REFERRAL              0x10
1023 #define TRANSACT2_REPORT_DFS_INCONSISTANCY      0x11
1024
1025 /* These are the NT transact sub commands. */
1026 #define NT_TRANSACT_CREATE                1
1027 #define NT_TRANSACT_IOCTL                 2
1028 #define NT_TRANSACT_SET_SECURITY_DESC     3
1029 #define NT_TRANSACT_NOTIFY_CHANGE         4
1030 #define NT_TRANSACT_RENAME                5
1031 #define NT_TRANSACT_QUERY_SECURITY_DESC   6
1032 #define NT_TRANSACT_GET_USER_QUOTA        7
1033 #define NT_TRANSACT_SET_USER_QUOTA        8
1034
1035 /* These are the NT transact_get_user_quota sub commands */
1036 #define TRANSACT_GET_USER_QUOTA_LIST_CONTINUE   0x0000
1037 #define TRANSACT_GET_USER_QUOTA_LIST_START      0x0100
1038 #define TRANSACT_GET_USER_QUOTA_FOR_SID         0x0101
1039
1040 /* Relevant IOCTL codes */
1041 #define IOCTL_QUERY_JOB_INFO      0x530060
1042
1043 /* these are the trans2 sub fields for primary requests */
1044 #define smb_tpscnt smb_vwv0
1045 #define smb_tdscnt smb_vwv1
1046 #define smb_mprcnt smb_vwv2
1047 #define smb_mdrcnt smb_vwv3
1048 #define smb_msrcnt smb_vwv4
1049 #define smb_flags smb_vwv5
1050 #define smb_timeout smb_vwv6
1051 #define smb_pscnt smb_vwv9
1052 #define smb_psoff smb_vwv10
1053 #define smb_dscnt smb_vwv11
1054 #define smb_dsoff smb_vwv12
1055 #define smb_suwcnt smb_vwv13
1056 #define smb_setup smb_vwv14
1057 #define smb_setup0 smb_setup
1058 #define smb_setup1 (smb_setup+2)
1059 #define smb_setup2 (smb_setup+4)
1060
1061 /* these are for the secondary requests */
1062 #define smb_spscnt smb_vwv2
1063 #define smb_spsoff smb_vwv3
1064 #define smb_spsdisp smb_vwv4
1065 #define smb_sdscnt smb_vwv5
1066 #define smb_sdsoff smb_vwv6
1067 #define smb_sdsdisp smb_vwv7
1068 #define smb_sfid smb_vwv8
1069
1070 /* and these for responses */
1071 #define smb_tprcnt smb_vwv0
1072 #define smb_tdrcnt smb_vwv1
1073 #define smb_prcnt smb_vwv3
1074 #define smb_proff smb_vwv4
1075 #define smb_prdisp smb_vwv5
1076 #define smb_drcnt smb_vwv6
1077 #define smb_droff smb_vwv7
1078 #define smb_drdisp smb_vwv8
1079
1080 /* these are for the NT trans primary request. */
1081 #define smb_nt_MaxSetupCount smb_vwv0
1082 #define smb_nt_Flags (smb_vwv0 + 1)
1083 #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
1084 #define smb_nt_TotalDataCount (smb_vwv0 + 7)
1085 #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
1086 #define smb_nt_MaxDataCount (smb_vwv0 + 15)
1087 #define smb_nt_ParameterCount (smb_vwv0 + 19)
1088 #define smb_nt_ParameterOffset (smb_vwv0 + 23)
1089 #define smb_nt_DataCount (smb_vwv0 + 27)
1090 #define smb_nt_DataOffset (smb_vwv0 + 31)
1091 #define smb_nt_SetupCount (smb_vwv0 + 35)
1092 #define smb_nt_Function (smb_vwv0 + 36)
1093 #define smb_nt_SetupStart (smb_vwv0 + 38)
1094
1095 /* these are for the NT trans secondary request. */
1096 #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
1097 #define smb_nts_TotalDataCount (smb_vwv0 + 7)
1098 #define smb_nts_ParameterCount (smb_vwv0 + 11)
1099 #define smb_nts_ParameterOffset (smb_vwv0 + 15)
1100 #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
1101 #define smb_nts_DataCount (smb_vwv0 + 23)
1102 #define smb_nts_DataOffset (smb_vwv0 + 27)
1103 #define smb_nts_DataDisplacement (smb_vwv0 + 31)
1104
1105 /* these are for the NT trans reply. */
1106 #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
1107 #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
1108 #define smb_ntr_ParameterCount (smb_vwv0 + 11)
1109 #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
1110 #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
1111 #define smb_ntr_DataCount (smb_vwv0 + 23)
1112 #define smb_ntr_DataOffset (smb_vwv0 + 27)
1113 #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
1114
1115 /* these are for the NT create_and_X */
1116 #define smb_ntcreate_NameLength (smb_vwv0 + 5)
1117 #define smb_ntcreate_Flags (smb_vwv0 + 7)
1118 #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
1119 #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
1120 #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
1121 #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
1122 #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
1123 #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
1124 #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
1125 #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
1126 #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
1127
1128 /* this is used on a TConX. I'm not sure the name is very helpful though */
1129 #define SMB_SUPPORT_SEARCH_BITS        0x0001
1130 #define SMB_SHARE_IN_DFS               0x0002
1131
1132 /* Named pipe write mode flags. Used in writeX calls. */
1133 #define PIPE_RAW_MODE 0x4
1134 #define PIPE_START_MESSAGE 0x8
1135
1136 /* File Specific access rights */
1137 #define FILE_READ_DATA        0x00000001
1138 #define FILE_WRITE_DATA       0x00000002
1139 #define FILE_APPEND_DATA      0x00000004
1140 #define FILE_READ_EA          0x00000008 /* File and directory */
1141 #define FILE_WRITE_EA         0x00000010 /* File and directory */
1142 #define FILE_EXECUTE          0x00000020
1143 #define FILE_DELETE_CHILD     0x00000040
1144 #define FILE_READ_ATTRIBUTES  0x00000080
1145 #define FILE_WRITE_ATTRIBUTES 0x00000100
1146
1147 #define FILE_ALL_ACCESS       0x000001FF
1148
1149 /* Directory specific access rights */
1150 #define FILE_LIST_DIRECTORY   0x00000001
1151 #define FILE_ADD_FILE         0x00000002
1152 #define FILE_ADD_SUBDIRECTORY 0x00000004
1153 #define FILE_TRAVERSE         0x00000020
1154 #define FILE_DELETE_CHILD     0x00000040
1155
1156 /* the desired access to use when opening a pipe */
1157 #define DESIRED_ACCESS_PIPE 0x2019f
1158  
1159 /* Generic access masks & rights. */
1160 #define DELETE_ACCESS        0x00010000 /* (1L<<16) */
1161 #define READ_CONTROL_ACCESS  0x00020000 /* (1L<<17) */
1162 #define WRITE_DAC_ACCESS     0x00040000 /* (1L<<18) */
1163 #define WRITE_OWNER_ACCESS   0x00080000 /* (1L<<19) */
1164 #define SYNCHRONIZE_ACCESS   0x00100000 /* (1L<<20) */
1165
1166 #define SYSTEM_SECURITY_ACCESS 0x01000000 /* (1L<<24) */
1167 #define MAXIMUM_ALLOWED_ACCESS 0x02000000 /* (1L<<25) */
1168 #define GENERIC_ALL_ACCESS     0x10000000 /* (1<<28) */
1169 #define GENERIC_EXECUTE_ACCESS 0x20000000 /* (1<<29) */
1170 #define GENERIC_WRITE_ACCESS   0x40000000 /* (1<<30) */
1171 #define GENERIC_READ_ACCESS    ((unsigned)0x80000000) /* (((unsigned)1)<<31) */
1172
1173 /* Mapping of generic access rights for files to specific rights. */
1174
1175 #define FILE_GENERIC_ALL (STANDARD_RIGHTS_REQUIRED_ACCESS| SYNCHRONIZE_ACCESS|FILE_ALL_ACCESS)
1176
1177 #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ_ACCESS|FILE_READ_DATA|FILE_READ_ATTRIBUTES|\
1178                                                         FILE_READ_EA|SYNCHRONIZE_ACCESS)
1179
1180 #define FILE_GENERIC_WRITE (STD_RIGHT_READ_CONTROL_ACCESS|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|\
1181                                                         FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONIZE_ACCESS)
1182
1183 #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE_ACCESS|\
1184                                                                 FILE_EXECUTE|SYNCHRONIZE_ACCESS)
1185
1186 /* Mapping of access rights to UNIX perms. */
1187 #define UNIX_ACCESS_RWX         FILE_GENERIC_ALL
1188 #define UNIX_ACCESS_R           FILE_GENERIC_READ
1189 #define UNIX_ACCESS_W           FILE_GENERIC_WRITE
1190 #define UNIX_ACCESS_X           FILE_GENERIC_EXECUTE
1191
1192 /* Mapping of access rights to UNIX perms. for a UNIX directory. */
1193 #define UNIX_DIRECTORY_ACCESS_RWX               FILE_GENERIC_ALL
1194 #define UNIX_DIRECTORY_ACCESS_R                 FILE_GENERIC_READ
1195 #define UNIX_DIRECTORY_ACCESS_W                 FILE_GENERIC_WRITE
1196 #define UNIX_DIRECTORY_ACCESS_X                 FILE_GENERIC_EXECUTE
1197
1198 #if 0
1199 /*
1200  * This is the old mapping we used to use. To get W2KSP2 profiles
1201  * working we need to map to the canonical file perms.
1202  */
1203 #define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
1204 #define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1205                         FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
1206 #define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1207                         FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
1208                         FILE_APPEND_DATA|FILE_WRITE_DATA)
1209 #define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
1210                         FILE_EXECUTE|FILE_READ_ATTRIBUTES)
1211 #endif
1212
1213 #define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
1214
1215 /* Flags field. */
1216 #define REQUEST_OPLOCK 2
1217 #define REQUEST_BATCH_OPLOCK 4
1218 #define OPEN_DIRECTORY 8
1219 #define EXTENDED_RESPONSE_REQUIRED 0x10
1220
1221 /* ShareAccess field. */
1222 #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
1223 #define FILE_SHARE_READ 1
1224 #define FILE_SHARE_WRITE 2
1225 #define FILE_SHARE_DELETE 4
1226
1227 /* FileAttributesField */
1228 #define FILE_ATTRIBUTE_READONLY         0x001L
1229 #define FILE_ATTRIBUTE_HIDDEN           0x002L
1230 #define FILE_ATTRIBUTE_SYSTEM           0x004L
1231 #define FILE_ATTRIBUTE_DIRECTORY        0x010L
1232 #define FILE_ATTRIBUTE_ARCHIVE          0x020L
1233 #define FILE_ATTRIBUTE_NORMAL           0x080L
1234 #define FILE_ATTRIBUTE_TEMPORARY        0x100L
1235 #define FILE_ATTRIBUTE_SPARSE           0x200L
1236 #define FILE_ATTRIBUTE_REPARSE_POINT    0x400L
1237 #define FILE_ATTRIBUTE_COMPRESSED       0x800L
1238 #define FILE_ATTRIBUTE_OFFLINE          0x1000L
1239 #define FILE_ATTRIBUTE_NONINDEXED       0x2000L
1240 #define FILE_ATTRIBUTE_ENCRYPTED        0x4000L
1241 #define SAMBA_ATTRIBUTES_MASK           0x7F
1242
1243 /* Flags - combined with attributes. */
1244 #define FILE_FLAG_WRITE_THROUGH    0x80000000L
1245 #define FILE_FLAG_NO_BUFFERING     0x20000000L
1246 #define FILE_FLAG_RANDOM_ACCESS    0x10000000L
1247 #define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
1248 #define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
1249 #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
1250 #define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
1251
1252 /* CreateDisposition field. */
1253 #define FILE_SUPERSEDE 0                /* File exists overwrite/supersede. File not exist create. */
1254 #define FILE_OPEN 1                     /* File exists open. File not exist fail. */
1255 #define FILE_CREATE 2                   /* File exists fail. File not exist create. */
1256 #define FILE_OPEN_IF 3                  /* File exists open. File not exist create. */
1257 #define FILE_OVERWRITE 4                /* File exists overwrite. File not exist fail. */
1258 #define FILE_OVERWRITE_IF 5             /* File exists overwrite. File not exist create. */
1259
1260 /* CreateOptions field. */
1261 #define FILE_DIRECTORY_FILE       0x0001
1262 #define FILE_WRITE_THROUGH        0x0002
1263 #define FILE_SEQUENTIAL_ONLY      0x0004
1264 #define FILE_NON_DIRECTORY_FILE   0x0040
1265 #define FILE_NO_EA_KNOWLEDGE      0x0200
1266 #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
1267 #define FILE_RANDOM_ACCESS        0x0800
1268 #define FILE_DELETE_ON_CLOSE      0x1000
1269 #define FILE_OPEN_BY_FILE_ID      0x2000
1270
1271 /* Private create options used by the ntcreatex processing code. From Samba4. */
1272 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS     0x01000000
1273 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB     0x02000000
1274
1275 /* Responses when opening a file. */
1276 #define FILE_WAS_SUPERSEDED 0
1277 #define FILE_WAS_OPENED 1
1278 #define FILE_WAS_CREATED 2
1279 #define FILE_WAS_OVERWRITTEN 3
1280
1281 /* File type flags */
1282 #define FILE_TYPE_DISK  0
1283 #define FILE_TYPE_BYTE_MODE_PIPE 1
1284 #define FILE_TYPE_MESSAGE_MODE_PIPE 2
1285 #define FILE_TYPE_PRINTER 3
1286 #define FILE_TYPE_COMM_DEVICE 4
1287 #define FILE_TYPE_UNKNOWN 0xFFFF
1288
1289 /* Flag for NT transact rename call. */
1290 #define RENAME_REPLACE_IF_EXISTS 1
1291
1292 /* flags for SMBntrename call (from Samba4) */
1293 #define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */
1294 #define RENAME_FLAG_HARD_LINK                0x103
1295 #define RENAME_FLAG_RENAME                   0x104
1296 #define RENAME_FLAG_COPY                     0x105
1297
1298 /* Filesystem Attributes. */
1299 #define FILE_CASE_SENSITIVE_SEARCH      0x00000001
1300 #define FILE_CASE_PRESERVED_NAMES       0x00000002
1301 #define FILE_UNICODE_ON_DISK            0x00000004
1302 /* According to cifs9f, this is 4, not 8 */
1303 /* Acconding to testing, this actually sets the security attribute! */
1304 #define FILE_PERSISTENT_ACLS            0x00000008
1305 #define FILE_FILE_COMPRESSION           0x00000010
1306 #define FILE_VOLUME_QUOTAS              0x00000020
1307 #define FILE_SUPPORTS_SPARSE_FILES      0x00000040
1308 #define FILE_SUPPORTS_REPARSE_POINTS    0x00000080
1309 #define FILE_SUPPORTS_REMOTE_STORAGE    0x00000100
1310 #define FS_LFN_APIS                     0x00004000
1311 #define FILE_VOLUME_IS_COMPRESSED       0x00008000
1312 #define FILE_SUPPORTS_OBJECT_IDS        0x00010000
1313 #define FILE_SUPPORTS_ENCRYPTION        0x00020000
1314 #define FILE_NAMED_STREAMS              0x00040000
1315 #define FILE_READ_ONLY_VOLUME           0x00080000
1316
1317 /* ChangeNotify flags. */
1318 #define FILE_NOTIFY_CHANGE_FILE        0x001
1319 #define FILE_NOTIFY_CHANGE_DIR_NAME    0x002
1320 #define FILE_NOTIFY_CHANGE_ATTRIBUTES  0x004
1321 #define FILE_NOTIFY_CHANGE_SIZE        0x008
1322 #define FILE_NOTIFY_CHANGE_LAST_WRITE  0x010
1323 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
1324 #define FILE_NOTIFY_CHANGE_CREATION    0x040
1325 #define FILE_NOTIFY_CHANGE_EA          0x080
1326 #define FILE_NOTIFY_CHANGE_SECURITY    0x100
1327 #define FILE_NOTIFY_CHANGE_FILE_NAME   0x200
1328
1329 /* where to find the base of the SMB packet proper */
1330 #define smb_base(buf) (((char *)(buf))+4)
1331
1332 /* we don't allow server strings to be longer than 48 characters as
1333    otherwise NT will not honour the announce packets */
1334 #define MAX_SERVER_STRING_LENGTH 48
1335
1336
1337 #define SMB_SUCCESS 0  /* The request was successful. */
1338
1339 #ifdef WITH_DFS
1340 void dfs_unlogin(void);
1341 extern int dcelogin_atmost_once;
1342 #endif
1343
1344 #ifdef NOSTRDUP
1345 char *strdup(char *s);
1346 #endif
1347
1348 #ifndef SIGNAL_CAST
1349 #define SIGNAL_CAST (RETSIGTYPE (*)(int))
1350 #endif
1351
1352 #ifndef SELECT_CAST
1353 #define SELECT_CAST
1354 #endif
1355
1356 /* these are used in NetServerEnum to choose what to receive */
1357 /* defined in librpc/gen_ndr/srvsvc.h */
1358
1359 /* This was set by JHT in liaison with Jeremy Allison early 1997
1360  * History:
1361  * Version 4.0 - never made public
1362  * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9
1363  *              - Reappeared in 1.9.16p11 with fixed smbd services
1364  * Version 4.20 - To indicate that nmbd and browsing now works better
1365  * Version 4.50 - Set at release of samba-2.2.0 by JHT
1366  *
1367  *  Note: In the presence of NT4.X do not set above 4.9
1368  *        Setting this above 4.9 can have undesired side-effects.
1369  *        This may change again in Samba-3.0 after further testing. JHT
1370  */
1371  
1372 #define DEFAULT_MAJOR_VERSION 0x04
1373 #define DEFAULT_MINOR_VERSION 0x09
1374
1375 /* Browser Election Values */
1376 #define BROWSER_ELECTION_VERSION        0x010f
1377 #define BROWSER_CONSTANT        0xaa55
1378
1379 /* Sercurity mode bits. */
1380 #define NEGOTIATE_SECURITY_USER_LEVEL           0x01
1381 #define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE   0x02
1382 #define NEGOTIATE_SECURITY_SIGNATURES_ENABLED   0x04
1383 #define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED  0x08
1384
1385 /* NT Flags2 bits - cifs6.txt section 3.1.2 */
1386    
1387 #define FLAGS2_LONG_PATH_COMPONENTS    0x0001
1388 #define FLAGS2_EXTENDED_ATTRIBUTES     0x0002
1389 #define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004
1390 #define FLAGS2_IS_LONG_NAME            0x0040
1391 #define FLAGS2_EXTENDED_SECURITY       0x0800 
1392 #define FLAGS2_DFS_PATHNAMES           0x1000
1393 #define FLAGS2_READ_PERMIT_EXECUTE     0x2000
1394 #define FLAGS2_32_BIT_ERROR_CODES      0x4000 
1395 #define FLAGS2_UNICODE_STRINGS         0x8000
1396
1397 #define FLAGS2_WIN2K_SIGNATURE         0xC852 /* Hack alert ! For now... JRA. */
1398
1399 /* Capabilities.  see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
1400
1401 #define CAP_RAW_MODE         0x0001
1402 #define CAP_MPX_MODE         0x0002
1403 #define CAP_UNICODE          0x0004
1404 #define CAP_LARGE_FILES      0x0008
1405 #define CAP_NT_SMBS          0x0010
1406 #define CAP_RPC_REMOTE_APIS  0x0020
1407 #define CAP_STATUS32         0x0040
1408 #define CAP_LEVEL_II_OPLOCKS 0x0080
1409 #define CAP_LOCK_AND_READ    0x0100
1410 #define CAP_NT_FIND          0x0200
1411 #define CAP_DFS              0x1000
1412 #define CAP_W2K_SMBS         0x2000
1413 #define CAP_LARGE_READX      0x4000
1414 #define CAP_LARGE_WRITEX     0x8000
1415 #define CAP_UNIX             0x800000 /* Capabilities for UNIX extensions. Created by HP. */
1416 #define CAP_EXTENDED_SECURITY 0x80000000
1417
1418 /* protocol types. It assumes that higher protocols include lower protocols
1419    as subsets */
1420 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
1421
1422 /* security levels */
1423 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN,SEC_ADS};
1424
1425 /* server roles */
1426 enum server_types {
1427         ROLE_STANDALONE,
1428         ROLE_DOMAIN_MEMBER,
1429         ROLE_DOMAIN_BDC,
1430         ROLE_DOMAIN_PDC
1431 };
1432
1433 /* printing types */
1434 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
1435                      PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,
1436                      PRINT_CUPS,PRINT_LPRNT,PRINT_LPROS2,PRINT_IPRINT
1437 #if defined(DEVELOPER) || defined(ENABLE_BUILD_FARM_HACKS)
1438 ,PRINT_TEST,PRINT_VLP
1439 #endif /* DEVELOPER */
1440 };
1441
1442 /* LDAP schema types */
1443 enum schema_types {SCHEMA_COMPAT, SCHEMA_AD, SCHEMA_SAMBA};
1444
1445 /* LDAP SSL options */
1446 enum ldap_ssl_types {LDAP_SSL_ON, LDAP_SSL_OFF, LDAP_SSL_START_TLS};
1447
1448 /* LDAP PASSWD SYNC methods */
1449 enum ldap_passwd_sync_types {LDAP_PASSWD_SYNC_ON, LDAP_PASSWD_SYNC_OFF, LDAP_PASSWD_SYNC_ONLY};
1450
1451 /* Remote architectures we know about. */
1452 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT,
1453                         RA_WIN2K, RA_WINXP, RA_WIN2K3, RA_SAMBA, RA_CIFSFS};
1454
1455 /* case handling */
1456 enum case_handling {CASE_LOWER,CASE_UPPER};
1457
1458 /* ACL compatibility */
1459 enum acl_compatibility {ACL_COMPAT_AUTO, ACL_COMPAT_WINNT, ACL_COMPAT_WIN2K};
1460 /*
1461  * Global value meaing that the smb_uid field should be
1462  * ingored (in share level security and protocol level == CORE)
1463  */
1464
1465 #define UID_FIELD_INVALID 0
1466 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
1467
1468 /* 
1469  * Size of buffer to use when moving files across filesystems. 
1470  */
1471 #define COPYBUF_SIZE (8*1024)
1472
1473 /*
1474  * Used in chaining code.
1475  */
1476 extern int chain_size;
1477
1478 /*
1479  * Map the Core and Extended Oplock requesst bits down
1480  * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
1481  */
1482
1483 /*
1484  * Core protocol.
1485  */
1486 #define CORE_OPLOCK_REQUEST(inbuf) \
1487     ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
1488
1489 /*
1490  * Extended protocol.
1491  */
1492 #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
1493
1494 /* Lock types. */
1495 #define LOCKING_ANDX_SHARED_LOCK 0x1
1496 #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
1497 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
1498 #define LOCKING_ANDX_CANCEL_LOCK 0x8
1499 #define LOCKING_ANDX_LARGE_FILES 0x10
1500
1501 /*
1502  * Bits we test with.
1503  * Note these must fit into 16-bits.
1504  */
1505
1506 #define NO_OPLOCK 0
1507 #define EXCLUSIVE_OPLOCK 1
1508 #define BATCH_OPLOCK 2
1509 #define LEVEL_II_OPLOCK 4
1510
1511 /* The following are Samba-private. */
1512 #define INTERNAL_OPEN_ONLY 8
1513 #define FAKE_LEVEL_II_OPLOCK 16 /* Client requested no_oplock, but we have to
1514                                  * inform potential level2 holders on
1515                                  * write. */
1516 #define DEFERRED_OPEN_ENTRY 32
1517 #define UNUSED_SHARE_MODE_ENTRY 64
1518 #define FORCE_OPLOCK_BREAK_TO_NONE 128
1519
1520 /* None of the following should ever appear in fsp->oplock_request. */
1521 #define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|UNUSED_SHARE_MODE_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
1522
1523 #define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
1524 #define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
1525 #define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)LEVEL_II_OPLOCK|(unsigned int)FAKE_LEVEL_II_OPLOCK))
1526
1527 struct inform_level2_message {
1528         SMB_DEV_T dev;
1529         SMB_INO_T inode;
1530         uint16 mid;
1531         unsigned long target_file_id;
1532         unsigned long source_file_id;
1533 };
1534
1535 /* kernel_oplock_message definition.
1536
1537 struct kernel_oplock_message {
1538         SMB_DEV_T dev;
1539         SMB_INO_T inode;
1540         unsigned long file_id;
1541 };
1542
1543 Offset  Data                  length.
1544 0     SMB_DEV_T dev           8 bytes.
1545 8     SMB_INO_T inode         8 bytes
1546 16    unsigned long file_id   4 bytes
1547 20
1548
1549 */
1550 #define MSG_SMB_KERNEL_BREAK_SIZE 20
1551
1552 /* file_renamed_message definition.
1553
1554 struct file_renamed_message {
1555         SMB_DEV_T dev;
1556         SMB_INO_T inode;
1557         char names[1]; A variable area containing sharepath and filename.
1558 };
1559
1560 Offset  Data                    length.
1561 0       SMB_DEV_T dev           8 bytes.
1562 8       SMB_INO_T inode         8 bytes
1563 16      char [] name            zero terminated namelen bytes
1564 minimum length == 18.
1565
1566 */
1567
1568 #define MSG_FILE_RENAMED_MIN_SIZE 16
1569
1570 /*
1571  * On the wire return values for oplock types.
1572  */
1573
1574 #define CORE_OPLOCK_GRANTED (1<<5)
1575 #define EXTENDED_OPLOCK_GRANTED (1<<15)
1576
1577 #define NO_OPLOCK_RETURN 0
1578 #define EXCLUSIVE_OPLOCK_RETURN 1
1579 #define BATCH_OPLOCK_RETURN 2
1580 #define LEVEL_II_OPLOCK_RETURN 3
1581
1582 /* Oplock levels */
1583 #define OPLOCKLEVEL_NONE 0
1584 #define OPLOCKLEVEL_II 1
1585
1586 /*
1587  * Capabilities abstracted for different systems.
1588  */
1589
1590 enum smbd_capability {
1591     KERNEL_OPLOCK_CAPABILITY,
1592     DMAPI_ACCESS_CAPABILITY
1593 };
1594
1595 /* if a kernel does support oplocks then a structure of the following
1596    typee is used to describe how to interact with the kernel */
1597 struct kernel_oplocks {
1598         files_struct * (*receive_message)(fd_set *fds);
1599         BOOL (*set_oplock)(files_struct *fsp, int oplock_type);
1600         void (*release_oplock)(files_struct *fsp);
1601         BOOL (*msg_waiting)(fd_set *fds);
1602         int notification_fd;
1603 };
1604
1605
1606 /* this structure defines the functions for doing change notify in
1607    various implementations */
1608 struct cnotify_fns {
1609         void * (*register_notify)(connection_struct *conn, char *path, uint32 flags);
1610         BOOL (*check_notify)(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *data, time_t t);
1611         void (*remove_notify)(void *data);
1612         int select_time;
1613         int notification_fd;
1614 };
1615
1616 #include "smb_macros.h"
1617
1618 #define MAX_NETBIOSNAME_LEN 16
1619 /* DOS character, NetBIOS namestring. Type used on the wire. */
1620 typedef char nstring[MAX_NETBIOSNAME_LEN];
1621 /* Unix character, NetBIOS namestring. Type used to manipulate name in nmbd. */
1622 typedef char unstring[MAX_NETBIOSNAME_LEN*4];
1623
1624 /* A netbios name structure. */
1625 struct nmb_name {
1626         nstring      name;
1627         char         scope[64];
1628         unsigned int name_type;
1629 };
1630
1631 /* A netbios node status array element. */
1632 typedef struct node_status_ {
1633         nstring name;
1634         unsigned char type;
1635         unsigned char flags;
1636 } NODE_STATUS_STRUCT;
1637
1638 /* The extra info from a NetBIOS node status query */
1639 struct node_status_extra {
1640         unsigned char mac_addr[6];
1641         /* There really is more here ... */ 
1642 };
1643
1644 struct pwd_info {
1645         BOOL null_pwd;
1646         BOOL cleartext;
1647
1648         fstring password;
1649 };
1650
1651 typedef struct user_struct {
1652         struct user_struct *next, *prev;
1653         uint16 vuid; /* Tag for this entry. */
1654         uid_t uid; /* uid of a validated user */
1655         gid_t gid; /* gid of a validated user */
1656
1657         userdom_struct user;
1658         char *homedir;
1659         char *unix_homedir;
1660         char *logon_script;
1661         
1662         BOOL guest;
1663
1664         /* following groups stuff added by ih */
1665         /* This groups info is needed for when we become_user() for this uid */
1666         int n_groups;
1667         gid_t *groups;
1668
1669         NT_USER_TOKEN *nt_user_token;
1670
1671         DATA_BLOB session_key;
1672
1673         char *session_keystr; /* used by utmp and pam session code.  
1674                                  TDB key string */
1675         int homes_snum;
1676
1677         struct auth_serversupplied_info *server_info;
1678
1679         struct auth_ntlmssp_state *auth_ntlmssp_state;
1680
1681 } user_struct;
1682
1683 struct unix_error_map {
1684         int unix_error;
1685         int dos_class;
1686         int dos_code;
1687         NTSTATUS nt_error;
1688 };
1689
1690 /*
1691  * Size of new password account encoding string.  This is enough space to
1692  * hold 11 ACB characters, plus the surrounding [] and a terminating null.
1693  * Do not change unless you are adding new ACB bits!
1694  */
1695
1696 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
1697
1698 /*
1699    Do you want session setups at user level security with a invalid
1700    password to be rejected or allowed in as guest? WinNT rejects them
1701    but it can be a pain as it means "net view" needs to use a password
1702
1703    You have 3 choices in the setting of map_to_guest:
1704
1705    "NEVER_MAP_TO_GUEST" means session setups with an invalid password
1706    are rejected. This is the default.
1707
1708    "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
1709    are rejected, unless the username does not exist, in which case it
1710    is treated as a guest login
1711
1712    "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
1713    are treated as a guest login
1714
1715    Note that map_to_guest only has an effect in user or server
1716    level security.
1717 */
1718
1719 #define NEVER_MAP_TO_GUEST              0
1720 #define MAP_TO_GUEST_ON_BAD_USER        1
1721 #define MAP_TO_GUEST_ON_BAD_PASSWORD    2
1722 #define MAP_TO_GUEST_ON_BAD_UID         3
1723
1724 #define SAFE_NETBIOS_CHARS ". -_"
1725
1726 /* generic iconv conversion structure */
1727 typedef struct _smb_iconv_t {
1728         size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
1729                          char **outbuf, size_t *outbytesleft);
1730         size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
1731                        char **outbuf, size_t *outbytesleft);
1732         size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft,
1733                        char **outbuf, size_t *outbytesleft);
1734         void *cd_direct, *cd_pull, *cd_push;
1735         char *from_name, *to_name;
1736 } *smb_iconv_t;
1737
1738 /* The maximum length of a trust account password.
1739    Used when we randomly create it, 15 char passwords
1740    exceed NT4's max password length */
1741
1742 #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14
1743
1744 #include "popt_common.h"
1745
1746 #define PORT_NONE       0
1747 #ifndef LDAP_PORT
1748 #define LDAP_PORT       389
1749 #endif
1750
1751 /* used by the IP comparison function */
1752 struct ip_service {
1753         struct in_addr ip;
1754         unsigned port;
1755 };
1756
1757 /* Special name type used to cause a _kerberos DNS lookup. */
1758 #define KDC_NAME_TYPE 0xDCDC
1759
1760 /* Used by the SMB signing functions. */
1761
1762 typedef struct smb_sign_info {
1763         void (*sign_outgoing_message)(char *outbuf, struct smb_sign_info *si);
1764         BOOL (*check_incoming_message)(char *inbuf, struct smb_sign_info *si, BOOL must_be_ok);
1765         void (*free_signing_context)(struct smb_sign_info *si);
1766         void *signing_context;
1767
1768         BOOL negotiated_smb_signing;
1769         BOOL allow_smb_signing;
1770         BOOL doing_signing;
1771         BOOL mandatory_signing;
1772         BOOL seen_valid; /* Have I ever seen a validly signed packet? */
1773 } smb_sign_info;
1774
1775 struct ea_struct {
1776         uint8 flags;
1777         char *name;
1778         DATA_BLOB value;
1779 };
1780
1781 struct ea_list {
1782         struct ea_list *next, *prev;
1783         struct ea_struct ea;
1784 };
1785
1786 /* EA names used internally in Samba. KEEP UP TO DATE with prohibited_ea_names in trans2.c !. */
1787 #define SAMBA_POSIX_INHERITANCE_EA_NAME "user.SAMBA_PAI"
1788 /* EA to use for DOS attributes */
1789 #define SAMBA_XATTR_DOS_ATTRIB "user.DOSATTRIB"
1790
1791 #define UUID_SIZE 16
1792
1793 #define UUID_FLAT_SIZE 16
1794 typedef struct uuid_flat {
1795         uint8 info[UUID_FLAT_SIZE];
1796 } UUID_FLAT;
1797
1798 /* map readonly options */
1799 enum mapreadonly_options {MAP_READONLY_NO, MAP_READONLY_YES, MAP_READONLY_PERMISSIONS};
1800
1801 /* usershare error codes. */
1802 enum usershare_err {
1803                 USERSHARE_OK=0,
1804                 USERSHARE_MALFORMED_FILE,
1805                 USERSHARE_BAD_VERSION,
1806                 USERSHARE_MALFORMED_PATH,
1807                 USERSHARE_MALFORMED_COMMENT_DEF,
1808                 USERSHARE_MALFORMED_ACL_DEF,
1809                 USERSHARE_ACL_ERR,
1810                 USERSHARE_PATH_NOT_ABSOLUTE,
1811                 USERSHARE_PATH_IS_DENIED,
1812                 USERSHARE_PATH_NOT_ALLOWED,
1813                 USERSHARE_PATH_NOT_DIRECTORY,
1814                 USERSHARE_POSIX_ERR
1815 };
1816
1817 /* Different reasons for closing a file. */
1818 enum file_close_type {NORMAL_CLOSE=0,SHUTDOWN_CLOSE,ERROR_CLOSE};
1819
1820 #endif /* _SMB_H */