|
xsecurelock
1.7.0
XSecureLock is an X11 screen lock utility.
|
#include <X11/X.h>#include <X11/Xlib.h>#include <locale.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/select.h>#include <sys/time.h>#include <time.h>#include <unistd.h>#include "../env_info.h"#include "../env_settings.h"#include "../logging.h"#include "../mlock_page.h"#include "../util.h"#include "../wait_pgrp.h"#include "../wm_properties.h"#include "../xscreensaver_api.h"#include "authproto.h"#include "monitors.h"Macros | |
| #define | STATIC_ASSERT(state, message) extern int statically_asserted(int assertion[(state) ? 1 : -1]); |
| #define | BLINK_INTERVAL (250 * 1000) |
| The blinking interval in microseconds. More... | |
| #define | DISCO_PASSWORD_DANCERS 5 |
| Number of dancers in the disco password display. More... | |
| #define | PARANOID_PASSWORD_LENGTH (1 << DISCO_PASSWORD_DANCERS) |
| Length of the "paranoid password display". More... | |
| #define | PARANOID_PASSWORD_MIN_CHANGE 4 |
| Minimum distance the cursor shall move on keypress. More... | |
| #define | WINDOW_BORDER 16 |
| Border of the window around the text. More... | |
| #define | LINE_SPACING 4 |
| Draw border rectangle (mainly for debugging). More... | |
| #define | MAIN_WINDOW 0 |
| #define | MAX_WINDOWS 16 |
| #define | NOTE_DS3 156 |
| #define | NOTE_A3 220 |
| #define | NOTE_DS4 311 |
| #define | NOTE_E4 330 |
| #define | NOTE_B4 494 |
| #define | NOTE_E5 659 |
| #define | SOUND_SLEEP_MS 125 |
| #define | SOUND_TONE_MS 100 |
| #define | PWBUF_SIZE 256 |
| The size of the buffer to store the password in. Not NUL terminated. More... | |
| #define | DISPLAYBUF_SIZE (PWBUF_SIZE + 2) |
| The size of the buffer to use for display, with space for cursor and NUL. More... | |
Enumerations | |
| enum | PasswordPrompt { PASSWORD_PROMPT_CURSOR, PASSWORD_PROMPT_ASTERISKS, PASSWORD_PROMPT_HIDDEN, PASSWORD_PROMPT_DISCO, PASSWORD_PROMPT_EMOJI, PASSWORD_PROMPT_EMOTICON, PASSWORD_PROMPT_KAOMOJI, PASSWORD_PROMPT_COUNT } |
| Actual password prompt selected. More... | |
| enum | Sound { SOUND_PROMPT, SOUND_INFO, SOUND_ERROR, SOUND_SUCCESS } |
Functions | |
| STATIC_ASSERT (sizeof(emoji)/sizeof(*emoji)==PARANOID_PASSWORD_LENGTH, "Emoji array size must be equal to PARANOID_PASSWORD_LENGTH") | |
| STATIC_ASSERT (sizeof(emoticons)/sizeof(*emoticons)==PARANOID_PASSWORD_LENGTH, "Emoticons array size must be equal to PARANOID_PASSWORD_LENGTH") | |
| STATIC_ASSERT (sizeof(kaomoji)/sizeof(*kaomoji)==PARANOID_PASSWORD_LENGTH, "Kaomoji array size must be equal to PARANOID_PASSWORD_LENGTH") | |
| void | PlaySound (enum Sound snd) |
| Play a sound sequence. More... | |
| void | SwitchKeyboardLayout (void) |
| Switch to the next keyboard layout. More... | |
| const char * | GetIndicators (int *warning, int *have_multiple_layouts) |
| Check which modifiers are active. More... | |
| void | DestroyPerMonitorWindows (size_t keep_windows) |
| void | CreateOrUpdatePerMonitorWindow (size_t i, const Monitor *monitor, int region_w, int region_h, int x_offset, int y_offset) |
| void | UpdatePerMonitorWindows (int monitors_changed, int region_w, int region_h, int x_offset, int y_offset) |
| int | TextAscent (void) |
| int | TextDescent (void) |
| int | TextWidth (const char *string, int len) |
| void | DrawString (int monitor, int x, int y, int is_warning, const char *string, int len) |
| void | StrAppend (char **output, size_t *output_size, const char *input, size_t input_size) |
| void | BuildTitle (char *output, size_t output_size, const char *input) |
| void | DisplayMessage (const char *title, const char *str, int is_warning) |
| Display a string in the window. More... | |
| void | WaitForKeypress (int seconds) |
| void | BumpDisplayMarker (size_t pwlen, size_t *pos, struct timeval *last_keystroke) |
| Bump the position for the password "cursor". More... | |
| void | ShowFromArray (const char **array, size_t displaymarker, char *displaybuf, size_t displaybufsize, size_t *displaylen) |
| int | Prompt (const char *msg, char **response, int echo) |
| Ask a question to the user. More... | |
| int | Authenticate () |
| Perform authentication using a helper proxy. More... | |
| enum PasswordPrompt | GetPasswordPromptFromFlags (int paranoid_password_flag, const char *password_prompt_flag) |
| int | main (int argc_local, char **argv_local) |
| The main program. More... | |
Variables | |
| int | argc |
| Number of args. More... | |
| char *const * | argv |
| Args. More... | |
| const char * | authproto_executable |
| The authproto helper to use. More... | |
| int | prompt_timeout |
| The maximum time to wait at a prompt for user input in seconds. More... | |
| const char * | PasswordPromptStrings [] |
| enum PasswordPrompt | password_prompt |
| const char * | disco_combiner = " ♪ " |
| const char * | disco_dancers [] |
| const char * | emoji [] |
| const char * | emoticons [] |
| const char * | kaomoji [] |
| int | have_switch_user_command |
| If set, we can start a new login session. More... | |
| int | show_username |
| If set, the prompt will be fixed by <username>. More... | |
| int | show_hostname |
| If set, the prompt will be fixed by <hostname>. If >1, the hostname will be. More... | |
| int | show_datetime |
| If set, data and time will be shown. More... | |
| const char * | datetime_format = "%c" |
| The date format to display. More... | |
| char | hostname [256] |
| The local hostname. More... | |
| char | username [256] |
| The username to authenticate as. More... | |
| Display * | display |
| The X11 display. More... | |
| Window | main_window |
| The X11 window provided by main. Provided from $XSCREENSAVER_WINDOW. More... | |
| Window | parent_window |
| main_window's parent. Used to create per-monitor siblings. More... | |
| XFontStruct * | core_font |
| The X11 core font for the PAM messages. More... | |
| XColor | xcolor_background |
| The background color. More... | |
| XColor | xcolor_foreground |
| The foreground color. More... | |
| XColor | xcolor_warning |
| The warning color (used as foreground). More... | |
| static const char | cursor [] = "_" |
| The cursor character displayed at the end of the masked password input. More... | |
| static int | x_offset = 0 |
| The x offset to apply to the entire display (to mitigate burn-in). More... | |
| static int | y_offset = 0 |
| The y offset to apply to the entire display (to mitigate burn-in). More... | |
| static int | burnin_mitigation_max_offset = 0 |
| Maximum offset value when dynamic changes are enabled. More... | |
| static int | burnin_mitigation_max_offset_change = 0 |
| How much the offsets are allowed to change dynamically, and if so, how high. More... | |
| static int | auth_sounds = 0 |
| Whether to play sounds during authentication. More... | |
| static int | auth_cursor_blink = 1 |
| Whether to blink the cursor in the auth dialog. More... | |
| static int | single_auth_window = 0 |
| Whether we only want a single auth window. More... | |
| int | per_monitor_windows_dirty = 1 |
| If set, we need to re-query monitor data and adjust windows. More... | |
| size_t | num_windows = 0 |
| The number of active X11 per-monitor windows. More... | |
| Window | windows [MAX_WINDOWS] |
| The X11 per-monitor windows to draw on. More... | |
| GC | gcs [MAX_WINDOWS] |
| The X11 graphics contexts to draw with. More... | |
| GC | gcs_warning [MAX_WINDOWS] |
| The X11 graphics contexts to draw warnings with. More... | |
| int | have_xkb_ext |
| int | sounds [][2] |
| #define BLINK_INTERVAL (250 * 1000) |
The blinking interval in microseconds.
| #define DISCO_PASSWORD_DANCERS 5 |
Number of dancers in the disco password display.
| #define DISPLAYBUF_SIZE (PWBUF_SIZE + 2) |
The size of the buffer to use for display, with space for cursor and NUL.
| #define LINE_SPACING 4 |
Draw border rectangle (mainly for debugging).
Extra line spacing.
| #define MAIN_WINDOW 0 |
| #define MAX_WINDOWS 16 |
| #define NOTE_A3 220 |
| #define NOTE_B4 494 |
| #define NOTE_DS3 156 |
| #define NOTE_DS4 311 |
| #define NOTE_E4 330 |
| #define NOTE_E5 659 |
| #define PARANOID_PASSWORD_LENGTH (1 << DISCO_PASSWORD_DANCERS) |
Length of the "paranoid password display".
| #define PARANOID_PASSWORD_MIN_CHANGE 4 |
Minimum distance the cursor shall move on keypress.
| #define PWBUF_SIZE 256 |
The size of the buffer to store the password in. Not NUL terminated.
| #define SOUND_SLEEP_MS 125 |
| #define SOUND_TONE_MS 100 |
| #define STATIC_ASSERT | ( | state, | |
| message | |||
| ) | extern int statically_asserted(int assertion[(state) ? 1 : -1]); |
| #define WINDOW_BORDER 16 |
Border of the window around the text.
| enum PasswordPrompt |
| enum Sound |
| int Authenticate | ( | ) |
Perform authentication using a helper proxy.
| void BuildTitle | ( | char * | output, |
| size_t | output_size, | ||
| const char * | input | ||
| ) |
| void BumpDisplayMarker | ( | size_t | pwlen, |
| size_t * | pos, | ||
| struct timeval * | last_keystroke | ||
| ) |
Bump the position for the password "cursor".
If pwlen > 0: Precondition: pos in 0..PARANOID_PASSWORD_LENGTH-1. Postcondition: pos' in 1..PARANOID_PASSWORD_LENGTH-1. Postcondition: abs(pos' - pos) >= PARANOID_PASSWORD_MIN_CHANGE. Postcondition: pos' is uniformly distributed among all permitted choices. If pwlen == 0: Postcondition: pos' is 0.
| pwlen | The current password length. |
| pos | The initial cursor position; will get updated. |
| last_keystroke | The time of last keystroke; will get updated. |
| void CreateOrUpdatePerMonitorWindow | ( | size_t | i, |
| const Monitor * | monitor, | ||
| int | region_w, | ||
| int | region_h, | ||
| int | x_offset, | ||
| int | y_offset | ||
| ) |
| void DestroyPerMonitorWindows | ( | size_t | keep_windows | ) |
| void DisplayMessage | ( | const char * | title, |
| const char * | str, | ||
| int | is_warning | ||
| ) |
Display a string in the window.
The given title and message will be displayed on all screens. In case caps lock is enabled, the string's case will be inverted.
| title | The title of the message. |
| str | The message itself. |
| is_warning | Whether to use the warning style to display the message. |
| void DrawString | ( | int | monitor, |
| int | x, | ||
| int | y, | ||
| int | is_warning, | ||
| const char * | string, | ||
| int | len | ||
| ) |
| const char* GetIndicators | ( | int * | warning, |
| int * | have_multiple_layouts | ||
| ) |
Check which modifiers are active.
| warning | Will be set to 1 if something's "bad" with the keyboard layout (e.g. Caps Lock). |
| have_multiple_layouts | Will be set to 1 if more than one keyboard layout is available for switching. |
| enum PasswordPrompt GetPasswordPromptFromFlags | ( | int | paranoid_password_flag, |
| const char * | password_prompt_flag | ||
| ) |
| int main | ( | int | argc_local, |
| char ** | argv_local | ||
| ) |
The main program.
Usage: XSCREENSAVER_WINDOW=window_id ./auth_x11; status=$?
Deprecated flag for setting whether password display should hide the length.
Updated flag for password display choice
| void PlaySound | ( | enum Sound | snd | ) |
Play a sound sequence.
| int Prompt | ( | const char * | msg, |
| char ** | response, | ||
| int | echo | ||
| ) |
Ask a question to the user.
| msg | The message. |
| response | The response will be stored in a newly allocated buffer here. The caller is supposed to eventually free() it. |
| echo | If true, the input will be shown; otherwise it will be hidden (password entry). |
| void ShowFromArray | ( | const char ** | array, |
| size_t | displaymarker, | ||
| char * | displaybuf, | ||
| size_t | displaybufsize, | ||
| size_t * | displaylen | ||
| ) |
| STATIC_ASSERT | ( | sizeof(emoji)/sizeof * | emoji = =PARANOID_PASSWORD_LENGTH, |
| "Emoji array size must be equal to PARANOID_PASSWORD_LENGTH" | |||
| ) |
| STATIC_ASSERT | ( | sizeof(emoticons)/sizeof * | emoticons = =PARANOID_PASSWORD_LENGTH, |
| "Emoticons array size must be equal to PARANOID_PASSWORD_LENGTH" | |||
| ) |
| STATIC_ASSERT | ( | sizeof(kaomoji)/sizeof * | kaomoji = =PARANOID_PASSWORD_LENGTH, |
| "Kaomoji array size must be equal to PARANOID_PASSWORD_LENGTH" | |||
| ) |
| void StrAppend | ( | char ** | output, |
| size_t * | output_size, | ||
| const char * | input, | ||
| size_t | input_size | ||
| ) |
| void SwitchKeyboardLayout | ( | void | ) |
Switch to the next keyboard layout.
| int TextAscent | ( | void | ) |
| int TextDescent | ( | void | ) |
| int TextWidth | ( | const char * | string, |
| int | len | ||
| ) |
| void UpdatePerMonitorWindows | ( | int | monitors_changed, |
| int | region_w, | ||
| int | region_h, | ||
| int | x_offset, | ||
| int | y_offset | ||
| ) |
| void WaitForKeypress | ( | int | seconds | ) |
| int argc |
Number of args.
| char* const* argv |
Args.
|
static |
Whether to blink the cursor in the auth dialog.
|
static |
Whether to play sounds during authentication.
| const char* authproto_executable |
The authproto helper to use.
|
static |
Maximum offset value when dynamic changes are enabled.
|
static |
How much the offsets are allowed to change dynamically, and if so, how high.
| XFontStruct* core_font |
The X11 core font for the PAM messages.
|
static |
The cursor character displayed at the end of the masked password input.
| const char* datetime_format = "%c" |
The date format to display.
| const char* disco_combiner = " ♪ " |
| const char* disco_dancers[] |
| Display* display |
The X11 display.
| const char* emoji[] |
| const char* emoticons[] |
| GC gcs[MAX_WINDOWS] |
The X11 graphics contexts to draw with.
| GC gcs_warning[MAX_WINDOWS] |
The X11 graphics contexts to draw warnings with.
| int have_switch_user_command |
If set, we can start a new login session.
| int have_xkb_ext |
| char hostname[256] |
The local hostname.
| const char* kaomoji[] |
| Window main_window |
The X11 window provided by main. Provided from $XSCREENSAVER_WINDOW.
| size_t num_windows = 0 |
The number of active X11 per-monitor windows.
| Window parent_window |
main_window's parent. Used to create per-monitor siblings.
| enum PasswordPrompt password_prompt |
| const char* PasswordPromptStrings[] |
| int per_monitor_windows_dirty = 1 |
If set, we need to re-query monitor data and adjust windows.
| int prompt_timeout |
The maximum time to wait at a prompt for user input in seconds.
| int show_datetime |
If set, data and time will be shown.
| int show_hostname |
If set, the prompt will be fixed by <hostname>. If >1, the hostname will be.
| int show_username |
If set, the prompt will be fixed by <username>.
|
static |
Whether we only want a single auth window.
| int sounds[][2] |
| char username[256] |
The username to authenticate as.
| Window windows[MAX_WINDOWS] |
The X11 per-monitor windows to draw on.
|
static |
The x offset to apply to the entire display (to mitigate burn-in).
| XColor xcolor_background |
The background color.
| XColor xcolor_foreground |
The foreground color.
| XColor xcolor_warning |
The warning color (used as foreground).
|
static |
The y offset to apply to the entire display (to mitigate burn-in).
1.8.14