Netdfs.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. // This code is derived from jcifs smb client library <jcifs at samba dot org>
  2. // Ported by J. Arturo <webmaster at komodosoft dot net>
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. using SharpCifs.Dcerpc.Ndr;
  18. namespace SharpCifs.Dcerpc.Msrpc
  19. {
  20. public class Netdfs
  21. {
  22. public static string GetSyntax()
  23. {
  24. return "4fc742e0-4a10-11cf-8273-00aa004ae673:3.0";
  25. }
  26. public const int DfsVolumeFlavorStandalone = unchecked(0x100);
  27. public const int DfsVolumeFlavorAdBlob = unchecked(0x200);
  28. public const int DfsStorageStateOffline = unchecked(0x0001);
  29. public const int DfsStorageStateOnline = unchecked(0x0002);
  30. public const int DfsStorageStateActive = unchecked(0x0004);
  31. public class DfsInfo1 : NdrObject
  32. {
  33. public string EntryPath;
  34. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  35. public override void Encode(NdrBuffer dst)
  36. {
  37. dst.Align(4);
  38. dst.Enc_ndr_referent(EntryPath, 1);
  39. if (EntryPath != null)
  40. {
  41. dst = dst.Deferred;
  42. dst.Enc_ndr_string(EntryPath);
  43. }
  44. }
  45. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  46. public override void Decode(NdrBuffer src)
  47. {
  48. src.Align(4);
  49. int entryPathp = src.Dec_ndr_long();
  50. if (entryPathp != 0)
  51. {
  52. src = src.Deferred;
  53. EntryPath = src.Dec_ndr_string();
  54. }
  55. }
  56. }
  57. public class DfsEnumArray1 : NdrObject
  58. {
  59. public int Count;
  60. public DfsInfo1[] S;
  61. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  62. public override void Encode(NdrBuffer dst)
  63. {
  64. dst.Align(4);
  65. dst.Enc_ndr_long(Count);
  66. dst.Enc_ndr_referent(S, 1);
  67. if (S != null)
  68. {
  69. dst = dst.Deferred;
  70. int ss = Count;
  71. dst.Enc_ndr_long(ss);
  72. int si = dst.Index;
  73. dst.Advance(4 * ss);
  74. dst = dst.Derive(si);
  75. for (int i = 0; i < ss; i++)
  76. {
  77. S[i].Encode(dst);
  78. }
  79. }
  80. }
  81. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  82. public override void Decode(NdrBuffer src)
  83. {
  84. src.Align(4);
  85. Count = src.Dec_ndr_long();
  86. int sp = src.Dec_ndr_long();
  87. if (sp != 0)
  88. {
  89. src = src.Deferred;
  90. int ss = src.Dec_ndr_long();
  91. int si = src.Index;
  92. src.Advance(4 * ss);
  93. if (S == null)
  94. {
  95. if (ss < 0 || ss > unchecked(0xFFFF))
  96. {
  97. throw new NdrException(NdrException.InvalidConformance);
  98. }
  99. S = new DfsInfo1[ss];
  100. }
  101. src = src.Derive(si);
  102. for (int i = 0; i < ss; i++)
  103. {
  104. if (S[i] == null)
  105. {
  106. S[i] = new DfsInfo1();
  107. }
  108. S[i].Decode(src);
  109. }
  110. }
  111. }
  112. }
  113. public class DfsStorageInfo : NdrObject
  114. {
  115. public int State;
  116. public string ServerName;
  117. public string ShareName;
  118. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  119. public override void Encode(NdrBuffer dst)
  120. {
  121. dst.Align(4);
  122. dst.Enc_ndr_long(State);
  123. dst.Enc_ndr_referent(ServerName, 1);
  124. dst.Enc_ndr_referent(ShareName, 1);
  125. if (ServerName != null)
  126. {
  127. dst = dst.Deferred;
  128. dst.Enc_ndr_string(ServerName);
  129. }
  130. if (ShareName != null)
  131. {
  132. dst = dst.Deferred;
  133. dst.Enc_ndr_string(ShareName);
  134. }
  135. }
  136. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  137. public override void Decode(NdrBuffer src)
  138. {
  139. src.Align(4);
  140. State = src.Dec_ndr_long();
  141. int serverNamep = src.Dec_ndr_long();
  142. int shareNamep = src.Dec_ndr_long();
  143. if (serverNamep != 0)
  144. {
  145. src = src.Deferred;
  146. ServerName = src.Dec_ndr_string();
  147. }
  148. if (shareNamep != 0)
  149. {
  150. src = src.Deferred;
  151. ShareName = src.Dec_ndr_string();
  152. }
  153. }
  154. }
  155. public class DfsInfo3 : NdrObject
  156. {
  157. public string Path;
  158. public string Comment;
  159. public int State;
  160. public int NumStores;
  161. public DfsStorageInfo[] Stores;
  162. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  163. public override void Encode(NdrBuffer dst)
  164. {
  165. dst.Align(4);
  166. dst.Enc_ndr_referent(Path, 1);
  167. dst.Enc_ndr_referent(Comment, 1);
  168. dst.Enc_ndr_long(State);
  169. dst.Enc_ndr_long(NumStores);
  170. dst.Enc_ndr_referent(Stores, 1);
  171. if (Path != null)
  172. {
  173. dst = dst.Deferred;
  174. dst.Enc_ndr_string(Path);
  175. }
  176. if (Comment != null)
  177. {
  178. dst = dst.Deferred;
  179. dst.Enc_ndr_string(Comment);
  180. }
  181. if (Stores != null)
  182. {
  183. dst = dst.Deferred;
  184. int storess = NumStores;
  185. dst.Enc_ndr_long(storess);
  186. int storesi = dst.Index;
  187. dst.Advance(12 * storess);
  188. dst = dst.Derive(storesi);
  189. for (int i = 0; i < storess; i++)
  190. {
  191. Stores[i].Encode(dst);
  192. }
  193. }
  194. }
  195. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  196. public override void Decode(NdrBuffer src)
  197. {
  198. src.Align(4);
  199. int pathp = src.Dec_ndr_long();
  200. int commentp = src.Dec_ndr_long();
  201. State = src.Dec_ndr_long();
  202. NumStores = src.Dec_ndr_long();
  203. int storesp = src.Dec_ndr_long();
  204. if (pathp != 0)
  205. {
  206. src = src.Deferred;
  207. Path = src.Dec_ndr_string();
  208. }
  209. if (commentp != 0)
  210. {
  211. src = src.Deferred;
  212. Comment = src.Dec_ndr_string();
  213. }
  214. if (storesp != 0)
  215. {
  216. src = src.Deferred;
  217. int storess = src.Dec_ndr_long();
  218. int storesi = src.Index;
  219. src.Advance(12 * storess);
  220. if (Stores == null)
  221. {
  222. if (storess < 0 || storess > unchecked(0xFFFF))
  223. {
  224. throw new NdrException(NdrException.InvalidConformance);
  225. }
  226. Stores = new DfsStorageInfo[storess];
  227. }
  228. src = src.Derive(storesi);
  229. for (int i = 0; i < storess; i++)
  230. {
  231. if (Stores[i] == null)
  232. {
  233. Stores[i] = new DfsStorageInfo();
  234. }
  235. Stores[i].Decode(src);
  236. }
  237. }
  238. }
  239. }
  240. public class DfsEnumArray3 : NdrObject
  241. {
  242. public int Count;
  243. public DfsInfo3[] S;
  244. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  245. public override void Encode(NdrBuffer dst)
  246. {
  247. dst.Align(4);
  248. dst.Enc_ndr_long(Count);
  249. dst.Enc_ndr_referent(S, 1);
  250. if (S != null)
  251. {
  252. dst = dst.Deferred;
  253. int ss = Count;
  254. dst.Enc_ndr_long(ss);
  255. int si = dst.Index;
  256. dst.Advance(20 * ss);
  257. dst = dst.Derive(si);
  258. for (int i = 0; i < ss; i++)
  259. {
  260. S[i].Encode(dst);
  261. }
  262. }
  263. }
  264. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  265. public override void Decode(NdrBuffer src)
  266. {
  267. src.Align(4);
  268. Count = src.Dec_ndr_long();
  269. int sp = src.Dec_ndr_long();
  270. if (sp != 0)
  271. {
  272. src = src.Deferred;
  273. int ss = src.Dec_ndr_long();
  274. int si = src.Index;
  275. src.Advance(20 * ss);
  276. if (S == null)
  277. {
  278. if (ss < 0 || ss > unchecked(0xFFFF))
  279. {
  280. throw new NdrException(NdrException.InvalidConformance);
  281. }
  282. S = new DfsInfo3[ss];
  283. }
  284. src = src.Derive(si);
  285. for (int i = 0; i < ss; i++)
  286. {
  287. if (S[i] == null)
  288. {
  289. S[i] = new DfsInfo3();
  290. }
  291. S[i].Decode(src);
  292. }
  293. }
  294. }
  295. }
  296. public class DfsInfo200 : NdrObject
  297. {
  298. public string DfsName;
  299. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  300. public override void Encode(NdrBuffer dst)
  301. {
  302. dst.Align(4);
  303. dst.Enc_ndr_referent(DfsName, 1);
  304. if (DfsName != null)
  305. {
  306. dst = dst.Deferred;
  307. dst.Enc_ndr_string(DfsName);
  308. }
  309. }
  310. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  311. public override void Decode(NdrBuffer src)
  312. {
  313. src.Align(4);
  314. int dfsNamep = src.Dec_ndr_long();
  315. if (dfsNamep != 0)
  316. {
  317. src = src.Deferred;
  318. DfsName = src.Dec_ndr_string();
  319. }
  320. }
  321. }
  322. public class DfsEnumArray200 : NdrObject
  323. {
  324. public int Count;
  325. public DfsInfo200[] S;
  326. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  327. public override void Encode(NdrBuffer dst)
  328. {
  329. dst.Align(4);
  330. dst.Enc_ndr_long(Count);
  331. dst.Enc_ndr_referent(S, 1);
  332. if (S != null)
  333. {
  334. dst = dst.Deferred;
  335. int ss = Count;
  336. dst.Enc_ndr_long(ss);
  337. int si = dst.Index;
  338. dst.Advance(4 * ss);
  339. dst = dst.Derive(si);
  340. for (int i = 0; i < ss; i++)
  341. {
  342. S[i].Encode(dst);
  343. }
  344. }
  345. }
  346. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  347. public override void Decode(NdrBuffer src)
  348. {
  349. src.Align(4);
  350. Count = src.Dec_ndr_long();
  351. int sp = src.Dec_ndr_long();
  352. if (sp != 0)
  353. {
  354. src = src.Deferred;
  355. int ss = src.Dec_ndr_long();
  356. int si = src.Index;
  357. src.Advance(4 * ss);
  358. if (S == null)
  359. {
  360. if (ss < 0 || ss > unchecked(0xFFFF))
  361. {
  362. throw new NdrException(NdrException.InvalidConformance);
  363. }
  364. S = new DfsInfo200[ss];
  365. }
  366. src = src.Derive(si);
  367. for (int i = 0; i < ss; i++)
  368. {
  369. if (S[i] == null)
  370. {
  371. S[i] = new DfsInfo200();
  372. }
  373. S[i].Decode(src);
  374. }
  375. }
  376. }
  377. }
  378. public class DfsInfo300 : NdrObject
  379. {
  380. public int Flags;
  381. public string DfsName;
  382. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  383. public override void Encode(NdrBuffer dst)
  384. {
  385. dst.Align(4);
  386. dst.Enc_ndr_long(Flags);
  387. dst.Enc_ndr_referent(DfsName, 1);
  388. if (DfsName != null)
  389. {
  390. dst = dst.Deferred;
  391. dst.Enc_ndr_string(DfsName);
  392. }
  393. }
  394. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  395. public override void Decode(NdrBuffer src)
  396. {
  397. src.Align(4);
  398. Flags = src.Dec_ndr_long();
  399. int dfsNamep = src.Dec_ndr_long();
  400. if (dfsNamep != 0)
  401. {
  402. src = src.Deferred;
  403. DfsName = src.Dec_ndr_string();
  404. }
  405. }
  406. }
  407. public class DfsEnumArray300 : NdrObject
  408. {
  409. public int Count;
  410. public DfsInfo300[] S;
  411. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  412. public override void Encode(NdrBuffer dst)
  413. {
  414. dst.Align(4);
  415. dst.Enc_ndr_long(Count);
  416. dst.Enc_ndr_referent(S, 1);
  417. if (S != null)
  418. {
  419. dst = dst.Deferred;
  420. int ss = Count;
  421. dst.Enc_ndr_long(ss);
  422. int si = dst.Index;
  423. dst.Advance(8 * ss);
  424. dst = dst.Derive(si);
  425. for (int i = 0; i < ss; i++)
  426. {
  427. S[i].Encode(dst);
  428. }
  429. }
  430. }
  431. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  432. public override void Decode(NdrBuffer src)
  433. {
  434. src.Align(4);
  435. Count = src.Dec_ndr_long();
  436. int sp = src.Dec_ndr_long();
  437. if (sp != 0)
  438. {
  439. src = src.Deferred;
  440. int ss = src.Dec_ndr_long();
  441. int si = src.Index;
  442. src.Advance(8 * ss);
  443. if (S == null)
  444. {
  445. if (ss < 0 || ss > unchecked(0xFFFF))
  446. {
  447. throw new NdrException(NdrException.InvalidConformance);
  448. }
  449. S = new DfsInfo300[ss];
  450. }
  451. src = src.Derive(si);
  452. for (int i = 0; i < ss; i++)
  453. {
  454. if (S[i] == null)
  455. {
  456. S[i] = new DfsInfo300();
  457. }
  458. S[i].Decode(src);
  459. }
  460. }
  461. }
  462. }
  463. public class DfsEnumStruct : NdrObject
  464. {
  465. public int Level;
  466. public NdrObject E;
  467. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  468. public override void Encode(NdrBuffer dst)
  469. {
  470. dst.Align(4);
  471. dst.Enc_ndr_long(Level);
  472. int descr = Level;
  473. dst.Enc_ndr_long(descr);
  474. dst.Enc_ndr_referent(E, 1);
  475. if (E != null)
  476. {
  477. dst = dst.Deferred;
  478. E.Encode(dst);
  479. }
  480. }
  481. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  482. public override void Decode(NdrBuffer src)
  483. {
  484. src.Align(4);
  485. Level = src.Dec_ndr_long();
  486. src.Dec_ndr_long();
  487. int ep = src.Dec_ndr_long();
  488. if (ep != 0)
  489. {
  490. if (E == null)
  491. {
  492. E = new DfsEnumArray1();
  493. }
  494. src = src.Deferred;
  495. E.Decode(src);
  496. }
  497. }
  498. }
  499. public class NetrDfsEnumEx : DcerpcMessage
  500. {
  501. public override int GetOpnum()
  502. {
  503. return unchecked(0x15);
  504. }
  505. public int Retval;
  506. public string DfsName;
  507. public int Level;
  508. public int Prefmaxlen;
  509. public DfsEnumStruct Info;
  510. public NdrLong Totalentries;
  511. public NetrDfsEnumEx(string dfsName, int level, int prefmaxlen, DfsEnumStruct
  512. info, NdrLong totalentries)
  513. {
  514. this.DfsName = dfsName;
  515. this.Level = level;
  516. this.Prefmaxlen = prefmaxlen;
  517. this.Info = info;
  518. this.Totalentries = totalentries;
  519. }
  520. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  521. public override void Encode_in(NdrBuffer dst)
  522. {
  523. dst.Enc_ndr_string(DfsName);
  524. dst.Enc_ndr_long(Level);
  525. dst.Enc_ndr_long(Prefmaxlen);
  526. dst.Enc_ndr_referent(Info, 1);
  527. if (Info != null)
  528. {
  529. Info.Encode(dst);
  530. }
  531. dst.Enc_ndr_referent(Totalentries, 1);
  532. if (Totalentries != null)
  533. {
  534. Totalentries.Encode(dst);
  535. }
  536. }
  537. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  538. public override void Decode_out(NdrBuffer src)
  539. {
  540. int infop = src.Dec_ndr_long();
  541. if (infop != 0)
  542. {
  543. if (Info == null)
  544. {
  545. Info = new DfsEnumStruct();
  546. }
  547. Info.Decode(src);
  548. }
  549. int totalentriesp = src.Dec_ndr_long();
  550. if (totalentriesp != 0)
  551. {
  552. Totalentries.Decode(src);
  553. }
  554. Retval = src.Dec_ndr_long();
  555. }
  556. }
  557. }
  558. }