]>
Commit | Line | Data |
---|---|---|
18f8bd28 CP |
1 | /* |
2 | nterface library functions | |
3 | Copyright (C) 2003-2004 Chris Porter. | |
4 | */ | |
5 | ||
6 | #ifndef __nterface_library_H | |
7 | #define __nterface_library_H | |
8 | ||
9 | #include "../core/error.h" | |
5ab07198 | 10 | #include "../core/nsmalloc.h" |
18f8bd28 | 11 | |
1ac1d43c CP |
12 | #include "../lib/sha2.h" |
13 | ||
18f8bd28 CP |
14 | #define RE_OK 0x00 |
15 | #define RE_MEM_ERROR 0x01 | |
16 | #define RE_BAD_LINE 0x02 | |
17 | #define RE_REQUEST_REJECTED 0x03 | |
18 | #define RE_SERVICE_NOT_FOUND 0x04 | |
19 | #define RE_CONNECTION_CLOSED 0x05 | |
20 | #define RE_TRANSPORT_NOT_FOUND 0x06 | |
21 | #define RE_COMMAND_NOT_FOUND 0x07 | |
22 | #define RE_WRONG_ARG_COUNT 0x08 | |
23 | #define RE_TOO_MANY_ARGS 0x09 | |
24 | #define RE_SERVICER_NOT_FOUND 0x0A | |
5757e1ef | 25 | #define RE_SOCKET_ERROR 0x0B |
18f8bd28 CP |
26 | |
27 | #define snc(err, f) strncpy(err, f, sizeof(err) - 1) | |
28 | #define TwentyByteHex(output, buf) snprintf(output, sizeof(output), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]); | |
1ac1d43c CP |
29 | #define SixteenByteHex(output, buf) snprintf(output, sizeof(output), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); |
30 | #define ThirtyTwoByteHex(output, buf) snprintf(output, sizeof(output), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19], buf[20], buf[21], buf[22], buf[23], buf[24], buf[25], buf[26], buf[27], buf[28], buf[29], buf[30], buf[31]); | |
18f8bd28 CP |
31 | |
32 | #define MemError() Error("nterface", ERR_FATAL, "Memory allocation error, file: %s line: %d", __FILE__, __LINE__); | |
33 | ||
1ac1d43c | 34 | #define RANDOM_LOCATION "/dev/urandom" |
18f8bd28 CP |
35 | |
36 | #define MemCheck(x) \ | |
37 | if(!x) { \ | |
38 | MemError(); \ | |
39 | return; \ | |
40 | } | |
41 | ||
42 | #define MemCheckR(x, y) \ | |
43 | if(!x) { \ | |
44 | MemError(); \ | |
45 | return y; \ | |
46 | } | |
47 | ||
48 | int getcopyconfigitemint(char *section, char *key, int def, int *value); | |
49 | int getcopyconfigitemintpositive(char *section, char *key, int def); | |
50 | int protected_atoi(char *buf, int *value); | |
51 | int positive_atoi(char *data); | |
52 | char *challenge_response(char *challenge, char *password); | |
18f8bd28 | 53 | char *request_error(int errn); |
1ac1d43c | 54 | int get_entropy(unsigned char *data, int bytes); |
18f8bd28 CP |
55 | int generate_nonce(unsigned char *nonce, int nterfacer); |
56 | char *int_to_hex(unsigned char *input, char *buf, int len); | |
57 | int hex_to_int(char *input, unsigned char *buf, int buflen); | |
58 | ||
5ab07198 CP |
59 | #define ntmalloc(x) nsmalloc(POOL_NTERFACER, x) |
60 | #define ntfree(x) nsfree(POOL_NTERFACER, x) | |
61 | #define ntrealloc(x, y) nsrealloc(POOL_NTERFACER, x, y) | |
62 | ||
18f8bd28 | 63 | #endif |