2 // Mono.Security.Protocol.Ntlm.NtlmTargetInformation
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2007 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 namespace Mono.Security.Protocol.Ntlm {
35 public class NtlmTargetInformation {
36 string _server, _domain, _dns_host, _dns_domain;
38 public string ServerName {
39 get { return _server; }
40 set { _server = value; }
43 public string DomainName {
44 get { return _domain; }
45 set { _domain = value; }
48 public string DnsHostName {
49 get { return _dns_host; }
50 set { _dns_host = value; }
53 public string DnsDomainName {
54 get { return _dns_domain; }
55 set { _dns_domain = value; }
58 public void Decode (byte [] bytes, int length, int offset)
60 int end = offset + length;
61 for (int pos = offset; pos < end;) {
62 short type = BitConverterLE.ToInt16 (bytes, pos); // reader.ReadInt16 ();
63 short blen = BitConverterLE.ToInt16 (bytes, pos + 2); // reader.ReadInt16 ();
64 string s = Encoding.Unicode.GetString (bytes, pos + 4, blen);
67 case 0: break; // terminator
68 case 1: ServerName = s; break;
69 case 2: DomainName = s; break;
70 case 3: DnsHostName = s; break;
71 case 4: DnsDomainName = s; break;
73 throw new ArgumentException (String.Format ("Invalid SSPI message type 2 subblock type: {0}", type));
76 break; // terminator subblock
80 public byte [] ToBytes ()
82 MemoryStream ms = new MemoryStream ();
83 BinaryWriter bw = new BinaryWriter (ms);
85 WriteName (bw, 1, ServerName);
86 WriteName (bw, 2, DomainName);
87 WriteName (bw, 3, DnsHostName);
88 WriteName (bw, 4, DnsDomainName);
93 private void WriteName (BinaryWriter bw, short type, string value)
97 byte [] bytes = Encoding.Unicode.GetBytes (value);
99 bw.Write ((short) bytes.Length);