home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / contrib / samba / samba-1.8 / samba-1 / samba-1.8.05 / smb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  30.4 KB  |  904 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.8.
  4.    Copyright (C) Andrew Tridgell 1992,1993,1994
  5.    
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _SMB_H
  21. #define _SMB_H
  22.  
  23. #ifndef MAX_CONNECTIONS
  24. #define MAX_CONNECTIONS 127
  25. #endif
  26.  
  27. #ifndef MAX_OPEN_FILES
  28. #define MAX_OPEN_FILES 50
  29. #endif
  30.  
  31. #ifndef GUEST_ACCOUNT
  32. #define GUEST_ACCOUNT "pcuser"
  33. #endif
  34.  
  35. #define BUFFER_SIZE (0xFFFF)
  36. #define SAFETY_MARGIN 1024
  37.  
  38. #ifndef EXTERN
  39. #    define EXTERN extern
  40. #endif
  41.  
  42. #define False (0)
  43. #define True (1)
  44. #define BOOLSTR(b) ((b) ? "Yes" : "No")
  45. #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
  46. #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
  47. #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
  48.  
  49. typedef int BOOL;
  50.  
  51. typedef short int16;
  52. typedef int int32;
  53. typedef unsigned short uint16;
  54. typedef unsigned int uint32;
  55.  
  56. #ifndef DEF_CREATE_MASK
  57. #define DEF_CREATE_MASK (0755)
  58. #endif
  59.  
  60. #ifndef DEFAULT_PIPE_TIMEOUT
  61. #define DEFAULT_PIPE_TIMEOUT 10000000 /* Ten seconds */
  62. #endif
  63.  
  64. /* debugging code */
  65. #define DEBUG(level,body) ((DEBUGLEVEL>=(level))?(Debug1 body):0)
  66.  
  67.  
  68. /* these macros make access to the packet buffers easier. See also the
  69. functions SSVAL() and SIVAL(). */
  70. #define SIVAL(buf,pos,val) sival((char *)(buf),pos,val)
  71. #define SSVAL(buf,pos,val) ssval((char *)(buf),pos,val)
  72. #define IVAL(buf,pos) ival((char *)(buf),pos)
  73. #define SVAL(buf,pos) sval((char *)buf,pos)
  74.  
  75. /* these are the signed versions */
  76. #define SIVALS(buf,pos,val) sival_s((char *)(buf),pos,val)
  77. #define SSVALS(buf,pos,val) ssval_s((char *)(buf),pos,val)
  78. #define IVALS(buf,pos) ival_s((char *)(buf),pos)
  79. #define SVALS(buf,pos) sval_s((char *)buf,pos)
  80.  
  81. #define PVAL(buf,pos,type) (*((type *)(((char *)buf) + pos)))
  82. #define SCVAL(buf,pos,x) PVAL(buf,pos,unsigned char) = (x)
  83. #define CVAL(buf,pos) PVAL(buf,pos,unsigned char)
  84.  
  85. #define BSWP(buf,len) object_byte_swap(buf,len)
  86. #define SWP(buf,len) (NeedSwap?BSWP(buf,len):((void *)buf))
  87.  
  88. #define DIR_STRUCT_SIZE 43
  89.  
  90. /* these define all the command types recognised by the server - there
  91. are lots of gaps so probably there are some rare commands that are not
  92. implemented */
  93.  
  94. #define pSETDIR '\377'
  95.  
  96. /* these define the attribute byte as seen by DOS */
  97. #define aRONLY (1L<<0)
  98. #define aHIDDEN (1L<<1)
  99. #define aSYSTEM (1L<<2)
  100. #define aVOLID (1L<<3)
  101. #define aDIR (1L<<4)
  102. #define aARCH (1L<<5)
  103.  
  104.  
  105. /* SMB X/Open error codes for the ERRdos error class */
  106. #define ERRbadfunc 1 /* Invalid function (or system call) */
  107. #define ERRbadfile 2 /* File not found (pathname error) */
  108. #define ERRbadpath 3 /* Directory not found */
  109. #define ERRnofids 4 /* Too many open files */
  110. #define ERRnoaccess 5 /* Access denied */
  111. #define ERRbadfid 6 /* Invalid fid */
  112. #define ERRnomem 8 /* Out of memory */
  113. #define ERRbadmem 9 /* Invalid memory block address */
  114. #define ERRbadenv 10 /* Invalid environment */
  115. #define ERRbadaccess 12 /* Invalid open mode */
  116. #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
  117. #define ERRres 14 /* reserved */
  118. #define ERRbaddrive 15 /* Invalid drive */
  119. #define ERRremcd 16 /* Attempt to delete current directory */
  120. #define ERRdiffdevice 17 /* rename/move across different filesystems */
  121. #define ERRnofiles 18 /* no more files found in file search */
  122. #define ERRbadshare 32 /* Share mode on file conflict with open mode */
  123. #define ERRlock 33 /* Lock request conflicts with existing lock */
  124. #define ERRfilexists 80 /* File in operation already exists */
  125. #define ERRbadpipe 230 /* Named pipe invalid */
  126. #define ERRpipebusy 231 /* All instances of pipe are busy */
  127. #define ERRpipeclosing 232 /* named pipe close in progress */
  128. #define ERRnotconnected 233 /* No process on other end of named pipe */
  129. #define ERRmoredata 234 /* More data to be returned */
  130. #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
  131. #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not suppored */
  132.  
  133. /* here's a special one from observing NT */
  134. #define ERRnoipc 66 /* don't support ipc */
  135.  
  136. /* Error codes for the ERRSRV class */
  137.  
  138. #define ERRerror 1 /* Non specific error code */
  139. #define ERRbadpw 2 /* Bad password */
  140. #define ERRbadtype 3 /* reserved */
  141. #define ERRaccess 4 /* No permissions to do the requested operation */
  142. #define ERRinvnid 5 /* tid invalid */
  143. #define ERRinvnetname 6 /* Invalid servername */
  144. #define ERRinvdevice 7 /* Invalid device */
  145. #define ERRqfull 49 /* Print queue full */
  146. #define ERRqtoobig 50 /* Queued item too big */
  147. #define ERRinvpfid 52 /* Invalid print file in smb_fid */
  148. #define ERRsmbcmd 64 /* Unrecognised command */
  149. #define ERRsrverror 65 /* smb server internal error */
  150. #define ERRfilespecs 67 /* fid and pathname invalid combination */
  151. #define ERRbadlink 68 /* reserved */
  152. #define ERRbadpermits 69 /* Access specified for a file is not valid */
  153. #define ERRbadpid 70 /* reserved */
  154. #define ERRsetattrmode 71 /* attribute mode invalid */
  155. #define ERRpaused 81 /* Message server paused */
  156. #define ERRmsgoff 82 /* Not receiving messages */
  157. #define ERRnoroom 83 /* No room for message */
  158. #define ERRrmuns 87 /* too many remote usernames */
  159. #define ERRtimeout 88 /* operation timed out */
  160. #define ERRnoresource  89 /* No resources currently available for request. */
  161. #define ERRtoomanyuids 90 /* too many userids */
  162. #define ERRbaduid 91 /* bad userid */
  163. #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
  164. #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
  165. #define ERRcontMPX 252 /* resume MPX mode */
  166. #define ERRbadPW /* reserved */
  167. #define ERRnosupport 0xFFFF
  168.  
  169. /* Error codes for the ERRHRD class */
  170.  
  171. #define ERRnowrite 19 /* read only media */
  172. #define ERRbadunit 20 /* Unknown device */
  173. #define ERRnotready 21 /* Drive not ready */
  174. #define ERRbadcmd 22 /* Unknown command */
  175. #define ERRdata 23 /* Data (CRC) error */
  176. #define ERRbadreq 24 /* Bad request structure length */
  177. #define ERRseek 25
  178. #define ERRbadmedia 26
  179. #define ERRbadsector 27
  180. #define ERRnopaper 28
  181. #define ERRwrite 29 /* write fault */
  182. #define ERRread 30 /* read fault */
  183. #define ERRgeneral 31 /* General hardware failure */
  184. #define ERRwrongdisk 34
  185. #define ERRFCBunavail 35
  186. #define ERRsharebufexc 36 /* share buffer exceeded */
  187. #define ERRdiskfull 39
  188.  
  189.  
  190. typedef char pstring[1024];
  191. typedef char fstring[128];
  192.  
  193. typedef struct
  194. {
  195.   int size;
  196.   int mode;
  197.   int uid;
  198.   int gid;
  199.   time_t mtime;
  200.   time_t atime;
  201.   time_t ctime;
  202.   pstring name;
  203. } file_info;
  204.  
  205.  
  206. /* Structure used when SMBwritebmpx is active */
  207. typedef struct
  208.         {
  209.     int   wr_total_written; /* So we know when to discard this */
  210.     int32 wr_timeout;
  211.     int32 wr_errclass;
  212.     int32 wr_error; /* Cached errors */
  213.     BOOL  wr_mode; /* write through mode) */
  214.     BOOL  wr_discard; /* discard all further data */
  215.         } write_bmpx_struct;
  216.  
  217. typedef struct
  218.     {
  219.     int cnum;
  220.     int fd;
  221.     int pos;
  222.     char *mmap_ptr;
  223.     int mmap_size;
  224.     write_bmpx_struct *wbmpx_ptr;
  225.     BOOL open;
  226.     BOOL can_lock;
  227.     BOOL read_only;
  228.     BOOL print_file;
  229.     pstring name;
  230.     } files_struct;
  231.  
  232. /* this is the structure used for the local netbios name table */
  233. typedef struct
  234. {
  235.   time_t start_time;
  236.   int ttl;
  237.   struct in_addr ip;
  238.   struct in_addr master_ip;
  239.   BOOL found_master;
  240.   BOOL valid;
  241.   BOOL subnet;
  242.   char flags[10];
  243.   unsigned char nb_flags;
  244.   char name[100];
  245. } name_struct;
  246.  
  247.  
  248. typedef struct
  249. {
  250.   int service;
  251.   int connect_num;
  252.   int uid;
  253.   int gid;
  254.   void *dirptr;
  255.   BOOL open;
  256.   BOOL printer;
  257.   BOOL ipc;
  258.   BOOL read_only;
  259.   pstring dirpath;
  260.   pstring connectpath;
  261.   /* following groups stuff added by ih */
  262.   int ngroups;
  263.   gid_t *groups;
  264.   int *igroups; /* an integer version - some OSes are broken :-( */
  265. } connection_struct;
  266.  
  267.  
  268. typedef struct
  269. {
  270.   int uid;
  271.   char *name;
  272.   BOOL guest;
  273. } user_struct;
  274.  
  275.  
  276. typedef struct
  277. {
  278.   BOOL have_saved_ids;
  279. } machine_struct;
  280.  
  281.  
  282. enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
  283.  
  284. typedef struct
  285. {
  286.   int job;
  287.   int size;
  288.   int status;
  289.   time_t time;
  290.   char user[30];
  291.   char file[100];
  292. } print_queue_struct;
  293.  
  294. /* this is used for smbstatus */
  295. struct connect_record
  296. {
  297.   int magic;
  298.   int pid;
  299.   int cnum;
  300.   int uid;
  301.   int gid;
  302.   char name[24];
  303.   char addr[24];
  304.   char machine[128];
  305.   time_t start;
  306. };
  307.  
  308.  
  309.  
  310.  
  311. /* these are useful macros for checking validity of handles */
  312. #define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < MAX_OPEN_FILES))
  313. #define OPEN_FNUM(fnum)    (VALID_FNUM(fnum) && Files[fnum].open)
  314. #define VALID_CNUM(cnum)   (((cnum) >= 0) && ((cnum) < MAX_CONNECTIONS))
  315. #define OPEN_CNUM(cnum)    (VALID_CNUM(cnum) && Connections[cnum].open)
  316. #define IS_IPC(cnum)       (VALID_CNUM(cnum) && Connections[cnum].ipc)
  317.  
  318. /* translates a connection number into a service number */
  319. #define SNUM(cnum)         (Connections[cnum].service)
  320.  
  321. /* access various service details */
  322. #define GUEST              (lp_guestaccount())
  323. #define HOME(cnum)         (lp_pathname(SNUM(cnum)))
  324. #define PATH(snum)         (lp_pathname(snum))
  325. #define USER(snum)         (lp_username(snum))
  326. #define SERVICE(snum)      (lp_servicename(snum))
  327. #define PRINTCAP           (lp_printcapname())
  328. #define PRINTCOMMAND(snum) (lp_printcommand(snum))
  329. #define PRINTERNAME(snum)  (lp_printername(snum))
  330. #define CAN_WRITE(cnum)    (OPEN_CNUM(cnum) && !Connections[cnum].read_only)
  331. #define VALID_SNUM(snum)   (lp_snum_ok(snum))
  332. #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
  333. #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
  334. #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
  335. #define CAN_PRINT(cnum)    (OPEN_CNUM(cnum) && lp_print_ok(SNUM(cnum)))
  336. #define POSTSCRIPT(cnum)   (OPEN_CNUM(cnum) && lp_postscript(SNUM(cnum)))
  337. #define MAP_HIDDEN(cnum)   (OPEN_CNUM(cnum) && lp_map_hidden(SNUM(cnum)))
  338. #define MAP_SYSTEM(cnum)   (OPEN_CNUM(cnum) && lp_map_system(SNUM(cnum)))
  339. #define CREATE_MODE(cnum)  (lp_create_mode(SNUM(cnum)))
  340.  
  341. /* the basic packet size, assuming no words or bytes */
  342. #define smb_size 39
  343.  
  344. /* offsets into message for common items */
  345. #define smb_com 8
  346. #define smb_rcls 9
  347. #define smb_reh 10
  348. #define smb_err 11
  349. #define smb_flg 13
  350. #define smb_flg2 14
  351. #define smb_reb 13
  352. #define smb_tid 28
  353. #define smb_pid 30
  354. #define smb_uid 32
  355. #define smb_mid 34
  356. #define smb_wct 36
  357. #define smb_vwv 37
  358. #define smb_vwv0 37
  359. #define smb_vwv1 39
  360. #define smb_vwv2 41
  361. #define smb_vwv3 43
  362. #define smb_vwv4 45
  363. #define smb_vwv5 47
  364. #define smb_vwv6 49
  365. #define smb_vwv7 51
  366. #define smb_vwv8 53
  367. #define smb_vwv9 55
  368. #define smb_vwv10 57
  369. #define smb_vwv11 59
  370. #define smb_vwv12 61
  371. #define smb_vwv13 63
  372. #define smb_vwv14 65
  373. #define smb_vwv15 67
  374. #define smb_vwv16 69
  375. #define smb_vwv17 71
  376.  
  377.  
  378. /* the complete */
  379. #define SMBmkdir      0x00   /* create directory */
  380. #define SMBrmdir      0x01   /* delete directory */
  381. #define SMBopen       0x02   /* open file */
  382. #define SMBcreate     0x03   /* create file */
  383. #define SMBclose      0x04   /* close file */
  384. #define SMBflush      0x05   /* flush file */
  385. #define SMBunlink     0x06   /* delete file */
  386. #define SMBmv         0x07   /* rename file */
  387. #define SMBgetatr     0x08   /* get file attributes */
  388. #define SMBsetatr     0x09   /* set file attributes */
  389. #define SMBread       0x0A   /* read from file */
  390. #define SMBwrite      0x0B   /* write to file */
  391. #define SMBlock       0x0C   /* lock byte range */
  392. #define SMBunlock     0x0D   /* unlock byte range */
  393. #define SMBctemp      0x0E   /* create temporary file */
  394. #define SMBmknew      0x0F   /* make new file */
  395. #define SMBchkpth     0x10   /* check directory path */
  396. #define SMBexit       0x11   /* process exit */
  397. #define SMBlseek      0x12   /* seek */
  398. #define SMBtcon       0x70   /* tree connect */
  399. #define SMBtconX      0x75   /* tree connect and X*/
  400. #define SMBtdis       0x71   /* tree disconnect */
  401. #define SMBnegprot    0x72   /* negotiate protocol */
  402. #define SMBdskattr    0x80   /* get disk attributes */
  403. #define SMBsearch     0x81   /* search directory */
  404. #define SMBsplopen    0xC0   /* open print spool file */
  405. #define SMBsplwr      0xC1   /* write to print spool file */
  406. #define SMBsplclose   0xC2   /* close print spool file */
  407. #define SMBsplretq    0xC3   /* return print queue */
  408. #define SMBsends      0xD0   /* send single block message */
  409. #define SMBsendb      0xD1   /* send broadcast message */
  410. #define SMBfwdname    0xD2   /* forward user name */
  411. #define SMBcancelf    0xD3   /* cancel forward */
  412. #define SMBgetmac     0xD4   /* get machine name */
  413. #define SMBsendstrt   0xD5   /* send start of multi-block message */
  414. #define SMBsendend    0xD6   /* send end of multi-block message */
  415. #define SMBsendtxt    0xD7   /* send text of multi-block message */
  416.  
  417. /* Core+ protocol */
  418. #define SMBlockread      0x13   /* Lock a range and read */
  419. #define SMBwriteunlock 0x14 /* Unlock a range then write */
  420. #define SMBreadbraw   0x1a  /* read a block of data with no smb header */
  421. #define SMBwritebraw  0x1d  /* write a block of data with no smb header */
  422. #define SMBwritec     0x20  /* secondary write request */
  423. #define SMBwriteclose 0x2c  /* write a file then close it */
  424.  
  425. /* dos extended protocol */
  426. #define SMBreadBraw      0x1A   /* read block raw */
  427. #define SMBreadBmpx      0x1B   /* read block multiplexed */
  428. #define SMBreadBs        0x1C   /* read block (secondary response) */
  429. #define SMBwriteBraw     0x1D   /* write block raw */
  430. #define SMBwriteBmpx     0x1E   /* write block multiplexed */
  431. #define SMBwriteBs       0x1F   /* write block (secondary request) */
  432. #define SMBwriteC        0x20   /* write complete response */
  433. #define SMBsetattrE      0x22   /* set file attributes expanded */
  434. #define SMBgetattrE      0x23   /* get file attributes expanded */
  435. #define SMBlockingX      0x24   /* lock/unlock byte ranges and X */
  436. #define SMBtrans         0x25   /* transaction - name, bytes in/out */
  437. #define SMBtranss        0x26   /* transaction (secondary request/response) */
  438. #define SMBioctl         0x27   /* IOCTL */
  439. #define SMBioctls        0x28   /* IOCTL  (secondary request/response) */
  440. #define SMBcopy          0x29   /* copy */
  441. #define SMBmove          0x2A   /* move */
  442. #define SMBecho          0x2B   /* echo */
  443. #define SMBopenX         0x2D   /* open and X */
  444. #define SMBreadX         0x2E   /* read and X */
  445. #define SMBwriteX        0x2F   /* write and X */
  446. #define SMBsesssetupX    0x73   /* Session Set Up & X (including User Logon) */
  447. #define SMBtconX         0x75   /* tree connect and X */
  448. #define SMBffirst        0x82   /* find first */
  449. #define SMBfunique       0x83   /* find unique */
  450. #define SMBfclose        0x84   /* find close */
  451. #define SMBinvalid       0xFE   /* invalid command */
  452.  
  453. /* Extended 2.0 protocol */
  454. #define SMBtrans2        0x32   /* TRANS2 protocol set */
  455. #define SMBtranss2       0x33   /* TRANS2 protocol set, secondary command */
  456. #define SMBfindclose     0x34   /* Terminate a TRANSACT2_FINDFIRST */
  457. #define SMBfindnclose    0x35   /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
  458. #define SMBulogoffX      0x74   /* user logoff */
  459.  
  460.  
  461. /* these are the TRANS2 sub commands */
  462. #define TRANSACT2_OPEN          0
  463. #define TRANSACT2_FINDFIRST     1
  464. #define TRANSACT2_FINDNEXT      2
  465. #define TRANSACT2_QFSINFO       3
  466. #define TRANSACT2_SETFSINFO     4
  467. #define TRANSACT2_QPATHINFO     5
  468. #define TRANSACT2_SETPATHINFO   6
  469. #define TRANSACT2_QFILEINFO     7
  470. #define TRANSACT2_SETFILEINFO   8
  471. #define TRANSACT2_FSCTL         9
  472. #define TRANSACT2_IOCTL           10
  473. #define TRANSACT2_FINDNOTIFYFIRST 11
  474. #define TRANSACT2_FINDNOTIFYNEXT  12
  475. #define TRANSACT2_MKDIR           13
  476.  
  477.  
  478. /* these are the trans2 sub fields for primary requests */
  479. #define smb_tpscnt smb_vwv0
  480. #define smb_tdscnt smb_vwv1
  481. #define smb_mprcnt smb_vwv2
  482. #define smb_mdrcnt smb_vwv3
  483. #define smb_msrcnt smb_vwv4
  484. #define smb_flags smb_vwv5
  485. #define smb_timeout smb_vwv6
  486. #define smb_pscnt smb_vwv9
  487. #define smb_psoff smb_vwv10
  488. #define smb_dscnt smb_vwv11
  489. #define smb_dsoff smb_vwv12
  490. #define smb_suwcnt smb_vwv13
  491. #define smb_setup smb_vwv14
  492. #define smb_setup0 smb_setup
  493. #define smb_setup1 (smb_setup+2)
  494. #define smb_setup2 (smb_setup+4)
  495.  
  496. /* these are for the secondary requests */
  497. #define smb_spscnt smb_vwv2
  498. #define smb_spsoff smb_vwv3
  499. #define smb_spsdisp smb_vwv4
  500. #define smb_sdscnt smb_vwv5
  501. #define smb_sdsoff smb_vwv6
  502. #define smb_sdsdisp smb_vwv7
  503. #define smb_sfid smb_vwv8
  504.  
  505. /* and these for responses */
  506. #define smb_tprcnt smb_vwv0
  507. #define smb_tdrcnt smb_vwv1
  508. #define smb_prcnt smb_vwv3
  509. #define smb_proff smb_vwv4
  510. #define smb_prdisp smb_vwv5
  511. #define smb_drcnt smb_vwv6
  512. #define smb_droff smb_vwv7
  513. #define smb_drdisp smb_vwv8
  514.  
  515. /* where to find the base of the SMB packet proper */
  516. #define smb_base(buf) ((buf)+4)
  517.  
  518.  
  519. #define SUCCESS 0  /* The request was successful. */
  520. #define ERRDOS 0x01 /*  Error is from the core DOS operating system set. */
  521. #define ERRSRV 0x02  /* Error is generated by the server network file manager.*/
  522. #define ERRHRD 0x03  /* Error is an hardware error. */
  523. #define ERRCMD 0xFF  /* Command was not in the "SMB" format. */
  524.  
  525.  
  526. #ifdef USE_DIRECT
  527. #define DIRECT direct
  528. #else
  529. #define DIRECT dirent
  530. #endif
  531.  
  532. /* structure used to hold the incoming hosts info */
  533. struct from_host {
  534.     char   *name;            /* host name */
  535.     char   *addr;            /* host address */
  536.     struct sockaddr_in *sin;        /* their side of the link */
  537. };
  538.  
  539. /* and a few prototypes */
  540. char *fgets_slash(char *s,int maxlen,FILE *f);
  541. int read_udp_socket(int fd,char *buf,int len);
  542. void exit_server(void);
  543. BOOL process_exists(int pid);
  544. int lockfread(void *p,int pos,int size,int n,FILE *f);
  545. BOOL chgpasswd(char *name,char *oldpass,char *newpass);
  546. void push_mangled_name(char *s);
  547. void array_promote(char *array,int elsize,int element);
  548. void string_replace(char *s,char old,char new);
  549. BOOL user_in_list(char *user,char *list);
  550. BOOL string_sub(char *s,char *pattern,char *insert);
  551. char *StrnCpy(char *dest,char *src,int n);
  552. char *validated_username(int vuid);
  553. BOOL set_user_password(char *user,char *oldpass,char *newpass);
  554. int smb_buf_ofs(char *buf);
  555. char *skip_string(char *buf,int n);
  556. BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset);
  557. int read_file(int fnum,char *data,int pos,int mincnt,int maxcnt,int timeout,BOOL exact);
  558. BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
  559. int seek_file(int fnum,int pos);
  560. BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode);
  561. int get_printqueue(int snum,print_queue_struct **queue);
  562. int sig_cld();
  563. int find_free_connection(void );
  564. void parse_connect(char *buf,char *service,char *user,char *password,char *dev);
  565. int make_connection(char *service,char *user,char *password,char *dev,int vuid);
  566. void *dptr_get(int key);
  567. char *dptr_path(int key);
  568. char *dptr_wcard(int key);
  569. int dptr_set_wcard(int key, char *wcard);
  570. int dptr_set_attr(int key, uint16 attr);
  571. uint16 dptr_attr(int key);
  572. void dptr_promote(int key);
  573. void dptr_demote(int key);
  574. void dptr_close(int key);
  575. void dptr_closepath(char *path,int pid);
  576. int dptr_create(void *p,char *path, BOOL expect_close,int pid);
  577. BOOL dptr_fill(char *buf,unsigned int key);
  578. BOOL dptr_zero(char *buf);
  579. void *dptr_fetch(char *buf,int *num);
  580. void *dptr_fetch_lanman2(char *params,int dptr_num);
  581. BOOL get_dir_entry(int cnum,char *mask,int dirtype,char *fname,int *size,int *mode,time_t *date,BOOL check_descend);
  582. void open_file(int fnum,int cnum,char *fname,int flags,int mode);
  583. void close_open_files(int cnum);
  584. void close_file(int fnum);
  585. int reply_trans2(char *inbuf,char *outbuf,int length,int bufsize);
  586. int reply_trans(char *inbuf,char *outbuf);
  587. char *ufc_crypt(char *key,char *salt);
  588. BOOL authorise_login(int snum,char *user,char *password,BOOL *guest,int vuid);
  589. void add_session_user(char *user);
  590. int valid_uid(int uid);
  591. BOOL password_ok(char *user,char *password, struct passwd *pwd);
  592. void register_uid(int uid,char *name,BOOL guest);
  593. BOOL string_combinations(char *s,int offset,BOOL (*fn)(),int N);
  594. BOOL fromhost(int sock,struct from_host *f);
  595. BOOL strhasupper(char *s);
  596. BOOL strhaslower(char *s);
  597. void disk_free(char *path,int *bsize,int *dfree,int *dsize);
  598. int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line);
  599. time_t make_unix_date2(void *date_ptr);
  600. int cached_error_packet(char *inbuf,char *outbuf,int fnum,int line);
  601. BOOL start_dir(int cnum,char *directory);
  602. mode_t unix_mode(int cnum,int dosmode);
  603. BOOL check_name(char *name,int cnum);
  604. int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line);
  605. int find_free_file(void );
  606. void unix_convert(char *name,int cnum);
  607. void unix_convert_lanman2(char *s,char *home,BOOL case_is_sig);
  608. int call_trans2findfirst(char *inbuf, char *outbuf, int bufsize, int cnum,char **pparams, char **ppdata);
  609. int call_trans2qfsinfo(char *inbuf, char *outbuf, int length, int bufsize,
  610.             int cnum, char **pparams, char **ppdata);
  611. int call_trans2findnext(char *inbuf, char *outbuf, int length, int bufsize,
  612.             int cnum, char **pparams, char **ppdata);
  613. void print_file(int fnum);
  614. void check_magic(int fnum,int cnum);
  615. int read_smb_length(int fd,char *inbuf,int timeout);
  616. int read_predict(int fd,int offset,char *buf,int num);
  617. void invalidate_read_prediction(int fd);
  618. void do_read_prediction();
  619. BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear);
  620. BOOL yield_connection(int cnum,char *name,int max_connections);
  621. BOOL fcntl_lock(int fd,int op,int offset,int count,int type);
  622. int count_chars(char *s,char c);
  623. int smbrun(char *);
  624. void unix_convert_83(char *s,char *home,BOOL mangle, char *MangledMap);
  625. BOOL name_convert(char *OutName,char *InName,BOOL mangle, char *MangledNames);
  626. struct hostent *Get_Hostbyname(char *name);
  627. struct passwd *Get_Pwnam(char *user);
  628. void Abort(void);
  629. void safe_memcpy(void *dest,void *src,int size);
  630. void *Realloc(void *p,int size);
  631. void send_logout(char *inbuf,char *outbuf );
  632. void smb_setlen(char *buf,int len);
  633. int set_message(char *buf,int num_words,int num_bytes,BOOL zero);
  634. void name_interpret(char *in,char *out);
  635. BOOL check_access(int snum);
  636. BOOL in_group(gid_t group, int current_gid, int ngroups, int *groups);
  637. void *object_byte_swap(void *obj,int size);
  638. void ssval(char *buf,int pos,uint16 val);
  639. void sival(char *buf,int pos,uint32 val);
  640. uint32 ival(char *buf,int pos);
  641. uint16 sval(char *,int );
  642. void ssval_s(char *buf,int pos,int16 val);
  643. void sival_s(char *buf,int pos,int32 val);
  644. int32 ival_s(char *buf,int pos);
  645. int16 sval_s(char *,int );
  646. BOOL string_set(char **dest,char *src);
  647. BOOL string_init(char **dest,char *src);
  648. void string_free(char **s);
  649. char *attrib_string(int mode);
  650. int do_long_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*fn)(),BOOL recurse_dir);
  651. int do_short_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*fn)(),BOOL recurse_dir);
  652. void do_dir(char *inbuf,char *outbuf,char *Mask,int attribute,void (*fn)(),BOOL recurse_dir);
  653. void unix_format(char *fname);
  654. BOOL directory_exist(char *dname);
  655. void make_dir_struct(char *buf,char *mask,char *fname,unsigned int size,int mode,time_t date);
  656. BOOL in_list(char *s,char *list,BOOL case_sensitive);
  657. void strupper(char *s);
  658. BOOL file_exist(char *fname);
  659. int read_with_timeout(int fd,char *buf,int mincnt,int maxcnt, long time_out, BOOL exact);
  660. int write_socket(int fd,char *buf,int len);
  661. void close_sockets(void );
  662. int write_with_timeout(int fd, char *buf, int length, long time_out);
  663. BOOL send_smb(char *buffer);
  664. BOOL read_data(int fd,char *buffer,int N);
  665. int smb_len(char *buf);
  666. BOOL receive_smb(char *buffer,int timeout);
  667. void show_msg(char *buf);
  668. BOOL big_endian(void );
  669. BOOL become_user(int cnum);
  670. BOOL unbecome_user(void);
  671. void become_daemon(void);
  672. BOOL reduce_name(char *s,char *dir,BOOL widelinks);
  673. void strlower(char *s);
  674. void strnorm(char *s);
  675. char *smb_buf();
  676. char *smb_trans2_param(char *buf);
  677. char *smb_trans2_data(char *buf);
  678. BOOL strequal(char *,char *);
  679. BOOL mask_match(char *,char *,BOOL ,BOOL, BOOL);
  680. int dos_mode(int ,char *,struct stat *);
  681. char *timestring();
  682. BOOL ip_equal(struct in_addr *ip1,struct in_addr *ip2);
  683. BOOL send_packet(char *buf,int len,struct in_addr *ip,int port,int type);
  684. char *get_home_dir(char *);
  685. int set_filelen(int fd, long len);
  686. void put_dos_date(char *buf,int offset,time_t unixdate);
  687. void put_dos_date2(char *buf,int offset,time_t unixdate);
  688. uint16 make_dos_time1(time_t unixdate);
  689. uint16 make_dos_date1(time_t unixdate);
  690. uint32 make_dos_date(time_t );
  691. uint32 make_dos_date2(time_t );
  692. int lp_keepalive(void);
  693. int name_len(char *s);
  694. void dos_clean_name(char *s);
  695. void unix_clean_name(char *s);
  696. time_t make_unix_date(void *date_ptr);
  697. void trim_string(char *s,char *front,char *back);
  698. int byte_checksum(char *buf,int len);
  699. BOOL yesno(char *p);
  700. uint32 file_size(char *file_name);
  701. void dos_format(char *fname);
  702. char *GetWd(char *s);
  703. int name_mangle(char *in,char *out);
  704. int name_len(char *s);
  705. BOOL name_equal(char *s1,char *s2);
  706. void show_nmb(char *inbuf);
  707. int nmb_len(char *buf);
  708. void create_mangled_stack(int size);
  709. BOOL receive_nmb(char *buffer,int timeout);
  710. void name_extract(char *buf,int ofs,char *name);
  711. BOOL name_query(char *inbuf,char *outbuf,char *name,struct in_addr to_ip,struct in_addr *ip,int maxtime,void (*fn)());
  712. BOOL name_status(char *inbuf,char *outbuf,char *name);
  713. void get_broadcast(struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask);
  714. BOOL allow_access(char *deny_list,char *allow_list,struct from_host *client);
  715. #ifdef __STDC__
  716. int Debug1(char *, ...);
  717. #else
  718. int Debug1();
  719. #endif
  720. BOOL check_hosts_equiv(char *user);
  721. char *validate_group(char *group,char *password,int snum);
  722. int chain_reply(int type,char *inbuf,char *inbuf2,char *outbuf,char *outbuf2,int size,int bufsize);
  723. void close_cnum(int cnum);
  724. char *smb_errstr(char *inbuf);
  725. struct tm *LocalTime(time_t *t,int);
  726. time_t TimeLocal(struct tm *tm,int);
  727. int TimeDiff(void);
  728. void replacestr(char *str1, char *str2, int start, int n);
  729. void openstr(char *s, int start, int n);
  730. void closestr(char *s, int start, int n);
  731. BOOL set_filetime(char *fname,time_t mtime);
  732. char *dirname_dos(char *path,char *buf);
  733. char *filename_dos(char *path,char *buf);
  734. BOOL get_myname(char *myname,struct in_addr *ip);
  735. BOOL ip_equal(struct in_addr *ip1,struct in_addr *ip2);
  736. void expand_mask(char *Mask, BOOL);
  737. BOOL sane_unix_date(time_t unixdate);
  738. time_t start_of_month(void);
  739. void log_out(char *buffer,int len);
  740. BOOL register_name(name_struct *name,struct in_addr *destip,void (*)());
  741. char *smb_fn_name(int cnum);
  742. int construct_datagram(char *,int,int,int,struct in_addr *,int,char *,char *);
  743. void get_machine_info(void);
  744. int open_socket_in(int type, int port);
  745. int open_socket_out(struct in_addr *addr, int port );
  746. int read_max_udp(int fd,char *buffer,int bufsize,int maxtime);
  747. void log_in(char *buffer,int len);
  748. int interpret_protocol(char *str,int def);
  749. int interpret_security(char *str,int def);
  750. int ChDir(char *path);
  751. int smb_buflen(char *buf);
  752. int interpret_short_filename(char *p,file_info *finfo);
  753. int interpret_long_filename(int level,char *p,file_info *finfo);
  754. unsigned long interpret_addr(char *str);
  755. void mangle_name_83(char *s, char *MangledMap);
  756. void *dptr_get(int);
  757. char *dptr_path(int);
  758. char *dptr_wcard(int);
  759. int dptr_set_wcard(int, char *);
  760. int dptr_set_attr(int, uint16);
  761. void *dptr_fetch_lanman2(char *,int);
  762. uint16 dptr_attr(int);
  763. void dptr_promote(int);
  764. void dptr_demote(int);
  765. void dptr_close(int);
  766. void dptr_closepath(char *,int);
  767. int dptr_create(void *,char *, BOOL, int);
  768. BOOL lp_casesignames(void);
  769. #ifdef NOSTRDUP
  770. char *strdup(char *s);
  771. #endif
  772. #ifdef REPLACE_STRLEN
  773. int Strlen(char *);
  774. #endif
  775. #ifdef REPLACE_STRSTR
  776. char *Strstr(char *s, char *p);
  777. #endif
  778.  
  779. #ifdef SUN
  780. struct DIRECT *readdir();
  781. char *strcpy();
  782. int fprintf();
  783. #endif
  784.  
  785. #ifdef STRING_DEBUG
  786. #define strcpy mystrcpy
  787. #define strchr mystrchr
  788. #define strrchr mystrrchr
  789. #define strlen mystrlen
  790. #define strncpy mystrncpy
  791. #define strcat mystrcat
  792. #define memcpy mymemcpy
  793. #define memset mymemset
  794. #endif
  795.  
  796.  
  797. #ifndef MIN
  798. #define MIN(a,b) ((a)<(b)?(a):(b))
  799. #endif
  800. #ifndef MAX
  801. #define MAX(a,b) ((a)>(b)?(a):(b))
  802. #endif
  803.  
  804. #ifndef ABS
  805. #define ABS(a) ((a)>0?(a):(-(a)))
  806. #endif
  807.  
  808. #ifndef SIGNAL_CAST
  809. #define SIGNAL_CAST
  810. #endif
  811.  
  812. #ifndef SELECT_CAST
  813. #define SELECT_CAST
  814. #endif
  815.  
  816.  
  817. /* Some POSIX definitions for those without */
  818.  
  819. #ifndef S_IFDIR
  820. #define S_IFDIR         0x4000
  821. #endif
  822. #ifndef S_ISDIR
  823. #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
  824. #endif
  825. #ifndef S_IRWXU
  826. #define S_IRWXU 00700           /* read, write, execute: owner */
  827. #endif
  828. #ifndef S_IRUSR
  829. #define S_IRUSR 00400           /* read permission: owner */
  830. #endif
  831. #ifndef S_IWUSR
  832. #define S_IWUSR 00200           /* write permission: owner */
  833. #endif
  834. #ifndef S_IXUSR
  835. #define S_IXUSR 00100           /* execute permission: owner */
  836. #endif
  837. #ifndef S_IRWXG
  838. #define S_IRWXG 00070           /* read, write, execute: group */
  839. #endif
  840. #ifndef S_IRGRP
  841. #define S_IRGRP 00040           /* read permission: group */
  842. #endif
  843. #ifndef S_IWGRP
  844. #define S_IWGRP 00020           /* write permission: group */
  845. #endif
  846. #ifndef S_IXGRP
  847. #define S_IXGRP 00010           /* execute permission: group */
  848. #endif
  849. #ifndef S_IRWXO
  850. #define S_IRWXO 00007           /* read, write, execute: other */
  851. #endif
  852. #ifndef S_IROTH
  853. #define S_IROTH 00004           /* read permission: other */
  854. #endif
  855. #ifndef S_IWOTH
  856. #define S_IWOTH 00002           /* write permission: other */
  857. #endif
  858. #ifndef S_IXOTH
  859. #define S_IXOTH 00001           /* execute permission: other */
  860. #endif
  861.  
  862.  
  863.  
  864. /* protocol types. It assumes that higher protocols include lower protocols
  865.    as subsets */
  866. enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
  867.  
  868. /* security levels */
  869. enum security_types {SEC_SHARE,SEC_USER};
  870.  
  871. /* case handling */
  872. enum case_handling {CASE_LOWER,CASE_UPPER};
  873.  
  874.  
  875. /* Macros to get at offsets within smb_lkrng and smb_unlkrng
  876.    structures. We cannot define these as actual structures
  877.    due to possible differences in structure packing
  878.    on different machines/compilers. */
  879.  
  880. #define SMB_LPID_OFFSET(indx) (10 * (indx))
  881. #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
  882. #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
  883.  
  884. /* Macro to cache an error in a write_bmpx_struct */
  885. #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
  886.                 w->wr_discard = True, -1)
  887. /* Macro to test if an error has been cached for this fnum */
  888. #define HAS_CACHED_ERROR(fnum) (Files[(fnum)].open && \
  889.                 Files[(fnum)].wbmpx_ptr && \
  890.                 Files[(fnum)].wbmpx_ptr->wr_discard)
  891. /* Macro to turn the cached error into an error packet */
  892. #define CACHED_ERROR(fnum) cached_error_packet(inbuf,outbuf,fnum,__LINE__)
  893.  
  894. /* these are the datagram types */
  895. #define DGRAM_DIRECT_UNIQUE 0x10
  896.  
  897. #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
  898.  
  899. /* this is how errors are generated */
  900. #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
  901.  
  902. #endif 
  903. /* _SMB_H */
  904.