vnc: Don't enable auth without an authfile
diff --git a/src/VNCFlinger.cpp b/src/VNCFlinger.cpp
index b9b5da4..b910453 100644
--- a/src/VNCFlinger.cpp
+++ b/src/VNCFlinger.cpp
@@ -18,6 +18,8 @@
#define LOG_TAG "VNCFlinger"
#include <utils/Log.h>
+#include <fstream>
+
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
@@ -86,6 +88,7 @@
status_t VNCFlinger::clearPassword() {
std::remove(VNC_AUTH_FILE);
ALOGW("Password authentication disabled");
+ mVNCScreen->authPasswdData = NULL;
return OK;
}
@@ -97,6 +100,7 @@
return BAD_VALUE;
}
ALOGI("Password has been set");
+ mVNCScreen->authPasswdData = (void *)VNC_AUTH_FILE;
return OK;
}
@@ -238,7 +242,6 @@
mVNCScreen->desktopName = "VNCFlinger";
mVNCScreen->alwaysShared = TRUE;
mVNCScreen->httpDir = NULL;
- mVNCScreen->authPasswdData = (void *)VNC_AUTH_FILE;
mVNCScreen->newClientHook = (rfbNewClientHookPtr)VNCFlinger::onNewClient;
mVNCScreen->kbdAddEvent = InputDevice::onKeyEvent;
mVNCScreen->ptrAddEvent = InputDevice::onPointerEvent;
@@ -251,6 +254,11 @@
mVNCScreen->deferUpdateTime = 0;
mVNCScreen->screenData = this;
+ std::ifstream authFile(VNC_AUTH_FILE);
+ if ((bool)authFile) {
+ mVNCScreen->authPasswdData = (void *)VNC_AUTH_FILE;
+ }
+
return err;
}
diff --git a/src/main.cpp b/src/main.cpp
index 322fcc0..29178ff 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -28,12 +28,13 @@
static sp<VNCFlinger> gVNC;
-static const char* const shortOpts = "4:6:p:s:l:vh";
+static const char* const shortOpts = "4:6:p:cs:l:vh";
static const option longOpts[] = {
{"listen", 1, nullptr, '4'},
{"listen6", 1, nullptr, '6'},
{"port", 1, nullptr, 'p'},
{"password", 1, nullptr, 's'},
+ {"clear-password", 0, nullptr, 'c'},
{"scale", 1, nullptr, 'l'},
{"version", 0, nullptr, 'v'},
{"help", 0, nullptr, 'h'},