From 7e8bff904fd4f446d8b5ce470de33193dfc7e923 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 23 Mar 2001 02:26:15 +0000 Subject: [PATCH] Fixed secure textfields not to allow text selection, to avoid compromising sensitive information by pasting it to a terminal. --- WINGs/ChangeLog | 3 +++ WINGs/wtextfield.c | 53 ++++++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 400f5930..2fe5ebcb 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -16,6 +16,9 @@ Changes since wmaker 0.64.0: - better and more robust handling of events (timer, idle, input, X) in WMMaskEvent(). Also fixed a bug where input and timer events were not 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: ............................ diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index e310dda8..97f6c5ae 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -64,9 +64,9 @@ typedef struct W_TextField { unsigned int secure:1; /* password entry style */ unsigned int pointerGrabbed:1; - + unsigned int ownsSelection:1; - + unsigned int waitingSelection:1; /* requested selection, but * didnt get yet */ @@ -1255,32 +1255,30 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) } break; } - - + if (relay) { WMRelayToNextResponder(W_VIEW(tPtr), event); return; } - - if (!cancelSelection) { - if (tPtr->selection.count != tPtr->cursorPosition - tPtr->selection.position) { - + /* Do not allow text selection in secure text fields */ + 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; - WMPostNotificationName("_lostOwnership", NULL, tPtr); + WMPostNotificationName("_lostOwnership", NULL, tPtr); 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);*/ @@ -1426,9 +1424,14 @@ handleTextFieldActionEvents(XEvent *event, void *data) tPtr->cursorPosition = 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->flags.ownsSelection) { WMCreateSelectionHandler(tPtr->view, @@ -1464,12 +1467,11 @@ handleTextFieldActionEvents(XEvent *event, void *data) textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen); if (tPtr->flags.enabled && !tPtr->flags.focused) { WMSetFocusToWidget(tPtr); - } else if (tPtr->flags.focused) { tPtr->selection.position = tPtr->cursorPosition; tPtr->selection.count = 0; } - if(textWidth < tPtr->usableWidth) { + if (textWidth < tPtr->usableWidth) { tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x - tPtr->usableWidth + textWidth); @@ -1544,8 +1546,9 @@ handleTextFieldActionEvents(XEvent *event, void *data) move = 0; - if (event->xbutton.time - lastButtonReleasedEvent - <= WINGsConfiguration.doubleClickDelay) { + if (!tPtr->flags.secure && + event->xbutton.time - lastButtonReleasedEvent + <= WINGsConfiguration.doubleClickDelay) { tPtr->selection.position = 0; tPtr->selection.count = tPtr->textLen; paintTextField(tPtr);