smb.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  1. /*
  2. Unix SMB/Netbios implementation.
  3. Version 1.9.
  4. SMB parameters and setup
  5. Copyright (C) Andrew Tridgell 1992-1998
  6. Copyright (C) John H Terpstra 1996-1998
  7. Copyright (C) Luke Kenneth Casson Leighton 1996-1998
  8. Copyright (C) Paul Ashton 1998
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef _SMB_H
  22. #define _SMB_H
  23. #define BUFFER_SIZE (0xFFFF)
  24. #define SAFETY_MARGIN 1024
  25. #define NMB_PORT 137
  26. #define DGRAM_PORT 138
  27. #define SMB_PORT 139
  28. #define False (0)
  29. #define True (1)
  30. #define BOOLSTR(b) ((b) ? "Yes" : "No")
  31. #define BITSETB(ptr,bit) ((((char *)ptr)[0] & (1<<(bit)))!=0)
  32. #define BITSETW(ptr,bit) ((SVAL(ptr,0) & (1<<(bit)))!=0)
  33. #define IS_BITS_SET_ALL(var,bit) (((var)&(bit))==(bit))
  34. #define IS_BITS_SET_SOME(var,bit) (((var)&(bit))!=0)
  35. #define IS_BITS_CLR_ALL(var,bit) (((var)&(bit))==0)
  36. #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
  37. typedef int BOOL;
  38. /* limiting size of ipc replies */
  39. #define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
  40. #define SIZEOFWORD 2
  41. #ifndef DEF_CREATE_MASK
  42. #define DEF_CREATE_MASK (0755)
  43. #endif
  44. /* how long to wait for secondary SMB packets (milli-seconds) */
  45. #define SMB_SECONDARY_WAIT (60*1000)
  46. /* -------------------------------------------------------------------------- **
  47. * Debugging code. See also debug.c
  48. */
  49. /* mkproto.awk has trouble with ifdef'd function definitions (it ignores
  50. * the #ifdef directive and will read both definitions, thus creating two
  51. * diffferent prototype declarations), so we must do these by hand.
  52. */
  53. /* I know the __attribute__ stuff is ugly, but it does ensure we get the
  54. arguemnts to DEBUG() right. We have got them wrong too often in the
  55. past */
  56. #ifdef HAVE_STDARG_H
  57. int Debug1( const char *, ... )
  58. #ifdef __GNUC__
  59. __attribute__ ((format (printf, 1, 2)))
  60. #endif
  61. ;
  62. BOOL dbgtext( const char *, ... )
  63. #ifdef __GNUC__
  64. __attribute__ ((format (printf, 1, 2)))
  65. #endif
  66. ;
  67. #else
  68. int Debug1();
  69. BOOL dbgtext();
  70. #endif
  71. /* If we have these macros, we can add additional info to the header. */
  72. #ifdef HAVE_FILE_MACRO
  73. #define FILE_MACRO (__FILE__)
  74. #else
  75. #define FILE_MACRO ("")
  76. #endif
  77. #ifdef HAVE_FUNCTION_MACRO
  78. #define FUNCTION_MACRO (__FUNCTION__)
  79. #else
  80. #define FUNCTION_MACRO ("")
  81. #endif
  82. /* Debugging macros.
  83. * DEBUGLVL() - If level is <= the system-wide DEBUGLEVEL then generate a
  84. * header using the default macros for file, line, and
  85. * function name.
  86. * Returns True if the debug level was <= DEBUGLEVEL.
  87. * Example usage:
  88. * if( DEBUGLVL( 2 ) )
  89. * dbgtext( "Some text.\n" );
  90. * DEGUG() - Good old DEBUG(). Each call to DEBUG() will generate a new
  91. * header *unless* the previous debug output was unterminated
  92. * (i.e., no '\n'). See debug.c:dbghdr() for more info.
  93. * Example usage:
  94. * DEBUG( 2, ("Some text.\n") );
  95. * DEBUGADD() - If level <= DEBUGLEVEL, then the text is appended to the
  96. * current message (i.e., no header).
  97. * Usage:
  98. * DEBUGADD( 2, ("Some additional text.\n") );
  99. */
  100. #define DEBUGLVL( level ) \
  101. ( (DEBUGLEVEL >= (level)) \
  102. && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) )
  103. #if 0
  104. #define DEBUG( level, body ) \
  105. ( ( DEBUGLEVEL >= (level) \
  106. && dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) ) ) \
  107. ? (void)(dbgtext body) : (void)0 )
  108. #define DEBUGADD( level, body ) \
  109. ( (DEBUGLEVEL >= (level)) ? (void)(dbgtext body) : (void)0 )
  110. #else
  111. #define DEBUG( level, body ) \
  112. (void)( (DEBUGLEVEL >= (level)) \
  113. && (dbghdr( level, FILE_MACRO, FUNCTION_MACRO, (__LINE__) )) \
  114. && (dbgtext body) )
  115. #define DEBUGADD( level, body ) \
  116. (void)( (DEBUGLEVEL >= (level)) && (dbgtext body) )
  117. #endif
  118. /* End Debugging code section.
  119. * -------------------------------------------------------------------------- **
  120. */
  121. /* this defines the error codes that receive_smb can put in smb_read_error */
  122. #define READ_TIMEOUT 1
  123. #define READ_EOF 2
  124. #define READ_ERROR 3
  125. #define DIR_STRUCT_SIZE 43
  126. /* these define all the command types recognised by the server - there
  127. are lots of gaps so probably there are some rare commands that are not
  128. implemented */
  129. #define pSETDIR '\377'
  130. /* these define the attribute byte as seen by DOS */
  131. #define aRONLY (1L<<0)
  132. #define aHIDDEN (1L<<1)
  133. #define aSYSTEM (1L<<2)
  134. #define aVOLID (1L<<3)
  135. #define aDIR (1L<<4)
  136. #define aARCH (1L<<5)
  137. /* for readability... */
  138. #define IS_DOS_READONLY(test_mode) (((test_mode) & aRONLY) != 0)
  139. #define IS_DOS_DIR(test_mode) (((test_mode) & aDIR) != 0)
  140. #define IS_DOS_ARCHIVE(test_mode) (((test_mode) & aARCH) != 0)
  141. #define IS_DOS_SYSTEM(test_mode) (((test_mode) & aSYSTEM) != 0)
  142. #define IS_DOS_HIDDEN(test_mode) (((test_mode) & aHIDDEN) != 0)
  143. /* deny modes */
  144. #define DENY_DOS 0
  145. #define DENY_ALL 1
  146. #define DENY_WRITE 2
  147. #define DENY_READ 3
  148. #define DENY_NONE 4
  149. #define DENY_FCB 7
  150. /* open modes */
  151. #define DOS_OPEN_RDONLY 0
  152. #define DOS_OPEN_WRONLY 1
  153. #define DOS_OPEN_RDWR 2
  154. #define DOS_OPEN_FCB 0xF
  155. /* define shifts and masks for share and open modes. */
  156. #define OPEN_MODE_MASK 0xF
  157. #define SHARE_MODE_SHIFT 4
  158. #define SHARE_MODE_MASK 0x7
  159. #define GET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
  160. #define SET_OPEN_MODE(x) ((x) & OPEN_MODE_MASK)
  161. #define GET_DENY_MODE(x) (((x)>>SHARE_MODE_SHIFT) & SHARE_MODE_MASK)
  162. #define SET_DENY_MODE(x) ((x)<<SHARE_MODE_SHIFT)
  163. /* Sync on open file (not sure if used anymore... ?) */
  164. #define FILE_SYNC_OPENMODE (1<<14)
  165. #define GET_FILE_SYNC_OPENMODE(x) (((x) & FILE_SYNC_OPENMODE) ? True : False)
  166. /* allow delete on open file mode (used by NT SMB's). */
  167. #define ALLOW_SHARE_DELETE (1<<15)
  168. #define GET_ALLOW_SHARE_DELETE(x) (((x) & ALLOW_SHARE_DELETE) ? True : False)
  169. #define SET_ALLOW_SHARE_DELETE(x) ((x) ? ALLOW_SHARE_DELETE : 0)
  170. /* delete on close flag (used by NT SMB's). */
  171. #define DELETE_ON_CLOSE_FLAG (1<<16)
  172. #define GET_DELETE_ON_CLOSE_FLAG(x) (((x) & DELETE_ON_CLOSE_FLAG) ? True : False)
  173. #define SET_DELETE_ON_CLOSE_FLAG(x) ((x) ? DELETE_ON_CLOSE_FLAG : 0)
  174. /* open disposition values */
  175. #define FILE_EXISTS_FAIL 0
  176. #define FILE_EXISTS_OPEN 1
  177. #define FILE_EXISTS_TRUNCATE 2
  178. /* mask for open disposition. */
  179. #define FILE_OPEN_MASK 0x3
  180. #define GET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
  181. #define SET_FILE_OPEN_DISPOSITION(x) ((x) & FILE_OPEN_MASK)
  182. /* The above can be OR'ed with... */
  183. #define FILE_CREATE_IF_NOT_EXIST 0x10
  184. #define FILE_FAIL_IF_NOT_EXIST 0
  185. #define GET_FILE_CREATE_DISPOSITION(x) ((x) & (FILE_CREATE_IF_NOT_EXIST|FILE_FAIL_IF_NOT_EXIST))
  186. /* share types */
  187. #define STYPE_DISKTREE 0 /* Disk drive */
  188. #define STYPE_PRINTQ 1 /* Spooler queue */
  189. #define STYPE_DEVICE 2 /* Serial device */
  190. #define STYPE_IPC 3 /* Interprocess communication (IPC) */
  191. #define STYPE_HIDDEN 0x80000000 /* share is a hidden one (ends with $) */
  192. /* SMB X/Open error codes for the ERRDOS error class */
  193. #define ERRbadfunc 1 /* Invalid function (or system call) */
  194. #define ERRbadfile 2 /* File not found (pathname error) */
  195. #define ERRbadpath 3 /* Directory not found */
  196. #define ERRnofids 4 /* Too many open files */
  197. #define ERRnoaccess 5 /* Access denied */
  198. #define ERRbadfid 6 /* Invalid fid */
  199. #define ERRnomem 8 /* Out of memory */
  200. #define ERRbadmem 9 /* Invalid memory block address */
  201. #define ERRbadenv 10 /* Invalid environment */
  202. #define ERRbadaccess 12 /* Invalid open mode */
  203. #define ERRbaddata 13 /* Invalid data (only from ioctl call) */
  204. #define ERRres 14 /* reserved */
  205. #define ERRbaddrive 15 /* Invalid drive */
  206. #define ERRremcd 16 /* Attempt to delete current directory */
  207. #define ERRdiffdevice 17 /* rename/move across different filesystems */
  208. #define ERRnofiles 18 /* no more files found in file search */
  209. #define ERRbadshare 32 /* Share mode on file conflict with open mode */
  210. #define ERRlock 33 /* Lock request conflicts with existing lock */
  211. #define ERRunsup 50 /* Request unsupported, returned by Win 95, RJS 20Jun98 */
  212. #define ERRfilexists 80 /* File in operation already exists */
  213. #define ERRcannotopen 110 /* Cannot open the file specified */
  214. #define ERRunknownlevel 124
  215. #define ERRrename 183
  216. #define ERRbadpipe 230 /* Named pipe invalid */
  217. #define ERRpipebusy 231 /* All instances of pipe are busy */
  218. #define ERRpipeclosing 232 /* named pipe close in progress */
  219. #define ERRnotconnected 233 /* No process on other end of named pipe */
  220. #define ERRmoredata 234 /* More data to be returned */
  221. #define ERRbaddirectory 267 /* Invalid directory name in a path. */
  222. #define ERROR_EAS_DIDNT_FIT 275 /* Extended attributes didn't fit */
  223. #define ERROR_EAS_NOT_SUPPORTED 282 /* Extended attributes not supported */
  224. #define ERROR_NOTIFY_ENUM_DIR 1022 /* Buffer too small to return change notify. */
  225. #define ERRunknownipc 2142
  226. /* here's a special one from observing NT */
  227. #define ERRnoipc 66 /* don't support ipc */
  228. /* Error codes for the ERRSRV class */
  229. #define ERRerror 1 /* Non specific error code */
  230. #define ERRbadpw 2 /* Bad password */
  231. #define ERRbadtype 3 /* reserved */
  232. #define ERRaccess 4 /* No permissions to do the requested operation */
  233. #define ERRinvnid 5 /* tid invalid */
  234. #define ERRinvnetname 6 /* Invalid servername */
  235. #define ERRinvdevice 7 /* Invalid device */
  236. #define ERRqfull 49 /* Print queue full */
  237. #define ERRqtoobig 50 /* Queued item too big */
  238. #define ERRinvpfid 52 /* Invalid print file in smb_fid */
  239. #define ERRsmbcmd 64 /* Unrecognised command */
  240. #define ERRsrverror 65 /* smb server internal error */
  241. #define ERRfilespecs 67 /* fid and pathname invalid combination */
  242. #define ERRbadlink 68 /* reserved */
  243. #define ERRbadpermits 69 /* Access specified for a file is not valid */
  244. #define ERRbadpid 70 /* reserved */
  245. #define ERRsetattrmode 71 /* attribute mode invalid */
  246. #define ERRpaused 81 /* Message server paused */
  247. #define ERRmsgoff 82 /* Not receiving messages */
  248. #define ERRnoroom 83 /* No room for message */
  249. #define ERRrmuns 87 /* too many remote usernames */
  250. #define ERRtimeout 88 /* operation timed out */
  251. #define ERRnoresource 89 /* No resources currently available for request. */
  252. #define ERRtoomanyuids 90 /* too many userids */
  253. #define ERRbaduid 91 /* bad userid */
  254. #define ERRuseMPX 250 /* temporarily unable to use raw mode, use MPX mode */
  255. #define ERRuseSTD 251 /* temporarily unable to use raw mode, use standard mode */
  256. #define ERRcontMPX 252 /* resume MPX mode */
  257. #define ERRbadPW /* reserved */
  258. #define ERRnosupport 0xFFFF
  259. #define ERRunknownsmb 22 /* from NT 3.5 response */
  260. /* Error codes for the ERRHRD class */
  261. #define ERRnowrite 19 /* read only media */
  262. #define ERRbadunit 20 /* Unknown device */
  263. #define ERRnotready 21 /* Drive not ready */
  264. #define ERRbadcmd 22 /* Unknown command */
  265. #define ERRdata 23 /* Data (CRC) error */
  266. #define ERRbadreq 24 /* Bad request structure length */
  267. #define ERRseek 25
  268. #define ERRbadmedia 26
  269. #define ERRbadsector 27
  270. #define ERRnopaper 28
  271. #define ERRwrite 29 /* write fault */
  272. #define ERRread 30 /* read fault */
  273. #define ERRgeneral 31 /* General hardware failure */
  274. #define ERRwrongdisk 34
  275. #define ERRFCBunavail 35
  276. #define ERRsharebufexc 36 /* share buffer exceeded */
  277. #define ERRdiskfull 39
  278. typedef char pstring[1024];
  279. typedef char fstring[128];
  280. /* pipe string names */
  281. #define PIPE_LANMAN "\\PIPE\\LANMAN"
  282. #define PIPE_SRVSVC "\\PIPE\\srvsvc"
  283. #define PIPE_SAMR "\\PIPE\\samr"
  284. #define PIPE_WINREG "\\PIPE\\winreg"
  285. #define PIPE_WKSSVC "\\PIPE\\wkssvc"
  286. #define PIPE_NETLOGON "\\PIPE\\NETLOGON"
  287. #define PIPE_NTLSA "\\PIPE\\ntlsa"
  288. #define PIPE_NTSVCS "\\PIPE\\ntsvcs"
  289. #define PIPE_LSASS "\\PIPE\\lsass"
  290. #define PIPE_LSARPC "\\PIPE\\lsarpc"
  291. /* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
  292. typedef struct nttime_info
  293. {
  294. uint32 low;
  295. uint32 high;
  296. } NTTIME;
  297. /* Allowable account control bits */
  298. #define ACB_DISABLED 0x0001 /* 1 = User account disabled */
  299. #define ACB_HOMDIRREQ 0x0002 /* 1 = Home directory required */
  300. #define ACB_PWNOTREQ 0x0004 /* 1 = User password not required */
  301. #define ACB_TEMPDUP 0x0008 /* 1 = Temporary duplicate account */
  302. #define ACB_NORMAL 0x0010 /* 1 = Normal user account */
  303. #define ACB_MNS 0x0020 /* 1 = MNS logon user account */
  304. #define ACB_DOMTRUST 0x0040 /* 1 = Interdomain trust account */
  305. #define ACB_WSTRUST 0x0080 /* 1 = Workstation trust account */
  306. #define ACB_SVRTRUST 0x0100 /* 1 = Server trust account */
  307. #define ACB_PWNOEXP 0x0200 /* 1 = User password does not expire */
  308. #define ACB_AUTOLOCK 0x0400 /* 1 = Account auto locked */
  309. #define MAX_HOURS_LEN 32
  310. struct sam_passwd
  311. {
  312. time_t logon_time; /* logon time */
  313. time_t logoff_time; /* logoff time */
  314. time_t kickoff_time; /* kickoff time */
  315. time_t pass_last_set_time; /* password last set time */
  316. time_t pass_can_change_time; /* password can change time */
  317. time_t pass_must_change_time; /* password must change time */
  318. char *smb_name; /* username string */
  319. char *full_name; /* user's full name string */
  320. char *home_dir; /* home directory string */
  321. char *dir_drive; /* home directory drive string */
  322. char *logon_script; /* logon script string */
  323. char *profile_path; /* profile path string */
  324. char *acct_desc ; /* user description string */
  325. char *workstations; /* login from workstations string */
  326. char *unknown_str ; /* don't know what this is, yet. */
  327. char *munged_dial ; /* munged path name and dial-back tel number */
  328. uid_t smb_userid; /* this is actually the unix uid_t */
  329. gid_t smb_grpid; /* this is actually the unix gid_t */
  330. uint32 user_rid; /* Primary User ID */
  331. uint32 group_rid; /* Primary Group ID */
  332. unsigned char *smb_passwd; /* Null if no password */
  333. unsigned char *smb_nt_passwd; /* Null if no password */
  334. uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
  335. uint32 unknown_3; /* 0x00ff ffff */
  336. uint16 logon_divs; /* 168 - number of hours in a week */
  337. uint32 hours_len; /* normally 21 bytes */
  338. uint8 hours[MAX_HOURS_LEN];
  339. uint32 unknown_5; /* 0x0002 0000 */
  340. uint32 unknown_6; /* 0x0000 04ec */
  341. };
  342. struct smb_passwd
  343. {
  344. uid_t smb_userid; /* this is actually the unix uid_t */
  345. char *smb_name; /* username string */
  346. unsigned char *smb_passwd; /* Null if no password */
  347. unsigned char *smb_nt_passwd; /* Null if no password */
  348. uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
  349. time_t pass_last_set_time; /* password last set time */
  350. };
  351. struct sam_disp_info
  352. {
  353. uint32 user_rid; /* Primary User ID */
  354. char *smb_name; /* username string */
  355. char *full_name; /* user's full name string */
  356. };
  357. #define MAXSUBAUTHS 15 /* max sub authorities in a SID */
  358. /* DOM_SID - security id */
  359. typedef struct sid_info
  360. {
  361. uint8 sid_rev_num; /* SID revision number */
  362. uint8 num_auths; /* number of sub-authorities */
  363. uint8 id_auth[6]; /* Identifier Authority */
  364. /*
  365. * Note that the values in these uint32's are in *native* byteorder,
  366. * not neccessarily little-endian...... JRA.
  367. */
  368. uint32 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */
  369. } DOM_SID;
  370. /*** query a local group, get a list of these: shows who is in that group ***/
  371. /* local group member info */
  372. typedef struct local_grp_member_info
  373. {
  374. DOM_SID sid ; /* matches with name */
  375. uint8 sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */
  376. fstring name ; /* matches with sid: must be of the form "DOMAIN\account" */
  377. } LOCAL_GRP_MEMBER;
  378. /* enumerate these to get list of local groups */
  379. /* local group info */
  380. typedef struct local_grp_info
  381. {
  382. fstring name;
  383. fstring comment;
  384. } LOCAL_GRP;
  385. /*** enumerate these to get list of domain groups ***/
  386. /* domain group member info */
  387. typedef struct domain_grp_info
  388. {
  389. fstring name;
  390. fstring comment;
  391. uint32 rid; /* group rid */
  392. uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
  393. } DOMAIN_GRP;
  394. /*** query a domain group, get a list of these: shows who is in that group ***/
  395. /* domain group info */
  396. typedef struct domain_grp_member_info
  397. {
  398. fstring name;
  399. uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */
  400. } DOMAIN_GRP_MEMBER;
  401. /* DOM_CHAL - challenge info */
  402. typedef struct chal_info
  403. {
  404. uchar data[8]; /* credentials */
  405. } DOM_CHAL;
  406. /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
  407. typedef struct time_info
  408. {
  409. uint32 time;
  410. } UTIME;
  411. /* DOM_CREDs - timestamped client or server credentials */
  412. typedef struct cred_info
  413. {
  414. DOM_CHAL challenge; /* credentials */
  415. UTIME timestamp; /* credential time-stamp */
  416. } DOM_CRED;
  417. /* Structure used when SMBwritebmpx is active */
  418. typedef struct
  419. {
  420. size_t wr_total_written; /* So we know when to discard this */
  421. int32 wr_timeout;
  422. int32 wr_errclass;
  423. int32 wr_error; /* Cached errors */
  424. BOOL wr_mode; /* write through mode) */
  425. BOOL wr_discard; /* discard all further data */
  426. } write_bmpx_struct;
  427. /*
  428. * Structure used to indirect fd's from the files_struct.
  429. * Needed as POSIX locking is based on file and process, not
  430. * file descriptor and process.
  431. */
  432. typedef struct file_fd_struct
  433. {
  434. struct file_fd_struct *next, *prev;
  435. uint16 ref_count;
  436. uint16 uid_cache_count;
  437. uid_t uid_users_cache[10];
  438. SMB_DEV_T dev;
  439. SMB_INO_T inode;
  440. int fd;
  441. int fd_readonly;
  442. int fd_writeonly;
  443. int real_open_flags;
  444. BOOL delete_on_close;
  445. } file_fd_struct;
  446. /*
  447. * Structure used to keep directory state information around.
  448. * Used in NT change-notify code.
  449. */
  450. typedef struct
  451. {
  452. time_t modify_time;
  453. time_t status_time;
  454. } dir_status_struct;
  455. struct uid_cache {
  456. int entries;
  457. uid_t list[UID_CACHE_SIZE];
  458. };
  459. typedef struct
  460. {
  461. char *name;
  462. BOOL is_wild;
  463. } name_compare_entry;
  464. typedef struct connection_struct
  465. {
  466. struct connection_struct *next, *prev;
  467. unsigned cnum; /* an index passed over the wire */
  468. int service;
  469. BOOL force_user;
  470. struct uid_cache uid_cache;
  471. void *dirptr;
  472. BOOL printer;
  473. BOOL ipc;
  474. BOOL read_only;
  475. BOOL admin_user;
  476. char *dirpath;
  477. char *connectpath;
  478. char *origpath;
  479. char *user; /* name of user who *opened* this connection */
  480. uid_t uid; /* uid of user who *opened* this connection */
  481. gid_t gid; /* gid of user who *opened* this connection */
  482. uint16 vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
  483. /* following groups stuff added by ih */
  484. /* This groups info is valid for the user that *opened* the connection */
  485. int ngroups;
  486. gid_t *groups;
  487. time_t lastused;
  488. BOOL used;
  489. int num_files_open;
  490. name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
  491. name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
  492. name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */
  493. } connection_struct;
  494. struct current_user
  495. {
  496. connection_struct *conn;
  497. uint16 vuid;
  498. uid_t uid;
  499. gid_t gid;
  500. int ngroups;
  501. gid_t *groups;
  502. };
  503. typedef struct files_struct
  504. {
  505. struct files_struct *next, *prev;
  506. int fnum;
  507. connection_struct *conn;
  508. file_fd_struct *fd_ptr;
  509. SMB_OFF_T pos;
  510. SMB_OFF_T size;
  511. mode_t mode;
  512. uint16 vuid;
  513. char *mmap_ptr;
  514. SMB_OFF_T mmap_size;
  515. write_bmpx_struct *wbmpx_ptr;
  516. struct timeval open_time;
  517. int share_mode;
  518. time_t pending_modtime;
  519. BOOL open;
  520. BOOL can_lock;
  521. BOOL can_read;
  522. BOOL can_write;
  523. BOOL print_file;
  524. BOOL modified;
  525. BOOL granted_oplock;
  526. BOOL sent_oplock_break;
  527. BOOL is_directory;
  528. BOOL directory_delete_on_close;
  529. BOOL stat_open;
  530. char *fsp_name;
  531. } files_struct;
  532. /* Domain controller authentication protocol info */
  533. struct dcinfo
  534. {
  535. DOM_CHAL clnt_chal; /* Initial challenge received from client */
  536. DOM_CHAL srv_chal; /* Initial server challenge */
  537. DOM_CRED clnt_cred; /* Last client credential */
  538. DOM_CRED srv_cred; /* Last server credential */
  539. uchar sess_key[8]; /* Session key */
  540. uchar md4pw[16]; /* md4(machine password) */
  541. };
  542. typedef struct
  543. {
  544. uid_t uid; /* uid of a validated user */
  545. gid_t gid; /* gid of a validated user */
  546. fstring requested_name; /* user name from the client */
  547. fstring name; /* unix user name of a validated user */
  548. fstring real_name; /* to store real name from password file - simeon */
  549. BOOL guest;
  550. /* following groups stuff added by ih */
  551. /* This groups info is needed for when we become_user() for this uid */
  552. int n_groups;
  553. gid_t *groups;
  554. int n_sids;
  555. int *sids;
  556. /* per-user authentication information on NT RPCs */
  557. struct dcinfo dc;
  558. } user_struct;
  559. enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
  560. typedef struct
  561. {
  562. int job;
  563. int size;
  564. int status;
  565. int priority;
  566. time_t time;
  567. char user[30];
  568. char file[100];
  569. } print_queue_struct;
  570. enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
  571. typedef struct
  572. {
  573. fstring message;
  574. int status;
  575. } print_status_struct;
  576. /* used for server information: client, nameserv and ipc */
  577. struct server_info_struct
  578. {
  579. fstring name;
  580. uint32 type;
  581. fstring comment;
  582. fstring domain; /* used ONLY in ipc.c NOT namework.c */
  583. BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
  584. };
  585. /* used for network interfaces */
  586. struct interface
  587. {
  588. struct interface *next;
  589. struct in_addr ip;
  590. struct in_addr bcast;
  591. struct in_addr nmask;
  592. };
  593. /* struct returned by get_share_modes */
  594. typedef struct
  595. {
  596. int pid;
  597. uint16 op_port;
  598. uint16 op_type;
  599. int share_mode;
  600. struct timeval time;
  601. } share_mode_entry;
  602. /* each implementation of the share mode code needs
  603. to support the following operations */
  604. struct share_ops {
  605. BOOL (*stop_mgmt)(void);
  606. BOOL (*lock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int *);
  607. BOOL (*unlock_entry)(connection_struct *, SMB_DEV_T , SMB_INO_T , int );
  608. int (*get_entries)(connection_struct *, int , SMB_DEV_T , SMB_INO_T , share_mode_entry **);
  609. void (*del_entry)(int , files_struct *);
  610. BOOL (*set_entry)(int, files_struct *, uint16 , uint16 );
  611. BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
  612. int (*forall)(void (*)(share_mode_entry *, char *));
  613. void (*status)(FILE *);
  614. };
  615. /* each implementation of the shared memory code needs
  616. to support the following operations */
  617. struct shmem_ops {
  618. BOOL (*shm_close)( void );
  619. int (*shm_alloc)(int );
  620. BOOL (*shm_free)(int );
  621. int (*get_userdef_off)(void);
  622. void *(*offset2addr)(int );
  623. int (*addr2offset)(void *addr);
  624. BOOL (*lock_hash_entry)(unsigned int);
  625. BOOL (*unlock_hash_entry)( unsigned int );
  626. BOOL (*get_usage)(int *,int *,int *);
  627. unsigned (*hash_size)(void);
  628. };
  629. /*
  630. * Each implementation of the password database code needs
  631. * to support the following operations.
  632. */
  633. struct passdb_ops {
  634. /*
  635. * Password database ops.
  636. */
  637. void *(*startsmbpwent)(BOOL);
  638. void (*endsmbpwent)(void *);
  639. SMB_BIG_UINT (*getsmbpwpos)(void *);
  640. BOOL (*setsmbpwpos)(void *, SMB_BIG_UINT);
  641. /*
  642. * smb password database query functions.
  643. */
  644. struct smb_passwd *(*getsmbpwnam)(char *);
  645. struct smb_passwd *(*getsmbpwuid)(uid_t);
  646. struct smb_passwd *(*getsmbpwrid)(uint32);
  647. struct smb_passwd *(*getsmbpwent)(void *);
  648. /*
  649. * smb password database modification functions.
  650. */
  651. BOOL (*add_smbpwd_entry)(struct smb_passwd *);
  652. BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL);
  653. /*
  654. * Functions that manipulate a struct sam_passwd.
  655. */
  656. struct sam_passwd *(*getsam21pwent)(void *);
  657. /*
  658. * sam password database query functions.
  659. */
  660. struct sam_passwd *(*getsam21pwnam)(char *);
  661. struct sam_passwd *(*getsam21pwuid)(uid_t);
  662. struct sam_passwd *(*getsam21pwrid)(uint32);
  663. /*
  664. * sam password database modification functions.
  665. */
  666. BOOL (*add_sam21pwd_entry)(struct sam_passwd *);
  667. BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL);
  668. /*
  669. * sam query display info functions.
  670. */
  671. struct sam_disp_info *(*getsamdispnam)(char *);
  672. struct sam_disp_info *(*getsamdisprid)(uint32);
  673. struct sam_disp_info *(*getsamdispent)(void *);
  674. #if 0
  675. /*
  676. * password checking functions
  677. */
  678. struct smb_passwd *(*smb_password_chal )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
  679. struct smb_passwd *(*smb_password_check )(char *username, char lm_hash[16], char nt_hash[16]);
  680. struct passwd *(*unix_password_check)(char *username, char *pass, int pass_len);
  681. #endif
  682. };
  683. /* this is used for smbstatus */
  684. struct connect_record
  685. {
  686. int magic;
  687. int pid;
  688. int cnum;
  689. uid_t uid;
  690. gid_t gid;
  691. char name[24];
  692. char addr[24];
  693. char machine[128];
  694. time_t start;
  695. };
  696. /* This is used by smbclient to send it to a smbfs mount point */
  697. struct connection_options {
  698. int protocol;
  699. /* Connection-Options */
  700. uint32 max_xmit;
  701. uint16 server_vuid;
  702. uint16 tid;
  703. /* The following are LANMAN 1.0 options */
  704. uint16 sec_mode;
  705. uint16 max_mux;
  706. uint16 max_vcs;
  707. uint16 rawmode;
  708. uint32 sesskey;
  709. /* The following are NT LM 0.12 options */
  710. uint32 maxraw;
  711. uint32 capabilities;
  712. uint16 serverzone;
  713. };
  714. /* the following are used by loadparm for option lists */
  715. typedef enum
  716. {
  717. P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
  718. P_STRING,P_USTRING,P_GSTRING,P_UGSTRING,P_ENUM,P_SEP
  719. } parm_type;
  720. typedef enum
  721. {
  722. P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
  723. } parm_class;
  724. struct enum_list {
  725. int value;
  726. const char *name;
  727. };
  728. struct parm_struct
  729. {
  730. const char *label;
  731. parm_type type;
  732. parm_class class;
  733. void *ptr;
  734. BOOL (*special)(const char *, char **);
  735. const struct enum_list *enum_list;
  736. unsigned flags;
  737. union {
  738. BOOL bvalue;
  739. int ivalue;
  740. char *svalue;
  741. char cvalue;
  742. } def;
  743. };
  744. struct bitmap {
  745. uint32 *b;
  746. int n;
  747. };
  748. #define FLAG_BASIC 0x01 /* fundamental options */
  749. #define FLAG_SHARE 0x02 /* file sharing options */
  750. #define FLAG_PRINT 0x04 /* printing options */
  751. #define FLAG_GLOBAL 0x08 /* local options that should be globally settable in SWAT */
  752. #define FLAG_DEPRECATED 0x10 /* options that should no longer be used */
  753. #define FLAG_HIDE 0x20 /* options that should be hidden in SWAT */
  754. #ifndef LOCKING_VERSION
  755. #define LOCKING_VERSION 4
  756. #endif /* LOCKING_VERSION */
  757. /* these are useful macros for checking validity of handles */
  758. #define OPEN_FSP(fsp) ((fsp) && (fsp)->open && !(fsp)->is_directory)
  759. #define OPEN_CONN(conn) ((conn) && (conn)->open)
  760. #define IS_IPC(conn) ((conn) && (conn)->ipc)
  761. #define IS_PRINT(conn) ((conn) && (conn)->printer)
  762. #define FNUM_OK(fsp,c) (OPEN_FSP(fsp) && (c)==(fsp)->conn)
  763. #define CHECK_FSP(fsp,conn) if (!FNUM_OK(fsp,conn)) \
  764. return(ERROR(ERRDOS,ERRbadfid)); \
  765. else if((fsp)->fd_ptr == NULL) \
  766. return(ERROR(ERRDOS,ERRbadaccess))
  767. #define CHECK_READ(fsp) if (!(fsp)->can_read) \
  768. return(ERROR(ERRDOS,ERRbadaccess))
  769. #define CHECK_WRITE(fsp) if (!(fsp)->can_write) \
  770. return(ERROR(ERRDOS,ERRbadaccess))
  771. #define CHECK_ERROR(fsp) if (HAS_CACHED_ERROR(fsp)) \
  772. return(CACHED_ERROR(fsp))
  773. /* translates a connection number into a service number */
  774. #define SNUM(conn) ((conn)?(conn)->service:-1)
  775. /* access various service details */
  776. #define SERVICE(snum) (lp_servicename(snum))
  777. #define PRINTCAP (lp_printcapname())
  778. #define PRINTCOMMAND(snum) (lp_printcommand(snum))
  779. #define PRINTERNAME(snum) (lp_printername(snum))
  780. #define CAN_WRITE(conn) (!conn->read_only)
  781. #define VALID_SNUM(snum) (lp_snum_ok(snum))
  782. #define GUEST_OK(snum) (VALID_SNUM(snum) && lp_guest_ok(snum))
  783. #define GUEST_ONLY(snum) (VALID_SNUM(snum) && lp_guest_only(snum))
  784. #define CAN_SETDIR(snum) (!lp_no_set_dir(snum))
  785. #define CAN_PRINT(conn) ((conn) && lp_print_ok((conn)->service))
  786. #define MAP_HIDDEN(conn) ((conn) && lp_map_hidden((conn)->service))
  787. #define MAP_SYSTEM(conn) ((conn) && lp_map_system((conn)->service))
  788. #define MAP_ARCHIVE(conn) ((conn) && lp_map_archive((conn)->service))
  789. #define IS_HIDDEN_PATH(conn,path) ((conn) && is_in_path((path),(conn)->hide_list))
  790. #define IS_VETO_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_list))
  791. #define IS_VETO_OPLOCK_PATH(conn,path) ((conn) && is_in_path((path),(conn)->veto_oplock_list))
  792. /*
  793. * Used by the stat cache code to check if a returned
  794. * stat structure is valid.
  795. */
  796. #define VALID_STAT(st) (st.st_nlink != 0)
  797. #define VALID_STAT_OF_DIR(st) (VALID_STAT(st) && S_ISDIR(st.st_mode))
  798. #define SMBENCRYPT() (lp_encrypted_passwords())
  799. /* the basic packet size, assuming no words or bytes */
  800. #define smb_size 39
  801. /* offsets into message for common items */
  802. #define smb_com 8
  803. #define smb_rcls 9
  804. #define smb_reh 10
  805. #define smb_err 11
  806. #define smb_flg 13
  807. #define smb_flg2 14
  808. #define smb_reb 13
  809. #define smb_tid 28
  810. #define smb_pid 30
  811. #define smb_uid 32
  812. #define smb_mid 34
  813. #define smb_wct 36
  814. #define smb_vwv 37
  815. #define smb_vwv0 37
  816. #define smb_vwv1 39
  817. #define smb_vwv2 41
  818. #define smb_vwv3 43
  819. #define smb_vwv4 45
  820. #define smb_vwv5 47
  821. #define smb_vwv6 49
  822. #define smb_vwv7 51
  823. #define smb_vwv8 53
  824. #define smb_vwv9 55
  825. #define smb_vwv10 57
  826. #define smb_vwv11 59
  827. #define smb_vwv12 61
  828. #define smb_vwv13 63
  829. #define smb_vwv14 65
  830. #define smb_vwv15 67
  831. #define smb_vwv16 69
  832. #define smb_vwv17 71
  833. /* flag defines. CIFS spec 3.1.1 */
  834. #define FLAG_SUPPORT_LOCKREAD 0x01
  835. #define FLAG_CLIENT_BUF_AVAIL 0x02
  836. #define FLAG_RESERVED 0x04
  837. #define FLAG_CASELESS_PATHNAMES 0x08
  838. #define FLAG_CANONICAL_PATHNAMES 0x10
  839. #define FLAG_REQUEST_OPLOCK 0x20
  840. #define FLAG_REQUEST_BATCH_OPLOCK 0x40
  841. #define FLAG_REPLY 0x80
  842. /* the complete */
  843. #define SMBmkdir 0x00 /* create directory */
  844. #define SMBrmdir 0x01 /* delete directory */
  845. #define SMBopen 0x02 /* open file */
  846. #define SMBcreate 0x03 /* create file */
  847. #define SMBclose 0x04 /* close file */
  848. #define SMBflush 0x05 /* flush file */
  849. #define SMBunlink 0x06 /* delete file */
  850. #define SMBmv 0x07 /* rename file */
  851. #define SMBgetatr 0x08 /* get file attributes */
  852. #define SMBsetatr 0x09 /* set file attributes */
  853. #define SMBread 0x0A /* read from file */
  854. #define SMBwrite 0x0B /* write to file */
  855. #define SMBlock 0x0C /* lock byte range */
  856. #define SMBunlock 0x0D /* unlock byte range */
  857. #define SMBctemp 0x0E /* create temporary file */
  858. #define SMBmknew 0x0F /* make new file */
  859. #define SMBchkpth 0x10 /* check directory path */
  860. #define SMBexit 0x11 /* process exit */
  861. #define SMBlseek 0x12 /* seek */
  862. #define SMBtcon 0x70 /* tree connect */
  863. #define SMBtconX 0x75 /* tree connect and X*/
  864. #define SMBtdis 0x71 /* tree disconnect */
  865. #define SMBnegprot 0x72 /* negotiate protocol */
  866. #define SMBdskattr 0x80 /* get disk attributes */
  867. #define SMBsearch 0x81 /* search directory */
  868. #define SMBsplopen 0xC0 /* open print spool file */
  869. #define SMBsplwr 0xC1 /* write to print spool file */
  870. #define SMBsplclose 0xC2 /* close print spool file */
  871. #define SMBsplretq 0xC3 /* return print queue */
  872. #define SMBsends 0xD0 /* send single block message */
  873. #define SMBsendb 0xD1 /* send broadcast message */
  874. #define SMBfwdname 0xD2 /* forward user name */
  875. #define SMBcancelf 0xD3 /* cancel forward */
  876. #define SMBgetmac 0xD4 /* get machine name */
  877. #define SMBsendstrt 0xD5 /* send start of multi-block message */
  878. #define SMBsendend 0xD6 /* send end of multi-block message */
  879. #define SMBsendtxt 0xD7 /* send text of multi-block message */
  880. /* Core+ protocol */
  881. #define SMBlockread 0x13 /* Lock a range and read */
  882. #define SMBwriteunlock 0x14 /* Unlock a range then write */
  883. #define SMBreadbraw 0x1a /* read a block of data with no smb header */
  884. #define SMBwritebraw 0x1d /* write a block of data with no smb header */
  885. #define SMBwritec 0x20 /* secondary write request */
  886. #define SMBwriteclose 0x2c /* write a file then close it */
  887. /* dos extended protocol */
  888. #define SMBreadBraw 0x1A /* read block raw */
  889. #define SMBreadBmpx 0x1B /* read block multiplexed */
  890. #define SMBreadBs 0x1C /* read block (secondary response) */
  891. #define SMBwriteBraw 0x1D /* write block raw */
  892. #define SMBwriteBmpx 0x1E /* write block multiplexed */
  893. #define SMBwriteBs 0x1F /* write block (secondary request) */
  894. #define SMBwriteC 0x20 /* write complete response */
  895. #define SMBsetattrE 0x22 /* set file attributes expanded */
  896. #define SMBgetattrE 0x23 /* get file attributes expanded */
  897. #define SMBlockingX 0x24 /* lock/unlock byte ranges and X */
  898. #define SMBtrans 0x25 /* transaction - name, bytes in/out */
  899. #define SMBtranss 0x26 /* transaction (secondary request/response) */
  900. #define SMBioctl 0x27 /* IOCTL */
  901. #define SMBioctls 0x28 /* IOCTL (secondary request/response) */
  902. #define SMBcopy 0x29 /* copy */
  903. #define SMBmove 0x2A /* move */
  904. #define SMBecho 0x2B /* echo */
  905. #define SMBopenX 0x2D /* open and X */
  906. #define SMBreadX 0x2E /* read and X */
  907. #define SMBwriteX 0x2F /* write and X */
  908. #define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */
  909. #define SMBffirst 0x82 /* find first */
  910. #define SMBfunique 0x83 /* find unique */
  911. #define SMBfclose 0x84 /* find close */
  912. #define SMBinvalid 0xFE /* invalid command */
  913. /* Extended 2.0 protocol */
  914. #define SMBtrans2 0x32 /* TRANS2 protocol set */
  915. #define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */
  916. #define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */
  917. #define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */
  918. #define SMBulogoffX 0x74 /* user logoff */
  919. /* NT SMB extensions. */
  920. #define SMBnttrans 0xA0 /* NT transact */
  921. #define SMBnttranss 0xA1 /* NT transact secondary */
  922. #define SMBntcreateX 0xA2 /* NT create and X */
  923. #define SMBntcancel 0xA4 /* NT cancel */
  924. /* These are the TRANS2 sub commands */
  925. #define TRANSACT2_OPEN 0
  926. #define TRANSACT2_FINDFIRST 1
  927. #define TRANSACT2_FINDNEXT 2
  928. #define TRANSACT2_QFSINFO 3
  929. #define TRANSACT2_SETFSINFO 4
  930. #define TRANSACT2_QPATHINFO 5
  931. #define TRANSACT2_SETPATHINFO 6
  932. #define TRANSACT2_QFILEINFO 7
  933. #define TRANSACT2_SETFILEINFO 8
  934. #define TRANSACT2_FSCTL 9
  935. #define TRANSACT2_IOCTL 0xA
  936. #define TRANSACT2_FINDNOTIFYFIRST 0xB
  937. #define TRANSACT2_FINDNOTIFYNEXT 0xC
  938. #define TRANSACT2_MKDIR 0xD
  939. #define TRANSACT2_SESSION_SETUP 0xE
  940. #define TRANSACT2_GET_DFS_REFERRAL 0x10
  941. #define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11
  942. /* These are the NT transact sub commands. */
  943. #define NT_TRANSACT_CREATE 1
  944. #define NT_TRANSACT_IOCTL 2
  945. #define NT_TRANSACT_SET_SECURITY_DESC 3
  946. #define NT_TRANSACT_NOTIFY_CHANGE 4
  947. #define NT_TRANSACT_RENAME 5
  948. #define NT_TRANSACT_QUERY_SECURITY_DESC 6
  949. /* these are the trans2 sub fields for primary requests */
  950. #define smb_tpscnt smb_vwv0
  951. #define smb_tdscnt smb_vwv1
  952. #define smb_mprcnt smb_vwv2
  953. #define smb_mdrcnt smb_vwv3
  954. #define smb_msrcnt smb_vwv4
  955. #define smb_flags smb_vwv5
  956. #define smb_timeout smb_vwv6
  957. #define smb_pscnt smb_vwv9
  958. #define smb_psoff smb_vwv10
  959. #define smb_dscnt smb_vwv11
  960. #define smb_dsoff smb_vwv12
  961. #define smb_suwcnt smb_vwv13
  962. #define smb_setup smb_vwv14
  963. #define smb_setup0 smb_setup
  964. #define smb_setup1 (smb_setup+2)
  965. #define smb_setup2 (smb_setup+4)
  966. /* these are for the secondary requests */
  967. #define smb_spscnt smb_vwv2
  968. #define smb_spsoff smb_vwv3
  969. #define smb_spsdisp smb_vwv4
  970. #define smb_sdscnt smb_vwv5
  971. #define smb_sdsoff smb_vwv6
  972. #define smb_sdsdisp smb_vwv7
  973. #define smb_sfid smb_vwv8
  974. /* and these for responses */
  975. #define smb_tprcnt smb_vwv0
  976. #define smb_tdrcnt smb_vwv1
  977. #define smb_prcnt smb_vwv3
  978. #define smb_proff smb_vwv4
  979. #define smb_prdisp smb_vwv5
  980. #define smb_drcnt smb_vwv6
  981. #define smb_droff smb_vwv7
  982. #define smb_drdisp smb_vwv8
  983. /* these are for the NT trans primary request. */
  984. #define smb_nt_MaxSetupCount smb_vwv0
  985. #define smb_nt_Flags (smb_vwv0 + 1)
  986. #define smb_nt_TotalParameterCount (smb_vwv0 + 3)
  987. #define smb_nt_TotalDataCount (smb_vwv0 + 7)
  988. #define smb_nt_MaxParameterCount (smb_vwv0 + 11)
  989. #define smb_nt_MaxDataCount (smb_vwv0 + 15)
  990. #define smb_nt_ParameterCount (smb_vwv0 + 19)
  991. #define smb_nt_ParameterOffset (smb_vwv0 + 23)
  992. #define smb_nt_DataCount (smb_vwv0 + 27)
  993. #define smb_nt_DataOffset (smb_vwv0 + 31)
  994. #define smb_nt_SetupCount (smb_vwv0 + 35)
  995. #define smb_nt_Function (smb_vwv0 + 36)
  996. #define smb_nt_SetupStart (smb_vwv0 + 38)
  997. /* these are for the NT trans secondary request. */
  998. #define smb_nts_TotalParameterCount (smb_vwv0 + 3)
  999. #define smb_nts_TotalDataCount (smb_vwv0 + 7)
  1000. #define smb_nts_ParameterCount (smb_vwv0 + 11)
  1001. #define smb_nts_ParameterOffset (smb_vwv0 + 15)
  1002. #define smb_nts_ParameterDisplacement (smb_vwv0 + 19)
  1003. #define smb_nts_DataCount (smb_vwv0 + 23)
  1004. #define smb_nts_DataOffset (smb_vwv0 + 27)
  1005. #define smb_nts_DataDisplacement (smb_vwv0 + 31)
  1006. /* these are for the NT trans reply. */
  1007. #define smb_ntr_TotalParameterCount (smb_vwv0 + 3)
  1008. #define smb_ntr_TotalDataCount (smb_vwv0 + 7)
  1009. #define smb_ntr_ParameterCount (smb_vwv0 + 11)
  1010. #define smb_ntr_ParameterOffset (smb_vwv0 + 15)
  1011. #define smb_ntr_ParameterDisplacement (smb_vwv0 + 19)
  1012. #define smb_ntr_DataCount (smb_vwv0 + 23)
  1013. #define smb_ntr_DataOffset (smb_vwv0 + 27)
  1014. #define smb_ntr_DataDisplacement (smb_vwv0 + 31)
  1015. /* these are for the NT create_and_X */
  1016. #define smb_ntcreate_NameLength (smb_vwv0 + 5)
  1017. #define smb_ntcreate_Flags (smb_vwv0 + 7)
  1018. #define smb_ntcreate_RootDirectoryFid (smb_vwv0 + 11)
  1019. #define smb_ntcreate_DesiredAccess (smb_vwv0 + 15)
  1020. #define smb_ntcreate_AllocationSize (smb_vwv0 + 19)
  1021. #define smb_ntcreate_FileAttributes (smb_vwv0 + 27)
  1022. #define smb_ntcreate_ShareAccess (smb_vwv0 + 31)
  1023. #define smb_ntcreate_CreateDisposition (smb_vwv0 + 35)
  1024. #define smb_ntcreate_CreateOptions (smb_vwv0 + 39)
  1025. #define smb_ntcreate_ImpersonationLevel (smb_vwv0 + 43)
  1026. #define smb_ntcreate_SecurityFlags (smb_vwv0 + 47)
  1027. /* this is used on a TConX. I'm not sure the name is very helpful though */
  1028. #define SMB_SUPPORT_SEARCH_BITS 0x0001
  1029. /* these are the constants used in the above call. */
  1030. /* DesiredAccess */
  1031. /* File Specific access rights. */
  1032. #define FILE_READ_DATA 0x001
  1033. #define FILE_WRITE_DATA 0x002
  1034. #define FILE_APPEND_DATA 0x004
  1035. #define FILE_READ_EA 0x008
  1036. #define FILE_WRITE_EA 0x010
  1037. #define FILE_EXECUTE 0x020
  1038. #define FILE_DELETE_CHILD 0x040
  1039. #define FILE_READ_ATTRIBUTES 0x080
  1040. #define FILE_WRITE_ATTRIBUTES 0x100
  1041. #define FILE_ALL_ATTRIBUTES 0x1FF
  1042. /* Generic access masks & rights. */
  1043. #define SPECIFIC_RIGHTS_MASK 0x00FFFFL
  1044. #define STANDARD_RIGHTS_MASK 0xFF0000L
  1045. #define DELETE_ACCESS (1L<<16)
  1046. #define READ_CONTROL_ACCESS (1L<<17)
  1047. #define WRITE_DAC_ACCESS (1L<<18)
  1048. #define WRITE_OWNER_ACCESS (1L<<19)
  1049. #define SYNCHRONIZE_ACCESS (1L<<20)
  1050. #define SYSTEM_SECURITY_ACCESS (1L<<24)
  1051. #define GENERIC_ALL_ACCESS (1<<28)
  1052. #define GENERIC_EXECUTE_ACCESS (1<<29)
  1053. #define GENERIC_WRITE_ACCESS (1<<30)
  1054. #define GENERIC_READ_ACCESS (1<<31)
  1055. #define FILE_ALL_STANDARD_ACCESS 0x1F0000
  1056. /* Mapping of access rights to UNIX perms. */
  1057. #if 0 /* Don't use all here... JRA. */
  1058. #define UNIX_ACCESS_RWX (FILE_ALL_ATTRIBUTES|FILE_ALL_STANDARD_ACCESS)
  1059. #else
  1060. #define UNIX_ACCESS_RWX (UNIX_ACCESS_R|UNIX_ACCESS_W|UNIX_ACCESS_X)
  1061. #endif
  1062. #define UNIX_ACCESS_R (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
  1063. FILE_READ_ATTRIBUTES|FILE_READ_EA|FILE_READ_DATA)
  1064. #define UNIX_ACCESS_W (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
  1065. FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|\
  1066. FILE_APPEND_DATA|FILE_WRITE_DATA)
  1067. #define UNIX_ACCESS_X (READ_CONTROL_ACCESS|SYNCHRONIZE_ACCESS|\
  1068. FILE_EXECUTE|FILE_READ_ATTRIBUTES)
  1069. #define UNIX_ACCESS_NONE (WRITE_OWNER_ACCESS)
  1070. /* Flags field. */
  1071. #define REQUEST_OPLOCK 2
  1072. #define REQUEST_BATCH_OPLOCK 4
  1073. #define OPEN_DIRECTORY 8
  1074. /* ShareAccess field. */
  1075. #define FILE_SHARE_NONE 0 /* Cannot be used in bitmask. */
  1076. #define FILE_SHARE_READ 1
  1077. #define FILE_SHARE_WRITE 2
  1078. #define FILE_SHARE_DELETE 4
  1079. /* FileAttributesField */
  1080. #define FILE_ATTRIBUTE_READONLY aRONLY
  1081. #define FILE_ATTRIBUTE_HIDDEN aHIDDEN
  1082. #define FILE_ATTRIBUTE_SYSTEM aSYSTEM
  1083. #define FILE_ATTRIBUTE_DIRECTORY aDIR
  1084. #define FILE_ATTRIBUTE_ARCHIVE aARCH
  1085. #define FILE_ATTRIBUTE_NORMAL 0x80L
  1086. #define FILE_ATTRIBUTE_TEMPORARY 0x100L
  1087. #define FILE_ATTRIBUTE_COMPRESSED 0x800L
  1088. #define SAMBA_ATTRIBUTES_MASK 0x7F
  1089. /* Flags - combined with attributes. */
  1090. #define FILE_FLAG_WRITE_THROUGH 0x80000000L
  1091. #define FILE_FLAG_NO_BUFFERING 0x20000000L
  1092. #define FILE_FLAG_RANDOM_ACCESS 0x10000000L
  1093. #define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000L
  1094. #define FILE_FLAG_DELETE_ON_CLOSE 0x04000000L
  1095. #define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
  1096. #define FILE_FLAG_POSIX_SEMANTICS 0x01000000L
  1097. /* CreateDisposition field. */
  1098. #define FILE_SUPERSEDE 0
  1099. #define FILE_OPEN 1
  1100. #define FILE_CREATE 2
  1101. #define FILE_OPEN_IF 3
  1102. #define FILE_OVERWRITE 4
  1103. #define FILE_OVERWRITE_IF 5
  1104. /* CreateOptions field. */
  1105. #define FILE_DIRECTORY_FILE 0x0001
  1106. #define FILE_WRITE_THROUGH 0x0002
  1107. #define FILE_SEQUENTIAL_ONLY 0x0004
  1108. #define FILE_NON_DIRECTORY_FILE 0x0040
  1109. #define FILE_NO_EA_KNOWLEDGE 0x0200
  1110. #define FILE_EIGHT_DOT_THREE_ONLY 0x0400
  1111. #define FILE_RANDOM_ACCESS 0x0800
  1112. #define FILE_DELETE_ON_CLOSE 0x1000
  1113. /* Responses when opening a file. */
  1114. #define FILE_WAS_OPENED 1
  1115. #define FILE_WAS_CREATED 2
  1116. #define FILE_WAS_OVERWRITTEN 3
  1117. /* File type flags */
  1118. #define FILE_TYPE_DISK 0
  1119. #define FILE_TYPE_BYTE_MODE_PIPE 1
  1120. #define FILE_TYPE_MESSAGE_MODE_PIPE 2
  1121. #define FILE_TYPE_PRINTER 3
  1122. #define FILE_TYPE_COMM_DEVICE 4
  1123. #define FILE_TYPE_UNKNOWN 0xFFFF
  1124. /* Flag for NT transact rename call. */
  1125. #define RENAME_REPLACE_IF_EXISTS 1
  1126. /* Filesystem Attributes. */
  1127. #define FILE_CASE_SENSITIVE_SEARCH 0x1
  1128. #define FILE_CASE_PRESERVED_NAMES 0x2
  1129. #define FILE_UNICODE_ON_DISK 0x4
  1130. #define FILE_PERSISTENT_ACLS 0x8
  1131. /* ChangeNotify flags. */
  1132. #define FILE_NOTIFY_CHANGE_FILE_NAME 0x001
  1133. #define FILE_NOTIFY_CHANGE_DIR_NAME 0x002
  1134. #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x004
  1135. #define FILE_NOTIFY_CHANGE_SIZE 0x008
  1136. #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x010
  1137. #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x020
  1138. #define FILE_NOTIFY_CHANGE_CREATION 0x040
  1139. #define FILE_NOTIFY_CHANGE_EA 0x080
  1140. #define FILE_NOTIFY_CHANGE_SECURITY 0x100
  1141. /* where to find the base of the SMB packet proper */
  1142. #define smb_base(buf) (((char *)(buf))+4)
  1143. #define SMB_SUCCESS 0 /* The request was successful. */
  1144. #define ERRDOS 0x01 /* Error is from the core DOS operating system set. */
  1145. #define ERRSRV 0x02 /* Error is generated by the server network file manager.*/
  1146. #define ERRHRD 0x03 /* Error is an hardware error. */
  1147. #define ERRCMD 0xFF /* Command was not in the "SMB" format. */
  1148. #ifdef HAVE_STDARG_H
  1149. int slprintf(char *str, int n, const char *format, ...)
  1150. #ifdef __GNUC__
  1151. __attribute__ ((format (printf, 3, 4)))
  1152. #endif
  1153. ;
  1154. #else
  1155. int slprintf();
  1156. #endif
  1157. #ifdef WITH_DFS
  1158. void dfs_unlogin(void);
  1159. extern int dcelogin_atmost_once;
  1160. #endif
  1161. #ifndef MIN
  1162. #define MIN(a,b) ((a)<(b)?(a):(b))
  1163. #endif
  1164. #ifndef MAX
  1165. #define MAX(a,b) ((a)>(b)?(a):(b))
  1166. #endif
  1167. #ifndef ABS
  1168. #define ABS(a) ((a)>0?(a):(-(a)))
  1169. #endif
  1170. #ifndef SIGNAL_CAST
  1171. #define SIGNAL_CAST (RETSIGTYPE (*)(int))
  1172. #endif
  1173. #ifndef SELECT_CAST
  1174. #define SELECT_CAST
  1175. #endif
  1176. /* Some POSIX definitions for those without */
  1177. #ifndef S_IFDIR
  1178. #define S_IFDIR 0x4000
  1179. #endif
  1180. #ifndef S_ISDIR
  1181. #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
  1182. #endif
  1183. #ifndef S_IRWXU
  1184. #define S_IRWXU 00700 /* read, write, execute: owner */
  1185. #endif
  1186. #ifndef S_IRUSR
  1187. #define S_IRUSR 00400 /* read permission: owner */
  1188. #endif
  1189. #ifndef S_IWUSR
  1190. #define S_IWUSR 00200 /* write permission: owner */
  1191. #endif
  1192. #ifndef S_IXUSR
  1193. #define S_IXUSR 00100 /* execute permission: owner */
  1194. #endif
  1195. #ifndef S_IRWXG
  1196. #define S_IRWXG 00070 /* read, write, execute: group */
  1197. #endif
  1198. #ifndef S_IRGRP
  1199. #define S_IRGRP 00040 /* read permission: group */
  1200. #endif
  1201. #ifndef S_IWGRP
  1202. #define S_IWGRP 00020 /* write permission: group */
  1203. #endif
  1204. #ifndef S_IXGRP
  1205. #define S_IXGRP 00010 /* execute permission: group */
  1206. #endif
  1207. #ifndef S_IRWXO
  1208. #define S_IRWXO 00007 /* read, write, execute: other */
  1209. #endif
  1210. #ifndef S_IROTH
  1211. #define S_IROTH 00004 /* read permission: other */
  1212. #endif
  1213. #ifndef S_IWOTH
  1214. #define S_IWOTH 00002 /* write permission: other */
  1215. #endif
  1216. #ifndef S_IXOTH
  1217. #define S_IXOTH 00001 /* execute permission: other */
  1218. #endif
  1219. /* these are used in NetServerEnum to choose what to receive */
  1220. #define SV_TYPE_WORKSTATION 0x00000001
  1221. #define SV_TYPE_SERVER 0x00000002
  1222. #define SV_TYPE_SQLSERVER 0x00000004
  1223. #define SV_TYPE_DOMAIN_CTRL 0x00000008
  1224. #define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
  1225. #define SV_TYPE_TIME_SOURCE 0x00000020
  1226. #define SV_TYPE_AFP 0x00000040
  1227. #define SV_TYPE_NOVELL 0x00000080
  1228. #define SV_TYPE_DOMAIN_MEMBER 0x00000100
  1229. #define SV_TYPE_PRINTQ_SERVER 0x00000200
  1230. #define SV_TYPE_DIALIN_SERVER 0x00000400
  1231. #define SV_TYPE_SERVER_UNIX 0x00000800
  1232. #define SV_TYPE_NT 0x00001000
  1233. #define SV_TYPE_WFW 0x00002000
  1234. #define SV_TYPE_SERVER_MFPN 0x00004000
  1235. #define SV_TYPE_SERVER_NT 0x00008000
  1236. #define SV_TYPE_POTENTIAL_BROWSER 0x00010000
  1237. #define SV_TYPE_BACKUP_BROWSER 0x00020000
  1238. #define SV_TYPE_MASTER_BROWSER 0x00040000
  1239. #define SV_TYPE_DOMAIN_MASTER 0x00080000
  1240. #define SV_TYPE_SERVER_OSF 0x00100000
  1241. #define SV_TYPE_SERVER_VMS 0x00200000
  1242. #define SV_TYPE_WIN95_PLUS 0x00400000
  1243. #define SV_TYPE_ALTERNATE_XPORT 0x20000000
  1244. #define SV_TYPE_LOCAL_LIST_ONLY 0x40000000
  1245. #define SV_TYPE_DOMAIN_ENUM 0x80000000
  1246. #define SV_TYPE_ALL 0xFFFFFFFF
  1247. /* what server type are we currently - JHT Says we ARE 4.20 */
  1248. /* this was set by JHT in liaison with Jeremy Allison early 1997 */
  1249. /* setting to 4.20 at same time as announcing ourselves as NT Server */
  1250. /* History: */
  1251. /* Version 4.0 - never made public */
  1252. /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
  1253. /* - Reappeared in 1.9.16p11 with fixed smbd services */
  1254. /* Version 4.20 - To indicate that nmbd and browsing now works better */
  1255. #define DEFAULT_MAJOR_VERSION 0x04
  1256. #define DEFAULT_MINOR_VERSION 0x02
  1257. /* Browser Election Values */
  1258. #define BROWSER_ELECTION_VERSION 0x010f
  1259. #define BROWSER_CONSTANT 0xaa55
  1260. /* NT Flags2 bits - cifs6.txt section 3.1.2 */
  1261. #define FLAGS2_LONG_PATH_COMPONENTS 0x0001
  1262. #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002
  1263. #define FLAGS2_DFS_PATHNAMES 0x1000
  1264. #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
  1265. #define FLAGS2_32_BIT_ERROR_CODES 0x4000
  1266. #define FLAGS2_UNICODE_STRINGS 0x8000
  1267. /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
  1268. #define CAP_RAW_MODE 0x0001
  1269. #define CAP_MPX_MODE 0x0002
  1270. #define CAP_UNICODE 0x0004
  1271. #define CAP_LARGE_FILES 0x0008
  1272. #define CAP_NT_SMBS 0x0010
  1273. #define CAP_RPC_REMOTE_APIS 0x0020
  1274. #define CAP_STATUS32 0x0040
  1275. #define CAP_LEVEL_II_OPLOCKS 0x0080
  1276. #define CAP_LOCK_AND_READ 0x0100
  1277. #define CAP_NT_FIND 0x0200
  1278. #define CAP_DFS 0x1000
  1279. #define CAP_LARGE_READX 0x4000
  1280. /* protocol types. It assumes that higher protocols include lower protocols
  1281. as subsets */
  1282. enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
  1283. /* security levels */
  1284. enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
  1285. /* printing types */
  1286. enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
  1287. PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
  1288. /* Remote architectures we know about. */
  1289. enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
  1290. /* case handling */
  1291. enum case_handling {CASE_LOWER,CASE_UPPER};
  1292. #ifdef WITH_SSL
  1293. /* SSL version options */
  1294. enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
  1295. #endif /* WITH_SSL */
  1296. /* Macros to get at offsets within smb_lkrng and smb_unlkrng
  1297. structures. We cannot define these as actual structures
  1298. due to possible differences in structure packing
  1299. on different machines/compilers. */
  1300. #define SMB_LPID_OFFSET(indx) (10 * (indx))
  1301. #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
  1302. #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
  1303. #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
  1304. #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
  1305. #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
  1306. #define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
  1307. /* Macro to cache an error in a write_bmpx_struct */
  1308. #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
  1309. w->wr_discard = True, -1)
  1310. /* Macro to test if an error has been cached for this fnum */
  1311. #define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
  1312. (fsp)->wbmpx_ptr->wr_discard)
  1313. /* Macro to turn the cached error into an error packet */
  1314. #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
  1315. /* these are the datagram types */
  1316. #define DGRAM_DIRECT_UNIQUE 0x10
  1317. #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
  1318. /* this is how errors are generated */
  1319. #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
  1320. #define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
  1321. /*
  1322. * Global value meaing that the smb_uid field should be
  1323. * ingored (in share level security and protocol level == CORE)
  1324. */
  1325. #define UID_FIELD_INVALID 0
  1326. #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
  1327. /* Defines needed for multi-codepage support. */
  1328. #define MSDOS_LATIN_1_CODEPAGE 850
  1329. #define KANJI_CODEPAGE 932
  1330. #define HANGUL_CODEPAGE 949
  1331. #define BIG5_CODEPAGE 950
  1332. #define SIMPLIFIED_CHINESE_CODEPAGE 936
  1333. #ifdef KANJI
  1334. /*
  1335. * Default client code page - Japanese
  1336. */
  1337. #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
  1338. #else /* KANJI */
  1339. /*
  1340. * Default client code page - 850 - Western European
  1341. */
  1342. #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
  1343. #endif /* KANJI */
  1344. /*
  1345. * Size of buffer to use when moving files across filesystems.
  1346. */
  1347. #define COPYBUF_SIZE (8*1024)
  1348. /*
  1349. * Integers used to override error codes.
  1350. */
  1351. extern int unix_ERR_class;
  1352. extern int unix_ERR_code;
  1353. /*
  1354. * Map the Core and Extended Oplock requesst bits down
  1355. * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
  1356. */
  1357. /*
  1358. * Core protocol.
  1359. */
  1360. #define CORE_OPLOCK_REQUEST(inbuf) \
  1361. ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
  1362. /*
  1363. * Extended protocol.
  1364. */
  1365. #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
  1366. /* Lock types. */
  1367. #define LOCKING_ANDX_SHARED_LOCK 0x1
  1368. #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
  1369. #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
  1370. #define LOCKING_ANDX_CANCEL_LOCK 0x8
  1371. #define LOCKING_ANDX_LARGE_FILES 0x10
  1372. /* Oplock levels */
  1373. #define OPLOCKLEVEL_NONE 0
  1374. #define OPLOCKLEVEL_II 1
  1375. /*
  1376. * Bits we test with.
  1377. */
  1378. #define EXCLUSIVE_OPLOCK 1
  1379. #define BATCH_OPLOCK 2
  1380. #define CORE_OPLOCK_GRANTED (1<<5)
  1381. #define EXTENDED_OPLOCK_GRANTED (1<<15)
  1382. /*
  1383. * Loopback command offsets.
  1384. */
  1385. #define OPBRK_CMD_LEN_OFFSET 0
  1386. #define OPBRK_CMD_PORT_OFFSET 4
  1387. #define OPBRK_CMD_HEADER_LEN 6
  1388. #define OPBRK_MESSAGE_CMD_OFFSET 0
  1389. /*
  1390. * Oplock break command code to send over the udp socket.
  1391. *
  1392. * Form of this is :
  1393. *
  1394. * 0 2 6 10 14 14+devsize 14+devsize+inodesize
  1395. * +----+--------+--------+--------+-------+--------+
  1396. * | cmd| pid | sec | usec | dev | inode |
  1397. * +----+--------+--------+--------+-------+--------+
  1398. */
  1399. #define OPLOCK_BREAK_CMD 0x1
  1400. #define OPLOCK_BREAK_PID_OFFSET 2
  1401. #define OPLOCK_BREAK_SEC_OFFSET 6
  1402. #define OPLOCK_BREAK_USEC_OFFSET 10
  1403. #define OPLOCK_BREAK_DEV_OFFSET 14
  1404. #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
  1405. #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
  1406. /*
  1407. * Capabilities abstracted for different systems.
  1408. */
  1409. #define KERNEL_OPLOCK_CAPABILITY 0x1
  1410. #if defined(HAVE_KERNEL_OPLOCKS)
  1411. /*
  1412. * Oplock break command code sent via the kernel interface.
  1413. *
  1414. * Form of this is :
  1415. *
  1416. * 0 2 2+devsize 2+devsize+inodesize
  1417. * +----+--------+--------+
  1418. * | cmd| dev | inode |
  1419. * +----+--------+--------+
  1420. */
  1421. #define KERNEL_OPLOCK_BREAK_CMD 0x2
  1422. #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
  1423. #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
  1424. #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
  1425. #endif /* HAVE_KERNEL_OPLOCKS */
  1426. #define CMD_REPLY 0x8000
  1427. /* useful macros */
  1428. /* zero a structure */
  1429. #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
  1430. /* zero a structure given a pointer to the structure - no zero check */
  1431. #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
  1432. /* zero a structure given a pointer to the structure */
  1433. #define ZERO_STRUCTP(x) { if ((x) != NULL) ZERO_STRUCTPN(x); }
  1434. /* zero an array - note that sizeof(array) must work - ie. it must not be a
  1435. pointer */
  1436. #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
  1437. #define SMB_ASSERT(b) ((b)?(void)0: \
  1438. (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
  1439. __FILE__, __LINE__)), smb_panic("assert failed")))
  1440. #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
  1441. /* A netbios name structure. */
  1442. struct nmb_name {
  1443. char name[17];
  1444. char scope[64];
  1445. unsigned int name_type;
  1446. };
  1447. #include "client.h"
  1448. /*
  1449. * Size of new password account encoding string. DO NOT CHANGE.
  1450. */
  1451. #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
  1452. /*
  1453. Do you want session setups at user level security with a invalid
  1454. password to be rejected or allowed in as guest? WinNT rejects them
  1455. but it can be a pain as it means "net view" needs to use a password
  1456. You have 3 choices in the setting of map_to_guest:
  1457. "NEVER_MAP_TO_GUEST" means session setups with an invalid password
  1458. are rejected. This is the default.
  1459. "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
  1460. are rejected, unless the username does not exist, in which case it
  1461. is treated as a guest login
  1462. "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
  1463. are treated as a guest login
  1464. Note that map_to_guest only has an effect in user or server
  1465. level security.
  1466. */
  1467. #define NEVER_MAP_TO_GUEST 0
  1468. #define MAP_TO_GUEST_ON_BAD_USER 1
  1469. #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
  1470. #endif /* _SMB_H */
  1471. /* _SMB_H */