Prevent duplicated uses of pinentry

pull/9/head 0.2.2
Moritz Luedecke 4 years ago
parent df021cebfd
commit a77bb7a194
No known key found for this signature in database
GPG Key ID: 16A7C55D54A18BF9

@ -64,7 +64,7 @@ static Clr *scheme[SchemeLast];
static int timed_out; static int timed_out;
static int winmode; static int winmode;
pinentry_t pinentry; pinentry_t pinentry_info;
#include "config.h" #include "config.h"
@ -157,10 +157,10 @@ insert(const char *str, ssize_t n) {
pin_len = 0; pin_len = 0;
} }
} else { } else {
if (!pinentry_setbufferlen(pinentry, 2 * pinentry->pin_len)) { if (!pinentry_setbufferlen(pinentry_info, 2 * pinentry_info->pin_len)) {
pin_len = 0; pin_len = 0;
} else { } else {
setup_pin(pinentry->pin, pinentry->pin_len, 0); setup_pin(pinentry_info->pin, pinentry_info->pin_len, 0);
} }
} }
if (pin_len == 0) { if (pin_len == 0) {
@ -189,7 +189,7 @@ drawwin(void) {
int leftinput; int leftinput;
char* censort; char* censort;
char* pprompt = (repeat) ? pinentry->repeat_passphrase : pinentry->prompt; char* pprompt = (repeat) ? pinentry_info->repeat_passphrase : pinentry_info->prompt;
int ppromptw = (pprompt) ? TEXTW(pprompt) : 0; int ppromptw = (pprompt) ? TEXTW(pprompt) : 0;
unsigned int censortl = minpwlen * TEXTW(asterisk) / strlen(asterisk); unsigned int censortl = minpwlen * TEXTW(asterisk) / strlen(asterisk);
@ -209,9 +209,9 @@ drawwin(void) {
x += ppromptw; x += ppromptw;
} }
if (pinentry->description) { if (pinentry_info->description) {
pb = mw - x; pb = mw - x;
pdesclen = strlen(pinentry->description); pdesclen = strlen(pinentry_info->description);
if (pb > 0) { if (pb > 0) {
pb -= (winmode == WinPin) ? censortl : confirml; pb -= (winmode == WinPin) ? censortl : confirml;
@ -224,13 +224,13 @@ drawwin(void) {
pb = mw - pbw; pb = mw - pbw;
for (i = 0; i < pdesclen; i++) { for (i = 0; i < pdesclen; i++) {
if (pinentry->description[i] == '\n') { if (pinentry_info->description[i] == '\n') {
pinentry->description[i] = ' '; pinentry_info->description[i] = ' ';
} }
} }
drw_setscheme(drw, scheme[SchemeDesc]); drw_setscheme(drw, scheme[SchemeDesc]);
drw_text(drw, pb, 0, pbw, bh, lrpad / 2, pinentry->description, drw_text(drw, pb, 0, pbw, bh, lrpad / 2, pinentry_info->description,
0); 0);
} else { } else {
pbw = 0; pbw = 0;
@ -344,7 +344,7 @@ setup(void) {
mw = wa.width; mw = wa.width;
} }
pdescw = (pinentry->description) ? TEXTW(pinentry->description) : 0; pdescw = (pinentry_info->description) ? TEXTW(pinentry_info->description) : 0;
/* Create menu window */ /* Create menu window */
swa.override_redirect = True; swa.override_redirect = True;
@ -393,7 +393,7 @@ keypress_confirm(XKeyEvent *ev, KeySym ksym) {
if (ev->state & ControlMask) { if (ev->state & ControlMask) {
switch(ksym) { switch(ksym) {
case XK_c: case XK_c:
pinentry->canceled = 1; pinentry_info->canceled = 1;
sel = No; sel = No;
return 1; return 1;
default: default:
@ -419,7 +419,7 @@ keypress_confirm(XKeyEvent *ev, KeySym ksym) {
case XK_g: case XK_g:
case XK_G: case XK_G:
case XK_Escape: case XK_Escape:
pinentry->canceled = 1; pinentry_info->canceled = 1;
sel = No; sel = No;
return 1; return 1;
case XK_h: case XK_h:
@ -473,7 +473,7 @@ keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) {
case XK_KP_Enter: case XK_KP_Enter:
break; break;
case XK_bracketleft: case XK_bracketleft:
pinentry->canceled = 1; pinentry_info->canceled = 1;
return 1; return 1;
default: default:
return 1; return 1;
@ -494,7 +494,7 @@ keypress_pin(XKeyEvent *ev, KeySym ksym, char* buf, int len) {
insert(NULL, nextrune(cursor, -1) - cursor); insert(NULL, nextrune(cursor, -1) - cursor);
break; break;
case XK_Escape: case XK_Escape:
pinentry->canceled = 1; pinentry_info->canceled = 1;
return 1; return 1;
case XK_Left: case XK_Left:
if (cursor > 0) { if (cursor > 0) {
@ -611,31 +611,31 @@ static void
password(void) { password(void) {
winmode = WinPin; winmode = WinPin;
repeat = 0; repeat = 0;
setup_pin(pinentry->pin, pinentry->pin_len, 1); setup_pin(pinentry_info->pin, pinentry_info->pin_len, 1);
run(); run();
if (!pinentry->canceled && pinentry->repeat_passphrase) { if (!pinentry_info->canceled && pinentry_info->repeat_passphrase) {
repeat = 1; repeat = 1;
pin_repeat_len = pinentry->pin_len; pin_repeat_len = pinentry_info->pin_len;
pin_repeat = secmem_malloc(pinentry->pin_len); pin_repeat = secmem_malloc(pinentry_info->pin_len);
setup_pin(pin_repeat, pin_repeat_len, 1); setup_pin(pin_repeat, pin_repeat_len, 1);
run(); run();
pinentry->repeat_okay = (strcmp(pinentry->pin, pin_repeat) == 0)? 1 : 0; pinentry_info->repeat_okay = (strcmp(pinentry_info->pin, pin_repeat) == 0)? 1 : 0;
secmem_free(pin_repeat); secmem_free(pin_repeat);
if (!pinentry->repeat_okay) { if (!pinentry_info->repeat_okay) {
pinentry->result = -1; pinentry_info->result = -1;
return; return;
} }
} }
if (pinentry->canceled) { if (pinentry_info->canceled) {
pinentry->result = -1; pinentry_info->result = -1;
return; return;
} }
pinentry->result = strlen(pinentry->pin); pinentry_info->result = strlen(pinentry_info->pin);
} }
static void static void
@ -643,7 +643,7 @@ confirm(void) {
winmode = WinConfirm; winmode = WinConfirm;
sel = Nothing; sel = Nothing;
run(); run();
pinentry->result = sel != No; pinentry_info->result = sel != No;
} }
static int static int
@ -651,18 +651,18 @@ cmdhandler(pinentry_t received_pinentry) {
struct sigaction sa; struct sigaction sa;
XWindowAttributes wa; XWindowAttributes wa;
pinentry = received_pinentry; pinentry_info = received_pinentry;
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) { if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) {
fputs("warning: no locale support\n", stderr); fputs("warning: no locale support\n", stderr);
} }
if (!(dpy = XOpenDisplay(pinentry->display))) { if (!(dpy = XOpenDisplay(pinentry_info->display))) {
die("cannot open display"); die("cannot open display");
} }
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen); root = RootWindow(dpy, screen);
embedded = (pinentry->parent_wid) ? embedded : 0; embedded = (pinentry_info->parent_wid) ? embedded : 0;
parentwin = (embedded) ? pinentry->parent_wid : root; parentwin = (embedded) ? pinentry_info->parent_wid : root;
if (!XGetWindowAttributes(dpy, parentwin, &wa)) { if (!XGetWindowAttributes(dpy, parentwin, &wa)) {
die("could not get embedding window attributes: 0x%lx", parentwin); die("could not get embedding window attributes: 0x%lx", parentwin);
} }
@ -673,28 +673,28 @@ cmdhandler(pinentry_t received_pinentry) {
lrpad = drw->fonts->h; lrpad = drw->fonts->h;
drw_setscheme(drw, scheme[SchemePrompt]); drw_setscheme(drw, scheme[SchemePrompt]);
if (pinentry->timeout) { if (pinentry_info->timeout) {
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = catchsig; sa.sa_handler = catchsig;
sigaction(SIGALRM, &sa, NULL); sigaction(SIGALRM, &sa, NULL);
alarm(pinentry->timeout); alarm(pinentry_info->timeout);
} }
grabkeyboard(); grabkeyboard();
setup(); setup();
if (pinentry->pin) { if (pinentry_info->pin) {
do { do {
password(); password();
} while (!pinentry->canceled && pinentry->repeat_passphrase } while (!pinentry_info->canceled && pinentry_info->repeat_passphrase
&& !pinentry->repeat_okay); && !pinentry_info->repeat_okay);
} else { } else {
confirm(); confirm();
} }
cleanup(); cleanup();
return pinentry->result; return pinentry_info->result;
} }
pinentry_cmd_handler_t pinentry_cmd_handler = cmdhandler; pinentry_cmd_handler_t pinentry_cmd_handler = cmdhandler;

Loading…
Cancel
Save