/// <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)); } } }
/// <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; }