1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-28 17:32:29 +01:00

Fixed secure textfields not to allow text selection, to avoid

compromising sensitive information by pasting it to a terminal.
This commit is contained in:
dan
2001-03-23 02:26:15 +00:00
parent 1a3fd2f795
commit 7e8bff904f
2 changed files with 31 additions and 25 deletions

View File

@@ -16,6 +16,9 @@ Changes since wmaker 0.64.0:
- better and more robust handling of events (timer, idle, input, X) in - better and more robust handling of events (timer, idle, input, X) in
WMMaskEvent(). Also fixed a bug where input and timer events were not WMMaskEvent(). Also fixed a bug where input and timer events were not
treated for undefined periods of time under some circumstances. treated for undefined periods of time under some circumstances.
- fixed secure textfields not to allow text selection, to avoid compromising
sensitive information by pasting it to a terminal.
changes since wmaker 0.63.1: changes since wmaker 0.63.1:
............................ ............................

View File

@@ -64,9 +64,9 @@ typedef struct W_TextField {
unsigned int secure:1; /* password entry style */ unsigned int secure:1; /* password entry style */
unsigned int pointerGrabbed:1; unsigned int pointerGrabbed:1;
unsigned int ownsSelection:1; unsigned int ownsSelection:1;
unsigned int waitingSelection:1; /* requested selection, but unsigned int waitingSelection:1; /* requested selection, but
* didnt get yet */ * didnt get yet */
@@ -1255,32 +1255,30 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event)
} }
break; break;
} }
if (relay) { if (relay) {
WMRelayToNextResponder(W_VIEW(tPtr), event); WMRelayToNextResponder(W_VIEW(tPtr), event);
return; return;
} }
if (!cancelSelection) { /* Do not allow text selection in secure text fields */
if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) { if (cancelSelection || tPtr->flags.secure) {
lostHandler(tPtr->view, XA_PRIMARY, NULL);
if (tPtr->selection.count) {
tPtr->selection.count = 0;
refresh = 1;
}
tPtr->selection.position = tPtr->cursorPosition;
} else {
if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) {
tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;
WMPostNotificationName("_lostOwnership", NULL, tPtr); WMPostNotificationName("_lostOwnership", NULL, tPtr);
refresh = 1; refresh = 1;
} }
} else {
lostHandler(tPtr->view, XA_PRIMARY, NULL);
if (tPtr->selection.count) {
tPtr->selection.count = 0;
refresh = 1;
}
tPtr->selection.position = tPtr->cursorPosition;
} }
/*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count);*/ /*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count);*/
@@ -1426,9 +1424,14 @@ handleTextFieldActionEvents(XEvent *event, void *data)
tPtr->cursorPosition = tPtr->cursorPosition =
pointToCursorPosition(tPtr, event->xmotion.x); pointToCursorPosition(tPtr, event->xmotion.x);
tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position; /* Do not allow text selection in secure textfields */
if (tPtr->flags.secure) {
tPtr->selection.position = tPtr->cursorPosition;
}
tPtr->selection.count = tPtr->cursorPosition - tPtr->selection.position;
if (tPtr->selection.count != 0) { if (tPtr->selection.count != 0) {
if (!tPtr->flags.ownsSelection) { if (!tPtr->flags.ownsSelection) {
WMCreateSelectionHandler(tPtr->view, WMCreateSelectionHandler(tPtr->view,
@@ -1464,12 +1467,11 @@ handleTextFieldActionEvents(XEvent *event, void *data)
textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
if (tPtr->flags.enabled && !tPtr->flags.focused) { if (tPtr->flags.enabled && !tPtr->flags.focused) {
WMSetFocusToWidget(tPtr); WMSetFocusToWidget(tPtr);
} else if (tPtr->flags.focused) { } else if (tPtr->flags.focused) {
tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.position = tPtr->cursorPosition;
tPtr->selection.count = 0; tPtr->selection.count = 0;
} }
if(textWidth < tPtr->usableWidth) { if (textWidth < tPtr->usableWidth) {
tPtr->cursorPosition = pointToCursorPosition(tPtr, tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x - tPtr->usableWidth event->xbutton.x - tPtr->usableWidth
+ textWidth); + textWidth);
@@ -1544,8 +1546,9 @@ handleTextFieldActionEvents(XEvent *event, void *data)
move = 0; move = 0;
if (event->xbutton.time - lastButtonReleasedEvent if (!tPtr->flags.secure &&
<= WINGsConfiguration.doubleClickDelay) { event->xbutton.time - lastButtonReleasedEvent
<= WINGsConfiguration.doubleClickDelay) {
tPtr->selection.position = 0; tPtr->selection.position = 0;
tPtr->selection.count = tPtr->textLen; tPtr->selection.count = tPtr->textLen;
paintTextField(tPtr); paintTextField(tPtr);