Srvsvc.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 Srvsvc
  21. {
  22. public static string GetSyntax()
  23. {
  24. return "4b324fc8-1670-01d3-1278-5a47bf6ee188:3.0";
  25. }
  26. public class ShareInfo0 : NdrObject
  27. {
  28. public string Netname;
  29. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  30. public override void Encode(NdrBuffer dst)
  31. {
  32. dst.Align(4);
  33. dst.Enc_ndr_referent(Netname, 1);
  34. if (Netname != null)
  35. {
  36. dst = dst.Deferred;
  37. dst.Enc_ndr_string(Netname);
  38. }
  39. }
  40. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  41. public override void Decode(NdrBuffer src)
  42. {
  43. src.Align(4);
  44. int netnamep = src.Dec_ndr_long();
  45. if (netnamep != 0)
  46. {
  47. src = src.Deferred;
  48. Netname = src.Dec_ndr_string();
  49. }
  50. }
  51. }
  52. public class ShareInfoCtr0 : NdrObject
  53. {
  54. public int Count;
  55. public ShareInfo0[] Array;
  56. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  57. public override void Encode(NdrBuffer dst)
  58. {
  59. dst.Align(4);
  60. dst.Enc_ndr_long(Count);
  61. dst.Enc_ndr_referent(Array, 1);
  62. if (Array != null)
  63. {
  64. dst = dst.Deferred;
  65. int arrays = Count;
  66. dst.Enc_ndr_long(arrays);
  67. int arrayi = dst.Index;
  68. dst.Advance(4 * arrays);
  69. dst = dst.Derive(arrayi);
  70. for (int i = 0; i < arrays; i++)
  71. {
  72. Array[i].Encode(dst);
  73. }
  74. }
  75. }
  76. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  77. public override void Decode(NdrBuffer src)
  78. {
  79. src.Align(4);
  80. Count = src.Dec_ndr_long();
  81. int arrayp = src.Dec_ndr_long();
  82. if (arrayp != 0)
  83. {
  84. src = src.Deferred;
  85. int arrays = src.Dec_ndr_long();
  86. int arrayi = src.Index;
  87. src.Advance(4 * arrays);
  88. if (Array == null)
  89. {
  90. if (arrays < 0 || arrays > unchecked(0xFFFF))
  91. {
  92. throw new NdrException(NdrException.InvalidConformance);
  93. }
  94. Array = new ShareInfo0[arrays];
  95. }
  96. src = src.Derive(arrayi);
  97. for (int i = 0; i < arrays; i++)
  98. {
  99. if (Array[i] == null)
  100. {
  101. Array[i] = new ShareInfo0();
  102. }
  103. Array[i].Decode(src);
  104. }
  105. }
  106. }
  107. }
  108. public class ShareInfo1 : NdrObject
  109. {
  110. public string Netname;
  111. public int Type;
  112. public string Remark;
  113. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  114. public override void Encode(NdrBuffer dst)
  115. {
  116. dst.Align(4);
  117. dst.Enc_ndr_referent(Netname, 1);
  118. dst.Enc_ndr_long(Type);
  119. dst.Enc_ndr_referent(Remark, 1);
  120. if (Netname != null)
  121. {
  122. dst = dst.Deferred;
  123. dst.Enc_ndr_string(Netname);
  124. }
  125. if (Remark != null)
  126. {
  127. dst = dst.Deferred;
  128. dst.Enc_ndr_string(Remark);
  129. }
  130. }
  131. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  132. public override void Decode(NdrBuffer src)
  133. {
  134. src.Align(4);
  135. int netnamep = src.Dec_ndr_long();
  136. Type = src.Dec_ndr_long();
  137. int remarkp = src.Dec_ndr_long();
  138. if (netnamep != 0)
  139. {
  140. src = src.Deferred;
  141. Netname = src.Dec_ndr_string();
  142. }
  143. if (remarkp != 0)
  144. {
  145. src = src.Deferred;
  146. Remark = src.Dec_ndr_string();
  147. }
  148. }
  149. }
  150. public class ShareInfoCtr1 : NdrObject
  151. {
  152. public int Count;
  153. public ShareInfo1[] Array;
  154. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  155. public override void Encode(NdrBuffer dst)
  156. {
  157. dst.Align(4);
  158. dst.Enc_ndr_long(Count);
  159. dst.Enc_ndr_referent(Array, 1);
  160. if (Array != null)
  161. {
  162. dst = dst.Deferred;
  163. int arrays = Count;
  164. dst.Enc_ndr_long(arrays);
  165. int arrayi = dst.Index;
  166. dst.Advance(12 * arrays);
  167. dst = dst.Derive(arrayi);
  168. for (int i = 0; i < arrays; i++)
  169. {
  170. Array[i].Encode(dst);
  171. }
  172. }
  173. }
  174. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  175. public override void Decode(NdrBuffer src)
  176. {
  177. src.Align(4);
  178. Count = src.Dec_ndr_long();
  179. int arrayp = src.Dec_ndr_long();
  180. if (arrayp != 0)
  181. {
  182. src = src.Deferred;
  183. int arrays = src.Dec_ndr_long();
  184. int arrayi = src.Index;
  185. src.Advance(12 * arrays);
  186. if (Array == null)
  187. {
  188. if (arrays < 0 || arrays > unchecked(0xFFFF))
  189. {
  190. throw new NdrException(NdrException.InvalidConformance);
  191. }
  192. Array = new ShareInfo1[arrays];
  193. }
  194. src = src.Derive(arrayi);
  195. for (int i = 0; i < arrays; i++)
  196. {
  197. if (Array[i] == null)
  198. {
  199. Array[i] = new ShareInfo1();
  200. }
  201. Array[i].Decode(src);
  202. }
  203. }
  204. }
  205. }
  206. public class ShareInfo502 : NdrObject
  207. {
  208. public string Netname;
  209. public int Type;
  210. public string Remark;
  211. public int Permissions;
  212. public int MaxUses;
  213. public int CurrentUses;
  214. public string Path;
  215. public string Password;
  216. public int SdSize;
  217. public byte[] SecurityDescriptor;
  218. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  219. public override void Encode(NdrBuffer dst)
  220. {
  221. dst.Align(4);
  222. dst.Enc_ndr_referent(Netname, 1);
  223. dst.Enc_ndr_long(Type);
  224. dst.Enc_ndr_referent(Remark, 1);
  225. dst.Enc_ndr_long(Permissions);
  226. dst.Enc_ndr_long(MaxUses);
  227. dst.Enc_ndr_long(CurrentUses);
  228. dst.Enc_ndr_referent(Path, 1);
  229. dst.Enc_ndr_referent(Password, 1);
  230. dst.Enc_ndr_long(SdSize);
  231. dst.Enc_ndr_referent(SecurityDescriptor, 1);
  232. if (Netname != null)
  233. {
  234. dst = dst.Deferred;
  235. dst.Enc_ndr_string(Netname);
  236. }
  237. if (Remark != null)
  238. {
  239. dst = dst.Deferred;
  240. dst.Enc_ndr_string(Remark);
  241. }
  242. if (Path != null)
  243. {
  244. dst = dst.Deferred;
  245. dst.Enc_ndr_string(Path);
  246. }
  247. if (Password != null)
  248. {
  249. dst = dst.Deferred;
  250. dst.Enc_ndr_string(Password);
  251. }
  252. if (SecurityDescriptor != null)
  253. {
  254. dst = dst.Deferred;
  255. int securityDescriptors = SdSize;
  256. dst.Enc_ndr_long(securityDescriptors);
  257. int securityDescriptori = dst.Index;
  258. dst.Advance(1 * securityDescriptors);
  259. dst = dst.Derive(securityDescriptori);
  260. for (int i = 0; i < securityDescriptors; i++)
  261. {
  262. dst.Enc_ndr_small(SecurityDescriptor[i]);
  263. }
  264. }
  265. }
  266. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  267. public override void Decode(NdrBuffer src)
  268. {
  269. src.Align(4);
  270. int netnamep = src.Dec_ndr_long();
  271. Type = src.Dec_ndr_long();
  272. int remarkp = src.Dec_ndr_long();
  273. Permissions = src.Dec_ndr_long();
  274. MaxUses = src.Dec_ndr_long();
  275. CurrentUses = src.Dec_ndr_long();
  276. int pathp = src.Dec_ndr_long();
  277. int passwordp = src.Dec_ndr_long();
  278. SdSize = src.Dec_ndr_long();
  279. int securityDescriptorp = src.Dec_ndr_long();
  280. if (netnamep != 0)
  281. {
  282. src = src.Deferred;
  283. Netname = src.Dec_ndr_string();
  284. }
  285. if (remarkp != 0)
  286. {
  287. src = src.Deferred;
  288. Remark = src.Dec_ndr_string();
  289. }
  290. if (pathp != 0)
  291. {
  292. src = src.Deferred;
  293. Path = src.Dec_ndr_string();
  294. }
  295. if (passwordp != 0)
  296. {
  297. src = src.Deferred;
  298. Password = src.Dec_ndr_string();
  299. }
  300. if (securityDescriptorp != 0)
  301. {
  302. src = src.Deferred;
  303. int securityDescriptors = src.Dec_ndr_long();
  304. int securityDescriptori = src.Index;
  305. src.Advance(1 * securityDescriptors);
  306. if (SecurityDescriptor == null)
  307. {
  308. if (securityDescriptors < 0 || securityDescriptors > unchecked(0xFFFF))
  309. {
  310. throw new NdrException(NdrException.InvalidConformance);
  311. }
  312. SecurityDescriptor = new byte[securityDescriptors];
  313. }
  314. src = src.Derive(securityDescriptori);
  315. for (int i = 0; i < securityDescriptors; i++)
  316. {
  317. SecurityDescriptor[i] = unchecked((byte)src.Dec_ndr_small());
  318. }
  319. }
  320. }
  321. }
  322. public class ShareInfoCtr502 : NdrObject
  323. {
  324. public int Count;
  325. public ShareInfo502[] Array;
  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(Array, 1);
  332. if (Array != null)
  333. {
  334. dst = dst.Deferred;
  335. int arrays = Count;
  336. dst.Enc_ndr_long(arrays);
  337. int arrayi = dst.Index;
  338. dst.Advance(40 * arrays);
  339. dst = dst.Derive(arrayi);
  340. for (int i = 0; i < arrays; i++)
  341. {
  342. Array[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 arrayp = src.Dec_ndr_long();
  352. if (arrayp != 0)
  353. {
  354. src = src.Deferred;
  355. int arrays = src.Dec_ndr_long();
  356. int arrayi = src.Index;
  357. src.Advance(40 * arrays);
  358. if (Array == null)
  359. {
  360. if (arrays < 0 || arrays > unchecked(0xFFFF))
  361. {
  362. throw new NdrException(NdrException.InvalidConformance);
  363. }
  364. Array = new ShareInfo502[arrays];
  365. }
  366. src = src.Derive(arrayi);
  367. for (int i = 0; i < arrays; i++)
  368. {
  369. if (Array[i] == null)
  370. {
  371. Array[i] = new ShareInfo502();
  372. }
  373. Array[i].Decode(src);
  374. }
  375. }
  376. }
  377. }
  378. public class ShareEnumAll : DcerpcMessage
  379. {
  380. public override int GetOpnum()
  381. {
  382. return unchecked(0x0f);
  383. }
  384. public int Retval;
  385. public string Servername;
  386. public int Level;
  387. public NdrObject Info;
  388. public int Prefmaxlen;
  389. public int Totalentries;
  390. public int ResumeHandle;
  391. public ShareEnumAll(string servername, int level, NdrObject info, int prefmaxlen,
  392. int totalentries, int resumeHandle)
  393. {
  394. this.Servername = servername;
  395. this.Level = level;
  396. this.Info = info;
  397. this.Prefmaxlen = prefmaxlen;
  398. this.Totalentries = totalentries;
  399. this.ResumeHandle = resumeHandle;
  400. }
  401. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  402. public override void Encode_in(NdrBuffer dst)
  403. {
  404. dst.Enc_ndr_referent(Servername, 1);
  405. if (Servername != null)
  406. {
  407. dst.Enc_ndr_string(Servername);
  408. }
  409. dst.Enc_ndr_long(Level);
  410. int descr = Level;
  411. dst.Enc_ndr_long(descr);
  412. dst.Enc_ndr_referent(Info, 1);
  413. if (Info != null)
  414. {
  415. dst = dst.Deferred;
  416. Info.Encode(dst);
  417. }
  418. dst.Enc_ndr_long(Prefmaxlen);
  419. dst.Enc_ndr_long(ResumeHandle);
  420. }
  421. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  422. public override void Decode_out(NdrBuffer src)
  423. {
  424. Level = src.Dec_ndr_long();
  425. src.Dec_ndr_long();
  426. int infop = src.Dec_ndr_long();
  427. if (infop != 0)
  428. {
  429. if (Info == null)
  430. {
  431. Info = new ShareInfoCtr0();
  432. }
  433. src = src.Deferred;
  434. Info.Decode(src);
  435. }
  436. Totalentries = src.Dec_ndr_long();
  437. ResumeHandle = src.Dec_ndr_long();
  438. Retval = src.Dec_ndr_long();
  439. }
  440. }
  441. public class ShareGetInfo : DcerpcMessage
  442. {
  443. public override int GetOpnum()
  444. {
  445. return unchecked(0x10);
  446. }
  447. public int Retval;
  448. public string Servername;
  449. public string Sharename;
  450. public int Level;
  451. public NdrObject Info;
  452. public ShareGetInfo(string servername, string sharename, int level, NdrObject info
  453. )
  454. {
  455. this.Servername = servername;
  456. this.Sharename = sharename;
  457. this.Level = level;
  458. this.Info = info;
  459. }
  460. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  461. public override void Encode_in(NdrBuffer dst)
  462. {
  463. dst.Enc_ndr_referent(Servername, 1);
  464. if (Servername != null)
  465. {
  466. dst.Enc_ndr_string(Servername);
  467. }
  468. dst.Enc_ndr_string(Sharename);
  469. dst.Enc_ndr_long(Level);
  470. }
  471. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  472. public override void Decode_out(NdrBuffer src)
  473. {
  474. src.Dec_ndr_long();
  475. int infop = src.Dec_ndr_long();
  476. if (infop != 0)
  477. {
  478. if (Info == null)
  479. {
  480. Info = new ShareInfo0();
  481. }
  482. src = src.Deferred;
  483. Info.Decode(src);
  484. }
  485. Retval = src.Dec_ndr_long();
  486. }
  487. }
  488. public class ServerInfo100 : NdrObject
  489. {
  490. public int PlatformId;
  491. public string Name;
  492. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  493. public override void Encode(NdrBuffer dst)
  494. {
  495. dst.Align(4);
  496. dst.Enc_ndr_long(PlatformId);
  497. dst.Enc_ndr_referent(Name, 1);
  498. if (Name != null)
  499. {
  500. dst = dst.Deferred;
  501. dst.Enc_ndr_string(Name);
  502. }
  503. }
  504. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  505. public override void Decode(NdrBuffer src)
  506. {
  507. src.Align(4);
  508. PlatformId = src.Dec_ndr_long();
  509. int namep = src.Dec_ndr_long();
  510. if (namep != 0)
  511. {
  512. src = src.Deferred;
  513. Name = src.Dec_ndr_string();
  514. }
  515. }
  516. }
  517. public class ServerGetInfo : DcerpcMessage
  518. {
  519. public override int GetOpnum()
  520. {
  521. return unchecked(0x15);
  522. }
  523. public int Retval;
  524. public string Servername;
  525. public int Level;
  526. public NdrObject Info;
  527. public ServerGetInfo(string servername, int level, NdrObject info)
  528. {
  529. this.Servername = servername;
  530. this.Level = level;
  531. this.Info = info;
  532. }
  533. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  534. public override void Encode_in(NdrBuffer dst)
  535. {
  536. dst.Enc_ndr_referent(Servername, 1);
  537. if (Servername != null)
  538. {
  539. dst.Enc_ndr_string(Servername);
  540. }
  541. dst.Enc_ndr_long(Level);
  542. }
  543. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  544. public override void Decode_out(NdrBuffer src)
  545. {
  546. src.Dec_ndr_long();
  547. int infop = src.Dec_ndr_long();
  548. if (infop != 0)
  549. {
  550. if (Info == null)
  551. {
  552. Info = new ServerInfo100();
  553. }
  554. src = src.Deferred;
  555. Info.Decode(src);
  556. }
  557. Retval = src.Dec_ndr_long();
  558. }
  559. }
  560. public class TimeOfDayInfo : NdrObject
  561. {
  562. public int Elapsedt;
  563. public int Msecs;
  564. public int Hours;
  565. public int Mins;
  566. public int Secs;
  567. public int Hunds;
  568. public int Timezone;
  569. public int Tinterval;
  570. public int Day;
  571. public int Month;
  572. public int Year;
  573. public int Weekday;
  574. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  575. public override void Encode(NdrBuffer dst)
  576. {
  577. dst.Align(4);
  578. dst.Enc_ndr_long(Elapsedt);
  579. dst.Enc_ndr_long(Msecs);
  580. dst.Enc_ndr_long(Hours);
  581. dst.Enc_ndr_long(Mins);
  582. dst.Enc_ndr_long(Secs);
  583. dst.Enc_ndr_long(Hunds);
  584. dst.Enc_ndr_long(Timezone);
  585. dst.Enc_ndr_long(Tinterval);
  586. dst.Enc_ndr_long(Day);
  587. dst.Enc_ndr_long(Month);
  588. dst.Enc_ndr_long(Year);
  589. dst.Enc_ndr_long(Weekday);
  590. }
  591. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  592. public override void Decode(NdrBuffer src)
  593. {
  594. src.Align(4);
  595. Elapsedt = src.Dec_ndr_long();
  596. Msecs = src.Dec_ndr_long();
  597. Hours = src.Dec_ndr_long();
  598. Mins = src.Dec_ndr_long();
  599. Secs = src.Dec_ndr_long();
  600. Hunds = src.Dec_ndr_long();
  601. Timezone = src.Dec_ndr_long();
  602. Tinterval = src.Dec_ndr_long();
  603. Day = src.Dec_ndr_long();
  604. Month = src.Dec_ndr_long();
  605. Year = src.Dec_ndr_long();
  606. Weekday = src.Dec_ndr_long();
  607. }
  608. }
  609. public class RemoteTod : DcerpcMessage
  610. {
  611. public override int GetOpnum()
  612. {
  613. return unchecked(0x1c);
  614. }
  615. public int Retval;
  616. public string Servername;
  617. public TimeOfDayInfo Info;
  618. public RemoteTod(string servername, TimeOfDayInfo info)
  619. {
  620. this.Servername = servername;
  621. this.Info = info;
  622. }
  623. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  624. public override void Encode_in(NdrBuffer dst)
  625. {
  626. dst.Enc_ndr_referent(Servername, 1);
  627. if (Servername != null)
  628. {
  629. dst.Enc_ndr_string(Servername);
  630. }
  631. }
  632. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  633. public override void Decode_out(NdrBuffer src)
  634. {
  635. int infop = src.Dec_ndr_long();
  636. if (infop != 0)
  637. {
  638. if (Info == null)
  639. {
  640. Info = new TimeOfDayInfo();
  641. }
  642. Info.Decode(src);
  643. }
  644. Retval = src.Dec_ndr_long();
  645. }
  646. }
  647. }
  648. }