ProxyAuth
Linux PAM to authenticate device via Bluetooth device
proxy_dbus.c
Go to the documentation of this file.
1 #include "proxy_dbus.h"
2 
3 void terminate(struct dbus_obj *data_obj) {
4  if (data_obj->proxy) {
5  if (data_obj->handler_id > 0) {
6  g_signal_handler_disconnect(data_obj->proxy, data_obj->handler_id);
7  }
8  g_object_unref(data_obj->proxy);
9  }
10 
11  if (data_obj->context) {
12  g_main_context_unref(data_obj->context);
13  }
14 
15  terminate_server(data_obj->server, *(data_obj->client), data_obj->session);
16 
17  exit(0);
18 }
19 
20 void on_signal (
21  GDBusProxy *proxy,
22  gchar *sender_name,
23  gchar *signal_name,
24  GVariant *parameters, //in the form of (u)
25  gpointer user_data
26 ) {
27  GVariant *value;
28  guint32 num = -1;
29  if ((value = g_variant_get_child_value(parameters, 0))) { //extract the value from the tuple
30  num = g_variant_get_uint32(value);
31  if (num == 3){
32  g_print("signal: %d\n", num);
33  terminate(user_data);
34  }
35  }
36 }
37 
39  struct dbus_obj *data_obj = NULL;
40 
41  if (!(data_obj = malloc(sizeof(struct dbus_obj)))) {
42  return NULL;
43  }
44 
45  if (!server) {
46  return NULL;
47  }
48 
49  data_obj->server = server->server;
50  data_obj->client = server->client;
51  data_obj->session = server->session;
52 
53  GError *error = NULL;
54 
55  data_obj->proxy = g_dbus_proxy_new_for_bus_sync(
56  G_BUS_TYPE_SESSION, //GBus Type
57  G_DBUS_PROXY_FLAGS_NONE, //Flag to use for constructing proxy
58  NULL, //GDBusInterfaceInfo
59  GNOME_SESSION_DBUS_NAME, //Bus Name
62  NULL, //GCancellable
63  &error //Error struct
64  );
65 
66  if (data_obj->proxy == NULL && error) {
67  g_printerr ("Error creating proxy: %s\n", error->message);
68  g_error_free (error);
69  terminate(data_obj);
70  }
71 
72  data_obj->handler_id = g_signal_connect(data_obj->proxy, "g-signal", G_CALLBACK(on_signal), data_obj);
73  data_obj->context = g_main_context_default();
74 
75  return data_obj;
76 }
77 
78 void check_lock_status(GMainContext *context) {
79  for (int i = 0; i < 15; i++) {
80  g_main_context_iteration(context, FALSE);
81  }
82 }
void terminate_server(int server, int client, sdp_session_t *session)
Definition: deauth.c:44
void on_signal(GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data)
Definition: proxy_dbus.c:20
struct dbus_obj * set_lock_listener(struct server_data_t *server)
Definition: proxy_dbus.c:38
void check_lock_status(GMainContext *context)
Definition: proxy_dbus.c:78
void terminate(struct dbus_obj *data_obj)
Definition: proxy_dbus.c:3
#define GNOME_SESSION_DBUS_OBJ_PATH_PRESENCE
Definition: proxy_dbus.h:11
#define GNOME_SESSION_DBUS_INTERFACE_PRESENCE
Definition: proxy_dbus.h:12
#define GNOME_SESSION_DBUS_NAME
Definition: proxy_dbus.h:10
sdp_session_t * session
Definition: proxy_dbus.h:26
int server
Definition: proxy_dbus.h:24
GDBusProxy * proxy
Definition: proxy_dbus.h:22
gulong handler_id
Definition: proxy_dbus.h:23
int * client
Definition: proxy_dbus.h:25
GMainContext * context
Definition: proxy_dbus.h:21