smb.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743
  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. #ifdef NOSTRDUP
  1162. char *strdup(char *s);
  1163. #endif
  1164. #ifndef MIN
  1165. #define MIN(a,b) ((a)<(b)?(a):(b))
  1166. #endif
  1167. #ifndef MAX
  1168. #define MAX(a,b) ((a)>(b)?(a):(b))
  1169. #endif
  1170. #ifndef ABS
  1171. #define ABS(a) ((a)>0?(a):(-(a)))
  1172. #endif
  1173. #ifndef SIGNAL_CAST
  1174. #define SIGNAL_CAST (RETSIGTYPE (*)(int))
  1175. #endif
  1176. #ifndef SELECT_CAST
  1177. #define SELECT_CAST
  1178. #endif
  1179. /* Some POSIX definitions for those without */
  1180. #ifndef S_IFDIR
  1181. #define S_IFDIR 0x4000
  1182. #endif
  1183. #ifndef S_ISDIR
  1184. #define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR)
  1185. #endif
  1186. #ifndef S_IRWXU
  1187. #define S_IRWXU 00700 /* read, write, execute: owner */
  1188. #endif
  1189. #ifndef S_IRUSR
  1190. #define S_IRUSR 00400 /* read permission: owner */
  1191. #endif
  1192. #ifndef S_IWUSR
  1193. #define S_IWUSR 00200 /* write permission: owner */
  1194. #endif
  1195. #ifndef S_IXUSR
  1196. #define S_IXUSR 00100 /* execute permission: owner */
  1197. #endif
  1198. #ifndef S_IRWXG
  1199. #define S_IRWXG 00070 /* read, write, execute: group */
  1200. #endif
  1201. #ifndef S_IRGRP
  1202. #define S_IRGRP 00040 /* read permission: group */
  1203. #endif
  1204. #ifndef S_IWGRP
  1205. #define S_IWGRP 00020 /* write permission: group */
  1206. #endif
  1207. #ifndef S_IXGRP
  1208. #define S_IXGRP 00010 /* execute permission: group */
  1209. #endif
  1210. #ifndef S_IRWXO
  1211. #define S_IRWXO 00007 /* read, write, execute: other */
  1212. #endif
  1213. #ifndef S_IROTH
  1214. #define S_IROTH 00004 /* read permission: other */
  1215. #endif
  1216. #ifndef S_IWOTH
  1217. #define S_IWOTH 00002 /* write permission: other */
  1218. #endif
  1219. #ifndef S_IXOTH
  1220. #define S_IXOTH 00001 /* execute permission: other */
  1221. #endif
  1222. /* these are used in NetServerEnum to choose what to receive */
  1223. #define SV_TYPE_WORKSTATION 0x00000001
  1224. #define SV_TYPE_SERVER 0x00000002
  1225. #define SV_TYPE_SQLSERVER 0x00000004
  1226. #define SV_TYPE_DOMAIN_CTRL 0x00000008
  1227. #define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
  1228. #define SV_TYPE_TIME_SOURCE 0x00000020
  1229. #define SV_TYPE_AFP 0x00000040
  1230. #define SV_TYPE_NOVELL 0x00000080
  1231. #define SV_TYPE_DOMAIN_MEMBER 0x00000100
  1232. #define SV_TYPE_PRINTQ_SERVER 0x00000200
  1233. #define SV_TYPE_DIALIN_SERVER 0x00000400
  1234. #define SV_TYPE_SERVER_UNIX 0x00000800
  1235. #define SV_TYPE_NT 0x00001000
  1236. #define SV_TYPE_WFW 0x00002000
  1237. #define SV_TYPE_SERVER_MFPN 0x00004000
  1238. #define SV_TYPE_SERVER_NT 0x00008000
  1239. #define SV_TYPE_POTENTIAL_BROWSER 0x00010000
  1240. #define SV_TYPE_BACKUP_BROWSER 0x00020000
  1241. #define SV_TYPE_MASTER_BROWSER 0x00040000
  1242. #define SV_TYPE_DOMAIN_MASTER 0x00080000
  1243. #define SV_TYPE_SERVER_OSF 0x00100000
  1244. #define SV_TYPE_SERVER_VMS 0x00200000
  1245. #define SV_TYPE_WIN95_PLUS 0x00400000
  1246. #define SV_TYPE_ALTERNATE_XPORT 0x20000000
  1247. #define SV_TYPE_LOCAL_LIST_ONLY 0x40000000
  1248. #define SV_TYPE_DOMAIN_ENUM 0x80000000
  1249. #define SV_TYPE_ALL 0xFFFFFFFF
  1250. /* what server type are we currently - JHT Says we ARE 4.20 */
  1251. /* this was set by JHT in liaison with Jeremy Allison early 1997 */
  1252. /* setting to 4.20 at same time as announcing ourselves as NT Server */
  1253. /* History: */
  1254. /* Version 4.0 - never made public */
  1255. /* Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 */
  1256. /* - Reappeared in 1.9.16p11 with fixed smbd services */
  1257. /* Version 4.20 - To indicate that nmbd and browsing now works better */
  1258. #define DEFAULT_MAJOR_VERSION 0x04
  1259. #define DEFAULT_MINOR_VERSION 0x02
  1260. /* Browser Election Values */
  1261. #define BROWSER_ELECTION_VERSION 0x010f
  1262. #define BROWSER_CONSTANT 0xaa55
  1263. /* NT Flags2 bits - cifs6.txt section 3.1.2 */
  1264. #define FLAGS2_LONG_PATH_COMPONENTS 0x0001
  1265. #define FLAGS2_EXTENDED_ATTRIBUTES 0x0002
  1266. #define FLAGS2_DFS_PATHNAMES 0x1000
  1267. #define FLAGS2_READ_PERMIT_NO_EXECUTE 0x2000
  1268. #define FLAGS2_32_BIT_ERROR_CODES 0x4000
  1269. #define FLAGS2_UNICODE_STRINGS 0x8000
  1270. /* Capabilities. see ftp.microsoft.com/developr/drg/cifs/cifs/cifs4.txt */
  1271. #define CAP_RAW_MODE 0x0001
  1272. #define CAP_MPX_MODE 0x0002
  1273. #define CAP_UNICODE 0x0004
  1274. #define CAP_LARGE_FILES 0x0008
  1275. #define CAP_NT_SMBS 0x0010
  1276. #define CAP_RPC_REMOTE_APIS 0x0020
  1277. #define CAP_STATUS32 0x0040
  1278. #define CAP_LEVEL_II_OPLOCKS 0x0080
  1279. #define CAP_LOCK_AND_READ 0x0100
  1280. #define CAP_NT_FIND 0x0200
  1281. #define CAP_DFS 0x1000
  1282. #define CAP_LARGE_READX 0x4000
  1283. /* protocol types. It assumes that higher protocols include lower protocols
  1284. as subsets */
  1285. enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
  1286. /* security levels */
  1287. enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
  1288. /* printing types */
  1289. enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
  1290. PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
  1291. /* Remote architectures we know about. */
  1292. enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
  1293. /* case handling */
  1294. enum case_handling {CASE_LOWER,CASE_UPPER};
  1295. #ifdef WITH_SSL
  1296. /* SSL version options */
  1297. enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
  1298. #endif /* WITH_SSL */
  1299. /* Macros to get at offsets within smb_lkrng and smb_unlkrng
  1300. structures. We cannot define these as actual structures
  1301. due to possible differences in structure packing
  1302. on different machines/compilers. */
  1303. #define SMB_LPID_OFFSET(indx) (10 * (indx))
  1304. #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
  1305. #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
  1306. #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
  1307. #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
  1308. #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
  1309. #define SMB_LARGE_LKLEN_OFFSET_LOW(indx) (16 + (20 * (indx)))
  1310. /* Macro to cache an error in a write_bmpx_struct */
  1311. #define CACHE_ERROR(w,c,e) ((w)->wr_errclass = (c), (w)->wr_error = (e), \
  1312. w->wr_discard = True, -1)
  1313. /* Macro to test if an error has been cached for this fnum */
  1314. #define HAS_CACHED_ERROR(fsp) ((fsp)->open && (fsp)->wbmpx_ptr && \
  1315. (fsp)->wbmpx_ptr->wr_discard)
  1316. /* Macro to turn the cached error into an error packet */
  1317. #define CACHED_ERROR(fsp) cached_error_packet(inbuf,outbuf,fsp,__LINE__)
  1318. /* these are the datagram types */
  1319. #define DGRAM_DIRECT_UNIQUE 0x10
  1320. #define ERROR(class,x) error_packet(inbuf,outbuf,class,x,__LINE__)
  1321. /* this is how errors are generated */
  1322. #define UNIXERROR(defclass,deferror) unix_error_packet(inbuf,outbuf,defclass,deferror,__LINE__)
  1323. #define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
  1324. /*
  1325. * Global value meaing that the smb_uid field should be
  1326. * ingored (in share level security and protocol level == CORE)
  1327. */
  1328. #define UID_FIELD_INVALID 0
  1329. #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
  1330. /* Defines needed for multi-codepage support. */
  1331. #define MSDOS_LATIN_1_CODEPAGE 850
  1332. #define KANJI_CODEPAGE 932
  1333. #define HANGUL_CODEPAGE 949
  1334. #define BIG5_CODEPAGE 950
  1335. #define SIMPLIFIED_CHINESE_CODEPAGE 936
  1336. #ifdef KANJI
  1337. /*
  1338. * Default client code page - Japanese
  1339. */
  1340. #define DEFAULT_CLIENT_CODE_PAGE KANJI_CODEPAGE
  1341. #else /* KANJI */
  1342. /*
  1343. * Default client code page - 850 - Western European
  1344. */
  1345. #define DEFAULT_CLIENT_CODE_PAGE MSDOS_LATIN_1_CODEPAGE
  1346. #endif /* KANJI */
  1347. /*
  1348. * Size of buffer to use when moving files across filesystems.
  1349. */
  1350. #define COPYBUF_SIZE (8*1024)
  1351. /*
  1352. * Integers used to override error codes.
  1353. */
  1354. extern int unix_ERR_class;
  1355. extern int unix_ERR_code;
  1356. /*
  1357. * Map the Core and Extended Oplock requesst bits down
  1358. * to common bits (EXCLUSIVE_OPLOCK & BATCH_OPLOCK).
  1359. */
  1360. /*
  1361. * Core protocol.
  1362. */
  1363. #define CORE_OPLOCK_REQUEST(inbuf) \
  1364. ((CVAL(inbuf,smb_flg)&(FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK))>>5)
  1365. /*
  1366. * Extended protocol.
  1367. */
  1368. #define EXTENDED_OPLOCK_REQUEST(inbuf) ((SVAL(inbuf,smb_vwv2)&((1<<1)|(1<<2)))>>1)
  1369. /* Lock types. */
  1370. #define LOCKING_ANDX_SHARED_LOCK 0x1
  1371. #define LOCKING_ANDX_OPLOCK_RELEASE 0x2
  1372. #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x4
  1373. #define LOCKING_ANDX_CANCEL_LOCK 0x8
  1374. #define LOCKING_ANDX_LARGE_FILES 0x10
  1375. /* Oplock levels */
  1376. #define OPLOCKLEVEL_NONE 0
  1377. #define OPLOCKLEVEL_II 1
  1378. /*
  1379. * Bits we test with.
  1380. */
  1381. #define EXCLUSIVE_OPLOCK 1
  1382. #define BATCH_OPLOCK 2
  1383. #define CORE_OPLOCK_GRANTED (1<<5)
  1384. #define EXTENDED_OPLOCK_GRANTED (1<<15)
  1385. /*
  1386. * Loopback command offsets.
  1387. */
  1388. #define OPBRK_CMD_LEN_OFFSET 0
  1389. #define OPBRK_CMD_PORT_OFFSET 4
  1390. #define OPBRK_CMD_HEADER_LEN 6
  1391. #define OPBRK_MESSAGE_CMD_OFFSET 0
  1392. /*
  1393. * Oplock break command code to send over the udp socket.
  1394. *
  1395. * Form of this is :
  1396. *
  1397. * 0 2 6 10 14 14+devsize 14+devsize+inodesize
  1398. * +----+--------+--------+--------+-------+--------+
  1399. * | cmd| pid | sec | usec | dev | inode |
  1400. * +----+--------+--------+--------+-------+--------+
  1401. */
  1402. #define OPLOCK_BREAK_CMD 0x1
  1403. #define OPLOCK_BREAK_PID_OFFSET 2
  1404. #define OPLOCK_BREAK_SEC_OFFSET 6
  1405. #define OPLOCK_BREAK_USEC_OFFSET 10
  1406. #define OPLOCK_BREAK_DEV_OFFSET 14
  1407. #define OPLOCK_BREAK_INODE_OFFSET (OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
  1408. #define OPLOCK_BREAK_MSG_LEN (OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
  1409. /*
  1410. * Capabilities abstracted for different systems.
  1411. */
  1412. #define KERNEL_OPLOCK_CAPABILITY 0x1
  1413. #if defined(HAVE_KERNEL_OPLOCKS)
  1414. /*
  1415. * Oplock break command code sent via the kernel interface.
  1416. *
  1417. * Form of this is :
  1418. *
  1419. * 0 2 2+devsize 2+devsize+inodesize
  1420. * +----+--------+--------+
  1421. * | cmd| dev | inode |
  1422. * +----+--------+--------+
  1423. */
  1424. #define KERNEL_OPLOCK_BREAK_CMD 0x2
  1425. #define KERNEL_OPLOCK_BREAK_DEV_OFFSET 2
  1426. #define KERNEL_OPLOCK_BREAK_INODE_OFFSET (KERNEL_OPLOCK_BREAK_DEV_OFFSET + sizeof(SMB_DEV_T))
  1427. #define KERNEL_OPLOCK_BREAK_MSG_LEN (KERNEL_OPLOCK_BREAK_INODE_OFFSET + sizeof(SMB_INO_T))
  1428. #endif /* HAVE_KERNEL_OPLOCKS */
  1429. #define CMD_REPLY 0x8000
  1430. /* useful macros */
  1431. /* zero a structure */
  1432. #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
  1433. /* zero a structure given a pointer to the structure - no zero check */
  1434. #define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x)))
  1435. /* zero a structure given a pointer to the structure */
  1436. #define ZERO_STRUCTP(x) { if ((x) != NULL) ZERO_STRUCTPN(x); }
  1437. /* zero an array - note that sizeof(array) must work - ie. it must not be a
  1438. pointer */
  1439. #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
  1440. #define SMB_ASSERT(b) ((b)?(void)0: \
  1441. (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
  1442. __FILE__, __LINE__)), smb_panic("assert failed")))
  1443. #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
  1444. /* A netbios name structure. */
  1445. struct nmb_name {
  1446. char name[17];
  1447. char scope[64];
  1448. unsigned int name_type;
  1449. };
  1450. #include "client.h"
  1451. /*
  1452. * Size of new password account encoding string. DO NOT CHANGE.
  1453. */
  1454. #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
  1455. /*
  1456. Do you want session setups at user level security with a invalid
  1457. password to be rejected or allowed in as guest? WinNT rejects them
  1458. but it can be a pain as it means "net view" needs to use a password
  1459. You have 3 choices in the setting of map_to_guest:
  1460. "NEVER_MAP_TO_GUEST" means session setups with an invalid password
  1461. are rejected. This is the default.
  1462. "MAP_TO_GUEST_ON_BAD_USER" means session setups with an invalid password
  1463. are rejected, unless the username does not exist, in which case it
  1464. is treated as a guest login
  1465. "MAP_TO_GUEST_ON_BAD_PASSWORD" means session setups with an invalid password
  1466. are treated as a guest login
  1467. Note that map_to_guest only has an effect in user or server
  1468. level security.
  1469. */
  1470. #define NEVER_MAP_TO_GUEST 0
  1471. #define MAP_TO_GUEST_ON_BAD_USER 1
  1472. #define MAP_TO_GUEST_ON_BAD_PASSWORD 2
  1473. #endif /* _SMB_H */
  1474. /* _SMB_H */