xsecurelock  1.7.0
XSecureLock is an X11 screen lock utility.
Macros | Enumerations | Functions | Variables
auth_x11.c File Reference
#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]
 

Macro Definition Documentation

◆ BLINK_INTERVAL

#define BLINK_INTERVAL   (250 * 1000)

The blinking interval in microseconds.

◆ DISCO_PASSWORD_DANCERS

#define DISCO_PASSWORD_DANCERS   5

Number of dancers in the disco password display.

◆ DISPLAYBUF_SIZE

#define DISPLAYBUF_SIZE   (PWBUF_SIZE + 2)

The size of the buffer to use for display, with space for cursor and NUL.

◆ LINE_SPACING

#define LINE_SPACING   4

Draw border rectangle (mainly for debugging).

Extra line spacing.

◆ MAIN_WINDOW

#define MAIN_WINDOW   0

◆ MAX_WINDOWS

#define MAX_WINDOWS   16

◆ NOTE_A3

#define NOTE_A3   220

◆ NOTE_B4

#define NOTE_B4   494

◆ NOTE_DS3

#define NOTE_DS3   156

◆ NOTE_DS4

#define NOTE_DS4   311

◆ NOTE_E4

#define NOTE_E4   330

◆ NOTE_E5

#define NOTE_E5   659

◆ PARANOID_PASSWORD_LENGTH

#define PARANOID_PASSWORD_LENGTH   (1 << DISCO_PASSWORD_DANCERS)

Length of the "paranoid password display".

◆ PARANOID_PASSWORD_MIN_CHANGE

#define PARANOID_PASSWORD_MIN_CHANGE   4

Minimum distance the cursor shall move on keypress.

◆ PWBUF_SIZE

#define PWBUF_SIZE   256

The size of the buffer to store the password in. Not NUL terminated.

◆ SOUND_SLEEP_MS

#define SOUND_SLEEP_MS   125

◆ SOUND_TONE_MS

#define SOUND_TONE_MS   100

◆ STATIC_ASSERT

#define STATIC_ASSERT (   state,
  message 
)    extern int statically_asserted(int assertion[(state) ? 1 : -1]);

◆ WINDOW_BORDER

#define WINDOW_BORDER   16

Border of the window around the text.

Enumeration Type Documentation

◆ PasswordPrompt

Actual password prompt selected.

Enumerator
PASSWORD_PROMPT_CURSOR 
PASSWORD_PROMPT_ASTERISKS 
PASSWORD_PROMPT_HIDDEN 
PASSWORD_PROMPT_DISCO 
PASSWORD_PROMPT_EMOJI 
PASSWORD_PROMPT_EMOTICON 
PASSWORD_PROMPT_KAOMOJI 
PASSWORD_PROMPT_COUNT 

◆ Sound

enum Sound
Enumerator
SOUND_PROMPT 
SOUND_INFO 
SOUND_ERROR 
SOUND_SUCCESS 

Function Documentation

◆ Authenticate()

int Authenticate ( )

Perform authentication using a helper proxy.

Returns
The authentication status (0 for OK, 1 otherwise).

◆ BuildTitle()

void BuildTitle ( char *  output,
size_t  output_size,
const char *  input 
)

◆ BumpDisplayMarker()

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.

Parameters
pwlenThe current password length.
posThe initial cursor position; will get updated.
last_keystrokeThe time of last keystroke; will get updated.

◆ CreateOrUpdatePerMonitorWindow()

void CreateOrUpdatePerMonitorWindow ( size_t  i,
const Monitor monitor,
int  region_w,
int  region_h,
int  x_offset,
int  y_offset 
)

◆ DestroyPerMonitorWindows()

void DestroyPerMonitorWindows ( size_t  keep_windows)

◆ DisplayMessage()

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.

Parameters
titleThe title of the message.
strThe message itself.
is_warningWhether to use the warning style to display the message.

◆ DrawString()

void DrawString ( int  monitor,
int  x,
int  y,
int  is_warning,
const char *  string,
int  len 
)

◆ GetIndicators()

const char* GetIndicators ( int *  warning,
int *  have_multiple_layouts 
)

Check which modifiers are active.

