private static byte[] ParseSddlForm(string sddlForm) { string sid = sddlForm; // If only 2 characters long, can't be a full SID string - so assume // it's an attempted alias. Do that conversion first. if (sddlForm.Length == 2) { WellKnownAccount acct = WellKnownAccount.LookupBySddlForm(sddlForm); if (acct == null) { throw new ArgumentException( "Invalid SDDL string - unrecognized account: " + sddlForm, "sddlForm"); } if (!acct.IsAbsolute) { throw new NotImplementedException( "Mono unable to convert account to SID: " + (acct.Name != null ? acct.Name : sddlForm)); } sid = acct.Sid; } string[] elements = sid.ToUpperInvariant().Split('-'); int numSubAuthorities = elements.Length - 3; if (elements.Length < 3 || elements[0] != "S" || numSubAuthorities > 15) { throw new ArgumentException("Value was invalid."); } if (elements[1] != "1") { throw new ArgumentException("Only SIDs with revision 1 are supported"); } byte[] buffer = new byte[8 + (numSubAuthorities * 4)]; buffer[0] = 1; buffer[1] = (byte)numSubAuthorities; ulong authority; if (!TryParseAuthority(elements[2], out authority)) throw new ArgumentException("Value was invalid."); }
private static byte[] ParseSddlForm(string sddlForm) { string sid = sddlForm; // If only 2 characters long, can't be a full SID string - so assume // it's an attempted alias. Do that conversion first. if (sddlForm.Length == 2) { WellKnownAccount acct = WellKnownAccount.LookupBySddlForm(sddlForm); if (acct == null) { throw new ArgumentException( "Invalid SDDL string - unrecognized account: " + sddlForm, "sddlForm"); } if (!acct.IsAbsolute) { throw new NotImplementedException( "Mono unable to convert account to SID: " + (acct.Name != null ? acct.Name : sddlForm)); } sid = acct.Sid; } string[] elements = sid.ToUpperInvariant().Split('-'); int numSubAuthorities = elements.Length - 3; if (elements.Length < 3 || elements[0] != "S" || numSubAuthorities > 15) { throw new ArgumentException("Value was invalid."); } if (elements[1] != "1") { throw new ArgumentException("Only SIDs with revision 1 are supported"); } byte[] buffer = new byte[8 + (numSubAuthorities * 4)]; buffer[0] = 1; buffer[1] = (byte)numSubAuthorities; ulong authority; if (!TryParseAuthority(elements[2], out authority)) { throw new ArgumentException("Value was invalid."); } buffer[2] = (byte)((authority >> 40) & 0xFF); buffer[3] = (byte)((authority >> 32) & 0xFF); buffer[4] = (byte)((authority >> 24) & 0xFF); buffer[5] = (byte)((authority >> 16) & 0xFF); buffer[6] = (byte)((authority >> 8) & 0xFF); buffer[7] = (byte)((authority >> 0) & 0xFF); for (int i = 0; i < numSubAuthorities; ++i) { uint subAuthority; if (!TryParseSubAuthority(elements[i + 3], out subAuthority)) { throw new ArgumentException("Value was invalid."); } // Note sub authorities little-endian! int offset = 8 + (i * 4); buffer[offset + 0] = (byte)(subAuthority >> 0); buffer[offset + 1] = (byte)(subAuthority >> 8); buffer[offset + 2] = (byte)(subAuthority >> 16); buffer[offset + 3] = (byte)(subAuthority >> 24); } return(buffer); }