public void DRSR_DRSVerifyNames_Verify_Dsnames() { DrsrTestChecker.Check(); // Init the data. EnvironmentConfig.Machine srv = EnvironmentConfig.Machine.WritableDC1; DsServer server = (DsServer)EnvironmentConfig.MachineStore[srv]; uint ret = 0; ret = drsTestClient.DrsBind( srv, EnvironmentConfig.User.ParentDomainAdmin, DRS_EXTENSIONS_IN_FLAGS.DRS_EXT_BASE ); BaseTestSite.Assert.AreEqual <uint>(0, ret, "IDL_DRSBind: Checking return value - got: {0}, expect: {1}, return value should always be 0 with a success bind to DC", ret, 0); // Create a DSNAME string dn = server.Site.DN; DSNAME dsSite = ldapAdapter.GetDsName(server, dn).Value; // Prefix table SCHEMA_PREFIX_TABLE prefixTable = OIDUtility.CreatePrefixTable(); // Create the attribute block. Here we go to RDN attribute. string rdnAttrId = DRSConstants.RDN_OID; uint attrTyp = OIDUtility.MakeAttid(prefixTable, rdnAttrId); ATTRVAL attrVal = DrsuapiClient.CreateATTRVAL(null); ATTRVALBLOCK attrValBlock = DrsuapiClient.CreateATTRVALBLOCK(new ATTRVAL[] { attrVal }); ATTR attr = DrsuapiClient.CreateATTR(attrTyp, attrValBlock); ATTRBLOCK attrBlock = DrsuapiClient.CreateATTRBLOCK(new ATTR[] { attr }); // Actual RPC call. ret = drsTestClient.DrsVerifyNames( srv, dwInVersion_Values.V1, DRS_MSG_VERIFYREQ_V1_dwFlags_Values.DRS_VERIFY_DSNAMES, new DSNAME[] { dsSite }, new string[] { dn }, attrBlock, prefixTable ); BaseTestSite.Assert.AreEqual <uint>(0, ret, "IDL_DRSVerifyNames: Checking return value - got: {0}, expect: {1}, return value should always be 0", ret, 0); // Unbind ret = drsTestClient.DrsUnbind(srv); BaseTestSite.Assert.AreEqual <uint>(0, ret, "IDL_DRSUnbind: Checking return value - got: {0}, expect: {1}, return value should always be 0", ret, 0); }
public void DRSR_DRSVerifyNames_Verify_SAM_Account_Names() { DrsrTestChecker.Check(); // Init the data. EnvironmentConfig.Machine srv = EnvironmentConfig.Machine.WritableDC1; DsServer server = (DsServer)EnvironmentConfig.MachineStore[srv]; DsUser user = EnvironmentConfig.UserStore[EnvironmentConfig.User.ParentDomainAdmin]; uint ret = 0; ret = drsTestClient.DrsBind( srv, EnvironmentConfig.User.ParentDomainAdmin, DRS_EXTENSIONS_IN_FLAGS.DRS_EXT_BASE ); BaseTestSite.Assert.AreEqual <uint>( 0, ret, "IDL_DRSBind: should return 0 with a success bind to DC"); // Create a DSNAME with only SAMAccountName. string userDn = ldapAdapter.GetUserDn(server, user); string sAMAccountName = (string)ldapAdapter.GetAttributeValue(server, userDn, "sAMAccountName"); DSNAME dsUser = DrsuapiClient.CreateDsName(sAMAccountName, Guid.Empty, null); // Prefix table SCHEMA_PREFIX_TABLE prefixTable = OIDUtility.CreatePrefixTable(); // Create the attribute block. Here we go to RDN attribute. string rdnAttrId = DRSConstants.RDN_OID; uint attrTyp = OIDUtility.MakeAttid(prefixTable, rdnAttrId); ATTRVAL attrVal = DrsuapiClient.CreateATTRVAL(null); ATTRVALBLOCK attrValBlock = DrsuapiClient.CreateATTRVALBLOCK(new ATTRVAL[] { attrVal }); ATTR attr = DrsuapiClient.CreateATTR(attrTyp, attrValBlock); ATTRBLOCK attrBlock = DrsuapiClient.CreateATTRBLOCK(new ATTR[] { attr }); // Actual RPC call. ret = drsTestClient.DrsVerifyNames( srv, dwInVersion_Values.V1, DRS_MSG_VERIFYREQ_V1_dwFlags_Values.DRS_VERIFY_SAM_ACCOUNT_NAMES, new DSNAME[] { dsUser }, new string[] { userDn }, attrBlock, prefixTable ); BaseTestSite.Assert.AreEqual <uint>( 0, ret, "IDL_DRSVerifyNames: return value should be 0" ); // Unbind ret = drsTestClient.DrsUnbind(srv); BaseTestSite.Assert.AreEqual <uint>( 0, ret, "IDL_DRSUnbind: return value should be 0"); }
public static ATTRVAL ATTRVALFromValue(DsServer dc, string v, string attrSyntax, SCHEMA_PREFIX_TABLE prefixTable) { ATTRVAL attrVal = new ATTRVAL(); switch (attrSyntax) { case "2.2.5.8": // Boolean { attrVal.valLen = 4; attrVal.pVal = new byte[4]; if (v == "TRUE") { attrVal.pVal[0] = 1; } else { attrVal.pVal[0] = 0; } break; } case "2.5.5.9": // Enumeration, Integer { attrVal.valLen = 4; int intValue = Convert.ToInt32(v); attrVal.pVal = BitConverter.GetBytes(intValue); break; } case "2.5.5.16": // LargeInteger { attrVal.valLen = 8; long intValue = Convert.ToInt64(v); attrVal.pVal = BitConverter.GetBytes(intValue); break; } case "2.5.5.13": // Object (Presentation-Address) { System.Text.UnicodeEncoding utf16 = new System.Text.UnicodeEncoding(); byte[] data = utf16.GetBytes(v); attrVal.valLen = (uint)data.Length + 4; attrVal.pVal = new byte[attrVal.valLen]; byte[] intBytes = BitConverter.GetBytes(attrVal.valLen); Array.Copy(intBytes, 0, attrVal.pVal, 0, intBytes.Length); Array.Copy(data, 0, attrVal.pVal, intBytes.Length, data.Length); break; } case "2.5.5.4": // String (Teletex) case "2.5.5.5": // String (IA5), String (Printable) case "2.5.5.6": // String (Numeric) case "2.5.5.10": // Object (Replica-Link), string (Octet) { attrVal.pVal = ToBinary(v); attrVal.valLen = (uint)attrVal.pVal.Length; break; } case "2.5.5.2": // String (Object-Identifier) { if (v is string && v.Contains(".") == false) { // Look in the Schema NC for the object class and it's governsID. RootDSE rootDse = LdapUtility.GetRootDSE(dc); string schemaNc = rootDse.schemaNamingContext; v = LdapUtility.GetAttributeValueInString( dc, schemaNc, "governsId", "(&(objectClass=classSchema)(lDAPDisplayName=" + v + "))", System.DirectoryServices.Protocols.SearchScope.Subtree); } attrVal.valLen = 4; uint attid = MakeAttid(prefixTable, v); attrVal.pVal = BitConverter.GetBytes(attid); break; } case "2.5.5.12": // String (Unicode) { System.Text.UnicodeEncoding utf16 = new System.Text.UnicodeEncoding(); attrVal.pVal = utf16.GetBytes(v); attrVal.valLen = (uint)attrVal.pVal.Length; break; } case "2.5.5.11": // String (UTC-Time), String (Generalized-Time) { DateTime t; string timePattern = "yyyyMMddHHmmss.'0Z'"; DateTime.TryParseExact( v, timePattern, null, System.Globalization.DateTimeStyles.None, out t); DateTime dsTime = new DateTime(1601, 1, 1, 0, 0, 0); TimeSpan diff = t - dsTime; attrVal.valLen = 8; attrVal.pVal = BitConverter.GetBytes((ulong)diff.TotalSeconds); break; } case "2.5.5.1": // Object (DS-DN) { DSNAME dsName = ParseObjectDsDn(v); attrVal.pVal = TypeMarshal.ToBytes <DSNAME>(dsName); attrVal.valLen = (uint)attrVal.pVal.Length; } break; case "2.5.5.14": // Object (DN-String), Object (Access-Point) { string pattern = @"S:([0-9a-fA-F]+):(.*):(.*)"; Regex r = new Regex(pattern); Match m = r.Match(v); uint char_count = (uint)Convert.ToInt32(m.Groups[1].Value, 16); SYNTAX_ADDRESS sa = new SYNTAX_ADDRESS(); sa.dataLen = (2 * char_count) + 4; System.Text.UnicodeEncoding utf16 = new System.Text.UnicodeEncoding(); sa.byteVal = utf16.GetBytes(m.Groups[2].Value); byte[] saBin = TypeMarshal.ToBytes <SYNTAX_ADDRESS>(sa); DSNAME dsdn = ParseObjectDsDn(m.Groups[3].Value); byte[] dsdnBin = TypeMarshal.ToBytes <DSNAME>(dsdn); // Add padding uint p = 4 - dsdn.structLen % 4; if (p == 4) { p = 0; } byte[] padding = new byte[p]; attrVal.pVal = new byte[dsdnBin.Length + p + saBin.Length]; Array.Copy(dsdnBin, attrVal.pVal, dsdnBin.Length); Array.Copy(saBin, 0, attrVal.pVal, dsdnBin.Length + p, saBin.Length); attrVal.valLen = (uint)attrVal.pVal.Length; } break; case "2.5.5.7": // Object (DN-Binary), Object (OR-Name) { string pattern = @"B:([0-9a-fA-F]+):([0-9a-fA-F]+):(.*)"; Regex r = new Regex(pattern); Match m = r.Match(v); uint char_count = (uint)Convert.ToInt32(m.Groups[1].Value, 16); SYNTAX_ADDRESS sa = new SYNTAX_ADDRESS(); sa.dataLen = char_count; sa.byteVal = FromBinaryString(m.Groups[2].Value); byte[] saBin = TypeMarshal.ToBytes <SYNTAX_ADDRESS>(sa); DSNAME dsdn = ParseObjectDsDn(m.Groups[3].Value); byte[] dsdnBin = TypeMarshal.ToBytes <DSNAME>(dsdn); // Add padding uint p = 4 - dsdn.structLen % 4; if (p == 4) { p = 0; } byte[] padding = new byte[p]; attrVal.pVal = new byte[dsdnBin.Length + p + saBin.Length]; Array.Copy(dsdnBin, attrVal.pVal, dsdnBin.Length); Array.Copy(saBin, 0, attrVal.pVal, dsdnBin.Length + p, saBin.Length); attrVal.valLen = (uint)attrVal.pVal.Length; } break; case "2.5.5.15": // String (NT-Sec-Desc) case "2.5.5.17": // String (SID) { attrVal.pVal = FromBinaryString(v); attrVal.valLen = (uint)attrVal.pVal.Length; } break; default: break; } return(attrVal); }