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 52 of file pin.c.

Referenced by hsm_logout_pin().

## SEM_PERM

#define SEM_PERM S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 54 of file pin.c.

## SHM_KEY

#define SHM_KEY (key_t)0x0d50d5ec

Definition at line 51 of file pin.c.

Referenced by hsm_logout_pin().

## SHM_PERM

#define SHM_PERM S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP

Definition at line 53 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

  id | Used for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
  repository | The repository name will be included in the prompt
  mode | The 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

  ctx | HSM context
  error | error code
  action | action for which the error occured
  message | error message format string

Definition at line 206 of file libhsm.c.

References 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_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

  id | Used for identifying the repository. Will have a value between zero and HSM_MAX_SESSIONS.
  repository | The repository name will be included in the prompt
  mode | The 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 56 of file libhsm.c.

Referenced by hsm_check_context(), and hsm_get_error().