projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Keep clang-format happy
[collectd.git]
/
src
/
libcollectdclient
/
network_parse.c
diff --git
a/src/libcollectdclient/network_parse.c
b/src/libcollectdclient/network_parse.c
index
02e14b9
..
9a90f8e
100644
(file)
--- a/
src/libcollectdclient/network_parse.c
+++ b/
src/libcollectdclient/network_parse.c
@@
-23,9
+23,7
@@
* Florian octo Forster <octo at collectd.org>
**/
* Florian octo Forster <octo at collectd.org>
**/
-#if HAVE_CONFIG_H
#include "config.h"
#include "config.h"
-#endif
#if !defined(__GNUC__) || !__GNUC__
#define __attribute__(x) /**/
#if !defined(__GNUC__) || !__GNUC__
#define __attribute__(x) /**/
@@
-37,29
+35,38
@@
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
/* for be{16,64}toh */
#if HAVE_ENDIAN_H
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
/* for be{16,64}toh */
#if HAVE_ENDIAN_H
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
+#else /* fallback */
+#include "stdendian.h"
#endif
#endif
+#if HAVE_GCRYPT_H
#define GCRYPT_NO_DEPRECATED
#include <gcrypt.h>
#define GCRYPT_NO_DEPRECATED
#include <gcrypt.h>
+#endif
#include <stdio.h>
#define DEBUG(...) printf(__VA_ARGS__)
#include <stdio.h>
#define DEBUG(...) printf(__VA_ARGS__)
+#if HAVE_GCRYPT_H
#if GCRYPT_VERSION_NUMBER < 0x010600
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
#if GCRYPT_VERSION_NUMBER < 0x010600
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
+#endif
/* forward declaration because parse_sign_sha256()/parse_encrypt_aes256() and
* network_parse() need to call each other. */
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
lcc_network_parse_options_t const *opts);
/* forward declaration because parse_sign_sha256()/parse_encrypt_aes256() and
* network_parse() need to call each other. */
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
lcc_network_parse_options_t const *opts);
+#if HAVE_GCRYPT_H
static int init_gcrypt() {
/* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
* Because you can't know in a library whether another library has
static int init_gcrypt() {
/* http://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html
* Because you can't know in a library whether another library has
@@
-89,6
+96,7
@@
static int init_gcrypt() {
gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
return 0;
}
gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
return 0;
}
+#endif
typedef struct {
uint8_t *data;
typedef struct {
uint8_t *data;
@@
-296,8
+304,6
@@
static int parse_values(void *payload, size_t payload_size,
state->values = calloc(sizeof(*state->values), state->values_len);
state->values_types = calloc(sizeof(*state->values_types), state->values_len);
if ((state->values == NULL) || (state->values_types == NULL)) {
state->values = calloc(sizeof(*state->values), state->values_len);
state->values_types = calloc(sizeof(*state->values_types), state->values_len);
if ((state->values == NULL) || (state->values_types == NULL)) {
- free(state->values);
- free(state->values_types);
return ENOMEM;
}
return ENOMEM;
}
@@
-341,6
+347,7
@@
static int parse_values(void *payload, size_t payload_size,
return 0;
}
return 0;
}
+#if HAVE_GCRYPT_H
static int verify_sha256(void *payload, size_t payload_size,
char const *username, char const *password,
uint8_t hash_provided[32]) {
static int verify_sha256(void *payload, size_t payload_size,
char const *username, char const *password,
uint8_t hash_provided[32]) {
@@
-373,6
+380,13
@@
static int verify_sha256(void *payload, size_t payload_size,
return !!ret;
}
return !!ret;
}
+#else /* !HAVE_GCRYPT_H */
+static int verify_sha256(void *payload, size_t payload_size,
+ char const *username, char const *password,
+ uint8_t hash_provided[32]) {
+ return ENOTSUP;
+}
+#endif
static int parse_sign_sha256(void *signature, size_t signature_len,
void *payload, size_t payload_size,
static int parse_sign_sha256(void *signature, size_t signature_len,
void *payload, size_t payload_size,
@@
-408,6
+422,7
@@
static int parse_sign_sha256(void *signature, size_t signature_len,
return network_parse(payload, payload_size, SIGN, opts);
}
return network_parse(payload, payload_size, SIGN, opts);
}
+#if HAVE_GCRYPT_H
static int decrypt_aes256(buffer_t *b, void *iv, size_t iv_size,
char const *password) {
gcry_cipher_hd_t cipher = NULL;
static int decrypt_aes256(buffer_t *b, void *iv, size_t iv_size,
char const *password) {
gcry_cipher_hd_t cipher = NULL;
@@
-480,6
+495,12
@@
static int parse_encrypt_aes256(void *data, size_t data_size,
return network_parse(b->data, b->len, ENCRYPT, opts);
}
return network_parse(b->data, b->len, ENCRYPT, opts);
}
+#else /* !HAVE_GCRYPT_H */
+static int parse_encrypt_aes256(void *data, size_t data_size,
+ lcc_network_parse_options_t const *opts) {
+ return ENOTSUP;
+}
+#endif
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
lcc_network_parse_options_t const *opts) {
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
lcc_network_parse_options_t const *opts) {
@@
-535,6
+556,8
@@
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
case TYPE_VALUES: {
lcc_value_list_t vl = state;
if (parse_values(payload, sizeof(payload), &vl)) {
case TYPE_VALUES: {
lcc_value_list_t vl = state;
if (parse_values(payload, sizeof(payload), &vl)) {
+ free(vl.values);
+ free(vl.values_types);
DEBUG("lcc_network_parse(): parse_values failed.\n");
return EINVAL;
}
DEBUG("lcc_network_parse(): parse_values failed.\n");
return EINVAL;
}
@@
-588,10
+611,14
@@
static int network_parse(void *data, size_t data_size, lcc_security_level_t sl,
int lcc_network_parse(void *data, size_t data_size,
lcc_network_parse_options_t opts) {
if (opts.password_lookup) {
int lcc_network_parse(void *data, size_t data_size,
lcc_network_parse_options_t opts) {
if (opts.password_lookup) {
+#if HAVE_GCRYPT_H
int status;
if ((status = init_gcrypt())) {
return status;
}
int status;
if ((status = init_gcrypt())) {
return status;
}
+#else
+ return ENOTSUP;
+#endif
}
return network_parse(data, data_size, NONE, &opts);
}
return network_parse(data, data_size, NONE, &opts);