[PATCH 01/20] dbus: Add _dbus1_message_iter_skip_entry and gvariant variant
by Andrew Zaborowski
This will be used for the get_nth_string_argument function in
dbus-message.c. There seems to be no other way to skip over an iterator
entry without knowing the data type.
---
ell/dbus-private.h | 1 +
ell/dbus-util.c | 16 ++++++++++++++++
ell/gvariant-private.h | 1 +
ell/gvariant-util.c | 10 ++++++++++
4 files changed, 28 insertions(+)
diff --git a/ell/dbus-private.h b/ell/dbus-private.h
index 8322475..cfed4f7 100644
--- a/ell/dbus-private.h
+++ b/ell/dbus-private.h
@@ -77,6 +77,7 @@ bool _dbus1_iter_enter_variant(struct l_dbus_message_iter *iter,
struct l_dbus_message_iter *variant);
bool _dbus1_iter_enter_array(struct l_dbus_message_iter *iter,
struct l_dbus_message_iter *array);
+bool _dbus1_iter_skip_entry(struct l_dbus_message_iter *iter);
struct dbus_builder *_dbus1_builder_new(void *body, size_t body_size);
void _dbus1_builder_free(struct dbus_builder *builder);
diff --git a/ell/dbus-util.c b/ell/dbus-util.c
index 5ab4298..9d5b5af 100644
--- a/ell/dbus-util.c
+++ b/ell/dbus-util.c
@@ -805,6 +805,22 @@ bool _dbus1_iter_enter_array(struct l_dbus_message_iter *iter,
return true;
}
+bool _dbus1_iter_skip_entry(struct l_dbus_message_iter *iter)
+{
+ size_t len;
+ const char *sig_end;
+
+ sig_end = calc_len_next_item(iter->sig_start + iter->sig_pos,
+ iter->data, iter->pos, iter->len, &len);
+ if (!sig_end)
+ return false;
+
+ iter->pos += len;
+ iter->sig_pos = sig_end - iter->sig_start;
+
+ return true;
+}
+
struct dbus_builder {
struct l_string *signature;
void *body;
diff --git a/ell/gvariant-private.h b/ell/gvariant-private.h
index 1acac74..2a20feb 100644
--- a/ell/gvariant-private.h
+++ b/ell/gvariant-private.h
@@ -35,6 +35,7 @@ bool _gvariant_iter_enter_variant(struct l_dbus_message_iter *iter,
struct l_dbus_message_iter *variant);
bool _gvariant_iter_enter_array(struct l_dbus_message_iter *iter,
struct l_dbus_message_iter *array);
+bool _gvariant_iter_skip_entry(struct l_dbus_message_iter *iter);
bool _gvariant_valid_signature(const char *sig);
int _gvariant_get_alignment(const char *signature);
diff --git a/ell/gvariant-util.c b/ell/gvariant-util.c
index 7534509..1aaddc3 100644
--- a/ell/gvariant-util.c
+++ b/ell/gvariant-util.c
@@ -731,6 +731,16 @@ bool _gvariant_iter_enter_array(struct l_dbus_message_iter *iter,
start, item_size);
}
+bool _gvariant_iter_skip_entry(struct l_dbus_message_iter *iter)
+{
+ size_t size;
+
+ if (!next_item(iter, &size))
+ return false;
+
+ return true;
+}
+
struct dbus_builder {
struct l_string *signature;
void *body;
--
2.5.0
6 years, 4 months
[PATCH] dbus: free previous sender string in _dbus_message_set_sender
by Andrew Zaborowski
Allow _dbus_message_set_sender and _dbus_message_set_destination to be
called multiple times.
---
ell/dbus-message.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/ell/dbus-message.c b/ell/dbus-message.c
index a123a8a..84d42d4 100644
--- a/ell/dbus-message.c
+++ b/ell/dbus-message.c
@@ -1390,6 +1390,8 @@ void _dbus_message_set_sender(struct l_dbus_message *message,
if (!_dbus_message_is_gvariant(message))
return;
+ l_free(message->sender);
+
message->sender = l_strdup(sender);
message->kdbus_sender = true;
}
@@ -1400,6 +1402,8 @@ void _dbus_message_set_destination(struct l_dbus_message *message,
if (!_dbus_message_is_gvariant(message))
return;
+ l_free(message->destination);
+
message->destination = l_strdup(destination);
message->kdbus_destination = true;
}
--
2.5.0
6 years, 4 months
[PATCH v2] dbus: Change type for pointer / integer cast to fix 32-bit break
by Mat Martineau
Casting void* to uint64_t on 32-bit x86 causes a build error with gcc
5.3.1, so cast to uintptr_t instead.
---
ell/dbus-kernel.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ell/dbus-kernel.c b/ell/dbus-kernel.c
index 6ce3e6f..8e4e552 100644
--- a/ell/dbus-kernel.c
+++ b/ell/dbus-kernel.c
@@ -385,7 +385,7 @@ int _dbus_kernel_send(int fd, size_t bloom_size, uint8_t bloom_n_hash,
header = _dbus_message_get_header(message, &header_size);
item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec);
item->type = KDBUS_ITEM_PAYLOAD_VEC;
- item->vec.address = (uint64_t) header;
+ item->vec.address = (uintptr_t) header;
item->vec.size = header_size;
item = KDBUS_ITEM_NEXT(item);
@@ -393,7 +393,7 @@ int _dbus_kernel_send(int fd, size_t bloom_size, uint8_t bloom_n_hash,
if (body_size > 0) {
item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec);
item->type = KDBUS_ITEM_PAYLOAD_VEC;
- item->vec.address = (uint64_t) body;
+ item->vec.address = (uintptr_t) body;
item->vec.size = body_size;
item = KDBUS_ITEM_NEXT(item);
}
--
2.7.3
6 years, 4 months
[PATCH] dbus: Change type for pointer / integer cast to fix 32-bit break
by Mat Martineau
Casting void* to uint64_t on 32-bit x86 causes a build error with gcc
5.9.1, so cast to uintptr_t instead.
---
ell/dbus-kernel.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ell/dbus-kernel.c b/ell/dbus-kernel.c
index 6ce3e6f..8e4e552 100644
--- a/ell/dbus-kernel.c
+++ b/ell/dbus-kernel.c
@@ -385,7 +385,7 @@ int _dbus_kernel_send(int fd, size_t bloom_size, uint8_t bloom_n_hash,
header = _dbus_message_get_header(message, &header_size);
item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec);
item->type = KDBUS_ITEM_PAYLOAD_VEC;
- item->vec.address = (uint64_t) header;
+ item->vec.address = (uintptr_t) header;
item->vec.size = header_size;
item = KDBUS_ITEM_NEXT(item);
@@ -393,7 +393,7 @@ int _dbus_kernel_send(int fd, size_t bloom_size, uint8_t bloom_n_hash,
if (body_size > 0) {
item->size = KDBUS_ITEM_HEADER_SIZE + sizeof(struct kdbus_vec);
item->type = KDBUS_ITEM_PAYLOAD_VEC;
- item->vec.address = (uint64_t) body;
+ item->vec.address = (uintptr_t) body;
item->vec.size = body_size;
item = KDBUS_ITEM_NEXT(item);
}
--
2.7.3
6 years, 4 months
[PATCH v2 1/2] key: Add basic keystore support
by Mat Martineau
---
Makefile.am | 6 ++-
ell/ell.h | 1 +
ell/key.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ell/key.h | 55 ++++++++++++++++++++++
4 files changed, 214 insertions(+), 2 deletions(-)
create mode 100644 ell/key.c
create mode 100644 ell/key.h
diff --git a/Makefile.am b/Makefile.am
index 55ab8e6..e5a8f94 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,7 +41,8 @@ pkginclude_HEADERS = ell/ell.h \
ell/base64.h \
ell/pem.h \
ell/tls.h \
- ell/uuid.h
+ ell/uuid.h \
+ ell/key.h
lib_LTLIBRARIES = ell/libell.la
@@ -88,7 +89,8 @@ ell_libell_la_SOURCES = $(linux_headers) \
ell/tls-private.h \
ell/tls.c \
ell/tls-record.c \
- ell/uuid.c
+ ell/uuid.c \
+ ell/key.c
ell_libell_la_LDFLAGS = -no-undefined \
-version-info $(ELL_CURRENT):$(ELL_REVISION):$(ELL_AGE)
diff --git a/ell/ell.h b/ell/ell.h
index 8cec756..390743f 100644
--- a/ell/ell.h
+++ b/ell/ell.h
@@ -43,6 +43,7 @@
#include <ell/pem.h>
#include <ell/tls.h>
#include <ell/uuid.h>
+#include <ell/key.h>
#include <ell/netlink.h>
#include <ell/genl.h>
diff --git a/ell/key.c b/ell/key.c
new file mode 100644
index 0000000..6ec8541
--- /dev/null
+++ b/ell/key.c
@@ -0,0 +1,154 @@
+/*
+ *
+ * Embedded Linux library
+ *
+ * Copyright (C) 2016 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/syscall.h>
+#include <linux/keyctl.h>
+
+#include "private.h"
+#include "util.h"
+#include "key.h"
+
+static int32_t keyring_base;
+
+struct l_key {
+ int type;
+ int32_t serial;
+};
+
+static const char * const key_type_names[] = {
+ [L_KEY_RAW] = "user",
+ [L_KEY_ASYMMETRIC] = "asymmetric",
+};
+
+static long kernel_add_key(const char *type, const char *description,
+ const void *payload, size_t len, int32_t keyring)
+{
+ return syscall(__NR_add_key, type, description, payload, len, keyring);
+}
+
+static long kernel_read_key(int32_t serial, const void *payload, size_t len)
+{
+ return syscall(__NR_keyctl, KEYCTL_READ, serial, payload, len);
+}
+
+static long kernel_update_key(int32_t serial, const void *payload, size_t len)
+{
+ return syscall(__NR_keyctl, KEYCTL_UPDATE, serial, payload, len);
+}
+
+static long kernel_revoke_key(int32_t serial)
+{
+ return syscall(__NR_keyctl, KEYCTL_REVOKE, serial);
+}
+
+static bool setup_keyring_base(void)
+{
+ keyring_base = kernel_add_key("keyring", "ell", 0, 0,
+ KEY_SPEC_THREAD_KEYRING);
+
+ if (keyring_base <= 0) {
+ keyring_base = 0;
+ return false;
+ }
+
+ return true;
+}
+
+LIB_EXPORT struct l_key *l_key_new(enum l_key_type type, const void *payload,
+ size_t payload_length)
+{
+ struct l_key *key;
+
+ if (unlikely(!payload))
+ return NULL;
+
+ if (unlikely((size_t)type >= L_ARRAY_SIZE(key_type_names)))
+ return NULL;
+
+ if (!keyring_base && !setup_keyring_base()) {
+ return NULL;
+ }
+
+ key = l_new(struct l_key, 1);
+ key->type = type;
+ key->serial = kernel_add_key(key_type_names[type], "ell", payload,
+ payload_length, keyring_base);
+
+ if (key->serial < 0) {
+ l_free(key);
+ key = NULL;
+ }
+
+ return key;
+}
+
+LIB_EXPORT void l_key_free(struct l_key *key)
+{
+ if (unlikely(!key))
+ return;
+
+ kernel_revoke_key(key->serial);
+
+ l_free(key);
+}
+
+LIB_EXPORT bool l_key_update(struct l_key *key, const void *payload, size_t len)
+{
+ long error;
+
+ if (unlikely(!key))
+ return false;
+
+ error = kernel_update_key(key->serial, payload, len);
+
+ return error == 0;
+}
+
+LIB_EXPORT bool l_key_extract(struct l_key *key, void *payload, size_t *len)
+{
+ long keylen;
+
+ if (unlikely(!key))
+ return false;
+
+ keylen = kernel_read_key(key->serial, payload, *len);
+
+ if (keylen < 0 || (size_t)keylen > *len) {
+ memset(payload, 0, *len);
+ return false;
+ }
+
+ *len = keylen;
+ return true;
+}
+
+LIB_EXPORT ssize_t l_key_get_size(struct l_key *key)
+{
+ return kernel_read_key(key->serial, NULL, 0);
+}
diff --git a/ell/key.h b/ell/key.h
new file mode 100644
index 0000000..73c2c97
--- /dev/null
+++ b/ell/key.h
@@ -0,0 +1,55 @@
+/*
+ *
+ * Embedded Linux library
+ *
+ * Copyright (C) 2016 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __ELL_KEY_H
+#define __ELL_KEY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdbool.h>
+
+struct l_key;
+
+enum l_key_type {
+ L_KEY_RAW = 0,
+ L_KEY_ASYMMETRIC
+};
+
+struct l_key *l_key_new(enum l_key_type type, const void *payload,
+ size_t payload_length);
+
+void l_key_free(struct l_key *key);
+
+bool l_key_update(struct l_key *key, const void *payload, size_t len);
+
+bool l_key_extract(struct l_key *key, void *payload, size_t *len);
+
+ssize_t l_key_get_size(struct l_key *key);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ELL_KEY_H */
--
2.7.2
6 years, 5 months
[PATCH 1/2] key: Add basic keystore support
by Mat Martineau
---
Makefile.am | 6 ++-
ell/ell.h | 1 +
ell/key.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ell/key.h | 58 +++++++++++++++++++++++
4 files changed, 218 insertions(+), 2 deletions(-)
create mode 100644 ell/key.c
create mode 100644 ell/key.h
diff --git a/Makefile.am b/Makefile.am
index 55ab8e6..e5a8f94 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,7 +41,8 @@ pkginclude_HEADERS = ell/ell.h \
ell/base64.h \
ell/pem.h \
ell/tls.h \
- ell/uuid.h
+ ell/uuid.h \
+ ell/key.h
lib_LTLIBRARIES = ell/libell.la
@@ -88,7 +89,8 @@ ell_libell_la_SOURCES = $(linux_headers) \
ell/tls-private.h \
ell/tls.c \
ell/tls-record.c \
- ell/uuid.c
+ ell/uuid.c \
+ ell/key.c
ell_libell_la_LDFLAGS = -no-undefined \
-version-info $(ELL_CURRENT):$(ELL_REVISION):$(ELL_AGE)
diff --git a/ell/ell.h b/ell/ell.h
index 8cec756..390743f 100644
--- a/ell/ell.h
+++ b/ell/ell.h
@@ -43,6 +43,7 @@
#include <ell/pem.h>
#include <ell/tls.h>
#include <ell/uuid.h>
+#include <ell/key.h>
#include <ell/netlink.h>
#include <ell/genl.h>
diff --git a/ell/key.c b/ell/key.c
new file mode 100644
index 0000000..b6a1303
--- /dev/null
+++ b/ell/key.c
@@ -0,0 +1,155 @@
+/*
+ *
+ * Embedded Linux library
+ *
+ * Copyright (C) 2016 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <linux/keyctl.h>
+
+#include "private.h"
+#include "util.h"
+#include "key.h"
+
+//DEBUG
+#include <stdio.h>
+
+#define is_valid_type(type) ((type) <= L_KEY_DH_PRIVATE)
+
+static int keyring_base;
+
+struct l_key {
+ int type;
+ long serial;
+};
+
+static long kernel_add_key(char *type, char *description,
+ const void *payload, size_t len, long keyring)
+{
+ return syscall(__NR_add_key, type, description, payload, len, keyring);
+}
+
+static long kernel_read_key(long serial, const void *payload, size_t len)
+{
+ return syscall(__NR_keyctl, KEYCTL_READ, serial, payload, len);
+}
+
+static long kernel_update_key(long serial, const void *payload, size_t len)
+{
+ return syscall(__NR_keyctl, KEYCTL_UPDATE, serial, payload, len);
+}
+
+static long kernel_revoke_key(long serial)
+{
+ return syscall(__NR_keyctl, KEYCTL_REVOKE, serial);
+}
+
+static bool setup_keyring_base(void)
+{
+ keyring_base = kernel_add_key("keyring", "ell", 0, 0,
+ KEY_SPEC_THREAD_KEYRING);
+
+ if (keyring_base <= 0) {
+ keyring_base = 0;
+ return false;
+ }
+
+ return true;
+}
+
+LIB_EXPORT struct l_key *l_key_new(enum l_key_type type, const void *payload,
+ size_t payload_length)
+{
+ struct l_key *key;
+
+ if (unlikely(!payload))
+ return NULL;
+
+ if (unlikely(!is_valid_type(type)))
+ return NULL;
+
+ if (!keyring_base && !setup_keyring_base()) {
+ return NULL;
+ }
+
+ key = l_new(struct l_key, 1);
+ key->type = type;
+ key->serial = kernel_add_key("user", "testing", payload, payload_length,
+ keyring_base);
+
+ if (key->serial < 0) {
+ l_free(key);
+ key = NULL;
+ }
+
+ return key;
+}
+
+LIB_EXPORT void l_key_free(struct l_key *key)
+{
+ if (unlikely(!key))
+ return;
+
+ kernel_revoke_key(key->serial);
+
+ l_free(key);
+}
+
+LIB_EXPORT bool l_key_set_payload(struct l_key *key, void *payload, size_t len)
+{
+ long error;
+
+ if (unlikely(!key))
+ return false;
+
+ error = kernel_update_key(key->serial, payload, len);
+
+ return error == 0;
+}
+
+LIB_EXPORT bool l_key_get_payload(struct l_key *key, void *payload, size_t *len)
+{
+ long copied;
+
+ if (unlikely(!key))
+ return false;
+
+ copied = kernel_read_key(key->serial, payload, *len);
+
+ if (copied < 0 || (size_t)copied > *len)
+ return false;
+
+ *len = copied;
+ return true;
+}
+
+LIB_EXPORT bool l_key_get_type(struct l_key *key, enum l_key_type *type)
+{
+ if (unlikely(!key))
+ return false;
+
+ *type = key->type;
+ return true;
+}
diff --git a/ell/key.h b/ell/key.h
new file mode 100644
index 0000000..c8b6c28
--- /dev/null
+++ b/ell/key.h
@@ -0,0 +1,58 @@
+/*
+ *
+ * Embedded Linux library
+ *
+ * Copyright (C) 2016 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __ELL_KEY_H
+#define __ELL_KEY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <stdbool.h>
+
+struct l_key;
+
+enum l_key_type {
+ L_KEY_USER = 0,
+ L_KEY_ASYMMETRIC_PUBLIC,
+ L_KEY_ASYMMETRIC_PRIVATE,
+ L_KEY_DH_PUBLIC,
+ L_KEY_DH_PRIVATE
+};
+
+struct l_key *l_key_new(enum l_key_type type, const void *payload,
+ size_t payload_length);
+
+void l_key_free(struct l_key *key);
+
+bool l_key_set_payload(struct l_key *key, void *payload, size_t len);
+
+bool l_key_get_payload(struct l_key *key, void *payload, size_t *len);
+
+bool l_key_get_type(struct l_key *key, enum l_key_type *type);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ELL_KEY_H */
--
2.7.2
6 years, 5 months