Parameters
warningWill be set to 1 if something's "bad" with the keyboard layout (e.g. Caps Lock).
have_multiple_layoutsWill be set to 1 if more than one keyboard layout is available for switching.
Returns
The current modifier mask as a string.

◆ GetPasswordPromptFromFlags()

enum PasswordPrompt GetPasswordPromptFromFlags ( int  paranoid_password_flag,
const char *  password_prompt_flag 
)

◆ main()

int main ( int  argc_local,
char **  argv_local 
)

The main program.

Usage: XSCREENSAVER_WINDOW=window_id ./auth_x11; status=$?

Returns
0 if authentication successful, anything else otherwise.

Deprecated flag for setting whether password display should hide the length.
Updated flag for password display choice

◆ PlaySound()

void PlaySound ( enum Sound  snd)

Play a sound sequence.

◆ Prompt()

int Prompt ( const char *  msg,
char **  response,
int  echo 
)

Ask a question to the user.

Parameters
msgThe message.
responseThe response will be stored in a newly allocated buffer here. The caller is supposed to eventually free() it.
echoIf true, the input will be shown; otherwise it will be hidden (password entry).
Returns
1 if successful, anything else otherwise.

◆ ShowFromArray()

void ShowFromArray ( const char **  array,
size_t  displaymarker,
char *  displaybuf,
size_t  displaybufsize,
size_t *  displaylen 
)

◆ STATIC_ASSERT() [1/3]

STATIC_ASSERT ( sizeof(emoji)/sizeof *  emoji = =PARANOID_PASSWORD_LENGTH,
"Emoji array size must be equal to PARANOID_PASSWORD_LENGTH  
)

◆ STATIC_ASSERT() [2/3]

STATIC_ASSERT ( sizeof(emoticons)/sizeof *  emoticons = =PARANOID_PASSWORD_LENGTH,
"Emoticons array size must be equal to PARANOID_PASSWORD_LENGTH  
)

◆ STATIC_ASSERT() [3/3]

STATIC_ASSERT ( sizeof(kaomoji)/sizeof *  kaomoji = =PARANOID_PASSWORD_LENGTH,
"Kaomoji array size must be equal to PARANOID_PASSWORD_LENGTH  
)

◆ StrAppend()

void StrAppend ( char **  output,
size_t *  output_size,
const char *  input,
size_t  input_size 
)

◆ SwitchKeyboardLayout()

void SwitchKeyboardLayout ( void  )

Switch to the next keyboard layout.

◆ TextAscent()

int TextAscent ( void  )

◆ TextDescent()

int TextDescent ( void  )

◆ TextWidth()

int TextWidth ( const char *  string,
int  len 
)

◆ UpdatePerMonitorWindows()

void UpdatePerMonitorWindows ( int  monitors_changed,
int  region_w,
int  region_h,
int  x_offset,
int  y_offset 
)

◆ WaitForKeypress()

void WaitForKeypress ( int  seconds)

Variable Documentation

◆ argc

int argc

Number of args.

◆ argv

char* const* argv

Args.

◆ auth_cursor_blink

int auth_cursor_blink = 1
static

Whether to blink the cursor in the auth dialog.

◆ auth_sounds

int auth_sounds = 0
static

Whether to play sounds during authentication.

◆ authproto_executable

const char* authproto_executable

The authproto helper to use.

◆ burnin_mitigation_max_offset

int burnin_mitigation_max_offset = 0
static

Maximum offset value when dynamic changes are enabled.

◆ burnin_mitigation_max_offset_change

int burnin_mitigation_max_offset_change = 0
static

How much the offsets are allowed to change dynamically, and if so, how high.

◆ core_font

XFontStruct* core_font

The X11 core font for the PAM messages.

◆ cursor

const char cursor[] = "_"
static

The cursor character displayed at the end of the masked password input.

◆ datetime_format

const char* datetime_format = "%c"

The date format to display.

◆ disco_combiner

const char* disco_combiner = " ♪ "

◆ disco_dancers

const char* disco_dancers[]
Initial value:
= {
"┏(・o・)┛",
"┗(・o・)┓",
}

◆ display

Display* display

The X11 display.

◆ emoji

