Implement passcode-based fullscreen phone locker (locker.so / xlocker)
This commit is contained in:
1 parent
32d5d2f2b4
commit
0656042f7f
56 files changed
+1264
-120
No files matched your search
@@ -160,7 +160,18 @@ static int try_send_plugin_fifo(const char *plugin_name, int sub_argc, char **su
|
||||
|
||||
char cmd[256];
|
||||
int len = 0;
|
||||
if (strcmp(plugin_name, "xdrawer") == 0) {
|
||||
if (strcmp(plugin_name, "locker") == 0) {
|
||||
if (sub_argc >= 2 && sub_argv[1] &&
|
||||
(strcasecmp(sub_argv[1], "screenoff") == 0 ||
|
||||
strcasecmp(sub_argv[1], "blank") == 0)) {
|
||||
len = snprintf(cmd, sizeof(cmd), "LOCK_BLANK\n");
|
||||
} else if (sub_argc >= 2 && sub_argv[1] &&
|
||||
strcasecmp(sub_argv[1], "wake") == 0) {
|
||||
len = snprintf(cmd, sizeof(cmd), "WAKE\n");
|
||||
} else {
|
||||
len = snprintf(cmd, sizeof(cmd), "LOCK\n");
|
||||
}
|
||||
} else if (strcmp(plugin_name, "xdrawer") == 0) {
|
||||
len = snprintf(cmd, sizeof(cmd), "TOGGLE\n");
|
||||
} else if (strcmp(plugin_name, "dmenu") == 0 && sub_argc >= 2 && sub_argv[1] &&
|
||||
strcmp(sub_argv[1], "close") == 0) {
|
||||
@@ -240,6 +251,9 @@ static const char *resolve_plugin_name_from_argv0(const char *argv0) {
|
||||
if (strcasecmp(base, "dmenu") == 0 || strcasecmp(base, "xdmenu") == 0) {
|
||||
return "dmenu";
|
||||
}
|
||||
if (strcasecmp(base, "xlocker") == 0 || strcasecmp(base, "locker") == 0) {
|
||||
return "locker";
|
||||
}
|
||||
if (strcasecmp(base, "xdrawer") == 0) {
|
||||
return "xdrawer";
|
||||
}
|
||||
@@ -285,6 +299,27 @@ static const char *resolve_plugin_name_from_argv0(const char *argv0) {
|
||||
strcasecmp(base, "xplayer") == 0) {
|
||||
return "music";
|
||||
}
|
||||
if (strcasecmp(base, "xsip") == 0 || strcasecmp(base, "sip") == 0) {
|
||||
return "sip";
|
||||
}
|
||||
if (strcasecmp(base, "xemail") == 0 || strcasecmp(base, "xmail") == 0 ||
|
||||
strcasecmp(base, "email") == 0) {
|
||||
return "email";
|
||||
}
|
||||
if (strcasecmp(base, "xirc") == 0 || strcasecmp(base, "irc") == 0) {
|
||||
return "irc";
|
||||
}
|
||||
if (strcasecmp(base, "xtox") == 0 || strcasecmp(base, "tox") == 0) {
|
||||
return "tox";
|
||||
}
|
||||
if (strcasecmp(base, "xkopher") == 0 || strcasecmp(base, "xsmallweb") == 0 ||
|
||||
strcasecmp(base, "smallweb") == 0) {
|
||||
return "smallweb";
|
||||
}
|
||||
if (strcasecmp(base, "xgps") == 0 || strcasecmp(base, "xmaps") == 0 ||
|
||||
strcasecmp(base, "gps") == 0) {
|
||||
return "gps";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -377,6 +412,20 @@ int main(int argc, char **argv) {
|
||||
sub_argv = argv + 1;
|
||||
}
|
||||
|
||||
if (access("/tmp/bananarchy_screen_locked", F_OK) == 0 &&
|
||||
strcmp(plugin_name, "locker") != 0 &&
|
||||
strcmp(plugin_name, "callscreen") != 0) {
|
||||
const char *a1 = (sub_argc >= 2 && sub_argv[1]) ? sub_argv[1] : "";
|
||||
if (strcmp(a1, "--preload") != 0 &&
|
||||
strcmp(a1, "close") != 0 &&
|
||||
strcmp(a1, "-v") != 0 &&
|
||||
strcmp(a1, "isopen") != 0 &&
|
||||
strcmp(a1, "--apply") != 0 &&
|
||||
strcmp(a1, "--export-default") != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(plugin_name, "dmenu") == 0) {
|
||||
if (sub_argc >= 2 && sub_argv[1]) {
|
||||
if (strcmp(sub_argv[1], "-v") == 0) {
|
||||
|
||||
@@ -0,0 +1,865 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// Fullscreen Passcode Phone Locker DWM Plugin (240x320)
|
||||
// Verifies numeric passcode against the current user's shadow password hash
|
||||
// and blocks all keypad, softkey, and power-button bypasses while locked.
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/XF86keysym.h>
|
||||
#ifndef _EVDEVK
|
||||
#define _EVDEVK(_v) (0x10081000 + (_v))
|
||||
#endif
|
||||
#include <pango/pango.h>
|
||||
#include <pango/pangoxft.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <csignal>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <crypt.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "../sxmo-dwm/dwm_plugin.h"
|
||||
#include "phone_data.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace bananarchy;
|
||||
|
||||
constexpr const char* kLockFlagPath = "/tmp/bananarchy_screen_locked";
|
||||
|
||||
volatile sig_atomic_t gRunning = 1;
|
||||
|
||||
void handleSignal(int) {
|
||||
// Ignore termination signals while the phone is locked so the locker cannot be killed
|
||||
if (::access(kLockFlagPath, F_OK) == 0) {
|
||||
return;
|
||||
}
|
||||
gRunning = 0;
|
||||
}
|
||||
|
||||
std::string readSmallFileTrimmed(const char* path) {
|
||||
int fd = ::open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
return "";
|
||||
}
|
||||
char buf[256];
|
||||
ssize_t n = ::read(fd, buf, sizeof(buf) - 1);
|
||||
::close(fd);
|
||||
if (n <= 0) {
|
||||
return "";
|
||||
}
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r' || buf[n - 1] == ' ')) {
|
||||
--n;
|
||||
}
|
||||
buf[n] = '\0';
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
void writeSmallFileStr(const char* path, const char* val) {
|
||||
int fd = ::open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (fd >= 0) {
|
||||
(void)::write(fd, val, std::strlen(val));
|
||||
::close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void writeSysfsStr(const char* path, const char* val) {
|
||||
int fd = ::open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
(void)::write(fd, val, std::strlen(val));
|
||||
::close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
bool isScreenBlanked() {
|
||||
std::string br = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness");
|
||||
return (!br.empty() && std::atoi(br.c_str()) <= 0);
|
||||
}
|
||||
|
||||
void blankScreenBacklight() {
|
||||
std::string cur = readSmallFileTrimmed("/sys/class/backlight/backlight/brightness");
|
||||
if (!cur.empty() && std::atoi(cur.c_str()) >= 1) {
|
||||
std::string line = std::to_string(std::atoi(cur.c_str())) + "\n";
|
||||
writeSmallFileStr("/tmp/sxmo_saved_brightness", line.c_str());
|
||||
}
|
||||
writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness", "0");
|
||||
writeSysfsStr("/sys/class/backlight/backlight/brightness", "0");
|
||||
}
|
||||
|
||||
void wakeScreenBacklight() {
|
||||
std::string cur = readSmallFileTrimmed("/tmp/sxmo_saved_brightness");
|
||||
int val = std::atoi(cur.c_str());
|
||||
if (val < 1) {
|
||||
std::string cfgPath = getHomeDir() + "/.config/sxmo/brightness";
|
||||
cur = readSmallFileTrimmed(cfgPath.c_str());
|
||||
val = std::atoi(cur.c_str());
|
||||
}
|
||||
if (val < 1) {
|
||||
val = 14;
|
||||
}
|
||||
std::string valStr = std::to_string(val);
|
||||
writeSysfsStr("/sys/class/backlight/backlight/bl_power", "0");
|
||||
writeSysfsStr("/sys/class/backlight/backlight/brightness", valStr.c_str());
|
||||
|
||||
std::string kbd = readSmallFileTrimmed("/tmp/sxmo_saved_kbd_brightness");
|
||||
if (kbd.empty()) {
|
||||
std::string kbdCfg = getHomeDir() + "/.config/sxmo/kbd_brightness";
|
||||
kbd = readSmallFileTrimmed(kbdCfg.c_str());
|
||||
}
|
||||
writeSysfsStr("/sys/class/leds/white:kbd_backlight/brightness",
|
||||
kbd.empty() ? "255" : kbd.c_str());
|
||||
}
|
||||
|
||||
void setSxmoStateFile(const char* st) {
|
||||
std::string path = getRuntimeFile("sxmo.state");
|
||||
std::string content = std::string(st) + "\n";
|
||||
writeSmallFileStr(path.c_str(), content.c_str());
|
||||
}
|
||||
|
||||
bool constantTimeEq(const std::string& a, const std::string& b) {
|
||||
if (a.empty() || a.size() != b.size()) {
|
||||
return false;
|
||||
}
|
||||
unsigned char diff = 0;
|
||||
for (size_t i = 0; i < a.size(); ++i) {
|
||||
diff |= static_cast<unsigned char>(a[i] ^ b[i]);
|
||||
}
|
||||
return diff == 0;
|
||||
}
|
||||
|
||||
class PasscodeVerifier {
|
||||
public:
|
||||
void refreshIfNeeded() {
|
||||
struct stat st {};
|
||||
if (::stat("/etc/shadow", &st) == 0) {
|
||||
if (!cachedHash_.empty() && st.st_mtim.tv_sec == shadowMtime_ &&
|
||||
st.st_size == shadowSize_) {
|
||||
return;
|
||||
}
|
||||
shadowMtime_ = st.st_mtim.tv_sec;
|
||||
shadowSize_ = st.st_size;
|
||||
}
|
||||
int pipefd[2];
|
||||
if (::pipe(pipefd) != 0) {
|
||||
return;
|
||||
}
|
||||
pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
::close(pipefd[0]);
|
||||
::dup2(pipefd[1], STDOUT_FILENO);
|
||||
int nullfd = ::open("/dev/null", O_RDWR);
|
||||
if (nullfd >= 0) {
|
||||
::dup2(nullfd, STDIN_FILENO);
|
||||
::dup2(nullfd, STDERR_FILENO);
|
||||
if (nullfd > 2) {
|
||||
::close(nullfd);
|
||||
}
|
||||
}
|
||||
if (pipefd[1] > 2) {
|
||||
::close(pipefd[1]);
|
||||
}
|
||||
::execl("/usr/bin/doas", "doas", "-n",
|
||||
"/usr/bin/bananarchy-verify-passcode", "--print-hash", "user",
|
||||
static_cast<char*>(nullptr));
|
||||
::_exit(1);
|
||||
}
|
||||
::close(pipefd[1]);
|
||||
char buf[256];
|
||||
ssize_t n = ::read(pipefd[0], buf, sizeof(buf) - 1);
|
||||
::close(pipefd[0]);
|
||||
int status = 0;
|
||||
if (pid > 0) {
|
||||
::waitpid(pid, &status, 0);
|
||||
}
|
||||
if (n > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
||||
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) {
|
||||
--n;
|
||||
}
|
||||
buf[n] = '\0';
|
||||
if (buf[0] == '$') {
|
||||
cachedHash_ = buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool verify(const std::string& candidate) {
|
||||
if (candidate.empty()) {
|
||||
return false;
|
||||
}
|
||||
refreshIfNeeded();
|
||||
if (!cachedHash_.empty()) {
|
||||
char* res = ::crypt(candidate.c_str(), cachedHash_.c_str());
|
||||
if (res && constantTimeEq(res, cachedHash_)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Fallback to helper binary via stdin
|
||||
int pipefd[2];
|
||||
if (::pipe(pipefd) != 0) {
|
||||
return false;
|
||||
}
|
||||
pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
::close(pipefd[1]);
|
||||
::dup2(pipefd[0], STDIN_FILENO);
|
||||
int nullfd = ::open("/dev/null", O_WRONLY);
|
||||
if (nullfd >= 0) {
|
||||
::dup2(nullfd, STDOUT_FILENO);
|
||||
::dup2(nullfd, STDERR_FILENO);
|
||||
if (nullfd > 2) {
|
||||
::close(nullfd);
|
||||
}
|
||||
}
|
||||
if (pipefd[0] > 2) {
|
||||
::close(pipefd[0]);
|
||||
}
|
||||
::execl("/usr/bin/doas", "doas", "-n",
|
||||
"/usr/bin/bananarchy-verify-passcode", "user",
|
||||
static_cast<char*>(nullptr));
|
||||
::_exit(1);
|
||||
}
|
||||
::close(pipefd[0]);
|
||||
std::string line = candidate + "\n";
|
||||
(void)::write(pipefd[1], line.data(), line.size());
|
||||
::close(pipefd[1]);
|
||||
int status = 0;
|
||||
if (pid > 0 && ::waitpid(pid, &status, 0) > 0) {
|
||||
return WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string cachedHash_;
|
||||
time_t shadowMtime_ = 0;
|
||||
off_t shadowSize_ = 0;
|
||||
};
|
||||
|
||||
int countNotifFiles() {
|
||||
std::string notifDir = getRuntimeFile("sxmo_notifications");
|
||||
DIR* d = ::opendir(notifDir.c_str());
|
||||
if (!d) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
struct dirent* ent;
|
||||
while ((ent = ::readdir(d)) != nullptr) {
|
||||
if (ent->d_name[0] != '.' && ent->d_name[0] != '\0') {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
::closedir(d);
|
||||
return count;
|
||||
}
|
||||
|
||||
int locker_run_main(int argc, char** argv) {
|
||||
gRunning = 1;
|
||||
bool isPreload = false;
|
||||
std::string initCmd = "LOCK";
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!argv[i]) {
|
||||
continue;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--preload") == 0) {
|
||||
isPreload = true;
|
||||
} else if (strcasecmp(argv[i], "lock") == 0 ||
|
||||
strcasecmp(argv[i], "open") == 0) {
|
||||
initCmd = "LOCK";
|
||||
} else if (strcasecmp(argv[i], "screenoff") == 0 ||
|
||||
strcasecmp(argv[i], "blank") == 0) {
|
||||
initCmd = "LOCK_BLANK";
|
||||
} else if (strcasecmp(argv[i], "wake") == 0) {
|
||||
initCmd = "WAKE";
|
||||
} else if (strcasecmp(argv[i], "status") == 0 ||
|
||||
strcasecmp(argv[i], "islocked") == 0) {
|
||||
return (::access(kLockFlagPath, F_OK) == 0) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendPluginCommand("locker", isPreload ? "NOP" : initCmd)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string daemonPidPath = getPluginDaemonPidPath("locker");
|
||||
std::string activePidPath = getRuntimeFile("xlocker.pid");
|
||||
writeIntFile(daemonPidPath, static_cast<int>(::getpid()));
|
||||
int fifoFd = setupPluginDaemonFifo("locker");
|
||||
|
||||
struct sigaction sa {};
|
||||
sa.sa_handler = handleSignal;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGTERM, &sa, nullptr);
|
||||
sigaction(SIGINT, &sa, nullptr);
|
||||
sigaction(SIGHUP, &sa, nullptr);
|
||||
|
||||
NeoWindow neo;
|
||||
if (!neo.create("xlocker", "XLocker", "Phone Lock",
|
||||
0, 0, kScreenWidth, kScreenHeight, true,
|
||||
ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask)) {
|
||||
if (fifoFd >= 0) {
|
||||
::close(fifoFd);
|
||||
}
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Display* dpy = neo.dpy;
|
||||
Window win = neo.win;
|
||||
Pixmap pix = neo.pix;
|
||||
GC gc = neo.gc;
|
||||
PangoLayout* layoutNum = neo.layoutNum;
|
||||
PangoLayout* layoutMain = neo.layoutMain;
|
||||
PangoLayout* layoutSmall = neo.layoutSmall;
|
||||
PangoLayout* layoutIcon = neo.layoutIcon;
|
||||
PluginTheme& theme = neo.theme;
|
||||
|
||||
// Create an extra-large clock layout
|
||||
PangoLayout* layoutClock = pango_layout_new(neo.pangoCtx);
|
||||
auto updateClockFont = [&]() {
|
||||
int clockPx = std::max(28, theme.spec.baseFontSize * 2 + 6);
|
||||
std::string fontDescStr =
|
||||
theme.spec.fontFace + " Bold " + std::to_string(clockPx) + "px";
|
||||
PangoFontDescription* fd =
|
||||
pango_font_description_from_string(fontDescStr.c_str());
|
||||
pango_layout_set_font_description(layoutClock, fd);
|
||||
pango_font_description_free(fd);
|
||||
};
|
||||
updateClockFont();
|
||||
|
||||
PasscodeVerifier verifier;
|
||||
verifier.refreshIfNeeded();
|
||||
|
||||
bool visible = false;
|
||||
bool grabHeld = false;
|
||||
std::string passcode;
|
||||
std::string statusMsg;
|
||||
bool statusIsError = false;
|
||||
int failedAttempts = 0;
|
||||
int64_t cooldownUntilMs = 0;
|
||||
int64_t statusClearAtMs = 0;
|
||||
int64_t lockActivatedMs = 0;
|
||||
|
||||
auto grabLockerInput = [&]() {
|
||||
if (!visible || isCallActiveOrRingingFast()) {
|
||||
return;
|
||||
}
|
||||
XRaiseWindow(dpy, win);
|
||||
XSetInputFocus(dpy, win, RevertToParent, CurrentTime);
|
||||
for (int attempt = 0; attempt < 5; ++attempt) {
|
||||
if (XGrabKeyboard(dpy, win, True, GrabModeAsync, GrabModeAsync,
|
||||
CurrentTime) == GrabSuccess) {
|
||||
grabHeld = true;
|
||||
break;
|
||||
}
|
||||
::usleep(10000);
|
||||
}
|
||||
XGrabPointer(dpy, win, True, ButtonPressMask | ButtonReleaseMask,
|
||||
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
||||
XFlush(dpy);
|
||||
};
|
||||
|
||||
auto releaseLockerGrab = [&]() {
|
||||
if (grabHeld) {
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
XUngrabPointer(dpy, CurrentTime);
|
||||
grabHeld = false;
|
||||
XFlush(dpy);
|
||||
}
|
||||
};
|
||||
|
||||
auto closeOtherOverlays = [&]() {
|
||||
sendPluginCommand("dmenu", "CLOSE");
|
||||
sendPluginCommand("xdrawer", "CLOSE");
|
||||
::unlink("/tmp/dwm_plugin_dmenu.active");
|
||||
};
|
||||
|
||||
auto render = [&]() {
|
||||
if (!visible || isScreenBlanked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t now = nowMs();
|
||||
if (statusClearAtMs > 0 && now >= statusClearAtMs && cooldownUntilMs <= now) {
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
statusClearAtMs = 0;
|
||||
}
|
||||
|
||||
// Background fill
|
||||
XSetForeground(dpy, gc, theme.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, kScreenHeight);
|
||||
|
||||
// Top bar strip (24px)
|
||||
XSetForeground(dpy, gc, theme.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kScreenWidth, 24);
|
||||
XSetForeground(dpy, gc, theme.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, 23, kScreenWidth, 23);
|
||||
|
||||
neo.drawPango(layoutIcon, &theme.colYellow, 8, 0, 24, kIconLock);
|
||||
neo.drawPango(layoutSmall, &theme.colLight, 26, 0, 24, "Locked");
|
||||
|
||||
std::string cap = readSmallFileTrimmed("/sys/class/power_supply/battery/capacity");
|
||||
std::string batStatus = readSmallFileTrimmed("/sys/class/power_supply/battery/status");
|
||||
std::string batText = cap.empty() ? "" : (cap + "%");
|
||||
if (batStatus == "Charging") {
|
||||
batText = std::string(kIconFlash) + " " + batText;
|
||||
}
|
||||
if (!batText.empty()) {
|
||||
int bw = neo.pangoWidth(layoutSmall, batText);
|
||||
XftColor* batCol = (std::atoi(cap.c_str()) <= 15 && batStatus != "Charging")
|
||||
? &theme.colRed
|
||||
: &theme.colMuted;
|
||||
neo.drawPango(layoutSmall, batCol, kScreenWidth - bw - 8, 0, 24, batText);
|
||||
}
|
||||
|
||||
// Current time and date
|
||||
std::time_t t = std::time(nullptr);
|
||||
struct tm tmNow {};
|
||||
localtime_r(&t, &tmNow);
|
||||
char timeBuf[32];
|
||||
char dateBuf[64];
|
||||
std::strftime(timeBuf, sizeof(timeBuf), "%H:%M", &tmNow);
|
||||
std::strftime(dateBuf, sizeof(dateBuf), "%a, %b %d", &tmNow);
|
||||
|
||||
neo.drawPango(layoutClock, &theme.colWhite, 0, 34, 42, timeBuf,
|
||||
kScreenWidth, 1);
|
||||
neo.drawPango(layoutMain, &theme.colMuted, 0, 78, 22, dateBuf,
|
||||
kScreenWidth, 1);
|
||||
|
||||
// Notification badge (count only, no private content exposed on lockscreen)
|
||||
int notifCount = countNotifFiles();
|
||||
if (notifCount > 0) {
|
||||
std::string nstr = std::string(kIconBell) + " " +
|
||||
std::to_string(notifCount) +
|
||||
(notifCount == 1 ? " notification" : " notifications");
|
||||
int pillW = std::min(200, neo.pangoWidth(layoutSmall, nstr) + 20);
|
||||
int pillX = (kScreenWidth - pillW) / 2;
|
||||
XSetForeground(dpy, gc, theme.spec.bgAltOdd);
|
||||
XFillRectangle(dpy, pix, gc, pillX, 105, pillW, 22);
|
||||
XSetForeground(dpy, gc, theme.spec.border);
|
||||
XDrawRectangle(dpy, pix, gc, pillX, 105, pillW - 1, 21);
|
||||
neo.drawPango(layoutSmall, &theme.colYellow, pillX, 105, 22, nstr,
|
||||
pillW, 1);
|
||||
}
|
||||
|
||||
// Passcode entry card
|
||||
int cardX = 18;
|
||||
int cardY = 136;
|
||||
int cardW = kScreenWidth - 36;
|
||||
int cardH = 54;
|
||||
bool inCooldown = (cooldownUntilMs > now);
|
||||
|
||||
uint32_t boxBg = theme.spec.bgInput;
|
||||
uint32_t boxBorder = statusIsError ? theme.spec.danger
|
||||
: (passcode.empty() ? theme.spec.border
|
||||
: theme.spec.selBg);
|
||||
XSetForeground(dpy, gc, boxBg);
|
||||
XFillRectangle(dpy, pix, gc, cardX, cardY, cardW, cardH);
|
||||
XSetForeground(dpy, gc, boxBorder);
|
||||
XDrawRectangle(dpy, pix, gc, cardX, cardY, cardW - 1, cardH - 1);
|
||||
if (!passcode.empty() || statusIsError) {
|
||||
XDrawRectangle(dpy, pix, gc, cardX + 1, cardY + 1, cardW - 3, cardH - 3);
|
||||
}
|
||||
|
||||
std::string labelStr = std::string(kIconKey) + " Enter Passcode";
|
||||
neo.drawPango(layoutSmall, &theme.colMuted, cardX, cardY + 4, 18,
|
||||
labelStr, cardW, 1);
|
||||
|
||||
if (inCooldown) {
|
||||
int remSec = static_cast<int>((cooldownUntilMs - now + 999) / 1000);
|
||||
std::string waitStr = "Locked out (" + std::to_string(remSec) + "s)";
|
||||
neo.drawPango(layoutMain, &theme.colRed, cardX + 6, cardY + 24, 24,
|
||||
waitStr, cardW - 12, 1);
|
||||
} else if (!passcode.empty()) {
|
||||
std::string masked;
|
||||
for (size_t i = 0; i < passcode.size(); ++i) {
|
||||
if (i > 0) {
|
||||
masked += ' ';
|
||||
}
|
||||
masked += '*';
|
||||
}
|
||||
neo.drawPango(layoutNum, &theme.colYellow, cardX + 6, cardY + 22, 26,
|
||||
masked, cardW - 12, 1);
|
||||
} else if (!statusMsg.empty()) {
|
||||
XftColor* stCol = statusIsError ? &theme.colRed : &theme.colLight;
|
||||
neo.drawPango(layoutMain, stCol, cardX + 6, cardY + 24, 24,
|
||||
statusMsg, cardW - 12, 1);
|
||||
} else {
|
||||
neo.drawPango(layoutSmall, &theme.colMuted, cardX + 6, cardY + 25, 22,
|
||||
"Type 0-9 on keypad", cardW - 12, 1);
|
||||
}
|
||||
|
||||
// Visual keypad grid hint / status panel
|
||||
int infoX = 18;
|
||||
int infoY = 202;
|
||||
int infoW = kScreenWidth - 36;
|
||||
int infoH = 74;
|
||||
XSetForeground(dpy, gc, theme.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, infoX, infoY, infoW, infoH);
|
||||
XSetForeground(dpy, gc, theme.spec.border);
|
||||
XDrawRectangle(dpy, pix, gc, infoX, infoY, infoW - 1, infoH - 1);
|
||||
|
||||
neo.drawPango(layoutSmall, &theme.colLight, infoX + 8, infoY + 8, 18,
|
||||
std::string(kIconShield) + " Device Protected",
|
||||
infoW - 16, 1);
|
||||
neo.drawPango(layoutSmall, &theme.colMuted, infoX + 8, infoY + 30, 18,
|
||||
"Enter user numeric password", infoW - 16, 1);
|
||||
neo.drawPango(layoutSmall, &theme.colMuted, infoX + 8, infoY + 48, 18,
|
||||
"End/Power: turn screen off", infoW - 16, 1);
|
||||
|
||||
// Bottom softkey bar (Y=294..320)
|
||||
neo.drawSoftbar("Unlock", "OK",
|
||||
passcode.empty() ? "Sleep" : "Clear",
|
||||
&theme.colYellow);
|
||||
|
||||
neo.present();
|
||||
};
|
||||
|
||||
auto unlockPhone = [&]() {
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
failedAttempts = 0;
|
||||
cooldownUntilMs = 0;
|
||||
::unlink(kLockFlagPath);
|
||||
::unlink(activePidPath.c_str());
|
||||
releaseLockerGrab();
|
||||
if (visible) {
|
||||
XUnmapWindow(dpy, win);
|
||||
XFlush(dpy);
|
||||
visible = false;
|
||||
}
|
||||
writeSoftkeySuppress(nowMs() + 350);
|
||||
setSxmoStateFile("unlock");
|
||||
wakeScreenBacklight();
|
||||
runAsyncCmd("sxmo_hook_unlock.sh >/dev/null 2>&1");
|
||||
};
|
||||
|
||||
auto lockPhone = [&](bool blankDisplay) {
|
||||
writeSmallFileStr(kLockFlagPath, "1\n");
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherOverlays();
|
||||
verifier.refreshIfNeeded();
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
lockActivatedMs = nowMs();
|
||||
writeSoftkeySuppress(lockActivatedMs + 400);
|
||||
if (!visible) {
|
||||
XMapRaised(dpy, win);
|
||||
XMoveResizeWindow(dpy, win, 0, 0, kScreenWidth, kScreenHeight);
|
||||
visible = true;
|
||||
}
|
||||
grabLockerInput();
|
||||
if (blankDisplay) {
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
} else {
|
||||
setSxmoStateFile("lock");
|
||||
wakeScreenBacklight();
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
auto submitPasscode = [&](bool explicitSubmit) {
|
||||
int64_t now = nowMs();
|
||||
if (cooldownUntilMs > now) {
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (passcode.empty()) {
|
||||
if (explicitSubmit) {
|
||||
statusMsg = "Enter passcode";
|
||||
statusIsError = false;
|
||||
statusClearAtMs = now + 1500;
|
||||
render();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (verifier.verify(passcode)) {
|
||||
unlockPhone();
|
||||
return;
|
||||
}
|
||||
if (explicitSubmit || passcode.size() >= 12) {
|
||||
passcode.clear();
|
||||
++failedAttempts;
|
||||
statusIsError = true;
|
||||
runAsyncCmd("sxmo_vibrate 80 >/dev/null 2>&1");
|
||||
if (failedAttempts >= 5) {
|
||||
cooldownUntilMs = now + 10000;
|
||||
statusMsg = "Locked out (10s)";
|
||||
statusClearAtMs = cooldownUntilMs;
|
||||
} else {
|
||||
statusMsg = "Wrong passcode";
|
||||
statusClearAtMs = now + 1800;
|
||||
}
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
if (!isPreload) {
|
||||
lockPhone(initCmd == "LOCK_BLANK");
|
||||
} else if (::access(kLockFlagPath, F_OK) == 0) {
|
||||
lockPhone(isScreenBlanked());
|
||||
}
|
||||
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
bool callWasActive = false;
|
||||
|
||||
while (gRunning) {
|
||||
if (fifoFd >= 0) {
|
||||
for (const std::string& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "NOP") {
|
||||
continue;
|
||||
}
|
||||
if (cmd == "RELOAD_THEME") {
|
||||
neo.reloadTheme();
|
||||
updateClockFont();
|
||||
if (visible) {
|
||||
render();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (cmd == "LOCK" || cmd == "OPEN" || cmd.rfind("OPEN ", 0) == 0) {
|
||||
if (cmd == "OPEN screenoff" || cmd == "OPEN blank") {
|
||||
lockPhone(true);
|
||||
} else {
|
||||
lockPhone(false);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (cmd == "LOCK_BLANK" || cmd == "SCREENOFF" || cmd == "BLANK") {
|
||||
lockPhone(true);
|
||||
continue;
|
||||
}
|
||||
if (cmd == "WAKE") {
|
||||
if (::access(kLockFlagPath, F_OK) == 0 || visible) {
|
||||
if (!visible) {
|
||||
lockPhone(false);
|
||||
} else {
|
||||
closeOtherOverlays();
|
||||
wakeScreenBacklight();
|
||||
grabLockerInput();
|
||||
render();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (cmd.rfind("VERIFY ", 0) == 0) {
|
||||
std::string code = trimStr(cmd.substr(7));
|
||||
if (cooldownUntilMs <= nowMs() && verifier.verify(code)) {
|
||||
unlockPhone();
|
||||
} else {
|
||||
passcode.clear();
|
||||
++failedAttempts;
|
||||
statusIsError = true;
|
||||
if (failedAttempts >= 5) {
|
||||
cooldownUntilMs = nowMs() + 10000;
|
||||
statusMsg = "Locked out (10s)";
|
||||
statusClearAtMs = cooldownUntilMs;
|
||||
} else {
|
||||
statusMsg = "Wrong passcode";
|
||||
statusClearAtMs = nowMs() + 1800;
|
||||
}
|
||||
if (visible) {
|
||||
render();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Ignore CLOSE while locked so external scripts cannot dismiss the lockscreen
|
||||
}
|
||||
}
|
||||
|
||||
if (visible) {
|
||||
if (neo.checkReloadTheme()) {
|
||||
updateClockFont();
|
||||
render();
|
||||
}
|
||||
bool callNow = isCallActiveOrRingingFast();
|
||||
if (callNow && !callWasActive) {
|
||||
releaseLockerGrab();
|
||||
} else if (!callNow && callWasActive) {
|
||||
grabLockerInput();
|
||||
render();
|
||||
} else if (!callNow && !grabHeld) {
|
||||
grabLockerInput();
|
||||
}
|
||||
callWasActive = callNow;
|
||||
}
|
||||
|
||||
while (XPending(dpy) > 0) {
|
||||
XEvent ev;
|
||||
XNextEvent(dpy, &ev);
|
||||
if (ev.type == Expose) {
|
||||
if (visible && ev.xexpose.count == 0) {
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == VisibilityNotify || ev.type == FocusOut ||
|
||||
ev.type == UnmapNotify) {
|
||||
if (visible && ::access(kLockFlagPath, F_OK) == 0 &&
|
||||
!isCallActiveOrRingingFast()) {
|
||||
if (ev.type == UnmapNotify) {
|
||||
XMapRaised(dpy, win);
|
||||
}
|
||||
grabLockerInput();
|
||||
render();
|
||||
}
|
||||
} else if (ev.type == KeyPress) {
|
||||
if (!visible) {
|
||||
continue;
|
||||
}
|
||||
int64_t now = nowMs();
|
||||
if (isScreenBlanked()) {
|
||||
wakeScreenBacklight();
|
||||
lockActivatedMs = now;
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (now - lockActivatedMs < 180) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int kc = ev.xkey.keycode;
|
||||
KeySym sym = XLookupKeysym(&ev.xkey, 0);
|
||||
|
||||
// Power / End Call / Sleep button blanks the screen while remaining locked
|
||||
if (kc == 124 || sym == XF86XK_PowerOff || sym == XF86XK_Sleep ||
|
||||
sym == XF86XK_Standby || sym == XF86XK_Suspend ||
|
||||
sym == XF86XK_HangupPhone || sym == XK_Cancel ||
|
||||
sym == _EVDEVK(0x74) || sym == _EVDEVK(0x8e) ||
|
||||
sym == XK_Escape) {
|
||||
passcode.clear();
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Left softkey: explicit Unlock attempt
|
||||
if (isLeftSoftkey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Right softkey: Clear last digit, or blank screen if empty
|
||||
if (isRightSoftkey(sym, kc)) {
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
} else {
|
||||
setSxmoStateFile("screenoff");
|
||||
blankScreenBacklight();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Backspace / Left arrow: delete last digit
|
||||
if (sym == XK_BackSpace || sym == XK_Delete ||
|
||||
sym == XK_Left || sym == XK_KP_Left) {
|
||||
if (!passcode.empty()) {
|
||||
passcode.pop_back();
|
||||
render();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Enter / Center OK / Call / Pound (#): explicit Unlock attempt
|
||||
if (sym == XK_Return || sym == XK_KP_Enter ||
|
||||
sym == XF86XK_Phone || sym == XF86XK_PickupPhone ||
|
||||
sym == XF86XK_Send || isPoundKey(sym, kc)) {
|
||||
submitPasscode(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Numeric digits 0-9
|
||||
char ch = mapDialKey(sym, kc, ev.xkey.state);
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
if (cooldownUntilMs > now) {
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
if (passcode.size() < 32) {
|
||||
passcode.push_back(ch);
|
||||
statusMsg.clear();
|
||||
statusIsError = false;
|
||||
render();
|
||||
if (passcode.size() >= 4) {
|
||||
submitPasscode(false);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (visible && !isScreenBlanked()) {
|
||||
render();
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
if (visible) {
|
||||
if (isScreenBlanked()) {
|
||||
timeoutMs = 2000;
|
||||
} else if (cooldownUntilMs > nowMs()) {
|
||||
timeoutMs = 250;
|
||||
} else {
|
||||
timeoutMs = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2] {};
|
||||
pfds[0].fd = xfd;
|
||||
pfds[0].events = POLLIN;
|
||||
pfds[1].fd = fifoFd;
|
||||
pfds[1].events = POLLIN;
|
||||
::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
|
||||
}
|
||||
|
||||
g_object_unref(layoutClock);
|
||||
releaseLockerGrab();
|
||||
if (fifoFd >= 0) {
|
||||
::close(fifoFd);
|
||||
}
|
||||
::unlink(getPluginFifoPath("locker").c_str());
|
||||
::unlink(daemonPidPath.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int locker_plugin_init(const DwmHostApi* host) {
|
||||
if (host && host->spawn_plugin) {
|
||||
host->spawn_plugin("locker", "--preload");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const DwmPlugin dwm_plugin_entry = {
|
||||
DWM_PLUGIN_API_VERSION,
|
||||
"locker",
|
||||
"Fullscreen numeric passcode phone locker verified against shadow password",
|
||||
locker_plugin_init,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
locker_run_main
|
||||
};
|
||||
@@ -480,6 +480,32 @@ inline char mapDialKey(KeySym sym, unsigned int keycode, unsigned int state) {
|
||||
return '\0';
|
||||
}
|
||||
|
||||
inline bool isLeftSoftkey(KeySym sym, unsigned int keycode) {
|
||||
return sym == XK_Menu || sym == XF86XK_KbdLcdMenu1 || keycode == 135;
|
||||
}
|
||||
|
||||
inline bool isRightSoftkey(KeySym sym, unsigned int keycode) {
|
||||
return sym == XF86XK_Back || sym == XF86XK_KbdLcdMenu2 || keycode == 166;
|
||||
}
|
||||
|
||||
inline bool isStarKey(KeySym sym, unsigned int keycode) {
|
||||
return keycode == 63 || keycode == 530 || sym == XK_asterisk ||
|
||||
sym == XK_KP_Multiply || static_cast<uint32_t>(sym) == 0x1008ffaa;
|
||||
}
|
||||
|
||||
inline bool isPoundKey(KeySym sym, unsigned int keycode) {
|
||||
return keycode == 106 || keycode == 531 || sym == XK_numbersign ||
|
||||
sym == XK_KP_Divide || static_cast<uint32_t>(sym) == 0x1008ffab;
|
||||
}
|
||||
|
||||
inline std::string getHomeDir() {
|
||||
return getHomeDirPath();
|
||||
}
|
||||
|
||||
inline bool isPhonePasscodeLocked() {
|
||||
return ::access("/tmp/bananarchy_screen_locked", F_OK) == 0;
|
||||
}
|
||||
|
||||
inline std::string trimStr(const std::string& s) {
|
||||
size_t b = 0;
|
||||
while (b < s.size() && std::isspace(static_cast<unsigned char>(s[b]))) {
|
||||
@@ -1794,6 +1820,12 @@ inline void closeOtherPlugins(const char* selfPluginName) {
|
||||
{"xringtones.pid", "ringtones"},
|
||||
{"xwallpapers.pid", "wallpapers"},
|
||||
{"xmusic.pid", "music"},
|
||||
{"xsip.pid", "sip"},
|
||||
{"xemail.pid", "email"},
|
||||
{"xirc.pid", "irc"},
|
||||
{"xtox.pid", "tox"},
|
||||
{"xsmallweb.pid", "smallweb"},
|
||||
{"xgps.pid", "gps"},
|
||||
};
|
||||
for (const auto& p : kAllPlugins) {
|
||||
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
|
||||
@@ -1815,6 +1847,7 @@ inline bool isAnotherPluginActive(const char* selfPluginName) {
|
||||
const char* name;
|
||||
};
|
||||
static const PluginRef kAllPlugins[] = {
|
||||
{"xlocker.pid", "locker"},
|
||||
{"xdrawer.pid", "xdrawer"},
|
||||
{"xdialer.pid", "dialer"},
|
||||
{"xcalllog.pid", "calllog"},
|
||||
@@ -1829,6 +1862,12 @@ inline bool isAnotherPluginActive(const char* selfPluginName) {
|
||||
{"xringtones.pid", "ringtones"},
|
||||
{"xwallpapers.pid", "wallpapers"},
|
||||
{"xmusic.pid", "music"},
|
||||
{"xsip.pid", "sip"},
|
||||
{"xemail.pid", "email"},
|
||||
{"xirc.pid", "irc"},
|
||||
{"xtox.pid", "tox"},
|
||||
{"xsmallweb.pid", "smallweb"},
|
||||
{"xgps.pid", "gps"},
|
||||
};
|
||||
for (const auto& p : kAllPlugins) {
|
||||
if (selfPluginName && std::strcmp(p.name, selfPluginName) == 0) {
|
||||
@@ -1859,6 +1898,7 @@ inline void grabPluginKeyboard(Display* dpy, Window win) {
|
||||
inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
|
||||
static const char* kPlugins[] = {
|
||||
"dmenu",
|
||||
"locker",
|
||||
"xdrawer",
|
||||
"dialer",
|
||||
"calllog",
|
||||
@@ -1873,6 +1913,12 @@ inline void broadcastThemeReload(const char* selfPluginName = nullptr) {
|
||||
"ringtones",
|
||||
"wallpapers",
|
||||
"music",
|
||||
"sip",
|
||||
"email",
|
||||
"irc",
|
||||
"tox",
|
||||
"smallweb",
|
||||
"gps",
|
||||
};
|
||||
for (const char* name : kPlugins) {
|
||||
if (selfPluginName && std::strcmp(name, selfPluginName) == 0) {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
// Bananarchy shadow passcode verifier for the fullscreen phone locker.
|
||||
|
||||
#ifndef _DEFAULT_SOURCE
|
||||
#define _DEFAULT_SOURCE
|
||||
#endif
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
#include <crypt.h>
|
||||
#include <pwd.h>
|
||||
#include <shadow.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int constant_time_eq(const char *a, const char *b) {
|
||||
if (!a || !b) {
|
||||
return 0;
|
||||
}
|
||||
size_t la = strlen(a);
|
||||
size_t lb = strlen(b);
|
||||
if (la == 0 || la != lb) {
|
||||
return 0;
|
||||
}
|
||||
unsigned char diff = 0;
|
||||
for (size_t i = 0; i < la; ++i) {
|
||||
diff |= (unsigned char)(a[i] ^ b[i]);
|
||||
}
|
||||
return diff == 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int print_hash = 0;
|
||||
const char *username = "user";
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "--print-hash") == 0) {
|
||||
print_hash = 1;
|
||||
} else if (argv[i][0] != '-') {
|
||||
username = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(username, "user") != 0 && strcmp(username, "root") != 0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
struct spwd *sp = getspnam(username);
|
||||
const char *hash = (sp && sp->sp_pwdp) ? sp->sp_pwdp : NULL;
|
||||
if (!hash || !hash[0]) {
|
||||
struct passwd *pw = getpwnam(username);
|
||||
hash = (pw && pw->pw_passwd) ? pw->pw_passwd : NULL;
|
||||
}
|
||||
if (!hash || !hash[0] || hash[0] == '!' || hash[0] == '*') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (print_hash) {
|
||||
puts(hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char pass[128];
|
||||
if (!fgets(pass, sizeof(pass), stdin)) {
|
||||
return 1;
|
||||
}
|
||||
size_t len = strlen(pass);
|
||||
while (len > 0 && (pass[len - 1] == '\n' || pass[len - 1] == '\r')) {
|
||||
pass[--len] = '\0';
|
||||
}
|
||||
if (len == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *calc = crypt(pass, hash);
|
||||
memset(pass, 0, sizeof(pass));
|
||||
if (!calc) {
|
||||
return 1;
|
||||
}
|
||||
return constant_time_eq(calc, hash) ? 0 : 1;
|
||||
}
|
||||
+2
-2
@@ -1772,9 +1772,9 @@ int neoui_apply_theme_file(const char* xth_path) {
|
||||
|
||||
int neoui_broadcast_theme_reload(const char* skip_plugin) {
|
||||
const char* kPlugins[] = {
|
||||
"dmenu", "xdrawer", "dialer", "calllog", "callscreen", "contacts",
|
||||
"dmenu", "locker", "xdrawer", "dialer", "calllog", "callscreen", "contacts",
|
||||
"sms", "files", "camera", "themes", "modem", "networks", "ringtones",
|
||||
"wallpapers", "music"
|
||||
"wallpapers", "music", "sip", "email", "irc", "tox", "smallweb", "gps"
|
||||
};
|
||||
std::string skip = (skip_plugin && skip_plugin[0]) ? skip_plugin : "";
|
||||
for (const char* p : kPlugins) {
|
||||
|
||||
+22
-2
@@ -2694,9 +2694,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
reset_session_defaults(1, "Power");
|
||||
append_active_call_entries();
|
||||
snprintf(label, sizeof(label), "%s Lock", ICON_LCK);
|
||||
add_menu_item(label, "sxmo_state.sh set lock", 0);
|
||||
add_menu_item(label, "@plugin:locker", 0);
|
||||
snprintf(label, sizeof(label), "%s Lock (Screen off)", ICON_LCK);
|
||||
add_menu_item(label, "sxmo_state.sh set screenoff", 0);
|
||||
add_menu_item(label, "@plugin:locker:screenoff", 0);
|
||||
snprintf(label, sizeof(label), "%s Logout", ICON_OUT);
|
||||
add_menu_item(label, "@menu:confirm_logout", 1);
|
||||
snprintf(label, sizeof(label), "%s Reboot", ICON_RLD);
|
||||
@@ -2820,7 +2820,10 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
static int
|
||||
any_other_plugin_active(void)
|
||||
{
|
||||
if (access("/tmp/bananarchy_screen_locked", F_OK) == 0)
|
||||
return 1;
|
||||
static const char *pid_files[] = {
|
||||
"xlocker.pid",
|
||||
"xdrawer.pid",
|
||||
"xdialer.pid",
|
||||
"xcalllog.pid",
|
||||
@@ -2835,6 +2838,12 @@ any_other_plugin_active(void)
|
||||
"xringtones.pid",
|
||||
"xwallpapers.pid",
|
||||
"xmusic.pid",
|
||||
"xsip.pid",
|
||||
"xemail.pid",
|
||||
"xirc.pid",
|
||||
"xtox.pid",
|
||||
"xsmallweb.pid",
|
||||
"xgps.pid",
|
||||
};
|
||||
const char *rdir = getenv("XDG_RUNTIME_DIR");
|
||||
const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
|
||||
@@ -2879,6 +2888,12 @@ close_other_active_plugins(void)
|
||||
{ "xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo" },
|
||||
{ "xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo" },
|
||||
{ "xmusic.pid", "/tmp/dwm_plugin_music.fifo" },
|
||||
{ "xsip.pid", "/tmp/dwm_plugin_sip.fifo" },
|
||||
{ "xemail.pid", "/tmp/dwm_plugin_email.fifo" },
|
||||
{ "xirc.pid", "/tmp/dwm_plugin_irc.fifo" },
|
||||
{ "xtox.pid", "/tmp/dwm_plugin_tox.fifo" },
|
||||
{ "xsmallweb.pid", "/tmp/dwm_plugin_smallweb.fifo" },
|
||||
{ "xgps.pid", "/tmp/dwm_plugin_gps.fifo" },
|
||||
};
|
||||
const char *rdir = getenv("XDG_RUNTIME_DIR");
|
||||
const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
|
||||
@@ -3074,6 +3089,11 @@ show_menu(void)
|
||||
const int bar_h = 24;
|
||||
int target_y;
|
||||
|
||||
if (access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
|
||||
menu_mode = MODE_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
check_dmenu_xres_changed();
|
||||
|
||||
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
|
||||
|
||||
+62
-10
@@ -1301,6 +1301,21 @@ set_sxmo_state_str(const char *st)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
is_screen_off(void)
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf));
|
||||
return (buf[0] != '\0' && atoi(buf) <= 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
is_passcode_locked(void)
|
||||
{
|
||||
return access("/tmp/bananarchy_screen_locked", F_OK) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
is_phone_locked(void)
|
||||
{
|
||||
@@ -1309,8 +1324,7 @@ is_phone_locked(void)
|
||||
int fd;
|
||||
ssize_t n;
|
||||
|
||||
read_sysfs_str("/sys/class/backlight/backlight/brightness", buf, sizeof(buf));
|
||||
if (buf[0] != '\0' && atoi(buf) <= 0)
|
||||
if (is_screen_off() || is_passcode_locked())
|
||||
return 1;
|
||||
|
||||
snprintf(path, sizeof(path), "%s/sxmo.state", (rdir && rdir[0]) ? rdir : "/run/user/10000");
|
||||
@@ -1728,7 +1742,7 @@ is_right_softkey(KeySym ks, unsigned int keycode)
|
||||
#include <dlfcn.h>
|
||||
#include "dwm_plugin.h"
|
||||
|
||||
#define MAX_DWM_PLUGINS 24
|
||||
#define MAX_DWM_PLUGINS 48
|
||||
|
||||
typedef struct {
|
||||
void *handle;
|
||||
@@ -1796,7 +1810,13 @@ host_spawn_plugin(const char *plugin_name, const char *arg)
|
||||
if (arg && strcmp(arg, "--preload") == 0) {
|
||||
if (is_plugin_daemon_alive(plugin_name))
|
||||
return;
|
||||
int stagger_ms = (strcmp(plugin_name, "dmenu") == 0) ? 150 : (600 + (preload_stagger_idx++ * 220));
|
||||
int stagger_ms = 600;
|
||||
if (strcmp(plugin_name, "locker") == 0)
|
||||
stagger_ms = 80;
|
||||
else if (strcmp(plugin_name, "dmenu") == 0)
|
||||
stagger_ms = 150;
|
||||
else
|
||||
stagger_ms = 600 + (preload_stagger_idx++ * 220);
|
||||
if (fork() == 0) {
|
||||
if (dpy)
|
||||
close(ConnectionNumber(dpy));
|
||||
@@ -1807,15 +1827,24 @@ host_spawn_plugin(const char *plugin_name, const char *arg)
|
||||
}
|
||||
return;
|
||||
}
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
XFlush(dpy);
|
||||
if (strcmp(plugin_name, "locker") != 0) {
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
XFlush(dpy);
|
||||
}
|
||||
if (is_plugin_daemon_alive(plugin_name)) {
|
||||
char fifopath[128], msg[128];
|
||||
snprintf(fifopath, sizeof(fifopath), "/tmp/dwm_plugin_%s.fifo", plugin_name);
|
||||
int fd = open(fifopath, O_WRONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd >= 0) {
|
||||
int len;
|
||||
if (strcmp(plugin_name, "xdrawer") == 0)
|
||||
if (strcmp(plugin_name, "locker") == 0) {
|
||||
if (arg && (strcmp(arg, "screenoff") == 0 || strcmp(arg, "blank") == 0))
|
||||
len = snprintf(msg, sizeof(msg), "LOCK_BLANK\n");
|
||||
else if (arg && strcmp(arg, "wake") == 0)
|
||||
len = snprintf(msg, sizeof(msg), "WAKE\n");
|
||||
else
|
||||
len = snprintf(msg, sizeof(msg), "LOCK\n");
|
||||
} else if (strcmp(plugin_name, "xdrawer") == 0)
|
||||
len = snprintf(msg, sizeof(msg), "TOGGLE\n");
|
||||
else if (strcmp(plugin_name, "dmenu") == 0 && arg && strcmp(arg, "close") == 0)
|
||||
len = snprintf(msg, sizeof(msg), "CLOSE\n");
|
||||
@@ -2086,6 +2115,7 @@ static void
|
||||
lock_phone_screenoff(void)
|
||||
{
|
||||
const Arg offcmd = SHCMD("sxmo_dmenu.sh close; sxmo_state.sh set screenoff");
|
||||
int lfd;
|
||||
softkey_pending = 0;
|
||||
softkey_first_ms = 0;
|
||||
softkey_deadline_ms = 0;
|
||||
@@ -2096,8 +2126,14 @@ lock_phone_screenoff(void)
|
||||
star_down = 0;
|
||||
pound_down = 0;
|
||||
write_softkey_state(0, 0);
|
||||
lfd = open("/tmp/bananarchy_screen_locked", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (lfd >= 0) {
|
||||
(void)write(lfd, "1\n", 2);
|
||||
close(lfd);
|
||||
}
|
||||
if (is_plugin_loaded("dmenu"))
|
||||
host_spawn_plugin("dmenu", "close");
|
||||
host_spawn_plugin("locker", "screenoff");
|
||||
set_sxmo_state_str("screenoff");
|
||||
set_hw_backlight(0);
|
||||
spawn(&offcmd);
|
||||
@@ -2121,10 +2157,15 @@ wake_phone(void)
|
||||
pound_down = 0;
|
||||
write_softkey_state(0, 0);
|
||||
write_softkey_suppress(now + SOFTKEY_SUPPRESS_MS);
|
||||
set_hw_backlight(1);
|
||||
if (is_passcode_locked()) {
|
||||
set_sxmo_state_str("lock");
|
||||
host_spawn_plugin("locker", "wake");
|
||||
return;
|
||||
}
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
XFlush(dpy);
|
||||
set_sxmo_state_str("unlock");
|
||||
set_hw_backlight(1);
|
||||
spawn(&oncmd);
|
||||
}
|
||||
|
||||
@@ -2138,6 +2179,14 @@ keypress(XEvent *e)
|
||||
ev = &e->xkey;
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||
|
||||
if (is_screen_off()) {
|
||||
wake_phone();
|
||||
return;
|
||||
}
|
||||
if (is_passcode_locked()) {
|
||||
host_spawn_plugin("locker", "wake");
|
||||
return;
|
||||
}
|
||||
if (is_phone_locked()) {
|
||||
wake_phone();
|
||||
return;
|
||||
@@ -2767,9 +2816,12 @@ run(void)
|
||||
pound_down = (ie.value != 0);
|
||||
|
||||
if (ie.value == 1) {
|
||||
if (is_phone_locked()) {
|
||||
if (is_screen_off()) {
|
||||
wake_phone();
|
||||
} else if ((ie.code == 522 || ie.code == 55 ||
|
||||
} else if (!is_passcode_locked() && is_phone_locked()) {
|
||||
wake_phone();
|
||||
} else if (!is_passcode_locked() &&
|
||||
(ie.code == 522 || ie.code == 55 ||
|
||||
ie.code == 523 || ie.code == 98) &&
|
||||
star_down && pound_down) {
|
||||
trigger_screenshot_chord(dwm_now_ms());
|
||||
|
||||
+15
-5
@@ -1021,11 +1021,15 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto isOtherPluginActive = [&]() {
|
||||
if (::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
|
||||
return true;
|
||||
}
|
||||
static const char* kPids[] = {
|
||||
"xdialer.pid", "xcalllog.pid", "xcallscreen.pid", "xcontacts.pid",
|
||||
"xsms.pid", "xfiles.pid", "xcamera.pid", "xthemes.pid",
|
||||
"xmodem.pid", "xnetworks.pid", "xringtones.pid", "xwallpapers.pid",
|
||||
"xmusic.pid",
|
||||
"xlocker.pid", "xdialer.pid", "xcalllog.pid", "xcallscreen.pid",
|
||||
"xcontacts.pid", "xsms.pid", "xfiles.pid", "xcamera.pid",
|
||||
"xthemes.pid", "xmodem.pid", "xnetworks.pid", "xringtones.pid",
|
||||
"xwallpapers.pid", "xmusic.pid", "xsip.pid", "xemail.pid",
|
||||
"xirc.pid", "xtox.pid", "xsmallweb.pid", "xgps.pid",
|
||||
};
|
||||
for (const char* pf : kPids) {
|
||||
int p = readIntFile(getRuntimeFile(pf), -1);
|
||||
@@ -1040,7 +1044,7 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
};
|
||||
|
||||
auto showWindow = [&]() {
|
||||
if (visible) {
|
||||
if (visible || ::access("/tmp/bananarchy_screen_locked", F_OK) == 0) {
|
||||
return;
|
||||
}
|
||||
writeIntFile(pidPath, static_cast<int>(::getpid()));
|
||||
@@ -1057,6 +1061,12 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
closeOtherPlugin("xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo");
|
||||
closeOtherPlugin("xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo");
|
||||
closeOtherPlugin("xmusic.pid", "/tmp/dwm_plugin_music.fifo");
|
||||
closeOtherPlugin("xsip.pid", "/tmp/dwm_plugin_sip.fifo");
|
||||
closeOtherPlugin("xemail.pid", "/tmp/dwm_plugin_email.fifo");
|
||||
closeOtherPlugin("xirc.pid", "/tmp/dwm_plugin_irc.fifo");
|
||||
closeOtherPlugin("xtox.pid", "/tmp/dwm_plugin_tox.fifo");
|
||||
closeOtherPlugin("xsmallweb.pid", "/tmp/dwm_plugin_smallweb.fifo");
|
||||
closeOtherPlugin("xgps.pid", "/tmp/dwm_plugin_gps.fifo");
|
||||
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) {
|
||||
int dfd = ::open("/tmp/dwm_plugin_dmenu.fifo", O_WRONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (dfd >= 0) {
|
||||
|
||||
Reference in new issue
Block a user