xsecurelock  1.7.0
XSecureLock is an X11 screen lock utility.
Functions | Variables
auth_child.c File Reference
#include "auth_child.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "env_settings.h"
#include "logging.h"
#include "wait_pgrp.h"
#include "xscreensaver_api.h"

Functions

void KillAuthChildSigHandler (int signo)
 Kill the auth child. More...
 
static int DiscardFirstKeypress ()
 Return whether the wake-up keypress should be discarded and not be sent to the auth child. More...
 
int WantAuthChild (int force_auth)
 Checks whether an auth child should be running. More...
 
static int ContainsNonControl (const char *buf)
 Return whether buf contains exclusively control characters. More...
 
int WatchAuthChild (Window w, const char *executable, int force_auth, const char *stdinbuf, int *auth_running)
 Starts or stops the authentication child process. More...
 

Variables

static pid_t auth_child_pid = 0
 The PID of a currently running saver child, or 0 if none is running. More...
 
static int auth_child_fd = 0
 If auth_child_pid != 0, the FD which connects to stdin of the auth child. More...
 

Function Documentation

◆ ContainsNonControl()

static int ContainsNonControl ( const char *  buf)
static

Return whether buf contains exclusively control characters.

Because there is no portable way of doing this (other than relying on wchar routines that are nowhere else exercised in the main program), I'll just match precisely those that ASCII defines as control codes - 00 to 1f as well as 7f (DEL).

We do this so we do not forward control keys to the auth child when just waking it up (e.g. because the user tried to unlock the screen with ESC or ENTER).

Parameters
bufThe string to check.
Returns
1 if buf contains at least one non-control character, and 0 otherwise.

◆ DiscardFirstKeypress()

static int DiscardFirstKeypress ( )
static

Return whether the wake-up keypress should be discarded and not be sent to the auth child.

Sending the wake-up keypress to the auth child is usually a bad idea because many people use "any" key, not their password's, to wake up the screen saver. Also, when using a blanking screen saver, one can't easily distinguish a locked screen from a turned-off screen, and may thus accidentally start entering the password into a web browser or similar "bad" place.

However, it was requested by a user, so why not add it. Usage:

XSECURELOCK_DISCARD_FIRST_KEYPRESS=0 xsecurelock

◆ KillAuthChildSigHandler()

void KillAuthChildSigHandler ( int  signo)

Kill the auth child.

This can be used from a signal handler.

◆ WantAuthChild()

int WantAuthChild ( int  force_auth)

Checks whether an auth child should be running.

Parameters
force_authIf true, assume we want to start a new auth child.
Returns
true if an auth child is expected to be running after a call to WatchAuthChild() with this force_auth parameter.

◆ WatchAuthChild()

int WatchAuthChild ( Window  w,
const char *  executable,
int  force_auth,
const char *  stdinbuf,
int *  auth_running 
)

Starts or stops the authentication child process.

Parameters
wThe screen saver window. Will get cleared after auth child execution.
executableWhat binary to spawn for authentication. No arguments will be passed.
force_authIf true, the auth child will be spawned if not already running.
stdinbufIf non-NULL, this data will be sent to stdin of the auth child.
auth_runningWill be set to the status of the current auth child (i.e. true iff it is running).
Returns
true if authentication was successful, i.e. if the auth child exited with status zero.

Variable Documentation

◆ auth_child_fd

int auth_child_fd = 0
static

If auth_child_pid != 0, the FD which connects to stdin of the auth child.

◆ auth_child_pid

pid_t auth_child_pid = 0
static

The PID of a currently running saver child, or 0 if none is running.