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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/**
** Provide HAVEGE socket communication API
**
** Copyright 2018-2021 Jirka Hladky hladky DOT jiri AT gmail DOT com
** Copyright 2018 Werner Fink <werner@suse.de>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
*/
#ifndef HAVEGECMD_H
#define HAVEGECMD_H
#ifdef __cplusplus
extern "C" {
#endif
#include "havege.h"
#include "haveged.h"
#include <sys/types.h>
#include <sys/socket.h>
#define HAVEGED_SOCKET_PATH "\0/sys/entropy/haveged"
#define MAGIC_CHROOT 'R'
#define MAGIC_CLOSE 'X'
#define MAGIC_PATH 'P'
#define ASCII_ACK "\x6" /* ASCII acknowledge */
#define ASCII_NAK "\x15" /* ASCII negative acknowledge */
#define ASCII_STX "\x2" /* ASCII start of text */
#ifndef SOCK_CLOEXEC
#define SOCK_CLOEXEC 0
#endif
#ifndef SOCK_NONBLOCK
#define SOCK_NONBLOCK 0
#endif
/**
* Open and listen on a UNIX socket to get command from there
*/
int cmd_listen(struct pparams *);
/**
* Open and connect on a UNIX socket to send command over this
*/
int cmd_connect(struct pparams *);
/**
* Handle arguments in command mode
*/
int getcmd(char *);
/**
* Handle incomming messages from socket
*/
int socket_handler(int, const volatile char *, char *const [], struct pparams *);
/**
* Receive incomming messages from socket
*/
ssize_t safein(int, void *, size_t);
/**
* Send outgoing messages to socket
*/
void safeout(int, const void *, size_t);
/**
* Send outgoing unsigned integer to socket
*/
void send_uinteger(int, uint32_t);
/**
* Receive incomming unsigned integer from socket
*/
int receive_uinteger(int, uint32_t *);
/**
* Socket file descriptor used for communication
*/
extern int socket_fd;
extern int first_byte;
#ifdef __cplusplus
}
#endif
#endif
|