smbdat.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct SmbSession SmbSession;
  10. typedef struct SmbTree SmbTree;
  11. typedef struct SmbService SmbService;
  12. typedef struct SmbPeerInfo SmbPeerInfo;
  13. typedef struct SmbTransaction SmbTransaction;
  14. typedef struct SmbBuffer SmbBuffer;
  15. typedef struct SmbIdMap SmbIdMap;
  16. typedef struct SmbSearch SmbSearch;
  17. typedef struct SmbDirCache SmbDirCache;
  18. typedef struct SmbFile SmbFile;
  19. typedef struct SmbSharedFile SmbSharedFile;
  20. typedef struct SmbCifsSession SmbCifsSession;
  21. typedef struct SmbServerInfo SmbServerInfo;
  22. typedef struct SmbRapServerInfo1 SmbRapServerInfo1;
  23. typedef struct SmbFindFileBothDirectoryInfo SmbFindFileBothDirectoryInfo;
  24. typedef struct SmbLock SmbLock;
  25. typedef struct SmbLockList SmbLockList;
  26. typedef struct SmbSlut SmbSlut;
  27. #pragma incomplete SmbIdMap
  28. #pragma incomplete SmbBuffer
  29. #pragma incomplete SmbLockList
  30. typedef int SMBCIFSWRITEFN(SmbCifsSession *cifs, void *buf, long n);
  31. typedef int SMBCIFSACCEPTFN(SmbCifsSession *cifs, SMBCIFSWRITEFN **fnp);
  32. typedef void SMBIDMAPAPPLYFN(void *magic, void *p);
  33. struct SmbPeerInfo {
  34. uint32_t capabilities;
  35. ushort maxlen;
  36. uchar securitymode;
  37. ushort maxmpxcount;
  38. ushort maxnumbervcs;
  39. uint32_t maxbuffersize;
  40. uint32_t maxrawsize;
  41. uint32_t sessionkey;
  42. vlong utc;
  43. short tzoff;
  44. uchar encryptionkeylength;
  45. uchar *encryptionkey;
  46. char *oemdomainname;
  47. };
  48. struct SmbTransaction {
  49. struct {
  50. char *name;
  51. uint32_t tpcount;
  52. uchar *parameters;
  53. uint32_t pcount;
  54. uint32_t tdcount;
  55. uchar *data;
  56. uint32_t maxpcount;
  57. uint32_t maxdcount;
  58. uint32_t maxscount;
  59. uint32_t dcount;
  60. ushort scount;
  61. ushort *setup;
  62. ushort flags;
  63. } in;
  64. struct {
  65. uint32_t tpcount;
  66. uint32_t tdcount;
  67. SmbBuffer *parameters;
  68. SmbBuffer *data;
  69. ushort *setup;
  70. } out;
  71. };
  72. enum {
  73. SmbSessionNeedNegotiate,
  74. SmbSessionNeedSetup,
  75. SmbSessionEstablished,
  76. };
  77. struct SmbSession {
  78. NbSession *nbss;
  79. SmbCifsSession *cifss;
  80. uchar nextcommand;
  81. SmbBuffer *response;
  82. SmbPeerInfo peerinfo;
  83. Chalstate *cs;
  84. struct {
  85. char *accountname;
  86. char *primarydomain;
  87. char *nativeos;
  88. char *nativelanman;
  89. ushort maxmpxcount;
  90. MSchapreply mschapreply;
  91. } client;
  92. SmbTransaction transaction;
  93. SmbIdMap *fidmap;
  94. SmbIdMap *tidmap;
  95. SmbIdMap *sidmap;
  96. int state;
  97. uchar errclass;
  98. ushort error;
  99. int tzoff; // as passed to client during negotiation
  100. SmbService *serv;
  101. };
  102. typedef struct SmbHeader {
  103. uchar command;
  104. union {
  105. struct {
  106. uchar errclass;
  107. ushort error;
  108. };
  109. uint32_t status;
  110. };
  111. uchar flags;
  112. ushort flags2;
  113. union {
  114. struct {
  115. ushort pidhigh;
  116. uchar securitysignature[8];
  117. };
  118. };
  119. ushort tid;
  120. ushort pid;
  121. ushort uid;
  122. ushort mid;
  123. uchar wordcount;
  124. } SmbHeader;
  125. typedef enum SmbProcessResult {
  126. SmbProcessResultOk,
  127. SmbProcessResultUnimp,
  128. SmbProcessResultFormat,
  129. SmbProcessResultMisc,
  130. SmbProcessResultError,
  131. SmbProcessResultReply,
  132. SmbProcessResultDie,
  133. } SmbProcessResult;
  134. typedef SmbProcessResult SMBPROCESSFN(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *);
  135. typedef struct SmbOpTableEntry SmbOpTableEntry;
  136. struct SmbOpTableEntry {
  137. char *name;
  138. SMBPROCESSFN *process;
  139. int debug;
  140. };
  141. extern SmbOpTableEntry smboptable[256];
  142. typedef struct SmbGlobals SmbGlobals;
  143. extern SmbGlobals smbglobals;
  144. struct SmbServerInfo {
  145. char *name;
  146. char *nativelanman;
  147. uchar vmaj, vmin;
  148. uint32_t stype;
  149. char *remark;
  150. };
  151. struct SmbGlobals {
  152. int maxreceive;
  153. int unicode;
  154. SmbServerInfo serverinfo;
  155. char *nativeos;
  156. char *primarydomain;
  157. NbName nbname;
  158. char *accountname;
  159. char *mailslotbrowse;
  160. char *pipelanman;
  161. int l2sectorsize;
  162. int l2allocationsize;
  163. int convertspace;
  164. struct {
  165. int fd;
  166. int print;
  167. int tids;
  168. int sids;
  169. int fids;
  170. int rap2;
  171. int find;
  172. int query;
  173. int sharedfiles;
  174. int sessions;
  175. int rep;
  176. int poolparanoia;
  177. int locks;
  178. } log;
  179. };
  180. struct SmbTree {
  181. long id;
  182. SmbService *serv;
  183. };
  184. struct SmbService {
  185. Ref;
  186. char *name;
  187. char *type;
  188. ushort stype;
  189. char *path;
  190. char *remark;
  191. SmbService *next;
  192. };
  193. extern SmbService *smbservices;
  194. typedef struct SmbClient SmbClient;
  195. typedef struct SmbTransactionMethod {
  196. int (*encodeprimary)(SmbTransaction *t, SmbHeader *h, SmbPeerInfo *p,
  197. SmbBuffer *ob, uchar *wordcount, ushort *bytecount, char **errmsgp);
  198. int (*encodesecondary)(SmbTransaction *t, SmbHeader *h, SmbBuffer *ob, char **errmsgp);
  199. int (*sendrequest)(void *magic, SmbBuffer *ob, char **errmsgp);
  200. int (*receiveintermediate)(void *magic, uchar *wordcountp, ushort *bytecountp, char **errmsgp);
  201. int (*receiveresponse)(void *magic, SmbBuffer *ib, char **errmsgp);
  202. int (*decoderesponse)(SmbTransaction *t, SmbHeader *h, uchar *pdata, SmbBuffer *b, char **errmsgp);
  203. int (*encoderesponse)(SmbTransaction *t, SmbHeader *h, SmbPeerInfo *p,
  204. SmbBuffer *ob, char **errmsgp);
  205. int (*sendresponse)(void *magic, SmbBuffer *ob, char **errmsgp);
  206. } SmbTransactionMethod;
  207. extern SmbTransactionMethod smbtransactionmethoddgram;
  208. struct SmbSearch {
  209. long id;
  210. SmbTree *t;
  211. SmbDirCache *dc;
  212. Reprog *rep;
  213. ushort tid;
  214. };
  215. struct SmbFile {
  216. long id;
  217. SmbTree *t; // tree this belongs to
  218. int fd;
  219. char *name;
  220. int p9mode; // how it was opened
  221. int share; // additional sharing restictions added by this fid
  222. int ioallowed;
  223. SmbSharedFile *sf;
  224. };
  225. struct SmbSharedFile {
  226. ushort type;
  227. uint32_t dev;
  228. vlong path;
  229. // char *name;
  230. int share; // current share level
  231. int deleteonclose;
  232. SmbLockList *locklist;
  233. };
  234. struct SmbLock {
  235. vlong base;
  236. vlong limit;
  237. SmbSession *s; // owning session
  238. ushort pid; // owning pid
  239. };
  240. struct SmbCifsSession {
  241. int fd;
  242. void *magic;
  243. };
  244. struct SmbClient {
  245. SmbPeerInfo peerinfo;
  246. NbSession *nbss;
  247. SmbBuffer *b;
  248. ushort ipctid;
  249. ushort sharetid;
  250. SmbHeader protoh;
  251. };
  252. struct SmbRapServerInfo1 {
  253. char name[16];
  254. uchar vmaj;
  255. uchar vmin;
  256. uint32_t type;
  257. char *remark;
  258. };
  259. struct SmbFindFileBothDirectoryInfo {
  260. uint32_t fileindex;
  261. vlong creationtime;
  262. vlong lastaccesstime;
  263. vlong lastwritetime;
  264. vlong changetime;
  265. vlong endoffile;
  266. vlong allocationsize;
  267. uint32_t extfileattributes;
  268. char *filename;
  269. };
  270. enum {
  271. SMB_STRING_UNALIGNED = 1,
  272. SMB_STRING_UPCASE = 2,
  273. SMB_STRING_UNTERMINATED = 4,
  274. SMB_STRING_UNICODE = 8,
  275. SMB_STRING_ASCII = 16,
  276. SMB_STRING_REVPATH = 32,
  277. SMB_STRING_PATH = 64,
  278. SMB_STRING_CONVERT_MASK = SMB_STRING_PATH | SMB_STRING_REVPATH | SMB_STRING_UPCASE,
  279. };
  280. struct SmbDirCache {
  281. Dir *buf;
  282. long n;
  283. long i;
  284. };
  285. typedef struct SmbTrans2OpTableEntry SmbTrans2OpTableEntry;
  286. typedef SmbProcessResult SMBTRANS2PROCESSFN(SmbSession *s, SmbHeader *h);
  287. struct SmbTrans2OpTableEntry {
  288. char *name;
  289. SMBTRANS2PROCESSFN *process;
  290. int debug;
  291. };
  292. extern SmbTrans2OpTableEntry smbtrans2optable[];
  293. extern int smbtrans2optablesize;
  294. struct SmbSlut {
  295. char *name;
  296. int val;
  297. };
  298. extern SmbSlut smbopenmodeslut[];
  299. extern SmbSlut smbsharemodeslut[];