* @return
* An array of domain trusts.
*/
public static DomainTrust[] getDomainTrusts(String serverName) {
IntByReference domainTrustCount = new IntByReference();
PointerByReference domainsPointerRef = new PointerByReference();
int rc = Netapi32.INSTANCE.DsEnumerateDomainTrusts(serverName,
DsGetDC.DS_DOMAIN_VALID_FLAGS, domainsPointerRef, domainTrustCount);
if(W32Errors.NO_ERROR != rc) {
throw new Win32Exception(rc);
}
try {
DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue());
DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]);
ArrayList<DomainTrust> trusts = new ArrayList<DomainTrust>(domainTrustCount.getValue());
for(DS_DOMAIN_TRUSTS domainTrust : domainTrusts) {
DomainTrust t = new DomainTrust();
if (domainTrust.DnsDomainName != null) {
t.DnsDomainName = domainTrust.DnsDomainName.toString();
}
if (domainTrust.NetbiosDomainName != null) {
t.NetbiosDomainName = domainTrust.NetbiosDomainName.toString();
}
t.DomainSid = domainTrust.DomainSid;
if (domainTrust.DomainSid != null) {
t.DomainSidString = Advapi32Util.convertSidToStringSid(domainTrust.DomainSid);
}
t.DomainGuid = domainTrust.DomainGuid;
if (domainTrust.DomainGuid != null) {
t.DomainGuidString = Ole32Util.getStringFromGUID(domainTrust.DomainGuid);
}
t.flags = domainTrust.Flags;
trusts.add(t);
}
return trusts.toArray(new DomainTrust[0]);
} finally {
rc = Netapi32.INSTANCE.NetApiBufferFree(domainsPointerRef.getValue());
if(W32Errors.NO_ERROR != rc) {
throw new Win32Exception(rc);
}
}
}