/** * Dial a phone book entry by name (Asynchronously - callback type 2) * @param entryName The phone book entry name * @param func2 * @return the HRASCONN for this connection * @throws Ras32Exception errors */ public static HANDLE dialEntry(String entryName, RasDialFunc2 func2) throws Ras32Exception { // get the RAS Credentials RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference(); synchronized (phoneBookMutex) { credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain; int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials); if (err != WinError.ERROR_SUCCESS) throw new Ras32Exception(err); } // set the dialing parameters RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference(); System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length()); System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length); System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length); System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length); // dial HANDLEByReference hrasConn = new HANDLEByReference(); int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 2, func2, hrasConn); if (err != WinError.ERROR_SUCCESS) { if (hrasConn.getValue() != null) Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue()); throw new Ras32Exception(err); } return hrasConn.getValue(); }
/** * Dial a phone book entry by name (Synchronously) * @param entryName The phone book entry name * @return result reference * @throws Ras32Exception errors */ public static HANDLE dialEntry(String entryName) throws Ras32Exception { // get the RAS Credentials RASCREDENTIALS.ByReference credentials = new RASCREDENTIALS.ByReference(); synchronized (phoneBookMutex) { credentials.dwMask = WinRas.RASCM_UserName | WinRas.RASCM_Password | WinRas.RASCM_Domain; int err = Rasapi32.INSTANCE.RasGetCredentials(null, entryName, credentials); if (err != WinError.ERROR_SUCCESS) throw new Ras32Exception(err); } // set the dialing parameters RASDIALPARAMS.ByReference rasDialParams = new RASDIALPARAMS.ByReference(); System.arraycopy(entryName.toCharArray(), 0, rasDialParams.szEntryName, 0, entryName.length()); System.arraycopy(credentials.szUserName, 0, rasDialParams.szUserName, 0, credentials.szUserName.length); System.arraycopy(credentials.szPassword, 0, rasDialParams.szPassword, 0, credentials.szPassword.length); System.arraycopy(credentials.szDomain, 0, rasDialParams.szDomain, 0, credentials.szDomain.length); // dial HANDLEByReference hrasConn = new HANDLEByReference(); int err = Rasapi32.INSTANCE.RasDial(null, null, rasDialParams, 0, null, hrasConn); if (err != WinError.ERROR_SUCCESS) { if (hrasConn.getValue() != null) Rasapi32.INSTANCE.RasHangUp(hrasConn.getValue()); throw new Ras32Exception(err); } return hrasConn.getValue(); }
WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, new HANDLEByReference().getValue());
if (!Advapi32.INSTANCE.DuplicateToken(openedAccessToken.getValue(), SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, duplicatedToken)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); BOOLByReference result = new BOOLByReference(); if (!Advapi32.INSTANCE.AccessCheck(securityDescriptorMemoryPointer, duplicatedToken.getValue(), rights.getValue(), mapping,
throw new SystemException("Cannot open access token"); accessToken = tokenReference.getValue();
if (!Advapi32.INSTANCE.DuplicateTokenEx(phProcessToken.getValue(), TOKEN_ADJUST_PRIVILEGES | TOKEN_IMPERSONATE, null, if (!Advapi32.INSTANCE.SetThreadToken(null, phThreadToken.getValue())) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); if ((phThreadToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phThreadToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phThreadToken.getValue()); phThreadToken.setValue(null); if ((phProcessToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phProcessToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phProcessToken.getValue()); phProcessToken.setValue(null); return phThreadToken.getValue();
WinNT.FILE_SHARE_READ, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, new HANDLEByReference().getValue());
Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, null, 0, pcbNeeded); if (pcbNeeded.getValue() <= 0) return new PRINTER_INFO_2(); if (!Winspool.INSTANCE.GetPrinter(pHandle.getValue(), 2, pinfo2.getPointer(), pcbNeeded.getValue(), pcReturned)) throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); we = e; } finally { if (!Winspool.INSTANCE.ClosePrinter(pHandle.getValue())) { Win32Exception ex = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (we != null) {
tp.Privileges[i] = new WinNT.LUID_AND_ATTRIBUTES(pLuids[i], new DWORD(0)); Advapi32.INSTANCE.AdjustTokenPrivileges(phThreadToken.getValue(), false, tp, 0, null, null); privilegesEnabled = false; if ((phThreadToken.getValue() != WinBase.INVALID_HANDLE_VALUE) && (phThreadToken.getValue() != null)) { Kernel32.INSTANCE.CloseHandle(phThreadToken.getValue()); phThreadToken.setValue(null);
public static JOB_INFO_1[] getJobInfo1(HANDLEByReference phPrinter) { IntByReference pcbNeeded = new IntByReference(); IntByReference pcReturned = new IntByReference(); Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, null, 0, pcbNeeded, pcReturned); if (pcbNeeded.getValue() <= 0) { return new JOB_INFO_1[0]; } JOB_INFO_1 pJobEnum = new JOB_INFO_1(pcbNeeded.getValue()); if (!Winspool.INSTANCE.EnumJobs(phPrinter.getValue(), 0, 255, 1, pJobEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } pJobEnum.read(); return (JOB_INFO_1[]) pJobEnum.toArray(pcReturned.getValue()); }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }
@Override public IWindowsIdentity logonDomainUserEx(final String username, final String domain, final String password, final int logonType, final int logonProvider) { final HANDLEByReference phUser = new HANDLEByReference(); if (!Advapi32.INSTANCE.LogonUser(username, domain, password, logonType, logonProvider, phUser)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return new WindowsIdentityImpl(phUser.getValue()); }
/** * Closes the handle in the reference * * @param ref The handle reference - ignored if {@code null} * @see #closeHandle(WinNT.HANDLE) */ public static void closeHandleRef(HANDLEByReference ref) { closeHandle((ref == null) ? null : ref.getValue()); }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }
@Override public IWindowsIdentity logonDomainUserEx(final String username, final String domain, final String password, final int logonType, final int logonProvider) { final HANDLEByReference phUser = new HANDLEByReference(); if (!Advapi32.INSTANCE.LogonUser(username, domain, password, logonType, logonProvider, phUser)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return new WindowsIdentityImpl(phUser.getValue()); }
@Override public IWindowsIdentity logonDomainUserEx(final String username, final String domain, final String password, final int logonType, final int logonProvider) { final HANDLEByReference phUser = new HANDLEByReference(); if (!Advapi32.INSTANCE.LogonUser(username, domain, password, logonType, logonProvider, phUser)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return new WindowsIdentityImpl(phUser.getValue()); }
private void addShutdownPrivilegeToProcess() { HANDLEByReference hToken = new HANDLEByReference(); LUID luid = new LUID(); Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), WinNT.TOKEN_ADJUST_PRIVILEGES, hToken); Advapi32.INSTANCE.LookupPrivilegeValue("", WinNT.SE_SHUTDOWN_NAME, luid); TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES(1); tp.Privileges[0] = new LUID_AND_ATTRIBUTES(luid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED)); Advapi32.INSTANCE.AdjustTokenPrivileges(hToken.getValue(), false, tp, tp.size(), null, new IntByReference()); }
@Override public IWindowsIdentity getIdentity() { final HANDLEByReference phContextToken = new HANDLEByReference(); final int rc = Secur32.INSTANCE.QuerySecurityContextToken(this.ctx, phContextToken); if (WinError.SEC_E_OK != rc) { throw new Win32Exception(rc); } return new WindowsIdentityImpl(phContextToken.getValue()); }