use of com.sun.jna.platform.win32.Netapi32Util.DomainController in project jna by java-native-access.
the class Netapi32UtilTest method main.
public static void main(String[] args) {
junit.textui.TestRunner.run(Netapi32UtilTest.class);
System.out.println("Domain: " + Netapi32Util.getDomainName("localhost"));
// server local groups
Netapi32Util.LocalGroup[] localGroups = Netapi32Util.getLocalGroups();
System.out.println("Local groups: " + localGroups.length);
for (Netapi32Util.LocalGroup localGroup : localGroups) {
System.out.println(" " + localGroup.name + " (" + localGroup.comment + ")");
}
// global groups
Netapi32Util.Group[] groups = Netapi32Util.getGlobalGroups();
System.out.println("Global groups: " + groups.length);
for (Netapi32Util.Group group : groups) {
System.out.println(" " + group.name);
}
// server users
Netapi32Util.User[] users = Netapi32Util.getUsers();
System.out.println("Users: " + users.length);
for (Netapi32Util.User user : users) {
System.out.println(" " + user.name);
}
// user local groups
Netapi32Util.Group[] userLocalGroups = Netapi32Util.getCurrentUserLocalGroups();
System.out.println("Local user groups: " + userLocalGroups.length);
for (Netapi32Util.Group localGroup : userLocalGroups) {
System.out.println(" " + localGroup.name);
}
// domain controller
if (Netapi32Util.getJoinStatus() == LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName) {
System.out.println("Pdc: " + Netapi32Util.getDCName());
DomainController dc = Netapi32Util.getDC();
System.out.println("Domain controller:");
System.out.println(" name: " + dc.name);
System.out.println(" address: " + dc.address);
System.out.println(" domain: " + dc.domainName);
System.out.println(" site: " + dc.clientSiteName);
System.out.println(" forest: " + dc.dnsForestName);
System.out.println(" guid: " + Ole32Util.getStringFromGUID(dc.domainGuid));
}
// domain trusts
if (Netapi32Util.getJoinStatus() == LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName) {
DomainTrust[] trusts = Netapi32Util.getDomainTrusts();
System.out.println("Domain trusts: (" + trusts.length + ")");
for (DomainTrust trust : trusts) {
System.out.println(" " + trust.NetbiosDomainName + ": " + trust.DnsDomainName + " (" + trust.DomainSidString + ")");
}
}
}
use of com.sun.jna.platform.win32.Netapi32Util.DomainController in project jna by java-native-access.
the class Netapi32UtilTest method testGetDC.
public void testGetDC() {
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
return;
DomainController dc = Netapi32Util.getDC();
assertTrue("Invalid address prefix: " + dc.address, dc.address.startsWith("\\\\"));
assertTrue("Empty domain name", dc.domainName.length() > 0);
}
use of com.sun.jna.platform.win32.Netapi32Util.DomainController in project jna by java-native-access.
the class Netapi32Util method getDC.
/**
* Return the domain controller for a current computer.
* @return
* Domain controller information.
*/
public static DomainController getDC() {
PDOMAIN_CONTROLLER_INFO pdci = new PDOMAIN_CONTROLLER_INFO();
int rc = Netapi32.INSTANCE.DsGetDcName(null, null, null, null, 0, pdci);
if (W32Errors.ERROR_SUCCESS != rc) {
throw new Win32Exception(rc);
}
DomainController dc = new DomainController();
if (pdci.dci.DomainControllerAddress != null) {
dc.address = pdci.dci.DomainControllerAddress.toString();
}
dc.addressType = pdci.dci.DomainControllerAddressType;
if (pdci.dci.ClientSiteName != null) {
dc.clientSiteName = pdci.dci.ClientSiteName.toString();
}
if (pdci.dci.DnsForestName != null) {
dc.dnsForestName = pdci.dci.DnsForestName.toString();
}
dc.domainGuid = pdci.dci.DomainGuid;
if (pdci.dci.DomainName != null) {
dc.domainName = pdci.dci.DomainName.toString();
}
dc.flags = pdci.dci.Flags;
if (pdci.dci.DomainControllerName != null) {
dc.name = pdci.dci.DomainControllerName.toString();
}
rc = Netapi32.INSTANCE.NetApiBufferFree(pdci.dci.getPointer());
if (LMErr.NERR_Success != rc) {
throw new Win32Exception(rc);
}
return dc;
}
use of com.sun.jna.platform.win32.Netapi32Util.DomainController in project jna by java-native-access.
the class Netapi32Test method testDsGetForestTrustInformation.
public void testDsGetForestTrustInformation() {
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
return;
String domainController = Netapi32Util.getDCName();
PLSA_FOREST_TRUST_INFORMATION.ByReference pfti = new PLSA_FOREST_TRUST_INFORMATION.ByReference();
assertEquals(W32Errors.NO_ERROR, Netapi32.INSTANCE.DsGetForestTrustInformation(domainController, null, 0, pfti));
assertTrue(pfti.fti.RecordCount >= 0);
for (PLSA_FOREST_TRUST_RECORD precord : pfti.fti.getEntries()) {
LSA_FOREST_TRUST_RECORD.UNION data = precord.tr.u;
switch(precord.tr.ForestTrustType) {
case NTSecApi.ForestTrustTopLevelName:
case NTSecApi.ForestTrustTopLevelNameEx:
assertTrue(data.TopLevelName.Length > 0);
assertTrue(data.TopLevelName.MaximumLength > 0);
assertTrue(data.TopLevelName.MaximumLength >= data.TopLevelName.Length);
assertTrue(data.TopLevelName.getString().length() > 0);
break;
case NTSecApi.ForestTrustDomainInfo:
assertTrue(data.DomainInfo.DnsName.Length > 0);
assertTrue(data.DomainInfo.DnsName.MaximumLength > 0);
assertTrue(data.DomainInfo.DnsName.MaximumLength >= data.DomainInfo.DnsName.Length);
assertTrue(data.DomainInfo.DnsName.getString().length() > 0);
assertTrue(data.DomainInfo.NetbiosName.Length > 0);
assertTrue(data.DomainInfo.NetbiosName.MaximumLength > 0);
assertTrue(data.DomainInfo.NetbiosName.MaximumLength >= data.DomainInfo.NetbiosName.Length);
assertTrue(data.DomainInfo.NetbiosName.getString().length() > 0);
assertTrue(Advapi32.INSTANCE.IsValidSid(data.DomainInfo.Sid));
assertTrue(Advapi32Util.convertSidToStringSid(data.DomainInfo.Sid).startsWith("S-"));
break;
}
}
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(pfti.getPointer()));
}
Aggregations