WSADATA initResult;
if (WSAStartup(requiredVersion, &initResult) != 0)
- throw rdr::SocketException("unable to initialise Winsock2", errorNumber);
+ throw rdr::socket_error("unable to initialise Winsock2", errorNumber);
#else
signal(SIGPIPE, SIG_IGN);
#endif
// Accept an incoming connection
if ((new_sock = ::accept(fd, nullptr, nullptr)) < 0)
- throw rdr::SocketException("unable to accept new connection", errorNumber);
+ throw rdr::socket_error("unable to accept new connection", errorNumber);
// Create the socket object & check connection is allowed
Socket* s = createSocket(new_sock);
if (::listen(sock, 5) < 0) {
int e = errorNumber;
closesocket(sock);
- throw rdr::SocketException("unable to set socket to listening mode", e);
+ throw rdr::socket_error("unable to set socket to listening mode", e);
}
fd = sock;
addr.sin_addr.s_addr = INADDR_ANY;
if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
- throw SocketException ("unable to create socket", errorNumber);
+ throw socket_error("unable to create socket", errorNumber);
addr.sin_port = 0;
if (bind (sock, (struct sockaddr *)&addr, sizeof (addr)) < 0)
- throw SocketException ("unable to find free port", errorNumber);
+ throw socket_error("unable to find free port", errorNumber);
socklen_t n = sizeof(addr);
if (getsockname (sock, (struct sockaddr *)&addr, &n) < 0)
- throw SocketException ("unable to get port number", errorNumber);
+ throw socket_error("unable to get port number", errorNumber);
closesocket (sock);
return ntohs(addr.sin_port);
hints.ai_next = nullptr;
if ((result = getaddrinfo(host, nullptr, &hints, &ai)) != 0) {
- throw GAIException("unable to resolve host by name", result);
+ throw getaddrinfo_error("unable to resolve host by name", result);
}
sock = -1;
if (sock == -1) {
err = errorNumber;
freeaddrinfo(ai);
- throw SocketException("unable to create socket", err);
+ throw socket_error("unable to create socket", err);
}
/* Attempt to connect to the remote host */
if (err == 0)
throw std::runtime_error("No useful address for host");
else
- throw SocketException("unable to connect to socket", err);
+ throw socket_error("unable to connect to socket", err);
}
// Take proper ownership of the socket
int sock;
if ((sock = socket (listenaddr->sa_family, SOCK_STREAM, 0)) < 0)
- throw SocketException("unable to create listening socket", errorNumber);
+ throw socket_error("unable to create listening socket", errorNumber);
memcpy (&sa, listenaddr, listenaddrlen);
#ifdef IPV6_V6ONLY
if (setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&one, sizeof(one))) {
int e = errorNumber;
closesocket(sock);
- throw SocketException("unable to set IPV6_V6ONLY", e);
+ throw socket_error("unable to set IPV6_V6ONLY", e);
}
}
#endif /* defined(IPV6_V6ONLY) */
(char *)&one, sizeof(one)) < 0) {
int e = errorNumber;
closesocket(sock);
- throw SocketException("unable to create listening socket", e);
+ throw socket_error("unable to create listening socket", e);
}
#endif
if (bind(sock, &sa.u.sa, listenaddrlen) == -1) {
int e = errorNumber;
closesocket(sock);
- throw SocketException("failed to bind socket", e);
+ throw socket_error("failed to bind socket", e);
}
listen(sock);
snprintf (service, sizeof (service) - 1, "%d", port);
service[sizeof (service) - 1] = '\0';
if ((result = getaddrinfo(addr, service, &hints, &ai)) != 0)
- throw GAIException("unable to resolve listening address", result);
+ throw getaddrinfo_error("unable to resolve listening address", result);
try {
createTcpListeners(listeners, ai);
try {
new_listeners.push_back(new TcpListener(current->ai_addr,
current->ai_addrlen));
- } catch (SocketException& e) {
+ } catch (socket_error& e) {
// Ignore this if it is due to lack of address family support on
// the interface or on the system
if (e.err != EADDRNOTAVAIL && e.err != EAFNOSUPPORT) {
}
if ((result = getaddrinfo (parts[0].c_str(), nullptr, &hints, &ai)) != 0) {
- throw GAIException("unable to resolve host by name", result);
+ throw getaddrinfo_error("unable to resolve host by name", result);
}
memcpy (&pattern.address.u.sa, ai->ai_addr, ai->ai_addrlen);
socklen_t salen;
if (strlen(path) >= sizeof(addr.sun_path))
- throw SocketException("socket path is too long", ENAMETOOLONG);
+ throw socket_error("socket path is too long", ENAMETOOLONG);
// - Create a socket
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1)
- throw SocketException("unable to create socket", errno);
+ throw socket_error("unable to create socket", errno);
// - Attempt to connect
memset(&addr, 0, sizeof(addr));
}
if (result == -1)
- throw SocketException("unable to connect to socket", err);
+ throw socket_error("unable to connect to socket", err);
setFd(sock);
}
int err, result;
if (strlen(path) >= sizeof(addr.sun_path))
- throw SocketException("socket path is too long", ENAMETOOLONG);
+ throw socket_error("socket path is too long", ENAMETOOLONG);
// - Create a socket
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
- throw SocketException("unable to create listening socket", errno);
+ throw socket_error("unable to create listening socket", errno);
// - Delete existing socket (ignore result)
unlink(path);
umask(saved_umask);
if (result < 0) {
close(fd);
- throw SocketException("unable to bind listening socket", err);
+ throw socket_error("unable to bind listening socket", err);
}
// - Set socket mode
if (chmod(path, mode) < 0) {
err = errno;
close(fd);
- throw SocketException("unable to set socket mode", err);
+ throw socket_error("unable to set socket mode", err);
}
listen(fd);
systemMutex = new pthread_mutex_t;
ret = pthread_mutex_init((pthread_mutex_t*)systemMutex, nullptr);
if (ret != 0)
- throw rdr::PosixException("Failed to create mutex", ret);
+ throw rdr::posix_error("Failed to create mutex", ret);
#endif
}
ret = pthread_mutex_lock((pthread_mutex_t*)systemMutex);
if (ret != 0)
- throw rdr::PosixException("Failed to lock mutex", ret);
+ throw rdr::posix_error("Failed to lock mutex", ret);
#endif
}
ret = pthread_mutex_unlock((pthread_mutex_t*)systemMutex);
if (ret != 0)
- throw rdr::PosixException("Failed to unlock mutex", ret);
+ throw rdr::posix_error("Failed to unlock mutex", ret);
#endif
}
systemCondition = new pthread_cond_t;
ret = pthread_cond_init((pthread_cond_t*)systemCondition, nullptr);
if (ret != 0)
- throw rdr::PosixException("Failed to create condition variable", ret);
+ throw rdr::posix_error("Failed to create condition variable", ret);
#endif
}
(CRITICAL_SECTION*)mutex->systemMutex,
INFINITE);
if (!ret)
- throw rdr::Win32Exception("Failed to wait on condition variable", GetLastError());
+ throw rdr::win32_error("Failed to wait on condition variable", GetLastError());
#else
int ret;
ret = pthread_cond_wait((pthread_cond_t*)systemCondition,
(pthread_mutex_t*)mutex->systemMutex);
if (ret != 0)
- throw rdr::PosixException("Failed to wait on condition variable", ret);
+ throw rdr::posix_error("Failed to wait on condition variable", ret);
#endif
}
ret = pthread_cond_signal((pthread_cond_t*)systemCondition);
if (ret != 0)
- throw rdr::PosixException("Failed to signal condition variable", ret);
+ throw rdr::posix_error("Failed to signal condition variable", ret);
#endif
}
ret = pthread_cond_broadcast((pthread_cond_t*)systemCondition);
if (ret != 0)
- throw rdr::PosixException("Failed to broadcast condition variable", ret);
+ throw rdr::posix_error("Failed to broadcast condition variable", ret);
#endif
}
#ifdef WIN32
*(HANDLE*)threadId = CreateThread(nullptr, 0, startRoutine, this, 0, nullptr);
if (*(HANDLE*)threadId == nullptr)
- throw rdr::Win32Exception("Failed to create thread", GetLastError());
+ throw rdr::win32_error("Failed to create thread", GetLastError());
#else
int ret;
sigset_t all, old;
sigfillset(&all);
ret = pthread_sigmask(SIG_SETMASK, &all, &old);
if (ret != 0)
- throw rdr::PosixException("Failed to mask signals", ret);
+ throw rdr::posix_error("Failed to mask signals", ret);
ret = pthread_create((pthread_t*)threadId, nullptr, startRoutine, this);
pthread_sigmask(SIG_SETMASK, &old, nullptr);
if (ret != 0)
- throw rdr::PosixException("Failed to create thread", ret);
+ throw rdr::posix_error("Failed to create thread", ret);
#endif
running = true;
ret = WaitForSingleObject(*(HANDLE*)threadId, INFINITE);
if (ret != WAIT_OBJECT_0)
- throw rdr::Win32Exception("Failed to join thread", GetLastError());
+ throw rdr::win32_error("Failed to join thread", GetLastError());
#else
int ret;
ret = pthread_join(*(pthread_t*)threadId, nullptr);
if (ret != 0)
- throw rdr::PosixException("Failed to join thread", ret);
+ throw rdr::posix_error("Failed to join thread", ret);
#endif
}
using namespace rdr;
-GAIException::GAIException(const char* s, int err_)
+getaddrinfo_error::getaddrinfo_error(const char* s, int err_)
: std::runtime_error(rfb::format("%s: %s (%d)", s,
strerror(err_).c_str(), err_)),
err(err_)
{
}
-GAIException::GAIException(const std::string& s, int err_)
+getaddrinfo_error::getaddrinfo_error(const std::string& s, int err_)
: std::runtime_error(rfb::format("%s: %s (%d)", s.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
-std::string GAIException::strerror(int err_) const
+std::string getaddrinfo_error::strerror(int err_) const
{
#ifdef _WIN32
char str[256];
#endif
}
-PosixException::PosixException(const char* what_arg, int err_)
+posix_error::posix_error(const char* what_arg, int err_)
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}
-PosixException::PosixException(const std::string& what_arg, int err_)
+posix_error::posix_error(const std::string& what_arg, int err_)
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
-std::string PosixException::strerror(int err_) const
+std::string posix_error::strerror(int err_) const
{
#ifdef _WIN32
char str[256];
}
#ifdef WIN32
-Win32Exception::Win32Exception(const char* what_arg, unsigned err_)
+win32_error::win32_error(const char* what_arg, unsigned err_)
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}
-Win32Exception::Win32Exception(const std::string& what_arg, unsigned err_)
+win32_error::win32_error(const std::string& what_arg, unsigned err_)
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
-std::string Win32Exception::strerror(unsigned err_) const
+std::string win32_error::strerror(unsigned err_) const
{
wchar_t wstr[256];
char str[256];
namespace rdr {
- class PosixException : public std::runtime_error {
+ class posix_error : public std::runtime_error {
public:
int err;
- PosixException(const char* what_arg, int err_);
- PosixException(const std::string& what_arg, int err_);
+ posix_error(const char* what_arg, int err_);
+ posix_error(const std::string& what_arg, int err_);
private:
std::string strerror(int err_) const;
};
#ifdef WIN32
- class Win32Exception : public std::runtime_error {
+ class win32_error : public std::runtime_error {
public:
unsigned err;
- Win32Exception(const char* what_arg, unsigned err_);
- Win32Exception(const std::string& what_arg, unsigned err_);
+ win32_error(const char* what_arg, unsigned err_);
+ win32_error(const std::string& what_arg, unsigned err_);
private:
std::string strerror(unsigned err_) const;
};
#endif
#ifdef WIN32
- class SocketException : public Win32Exception {
+ class socket_error : public win32_error {
public:
- SocketException(const char* what_arg, unsigned err_) : Win32Exception(what_arg, err_) {}
- SocketException(const std::string& what_arg, unsigned err_) : Win32Exception(what_arg, err_) {}
+ socket_error(const char* what_arg, unsigned err_) : win32_error(what_arg, err_) {}
+ socket_error(const std::string& what_arg, unsigned err_) : win32_error(what_arg, err_) {}
};
#else
- class SocketException : public PosixException {
+ class socket_error : public posix_error {
public:
- SocketException(const char* what_arg, unsigned err_) : PosixException(what_arg, err_) {}
- SocketException(const std::string& what_arg, unsigned err_) : PosixException(what_arg, err_) {}
+ socket_error(const char* what_arg, unsigned err_) : posix_error(what_arg, err_) {}
+ socket_error(const std::string& what_arg, unsigned err_) : posix_error(what_arg, err_) {}
};
#endif
- class GAIException : public std::runtime_error {
+ class getaddrinfo_error : public std::runtime_error {
public:
int err;
- GAIException(const char* s, int err_);
- GAIException(const std::string& s, int err_);
+ getaddrinfo_error(const char* s, int err_);
+ getaddrinfo_error(const std::string& s, int err_);
private:
std::string strerror(int err_) const;
};
- class EndOfStream : public std::runtime_error {
+ class end_of_stream : public std::runtime_error {
public:
- EndOfStream() : std::runtime_error("End of stream") {}
+ end_of_stream() : std::runtime_error("End of stream") {}
};
}
} while (n < 0 && errorNumber == EINTR);
if (n < 0)
- throw SocketException("select", errorNumber);
+ throw socket_error("select", errorNumber);
if (n == 0)
return 0;
} while (n < 0 && errorNumber == EINTR);
if (n < 0)
- throw SocketException("read", errorNumber);
+ throw socket_error("read", errorNumber);
if (n == 0)
- throw EndOfStream();
+ throw end_of_stream();
return n;
}
} while (n < 0 && errorNumber == EINTR);
if (n < 0)
- throw SocketException("select", errorNumber);
+ throw socket_error("select", errorNumber);
if (n == 0)
return 0;
} while (n < 0 && (errorNumber == EINTR));
if (n < 0)
- throw SocketException("write", errorNumber);
+ throw socket_error("write", errorNumber);
gettimeofday(&lastWrite, nullptr);
{
file = fopen(fileName, "rb");
if (!file)
- throw PosixException("fopen", errno);
+ throw posix_error("fopen", errno);
}
FileInStream::~FileInStream(void) {
size_t n = fread((uint8_t*)end, 1, availSpace(), file);
if (n == 0) {
if (ferror(file))
- throw PosixException("fread", errno);
+ throw posix_error("fread", errno);
if (feof(file))
- throw EndOfStream();
+ throw end_of_stream();
return false;
}
end += n;
private:
- bool overrun(size_t /*needed*/) override { throw EndOfStream(); }
+ bool overrun(size_t /*needed*/) override { throw end_of_stream(); }
const uint8_t* start;
bool deleteWhenDone;
};
#ifdef RFB_HAVE_WINCRYPT
if (provider) {
if (!CryptGenRandom(provider, availSpace(), (uint8_t*)end))
- throw rdr::Win32Exception("unable to CryptGenRandom", GetLastError());
+ throw rdr::win32_error("unable to CryptGenRandom", GetLastError());
end += availSpace();
} else {
#else
if (fp) {
size_t n = fread((uint8_t*)end, 1, availSpace(), fp);
if (n <= 0)
- throw rdr::PosixException("reading /dev/urandom or /dev/random failed",
- errno);
+ throw rdr::posix_error("reading /dev/urandom or /dev/random "
+ "failed", errno);
end += n;
} else {
#else
using namespace rdr;
#ifdef HAVE_GNUTLS
-TLSException::TLSException(const char* s, int err_)
+tls_error::tls_error(const char* s, int err_)
: std::runtime_error(rfb::format("%s: %s (%d)", s,
gnutls_strerror(err_), err_)),
err(err_)
namespace rdr {
- class TLSException : public std::runtime_error {
+ class tls_error : public std::runtime_error {
public:
int err;
- TLSException(const char* s, int err_);
+ tls_error(const char* s, int err_);
};
}
size = in->avail();
in->readBytes((uint8_t*)data, size);
- } catch (EndOfStream&) {
+ } catch (end_of_stream&) {
return 0;
- } catch (SocketException& e) {
+ } catch (socket_error& e) {
vlog.error("Failure reading TLS data: %s", e.what());
gnutls_transport_set_errno(self->session, e.err);
- self->saved_exception = new SocketException(e);
+ self->saved_exception = new socket_error(e);
return -1;
} catch (std::exception& e) {
vlog.error("Failure reading TLS data: %s", e.what());
throw *saved_exception;
if (n < 0)
- throw TLSException("readTLS", n);
+ throw tls_error("readTLS", n);
if (n == 0)
- throw EndOfStream();
+ throw end_of_stream();
return n;
}
try {
out->writeBytes((const uint8_t*)data, size);
out->flush();
- } catch (SocketException& e) {
+ } catch (socket_error& e) {
vlog.error("Failure sending TLS data: %s", e.what());
gnutls_transport_set_errno(self->session, e.err);
- self->saved_exception = new SocketException(e);
+ self->saved_exception = new socket_error(e);
return -1;
} catch (std::exception& e) {
vlog.error("Failure sending TLS data: %s", e.what());
throw *saved_exception;
if (n < 0)
- throw TLSException("writeTLS", n);
+ throw tls_error("writeTLS", n);
return n;
}
if (sscanf(verStr, "RFB %03d.%03d\n",
&majorVersion, &minorVersion) != 2) {
state_ = RFBSTATE_INVALID;
- throw ProtocolException("reading version failed: not an RFB server?");
+ throw protocol_error("reading version failed: not an RFB server?");
}
server.setVersion(majorVersion, minorVersion);
vlog.error("Server gave unsupported RFB protocol version %d.%d",
server.majorVersion, server.minorVersion);
state_ = RFBSTATE_INVALID;
- throw ProtocolException(format("Server gave unsupported RFB "
- "protocol version %d.%d",
- server.majorVersion,
- server.minorVersion));
+ throw protocol_error(format("Server gave unsupported RFB protocol "
+ "version %d.%d",
+ server.majorVersion,
+ server.minorVersion));
} else if (server.beforeVersion(3,7)) {
server.setVersion(3,3);
} else if (server.afterVersion(3,8)) {
secType = secTypeInvalid;
} else {
vlog.error("Unknown 3.3 security type %d", secType);
- throw ProtocolException("Unknown 3.3 security type");
+ throw protocol_error("Unknown 3.3 security type");
}
} else {
if (secType == secTypeInvalid) {
state_ = RFBSTATE_INVALID;
vlog.error("No matching security types");
- throw ProtocolException("No matching security types");
+ throw protocol_error("No matching security types");
}
state_ = RFBSTATE_SECURITY;
vlog.debug("auth failed - too many tries");
break;
default:
- throw ProtocolException("Unknown security result from server");
+ throw protocol_error("Unknown security result from server");
}
if (server.beforeVersion(3,8)) {
state_ = RFBSTATE_INVALID;
- throw AuthFailureException("Authentication failed");
+ throw auth_error("Authentication failed");
}
state_ = RFBSTATE_SECURITY_REASON;
reason[len] = '\0';
state_ = RFBSTATE_INVALID;
- throw AuthFailureException(reason.data());
+ throw auth_error(reason.data());
}
bool CConnection::processInitMsg()
bool processSecurityResultMsg();
bool processSecurityReasonMsg();
bool processInitMsg();
- void throwAuthFailureException();
+ void throwAuthError();
void securityCompleted();
void requestNewUpdate();
ret = readEndOfContinuousUpdates();
break;
default:
- throw ProtocolException(format("Unknown message type %d", currentMsgType));
+ throw protocol_error(format("Unknown message type %d", currentMsgType));
}
if (ret)
return false;
if (len < 4)
- throw ProtocolException("Invalid extended clipboard message");
+ throw protocol_error("Invalid extended clipboard message");
if (len > maxCutText) {
vlog.error("Extended clipboard message too long (%d bytes) - ignoring", len);
is->skip(len);
}
if (len < (int32_t)(4 + 4*num))
- throw ProtocolException("Invalid extended clipboard message");
+ throw protocol_error("Invalid extended clipboard message");
num = 0;
for (i = 0;i < 16;i++) {
continue;
if (!zis.hasData(4))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
lengths[num] = zis.readU32();
size_t chunk;
if (!zis.hasData(1))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
chunk = zis.avail();
if (chunk > lengths[num])
}
if (!zis.hasData(lengths[num]))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
buffers[num] = new uint8_t[lengths[num]];
zis.readBytes(buffers[num], lengths[num]);
handler->handleClipboardNotify(flags);
break;
default:
- throw ProtocolException("Invalid extended clipboard action");
+ throw protocol_error("Invalid extended clipboard action");
}
}
vlog.error("Rect too big: %dx%d at %d,%d exceeds %dx%d",
r.width(), r.height(), r.tl.x, r.tl.y,
handler->server.width(), handler->server.height());
- throw ProtocolException("Rect too big");
+ throw protocol_error("Rect too big");
}
if (r.is_empty())
bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot)
{
if (width > maxCursorSize || height > maxCursorSize)
- throw ProtocolException("Too big cursor");
+ throw protocol_error("Too big cursor");
std::vector<uint8_t> rgba(width*height*4);
bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot)
{
if (width > maxCursorSize || height > maxCursorSize)
- throw ProtocolException("Too big cursor");
+ throw protocol_error("Too big cursor");
int data_len = width * height * (handler->server.pf().bpp/8);
int mask_len = ((width+7)/8) * height;
bool CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hotspot)
{
if (width > maxCursorSize || height > maxCursorSize)
- throw ProtocolException("Too big cursor");
+ throw protocol_error("Too big cursor");
const PixelFormat rgbaPF(32, 32, false, true, 255, 255, 255, 16, 8, 0);
ManagedPixelBuffer pb(rgbaPF, width, height);
bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot)
{
if (width > maxCursorSize || height > maxCursorSize)
- throw ProtocolException("Too big cursor");
+ throw protocol_error("Too big cursor");
uint8_t type;
handler->setCursor(width, height, hotspot, data.data());
} else {
- throw ProtocolException("Unknown cursor type");
+ throw protocol_error("Unknown cursor type");
}
return true;
uint16_t gen = is->readU16();
keyLength = is->readU16();
if (keyLength < MinKeyLength)
- throw ProtocolException("DH key is too short");
+ throw protocol_error("DH key is too short");
if (keyLength > MaxKeyLength)
- throw ProtocolException("DH key is too long");
+ throw protocol_error("DH key is too long");
if (!is->hasDataOrRestore(keyLength * 2))
return false;
is->clearRestorePoint();
is->setRestorePoint();
serverKeyLength = is->readU32();
if (serverKeyLength < MinKeyLength)
- throw ProtocolException("server key is too short");
+ throw protocol_error("server key is too short");
if (serverKeyLength > MaxKeyLength)
- throw ProtocolException("server key is too long");
+ throw protocol_error("server key is too long");
size_t size = (serverKeyLength + 7) / 8;
if (!is->hasDataOrRestore(size * 2))
return false;
nettle_mpz_set_str_256_u(serverKey.n, size, serverKeyN);
nettle_mpz_set_str_256_u(serverKey.e, size, serverKeyE);
if (!rsa_public_key_prepare(&serverKey))
- throw ProtocolException("server key is invalid");
+ throw protocol_error("server key is invalid");
return true;
}
"Please verify that the information is correct and press \"Yes\". "
"Otherwise press \"No\"", f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]);
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, title, text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
}
void CSecurityRSAAES::writeRandom()
is->setRestorePoint();
size_t size = is->readU16();
if (size != clientKey.size)
- throw ProtocolException("client key length doesn't match");
+ throw protocol_error("client key length doesn't match");
if (!is->hasDataOrRestore(size))
return false;
is->clearRestorePoint();
if (!rsa_decrypt(&clientKey, &randomSize, serverRandom, x) ||
randomSize != (size_t)keySize / 8) {
mpz_clear(x);
- throw ProtocolException("failed to decrypt server random");
+ throw protocol_error("failed to decrypt server random");
}
mpz_clear(x);
return true;
sha256_digest(&ctx, hashSize, realHash);
}
if (memcmp(hash, realHash, hashSize) != 0)
- throw ProtocolException("hash doesn't match");
+ throw protocol_error("hash doesn't match");
return true;
}
return false;
subtype = rais->readU8();
if (subtype != secTypeRA2UserPass && subtype != secTypeRA2Pass)
- throw ProtocolException("unknown RSA-AES subtype");
+ throw protocol_error("unknown RSA-AES subtype");
return true;
}
{
int err = gnutls_global_init();
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_global_init()", err);
+ throw rdr::tls_error("gnutls_global_init()", err);
}
void CSecurityTLS::shutdown()
return false;
if (is->readU8() == 0)
- throw ProtocolException("Server failed to initialize TLS session");
+ throw protocol_error("Server failed to initialize TLS session");
ret = gnutls_init(&session, GNUTLS_CLIENT);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_init()", ret);
+ throw rdr::tls_error("gnutls_init()", ret);
ret = gnutls_set_default_priority(session);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_set_default_priority()", ret);
+ throw rdr::tls_error("gnutls_set_default_priority()", ret);
setParam();
vlog.error("TLS Handshake failed: %s\n", gnutls_strerror (err));
shutdown();
- throw rdr::TLSException("TLS Handshake failed", err);
+ throw rdr::tls_error("TLS Handshake failed", err);
}
vlog.debug("TLS handshake completed with %s",
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_priority_direct()", ret);
+ throw rdr::tls_error("gnutls_set_priority_direct()", ret);
}
} else if (anon) {
const char *err;
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_default_priority_append()", ret);
+ throw rdr::tls_error("gnutls_set_default_priority_append()", ret);
}
#else
// We don't know what the system default priority is, so we guess
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_priority_direct()", ret);
+ throw rdr::tls_error("gnutls_set_priority_direct()", ret);
}
#endif
}
if (anon) {
ret = gnutls_anon_allocate_client_credentials(&anon_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_anon_allocate_client_credentials()", ret);
+ throw rdr::tls_error("gnutls_anon_allocate_client_credentials()", ret);
ret = gnutls_credentials_set(session, GNUTLS_CRD_ANON, anon_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_credentials_set()", ret);
+ throw rdr::tls_error("gnutls_credentials_set()", ret);
vlog.debug("Anonymous session has been set");
} else {
ret = gnutls_certificate_allocate_credentials(&cert_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_certificate_allocate_credentials()", ret);
+ throw rdr::tls_error("gnutls_certificate_allocate_credentials()", ret);
if (gnutls_certificate_set_x509_system_trust(cert_cred) < 1)
vlog.error("Could not load system certificate trust store");
ret = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, cert_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_credentials_set()", ret);
+ throw rdr::tls_error("gnutls_credentials_set()", ret);
if (gnutls_server_name_set(session, GNUTLS_NAME_DNS,
client->getServerName(),
return;
if (gnutls_certificate_type_get(session) != GNUTLS_CRT_X509)
- throw ProtocolException("unsupported certificate type");
+ throw protocol_error("unsupported certificate type");
err = gnutls_certificate_verify_peers2(session, &status);
if (err != 0) {
vlog.error("server certificate verification failed: %s", gnutls_strerror(err));
- throw rdr::TLSException("server certificate verification()", err);
+ throw rdr::tls_error("server certificate verification()", err);
}
if (status != 0) {
&status_str,
0);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("Failed to get certificate error description", err);
+ throw rdr::tls_error("Failed to get certificate error description", err);
error = (const char*)status_str.data;
gnutls_free(status_str.data);
- throw ProtocolException(format("Invalid server certificate: %s",
+ throw protocol_error(format("Invalid server certificate: %s",
error.c_str()));
}
&status_str,
0);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("Failed to get certificate error description", err);
+ throw rdr::tls_error("Failed to get certificate error description", err);
vlog.info("Server certificate errors: %s", status_str.data);
cert_list = gnutls_certificate_get_peers(session, &cert_list_size);
if (!cert_list_size)
- throw ProtocolException("empty certificate chain");
+ throw protocol_error("empty certificate chain");
/* Process only server's certificate, not issuer's certificate */
gnutls_x509_crt_t crt;
err = gnutls_x509_crt_import(crt, &cert_list[0], GNUTLS_X509_FMT_DER);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("Failed to decode server certificate", err);
+ throw rdr::tls_error("Failed to decode server certificate", err);
if (gnutls_x509_crt_check_hostname(crt, client->getServerName()) == 0) {
vlog.info("Server certificate doesn't match given server name");
if ((known != GNUTLS_E_NO_CERTIFICATE_FOUND) &&
(known != GNUTLS_E_CERTIFICATE_KEY_MISMATCH)) {
- throw rdr::TLSException("Could not load known hosts database", known);
+ throw rdr::tls_error("Could not load known hosts database", known);
}
err = gnutls_x509_crt_print(crt, GNUTLS_CRT_PRINT_ONELINE, &info);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("Could not find certificate to display", err);
+ throw rdr::tls_error("Could not find certificate to display", err);
len = strlen((char*)info.data);
for (size_t i = 0; i < len - 1; i++) {
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unknown certificate issuer",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~(GNUTLS_CERT_INVALID |
GNUTLS_CERT_SIGNER_NOT_FOUND |
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Certificate is not yet valid",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_NOT_ACTIVATED;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Expired certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_EXPIRED;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Insecure certificate algorithm",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_INSECURE_ALGORITHM;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Certificate hostname mismatch",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
}
} else if (known == GNUTLS_E_CERTIFICATE_KEY_MISMATCH) {
std::string text;
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~(GNUTLS_CERT_INVALID |
GNUTLS_CERT_SIGNER_NOT_FOUND |
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_NOT_ACTIVATED;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_EXPIRED;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
status &= ~GNUTLS_CERT_INSECURE_ALGORITHM;
}
if (!cc->showMsgBox(MsgBoxFlags::M_YESNO,
"Unexpected server certificate",
text.c_str()))
- throw AuthCancelledException();
+ throw auth_cancelled();
}
}
os->writeU8(0);
os->writeU8(0);
os->flush();
- throw ProtocolException("The server reported an unsupported VeNCrypt version");
+ throw protocol_error("The server reported an unsupported VeNCrypt version");
}
haveSentVersion = true;
return false;
if (is->readU8())
- throw ProtocolException("The server reported it could not "
- "support the VeNCrypt version");
+ throw protocol_error("The server reported it could not "
+ "support the VeNCrypt version");
haveAgreedVersion = true;
}
nAvailableTypes = is->readU8();
if (!nAvailableTypes)
- throw ProtocolException("The server reported no VeNCrypt sub-types");
+ throw protocol_error("The server reported no VeNCrypt sub-types");
availableTypes = new uint32_t[nAvailableTypes];
haveNumberOfTypes = true;
/* Set up the stack according to the chosen type: */
if (chosenType == secTypeInvalid || chosenType == secTypeVeNCrypt)
- throw ProtocolException("No valid VeNCrypt sub-type");
+ throw protocol_error("No valid VeNCrypt sub-type");
vlog.info("Choosing security type %s (%d)", secTypeName(chosenType),
chosenType);
* happen, since if the server supports 0 sub-types, it doesn't support
* this security type
*/
- throw ProtocolException("The server reported 0 VeNCrypt sub-types");
+ throw protocol_error("The server reported 0 VeNCrypt sub-types");
}
return csecurity->processMsg();
if (!Decoder::supported(encoding)) {
vlog.error("Unknown encoding %d", encoding);
- throw ProtocolException("Unknown encoding");
+ throw protocol_error("Unknown encoding");
}
if (!decoders[encoding]) {
decoders[encoding] = Decoder::createDecoder(encoding);
if (!decoders[encoding]) {
vlog.error("Unknown encoding %d", encoding);
- throw ProtocolException("Unknown encoding");
+ throw protocol_error("Unknown encoding");
}
}
#include <stdexcept>
namespace rfb {
- class ProtocolException : public std::runtime_error {
+ class protocol_error : public std::runtime_error {
public:
- ProtocolException(const char* what_arg) : std::runtime_error(what_arg) {}
- ProtocolException(const std::string& what_arg) : std::runtime_error(what_arg) {}
+ protocol_error(const char* what_arg) : std::runtime_error(what_arg) {}
+ protocol_error(const std::string& what_arg) : std::runtime_error(what_arg) {}
};
- class AuthFailureException : public std::runtime_error {
+ class auth_error : public std::runtime_error {
public:
- AuthFailureException(const char* reason) : std::runtime_error(reason) {}
- AuthFailureException(std::string& reason) : std::runtime_error(reason) {}
+ auth_error(const char* reason) : std::runtime_error(reason) {}
+ auth_error(std::string& reason) : std::runtime_error(reason) {}
};
- class AuthCancelledException : public std::runtime_error {
+ class auth_cancelled : public std::runtime_error {
public:
- AuthCancelledException()
+ auth_cancelled()
: std::runtime_error("Authentication cancelled") {}
};
}
int w = ((wh >> 4) & 15) + 1;
int h = (wh & 15) + 1;
if (x + w > 16 || y + h > 16) {
- throw ProtocolException("HEXTILE_DECODE: Hextile out of bounds");
+ throw protocol_error("HEXTILE_DECODE: Hextile out of bounds");
}
ptr = buf + y * t.width() + x;
int rowAdd = t.width() - w;
jpeg_abort_decompress(dinfo);
if (dstBufIsTemp && dstBuf) delete[] dstBuf;
if (rowPointer) delete[] rowPointer;
- throw ProtocolException("Tight Decoding: Wrong JPEG data received.\n");
+ throw protocol_error("Tight Decoding: Wrong JPEG data received.\n");
}
while (dinfo->output_scanline < dinfo->output_height) {
}
if (!isSane())
- throw ProtocolException("invalid pixel format");
+ throw protocol_error("invalid pixel format");
updateState();
}
int h = is->readU16();
if (((x+w) > r.width()) || ((y+h) > r.height()))
- throw ProtocolException("RRE decode error");
+ throw protocol_error("RRE decode error");
pb->fillRect(pf, Rect(r.tl.x+x, r.tl.y+y, r.tl.x+x+w, r.tl.y+y+h), &pix);
}
if (sscanf(verStr, "RFB %03d.%03d\n",
&majorVersion, &minorVersion) != 2) {
state_ = RFBSTATE_INVALID;
- throw ProtocolException("reading version failed: not an RFB client?");
+ throw protocol_error("reading version failed: not an RFB client?");
}
client.setVersion(majorVersion, minorVersion);
secTypes = security.GetEnabledSecTypes();
if (std::find(secTypes.begin(), secTypes.end(),
secType) == secTypes.end())
- throw ProtocolException("Requested security type not available");
+ throw protocol_error("Requested security type not available");
vlog.info("Client requests security type %s(%d)",
secTypeName(secType),secType);
try {
if (!ssecurity->processMsg())
return false;
- } catch (AuthFailureException& e) {
- vlog.error("AuthFailureException: %s", e.what());
+ } catch (auth_error& e) {
+ vlog.error("Authentication error: %s", e.what());
state_ = RFBSTATE_SECURITY_FAILURE;
// Introduce a slight delay of the authentication failure response
// to make it difficult to brute force a password
}
state_ = RFBSTATE_INVALID;
- throw ProtocolException(message);
+ throw protocol_error(message);
}
void SConnection::failConnection(const std::string& message)
} else {
state_ = RFBSTATE_INVALID;
if (reason)
- throw AuthFailureException(reason);
+ throw auth_error(reason);
else
- throw AuthFailureException("Connection rejected");
+ throw auth_error("Connection rejected");
}
}
// data is available.
bool processMsg();
- // approveConnection() is called to either accept or reject the connection.
- // If accept is false, the reason string gives the reason for the
- // rejection. It can either be called directly from queryConnection() or
- // later, after queryConnection() has returned. It can only be called when
- // in state RFBSTATE_QUERYING. On rejection, an AuthFailureException is
- // thrown, so this must be handled appropriately by the caller.
+ // approveConnection() is called to either accept or reject the
+ // connection. If accept is false, the reason string gives the
+ // reason for the rejection. It can either be called directly from
+ // queryConnection() or later, after queryConnection() has returned.
+ // It can only be called when in state RFBSTATE_QUERYING. On
+ // rejection, an auth_error is thrown, so this must be handled
+ // appropriately by the caller.
void approveConnection(bool accept, const char* reason=nullptr);
break;
default:
vlog.error("unknown message type %d", currentMsgType);
- throw ProtocolException("unknown message type");
+ throw protocol_error("unknown message type");
}
if (ret)
return false;
if (len < 4)
- throw ProtocolException("Invalid extended clipboard message");
+ throw protocol_error("Invalid extended clipboard message");
if (len > maxCutText) {
vlog.error("Extended clipboard message too long (%d bytes) - ignoring", len);
is->skip(len);
}
if (len < (int32_t)(4 + 4*num))
- throw ProtocolException("Invalid extended clipboard message");
+ throw protocol_error("Invalid extended clipboard message");
num = 0;
for (i = 0;i < 16;i++) {
continue;
if (!zis.hasData(4))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
lengths[num] = zis.readU32();
size_t chunk;
if (!zis.hasData(1))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
chunk = zis.avail();
if (chunk > lengths[num])
}
if (!zis.hasData(lengths[num]))
- throw ProtocolException("Extended clipboard decode error");
+ throw protocol_error("Extended clipboard decode error");
buffers[num] = new uint8_t[lengths[num]];
zis.readBytes(buffers[num], lengths[num]);
handler->handleClipboardNotify(flags);
break;
default:
- throw ProtocolException("Invalid extended clipboard action");
+ throw protocol_error("Invalid extended clipboard action");
}
}
ret = readQEMUKeyEvent();
break;
default:
- throw ProtocolException(format("unknown QEMU submessage type %d", subType));
+ throw protocol_error(format("unknown QEMU submessage type %d", subType));
}
if (!ret) {
// derived class for a particular security type overrides the processMsg()
// method.
-// processMsg() is called first when the security type has been decided on, and
-// will keep being called whenever there is data to read from the client. It
-// should return false when it needs more data, or true when the connection has
-// been successfully authenticated. In the event of authentication failure an
-// AuthFailureException should be thrown - this will result in a "failed"
-// security result being sent to the client with the str() from the exception
-// being sent as the reason. Any other type of failure should be indicated by
-// some other kind of exception which will cause the connection to be aborted.
+// processMsg() is called first when the security type has been decided
+// on, and will keep being called whenever there is data to read from
+// the client. It should return false when it needs more data, or true
+// when the connection has been successfully authenticated. In the
+// event of authentication failure an auth_error should be thrown - this
+// will result in a "failed" security result being sent to the client
+// with the str() from the exception being sent as the reason. Any
+// other type of failure should be indicated by some other kind of
+// exception which will cause the connection to be aborted.
//
// processMsg() must never block (or at least must never block until the client
// has been authenticated) - this is to prevent denial of service attacks.
ulen = is->readU32();
if (ulen >= sizeof(username))
- throw AuthFailureException("Too long username");
+ throw auth_error("Too long username");
plen = is->readU32();
if (plen >= sizeof(password))
- throw AuthFailureException("Too long password");
+ throw auth_error("Too long password");
state = 1;
}
username[ulen] = 0;
plen = 0;
if (!valid->validate(sc, username, password))
- throw AuthFailureException("Authentication failed");
+ throw auth_error("Authentication failed");
}
return true;
{
FILE* file = fopen(keyFile, "rb");
if (!file)
- throw rdr::PosixException("failed to open key file", errno);
+ throw rdr::posix_error("failed to open key file", errno);
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
if (size == 0 || size > MaxKeyFileSize) {
std::vector<uint8_t> data(size);
if (fread(data.data(), 1, data.size(), file) != size) {
fclose(file);
- throw rdr::PosixException("failed to read key", errno);
+ throw rdr::posix_error("failed to read key", errno);
}
fclose(file);
is->setRestorePoint();
clientKeyLength = is->readU32();
if (clientKeyLength < MinKeyLength)
- throw ProtocolException("client key is too short");
+ throw protocol_error("client key is too short");
if (clientKeyLength > MaxKeyLength)
- throw ProtocolException("client key is too long");
+ throw protocol_error("client key is too long");
size_t size = (clientKeyLength + 7) / 8;
if (!is->hasDataOrRestore(size * 2))
return false;
nettle_mpz_set_str_256_u(clientKey.n, size, clientKeyN);
nettle_mpz_set_str_256_u(clientKey.e, size, clientKeyE);
if (!rsa_public_key_prepare(&clientKey))
- throw ProtocolException("client key is invalid");
+ throw protocol_error("client key is invalid");
return true;
}
is->setRestorePoint();
size_t size = is->readU16();
if (size != serverKey.size)
- throw ProtocolException("server key length doesn't match");
+ throw protocol_error("server key length doesn't match");
if (!is->hasDataOrRestore(size))
return false;
is->clearRestorePoint();
if (!rsa_decrypt(&serverKey, &randomSize, clientRandom, x) ||
randomSize != (size_t)keySize / 8) {
mpz_clear(x);
- throw ProtocolException("failed to decrypt client random");
+ throw protocol_error("failed to decrypt client random");
}
mpz_clear(x);
return true;
sha256_digest(&ctx, hashSize, realHash);
}
if (memcmp(hash, realHash, hashSize) != 0)
- throw ProtocolException("hash doesn't match");
+ throw protocol_error("hash doesn't match");
return true;
}
#endif
if (!valid->validate(sc, username, password)) {
delete valid;
- throw AuthFailureException("Authentication failed");
+ throw auth_error("Authentication failed");
}
delete valid;
#else
return;
}
- throw AuthFailureException("Authentication failed");
+ throw auth_error("Authentication failed");
}
const char* SSecurityRSAAES::getUserName() const
ret = gnutls_global_init();
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_global_init()", ret);
+ throw rdr::tls_error("gnutls_global_init()", ret);
}
void SSecurityTLS::shutdown()
err = gnutls_init(&session, GNUTLS_SERVER);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_init()", err);
+ throw rdr::tls_error("gnutls_init()", err);
err = gnutls_set_default_priority(session);
if (err != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_set_default_priority()", err);
+ throw rdr::tls_error("gnutls_set_default_priority()", err);
try {
setParams();
}
vlog.error("TLS Handshake failed: %s", gnutls_strerror (err));
shutdown();
- throw rdr::TLSException("TLS Handshake failed", err);
+ throw rdr::tls_error("TLS Handshake failed", err);
}
vlog.debug("TLS handshake completed with %s",
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_priority_direct()", ret);
+ throw rdr::tls_error("gnutls_set_priority_direct()", ret);
}
} else if (anon) {
const char *err;
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_default_priority_append()", ret);
+ throw rdr::tls_error("gnutls_set_default_priority_append()", ret);
}
#else
// We don't know what the system default priority is, so we guess
if (ret != GNUTLS_E_SUCCESS) {
if (ret == GNUTLS_E_INVALID_REQUEST)
vlog.error("GnuTLS priority syntax error at: %s", err);
- throw rdr::TLSException("gnutls_set_priority_direct()", ret);
+ throw rdr::tls_error("gnutls_set_priority_direct()", ret);
}
#endif
}
#if defined (SSECURITYTLS__USE_DEPRECATED_DH)
ret = gnutls_dh_params_init(&dh_params);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_dh_params_init()", ret);
+ throw rdr::tls_error("gnutls_dh_params_init()", ret);
ret = gnutls_dh_params_import_pkcs3(dh_params, &ffdhe_pkcs3_param,
GNUTLS_X509_FMT_PEM);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_dh_params_import_pkcs3()", ret);
+ throw rdr::tls_error("gnutls_dh_params_import_pkcs3()", ret);
#endif
if (anon) {
ret = gnutls_anon_allocate_server_credentials(&anon_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_anon_allocate_server_credentials()", ret);
+ throw rdr::tls_error("gnutls_anon_allocate_server_credentials()", ret);
#if defined (SSECURITYTLS__USE_DEPRECATED_DH)
gnutls_anon_set_server_dh_params(anon_cred, dh_params);
ret = gnutls_credentials_set(session, GNUTLS_CRD_ANON, anon_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_credentials_set()", ret);
+ throw rdr::tls_error("gnutls_credentials_set()", ret);
vlog.debug("Anonymous session has been set");
} else {
ret = gnutls_certificate_allocate_credentials(&cert_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_certificate_allocate_credentials()", ret);
+ throw rdr::tls_error("gnutls_certificate_allocate_credentials()", ret);
#if defined (SSECURITYTLS__USE_DEPRECATED_DH)
gnutls_certificate_set_dh_params(cert_cred, dh_params);
X509_KeyFile,
GNUTLS_X509_FMT_PEM);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("Failed to load certificate and key", ret);
+ throw rdr::tls_error("Failed to load certificate and key", ret);
ret = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, cert_cred);
if (ret != GNUTLS_E_SUCCESS)
- throw rdr::TLSException("gnutls_credentials_set()", ret);
+ throw rdr::tls_error("gnutls_credentials_set()", ret);
vlog.debug("X509 session has been set");
case 0x0001: /* 0.1 Legacy VeNCrypt, not supported */
os->writeU8(0xFF); /* This is not OK */
os->flush();
- throw ProtocolException("The client cannot support the server's "
+ throw protocol_error("The client cannot support the server's "
"VeNCrypt version");
case 0x0002: /* 0.2 */
default:
os->writeU8(0xFF); /* Not OK */
os->flush();
- throw ProtocolException("The client returned an unsupported VeNCrypt version");
+ throw protocol_error("The client returned an unsupported VeNCrypt version");
}
}
os->flush();
haveSentTypes = true;
} else
- throw ProtocolException("There are no VeNCrypt sub-types to send to the client");
+ throw protocol_error("There are no VeNCrypt sub-types to send to the client");
}
/* get type back from client (must be one of the ones we sent) */
/* Set up the stack according to the chosen type */
if (chosenType == secTypeInvalid || chosenType == secTypeVeNCrypt)
- throw ProtocolException("No valid VeNCrypt sub-type");
+ throw protocol_error("No valid VeNCrypt sub-type");
ssecurity = security->GetSSecurity(sc, chosenType);
}
return true;
}
- throw AuthFailureException("Authentication failed");
+ throw auth_error("Authentication failed");
}
VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name_,
// Quit on unsupported compression type.
if (comp_ctl > tightMaxSubencoding)
- throw ProtocolException("TightDecoder: bad subencoding value received");
+ throw protocol_error("TightDecoder: bad subencoding value received");
// "Basic" compression type.
int palSize = 0;
if (r.width() > TIGHT_MAX_WIDTH)
- throw ProtocolException(format("TightDecoder: too large rectangle (%d pixels)", r.width()));
+ throw protocol_error(format("TightDecoder: too large rectangle (%d pixels)", r.width()));
// Possible palette
if ((comp_ctl & tightExplicitFilter) != 0) {
break;
case tightFilterGradient:
if (server.pf().bpp == 8)
- throw ProtocolException("TightDecoder: invalid BPP for gradient filter");
+ throw protocol_error("TightDecoder: invalid BPP for gradient filter");
break;
case tightFilterCopy:
break;
default:
- throw ProtocolException("TightDecoder: unknown filter code received");
+ throw protocol_error("TightDecoder: unknown filter code received");
}
}
netbuf = new uint8_t[dataSize];
if (!zis[streamId].hasData(dataSize))
- throw ProtocolException("Tight decode error");
+ throw protocol_error("Tight decode error");
zis[streamId].readBytes(netbuf, dataSize);
zis[streamId].flushUnderlying();
// We wait until now with this to aggregate responses and to give
// higher priority to user actions such as keyboard and pointer events.
writeFramebufferUpdate();
- } catch (rdr::EndOfStream&) {
+ } catch (rdr::end_of_stream&) {
close("Clean disconnection");
} catch (std::exception& e) {
close(e.what());
Rect rect;
if (!client.supportsFence() || !client.supportsContinuousUpdates())
- throw ProtocolException("Client tried to enable continuous updates when not allowed");
+ throw protocol_error("Client tried to enable continuous updates when not allowed");
continuousUpdates = enable;
static inline void zlibHasData(rdr::ZlibInStream* zis, size_t length)
{
if (!zis->hasData(length))
- throw ProtocolException("ZRLE decode error");
+ throw protocol_error("ZRLE decode error");
}
ZRLEDecoder::ZRLEDecoder() : Decoder(DecoderOrdered)
} while (b == 255);
if (end - ptr < len) {
- throw ProtocolException("ZRLE decode error");
+ throw protocol_error("ZRLE decode error");
}
while (len-- > 0) *ptr++ = pix;
} while (b == 255);
if (end - ptr < len) {
- throw ProtocolException("ZRLE decode error");
+ throw protocol_error("ZRLE decode error");
}
}
try {
while (true)
cc->processMsg();
- } catch (rdr::EndOfStream& e) {
+ } catch (rdr::end_of_stream& e) {
} catch (std::exception& e) {
fprintf(stderr, "Failed to run rfb file: %s\n", e.what());
exit(1);
try {
while (true)
cc->processMsg();
- } catch (rdr::EndOfStream& e) {
+ } catch (rdr::end_of_stream& e) {
} catch (std::exception& e) {
fprintf(stderr, "Failed to run rfb file: %s\n", e.what());
exit(1);
FD_ZERO(&rfds);
FD_SET(ConnectionNumber(dpy), &rfds);
int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr);
- if (n < 0) throw rdr::SocketException("select", errno);
+ if (n < 0) throw rdr::socket_error("select", errno);
}
}
return true;
FD_ZERO(&rfds);
FD_SET(ConnectionNumber(dpy), &rfds);
int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, tvp);
- if (n < 0) throw rdr::SocketException("select", errno);
+ if (n < 0) throw rdr::socket_error("select", errno);
}
XCloseDisplay(dpy);
vlog.debug("Interrupted select() system call");
continue;
} else {
- throw rdr::SocketException("select", errno);
+ throw rdr::socket_error("select", errno);
}
}
}
cc->getOutStream()->cork(false);
- } catch (rdr::EndOfStream& e) {
+ } catch (rdr::end_of_stream& e) {
vlog.info("%s", e.what());
if (!cc->desktop) {
vlog.error(_("The connection was dropped by the server before "
} else {
disconnect();
}
- } catch (rfb::AuthCancelledException& e) {
+ } catch (rfb::auth_cancelled& e) {
vlog.info("%s", e.what());
disconnect();
- } catch (rfb::AuthFailureException& e) {
+ } catch (rfb::auth_error& e) {
cc->resetPassword();
vlog.error(_("Authentication failed: %s"), e.what());
abort_connection(_("Failed to authenticate with the server. Reason "
return;
}
std::string msg = format(_("Could not open \"%s\""), filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
int lineNr = 0;
fclose(f);
std::string msg = format(_("Failed to read line %d in "
"file \"%s\""), lineNr, filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
int len = strlen(line);
FILE* f = fopen(filepath, "w+");
if (!f) {
std::string msg = format(_("Could not open \"%s\""), filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
// Save the last X elements to the config file.
dc = CreateCompatibleDC(fl_gc);
if (!dc)
- throw rdr::Win32Exception("CreateCompatibleDC", GetLastError());
+ throw rdr::win32_error("CreateCompatibleDC", GetLastError());
if (!SelectObject(dc, bitmap))
- throw rdr::Win32Exception("SelectObject", GetLastError());
+ throw rdr::win32_error("SelectObject", GetLastError());
if (!BitBlt(fl_gc, dst_x, dst_y, dst_w, dst_h,
dc, src_x, src_y, SRCCOPY)) {
// with it. For now, we've only seen this error and for this function
// so only ignore this combination.
if (GetLastError() != ERROR_INVALID_HANDLE)
- throw rdr::Win32Exception("BitBlt", GetLastError());
+ throw rdr::win32_error("BitBlt", GetLastError());
}
DeleteDC(dc);
dstdc = CreateCompatibleDC(nullptr);
if (!dstdc)
- throw rdr::Win32Exception("CreateCompatibleDC", GetLastError());
+ throw rdr::win32_error("CreateCompatibleDC", GetLastError());
if (!SelectObject(dstdc, dst->bitmap))
- throw rdr::Win32Exception("SelectObject", GetLastError());
+ throw rdr::win32_error("SelectObject", GetLastError());
origdc = fl_gc;
fl_gc = dstdc;
dstdc = CreateCompatibleDC(nullptr);
if (!dstdc)
- throw rdr::Win32Exception("CreateCompatibleDC", GetLastError());
+ throw rdr::win32_error("CreateCompatibleDC", GetLastError());
srcdc = CreateCompatibleDC(nullptr);
if (!srcdc)
- throw rdr::Win32Exception("CreateCompatibleDC", GetLastError());
+ throw rdr::win32_error("CreateCompatibleDC", GetLastError());
if (!SelectObject(dstdc, dst->bitmap))
- throw rdr::Win32Exception("SelectObject", GetLastError());
+ throw rdr::win32_error("SelectObject", GetLastError());
if (!SelectObject(srcdc, bitmap))
- throw rdr::Win32Exception("SelectObject", GetLastError());
+ throw rdr::win32_error("SelectObject", GetLastError());
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
// with it. For now, we've only seen this error and for this function
// so only ignore this combination.
if (GetLastError() != ERROR_INVALID_HANDLE)
- throw rdr::Win32Exception("BitBlt", GetLastError());
+ throw rdr::win32_error("BitBlt", GetLastError());
}
DeleteDC(srcdc);
bitmap = CreateDIBSection(nullptr, (BITMAPINFO*)&bih,
DIB_RGB_COLORS, (void**)&data, nullptr, 0);
if (!bitmap)
- throw rdr::Win32Exception("CreateDIBSection", GetLastError());
+ throw rdr::win32_error("CreateDIBSection", GetLastError());
}
void Surface::dealloc()
fp = fopen(passwordFileName, "rb");
if (!fp)
- throw rdr::PosixException(_("Opening password file failed"), errno);
+ throw rdr::posix_error(_("Opening password file failed"), errno);
obfPwd.resize(fread(obfPwd.data(), 1, obfPwd.size(), fp));
fclose(fp);
delete win;
if (ret_val != 0)
- throw rfb::AuthCancelledException();
+ throw rfb::auth_cancelled();
}
bool UserDialog::showMsgBox(MsgBoxFlags flags, const char* title, const char* text)
LONG res = RegSetValueExW(*hKey, name, 0, REG_SZ, (BYTE*)&value, (wcslen(value)+1)*2);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegSetValueExW", res);
+ throw rdr::win32_error("RegSetValueExW", res);
}
LONG res = RegSetValueExW(*hKey, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegSetValueExW", res);
+ throw rdr::win32_error("RegSetValueExW", res);
}
if (res != ERROR_SUCCESS){
delete [] value;
if (res != ERROR_FILE_NOT_FOUND)
- throw rdr::Win32Exception("RegQueryValueExW", res);
+ throw rdr::win32_error("RegQueryValueExW", res);
// The value does not exist, defaults will be used.
return false;
}
LONG res = RegQueryValueExW(*hKey, name, nullptr, nullptr, (LPBYTE)&value, &dwordsize);
if (res != ERROR_SUCCESS){
if (res != ERROR_FILE_NOT_FOUND)
- throw rdr::Win32Exception("RegQueryValueExW", res);
+ throw rdr::win32_error("RegQueryValueExW", res);
// The value does not exist, defaults will be used.
return false;
}
LONG res = RegDeleteValueW(*hKey, name);
if (res != ERROR_SUCCESS) {
if (res != ERROR_FILE_NOT_FOUND)
- throw rdr::Win32Exception("RegDeleteValueW", res);
+ throw rdr::win32_error("RegDeleteValueW", res);
// The value does not exist, no need to remove it.
return;
}
&hKey, nullptr);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to create registry key"), res);
+ throw rdr::win32_error(_("Failed to create registry key"), res);
unsigned index = 0;
assert(SERVER_HISTORY_SIZE < 100);
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to close registry key"), res);
+ throw rdr::win32_error(_("Failed to close registry key"), res);
}
static void saveToReg(const char* servername) {
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nullptr,
&hKey, nullptr);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to create registry key"), res);
+ throw rdr::win32_error(_("Failed to create registry key"), res);
try {
setKeyString("ServerName", servername, &hKey);
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to close registry key"), res);
+ throw rdr::win32_error(_("Failed to close registry key"), res);
}
list<string> loadHistoryFromRegKey() {
return serverHistory;
}
- throw rdr::Win32Exception(_("Failed to open registry key"), res);
+ throw rdr::win32_error(_("Failed to open registry key"), res);
}
unsigned index;
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to close registry key"), res);
+ throw rdr::win32_error(_("Failed to close registry key"), res);
return serverHistory;
}
return nullptr;
}
- throw rdr::Win32Exception(_("Failed to open registry key"), res);
+ throw rdr::win32_error(_("Failed to open registry key"), res);
}
const size_t buffersize = 256;
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS)
- throw rdr::Win32Exception(_("Failed to close registry key"), res);
+ throw rdr::win32_error(_("Failed to close registry key"), res);
return servername;
}
FILE* f = fopen(filepath, "w+");
if (!f) {
std::string msg = format(_("Could not open \"%s\""), filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
fprintf(f, "%s\n", IDENTIFIER_STRING);
if (!filename)
return nullptr; // Use defaults.
std::string msg = format(_("Could not open \"%s\""), filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
int lineNr = 0;
fclose(f);
std::string msg = format(_("Failed to read line %d in "
"file \"%s\""), lineNr, filepath);
- throw rdr::PosixException(msg.c_str(), errno);
+ throw rdr::posix_error(msg.c_str(), errno);
}
if (strlen(line) == (sizeof(line) - 1)) {
vlog.debug("Interrupted select() system call");
continue;
} else {
- throw rdr::SocketException("select", errno);
+ throw rdr::socket_error("select", errno);
}
}
HRESULT result = CoCreateInstance(CLSID_ActiveDesktop, nullptr, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (PVOID*)&handle);
if (result != S_OK)
- throw rdr::Win32Exception("failed to contact Active Desktop", HRESULT_CODE(result));
+ throw rdr::win32_error("failed to contact Active Desktop", HRESULT_CODE(result));
}
~ActiveDesktop() {
if (handle)
// - Firstly, we must open the clipboard
if (!OpenClipboard(getHandle()))
- throw rdr::Win32Exception("unable to open Win32 clipboard", GetLastError());
+ throw rdr::win32_error("unable to open Win32 clipboard", GetLastError());
// - Convert the supplied clipboard text into UTF-16 format with CRLF
std::string filtered(convertCRLF(text));
// - Next, we must clear out any existing data
if (!EmptyClipboard())
- throw rdr::Win32Exception("unable to empty Win32 clipboard", GetLastError());
+ throw rdr::win32_error("unable to empty Win32 clipboard", GetLastError());
// - Set the new clipboard data
if (!SetClipboardData(CF_UNICODETEXT, clip_handle))
- throw rdr::Win32Exception("unable to set Win32 clipboard", GetLastError());
+ throw rdr::win32_error("unable to set Win32 clipboard", GetLastError());
clip_handle = nullptr;
vlog.debug("set clipboard");
CompatibleBitmap(HDC hdc, int width, int height) {
hbmp = CreateCompatibleBitmap(hdc, width, height);
if (!hbmp)
- throw rdr::Win32Exception("CreateCompatibleBitmap() failed", GetLastError());
+ throw rdr::win32_error("CreateCompatibleBitmap() failed", GetLastError());
}
virtual ~CompatibleBitmap() {
if (hbmp) DeleteObject(hbmp);
if (!OpenProcessToken(GetCurrentProcess(), GENERIC_ALL, &h)) {
DWORD err = GetLastError();
if (err != ERROR_CALL_NOT_IMPLEMENTED)
- throw rdr::Win32Exception("OpenProcessToken failed", err);
+ throw rdr::win32_error("OpenProcessToken failed", err);
h = INVALID_HANDLE_VALUE;
}
}
if (!ImpersonateLoggedOnUser(token)) {
DWORD err = GetLastError();
if (err != ERROR_CALL_NOT_IMPLEMENTED)
- throw rdr::Win32Exception("Failed to impersonate user", GetLastError());
+ throw rdr::win32_error("Failed to impersonate user", GetLastError());
}
}
char buf[UNLEN+1];
DWORD len = UNLEN+1;
if (!GetUserName(buf, &len))
- throw rdr::Win32Exception("GetUserName failed", GetLastError());
+ throw rdr::win32_error("GetUserName failed", GetLastError());
assign(buf);
}
if (!new_bitmap) {
int err = GetLastError();
- throw rdr::Win32Exception("unable to create DIB section", err);
+ throw rdr::win32_error("unable to create DIB section", err);
}
vlog.debug("recreateBuffer()");
// Determine the *actual* DIBSection format
DIBSECTION ds;
if (!GetObject(bitmap, sizeof(ds), &ds))
- throw rdr::Win32Exception("GetObject", GetLastError());
+ throw rdr::win32_error("GetObject", GetLastError());
// Correct the "stride" of the DIB
// *** This code DWORD aligns each row - is that right???
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biBitCount = 0;
if (!::GetDIBits(dc, bitmap, 0, 1, nullptr, (BITMAPINFO*)&bi, DIB_RGB_COLORS)) {
- throw rdr::Win32Exception("unable to determine device pixel format", GetLastError());
+ throw rdr::win32_error("unable to determine device pixel format", GetLastError());
}
if (!::GetDIBits(dc, bitmap, 0, 1, nullptr, (BITMAPINFO*)&bi, DIB_RGB_COLORS)) {
- throw rdr::Win32Exception("unable to determine pixel shifts/palette", GetLastError());
+ throw rdr::win32_error("unable to determine pixel shifts/palette", GetLastError());
}
// Set the initial format information
// Get the display dimensions
RECT cr;
if (!GetClipBox(dc, &cr))
- throw rdr::Win32Exception("GetClipBox", GetLastError());
+ throw rdr::win32_error("GetClipBox", GetLastError());
return Rect(cr.left, cr.top, cr.right, cr.bottom);
}
DeviceDC::DeviceDC(const char* deviceName) {
dc = ::CreateDC("DISPLAY", deviceName, nullptr, nullptr);
if (!dc)
- throw rdr::Win32Exception("failed to create DeviceDC", GetLastError());
+ throw rdr::win32_error("failed to create DeviceDC", GetLastError());
}
DeviceDC::~DeviceDC() {
WindowDC::WindowDC(HWND wnd) : hwnd(wnd) {
dc = GetDC(wnd);
if (!dc)
- throw rdr::Win32Exception("GetDC failed", GetLastError());
+ throw rdr::win32_error("GetDC failed", GetLastError());
}
WindowDC::~WindowDC() {
CompatibleDC::CompatibleDC(HDC existing) {
dc = CreateCompatibleDC(existing);
if (!dc)
- throw rdr::Win32Exception("CreateCompatibleDC failed", GetLastError());
+ throw rdr::win32_error("CreateCompatibleDC failed", GetLastError());
}
CompatibleDC::~CompatibleDC() {
BitmapDC::BitmapDC(HDC hdc, HBITMAP hbitmap) : CompatibleDC(hdc){
oldBitmap = (HBITMAP)SelectObject(dc, hbitmap);
if (!oldBitmap)
- throw rdr::Win32Exception("SelectObject to CompatibleDC failed",
+ throw rdr::win32_error("SelectObject to CompatibleDC failed",
GetLastError());
}
if (ignoreGrabErrors)
vlog.error("BitBlt failed:%ld", GetLastError());
else
- throw rdr::Win32Exception("BitBlt failed", GetLastError());
+ throw rdr::win32_error("BitBlt failed", GetLastError());
}
}
BITMAP maskInfo;
if (!GetObject(iconInfo.hbmMask, sizeof(BITMAP), &maskInfo))
- throw rdr::Win32Exception("GetObject() failed", GetLastError());
+ throw rdr::win32_error("GetObject() failed", GetLastError());
if (maskInfo.bmPlanes != 1)
throw std::invalid_argument("unsupported multi-plane cursor");
if (maskInfo.bmBitsPixel != 1)
if (!GetDIBits(dc, iconInfo.hbmColor, 0, height,
buffer.data(), (LPBITMAPINFO)&bi, DIB_RGB_COLORS))
- throw rdr::Win32Exception("GetDIBits", GetLastError());
+ throw rdr::win32_error("GetDIBits", GetLastError());
// We may not get the RGBA order we want, so shuffle things around
int ridx, gidx, bidx, aidx;
if (!GetBitmapBits(iconInfo.hbmMask,
maskInfo.bmWidthBytes * maskInfo.bmHeight, mask.data()))
- throw rdr::Win32Exception("GetBitmapBits", GetLastError());
+ throw rdr::win32_error("GetBitmapBits", GetLastError());
bool doOutline = false;
uint8_t* rwbuffer = buffer.data();
INT_PTR result = DialogBoxParam(inst, resource, owner,
staticDialogProc, (LPARAM)this);
if (result<0)
- throw rdr::Win32Exception("DialogBoxParam failed", GetLastError());
+ throw rdr::win32_error("DialogBoxParam failed", GetLastError());
alreadyShowing = false;
return (result == 1);
}
handle = (HWND)PropertySheet(&header);
if ((handle == nullptr) || (handle == (HWND)-1))
- throw rdr::Win32Exception("PropertySheet failed", GetLastError());
+ throw rdr::win32_error("PropertySheet failed", GetLastError());
centerWindow(handle, owner_);
plog.info("created %p", handle);
struct IconInfo : public ICONINFO {
IconInfo(HICON icon) {
if (!GetIconInfo(icon, this))
- throw rdr::Win32Exception("GetIconInfo() failed", GetLastError());
+ throw rdr::win32_error("GetIconInfo() failed", GetLastError());
}
~IconInfo() {
if (hbmColor)
if (!active || interval_ != interval) {
interval = interval_;
if (!SetTimer(hwnd, id, interval, nullptr))
- throw rdr::Win32Exception("SetTimer", GetLastError());
+ throw rdr::win32_error("SetTimer", GetLastError());
active = true;
}
}
char buf[256];
HDESK desktop = GetThreadDesktop(GetCurrentThreadId());
if (!GetUserObjectInformation(desktop, UOI_NAME, buf, 256, &size))
- throw rdr::Win32Exception("unable to launch process", GetLastError());
+ throw rdr::win32_error("unable to launch process", GetLastError());
snprintf(desktopName, 256, "WinSta0\\%s", buf);
flags, nullptr, nullptr,
&sinfo, &procInfo);
if (!success)
- throw rdr::Win32Exception("unable to launch process", GetLastError());
+ throw rdr::win32_error("unable to launch process", GetLastError());
// Wait for it to finish initialising
WaitForInputIdle(procInfo.hProcess, 15000);
detach();
return true;
} else if (result == WAIT_FAILED) {
- throw rdr::Win32Exception("await() failed", GetLastError());
+ throw rdr::win32_error("await() failed", GetLastError());
}
return false;
}
// Allocate and/or manage LocalAlloc memory.
struct LocalMem {
LocalMem(int size) : ptr(LocalAlloc(LMEM_FIXED, size)) {
- if (!ptr) throw rdr::Win32Exception("LocalAlloc", GetLastError());
+ if (!ptr) throw rdr::win32_error("LocalAlloc", GetLastError());
}
LocalMem(void* p) : ptr(p) {}
~LocalMem() {LocalFree(ptr);}
memset(mi, 0, sizeof(MONITORINFOEXA));
mi->cbSize = sizeof(MONITORINFOEXA);
if (!GetMonitorInfo(monitor, mi))
- throw rdr::Win32Exception("failed to GetMonitorInfo", GetLastError());
+ throw rdr::win32_error("failed to GetMonitorInfo", GetLastError());
vlog.debug("monitor is %ld,%ld-%ld,%ld", mi->rcMonitor.left, mi->rcMonitor.top, mi->rcMonitor.right, mi->rcMonitor.bottom);
vlog.debug("work area is %ld,%ld-%ld,%ld", mi->rcWork.left, mi->rcWork.top, mi->rcWork.right, mi->rcWork.bottom);
vlog.debug("device is \"%s\"", mi->szDevice);
HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST);
if (!monitor)
- throw rdr::Win32Exception("failed to get monitor", GetLastError());
+ throw rdr::win32_error("failed to get monitor", GetLastError());
fillMonitorInfo(monitor, this);
}
HMONITOR monitor = MonitorFromRect(&r, MONITOR_DEFAULTTONEAREST);
if (!monitor)
- throw rdr::Win32Exception("failed to get monitor", GetLastError());
+ throw rdr::win32_error("failed to get monitor", GetLastError());
fillMonitorInfo(monitor, this);
}
wndClass.lpszClassName = "rfb::win32::MsgWindowClass";
classAtom = RegisterClass(&wndClass);
if (!classAtom) {
- throw rdr::Win32Exception("unable to register MsgWindow window class", GetLastError());
+ throw rdr::win32_error("unable to register MsgWindow window class", GetLastError());
}
}
name.c_str(), WS_OVERLAPPED, 0, 0, 10, 10,
nullptr, nullptr, baseClass.instance, this);
if (!handle) {
- throw rdr::Win32Exception("unable to create WMNotifier window instance", GetLastError());
+ throw rdr::win32_error("unable to create WMNotifier window instance", GetLastError());
}
vlog.debug("created window \"%s\" (%p)", name.c_str(), handle);
}
if (!Configuration::setParam(name, value.c_str()))
vlog.info("unable to process %s", name);
}
- } catch (rdr::Win32Exception& e) {
+ } catch (rdr::win32_error& e) {
if (e.err != ERROR_INVALID_HANDLE)
vlog.error("%s", e.what());
}
thread_id = GetCurrentThreadId();
while ((result = eventMgr.getMessage(&msg, nullptr, 0, 0)) > 0) {}
if (result < 0)
- throw rdr::Win32Exception("RegConfigThread failed", GetLastError());
+ throw rdr::win32_error("RegConfigThread failed", GetLastError());
}
RegKey::RegKey(const HKEY k) : key(nullptr), freeKey(false), valueName(nullptr), valueNameBufLen(0) {
LONG result = RegOpenKeyEx(k, nullptr, 0, KEY_ALL_ACCESS, &key);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegOpenKeyEx(HKEY)", result);
+ throw rdr::win32_error("RegOpenKeyEx(HKEY)", result);
vlog.debug("duplicated %p to %p", k, key);
freeKey = true;
}
RegKey::RegKey(const RegKey& k) : key(nullptr), freeKey(false), valueName(nullptr), valueNameBufLen(0) {
LONG result = RegOpenKeyEx(k.key, nullptr, 0, KEY_ALL_ACCESS, &key);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegOpenKeyEx(RegKey&)", result);
+ throw rdr::win32_error("RegOpenKeyEx(RegKey&)", result);
vlog.debug("duplicated %p to %p", k.key, key);
freeKey = true;
}
LONG result = RegCreateKey(root.key, name, &key);
if (result != ERROR_SUCCESS) {
vlog.error("RegCreateKey(%p, %s): %lx", root.key, name, result);
- throw rdr::Win32Exception("RegCreateKeyEx", result);
+ throw rdr::win32_error("RegCreateKeyEx", result);
}
vlog.debug("createKey(%p,%s) = %p", root.key, name, key);
freeKey = true;
close();
LONG result = RegOpenKeyEx(root.key, name, 0, readOnly ? KEY_READ : KEY_ALL_ACCESS, &key);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegOpenKeyEx (open)", result);
+ throw rdr::win32_error("RegOpenKeyEx (open)", result);
vlog.debug("openKey(%p,%s,%s) = %p", root.key, name,
readOnly ? "ro" : "rw", key);
freeKey = true;
DACL_SECURITY_INFORMATION |
(inherit ? UNPROTECTED_DACL_SECURITY_INFORMATION : PROTECTED_DACL_SECURITY_INFORMATION),
nullptr, nullptr, acl, nullptr)) != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegKey::setDACL failed", result);
+ throw rdr::win32_error("RegKey::setDACL failed", result);
}
void RegKey::close() {
void RegKey::deleteKey(const char* name) const {
LONG result = RegDeleteKey(key, name);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegDeleteKey", result);
+ throw rdr::win32_error("RegDeleteKey", result);
}
void RegKey::deleteValue(const char* name) const {
LONG result = RegDeleteValue(key, name);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegDeleteValue", result);
+ throw rdr::win32_error("RegDeleteValue", result);
}
void RegKey::awaitChange(bool watchSubTree, DWORD filter, HANDLE event) const {
LONG result = RegNotifyChangeKeyValue(key, watchSubTree, filter, event, event != nullptr);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegNotifyChangeKeyValue", result);
+ throw rdr::win32_error("RegNotifyChangeKeyValue", result);
}
void RegKey::setExpandString(const char* valname, const char* value) const {
LONG result = RegSetValueEx(key, valname, 0, REG_EXPAND_SZ, (const BYTE*)value, (strlen(value)+1)*sizeof(char));
- if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setExpandString", result);
+ if (result != ERROR_SUCCESS) throw rdr::win32_error("setExpandString", result);
}
void RegKey::setString(const char* valname, const char* value) const {
LONG result = RegSetValueEx(key, valname, 0, REG_SZ, (const BYTE*)value, (strlen(value)+1)*sizeof(char));
- if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setString", result);
+ if (result != ERROR_SUCCESS) throw rdr::win32_error("setString", result);
}
void RegKey::setBinary(const char* valname, const void* value, size_t length) const {
LONG result = RegSetValueEx(key, valname, 0, REG_BINARY, (const BYTE*)value, length);
- if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setBinary", result);
+ if (result != ERROR_SUCCESS) throw rdr::win32_error("setBinary", result);
}
void RegKey::setInt(const char* valname, int value) const {
LONG result = RegSetValueEx(key, valname, 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
- if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setInt", result);
+ if (result != ERROR_SUCCESS) throw rdr::win32_error("setInt", result);
}
void RegKey::setBool(const char* valname, bool value) const {
DWORD type, length;
LONG result = RegQueryValueEx(key, valname, nullptr, &type, nullptr, &length);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("get registry value length", result);
+ throw rdr::win32_error("get registry value length", result);
std::vector<uint8_t> data(length);
result = RegQueryValueEx(key, valname, nullptr, &type, (BYTE*)data.data(), &length);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("get registry value", result);
+ throw rdr::win32_error("get registry value", result);
switch (type) {
case REG_BINARY:
std::string str((char*)data.data(), length);
DWORD required = ExpandEnvironmentStrings(str.c_str(), nullptr, 0);
if (required==0)
- throw rdr::Win32Exception("ExpandEnvironmentStrings", GetLastError());
+ throw rdr::win32_error("ExpandEnvironmentStrings", GetLastError());
std::vector<char> expanded(required);
length = ExpandEnvironmentStrings(str.c_str(), expanded.data(), required);
if (required<length)
DWORD maxValueNameLen;
LONG result = RegQueryInfoKey(key, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &maxValueNameLen, nullptr, nullptr, nullptr);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegQueryInfoKey", result);
+ throw rdr::win32_error("RegQueryInfoKey", result);
if (valueNameBufLen < maxValueNameLen + 1) {
valueNameBufLen = maxValueNameLen + 1;
delete [] valueName;
result = RegEnumValue(key, i, valueName, &length, nullptr, nullptr, nullptr, nullptr);
if (result == ERROR_NO_MORE_ITEMS) return nullptr;
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegEnumValue", result);
+ throw rdr::win32_error("RegEnumValue", result);
return valueName;
}
DWORD maxValueNameLen;
LONG result = RegQueryInfoKey(key, nullptr, nullptr, nullptr, nullptr, &maxValueNameLen, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegQueryInfoKey", result);
+ throw rdr::win32_error("RegQueryInfoKey", result);
if (valueNameBufLen < maxValueNameLen + 1) {
valueNameBufLen = maxValueNameLen + 1;
delete [] valueName;
result = RegEnumKeyEx(key, i, valueName, &length, nullptr, nullptr, nullptr, nullptr);
if (result == ERROR_NO_MORE_ITEMS) return nullptr;
if (result != ERROR_SUCCESS)
- throw rdr::Win32Exception("RegEnumKey", result);
+ throw rdr::win32_error("RegEnumKey", result);
return valueName;
}
evt.mi.mouseData = data;
evt.mi.time = 0;
if (SendInput(1, &evt, sizeof(evt)) != 1)
- throw rdr::Win32Exception("SendInput", GetLastError());
+ throw rdr::win32_error("SendInput", GetLastError());
}
}
throw std::invalid_argument("invalid SID in copyPSID");
PSID buf = (PSID)new uint8_t[GetLengthSid(sid)];
if (!CopySid(GetLengthSid(sid), buf, sid))
- throw rdr::Win32Exception("CopySid failed", GetLastError());
+ throw rdr::win32_error("CopySid failed", GetLastError());
return buf;
}
throw std::invalid_argument("invalid SID in copyPSID");
resize(GetLengthSid(sid));
if (!CopySid(GetLengthSid(sid), data(), sid))
- throw rdr::Win32Exception("CopySid failed", GetLastError());
+ throw rdr::win32_error("CopySid failed", GetLastError());
}
void Sid::getUserNameAndDomain(char** name, char** domain) {
SID_NAME_USE use;
LookupAccountSid(nullptr, (PSID)*this, nullptr, &nameLen, nullptr, &domainLen, &use);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- throw rdr::Win32Exception("Unable to determine SID name lengths", GetLastError());
+ throw rdr::win32_error("Unable to determine SID name lengths", GetLastError());
vlog.info("nameLen=%lu, domainLen=%lu, use=%d", nameLen, domainLen, use);
*name = new char[nameLen];
*domain = new char[domainLen];
if (!LookupAccountSid(nullptr, (PSID)*this, *name, &nameLen, *domain, &domainLen, &use))
- throw rdr::Win32Exception("Unable to lookup account SID", GetLastError());
+ throw rdr::win32_error("Unable to lookup account SID", GetLastError());
}
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &sid))
- throw rdr::Win32Exception("Sid::Administrators", GetLastError());
+ throw rdr::win32_error("Sid::Administrators", GetLastError());
setSID(sid);
FreeSid(sid);
}
if (!AllocateAndInitializeSid(&ntAuth, 1,
SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0, &sid))
- throw rdr::Win32Exception("Sid::SYSTEM", GetLastError());
+ throw rdr::win32_error("Sid::SYSTEM", GetLastError());
setSID(sid);
FreeSid(sid);
}
GetTokenInformation(h, TokenUser, nullptr, 0, &required);
std::vector<uint8_t> tmp(required);
if (!GetTokenInformation(h, TokenUser, tmp.data(), tmp.size(), &required))
- throw rdr::Win32Exception("GetTokenInformation", GetLastError());
+ throw rdr::win32_error("GetTokenInformation", GetLastError());
TOKEN_USER* tokenUser = (TOKEN_USER*)tmp.data();
setSID(tokenUser->User.Sid);
}
PACL new_dacl;
DWORD result;
if ((result = SetEntriesInAcl(ae.entry_count, ae.entries, existing_acl, &new_dacl)) != ERROR_SUCCESS)
- throw rdr::Win32Exception("SetEntriesInAcl", result);
+ throw rdr::win32_error("SetEntriesInAcl", result);
return new_dacl;
}
PSECURITY_DESCRIPTOR rfb::win32::CreateSdWithDacl(const PACL dacl) {
SECURITY_DESCRIPTOR absSD;
if (!InitializeSecurityDescriptor(&absSD, SECURITY_DESCRIPTOR_REVISION))
- throw rdr::Win32Exception("InitializeSecurityDescriptor", GetLastError());
+ throw rdr::win32_error("InitializeSecurityDescriptor", GetLastError());
Sid::SYSTEM owner;
if (!SetSecurityDescriptorOwner(&absSD, owner, FALSE))
- throw rdr::Win32Exception("SetSecurityDescriptorOwner", GetLastError());
+ throw rdr::win32_error("SetSecurityDescriptorOwner", GetLastError());
Sid::Administrators group;
if (!SetSecurityDescriptorGroup(&absSD, group, FALSE))
- throw rdr::Win32Exception("SetSecurityDescriptorGroupp", GetLastError());
+ throw rdr::win32_error("SetSecurityDescriptorGroupp", GetLastError());
if (!SetSecurityDescriptorDacl(&absSD, TRUE, dacl, FALSE))
- throw rdr::Win32Exception("SetSecurityDescriptorDacl", GetLastError());
+ throw rdr::win32_error("SetSecurityDescriptorDacl", GetLastError());
DWORD sdSize = GetSecurityDescriptorLength(&absSD);
SecurityDescriptorPtr sd(sdSize);
if (!MakeSelfRelativeSD(&absSD, (PSECURITY_DESCRIPTOR)sd.ptr, &sdSize))
- throw rdr::Win32Exception("MakeSelfRelativeSD", GetLastError());
+ throw rdr::win32_error("MakeSelfRelativeSD", GetLastError());
return sd.takeSD();
}
vlog.error("unable to set shutdown parameters: %lu", GetLastError());
service = this;
if (!StartServiceCtrlDispatcher(entry))
- throw Win32Exception("unable to start service", GetLastError());
+ throw win32_error("unable to start service", GetLastError());
}
void
// - Open the SCM
ServiceHandle scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE);
if (!scm)
- throw rdr::Win32Exception("unable to open Service Control Manager", GetLastError());
+ throw rdr::win32_error("unable to open Service Control Manager", GetLastError());
// - Add the service
ServiceHandle handle = CreateService(scm,
SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
cmdline.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr);
if (!handle)
- throw rdr::Win32Exception("unable to create service", GetLastError());
+ throw rdr::win32_error("unable to create service", GetLastError());
// - Set a description
SERVICE_DESCRIPTION sdesc = {(LPTSTR)desc};
// - Open the SCM
ServiceHandle scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE);
if (!scm)
- throw rdr::Win32Exception("unable to open Service Control Manager", GetLastError());
+ throw rdr::win32_error("unable to open Service Control Manager", GetLastError());
// - Create the service
ServiceHandle handle = OpenService(scm, name, SC_MANAGER_ALL_ACCESS);
if (!handle)
- throw rdr::Win32Exception("unable to locate the service", GetLastError());
+ throw rdr::win32_error("unable to locate the service", GetLastError());
if (!DeleteService(handle))
- throw rdr::Win32Exception("unable to remove the service", GetLastError());
+ throw rdr::win32_error("unable to remove the service", GetLastError());
// - Register the event log source
RegKey hk;
// - Open the SCM
ServiceHandle scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
if (!scm)
- throw rdr::Win32Exception("unable to open Service Control Manager", GetLastError());
+ throw rdr::win32_error("unable to open Service Control Manager", GetLastError());
// - Locate the service
ServiceHandle handle = OpenService(scm, name, SERVICE_START);
if (!handle)
- throw rdr::Win32Exception("unable to open the service", GetLastError());
+ throw rdr::win32_error("unable to open the service", GetLastError());
// - Start the service
if (!StartService(handle, 0, nullptr))
- throw rdr::Win32Exception("unable to start the service", GetLastError());
+ throw rdr::win32_error("unable to start the service", GetLastError());
Sleep(500);
// - Open the SCM
ServiceHandle scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
if (!scm)
- throw rdr::Win32Exception("unable to open Service Control Manager", GetLastError());
+ throw rdr::win32_error("unable to open Service Control Manager", GetLastError());
// - Locate the service
ServiceHandle handle = OpenService(scm, name, SERVICE_STOP);
if (!handle)
- throw rdr::Win32Exception("unable to open the service", GetLastError());
+ throw rdr::win32_error("unable to open the service", GetLastError());
// - Start the service
SERVICE_STATUS status;
if (!ControlService(handle, SERVICE_CONTROL_STOP, &status))
- throw rdr::Win32Exception("unable to stop the service", GetLastError());
+ throw rdr::win32_error("unable to stop the service", GetLastError());
Sleep(500);
// - Open the SCM
ServiceHandle scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
if (!scm)
- throw rdr::Win32Exception("unable to open Service Control Manager", GetLastError());
+ throw rdr::win32_error("unable to open Service Control Manager", GetLastError());
// - Locate the service
ServiceHandle handle = OpenService(scm, name, SERVICE_INTERROGATE);
if (!handle)
- throw rdr::Win32Exception("unable to open the service", GetLastError());
+ throw rdr::win32_error("unable to open the service", GetLastError());
// - Get the service status
SERVICE_STATUS status;
if (!ControlService(handle, SERVICE_CONTROL_INTERROGATE, (SERVICE_STATUS*)&status))
- throw rdr::Win32Exception("unable to query the service", GetLastError());
+ throw rdr::win32_error("unable to query the service", GetLastError());
return status.dwCurrentState;
}
flags |= FD_ADDRESS_LIST_CHANGE;
try {
if (event && (WSAEventSelect(sock_->getFd(), event, flags) == SOCKET_ERROR))
- throw rdr::SocketException("Unable to select on listener", WSAGetLastError());
+ throw rdr::socket_error("Unable to select on listener", WSAGetLastError());
// requestAddressChangeEvents MUST happen after WSAEventSelect, so that the socket is non-blocking
if (acn)
if (j->second.sock->outStream().hasBufferedData())
eventMask |= FD_WRITE;
if (WSAEventSelect(j->second.sock->getFd(), j->first, eventMask) == SOCKET_ERROR)
- throw rdr::SocketException("unable to adjust WSAEventSelect:%u", WSAGetLastError());
+ throw rdr::socket_error("unable to adjust WSAEventSelect:%u", WSAGetLastError());
}
}
// Fetch why this event notification triggered
if (WSAEnumNetworkEvents(ci.sock->getFd(), event, &network_events) == SOCKET_ERROR)
- throw rdr::SocketException("unable to get WSAEnumNetworkEvents:%u", WSAGetLastError());
+ throw rdr::socket_error("unable to get WSAEnumNetworkEvents:%u", WSAGetLastError());
// Cancel event notification for this socket
if (WSAEventSelect(ci.sock->getFd(), event, 0) == SOCKET_ERROR)
- throw rdr::SocketException("unable to disable WSAEventSelect:%u", WSAGetLastError());
+ throw rdr::socket_error("unable to disable WSAEventSelect:%u", WSAGetLastError());
// Reset the event object
WSAResetEvent(event);
if (ci.sock->outStream().hasBufferedData())
eventMask |= FD_WRITE;
if (WSAEventSelect(ci.sock->getFd(), event, eventMask) == SOCKET_ERROR)
- throw rdr::SocketException("unable to re-enable WSAEventSelect:%u", WSAGetLastError());
+ throw rdr::socket_error("unable to re-enable WSAEventSelect:%u", WSAGetLastError());
} catch (std::exception& e) {
vlog.error("%s", e.what());
remSocket(ci.sock);
if (processId == (DWORD)-1)
processId = GetCurrentProcessId();
if (!ProcessIdToSessionId(GetCurrentProcessId(), &id))
- throw rdr::Win32Exception("ProcessIdToSessionId", GetLastError());
+ throw rdr::win32_error("ProcessIdToSessionId", GetLastError());
}
ProcessSessionId mySessionId;
ConsoleSessionId console;
vlog.info("Console session is %lu", console.id);
if (!WTSConnectSession(sessionId, console.id, (PTSTR)"", 0))
- throw rdr::Win32Exception("Unable to connect session to Console", GetLastError());
+ throw rdr::win32_error("Unable to connect session to Console", GetLastError());
// Lock the newly connected session, for security
LockWorkStation();
CURSORINFO info;
info.cbSize = sizeof(CURSORINFO);
if (!GetCursorInfo(&info))
- throw rdr::Win32Exception("GetCursorInfo failed", GetLastError());
+ throw rdr::win32_error("GetCursorInfo failed", GetLastError());
result.cursor = info.hCursor;
result.position = Point(info.ptScreenPos.x, info.ptScreenPos.y);
result.visible = info.flags & CURSOR_SHOWING;
rfb::win32::WMPoller::checkPollWindow(HWND w) {
char buffer[128];
if (!GetClassName(w, buffer, 128))
- throw rdr::Win32Exception("unable to get window class:%u", GetLastError());
+ throw rdr::win32_error("unable to get window class:%u", GetLastError());
if ((strcmp(buffer, "tty") != 0) &&
(strcmp(buffer, "ConsoleWindowClass") != 0)) {
return false;
{
Handle file(CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr));
if (file.h == INVALID_HANDLE_VALUE)
- throw rdr::Win32Exception("Failed to open file", GetLastError());
+ throw rdr::win32_error("Failed to open file", GetLastError());
}
// Get version info size
DWORD handle;
int size = GetFileVersionInfoSize((char*)filename, &handle);
if (!size)
- throw rdr::Win32Exception("GetVersionInfoSize failed", GetLastError());
+ throw rdr::win32_error("GetVersionInfoSize failed", GetLastError());
// Get version info
buf = new char[size];
if (!GetFileVersionInfo((char*)filename, handle, size, buf))
- throw rdr::Win32Exception("GetVersionInfo failed", GetLastError());
+ throw rdr::win32_error("GetVersionInfo failed", GetLastError());
}
FileVersionInfo::~FileVersionInfo() {
std::string username;
try {
username = UserName();
- } catch (rdr::Win32Exception& e) {
+ } catch (rdr::win32_error& e) {
if (e.err != ERROR_NOT_LOGGED_ON)
throw;
}
// Set the DACL, and don't allow the key to inherit its parent's DACL
rootKey.setDACL(acl, false);
- } catch (rdr::Win32Exception& e) {
+ } catch (rdr::win32_error& e) {
// Something weird happens on NT 4.0 SP5 but I can't reproduce it on other
// NT 4.0 service pack revisions.
if (e.err == ERROR_INVALID_PARAMETER) {
#else
sheet.showPropSheet(nullptr, true, false);
#endif
- } catch (rdr::Win32Exception& e) {
+ } catch (rdr::win32_error& e) {
switch (e.err) {
case ERROR_ACCESS_DENIED:
MsgBox(nullptr, "You do not have sufficient access rights to run the VNC Configuration applet",
void QueryConnectDialog::initDialog() {
if (!SetTimer(handle, 1, 1000, nullptr))
- throw rdr::Win32Exception("SetTimer", GetLastError());
+ throw rdr::win32_error("SetTimer", GetLastError());
setItemString(IDC_QUERY_HOST, peerIp.c_str());
if (userName.empty())
userName = "(anonymous)";
while (runServer) {
result = sockMgr.getMessage(&msg, nullptr, 0, 0);
if (result < 0)
- throw rdr::Win32Exception("getMessage", GetLastError());
+ throw rdr::win32_error("getMessage", GetLastError());
if (!isServiceProcess() && (result == 0))
break;
TranslateMessage(&msg);
}
vlog.debug("Server exited cleanly");
- } catch (rdr::Win32Exception &s) {
+ } catch (rdr::win32_error &s) {
vlog.error("%s", s.what());
result = s.err;
} catch (std::exception &e) {
// Try to clean up earlier services we've had
try {
rfb::win32::unregisterService("WinVNC4");
- } catch (rdr::Win32Exception&) {
+ } catch (rdr::win32_error&) {
// Do nothing as we might fail simply because there was no
// service to remove
}
try {
rfb::win32::unregisterService("TigerVNC Server");
- } catch (rdr::Win32Exception&) {
+ } catch (rdr::win32_error&) {
}
if (rfb::win32::registerService(VNCServerService::Name,