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
|
#include <sys/time.h>
#include "events.h"
#include "util/util.h"
#include "sbus/sssd_dbus.h"
#include "sbus_interfaces.h"
#include "util/service_helpers.h"
static void task_check_for_new_policies(struct event_context *ev_ctx,
struct timed_event *te,
struct timeval tval, void *main_ctx);
static void set_task_check_for_new_policies(struct main_context *main_ctx) {
struct timed_event *te = NULL;
struct timeval tv;
gettimeofday(&tv, NULL);
tv.tv_sec += 5;
tv.tv_usec = 0;
te = event_add_timed(main_ctx->event_ctx, main_ctx, tv, task_check_for_new_policies, main_ctx);
if (te == NULL) exit(1);
}
static void task_check_for_new_policies(struct event_context *ev_ctx,
struct timed_event *te,
struct timeval tval, void *main_ctx) {
DEBUG(0,("Hello, I'm task_check_for_new_policies.\n"));
set_task_check_for_new_policies(main_ctx);
}
static int service_identity(DBusMessage *message, void *data, DBusMessage **r);
static int service_pong(DBusMessage *message, void *data, DBusMessage **r);
struct sbus_method sbus_methods[] = {
{SERVICE_METHOD_IDENTITY, service_identity},
{SERVICE_METHOD_PING, service_pong},
{NULL, NULL}
};
static int service_identity(DBusMessage *message, void *data, DBusMessage **r)
{
dbus_uint16_t version = 0x0001;
const char *name = "PolicyProcessor";
DBusMessage *reply;
dbus_bool_t ret;
reply = dbus_message_new_method_return(message);
ret = dbus_message_append_args(reply,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_UINT16, &version,
DBUS_TYPE_INVALID);
if (!ret) {
return EIO;
}
*r = reply;
return EOK;
}
static int service_pong(DBusMessage *message, void *data, DBusMessage **r)
{
DBusMessage *reply;
dbus_bool_t ret;
reply = dbus_message_new_method_return(message);
ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID);
if (!ret) {
return EIO;
}
*r = reply;
return EOK;
}
int setup_sbus_and_server_loop(void) {
int ret=0;
struct main_context *main_ctx = NULL;
struct service_sbus_ctx *sbus_ctx = NULL;
ret = server_setup("PolicyProcessor", 0, &main_ctx);
if (ret != EOK ) {
DEBUG(0, ("sever_setup failed.\n"));
return ret;
}
sbus_ctx = sssd_service_sbus_init(main_ctx, main_ctx->event_ctx,
main_ctx->confdb_ctx, sbus_methods);
if (sbus_ctx == NULL) return -1;
set_task_check_for_new_policies(main_ctx);
server_loop(main_ctx);
return 0;
}
|