internal NameServiceClient(int lport, IPAddress laddr) { this._lport = lport; this.laddr = laddr; try { Baddr = Config.GetInetAddress("jcifs.netbios.baddr", Extensions.GetAddressByName("255.255.255.255")); } catch (Exception ex) { } _sndBuf = new byte[SndBufSize]; _rcvBuf = new byte[RcvBufSize]; if (string.IsNullOrEmpty(Ro)) { if (NbtAddress.GetWinsAddress() == null) { _resolveOrder = new int[2]; _resolveOrder[0] = ResolverLmhosts; _resolveOrder[1] = ResolverBcast; } else { _resolveOrder = new int[3]; _resolveOrder[0] = ResolverLmhosts; _resolveOrder[1] = ResolverWins; _resolveOrder[2] = ResolverBcast; } } else { int[] tmp = new int[3]; StringTokenizer st = new StringTokenizer(Ro, ","); int i = 0; while (st.HasMoreTokens()) { string s = st.NextToken().Trim(); if (Runtime.EqualsIgnoreCase(s, "LMHOSTS")) { tmp[i++] = ResolverLmhosts; } else { if (Runtime.EqualsIgnoreCase(s, "WINS")) { if (NbtAddress.GetWinsAddress() == null) { if (_log.Level > 1) { _log.WriteLine("NetBIOS resolveOrder specifies WINS however the " + "jcifs.netbios.wins property has not been set" ); } continue; } tmp[i++] = ResolverWins; } else { if (Runtime.EqualsIgnoreCase(s, "BCAST")) { tmp[i++] = ResolverBcast; } else { if (Runtime.EqualsIgnoreCase(s, "DNS")) { } else { // skip if (_log.Level > 1) { _log.WriteLine("unknown resolver method: " + s); } } } } } } _resolveOrder = new int[i]; Array.Copy(tmp, 0, _resolveOrder, 0, i); } }
/// <summary> /// Retrieve an array of <tt>InetAddress</tt> created from a property /// value containting a <tt>delim</tt> separated list of hostnames and/or /// ipaddresses. /// </summary> /// <remarks> /// Retrieve an array of <tt>InetAddress</tt> created from a property /// value containting a <tt>delim</tt> separated list of hostnames and/or /// ipaddresses. /// </remarks> public static IPAddress[] GetInetAddressArray(string key, string delim, IPAddress [] def) { string p = GetProperty(key); if (p != null) { StringTokenizer tok = new StringTokenizer(p, delim); int len = tok.CountTokens(); IPAddress[] arr = new IPAddress[len]; for (int i = 0; i < len; i++) { string addr = tok.NextToken(); try { arr[i] = Extensions.GetAddressByName(addr); } catch (UnknownHostException uhe) { if (_log.Level > 0) { _log.WriteLine(addr); Runtime.PrintStackTrace(uhe, _log); } return def; } } return arr; } return def; }
/// <summary> /// Construct a SID from it's textual representation such as /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>. /// </summary> /// <remarks> /// Construct a SID from it's textual representation such as /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>. /// </remarks> /// <exception cref="SharpCifs.Smb.SmbException"></exception> public Sid(string textual) { StringTokenizer st = new StringTokenizer(textual, "-"); if (st.CountTokens() < 3 || !st.NextToken().Equals("S")) { // need S-N-M throw new SmbException("Bad textual SID format: " + textual); } Revision = byte.Parse(st.NextToken()); string tmp = st.NextToken(); long id = 0; if (tmp.StartsWith("0x")) { //id = long.Parse(Sharpen.Runtime.Substring(tmp, 2), 16); id = long.Parse(Runtime.Substring(tmp, 2)); } else { id = long.Parse(tmp); } IdentifierAuthority = new byte[6]; for (int i = 5; id > 0; i--) { IdentifierAuthority[i] = unchecked((byte)(id % 256)); id >>= 8; } SubAuthorityCount = unchecked((byte)st.CountTokens()); if (SubAuthorityCount > 0) { SubAuthority = new int[SubAuthorityCount]; for (int i1 = 0; i1 < SubAuthorityCount; i1++) { SubAuthority[i1] = (int)(long.Parse(st.NextToken()) & unchecked(0xFFFFFFFFL)); } } }
static UniAddress() { string ro = Config.GetProperty("jcifs.resolveOrder"); IPAddress nbns = NbtAddress.GetWinsAddress(); try { _baddr = Config.GetInetAddress("jcifs.netbios.baddr", Extensions.GetAddressByName ("255.255.255.255")); } catch (UnknownHostException) { } if (string.IsNullOrEmpty(ro)) { if (nbns == null) { _resolveOrder = new int[3]; _resolveOrder[0] = ResolverLmhosts; _resolveOrder[1] = ResolverDns; _resolveOrder[2] = ResolverBcast; } else { _resolveOrder = new int[4]; _resolveOrder[0] = ResolverLmhosts; _resolveOrder[1] = ResolverWins; _resolveOrder[2] = ResolverDns; _resolveOrder[3] = ResolverBcast; } } else { int[] tmp = new int[4]; StringTokenizer st = new StringTokenizer(ro, ","); int i = 0; while (st.HasMoreTokens()) { string s = st.NextToken().Trim(); if (Runtime.EqualsIgnoreCase(s, "LMHOSTS")) { tmp[i++] = ResolverLmhosts; } else { if (Runtime.EqualsIgnoreCase(s, "WINS")) { if (nbns == null) { if (_log.Level > 1) { _log.WriteLine("UniAddress resolveOrder specifies WINS however the " + "jcifs.netbios.wins property has not been set" ); } continue; } tmp[i++] = ResolverWins; } else { if (Runtime.EqualsIgnoreCase(s, "BCAST")) { tmp[i++] = ResolverBcast; } else { if (Runtime.EqualsIgnoreCase(s, "DNS")) { tmp[i++] = ResolverDns; } else { if (_log.Level > 1) { _log.WriteLine("unknown resolver method: " + s); } } } } } } _resolveOrder = new int[i]; Array.Copy(tmp, 0, _resolveOrder, 0, i); } }