Initial version imported to CVS
[kai/samba.git] / source3 / include / smb.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    SMB parameters and setup
5    Copyright (C) Andrew Tridgell 1992-1995
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 #ifndef _SMB_H
22 #define _SMB_H
23
24 #ifndef MAX_CONNECTIONS
25 #define MAX_CONNECTIONS 127
26 #endif
27
28 #ifndef MAX_OPEN_FILES
29 #define MAX_OPEN_FILES 50
30 #endif
31
32 #ifndef GUEST_ACCOUNT
33 #define GUEST_ACCOUNT "nobody"
34 #endif
35
36 #define BUFFER_SIZE (0xFFFF)
37 #define SAFETY_MARGIN 1024
38
39 #ifndef EXTERN
40 #       define EXTERN extern
41 #endif
42
43 #define False (0)
44 #define True (1)
45 #define BOOLSTR(b) ((b) ? "Yes" : "No")
46 #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
47 #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
48 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
49
50 typedef int BOOL;
51
52 /*
53    Samba needs type definitions for int16, int32, uint16 and uint32.
54    
55    Normally these are signed and unsigned 16 and 32 bit integers, but
56    they actually only need to be at least 16 and 32 bits
57    respectively. Thus if your word size is 8 bytes just defining them
58    as signed and unsigned int will work.
59 */
60
61 /* afs/stds.h defines int16 and int32 */
62 #ifndef AFS_AUTH
63 typedef short int16;
64 typedef int int32;
65 #endif
66
67 #ifndef uint16
68 typedef unsigned short uint16;
69 #endif
70
71 #ifndef uint32
72 typedef unsigned int uint32;
73 #endif
74
75 #define SIZEOFWORD 2
76
77 #ifndef DEF_CREATE_MASK
78 #define DEF_CREATE_MASK (0755)
79 #endif
80
81 #ifndef DEFAULT_PIPE_TIMEOUT
82 #define DEFAULT_PIPE_TIMEOUT 10000000 /* Ten seconds */
83 #endif
84
85 /* debugging code */
86 #ifndef SYSLOG
87 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
88 #else
89 EXTERN int syslog_level;
90
91 #define DEBUG(level,body) ((DEBUGLEVEL>=(level))? \
92                                                    (syslog_level = (level), Debug1 body):0)
93 #endif
94
95 #define DIR_STRUCT_SIZE 43
96
97 /* these define all the command types recognised by the server - there
98 are lots of gaps so probably there are some rare commands that are not
99 implemented */
100
101 #define pSETDIR '\377'
102
103 /* these define the attribute byte as seen by DOS */
104 #define aRONLY (1L<<0)
105 #define aHIDDEN (1L<<1)
106 #define aSYSTEM (1L<<2)
107 #define aVOLID (1L<<3)
108 #define aDIR (1L<<4)
109 #define aARCH (1L<<5)
110
111 /* deny modes */
112 #define DENY_DOS 0
113 #define DENY_ALL 1
114 #define DENY_WRITE 2
115 #define DENY_READ 3
116 #define DENY_NONE 4
117 #define DENY_FCB 7
118
119 /* share types */
120 #define STYPE_DISKTREE  0       /* Disk drive */
121 #define STYPE_PRINTQ    1       /* Spooler queue */
122 #define STYPE_DEVICE    2       /* Serial device */
123 #define STYPE_IPC       3       /* Interprocess communication (IPC) */
124
125 /* SMB X/Open error codes for the ERRdos error class */
126 #define ERRbadfunc 1 /* Invalid function (or system call) */
127 #define ERRbadfile 2 /* File not found (pathname error) */
128 #define ERRbadpath 3 /* Directory not found */
129 #define ERRnofids 4 /* Too many open files */
130 #define ERRnoaccess 5 /* Access denied */
131 #define ERRbadfid 6 /* Invalid fid */
132 #define ERRnomem 8 /* Out of memory */
133 #define ERRbadmem 9 /* Invalid memory block address */
134 #define ERRbadenv 10 /* Invalid environment */
135 #define ERRbadaccess 12 /* Invalid open mode */
136 #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
137 #define ERRres 14 /* reserved */
138 #define ERRbaddrive 15 /* Invalid drive */
139 #define ERRremcd 16 /* Attempt to delete current directory */
140 #define ERRdiffdevice 17 /* rename/move across different filesystems */
141 #define ERRnofiles 18 /* no more files found in file search */
142 #define ERRbadshare 32 /* Share mode on file conflict with open mode */
143 #define ERRlock 33 /* Lock request conflicts with existing lock */
144 #define ERRfilexists 80 /* File in operation already exists */
145 #define ERRbadpipe 230 /* Named pipe invalid */
146 #define ERRpipebusy 231 /* All instances of pipe are busy */
147 #define ERRpipeclosing 232 /* named pipe close in progress */
148 #define ERRnotconnected 233 /* No process on other end of named pipe */
149 #define ERRmoredata 234 /* More data to be returned */
150 #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
151 #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not suppored */
152 #define ERRunknownlevel 124
153 #define ERRunknownipc 2142
154
155
156 /* here's a special one from observing NT */
157 #define ERRnoipc 66 /* don't support ipc */
158
159 /* Error codes for the ERRSRV class */
160
161 #define ERRerror 1 /* Non specific error code */
162 #define ERRbadpw 2 /* Bad password */
163 #define ERRbadtype 3 /* reserved */
164 #define ERRaccess 4 /* No permissions to do the requested operation */
165 #define ERRinvnid 5 /* tid invalid */
166 #define ERRinvnetname 6 /* Invalid servername */
167 #define ERRinvdevice 7 /* Invalid device */
168 #define ERRqfull 49 /* Print queue full */
169 #define ERRqtoobig 50 /* Queued item too big */
170 #define ERRinvpfid 52 /* Invalid print file in smb_fid */
171 #define ERRsmbcmd 64 /* Unrecognised command */
172 #define ERRsrverror 65 /* smb server internal error */
173 #define ERRfilespecs 67 /* fid and pathname invalid combination */
174 #define ERRbadlink 68 /* reserved */
175 #define ERRbadpermits 69 /* Access specified for a file is not valid */
176 #define ERRbadpid 70 /* reserved */
177 #define ERRsetattrmode 71 /* attribute mode invalid */
178 #define ERRpaused 81 /* Message server paused */
179 #define ERRmsgoff 82 /* Not receiving messages */
180 #define ERRnoroom 83 /* No room for message */
181 #define ERRrmuns 87 /* too many remote usernames */
182 #define ERRtimeout 88 /* operation timed out */
183 #define ERRnoresource  89 /* No resources currently available for request. */
184 #define ERRtoomanyuids 90 /* too many userids */
185 #define ERRbaduid 91 /* bad userid */
186 #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
187 #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
188 #define ERRcontMPX 252 /* resume MPX mode */
189 #define ERRbadPW /* reserved */
190 #define ERRnosupport 0xFFFF
191 #define ERRunknownsmb 22 /* from NT 3.5 response */
192
193
194 /* Error codes for the ERRHRD class */
195
196 #define ERRnowrite 19 /* read only media */
197 #define ERRbadunit 20 /* Unknown device */
198 #define ERRnotready 21 /* Drive not ready */
199 #define ERRbadcmd 22 /* Unknown command */
200 #define ERRdata 23 /* Data (CRC) error */
201 #define ERRbadreq 24 /* Bad request structure length */
202 #define ERRseek 25
203 #define ERRbadmedia 26
204 #define ERRbadsector 27
205 #define ERRnopaper 28
206 #define ERRwrite 29 /* write fault */
207 #define ERRread 30 /* read fault */
208 #define ERRgeneral 31 /* General hardware failure */
209 #define ERRwrongdisk 34
210 #define ERRFCBunavail 35
211 #define ERRsharebufexc 36 /* share buffer exceeded */
212 #define ERRdiskfull 39
213
214
215 typedef char pstring[1024];
216 typedef char fstring[128];
217 typedef fstring string;
218
219 typedef struct
220 {
221   int size;
222   int mode;
223   int uid;
224   int gid;
225   /* these times are normally kept in GMT */
226   time_t mtime;
227   time_t atime;
228   time_t ctime;
229   pstring name;
230 } file_info;
231
232
233 /* Structure used when SMBwritebmpx is active */
234 typedef struct
235         {
236         int   wr_total_written; /* So we know when to discard this */
237         int32 wr_timeout;
238         int32 wr_errclass;
239         int32 wr_error; /* Cached errors */
240         BOOL  wr_mode; /* write through mode) */
241         BOOL  wr_discard; /* discard all further data */
242         } write_bmpx_struct;
243
244 typedef struct
245 {
246   int cnum;
247   int fd;
248   int pos;
249   int size;
250   int mode;
251   char *mmap_ptr;
252   int mmap_size;
253   write_bmpx_struct *wbmpx_ptr;
254   time_t open_time;
255   BOOL open;
256   BOOL can_lock;
257   BOOL can_read;
258   BOOL can_write;
259   BOOL share_mode;
260   BOOL share_pending;
261   BOOL print_file;
262   BOOL modified;
263   char *name;
264 } files_struct;
265
266
267 struct uid_cache {
268   int entries;
269   int list[UID_CACHE_SIZE];
270 };
271
272 typedef struct
273 {
274   int service;
275   BOOL force_user;
276   int uid; /* uid of user who *opened* this connection */
277   int gid; /* gid of user who *opened* this connection */
278   struct uid_cache uid_cache;
279   void *dirptr;
280   BOOL open;
281   BOOL printer;
282   BOOL ipc;
283   BOOL read_only;
284   BOOL admin_user;
285   char *dirpath;
286   char *connectpath;
287   char *origpath;
288   char *user; /* name of user who *opened* this connection */
289   /* following groups stuff added by ih */
290   /* This groups info is valid for the user that *opened* the connection */
291   int ngroups;
292   gid_t *groups;
293   int *igroups; /* an integer version - some OSes are broken :-( */
294   time_t lastused;
295   BOOL used;
296   int num_files_open;
297 } connection_struct;
298
299
300 typedef struct
301 {
302   int uid; /* uid of a validated user */
303   int gid; /* gid of a validated user */
304   fstring name; /* name of a validated user */
305   BOOL guest;
306   /* following groups stuff added by ih */
307   /* This groups info is needed for when we become_user() for this uid */
308   int user_ngroups;
309   gid_t *user_groups;
310   int *user_igroups; /* an integer version - some OSes are broken :-( */
311 } user_struct;
312
313
314 enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
315
316 typedef struct
317 {
318   int job;
319   int size;
320   int status;
321   int priority;
322   time_t time;
323   char user[30];
324   char file[100];
325 } print_queue_struct;
326
327 enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
328
329 typedef struct
330 {
331   fstring message;
332   int status;
333 }  print_status_struct;
334
335
336 /* this is used for smbstatus */
337 struct connect_record
338 {
339   int magic;
340   int pid;
341   int cnum;
342   int uid;
343   int gid;
344   char name[24];
345   char addr[24];
346   char machine[128];
347   time_t start;
348 };
349
350
351 #define LOCKING_VERSION 2
352
353 /* these are useful macros for checking validity of handles */
354 #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
355 #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
356 #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
357 #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
358 #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
359 #define FNUM_OK(fnum,c) (OPEN_FNUM(fnum) && (c)==Files[fnum].cnum)
360
361 #define CHECK_FNUM(fnum,c) if (!FNUM_OK(fnum,c)) \
362                                return(ERROR(ERRDOS,ERRbadfid))
363 #define CHECK_READ(fnum) if (!Files[fnum].can_read) \
364                                return(ERROR(ERRDOS,ERRbadaccess))
365 #define CHECK_WRITE(fnum) if (!Files[fnum].can_write) \
366                                return(ERROR(ERRDOS,ERRbadaccess))
367 #define CHECK_ERROR(fnum) if (HAS_CACHED_ERROR(fnum)) \
368                                return(CACHED_ERROR(fnum))
369
370 /* translates a connection number into a service number */
371 #define SNUM(cnum)         (Connections[cnum].service)
372
373 /* access various service details */
374 #define SERVICE(snum)      (lp_servicename(snum))
375 #define PRINTCAP           (lp_printcapname())
376 #define PRINTCOMMAND(snum) (lp_printcommand(snum))
377 #define PRINTERNAME(snum)  (lp_printername(snum))
378 #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
379 #define VALID_SNUM(snum)   (lp_snum_ok(snum))
380 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
381 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
382 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
383 #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
384 #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
385 #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
386 #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
387 #define MAP_ARCHIVE(cnum)   (OPEN_CNUM(cnum) && lp_map_archive(SNUM(cnum)))
388 #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)) | 0700)
389 #ifdef SMB_PASSWD
390 #define SMBENCRYPT()       (lp_encrypted_passwords())
391 #else
392 #define SMBENCRYPT() (False)
393 #endif
394
395 /* the basic packet size, assuming no words or bytes */
396 #define smb_size 39
397
398 /* offsets into message for common items */
399 #define smb_com 8
400 #define smb_rcls 9
401 #define smb_reh 10
402 #define smb_err 11
403 #define smb_flg 13
404 #define smb_flg2 14
405 #define smb_reb 13
406 #define smb_tid 28
407 #define smb_pid 30
408 #define smb_uid 32
409 #define smb_mid 34
410 #define smb_wct 36
411 #define smb_vwv 37
412 #define smb_vwv0 37
413 #define smb_vwv1 39
414 #define smb_vwv2 41
415 #define smb_vwv3 43
416 #define smb_vwv4 45
417 #define smb_vwv5 47
418 #define smb_vwv6 49
419 #define smb_vwv7 51
420 #define smb_vwv8 53
421 #define smb_vwv9 55
422 #define smb_vwv10 57
423 #define smb_vwv11 59
424 #define smb_vwv12 61
425 #define smb_vwv13 63
426 #define smb_vwv14 65
427 #define smb_vwv15 67
428 #define smb_vwv16 69
429 #define smb_vwv17 71
430
431
432 /* the complete */
433 #define SMBmkdir      0x00   /* create directory */
434 #define SMBrmdir      0x01   /* delete directory */
435 #define SMBopen       0x02   /* open file */
436 #define SMBcreate     0x03   /* create file */
437 #define SMBclose      0x04   /* close file */
438 #define SMBflush      0x05   /* flush file */
439 #define SMBunlink     0x06   /* delete file */
440 #define SMBmv         0x07   /* rename file */
441 #define SMBgetatr     0x08   /* get file attributes */
442 #define SMBsetatr     0x09   /* set file attributes */
443 #define SMBread       0x0A   /* read from file */
444 #define SMBwrite      0x0B   /* write to file */
445 #define SMBlock       0x0C   /* lock byte range */
446 #define SMBunlock     0x0D   /* unlock byte range */
447 #define SMBctemp      0x0E   /* create temporary file */
448 #define SMBmknew      0x0F   /* make new file */
449 #define SMBchkpth     0x10   /* check directory path */
450 #define SMBexit       0x11   /* process exit */
451 #define SMBlseek      0x12   /* seek */
452 #define SMBtcon       0x70   /* tree connect */
453 #define SMBtconX      0x75   /* tree connect and X*/
454 #define SMBtdis       0x71   /* tree disconnect */
455 #define SMBnegprot    0x72   /* negotiate protocol */
456 #define SMBdskattr    0x80   /* get disk attributes */
457 #define SMBsearch     0x81   /* search directory */
458 #define SMBsplopen    0xC0   /* open print spool file */
459 #define SMBsplwr      0xC1   /* write to print spool file */
460 #define SMBsplclose   0xC2   /* close print spool file */
461 #define SMBsplretq    0xC3   /* return print queue */
462 #define SMBsends      0xD0   /* send single block message */
463 #define SMBsendb      0xD1   /* send broadcast message */
464 #define SMBfwdname    0xD2   /* forward user name */
465 #define SMBcancelf    0xD3   /* cancel forward */
466 #define SMBgetmac     0xD4   /* get machine name */
467 #define SMBsendstrt   0xD5   /* send start of multi-block message */
468 #define SMBsendend    0xD6   /* send end of multi-block message */
469 #define SMBsendtxt    0xD7   /* send text of multi-block message */
470
471 /* Core+ protocol */
472 #define SMBlockread       0x13   /* Lock a range and read */
473 #define SMBwriteunlock 0x14 /* Unlock a range then write */
474 #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
475 #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
476 #define SMBwritec     0x20  /* secondary write request */
477 #define SMBwriteclose 0x2c  /* write a file then close it */
478
479 /* dos extended protocol */
480 #define SMBreadBraw      0x1A   /* read block raw */
481 #define SMBreadBmpx      0x1B   /* read block multiplexed */
482 #define SMBreadBs        0x1C   /* read block (secondary response) */
483 #define SMBwriteBraw     0x1D   /* write block raw */
484 #define SMBwriteBmpx     0x1E   /* write block multiplexed */
485 #define SMBwriteBs       0x1F   /* write block (secondary request) */
486 #define SMBwriteC        0x20   /* write complete response */
487 #define SMBsetattrE      0x22   /* set file attributes expanded */
488 #define SMBgetattrE      0x23   /* get file attributes expanded */
489 #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
490 #define SMBtrans         0x25   /* transaction - name, bytes in/out */
491 #define SMBtranss        0x26   /* transaction (secondary request/response) */
492 #define SMBioctl         0x27   /* IOCTL */
493 #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
494 #define SMBcopy          0x29   /* copy */
495 #define SMBmove          0x2A   /* move */
496 #define SMBecho          0x2B   /* echo */
497 #define SMBopenX         0x2D   /* open and X */
498 #define SMBreadX         0x2E   /* read and X */
499 #define SMBwriteX        0x2F   /* write and X */
500 #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
501 #define SMBffirst        0x82   /* find first */
502 #define SMBfunique       0x83   /* find unique */
503 #define SMBfclose        0x84   /* find close */
504 #define SMBinvalid       0xFE   /* invalid command */
505
506 /* Extended 2.0 protocol */
507 #define SMBtrans2        0x32   /* TRANS2 protocol set */
508 #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
509 #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
510 #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
511 #define SMBulogoffX      0x74   /* user logoff */
512
513
514 /* these are the TRANS2 sub commands */
515 #define TRANSACT2_OPEN          0
516 #define TRANSACT2_FINDFIRST     1
517 #define TRANSACT2_FINDNEXT      2
518 #define TRANSACT2_QFSINFO       3
519 #define TRANSACT2_SETFSINFO     4
520 #define TRANSACT2_QPATHINFO     5
521 #define TRANSACT2_SETPATHINFO   6
522 #define TRANSACT2_QFILEINFO     7
523 #define TRANSACT2_SETFILEINFO   8
524 #define TRANSACT2_FSCTL         9
525 #define TRANSACT2_IOCTL           10
526 #define TRANSACT2_FINDNOTIFYFIRST 11
527 #define TRANSACT2_FINDNOTIFYNEXT  12
528 #define TRANSACT2_MKDIR           13
529
530
531 /* these are the trans2 sub fields for primary requests */
532 #define smb_tpscnt smb_vwv0
533 #define smb_tdscnt smb_vwv1
534 #define smb_mprcnt smb_vwv2
535 #define smb_mdrcnt smb_vwv3
536 #define smb_msrcnt smb_vwv4
537 #define smb_flags smb_vwv5
538 #define smb_timeout smb_vwv6
539 #define smb_pscnt smb_vwv9
540 #define smb_psoff smb_vwv10
541 #define smb_dscnt smb_vwv11
542 #define smb_dsoff smb_vwv12
543 #define smb_suwcnt smb_vwv13
544 #define smb_setup smb_vwv14
545 #define smb_setup0 smb_setup
546 #define smb_setup1 (smb_setup+2)
547 #define smb_setup2 (smb_setup+4)
548
549 /* these are for the secondary requests */
550 #define smb_spscnt smb_vwv2
551 #define smb_spsoff smb_vwv3
552 #define smb_spsdisp smb_vwv4
553 #define smb_sdscnt smb_vwv5
554 #define smb_sdsoff smb_vwv6
555 #define smb_sdsdisp smb_vwv7
556 #define smb_sfid smb_vwv8
557
558 /* and these for responses */
559 #define smb_tprcnt smb_vwv0
560 #define smb_tdrcnt smb_vwv1
561 #define smb_prcnt smb_vwv3
562 #define smb_proff smb_vwv4
563 #define smb_prdisp smb_vwv5
564 #define smb_drcnt smb_vwv6
565 #define smb_droff smb_vwv7
566 #define smb_drdisp smb_vwv8
567
568 /* where to find the base of the SMB packet proper */
569 #define smb_base(buf) (((char *)(buf))+4)
570
571
572 #define SUCCESS 0  /* The request was successful. */
573 #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
574 #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
575 #define ERRHRD 0x03  /* Error is an hardware error. */
576 #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
577
578 /* structure used to hold the incoming hosts info */
579 struct from_host {
580     char   *name;                       /* host name */
581     char   *addr;                       /* host address */
582     struct sockaddr_in *sin;            /* their side of the link */
583 };
584
585 /* and a few prototypes */
586 BOOL user_ok(char *user,int snum);
587 int sys_rename(char *from, char *to);
588 int sys_select(fd_set *fds,struct timeval *tval);
589 int sys_unlink(char *fname);
590 int sys_open(char *fname,int flags,int mode);
591 DIR *sys_opendir(char *dname);
592 int sys_stat(char *fname,struct stat *sbuf);
593 int sys_lstat(char *fname,struct stat *sbuf);
594 int sys_mkdir(char *dname,int mode);
595 int sys_rmdir(char *dname);
596 int sys_chdir(char *dname);
597 int sys_utime(char *fname,struct utimbuf *times);
598 int sys_disk_free(char *path,int *bsize,int *dfree,int *dsize);
599 void lpq_reset(int);
600 void status_printjob(int cnum,int snum,int jobid,int status);
601 void DirCacheAdd(char *path,char *name,char *dname,int snum);
602 char *DirCacheCheck(char *path,char *name,int snum);
603 void DirCacheFlush(int snum);
604 int interpret_character_set(char *str, int def);
605 char *dos2unix_format(char *, BOOL);
606 char *unix2dos_format(char *, BOOL);
607 BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type);
608 void BlockSignals(BOOL block);
609 void msleep(int t);
610 int file_lock(char *name,int timeout);
611 void file_unlock(int fd);
612 int find_service(char *service);
613 int TvalDiff(struct timeval *tvalold,struct timeval *tvalnew);
614 int smb_offset(char *p,char *buf);
615 void sync_file(int fnum);
616 int PutUniCode(char *dst,char *src);
617 void map_username(char *user);
618 void close_low_fds(void);
619 void clean_share_files(void);
620 int write_socket(int fd,char *buf,int len);
621 char *readdirname(void *p);
622 int dos_chmod(int cnum,char *fname,int mode,struct stat *st);
623 int smb_numwords(char *buf);
624 int get_share_mode(int cnum,struct stat *sbuf,int *pid);
625 void del_share_mode(int fnum);
626 BOOL set_share_mode(int fnum,int mode);
627 int DSTDiff(time_t t);
628 void TimeInit(void);
629 void put_long_date(char *p,time_t t);
630 time_t interpret_long_date(char *p);
631 void dptr_idlecnum(int cnum);
632 void dptr_closecnum(int cnum);
633 void init_dptrs(void);
634 void fault_setup();
635 void set_socket_options(int fd, char *options);
636 void putip(void *dest,void *src);
637 void standard_sub_basic(char *s);
638 void *OpenDir(char *name);
639 void CloseDir(void *p);
640 char *ReadDirName(void *p);
641 BOOL SeekDir(void *p,int pos);
642 int TellDir(void *p);
643 int write_data(int fd,char *buffer,int N);
644 BOOL server_cryptkey(char *buf);
645 BOOL server_validate(char *buf);
646 BOOL become_service(int cnum,BOOL do_chdir);
647 BOOL snum_used(int snum);
648 BOOL reload_services(BOOL test);
649 void reopen_logs(void);
650 int transfer_file(int infd,int outfd,int n,char *header,int headlen,int align);
651 int str_checksum(char *s);
652 time_t file_modtime(char *fname);
653 BOOL do_match(char *str, char *regexp, int case_sig);
654 BOOL is_a_socket(int fd);
655 void _smb_setlen(char *buf,int len);
656 void valid_initialise(void);
657 BOOL is_8_3(char *fname);
658 BOOL is_mangled(char *s);
659 void standard_sub(int cnum,char *s);
660 void del_printqueue(int cnum,int snum,int jobid);
661 BOOL strisnormal(char *s);
662 BOOL check_mangled_stack(char *s);
663 int sys_chown(char *fname,int uid,int gid);
664 int sys_chroot(char *dname);
665 BOOL next_token(char **ptr,char *buff,char *sep);
666 void invalidate_uid(int uid);
667 char *fgets_slash(char *s,int maxlen,FILE *f);
668 int read_udp_socket(int fd,char *buf,int len);
669 void exit_server(char *reason);
670 BOOL process_exists(int pid);
671 BOOL chgpasswd(char *name,char *oldpass,char *newpass);
672 void array_promote(char *array,int elsize,int element);
673 void string_replace(char *s,char oldc,char newc);
674 BOOL user_in_list(char *user,char *list);
675 BOOL string_sub(char *s,char *pattern,char *insert);
676 char *StrnCpy(char *dest,const char *src,int n);
677 char *validated_username(int vuid);
678 BOOL set_user_password(char *user,char *oldpass,char *newpass);
679 int smb_buf_ofs(char *buf);
680 char *skip_string(char *buf,int n);
681 BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset);
682 int read_file(int fnum,char *data,int pos,int mincnt,int maxcnt,int timeout,BOOL exact);
683 int write_file(int fnum,char *data,int n);
684 BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
685 int seek_file(int fnum,int pos);
686 BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
687 int get_printqueue(int snum,int cnum,print_queue_struct **queue,print_status_struct *status);
688 void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev);
689 int setup_groups(char *user,int uid, int gid, int *p_ngroups, 
690                  int **p_igroups, gid_t **p_groups);
691 int make_connection(char *service,char *user,char *password, int pwlen, char *dev,int vuid);
692 char *dptr_path(int key);
693 char *dptr_wcard(int key);
694 BOOL dptr_set_wcard(int key, char *wcard);
695 BOOL dptr_set_attr(int key, uint16 attr);
696 uint16 dptr_attr(int key);
697 void dptr_close(int key);
698 void dptr_closepath(char *path,int pid);
699 int dptr_create(int cnum,char *path, BOOL expect_close,int pid);
700 BOOL dptr_fill(char *buf,unsigned int key);
701 BOOL dptr_zero(char *buf);
702 void *dptr_fetch(char *buf,int *num);
703 void *dptr_fetch_lanman2(char *params,int dptr_num);
704 BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend);
705 void open_file(int fnum,int cnum,char *fname,int flags,int mode);
706 void open_file_shared(int fnum,int cnum,char *fname,int share_mode,int ofun,int mode,int *Access,int *action);
707 void close_file(int fnum);
708 int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize);
709 int reply_trans(char *inbuf,char *outbuf);
710 char *ufc_crypt(char *key,char *salt);
711 BOOL authorise_login(int snum,char *user,char *password, int pwlen, 
712                      BOOL *guest,BOOL *force,int vuid);
713 void add_session_user(char *user);
714 int valid_uid(int uid);
715 user_struct *get_valid_user_struct(int uid);
716 BOOL password_ok(char *user,char *password, int pwlen, struct passwd *pwd, BOOL nt_password);
717 void register_uid(int uid,int gid,char *name,BOOL guest);
718 BOOL fromhost(int sock,struct from_host *f);
719 BOOL strhasupper(char *s);
720 BOOL strhaslower(char *s);
721 int disk_free(char *path,int *bsize,int *dfree,int *dsize);
722 char *uidtoname(int uid);
723 char *gidtoname(int gid);
724 int get_share_mode_byname(int cnum,char *fname,int *pid);
725 int get_share_mode_by_fnum(int cnum,int fnum,int *pid);
726 BOOL check_file_sharing(int cnum,char *fname);
727 char *StrCpy(char *dest,char *src);
728 int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line);
729 time_t make_unix_date2(void *date_ptr);
730 int cached_error_packet(char *inbuf,char *outbuf,int fnum,int line);
731 mode_t unix_mode(int cnum,int dosmode);
732 BOOL check_name(char *name,int cnum);
733 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line);
734 int find_free_file(void );
735 BOOL unix_convert(char *name,int cnum);
736 void unix_convert_lanman2(char *s,char *home,BOOL case_is_sig);
737 void print_file(int fnum);
738 int read_smb_length(int fd,char *inbuf,int timeout);
739 int read_predict(int fd,int offset,char *buf,char **ptr,int num);
740 void invalidate_read_prediction(int fd);
741 void do_read_prediction();
742 BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear);
743 BOOL yield_connection(int cnum,char *name,int max_connections);
744 int count_chars(char *s,char c);
745 int smbrun(char *,char *);
746 BOOL name_map_mangle(char *OutName,BOOL need83,int snum);
747 struct hostent *Get_Hostbyname(char *name);
748 struct passwd *Get_Pwnam(char *user,BOOL allow_change);
749 void Abort(void);
750 void *Realloc(void *p,int size);
751 void smb_setlen(char *buf,int len);
752 int set_message(char *buf,int num_words,int num_bytes,BOOL zero);
753 BOOL check_access(int snum);
754 BOOL in_group(gid_t group, int current_gid, int ngroups, int *groups);
755 BOOL string_set(char **dest,char *src);
756 BOOL string_init(char **dest,char *src);
757 void string_free(char **s);
758 char *attrib_string(int mode);
759 void unix_format(char *fname);
760 BOOL directory_exist(char *dname,struct stat *st);
761 time_t make_unix_date3(void *date_ptr);
762 void put_dos_date3(char *buf,int offset,time_t unixdate);
763 void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode,time_t date);
764 BOOL in_list(char *s,char *list,BOOL case_sensitive);
765 void strupper(char *s);
766 BOOL file_exist(char *fname,struct stat *sbuf);
767 int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt, long time_out, BOOL exact);
768 void close_sockets(void );
769 BOOL send_smb(int fd,char *buffer);
770 BOOL send_keepalive(int client);
771 int read_data(int fd,char *buffer,int N);
772 int smb_len(char *buf);
773 BOOL receive_smb(int fd,char *buffer,int timeout);
774 void show_msg(char *buf);
775 BOOL big_endian(void );
776 BOOL become_user(int cnum, int uid);
777 BOOL unbecome_user(void);
778 void become_daemon(void);
779 BOOL reduce_name(char *s,char *dir,BOOL widelinks);
780 void strlower(char *s);
781 void strnorm(char *s);
782 char *smb_buf(char *buf);
783 char *smb_trans2_param(char *buf);
784 char *smb_trans2_data(char *buf);
785 BOOL strequal(char *,char *);
786 BOOL strnequal(char *,char *,int n);
787 BOOL strcsequal(char *,char *);
788 BOOL mask_match( char *str, char *regexp, int case_sig, BOOL trans2);
789 int dos_mode(int ,char *,struct stat *);
790 char *timestring();
791 BOOL ip_equal(struct in_addr ip1,struct in_addr ip2);
792 BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
793 char *get_home_dir(char *);
794 int set_filelen(int fd, long len);
795 void put_dos_date(char *buf,int offset,time_t unixdate);
796 void put_dos_date2(char *buf,int offset,time_t unixdate);
797 int lp_keepalive(void);
798 int name_len(char *s);
799 void dos_clean_name(char *s);
800 void unix_clean_name(char *s);
801 time_t make_unix_date(void *date_ptr);
802 BOOL lanman2_match( char *str, char *regexp, int case_sig, BOOL autoext);
803 BOOL trim_string(char *s,char *front,char *back);
804 int byte_checksum(char *buf,int len);
805 BOOL yesno(char *p);
806 uint32 file_size(char *file_name);
807 void dos_format(char *fname);
808 char *GetWd(char *s);
809 int name_mangle(char *in,char *out,char name_type);
810 int name_len(char *s);
811 void create_mangled_stack(int size);
812 int name_extract(char *buf,int ofs,char *name);
813 void get_broadcast(struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask);
814 BOOL allow_access(char *deny_list,char *allow_list,struct from_host *client);
815 #ifdef __STDC__
816 int Debug1(char *, ...);
817 #else
818 int Debug1();
819 #endif
820 BOOL check_hosts_equiv(char *user);
821 int chain_reply(int type,char *inbuf,char *inbuf2,char *outbuf,char *outbuf2,int size,int bufsize);
822 void close_cnum(int cnum,int uid);
823 char *smb_errstr(char *inbuf);
824 void GetTimeOfDay(struct timeval *tval);
825 struct tm *LocalTime(time_t *t,int);
826 int TimeDiff(time_t t);
827 BOOL set_filetime(char *fname,time_t mtime);
828 char *dirname_dos(char *path,char *buf);
829 BOOL get_myname(char *myname,struct in_addr *ip);
830 void expand_mask(char *Mask, BOOL);
831 BOOL sane_unix_date(time_t unixdate);
832 time_t start_of_month(void);
833 char *smb_fn_name(int cnum);
834 void get_machine_info(void);
835 int open_socket_in(int type, int port, int dlevel);
836 int open_socket_out(int type,struct in_addr *addr, int port );
837 struct in_addr *interpret_addr2(char *str);
838 BOOL zero_ip(struct in_addr ip);
839 int read_max_udp(int fd,char *buffer,int bufsize,int maxtime);
840 int interpret_protocol(char *str,int def);
841 int interpret_security(char *str,int def);
842 int ChDir(char *path);
843 int smb_buflen(char *buf);
844 unsigned long interpret_addr(char *str);
845 void mangle_name_83(char *s);
846 BOOL lp_casesignames(void);
847 void setup_logging(char *pname,BOOL interactive);
848 #ifdef DFS_AUTH
849 void dfs_unlogin(void);
850 extern int dcelogin_atmost_once;
851 #endif
852 #if AJT
853 void ajt_panic(void);
854 #endif
855 #ifdef NOSTRDUP
856 char *strdup(char *s);
857 #endif
858 #ifdef REPLACE_STRLEN
859 int Strlen(char *);
860 #endif
861 #ifdef REPLACE_STRSTR
862 char *Strstr(char *s, char *p);
863 #endif
864
865 #ifndef MIN
866 #define MIN(a,b) ((a)<(b)?(a):(b))
867 #endif
868 #ifndef MAX
869 #define MAX(a,b) ((a)>(b)?(a):(b))
870 #endif
871
872 #ifndef ABS
873 #define ABS(a) ((a)>0?(a):(-(a)))
874 #endif
875
876 #ifndef SIGNAL_CAST
877 #define SIGNAL_CAST
878 #endif
879
880 #ifndef SELECT_CAST
881 #define SELECT_CAST
882 #endif
883
884
885 /* Some POSIX definitions for those without */
886  
887 #ifndef S_IFDIR
888 #define S_IFDIR         0x4000
889 #endif
890 #ifndef S_ISDIR
891 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
892 #endif
893 #ifndef S_IRWXU
894 #define S_IRWXU 00700           /* read, write, execute: owner */
895 #endif
896 #ifndef S_IRUSR
897 #define S_IRUSR 00400           /* read permission: owner */
898 #endif
899 #ifndef S_IWUSR
900 #define S_IWUSR 00200           /* write permission: owner */
901 #endif
902 #ifndef S_IXUSR
903 #define S_IXUSR 00100           /* execute permission: owner */
904 #endif
905 #ifndef S_IRWXG
906 #define S_IRWXG 00070           /* read, write, execute: group */
907 #endif
908 #ifndef S_IRGRP
909 #define S_IRGRP 00040           /* read permission: group */
910 #endif
911 #ifndef S_IWGRP
912 #define S_IWGRP 00020           /* write permission: group */
913 #endif
914 #ifndef S_IXGRP
915 #define S_IXGRP 00010           /* execute permission: group */
916 #endif
917 #ifndef S_IRWXO
918 #define S_IRWXO 00007           /* read, write, execute: other */
919 #endif
920 #ifndef S_IROTH
921 #define S_IROTH 00004           /* read permission: other */
922 #endif
923 #ifndef S_IWOTH
924 #define S_IWOTH 00002           /* write permission: other */
925 #endif
926 #ifndef S_IXOTH
927 #define S_IXOTH 00001           /* execute permission: other */
928 #endif
929
930
931 /* these are used in NetServerEnum to choose what to receive */
932 #define SV_TYPE_WORKSTATION         0x00000001
933 #define SV_TYPE_SERVER              0x00000002
934 #define SV_TYPE_SQLSERVER           0x00000004
935 #define SV_TYPE_DOMAIN_CTRL         0x00000008
936 #define SV_TYPE_DOMAIN_BAKCTRL      0x00000010
937 #define SV_TYPE_TIME_SOURCE         0x00000020
938 #define SV_TYPE_AFP                 0x00000040
939 #define SV_TYPE_NOVELL              0x00000080
940 #define SV_TYPE_DOMAIN_MEMBER       0x00000100
941 #define SV_TYPE_PRINTQ_SERVER       0x00000200
942 #define SV_TYPE_DIALIN_SERVER       0x00000400
943 #define SV_TYPE_SERVER_UNIX         0x00000800
944 #define SV_TYPE_NT                  0x00001000
945 #define SV_TYPE_WFW                 0x00002000
946 #define SV_TYPE_SERVER_MFPN         0x00004000
947 #define SV_TYPE_SERVER_NT           0x00008000
948 #define SV_TYPE_POTENTIAL_BROWSER   0x00010000
949 #define SV_TYPE_BACKUP_BROWSER      0x00020000
950 #define SV_TYPE_MASTER_BROWSER      0x00040000
951 #define SV_TYPE_DOMAIN_MASTER       0x00080000
952 #define SV_TYPE_SERVER_OSF          0x00100000
953 #define SV_TYPE_SERVER_VMS          0x00200000
954 #define SV_TYPE_ALTERNATE_XPORT     0x20000000  
955 #define SV_TYPE_LOCAL_LIST_ONLY     0x40000000  
956 #define SV_TYPE_DOMAIN_ENUM         0x80000000
957 #define SV_TYPE_ALL                 0xFFFFFFFF  
958
959
960
961 /* protocol types. It assumes that higher protocols include lower protocols
962    as subsets */
963 enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
964
965 /* security levels */
966 enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER};
967
968 /* printing types */
969 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,PRINT_QNX};
970
971
972 /* case handling */
973 enum case_handling {CASE_LOWER,CASE_UPPER};
974
975
976 /* Macros to get at offsets within smb_lkrng and smb_unlkrng
977    structures. We cannot define these as actual structures
978    due to possible differences in structure packing
979    on different machines/compilers. */
980
981 #define SMB_LPID_OFFSET(indx) (10 * (indx))
982 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
983 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
984
985 /* Macro to cache an error in a write_bmpx_struct */
986 #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
987                             w->wr_discard = True, -1)
988 /* Macro to test if an error has been cached for this fnum */
989 #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
990                                 Files[(fnum)].wbmpx_ptr && \
991                                 Files[(fnum)].wbmpx_ptr->wr_discard)
992 /* Macro to turn the cached error into an error packet */
993 #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
994
995 /* these are the datagram types */
996 #define DGRAM_DIRECT_UNIQUE 0x10
997
998 #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
999
1000 /* this is how errors are generated */
1001 #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
1002
1003 #define ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
1004
1005 #endif 
1006 /* _SMB_H */