smbdat.h 7.1 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, int32_t 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. uint16_t maxlen;
  36. uint8_t securitymode;
  37. uint16_t maxmpxcount;
  38. uint16_t maxnumbervcs;
  39. uint32_t maxbuffersize;
  40. uint32_t maxrawsize;
  41. uint32_t sessionkey;
  42. int64_t utc;
  43. int16_t tzoff;
  44. uint8_t encryptionkeylength;
  45. uint8_t *encryptionkey;
  46. char *oemdomainname;
  47. };
  48. struct SmbTransaction {
  49. struct {
  50. char *name;
  51. uint32_t tpcount;
  52. uint8_t *parameters;
  53. uint32_t pcount;
  54. uint32_t tdcount;
  55. uint8_t *data;
  56. uint32_t maxpcount;
  57. uint32_t maxdcount;
  58. uint32_t maxscount;
  59. uint32_t dcount;
  60. uint16_t scount;
  61. uint16_t *setup;
  62. uint16_t flags;
  63. } in;
  64. struct {
  65. uint32_t tpcount;
  66. uint32_t tdcount;
  67. SmbBuffer *parameters;
  68. SmbBuffer *data;
  69. uint16_t *setup;
  70. } out;
  71. };
  72. enum {
  73. SmbSessionNeedNegotiate,
  74. SmbSessionNeedSetup,
  75. SmbSessionEstablished,
  76. };
  77. struct SmbSession {
  78. NbSession *nbss;
  79. SmbCifsSession *cifss;
  80. uint8_t 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. uint16_t maxmpxcount;
  90. MSchapreply mschapreply;
  91. } client;
  92. SmbTransaction transaction;
  93. SmbIdMap *fidmap;
  94. SmbIdMap *tidmap;
  95. SmbIdMap *sidmap;
  96. int state;
  97. uint8_t errclass;
  98. uint16_t error;
  99. int tzoff; // as passed to client during negotiation
  100. SmbService *serv;
  101. };
  102. typedef struct SmbHeader {
  103. uint8_t command;
  104. union {
  105. struct {
  106. uint8_t errclass;
  107. uint16_t error;
  108. };
  109. uint32_t status;
  110. };
  111. uint8_t flags;
  112. uint16_t flags2;
  113. union {
  114. struct {
  115. uint16_t pidhigh;
  116. uint8_t securitysignature[8];
  117. };
  118. };
  119. uint16_t tid;
  120. uint16_t pid;
  121. uint16_t uid;
  122. uint16_t mid;
  123. uint8_t 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, uint8_t *pdata, SmbBuffer *b);
  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. uint8_t 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. int32_t id;
  182. SmbService *serv;
  183. };
  184. struct SmbService {
  185. Ref ref;
  186. char *name;
  187. char *type;
  188. uint16_t 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, uint8_t *wordcount, uint16_t *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, uint8_t *wordcountp, uint16_t *bytecountp, char **errmsgp);
  201. int (*receiveresponse)(void *magic, SmbBuffer *ib, char **errmsgp);
  202. int (*decoderesponse)(SmbTransaction *t, SmbHeader *h, uint8_t *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. int32_t id;
  210. SmbTree *t;
  211. SmbDirCache *dc;
  212. Reprog *rep;
  213. uint16_t tid;
  214. };
  215. struct SmbFile {
  216. int32_t id;
  217. SmbTree *t; // tree this beint32_ts 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. uint16_t type;
  227. uint32_t dev;
  228. int64_t path;
  229. // char *name;
  230. int share; // current share level
  231. int deleteonclose;
  232. SmbLockList *locklist;
  233. };
  234. struct SmbLock {
  235. int64_t base;
  236. int64_t limit;
  237. SmbSession *s; // owning session
  238. uint16_t 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. uint16_t ipctid;
  249. uint16_t sharetid;
  250. SmbHeader protoh;
  251. };
  252. struct SmbRapServerInfo1 {
  253. char name[16];
  254. uint8_t vmaj;
  255. uint8_t vmin;
  256. uint32_t type;
  257. char *remark;
  258. };
  259. struct SmbFindFileBothDirectoryInfo {
  260. uint32_t fileindex;
  261. int64_t creationtime;
  262. int64_t lastaccesstime;
  263. int64_t lastwritetime;
  264. int64_t changetime;
  265. int64_t endoffile;
  266. int64_t 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. int32_t n;
  283. int32_t 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[];