Srvsvc.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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,
  392. int level,
  393. NdrObject info,
  394. int prefmaxlen,
  395. int totalentries,
  396. int resumeHandle)
  397. {
  398. this.Servername = servername;
  399. this.Level = level;
  400. this.Info = info;
  401. this.Prefmaxlen = prefmaxlen;
  402. this.Totalentries = totalentries;
  403. this.ResumeHandle = resumeHandle;
  404. }
  405. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  406. public override void Encode_in(NdrBuffer dst)
  407. {
  408. dst.Enc_ndr_referent(Servername, 1);
  409. if (Servername != null)
  410. {
  411. dst.Enc_ndr_string(Servername);
  412. }
  413. dst.Enc_ndr_long(Level);
  414. int descr = Level;
  415. dst.Enc_ndr_long(descr);
  416. dst.Enc_ndr_referent(Info, 1);
  417. if (Info != null)
  418. {
  419. dst = dst.Deferred;
  420. Info.Encode(dst);
  421. }
  422. dst.Enc_ndr_long(Prefmaxlen);
  423. dst.Enc_ndr_long(ResumeHandle);
  424. }
  425. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  426. public override void Decode_out(NdrBuffer src)
  427. {
  428. Level = src.Dec_ndr_long();
  429. src.Dec_ndr_long();
  430. int infop = src.Dec_ndr_long();
  431. if (infop != 0)
  432. {
  433. if (Info == null)
  434. {
  435. Info = new ShareInfoCtr0();
  436. }
  437. src = src.Deferred;
  438. Info.Decode(src);
  439. }
  440. Totalentries = src.Dec_ndr_long();
  441. ResumeHandle = src.Dec_ndr_long();
  442. Retval = src.Dec_ndr_long();
  443. }
  444. }
  445. public class ShareGetInfo : DcerpcMessage
  446. {
  447. public override int GetOpnum()
  448. {
  449. return unchecked(0x10);
  450. }
  451. public int Retval;
  452. public string Servername;
  453. public string Sharename;
  454. public int Level;
  455. public NdrObject Info;
  456. public ShareGetInfo(string servername, string sharename, int level, NdrObject info)
  457. {
  458. this.Servername = servername;
  459. this.Sharename = sharename;
  460. this.Level = level;
  461. this.Info = info;
  462. }
  463. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  464. public override void Encode_in(NdrBuffer dst)
  465. {
  466. dst.Enc_ndr_referent(Servername, 1);
  467. if (Servername != null)
  468. {
  469. dst.Enc_ndr_string(Servername);
  470. }
  471. dst.Enc_ndr_string(Sharename);
  472. dst.Enc_ndr_long(Level);
  473. }
  474. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  475. public override void Decode_out(NdrBuffer src)
  476. {
  477. src.Dec_ndr_long();
  478. int infop = src.Dec_ndr_long();
  479. if (infop != 0)
  480. {
  481. if (Info == null)
  482. {
  483. Info = new ShareInfo0();
  484. }
  485. src = src.Deferred;
  486. Info.Decode(src);
  487. }
  488. Retval = src.Dec_ndr_long();
  489. }
  490. }
  491. public class ServerInfo100 : NdrObject
  492. {
  493. public int PlatformId;
  494. public string Name;
  495. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  496. public override void Encode(NdrBuffer dst)
  497. {
  498. dst.Align(4);
  499. dst.Enc_ndr_long(PlatformId);
  500. dst.Enc_ndr_referent(Name, 1);
  501. if (Name != null)
  502. {
  503. dst = dst.Deferred;
  504. dst.Enc_ndr_string(Name);
  505. }
  506. }
  507. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  508. public override void Decode(NdrBuffer src)
  509. {
  510. src.Align(4);
  511. PlatformId = src.Dec_ndr_long();
  512. int namep = src.Dec_ndr_long();
  513. if (namep != 0)
  514. {
  515. src = src.Deferred;
  516. Name = src.Dec_ndr_string();
  517. }
  518. }
  519. }
  520. public class ServerGetInfo : DcerpcMessage
  521. {
  522. public override int GetOpnum()
  523. {
  524. return unchecked(0x15);
  525. }
  526. public int Retval;
  527. public string Servername;
  528. public int Level;
  529. public NdrObject Info;
  530. public ServerGetInfo(string servername, int level, NdrObject info)
  531. {
  532. this.Servername = servername;
  533. this.Level = level;
  534. this.Info = info;
  535. }
  536. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  537. public override void Encode_in(NdrBuffer dst)
  538. {
  539. dst.Enc_ndr_referent(Servername, 1);
  540. if (Servername != null)
  541. {
  542. dst.Enc_ndr_string(Servername);
  543. }
  544. dst.Enc_ndr_long(Level);
  545. }
  546. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  547. public override void Decode_out(NdrBuffer src)
  548. {
  549. src.Dec_ndr_long();
  550. int infop = src.Dec_ndr_long();
  551. if (infop != 0)
  552. {
  553. if (Info == null)
  554. {
  555. Info = new ServerInfo100();
  556. }
  557. src = src.Deferred;
  558. Info.Decode(src);
  559. }
  560. Retval = src.Dec_ndr_long();
  561. }
  562. }
  563. public class TimeOfDayInfo : NdrObject
  564. {
  565. public int Elapsedt;
  566. public int Msecs;
  567. public int Hours;
  568. public int Mins;
  569. public int Secs;
  570. public int Hunds;
  571. public int Timezone;
  572. public int Tinterval;
  573. public int Day;
  574. public int Month;
  575. public int Year;
  576. public int Weekday;
  577. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  578. public override void Encode(NdrBuffer dst)
  579. {
  580. dst.Align(4);
  581. dst.Enc_ndr_long(Elapsedt);
  582. dst.Enc_ndr_long(Msecs);
  583. dst.Enc_ndr_long(Hours);
  584. dst.Enc_ndr_long(Mins);
  585. dst.Enc_ndr_long(Secs);
  586. dst.Enc_ndr_long(Hunds);
  587. dst.Enc_ndr_long(Timezone);
  588. dst.Enc_ndr_long(Tinterval);
  589. dst.Enc_ndr_long(Day);
  590. dst.Enc_ndr_long(Month);
  591. dst.Enc_ndr_long(Year);
  592. dst.Enc_ndr_long(Weekday);
  593. }
  594. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  595. public override void Decode(NdrBuffer src)
  596. {
  597. src.Align(4);
  598. Elapsedt = src.Dec_ndr_long();
  599. Msecs = src.Dec_ndr_long();
  600. Hours = src.Dec_ndr_long();
  601. Mins = src.Dec_ndr_long();
  602. Secs = src.Dec_ndr_long();
  603. Hunds = src.Dec_ndr_long();
  604. Timezone = src.Dec_ndr_long();
  605. Tinterval = src.Dec_ndr_long();
  606. Day = src.Dec_ndr_long();
  607. Month = src.Dec_ndr_long();
  608. Year = src.Dec_ndr_long();
  609. Weekday = src.Dec_ndr_long();
  610. }
  611. }
  612. public class RemoteTod : DcerpcMessage
  613. {
  614. public override int GetOpnum()
  615. {
  616. return unchecked(0x1c);
  617. }
  618. public int Retval;
  619. public string Servername;
  620. public TimeOfDayInfo Info;
  621. public RemoteTod(string servername, TimeOfDayInfo info)
  622. {
  623. this.Servername = servername;
  624. this.Info = info;
  625. }
  626. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  627. public override void Encode_in(NdrBuffer dst)
  628. {
  629. dst.Enc_ndr_referent(Servername, 1);
  630. if (Servername != null)
  631. {
  632. dst.Enc_ndr_string(Servername);
  633. }
  634. }
  635. /// <exception cref="SharpCifs.Dcerpc.Ndr.NdrException"></exception>
  636. public override void Decode_out(NdrBuffer src)
  637. {
  638. int infop = src.Dec_ndr_long();
  639. if (infop != 0)
  640. {
  641. if (Info == null)
  642. {
  643. Info = new TimeOfDayInfo();
  644. }
  645. Info.Decode(src);
  646. }
  647. Retval = src.Dec_ndr_long();
  648. }
  649. }
  650. }
  651. }