📄 vncserver.cpp
字号:
}
// Is this the entry we're interested in?
if ((strcmp(current->_machineName, hostname) == 0) &&
(current->_blocked)) {
// Machine is blocked, so just reject it
return vncServer::aqrReject;
}
previous = current;
current = current->_next;
}
// Has a hostname been specified?
if (hostname == 0) {
vnclog.Print(LL_INTWARN, VNCLOG("verify failed - null hostname\n"));
return vncServer::aqrReject;
}
// Set the state machine into the correct mode & process the filter
enum vh_Mode {vh_ExpectDelimiter, vh_ExpectIncludeExclude, vh_ExpectPattern};
vh_Mode machineMode = vh_ExpectIncludeExclude;
vncServer::AcceptQueryReject verifiedHost = vncServer::aqrAccept;
vncServer::AcceptQueryReject patternType = vncServer::aqrReject;
UINT authHostsPos = 0;
UINT patternStart = 0;
UINT hostNameLen = strlen(hostname);
// Run through the auth hosts string until we hit the end
if (m_auth_hosts) {
while (1) {
// Which mode are we in?
switch (machineMode) {
// ExpectIncludeExclude - we should see a + or -.
case vh_ExpectIncludeExclude:
if (m_auth_hosts[authHostsPos] == '+') {
patternType = vncServer::aqrAccept;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] == '-') {
patternType = vncServer::aqrReject;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] == '?') {
patternType = vncServer::aqrQuery;
patternStart = authHostsPos+1;
machineMode = vh_ExpectPattern;
} else if (m_auth_hosts[authHostsPos] != '\0') {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - malformed AuthHosts string\n"));
machineMode = vh_ExpectDelimiter;
}
break;
// ExpectPattern - we expect to see a valid pattern
case vh_ExpectPattern:
// ExpectDelimiter - we're scanning for the next ':', skipping a pattern
case vh_ExpectDelimiter:
if ((m_auth_hosts[authHostsPos] == ':') ||
(m_auth_hosts[authHostsPos] == '\0')) {
if (machineMode == vh_ExpectPattern) {
if (patternStart == 0) {
vnclog.Print(LL_INTWARN, VNCLOG("verify host - pattern processing failed!\n"));
} else {
// Process the match
if (MatchStringToTemplate(hostname, hostNameLen,
&(m_auth_hosts[patternStart]), authHostsPos-patternStart)) {
// The hostname matched - apply the include/exclude rule
verifiedHost = patternType;
}
}
}
// We now expect another + or -
machineMode = vh_ExpectIncludeExclude;
}
break;
}
// Have we hit the end of the pattern string?
if (m_auth_hosts[authHostsPos] == '\0')
break;
authHostsPos++;
}
}
// Based on the server's QuerySetting, adjust the verification result
switch (verifiedHost) {
case vncServer::aqrAccept:
if (QuerySetting() >= 3)
verifiedHost = vncServer::aqrQuery;
break;
case vncServer::aqrQuery:
if (QuerySetting() <= 1)
verifiedHost = vncServer::aqrAccept;
else if (QuerySetting() == 4)
verifiedHost = vncServer::aqrReject;
break;
case vncServer::aqrReject:
if (QuerySetting() == 0)
verifiedHost = vncServer::aqrQuery;
break;
};
return verifiedHost;
}
void
vncServer::AddAuthHostsBlacklist(const char *machine) {
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
// Get the current time as a 64-bit value
SYSTEMTIME systime;
FILETIME ftime;
LARGE_INTEGER now;
GetSystemTime(&systime);
SystemTimeToFileTime(&systime, &ftime);
now.LowPart=ftime.dwLowDateTime;now.HighPart=ftime.dwHighDateTime;
now.QuadPart /= 10000000; // Convert it into seconds
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
// If the host is already blocked then ignore
if (current->_blocked)
return;
// Set the RefTime & failureCount
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_failureCount++;
if (current->_failureCount > 5)
current->_blocked = TRUE;
return;
}
current = current->_next;
}
// Didn't find the entry
current = new vncServer::BlacklistEntry;
current->_blocked = FALSE;
current->_failureCount = 0;
current->_lastRefTime.QuadPart = now.QuadPart + 10;
current->_machineName = strdup(machine);
current->_next = m_blacklist;
m_blacklist = current;
}
void
vncServer::RemAuthHostsBlacklist(const char *machine) {
omni_mutex_lock l(m_clientsLock);
// -=- Is the specified host blacklisted?
vncServer::BlacklistEntry *current = m_blacklist;
vncServer::BlacklistEntry *previous = 0;
while (current) {
// Is this the entry we're interested in?
if (strcmp(current->_machineName, machine) == 0) {
if (previous)
previous->_next = current->_next;
else
m_blacklist = current->_next;
vncServer::BlacklistEntry *next = current->_next;
free (current->_machineName);
delete current;
current = next;
continue;
}
previous = current;
current = current->_next;
}
}
// Modif sf@2002
void vncServer::SetSingleWindowName(const char *szName)
{
memcpy(m_szWindowName, szName, 32);
}
// Modef rdv@202
void
vncServer::SetNewSWSize(long w,long h,BOOL desktop)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
if (!GetClient(*i)->SetNewSWSize(w,h,desktop)) {
vnclog.Print(LL_INTINFO, VNCLOG("Unable to set new desktop size\n"));
KillClient(*i);
}
}
}
void
vncServer::SetSWOffset(int x,int y)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->SetSWOffset(x,y);
}
}
void
vncServer::SetScreenOffset(int x,int y,int type)
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this screen size update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
// Post the update
GetClient(*i)->SetScreenOffset(x,y,type);
}
}
// Modif sf@2002 - v1.1.0 - Default Scaling
UINT vncServer::GetDefaultScale()
{
return m_nDefaultScale;
}
BOOL vncServer::SetDefaultScale(int nScale)
{
m_nDefaultScale = nScale;
return TRUE;
}
BOOL vncServer::FileTransferEnabled()
{
return m_fFileTransferEnabled;
}
BOOL vncServer::EnableFileTransfer(BOOL fEnable)
{
m_fFileTransferEnabled = fEnable;
return TRUE;
}
BOOL vncServer::MSLogonRequired()
{
return m_fMSLogonRequired;
}
BOOL vncServer::RequireMSLogon(BOOL fEnable)
{
m_fMSLogonRequired = fEnable;
return TRUE;
}
BOOL vncServer::GetNewMSLogon()
{
return m_fNewMSLogon;
}
BOOL vncServer::SetNewMSLogon(BOOL fEnable)
{
m_fNewMSLogon = fEnable;
return TRUE;
}
//
// sf@2002 - v1.1.x - DSM Plugin
//
BOOL vncServer::IsDSMPluginEnabled()
{
return m_fDSMPluginEnabled;
}
void vncServer::EnableDSMPlugin(BOOL fEnable)
{
m_fDSMPluginEnabled = fEnable;
}
char* vncServer::GetDSMPluginName()
{
return m_szDSMPlugin;
}
void vncServer::SetDSMPluginName(char* szDSMPlugin)
{
strcpy(m_szDSMPlugin, szDSMPlugin);
return;
}
//
// Load if necessary and initialize the current DSMPlugin
// This can only be done if NO client is connected (for the moment)
//
BOOL vncServer::SetDSMPlugin(void)
{
if (AuthClientCount() > 0) return FALSE;
if (!IsDSMPluginEnabled()) return FALSE;
// If the plugin is loaded, unload it first
// sf@2003 - it has been possibly pre-configured by
// clicking on the plugin config button
if (m_pDSMPlugin->IsLoaded())
{
// sf@2003 - We check if the loaded plugin is the same than
// the currently selected one or not
m_pDSMPlugin->DescribePlugin();
if (stricmp(m_pDSMPlugin->GetPluginFileName(), GetDSMPluginName()))
{
m_pDSMPlugin->SetEnabled(false);
m_pDSMPlugin->UnloadPlugin();
}
}
if (!m_pDSMPlugin->IsLoaded())
{
if (!m_pDSMPlugin->LoadPlugin(GetDSMPluginName(), false))
{
vnclog.Print(LL_INTINFO, VNCLOG("DSMPlugin cannot be loaded\n"));
return FALSE;
}
}
// Now that it is loaded, init it
if (m_pDSMPlugin->InitPlugin())
{
char szParams[MAXPWLEN + 64];
char password[MAXPWLEN];
GetPassword(password);
// Does the plugin need the VNC password to do its job ?
if (!stricmp(m_pDSMPlugin->GetPluginParams(), "VNCPasswordNeeded"))
strcpy(szParams, vncDecryptPasswd((char *)password));
else
strcpy(szParams, "NoPassword");
// The second parameter tells the plugin the kind of program is using it
// (in WinVNC : "server-app" or "server-svc"
strcat(szParams, ",");
strcat(szParams, vncService::RunningAsService() ? "server-svc" : "server-app");
if (m_pDSMPlugin->SetPluginParams(NULL, szParams/*vncDecryptPasswd((char *)password)*/))
{
m_pDSMPlugin->SetEnabled(true); // The plugin is ready to be used
vnclog.Print(LL_INTINFO, VNCLOG("DSMPlugin Params OK\n"));
return TRUE;
}
else
{
m_pDSMPlugin->SetEnabled(false);
vnclog.Print(LL_INTINFO, VNCLOG("Unable to set DSMPlugin Params\n"));
}
}
else
{
m_pDSMPlugin->SetEnabled(false);
vnclog.Print(LL_INTINFO, VNCLOG("Unable to init DSMPlugin\n"));
}
/*
MessageBox(NULL,
_T(_this->m_pDSMPlugin->DescribePlugin()),
_T("Plugin Description"), MB_OK | MB_ICONEXCLAMATION );
*/
return TRUE;
}
//
// sgf@2002 - for now, we disable cache rects when more than one client
//
void vncServer::DisableCacheForAllClients()
{
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
GetClient(*i)->EnableCache(FALSE);
}
}
void
vncServer::Clear_Update_Tracker() {
vncClientList::iterator i;
omni_mutex_lock l(m_clientsLock);
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
GetClient(*i)->Clear_Update_Tracker();
}
}
void vncServer::Driver(BOOL enable)
{
sethook=true;
m_driver = enable;
}
void vncServer::Hook(BOOL enable)
{
sethook=true;
m_hook=enable;
}
void vncServer::SetHookings()
{
if (sethook && m_desktop)
{
m_desktop->SethookMechanism(Hook(),Driver());
}
sethook=false;
}
void vncServer::EnableXRichCursor(BOOL fEnable)
{
m_fXRichCursor = fEnable;
}
BOOL
vncServer::SetDisableTrayIcon(BOOL disableTrayIcon)
{
if (disableTrayIcon != m_disableTrayIcon)
{
m_disableTrayIcon = disableTrayIcon;
}
return TRUE;
}
BOOL
vncServer::GetDisableTrayIcon()
{
return m_disableTrayIcon;
}
BOOL
vncServer::SetAllowEditClients(BOOL AllowEditClients)
{
if (AllowEditClients != m_AllowEditClients)
{
m_AllowEditClients = AllowEditClients;
}
return TRUE;
}
BOOL
vncServer::GetAllowEditClients()
{
return m_AllowEditClients;
}
BOOL
vncServer::All_clients_initialalized() {
vncClientList::iterator i;
// Post this update to all the connected clients
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
{
if (!GetClient(*i)->client_settings_passed) return false;
}
return true;
}
bool vncServer::IsClient(vncClient* pClient)
{
vncClientList::iterator i;
for (i = m_authClients.begin(); i != m_authClients.end(); i++)
if (GetClient(*i) == pClient) return true;
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -