From 2b7857283b834391266e414adcff8c20f8fe3067 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Sun, 20 Oct 2024 11:06:13 +0200 Subject: [PATCH] Use standard library naming for exceptions This makes things more consistent since we mix with the standard library exceptions so often. --- common/network/Socket.cxx | 6 +-- common/network/TcpSocket.cxx | 26 ++++++------ common/network/UnixSocket.cxx | 14 +++---- common/os/Mutex.cxx | 16 ++++---- common/os/Thread.cxx | 10 ++--- common/rdr/Exception.cxx | 18 ++++----- common/rdr/Exception.h | 34 ++++++++-------- common/rdr/FdInStream.cxx | 6 +-- common/rdr/FdOutStream.cxx | 4 +- common/rdr/FileInStream.cxx | 6 +-- common/rdr/MemInStream.h | 2 +- common/rdr/RandomStream.cxx | 6 +-- common/rdr/TLSException.cxx | 2 +- common/rdr/TLSException.h | 4 +- common/rdr/TLSInStream.cxx | 10 ++--- common/rdr/TLSOutStream.cxx | 6 +-- common/rfb/CConnection.cxx | 20 +++++----- common/rfb/CConnection.h | 2 +- common/rfb/CMsgReader.cxx | 26 ++++++------ common/rfb/CSecurityDH.cxx | 4 +- common/rfb/CSecurityRSAAES.cxx | 16 ++++---- common/rfb/CSecurityTLS.cxx | 62 ++++++++++++++--------------- common/rfb/CSecurityVeNCrypt.cxx | 12 +++--- common/rfb/DecodeManager.cxx | 4 +- common/rfb/Exception.h | 16 ++++---- common/rfb/HextileDecoder.cxx | 2 +- common/rfb/JpegDecompressor.cxx | 2 +- common/rfb/PixelFormat.cxx | 2 +- common/rfb/RREDecoder.cxx | 2 +- common/rfb/SConnection.cxx | 14 +++---- common/rfb/SConnection.h | 13 +++--- common/rfb/SMsgReader.cxx | 16 ++++---- common/rfb/SSecurity.h | 17 ++++---- common/rfb/SSecurityPlain.cxx | 6 +-- common/rfb/SSecurityRSAAES.cxx | 20 +++++----- common/rfb/SSecurityTLS.cxx | 28 ++++++------- common/rfb/SSecurityVeNCrypt.cxx | 8 ++-- common/rfb/SSecurityVncAuth.cxx | 2 +- common/rfb/TightDecoder.cxx | 10 ++--- common/rfb/VNCSConnectionST.cxx | 4 +- common/rfb/ZRLEDecoder.cxx | 6 +-- tests/perf/decperf.cxx | 2 +- tests/perf/encperf.cxx | 2 +- unix/tx/TXDialog.h | 2 +- unix/vncconfig/vncconfig.cxx | 2 +- unix/x0vncserver/x0vncserver.cxx | 2 +- vncviewer/CConn.cxx | 6 +-- vncviewer/ServerDialog.cxx | 6 +-- vncviewer/Surface_Win32.cxx | 22 +++++----- vncviewer/UserDialog.cxx | 4 +- vncviewer/parameters.cxx | 32 +++++++-------- vncviewer/vncviewer.cxx | 2 +- win/rfb_win32/CleanDesktop.cxx | 2 +- win/rfb_win32/Clipboard.cxx | 6 +-- win/rfb_win32/CompatibleBitmap.h | 2 +- win/rfb_win32/CurrentUser.cxx | 6 +-- win/rfb_win32/DIBSectionBuffer.cxx | 4 +- win/rfb_win32/DeviceContext.cxx | 14 +++---- win/rfb_win32/DeviceFrameBuffer.cxx | 8 ++-- win/rfb_win32/Dialog.cxx | 4 +- win/rfb_win32/IconInfo.h | 2 +- win/rfb_win32/IntervalTimer.h | 2 +- win/rfb_win32/LaunchProcess.cxx | 6 +-- win/rfb_win32/LocalMem.h | 2 +- win/rfb_win32/MonitorInfo.cxx | 6 +-- win/rfb_win32/MsgWindow.cxx | 4 +- win/rfb_win32/RegConfig.cxx | 4 +- win/rfb_win32/Registry.cxx | 38 +++++++++--------- win/rfb_win32/SInput.cxx | 2 +- win/rfb_win32/Security.cxx | 26 ++++++------ win/rfb_win32/Service.cxx | 30 +++++++------- win/rfb_win32/SocketManager.cxx | 10 ++--- win/rfb_win32/TsSessions.cxx | 4 +- win/rfb_win32/WMCursor.cxx | 2 +- win/rfb_win32/WMPoller.cxx | 2 +- win/rfb_win32/Win32Util.cxx | 6 +-- win/vncconfig/Legacy.cxx | 2 +- win/vncconfig/vncconfig.cxx | 4 +- win/winvnc/QueryConnectDialog.cxx | 2 +- win/winvnc/VNCServerWin32.cxx | 4 +- win/winvnc/winvnc.cxx | 4 +- 81 files changed, 388 insertions(+), 386 deletions(-) diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 03844acd33..879a63d0f7 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -55,7 +55,7 @@ void network::initSockets() { 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 @@ -163,7 +163,7 @@ Socket* SocketListener::accept() { // 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); @@ -181,7 +181,7 @@ void SocketListener::listen(int 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; diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 455df749b5..bf603755b2 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -85,15 +85,15 @@ int network::findFreeTcpPort (void) 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); @@ -137,7 +137,7 @@ TcpSocket::TcpSocket(const char *host, int 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; @@ -178,7 +178,7 @@ TcpSocket::TcpSocket(const char *host, int port) 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 */ @@ -205,7 +205,7 @@ TcpSocket::TcpSocket(const char *host, int port) 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 @@ -302,7 +302,7 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, 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 @@ -310,7 +310,7 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, 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) */ @@ -328,14 +328,14 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, (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); @@ -446,7 +446,7 @@ void network::createTcpListeners(std::list *listeners, 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); @@ -485,7 +485,7 @@ void network::createTcpListeners(std::list *listeners, 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) { @@ -633,7 +633,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { } 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); diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index 4b82b4b728..c8517300cb 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -53,12 +53,12 @@ UnixSocket::UnixSocket(const char *path) 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)); @@ -72,7 +72,7 @@ UnixSocket::UnixSocket(const char *path) } if (result == -1) - throw SocketException("unable to connect to socket", err); + throw socket_error("unable to connect to socket", err); setFd(sock); } @@ -119,11 +119,11 @@ UnixListener::UnixListener(const char *path, int mode) 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); @@ -138,14 +138,14 @@ UnixListener::UnixListener(const char *path, int mode) 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); diff --git a/common/os/Mutex.cxx b/common/os/Mutex.cxx index b82de4152e..1889e66b43 100644 --- a/common/os/Mutex.cxx +++ b/common/os/Mutex.cxx @@ -43,7 +43,7 @@ Mutex::Mutex() 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 } @@ -67,7 +67,7 @@ void Mutex::lock() 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 } @@ -80,7 +80,7 @@ void Mutex::unlock() 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 } @@ -97,7 +97,7 @@ Condition::Condition(Mutex* mutex_) 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 } @@ -120,14 +120,14 @@ void Condition::wait() (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 } @@ -140,7 +140,7 @@ void Condition::signal() 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 } @@ -153,6 +153,6 @@ void Condition::broadcast() 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 } diff --git a/common/os/Thread.cxx b/common/os/Thread.cxx index e99be63e24..6dca75a1d1 100644 --- a/common/os/Thread.cxx +++ b/common/os/Thread.cxx @@ -66,7 +66,7 @@ void Thread::start() #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; @@ -76,14 +76,14 @@ void Thread::start() 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; @@ -99,13 +99,13 @@ void Thread::wait() 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 } diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx index 65bd972078..694ee35989 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -43,21 +43,21 @@ 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]; @@ -71,21 +71,21 @@ std::string GAIException::strerror(int err_) const #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]; @@ -100,21 +100,21 @@ std::string PosixException::strerror(int err_) const } #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]; diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index 3e0ec46703..f3f878cbb8 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -27,52 +27,52 @@ 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") {} }; } diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx index bddee482f7..23ea2f8cc8 100644 --- a/common/rdr/FdInStream.cxx +++ b/common/rdr/FdInStream.cxx @@ -92,7 +92,7 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SocketException("select", errorNumber); + throw socket_error("select", errorNumber); if (n == 0) return 0; @@ -102,9 +102,9 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } 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; } diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 1b6049caeb..6db8c0bb22 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -117,7 +117,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SocketException("select", errorNumber); + throw socket_error("select", errorNumber); if (n == 0) return 0; @@ -134,7 +134,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && (errorNumber == EINTR)); if (n < 0) - throw SocketException("write", errorNumber); + throw socket_error("write", errorNumber); gettimeofday(&lastWrite, nullptr); diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx index db646a7e4b..df09ea768c 100644 --- a/common/rdr/FileInStream.cxx +++ b/common/rdr/FileInStream.cxx @@ -33,7 +33,7 @@ FileInStream::FileInStream(const char *fileName) { file = fopen(fileName, "rb"); if (!file) - throw PosixException("fopen", errno); + throw posix_error("fopen", errno); } FileInStream::~FileInStream(void) { @@ -48,9 +48,9 @@ bool FileInStream::fillBuffer() 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; diff --git a/common/rdr/MemInStream.h b/common/rdr/MemInStream.h index e10273b165..78ee2dee4d 100644 --- a/common/rdr/MemInStream.h +++ b/common/rdr/MemInStream.h @@ -59,7 +59,7 @@ namespace rdr { 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; }; diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx index 449a84c0ae..485259cf14 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -89,7 +89,7 @@ bool RandomStream::fillBuffer() { #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 @@ -97,8 +97,8 @@ bool RandomStream::fillBuffer() { 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 diff --git a/common/rdr/TLSException.cxx b/common/rdr/TLSException.cxx index 7061f38b14..ccff6090ca 100644 --- a/common/rdr/TLSException.cxx +++ b/common/rdr/TLSException.cxx @@ -35,7 +35,7 @@ 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_) diff --git a/common/rdr/TLSException.h b/common/rdr/TLSException.h index f58b618ded..cfa73f697f 100644 --- a/common/rdr/TLSException.h +++ b/common/rdr/TLSException.h @@ -25,10 +25,10 @@ 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_); }; } diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index 3418c68edd..7c867e88c2 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -54,12 +54,12 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) 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()); @@ -121,10 +121,10 @@ size_t TLSInStream::readTLS(uint8_t* buf, size_t len) 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; } diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index 4c6c3f473a..1e555fc15f 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -46,10 +46,10 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, 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()); @@ -118,7 +118,7 @@ size_t TLSOutStream::writeTLS(const uint8_t* data, size_t length) throw *saved_exception; if (n < 0) - throw TLSException("writeTLS", n); + throw tls_error("writeTLS", n); return n; } diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 8a718b5f2d..a4d6d17354 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -172,7 +172,7 @@ bool CConnection::processVersionMsg() 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); @@ -185,10 +185,10 @@ bool CConnection::processVersionMsg() 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)) { @@ -235,7 +235,7 @@ bool CConnection::processSecurityTypesMsg() 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 { @@ -285,7 +285,7 @@ bool CConnection::processSecurityTypesMsg() 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; @@ -329,12 +329,12 @@ bool CConnection::processSecurityResultMsg() 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; @@ -360,7 +360,7 @@ bool CConnection::processSecurityReasonMsg() reason[len] = '\0'; state_ = RFBSTATE_INVALID; - throw AuthFailureException(reason.data()); + throw auth_error(reason.data()); } bool CConnection::processInitMsg() diff --git a/common/rfb/CConnection.h b/common/rfb/CConnection.h index 3f277d7163..9101bf2672 100644 --- a/common/rfb/CConnection.h +++ b/common/rfb/CConnection.h @@ -273,7 +273,7 @@ namespace rfb { bool processSecurityResultMsg(); bool processSecurityReasonMsg(); bool processInitMsg(); - void throwAuthFailureException(); + void throwAuthError(); void securityCompleted(); void requestNewUpdate(); diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index 17c92227a6..3025959f03 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -119,7 +119,7 @@ bool CMsgReader::readMsg() ret = readEndOfContinuousUpdates(); break; default: - throw ProtocolException(format("Unknown message type %d", currentMsgType)); + throw protocol_error(format("Unknown message type %d", currentMsgType)); } if (ret) @@ -301,7 +301,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) 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); @@ -323,7 +323,7 @@ bool CMsgReader::readExtendedClipboard(int32_t 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++) { @@ -348,7 +348,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) continue; if (!zis.hasData(4)) - throw ProtocolException("Extended clipboard decode error"); + throw protocol_error("Extended clipboard decode error"); lengths[num] = zis.readU32(); @@ -361,7 +361,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) 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]) @@ -377,7 +377,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) } 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]); @@ -407,7 +407,7 @@ bool CMsgReader::readExtendedClipboard(int32_t len) handler->handleClipboardNotify(flags); break; default: - throw ProtocolException("Invalid extended clipboard action"); + throw protocol_error("Invalid extended clipboard action"); } } @@ -473,7 +473,7 @@ bool CMsgReader::readRect(const Rect& r, int encoding) 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()) @@ -485,7 +485,7 @@ bool CMsgReader::readRect(const Rect& r, int encoding) 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 rgba(width*height*4); @@ -549,7 +549,7 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) 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; @@ -595,7 +595,7 @@ bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) 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); @@ -656,7 +656,7 @@ bool CMsgReader::readSetCursorWithAlpha(int width, int height, const Point& hots 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; @@ -750,7 +750,7 @@ bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot handler->setCursor(width, height, hotspot, data.data()); } else { - throw ProtocolException("Unknown cursor type"); + throw protocol_error("Unknown cursor type"); } return true; diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index ca110cb2c2..d8308cbf8a 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -86,9 +86,9 @@ bool CSecurityDH::readKey() 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(); diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 11c392d5b1..96fd20cd6a 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -174,9 +174,9 @@ bool CSecurityRSAAES::readPublicKey() 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; @@ -189,7 +189,7 @@ bool CSecurityRSAAES::readPublicKey() 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; } @@ -215,7 +215,7 @@ void CSecurityRSAAES::verifyServer() "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() @@ -255,7 +255,7 @@ bool CSecurityRSAAES::readRandom() 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(); @@ -268,7 +268,7 @@ bool CSecurityRSAAES::readRandom() 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; @@ -397,7 +397,7 @@ bool CSecurityRSAAES::readHash() 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; } @@ -427,7 +427,7 @@ bool CSecurityRSAAES::readSubtype() 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; } diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index fc1cde8e2b..3761ca30bf 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -80,7 +80,7 @@ CSecurityTLS::CSecurityTLS(CConnection* cc_, bool _anon) { 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() @@ -146,15 +146,15 @@ bool CSecurityTLS::processMsg() 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(); @@ -177,7 +177,7 @@ bool CSecurityTLS::processMsg() 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", @@ -215,7 +215,7 @@ void CSecurityTLS::setParam() 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; @@ -227,7 +227,7 @@ void CSecurityTLS::setParam() 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 @@ -248,7 +248,7 @@ void CSecurityTLS::setParam() 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 } @@ -256,17 +256,17 @@ void CSecurityTLS::setParam() 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"); @@ -279,7 +279,7 @@ void CSecurityTLS::setParam() 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(), @@ -312,12 +312,12 @@ void CSecurityTLS::checkSession() 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) { @@ -334,13 +334,13 @@ void CSecurityTLS::checkSession() &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())); } @@ -349,7 +349,7 @@ void CSecurityTLS::checkSession() &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); @@ -360,7 +360,7 @@ void CSecurityTLS::checkSession() 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; @@ -368,7 +368,7 @@ void CSecurityTLS::checkSession() 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"); @@ -407,12 +407,12 @@ void CSecurityTLS::checkSession() 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++) { @@ -444,7 +444,7 @@ void CSecurityTLS::checkSession() 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 | @@ -464,7 +464,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Certificate is not yet valid", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_NOT_ACTIVATED; } @@ -483,7 +483,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Expired certificate", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_EXPIRED; } @@ -502,7 +502,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Insecure certificate algorithm", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_INSECURE_ALGORITHM; } @@ -527,7 +527,7 @@ void CSecurityTLS::checkSession() 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; @@ -553,7 +553,7 @@ void CSecurityTLS::checkSession() 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 | @@ -576,7 +576,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Unexpected server certificate", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_NOT_ACTIVATED; } @@ -597,7 +597,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Unexpected server certificate", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_EXPIRED; } @@ -618,7 +618,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Unexpected server certificate", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); status &= ~GNUTLS_CERT_INSECURE_ALGORITHM; } @@ -645,7 +645,7 @@ void CSecurityTLS::checkSession() if (!cc->showMsgBox(MsgBoxFlags::M_YESNO, "Unexpected server certificate", text.c_str())) - throw AuthCancelledException(); + throw auth_cancelled(); } } diff --git a/common/rfb/CSecurityVeNCrypt.cxx b/common/rfb/CSecurityVeNCrypt.cxx index 606fd96f60..1b6ecf2205 100644 --- a/common/rfb/CSecurityVeNCrypt.cxx +++ b/common/rfb/CSecurityVeNCrypt.cxx @@ -105,7 +105,7 @@ bool CSecurityVeNCrypt::processMsg() 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; @@ -117,8 +117,8 @@ bool CSecurityVeNCrypt::processMsg() 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; } @@ -131,7 +131,7 @@ bool CSecurityVeNCrypt::processMsg() 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; @@ -172,7 +172,7 @@ bool CSecurityVeNCrypt::processMsg() /* 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); @@ -191,7 +191,7 @@ bool CSecurityVeNCrypt::processMsg() * 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(); diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 0475d62d08..09118f36e6 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -114,14 +114,14 @@ bool DecodeManager::decodeRect(const Rect& r, int encoding, 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"); } } diff --git a/common/rfb/Exception.h b/common/rfb/Exception.h index 3b81b4a732..0e74209ca4 100644 --- a/common/rfb/Exception.h +++ b/common/rfb/Exception.h @@ -22,21 +22,21 @@ #include 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") {} }; } diff --git a/common/rfb/HextileDecoder.cxx b/common/rfb/HextileDecoder.cxx index d440b1af2e..35ec79285f 100644 --- a/common/rfb/HextileDecoder.cxx +++ b/common/rfb/HextileDecoder.cxx @@ -189,7 +189,7 @@ void HextileDecoder::hextileDecode(const Rect& r, rdr::InStream* is, 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; diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index 60c215fc78..10c9e49cd6 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -217,7 +217,7 @@ void JpegDecompressor::decompress(const uint8_t *jpegBuf, 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) { diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx index a538deb720..e312b3c91c 100644 --- a/common/rfb/PixelFormat.cxx +++ b/common/rfb/PixelFormat.cxx @@ -180,7 +180,7 @@ void PixelFormat::read(rdr::InStream* is) } if (!isSane()) - throw ProtocolException("invalid pixel format"); + throw protocol_error("invalid pixel format"); updateState(); } diff --git a/common/rfb/RREDecoder.cxx b/common/rfb/RREDecoder.cxx index 4f2db0710c..53ddc2da49 100644 --- a/common/rfb/RREDecoder.cxx +++ b/common/rfb/RREDecoder.cxx @@ -107,7 +107,7 @@ void RREDecoder::rreDecode(const Rect& r, rdr::InStream* is, 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); } diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index 6e58b3b463..0cde5bc69a 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -123,7 +123,7 @@ bool SConnection::processVersionMsg() 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); @@ -215,7 +215,7 @@ void SConnection::processSecurityType(int secType) 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); @@ -234,8 +234,8 @@ bool SConnection::processSecurityMsg() 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 @@ -320,7 +320,7 @@ void SConnection::failConnection(const char* message) } state_ = RFBSTATE_INVALID; - throw ProtocolException(message); + throw protocol_error(message); } void SConnection::failConnection(const std::string& message) @@ -474,9 +474,9 @@ void SConnection::approveConnection(bool accept, const char* reason) } else { state_ = RFBSTATE_INVALID; if (reason) - throw AuthFailureException(reason); + throw auth_error(reason); else - throw AuthFailureException("Connection rejected"); + throw auth_error("Connection rejected"); } } diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index 886972af79..ccffa74fc1 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -68,12 +68,13 @@ namespace rfb { // 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); diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index ee37370efa..fcc0a63c81 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -107,7 +107,7 @@ bool SMsgReader::readMsg() break; default: vlog.error("unknown message type %d", currentMsgType); - throw ProtocolException("unknown message type"); + throw protocol_error("unknown message type"); } if (ret) @@ -334,7 +334,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) 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); @@ -356,7 +356,7 @@ bool SMsgReader::readExtendedClipboard(int32_t 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++) { @@ -381,7 +381,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) continue; if (!zis.hasData(4)) - throw ProtocolException("Extended clipboard decode error"); + throw protocol_error("Extended clipboard decode error"); lengths[num] = zis.readU32(); @@ -394,7 +394,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) 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]) @@ -410,7 +410,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) } 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]); @@ -440,7 +440,7 @@ bool SMsgReader::readExtendedClipboard(int32_t len) handler->handleClipboardNotify(flags); break; default: - throw ProtocolException("Invalid extended clipboard action"); + throw protocol_error("Invalid extended clipboard action"); } } @@ -464,7 +464,7 @@ bool SMsgReader::readQEMUMessage() 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) { diff --git a/common/rfb/SSecurity.h b/common/rfb/SSecurity.h index 8e296c5ac9..0911ecd83b 100644 --- a/common/rfb/SSecurity.h +++ b/common/rfb/SSecurity.h @@ -20,14 +20,15 @@ // 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. diff --git a/common/rfb/SSecurityPlain.cxx b/common/rfb/SSecurityPlain.cxx index 1115b7ff28..e62e6d6086 100644 --- a/common/rfb/SSecurityPlain.cxx +++ b/common/rfb/SSecurityPlain.cxx @@ -95,11 +95,11 @@ bool SSecurityPlain::processMsg() 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; } @@ -114,7 +114,7 @@ bool SSecurityPlain::processMsg() username[ulen] = 0; plen = 0; if (!valid->validate(sc, username, password)) - throw AuthFailureException("Authentication failed"); + throw auth_error("Authentication failed"); } return true; diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 45f5c293b3..2f26de2680 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -159,7 +159,7 @@ void SSecurityRSAAES::loadPrivateKey() { 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) { @@ -170,7 +170,7 @@ void SSecurityRSAAES::loadPrivateKey() std::vector 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); @@ -299,9 +299,9 @@ bool SSecurityRSAAES::readPublicKey() 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; @@ -314,7 +314,7 @@ bool SSecurityRSAAES::readPublicKey() 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; } @@ -363,7 +363,7 @@ bool SSecurityRSAAES::readRandom() 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(); @@ -376,7 +376,7 @@ bool SSecurityRSAAES::readRandom() 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; @@ -505,7 +505,7 @@ bool SSecurityRSAAES::readHash() 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; } @@ -565,7 +565,7 @@ void SSecurityRSAAES::verifyUserPass() #endif if (!valid->validate(sc, username, password)) { delete valid; - throw AuthFailureException("Authentication failed"); + throw auth_error("Authentication failed"); } delete valid; #else @@ -592,7 +592,7 @@ void SSecurityRSAAES::verifyPass() return; } - throw AuthFailureException("Authentication failed"); + throw auth_error("Authentication failed"); } const char* SSecurityRSAAES::getUserName() const diff --git a/common/rfb/SSecurityTLS.cxx b/common/rfb/SSecurityTLS.cxx index b8377e656e..4b036e273f 100644 --- a/common/rfb/SSecurityTLS.cxx +++ b/common/rfb/SSecurityTLS.cxx @@ -80,7 +80,7 @@ SSecurityTLS::SSecurityTLS(SConnection* sc_, bool _anon) 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() @@ -152,11 +152,11 @@ bool SSecurityTLS::processMsg() 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(); @@ -186,7 +186,7 @@ bool SSecurityTLS::processMsg() } 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", @@ -222,7 +222,7 @@ void SSecurityTLS::setParams() 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; @@ -234,7 +234,7 @@ void SSecurityTLS::setParams() 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 @@ -255,7 +255,7 @@ void SSecurityTLS::setParams() 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 } @@ -263,18 +263,18 @@ void SSecurityTLS::setParams() #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); @@ -282,14 +282,14 @@ void SSecurityTLS::setParams() 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); @@ -299,11 +299,11 @@ void SSecurityTLS::setParams() 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"); diff --git a/common/rfb/SSecurityVeNCrypt.cxx b/common/rfb/SSecurityVeNCrypt.cxx index e4347fb6b8..4617fddba9 100644 --- a/common/rfb/SSecurityVeNCrypt.cxx +++ b/common/rfb/SSecurityVeNCrypt.cxx @@ -99,7 +99,7 @@ bool SSecurityVeNCrypt::processMsg() 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 */ @@ -109,7 +109,7 @@ bool SSecurityVeNCrypt::processMsg() 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"); } } @@ -138,7 +138,7 @@ bool SSecurityVeNCrypt::processMsg() 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) */ @@ -163,7 +163,7 @@ bool SSecurityVeNCrypt::processMsg() /* 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); } diff --git a/common/rfb/SSecurityVncAuth.cxx b/common/rfb/SSecurityVncAuth.cxx index b0401840e3..c4899aa907 100644 --- a/common/rfb/SSecurityVncAuth.cxx +++ b/common/rfb/SSecurityVncAuth.cxx @@ -113,7 +113,7 @@ bool SSecurityVncAuth::processMsg() return true; } - throw AuthFailureException("Authentication failed"); + throw auth_error("Authentication failed"); } VncAuthPasswdParameter::VncAuthPasswdParameter(const char* name_, diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index ff05b279f1..ccf45a9df6 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -104,14 +104,14 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, // 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) { @@ -143,12 +143,12 @@ bool TightDecoder::readRect(const Rect& r, rdr::InStream* is, 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"); } } @@ -384,7 +384,7 @@ void TightDecoder::decodeRect(const Rect& r, const uint8_t* buffer, 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(); diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 6f207eb055..c1cb96f2df 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -189,7 +189,7 @@ void VNCSConnectionST::processMessages() // 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()); @@ -730,7 +730,7 @@ void VNCSConnectionST::enableContinuousUpdates(bool enable, 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; diff --git a/common/rfb/ZRLEDecoder.cxx b/common/rfb/ZRLEDecoder.cxx index eab16bafa7..633d1c36eb 100644 --- a/common/rfb/ZRLEDecoder.cxx +++ b/common/rfb/ZRLEDecoder.cxx @@ -64,7 +64,7 @@ static inline T readPixel(rdr::ZlibInStream* zis) 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) @@ -242,7 +242,7 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, } while (b == 255); if (end - ptr < len) { - throw ProtocolException("ZRLE decode error"); + throw protocol_error("ZRLE decode error"); } while (len-- > 0) *ptr++ = pix; @@ -267,7 +267,7 @@ void ZRLEDecoder::zrleDecode(const Rect& r, rdr::InStream* is, } while (b == 255); if (end - ptr < len) { - throw ProtocolException("ZRLE decode error"); + throw protocol_error("ZRLE decode error"); } } diff --git a/tests/perf/decperf.cxx b/tests/perf/decperf.cxx index 41a93b3a56..46f42fa2ef 100644 --- a/tests/perf/decperf.cxx +++ b/tests/perf/decperf.cxx @@ -210,7 +210,7 @@ static struct stats runTest(const char *fn) 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); diff --git a/tests/perf/encperf.cxx b/tests/perf/encperf.cxx index 9c7c77fda9..d761bbed0c 100644 --- a/tests/perf/encperf.cxx +++ b/tests/perf/encperf.cxx @@ -380,7 +380,7 @@ static struct stats runTest(const char *fn) 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); diff --git a/unix/tx/TXDialog.h b/unix/tx/TXDialog.h index c663ffaeca..6533377f6b 100644 --- a/unix/tx/TXDialog.h +++ b/unix/tx/TXDialog.h @@ -65,7 +65,7 @@ class TXDialog : public TXWindow, public TXDeleteWindowCallback { 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; diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx index 421b45f941..ecc6eddc28 100644 --- a/unix/vncconfig/vncconfig.cxx +++ b/unix/vncconfig/vncconfig.cxx @@ -330,7 +330,7 @@ int main(int argc, char** argv) 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); diff --git a/unix/x0vncserver/x0vncserver.cxx b/unix/x0vncserver/x0vncserver.cxx index 81e07d57e5..03f31576d9 100644 --- a/unix/x0vncserver/x0vncserver.cxx +++ b/unix/x0vncserver/x0vncserver.cxx @@ -436,7 +436,7 @@ int main(int argc, char** argv) vlog.debug("Interrupted select() system call"); continue; } else { - throw rdr::SocketException("select", errno); + throw rdr::socket_error("select", errno); } } diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 90021d9563..31f5321d44 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -263,7 +263,7 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) } 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 " @@ -273,10 +273,10 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) } 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 " diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index 18909a6071..e24438d6b6 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -361,7 +361,7 @@ void ServerDialog::loadServerHistory() 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; @@ -377,7 +377,7 @@ void ServerDialog::loadServerHistory() 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); @@ -436,7 +436,7 @@ void ServerDialog::saveServerHistory() 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. diff --git a/vncviewer/Surface_Win32.cxx b/vncviewer/Surface_Win32.cxx index 67ba15c5ce..c992dbea40 100644 --- a/vncviewer/Surface_Win32.cxx +++ b/vncviewer/Surface_Win32.cxx @@ -57,10 +57,10 @@ void Surface::draw(int src_x, int src_y, int dst_x, int dst_y, 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)) { @@ -70,7 +70,7 @@ void Surface::draw(int src_x, int src_y, int dst_x, int dst_y, // 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); @@ -83,10 +83,10 @@ void Surface::draw(Surface* dst, int src_x, int src_y, 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; @@ -113,15 +113,15 @@ void Surface::blend(Surface* dst, int src_x, int src_y, 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; @@ -136,7 +136,7 @@ void Surface::blend(Surface* dst, int src_x, int src_y, // 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); @@ -161,7 +161,7 @@ void Surface::alloc() 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() diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index 56e6c17f0a..2c8d84744b 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -117,7 +117,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, 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); @@ -248,7 +248,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, delete win; if (ret_val != 0) - throw rfb::AuthCancelledException(); + throw rfb::auth_cancelled(); } bool UserDialog::showMsgBox(MsgBoxFlags flags, const char* title, const char* text) diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index b66c7da284..a6229a349c 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -320,7 +320,7 @@ static void setKeyString(const char *_name, const char *_value, HKEY* hKey) { 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); } @@ -336,7 +336,7 @@ static void setKeyInt(const char *_name, const int _value, HKEY* hKey) { 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); } @@ -357,7 +357,7 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h 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; } @@ -394,7 +394,7 @@ static bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { 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; } @@ -414,7 +414,7 @@ static void removeValue(const char* _name, HKEY* hKey) { 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; } @@ -428,7 +428,7 @@ void saveHistoryToRegKey(const list& serverHistory) { &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); @@ -449,7 +449,7 @@ void saveHistoryToRegKey(const list& serverHistory) { 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) { @@ -461,7 +461,7 @@ 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); @@ -506,7 +506,7 @@ static void saveToReg(const char* servername) { 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 loadHistoryFromRegKey() { @@ -522,7 +522,7 @@ list loadHistoryFromRegKey() { return serverHistory; } - throw rdr::Win32Exception(_("Failed to open registry key"), res); + throw rdr::win32_error(_("Failed to open registry key"), res); } unsigned index; @@ -549,7 +549,7 @@ list loadHistoryFromRegKey() { 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; } @@ -596,7 +596,7 @@ static char* loadFromReg() { 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; @@ -618,7 +618,7 @@ static char* loadFromReg() { 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; } @@ -652,7 +652,7 @@ void saveViewerParameters(const char *filename, const char *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); @@ -760,7 +760,7 @@ char* loadViewerParameters(const char *filename) { 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; @@ -775,7 +775,7 @@ char* loadViewerParameters(const char *filename) { 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)) { diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index df3b8964cb..5acab1a17c 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -773,7 +773,7 @@ int main(int argc, char** argv) vlog.debug("Interrupted select() system call"); continue; } else { - throw rdr::SocketException("select", errno); + throw rdr::socket_error("select", errno); } } diff --git a/win/rfb_win32/CleanDesktop.cxx b/win/rfb_win32/CleanDesktop.cxx index 6634d44506..02fdd37476 100644 --- a/win/rfb_win32/CleanDesktop.cxx +++ b/win/rfb_win32/CleanDesktop.cxx @@ -45,7 +45,7 @@ struct ActiveDesktop { 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) diff --git a/win/rfb_win32/Clipboard.cxx b/win/rfb_win32/Clipboard.cxx index 72e8999ec9..8577df462e 100644 --- a/win/rfb_win32/Clipboard.cxx +++ b/win/rfb_win32/Clipboard.cxx @@ -129,7 +129,7 @@ Clipboard::setClipText(const char* text) { // - 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)); @@ -144,11 +144,11 @@ Clipboard::setClipText(const char* 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"); diff --git a/win/rfb_win32/CompatibleBitmap.h b/win/rfb_win32/CompatibleBitmap.h index 0ecc6a3ddb..c8fdf82913 100644 --- a/win/rfb_win32/CompatibleBitmap.h +++ b/win/rfb_win32/CompatibleBitmap.h @@ -30,7 +30,7 @@ namespace rfb { 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); diff --git a/win/rfb_win32/CurrentUser.cxx b/win/rfb_win32/CurrentUser.cxx index 2ca48dd6d8..be36368289 100644 --- a/win/rfb_win32/CurrentUser.cxx +++ b/win/rfb_win32/CurrentUser.cxx @@ -80,7 +80,7 @@ CurrentUserToken::CurrentUserToken() { 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; } } @@ -96,7 +96,7 @@ ImpersonateCurrentUser::ImpersonateCurrentUser() { 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()); } } @@ -114,7 +114,7 @@ UserName::UserName() { 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); } diff --git a/win/rfb_win32/DIBSectionBuffer.cxx b/win/rfb_win32/DIBSectionBuffer.cxx index f6447b0d5e..440fe6b1b6 100644 --- a/win/rfb_win32/DIBSectionBuffer.cxx +++ b/win/rfb_win32/DIBSectionBuffer.cxx @@ -87,7 +87,7 @@ void DIBSectionBuffer::initBuffer(const PixelFormat& pf, int w, int h) { 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()"); @@ -130,7 +130,7 @@ void DIBSectionBuffer::initBuffer(const PixelFormat& pf, int w, int h) { // 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??? diff --git a/win/rfb_win32/DeviceContext.cxx b/win/rfb_win32/DeviceContext.cxx index 210bbf8025..1c64e1f519 100644 --- a/win/rfb_win32/DeviceContext.cxx +++ b/win/rfb_win32/DeviceContext.cxx @@ -51,10 +51,10 @@ PixelFormat DeviceContext::getPF(HDC dc) { 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 @@ -151,7 +151,7 @@ Rect DeviceContext::getClipBox(HDC dc) { // 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); } @@ -159,7 +159,7 @@ Rect DeviceContext::getClipBox(HDC dc) { 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() { @@ -171,7 +171,7 @@ 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() { @@ -183,7 +183,7 @@ 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() { @@ -195,7 +195,7 @@ 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()); } diff --git a/win/rfb_win32/DeviceFrameBuffer.cxx b/win/rfb_win32/DeviceFrameBuffer.cxx index 4da4d814a3..1c3e9575a2 100644 --- a/win/rfb_win32/DeviceFrameBuffer.cxx +++ b/win/rfb_win32/DeviceFrameBuffer.cxx @@ -102,7 +102,7 @@ DeviceFrameBuffer::grabRect(const Rect &rect) { if (ignoreGrabErrors) vlog.error("BitBlt failed:%ld", GetLastError()); else - throw rdr::Win32Exception("BitBlt failed", GetLastError()); + throw rdr::win32_error("BitBlt failed", GetLastError()); } } @@ -138,7 +138,7 @@ void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server) 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) @@ -174,7 +174,7 @@ void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server) 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; @@ -217,7 +217,7 @@ void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server) 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(); diff --git a/win/rfb_win32/Dialog.cxx b/win/rfb_win32/Dialog.cxx index d5938e8d52..e8af08465e 100644 --- a/win/rfb_win32/Dialog.cxx +++ b/win/rfb_win32/Dialog.cxx @@ -65,7 +65,7 @@ bool Dialog::showDialog(const char* resource, HWND owner) 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); } @@ -275,7 +275,7 @@ bool PropSheet::showPropSheet(HWND owner_, bool showApply, bool showCtxtHelp, bo 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); diff --git a/win/rfb_win32/IconInfo.h b/win/rfb_win32/IconInfo.h index ca23451476..991a5a13ae 100644 --- a/win/rfb_win32/IconInfo.h +++ b/win/rfb_win32/IconInfo.h @@ -28,7 +28,7 @@ namespace rfb { 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) diff --git a/win/rfb_win32/IntervalTimer.h b/win/rfb_win32/IntervalTimer.h index 5ced2c5eb5..b62040b35e 100644 --- a/win/rfb_win32/IntervalTimer.h +++ b/win/rfb_win32/IntervalTimer.h @@ -41,7 +41,7 @@ namespace rfb { 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; } } diff --git a/win/rfb_win32/LaunchProcess.cxx b/win/rfb_win32/LaunchProcess.cxx index beb7e6b717..38aa720f2d 100644 --- a/win/rfb_win32/LaunchProcess.cxx +++ b/win/rfb_win32/LaunchProcess.cxx @@ -53,7 +53,7 @@ void LaunchProcess::start(HANDLE userToken, bool createConsole) { 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); @@ -95,7 +95,7 @@ void LaunchProcess::start(HANDLE userToken, bool createConsole) { 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); @@ -119,7 +119,7 @@ bool LaunchProcess::await(DWORD timeoutMs) { detach(); return true; } else if (result == WAIT_FAILED) { - throw rdr::Win32Exception("await() failed", GetLastError()); + throw rdr::win32_error("await() failed", GetLastError()); } return false; } diff --git a/win/rfb_win32/LocalMem.h b/win/rfb_win32/LocalMem.h index e2dc80bd8a..5280dea3ce 100644 --- a/win/rfb_win32/LocalMem.h +++ b/win/rfb_win32/LocalMem.h @@ -28,7 +28,7 @@ namespace rfb { // 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);} diff --git a/win/rfb_win32/MonitorInfo.cxx b/win/rfb_win32/MonitorInfo.cxx index 854b467a6d..84a8d50147 100644 --- a/win/rfb_win32/MonitorInfo.cxx +++ b/win/rfb_win32/MonitorInfo.cxx @@ -44,7 +44,7 @@ static void fillMonitorInfo(HMONITOR monitor, MONITORINFOEXA* mi) { 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); @@ -57,7 +57,7 @@ MonitorInfo::MonitorInfo(HWND window) { 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); } @@ -67,7 +67,7 @@ MonitorInfo::MonitorInfo(const RECT& r) { 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); } diff --git a/win/rfb_win32/MsgWindow.cxx b/win/rfb_win32/MsgWindow.cxx index a5770e6710..4908126ec4 100644 --- a/win/rfb_win32/MsgWindow.cxx +++ b/win/rfb_win32/MsgWindow.cxx @@ -82,7 +82,7 @@ MsgWindowClass::MsgWindowClass() : classAtom(0) { 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()); } } @@ -104,7 +104,7 @@ MsgWindow::MsgWindow(const char* name_) : name(name_), handle(nullptr) { 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); } diff --git a/win/rfb_win32/RegConfig.cxx b/win/rfb_win32/RegConfig.cxx index d93e8eb45a..211570ca76 100644 --- a/win/rfb_win32/RegConfig.cxx +++ b/win/rfb_win32/RegConfig.cxx @@ -69,7 +69,7 @@ void RegConfig::loadRegistryConfig(RegKey& key) { 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()); } @@ -115,5 +115,5 @@ void RegConfigThread::worker() { 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()); } diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx index 54de8928bf..4775695075 100644 --- a/win/rfb_win32/Registry.cxx +++ b/win/rfb_win32/Registry.cxx @@ -54,7 +54,7 @@ RegKey::RegKey() : key(nullptr), freeKey(false), valueName(nullptr), valueNameBu 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; } @@ -62,7 +62,7 @@ RegKey::RegKey(const HKEY k) : key(nullptr), freeKey(false), valueName(nullptr), 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; } @@ -86,7 +86,7 @@ bool RegKey::createKey(const RegKey& root, const char* name) { 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; @@ -97,7 +97,7 @@ void RegKey::openKey(const RegKey& root, const char* name, bool readOnly) { 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; @@ -109,7 +109,7 @@ void RegKey::setDACL(const PACL acl, bool inherit) { 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() { @@ -123,19 +123,19 @@ 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); } @@ -144,22 +144,22 @@ RegKey::operator HKEY() const {return key;} 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 { @@ -214,11 +214,11 @@ std::string RegKey::getRepresentation(const char* valname) 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 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: @@ -243,7 +243,7 @@ std::string RegKey::getRepresentation(const char* valname) const { 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 expanded(required); length = ExpandEnvironmentStrings(str.c_str(), expanded.data(), required); if (required 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); } @@ -164,7 +164,7 @@ PACL rfb::win32::CreateACL(const AccessEntries& ae, PACL existing_acl) { 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; } @@ -172,18 +172,18 @@ PACL rfb::win32::CreateACL(const AccessEntries& ae, PACL existing_acl) { 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(); } diff --git a/win/rfb_win32/Service.cxx b/win/rfb_win32/Service.cxx index be3381da07..907e321425 100644 --- a/win/rfb_win32/Service.cxx +++ b/win/rfb_win32/Service.cxx @@ -115,7 +115,7 @@ Service::start() { 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 @@ -335,7 +335,7 @@ bool rfb::win32::registerService(const char* name, // - 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, @@ -344,7 +344,7 @@ bool rfb::win32::registerService(const char* name, 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}; @@ -380,14 +380,14 @@ bool rfb::win32::unregisterService(const char* name) { // - 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; @@ -407,16 +407,16 @@ bool rfb::win32::startService(const char* name) { // - 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); @@ -427,17 +427,17 @@ bool rfb::win32::stopService(const char* name) { // - 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); @@ -448,17 +448,17 @@ DWORD rfb::win32::getServiceState(const char* name) { // - 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; } diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 3d8c101e13..b42c66cb5a 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -69,7 +69,7 @@ void SocketManager::addListener(network::SocketListener* sock_, 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) @@ -186,7 +186,7 @@ int SocketManager::checkTimeouts() { 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()); } } @@ -236,11 +236,11 @@ void SocketManager::processEvent(HANDLE event) { // 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); @@ -268,7 +268,7 @@ void SocketManager::processEvent(HANDLE 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); diff --git a/win/rfb_win32/TsSessions.cxx b/win/rfb_win32/TsSessions.cxx index a8602ad2b1..faf83e894c 100644 --- a/win/rfb_win32/TsSessions.cxx +++ b/win/rfb_win32/TsSessions.cxx @@ -35,7 +35,7 @@ namespace win32 { if (processId == (DWORD)-1) processId = GetCurrentProcessId(); if (!ProcessIdToSessionId(GetCurrentProcessId(), &id)) - throw rdr::Win32Exception("ProcessIdToSessionId", GetLastError()); + throw rdr::win32_error("ProcessIdToSessionId", GetLastError()); } ProcessSessionId mySessionId; @@ -57,7 +57,7 @@ namespace win32 { 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(); diff --git a/win/rfb_win32/WMCursor.cxx b/win/rfb_win32/WMCursor.cxx index 603c7bc3e9..65d7a9d7bf 100644 --- a/win/rfb_win32/WMCursor.cxx +++ b/win/rfb_win32/WMCursor.cxx @@ -45,7 +45,7 @@ WMCursor::getCursorInfo() { 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; diff --git a/win/rfb_win32/WMPoller.cxx b/win/rfb_win32/WMPoller.cxx index db2672699e..98e8dce340 100644 --- a/win/rfb_win32/WMPoller.cxx +++ b/win/rfb_win32/WMPoller.cxx @@ -58,7 +58,7 @@ bool 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; diff --git a/win/rfb_win32/Win32Util.cxx b/win/rfb_win32/Win32Util.cxx index b22311af37..b35bf6291f 100644 --- a/win/rfb_win32/Win32Util.cxx +++ b/win/rfb_win32/Win32Util.cxx @@ -46,19 +46,19 @@ FileVersionInfo::FileVersionInfo(const char* filename) { { 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() { diff --git a/win/vncconfig/Legacy.cxx b/win/vncconfig/Legacy.cxx index 1edc2bfa69..c6b245cc0b 100644 --- a/win/vncconfig/Legacy.cxx +++ b/win/vncconfig/Legacy.cxx @@ -42,7 +42,7 @@ void LegacyPage::LoadPrefs() std::string username; try { username = UserName(); - } catch (rdr::Win32Exception& e) { + } catch (rdr::win32_error& e) { if (e.err != ERROR_NOT_LOGGED_ON) throw; } diff --git a/win/vncconfig/vncconfig.cxx b/win/vncconfig/vncconfig.cxx index de3a4620ac..7e692b9b76 100644 --- a/win/vncconfig/vncconfig.cxx +++ b/win/vncconfig/vncconfig.cxx @@ -125,7 +125,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE /*prev*/, char* /*cmdLine*/, int /* // 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) { @@ -169,7 +169,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE /*prev*/, char* /*cmdLine*/, int /* #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", diff --git a/win/winvnc/QueryConnectDialog.cxx b/win/winvnc/QueryConnectDialog.cxx index 6ec62bbd56..1ef26e6380 100644 --- a/win/winvnc/QueryConnectDialog.cxx +++ b/win/winvnc/QueryConnectDialog.cxx @@ -74,7 +74,7 @@ void QueryConnectDialog::worker() { 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)"; diff --git a/win/winvnc/VNCServerWin32.cxx b/win/winvnc/VNCServerWin32.cxx index d98aaa105f..cea0fe7837 100644 --- a/win/winvnc/VNCServerWin32.cxx +++ b/win/winvnc/VNCServerWin32.cxx @@ -188,7 +188,7 @@ int VNCServerWin32::run() { 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); @@ -196,7 +196,7 @@ int VNCServerWin32::run() { } 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) { diff --git a/win/winvnc/winvnc.cxx b/win/winvnc/winvnc.cxx index 4feff6b23b..1a370522de 100644 --- a/win/winvnc/winvnc.cxx +++ b/win/winvnc/winvnc.cxx @@ -177,13 +177,13 @@ static void processParams(int argc, char** argv) { // 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,