const char* emoji[]
Initial value:
= {
"_____", "😂", "❤", "♻", "😍", "♥", "😭", "😊", "😒", "💕", "😘",
"😩", "☺", "👌", "😔", "😁", "😏", "😉", "👍", "⬅", "😅", "🙏",
"😌", "😢", "👀", "💔", "😎", "🎶", "💙", "💜", "🙌", "😳",
}

◆ emoticons

const char* emoticons[]
Initial value:
= {
":-)", ":-p", ":-O", ":-\\", "(-:", "d-:", "O-:", "/-:",
"8-)", "8-p", "8-O", "8-\\", "(-8", "d-8", "O-8", "/-8",
"X-)", "X-p", "X-O", "X-\\", "(-X", "d-X", "O-X", "/-X",
":'-)", ":-S", ":-D", ":-#", "(-':", "S-:", "D-:", "#-:",
}

◆ gcs

GC gcs[MAX_WINDOWS]

The X11 graphics contexts to draw with.

◆ gcs_warning

GC gcs_warning[MAX_WINDOWS]

The X11 graphics contexts to draw warnings with.

◆ have_switch_user_command

int have_switch_user_command

If set, we can start a new login session.

◆ have_xkb_ext

int have_xkb_ext

◆ hostname

char hostname[256]

The local hostname.

◆ kaomoji

const char* kaomoji[]
Initial value:
= {
"(͡°͜ʖ͡°)", "(>_<)", "O_ם", "(^_-)", "o_0",
"o.O", "0_o", "O.o", "(°o°)", "^m^",
"^_^", "((d[-_-]b))", "┏(・o・)┛", "┗(・o・)┓", "(゚Д゚)",
"(°◇°)", "\\o/", "\\o|", "|o/", "|o|",
"(●^o^●)", "(^v^)", "(^u^)", "(^◇^)", "¯\\_(ツ)_/¯",
"(^0_0^)", "(☞゚∀゚)☞", "(-■_■)", "(┛ಠ_ಠ)┛彡┻━┻", "┬─┬ノ(º_ºノ)",
"(˘³˘)♥", "❤(◍•ᴗ•◍)",
}

◆ main_window

Window main_window

The X11 window provided by main. Provided from $XSCREENSAVER_WINDOW.

◆ num_windows

size_t num_windows = 0

The number of active X11 per-monitor windows.

◆ parent_window

Window parent_window

main_window's parent. Used to create per-monitor siblings.

◆ password_prompt

enum PasswordPrompt password_prompt

◆ PasswordPromptStrings

const char* PasswordPromptStrings[]
Initial value:
= {
"cursor",
"asterisks",
"hidden",
"disco",
"emoji",
"emoticon",
"kaomoji",
}

◆ per_monitor_windows_dirty

int per_monitor_windows_dirty = 1

If set, we need to re-query monitor data and adjust windows.

◆ prompt_timeout

int prompt_timeout

The maximum time to wait at a prompt for user input in seconds.

◆ show_datetime

int show_datetime

If set, data and time will be shown.

◆ show_hostname

int show_hostname

If set, the prompt will be fixed by <hostname>. If >1, the hostname will be.

◆ show_username

int show_username

If set, the prompt will be fixed by <username>.

◆ single_auth_window

int single_auth_window = 0
static

Whether we only want a single auth window.

◆ sounds

int sounds[][2]
Initial value:
= {
}
#define NOTE_B4
Definition: auth_x11.c:287
#define NOTE_DS4
Definition: auth_x11.c:285
#define NOTE_A3
Definition: auth_x11.c:284
#define NOTE_E5
Definition: auth_x11.c:288
#define NOTE_DS3
Definition: auth_x11.c:283
#define NOTE_E4
Definition: auth_x11.c:286

◆ username

char username[256]

The username to authenticate as.

◆ windows

Window windows[MAX_WINDOWS]

The X11 per-monitor windows to draw on.

◆ x_offset

int x_offset = 0
static

The x offset to apply to the entire display (to mitigate burn-in).

◆ xcolor_background

XColor xcolor_background

The background color.

◆ xcolor_foreground

XColor xcolor_foreground

The foreground color.

◆ xcolor_warning

XColor xcolor_warning

The warning color (used as foreground).

◆ y_offset

int y_offset = 0
static

The y offset to apply to the entire display (to mitigate burn-in).