aboutsummaryrefslogtreecommitdiff
path: root/src/auth.h
blob: ad09236fa82e7213846753d606688dc3cc62dbe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * auth.h
 *
 * Handles all authentication events via PAM
 * Created by buzzert <buzzert@buzzert.net> 2019-01-19
 */

#pragma once

#define MAX_RESPONSE_SIZE 128

typedef struct {
    char  response_buffer[MAX_RESPONSE_SIZE];
    int   response_code;
} auth_prompt_response_t;

// NOTE: These callbacks are called on a separate thread
typedef void(*ShowInfo)(const char *info_msg, void *context);
typedef void(*ShowError)(const char *error_msg, void *context);
typedef void(*PromptUser)(const char *prompt, void *context);
typedef void(*AuthenticationResult)(int result, void *context);

typedef struct {
    ShowInfo             info_handler;
    ShowError            error_handler;
    PromptUser           prompt_handler;
    AuthenticationResult result_handler;
} auth_callbacks_t;

struct auth_handle_t;

// Starts an authentication thread and returns immediately
struct auth_handle_t* auth_begin_authentication(auth_callbacks_t callbacks, void *context);

// Perform an authentication attempt
void auth_attempt_authentication(struct auth_handle_t *handle, auth_prompt_response_t response);