OpenDNSSEC-libhsm  2.1.7
Data Structures | Macros | Functions | Variables
pin.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <errno.h>
#include "libhsm.h"

Go to the source code of this file.

Data Structures

union  semun
 

Macros

#define SHM_KEY   (key_t)0x0d50d5ec
 
#define SEM_KEY   (key_t)0x0d50d5ec
 
#define SHM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
 
#define SEM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
 

Functions

void hsm_ctx_set_error (hsm_ctx_t *ctx, int error, const char *action, const char *message,...)
 
char * hsm_prompt_pin (unsigned int id, const char *repository, unsigned int mode)
 
char * hsm_check_pin (unsigned int id, const char *repository, unsigned int mode)
 
int hsm_logout_pin ()
 

Variables

hsm_ctx_t_hsm_ctx
 

Macro Definition Documentation

◆ SEM_KEY

#define SEM_KEY   (key_t)0x0d50d5ec

Definition at line 53 of file pin.c.

◆ SEM_PERM

#define SEM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 55 of file pin.c.

◆ SHM_KEY

#define SHM_KEY   (key_t)0x0d50d5ec

Definition at line 52 of file pin.c.

◆ SHM_PERM

#define SHM_PERM   S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 54 of file pin.c.

Function Documentation

◆ hsm_check_pin()

char* hsm_check_pin ( unsigned int  id,
const char *  repository,
unsigned int  mode 
)

Function that will check if there is a PIN in the shared memory and returns it.

Parameters
idUsed for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
repositoryThe repository name will be included in the prompt
modeThe type of mode the function should run in.
Returns
The string the user enters

Definition at line 325 of file pin.c.

References HSM_MAX_PIN_LENGTH, HSM_MAX_SESSIONS, HSM_PIN_FIRST, HSM_PIN_RETRY, and HSM_PIN_SAVE.

◆ hsm_ctx_set_error()

void hsm_ctx_set_error ( hsm_ctx_t ctx,
int  error,
const char *  action,
const char *  message,
  ... 
)

Set HSM Context Error

If the ctx is given, and it's error value is still 0, the value will be set to 'error', and the error_message and error_action will be set to the given strings.

Parameters
ctxHSM context
errorerror code
actionaction for which the error occured
messageerror message format string

Definition at line 207 of file libhsm.c.

References ctx, hsm_ctx_t::error, hsm_ctx_t::error_action, and hsm_ctx_t::error_message.

Referenced by hsm_get_dnskey(), hsm_logout_pin(), and hsm_token_attached().

◆ hsm_logout_pin()

int hsm_logout_pin ( void  )

Logout

Function that will logout the user by deleting the shared memory and semaphore. Any authenticated process will still be able to interact with the HSM.

Definition at line 413 of file pin.c.

References _hsm_ctx, hsm_ctx_set_error(), HSM_ERROR, HSM_OK, SEM_KEY, SHM_KEY, and semun::val.

◆ hsm_prompt_pin()

char* hsm_prompt_pin ( unsigned int  id,
const char *  repository,
unsigned int  mode 
)

Function that queries for a PIN, can be used as callback for hsm_open(). Stores the PIN in the shared memory.

Parameters
idUsed for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
repositoryThe repository name will be included in the prompt
modeThe type of mode the function should run in.
Returns
The string the user enters

Definition at line 228 of file pin.c.

References HSM_MAX_PIN_LENGTH, HSM_MAX_SESSIONS, HSM_PIN_FIRST, HSM_PIN_RETRY, and HSM_PIN_SAVE.

Variable Documentation

◆ _hsm_ctx

hsm_ctx_t* _hsm_ctx

Global (initial) context

Global (initial) context, with mutex to serialize access to it

Definition at line 57 of file libhsm.c.

Referenced by hsm_check_context(), hsm_close(), hsm_get_error(), hsm_logout_pin(), and hsm_open2().