This is so that it is more obvious that you can use
it for authentication, service availabilty and
process resource constraints.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbipcs.h | 41 +++++++++++++++++++++++++++++++++++++++--
lib/ipc_us.c | 12 +++++-------
lib/ipcs.c | 2 +-
tests/bms.c | 6 +++---
tests/check_ipc.c | 2 +-
5 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/include/qb/qbipcs.h b/include/qb/qbipcs.h
index d7dff7d..b1dc6d9 100644
--- a/include/qb/qbipcs.h
+++ b/include/qb/qbipcs.h
@@ -49,33 +49,70 @@ struct qb_ipcs_poll_handlers {
qb_ipcs_dispatch_rm_fn dispatch_rm;
};
-typedef int32_t (*qb_ipcs_connection_authenticate_fn) (qb_ipcs_connection_handle_t c,
uid_t uid, gid_t gid);
+/**
+ * This callback is to check wether you want to accept a new connection.
+ *
+ * The type of checks you should do are authentication, service availabilty
+ * or process resource constraints.
+ * @return 0 to accept or -errno to indicate a failure (sent back to the client)
+ */
+typedef int32_t (*qb_ipcs_connection_accept_fn) (qb_ipcs_connection_handle_t c, uid_t
uid, gid_t gid);
+
+/**
+ * This is called after a new connection has been created.
+ */
typedef void (*qb_ipcs_connection_created_fn) (qb_ipcs_connection_handle_t c);
+/**
+ * This is called after a connection has been destroyed.
+ */
typedef void (*qb_ipcs_connection_destroyed_fn) (qb_ipcs_connection_handle_t c);
+/**
+ * This is the message processing calback.
+ * It is called with the message data.
+ */
typedef void (*qb_ipcs_msg_process_fn) (qb_ipcs_connection_handle_t c,
void *data, size_t size);
struct qb_ipcs_service_handlers {
- qb_ipcs_connection_authenticate_fn connection_authenticate;
+ qb_ipcs_connection_accept_fn connection_accept;
qb_ipcs_connection_created_fn connection_created;
qb_ipcs_msg_process_fn msg_process;
qb_ipcs_connection_destroyed_fn connection_destroyed;
};
+/**
+ * Create a new IPC server.
+ */
qb_ipcs_service_pt qb_ipcs_create(const char* name,
enum qb_ipc_type type);
+/**
+ * Set your callbacks.
+ */
void qb_ipcs_service_handlers_set(qb_ipcs_service_pt s,
struct qb_ipcs_service_handlers *handlers);
void qb_ipcs_poll_handlers_set(qb_ipcs_service_pt s,
struct qb_ipcs_poll_handlers *handlers);
+/**
+ * run the new IPC server.
+ */
int32_t qb_ipcs_run(qb_ipcs_service_pt s, qb_handle_t poll);
+/**
+ * Destroy the IPC server.
+ */
void qb_ipcs_destroy(qb_ipcs_service_pt s);
+/**
+ * send a response to a incomming request.
+ */
ssize_t qb_ipcs_response_send(qb_ipcs_connection_handle_t c, void *data, size_t size);
+
+/**
+ * Send an asyncronous event message to the client.
+ */
ssize_t qb_ipcs_event_send(qb_ipcs_connection_handle_t c, void *data, size_t size);
/* *INDENT-OFF* */
diff --git a/lib/ipc_us.c b/lib/ipc_us.c
index 61a6d78..49781b7 100644
--- a/lib/ipc_us.c
+++ b/lib/ipc_us.c
@@ -264,13 +264,11 @@ cleanup_and_return:
#endif
if (res == 0) {
- res = -EACCES;
- if (c->service->serv_fns.connection_authenticate &&
- c->service->serv_fns.connection_authenticate(c->handle,
+ if (c->service->serv_fns.connection_accept) {
+ res = c->service->serv_fns.connection_accept(c->handle,
c->euid,
- c->egid)) {
- res = 0;
- } else if (c->service->serv_fns.connection_authenticate == NULL) {
+ c->egid);
+ } else {
res = 0;
}
}
@@ -586,7 +584,7 @@ send_response:
qb_util_log(LOG_ERR, "Invalid IPC credentials.");
} else {
strerror_r(-response.hdr.error, error_str, 100);
- qb_util_log(LOG_ERR, "Error in conection setup: %s.",
+ qb_util_log(LOG_ERR, "Error in connection setup: %s.",
error_str);
}
if (res != 0) {
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 2f9c1ed..65997a7 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -58,7 +58,7 @@ void qb_ipcs_service_handlers_set(qb_ipcs_service_pt pt,
qb_hdb_handle_get(&qb_ipc_services, pt, (void **)&s);
- s->serv_fns.connection_authenticate = handlers->connection_authenticate;
+ s->serv_fns.connection_accept = handlers->connection_accept;
s->serv_fns.connection_created = handlers->connection_created;
s->serv_fns.msg_process = handlers->msg_process;
s->serv_fns.connection_destroyed = handlers->connection_destroyed;
diff --git a/tests/bms.c b/tests/bms.c
index 0aa8c23..e770990 100644
--- a/tests/bms.c
+++ b/tests/bms.c
@@ -52,7 +52,7 @@ int32_t verbose = 0;
static qb_handle_t bms_poll_handle;
static qb_ipcs_service_pt s1;
-static int32_t s1_connection_authenticate_fn(qb_ipcs_connection_handle_t conn, uid_t uid,
gid_t gid)
+static int32_t s1_connection_accept_fn(qb_ipcs_connection_handle_t conn, uid_t uid, gid_t
gid)
{
#if 0
if (uid == 0 && gid == 0) {
@@ -65,7 +65,7 @@ static int32_t s1_connection_authenticate_fn(qb_ipcs_connection_handle_t
conn, u
printf("%s:%d %s() BAD user!\n", __FILE__, __LINE__, __func__);
return 0;
#else
- return 1;
+ return 0;
#endif
}
@@ -142,7 +142,7 @@ int32_t main(int32_t argc, char *argv[])
int32_t opt;
enum qb_ipc_type ipc_type = QB_IPC_SHM;
struct qb_ipcs_service_handlers sh = {
- .connection_authenticate = s1_connection_authenticate_fn,
+ .connection_accept = s1_connection_accept_fn,
.connection_created = s1_connection_created_fn,
.msg_process = s1_msg_process_fn,
.connection_destroyed = s1_connection_destroyed_fn,
diff --git a/tests/check_ipc.c b/tests/check_ipc.c
index 6211a98..fc3dd41 100644
--- a/tests/check_ipc.c
+++ b/tests/check_ipc.c
@@ -113,7 +113,7 @@ static void run_ipc_server(void)
int32_t res;
struct qb_ipcs_service_handlers sh = {
- .connection_authenticate = NULL,
+ .connection_accept = NULL,
.connection_created = NULL,
.msg_process = s1_msg_process_fn,
.connection_destroyed = NULL,
--
1.7.2.3