DcerpcBinding.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 System;
  18. using SharpCifs.Dcerpc.Msrpc;
  19. using SharpCifs.Util.Sharpen;
  20. namespace SharpCifs.Dcerpc
  21. {
  22. public class DcerpcBinding
  23. {
  24. private static Hashtable _interfaces;
  25. static DcerpcBinding()
  26. {
  27. _interfaces = new Hashtable();
  28. _interfaces.Put("srvsvc", Srvsvc.GetSyntax());
  29. _interfaces.Put("lsarpc", Lsarpc.GetSyntax());
  30. _interfaces.Put("samr", Samr.GetSyntax());
  31. _interfaces.Put("netdfs", Netdfs.GetSyntax());
  32. }
  33. public static void AddInterface(string name, string syntax)
  34. {
  35. _interfaces.Put(name, syntax);
  36. }
  37. internal string Proto;
  38. internal string Server;
  39. internal string Endpoint;
  40. internal Hashtable Options;
  41. internal Uuid Uuid;
  42. internal int Major;
  43. internal int Minor;
  44. internal DcerpcBinding(string proto, string server)
  45. {
  46. this.Proto = proto;
  47. this.Server = server;
  48. }
  49. /// <exception cref="SharpCifs.Dcerpc.DcerpcException"></exception>
  50. internal virtual void SetOption(string key, object val)
  51. {
  52. if (key.Equals("endpoint"))
  53. {
  54. Endpoint = val.ToString().ToLower();
  55. if (Endpoint.StartsWith("\\pipe\\"))
  56. {
  57. string iface = (string)_interfaces.Get(Runtime.Substring(Endpoint, 6));
  58. if (iface != null)
  59. {
  60. int c;
  61. int p;
  62. c = iface.IndexOf(':');
  63. p = iface.IndexOf('.', c + 1);
  64. Uuid = new Uuid(Runtime.Substring(iface, 0, c));
  65. Major = Convert.ToInt32(Runtime.Substring(iface, c + 1, p));
  66. Minor = Convert.ToInt32(Runtime.Substring(iface, p + 1));
  67. return;
  68. }
  69. }
  70. throw new DcerpcException("Bad endpoint: " + Endpoint);
  71. }
  72. if (Options == null)
  73. {
  74. Options = new Hashtable();
  75. }
  76. Options.Put(key, val);
  77. }
  78. internal virtual object GetOption(string key)
  79. {
  80. if (key.Equals("endpoint"))
  81. {
  82. return Endpoint;
  83. }
  84. if (Options != null)
  85. {
  86. return Options.Get(key);
  87. }
  88. return null;
  89. }
  90. public override string ToString()
  91. {
  92. /* string ret = proto + ":" + server + "[" + endpoint;
  93. if (options != null)
  94. {
  95. Iterator iter = (Iterator) options.Keys.GetEnumerator();
  96. while (iter.HasNext())
  97. {
  98. object key = iter.Next();
  99. object val = options.Get(key);
  100. ret += "," + key + "=" + val;
  101. }
  102. }
  103. ret += "]";
  104. return ret; */
  105. return null;
  106. }
  107. }
  108. }