use of com.sun.jna.platform.win32.LMAccess.USER_INFO_1 in project jna by java-native-access.
the class Advapi32Test method testImpersonateLoggedOnUser.
public void testImpersonateLoggedOnUser() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = "JNAAdvapi32TestImp";
userInfo.usri1_password = "!JNAP$$Wrd0";
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
// ignore test if not able to add user (need to be administrator to do this).
if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
return;
}
try {
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
assertTrue(Advapi32.INSTANCE.ImpersonateLoggedOnUser(phUser.getValue()));
assertTrue(Advapi32.INSTANCE.RevertToSelf());
} finally {
HANDLE hUser = phUser.getValue();
if (!WinBase.INVALID_HANDLE_VALUE.equals(hUser)) {
Kernel32Util.closeHandle(hUser);
}
}
} finally {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
}
}
use of com.sun.jna.platform.win32.LMAccess.USER_INFO_1 in project jna by java-native-access.
the class Advapi32UtilTest method testGetUserAccount.
public void testGetUserAccount() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = "JNANetapi32TestUser";
userInfo.usri1_password = "!JNAP$$Wrd0";
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
// ignore test if not able to add user (need to be administrator to do this).
if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
return;
}
try {
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
assertTrue(account.name.length() > 0);
assertEquals(userInfo.usri1_name.toString(), account.name);
} finally {
HANDLE hUser = phUser.getValue();
if (!WinBase.INVALID_HANDLE_VALUE.equals(hUser)) {
Kernel32Util.closeHandle(hUser);
}
}
} finally {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
}
}
use of com.sun.jna.platform.win32.LMAccess.USER_INFO_1 in project jna by java-native-access.
the class Netapi32Test method testNetUserEnum.
public void testNetUserEnum() {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesread = new IntByReference();
IntByReference totalentries = new IntByReference();
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserEnum(null, 1, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
USER_INFO_1 userinfo = new USER_INFO_1(bufptr.getValue());
USER_INFO_1[] userinfos = (USER_INFO_1[]) userinfo.toArray(entriesread.getValue());
for (USER_INFO_1 ui : userinfos) {
assertTrue(ui.usri1_name.length() > 0);
}
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
use of com.sun.jna.platform.win32.LMAccess.USER_INFO_1 in project jna by java-native-access.
the class Netapi32Test method testNetUserChangePassword.
public void testNetUserChangePassword() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = "JNANetapi32TestUser";
userInfo.usri1_password = "!JNAP$$Wrd0";
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
// ignore test if not able to add user (need to be administrator to do this).
if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(Kernel32Util.getComputerName(), 1, userInfo, null)) {
return;
}
try {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserChangePassword(Kernel32Util.getComputerName(), userInfo.usri1_name.toString(), userInfo.usri1_password.toString(), "!JNAP%%Wrd1"));
} finally {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(Kernel32Util.getComputerName(), userInfo.usri1_name.toString()));
}
}
use of com.sun.jna.platform.win32.LMAccess.USER_INFO_1 in project jna by java-native-access.
the class Advapi32UtilTest method testGetUserGroups.
public void testGetUserGroups() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = "JNANetapi32TestUser";
userInfo.usri1_password = "!JNAP$$Wrd0";
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
// ignore test if not able to add user (need to be administrator to do this).
if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
return;
}
try {
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
Account[] groups = Advapi32Util.getTokenGroups(phUser.getValue());
assertTrue(groups.length > 0);
for (Account group : groups) {
assertTrue(group.name.length() > 0);
assertTrue(group.sidString.length() > 0);
assertTrue(group.sid.length > 0);
}
} finally {
HANDLE hUser = phUser.getValue();
if (!WinBase.INVALID_HANDLE_VALUE.equals(hUser)) {
Kernel32Util.closeHandle(hUser);
}
}
} finally {
assertEquals("Error in NetUserDel", LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
}
}
Aggregations