8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / hal / utils / adt_data.c
blob1254efb51fef55e05a65a9bef5d9bd93d98dee5f
1 /***************************************************************************
3 * adt_data.c : Provides Audit functionalities
5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 ***************************************************************************/
12 #pragma ident "%Z%%M% %I% %E% SMI"
14 #include <stdio.h>
15 #include <errno.h>
16 #include <string.h>
17 #include <stdlib.h>
18 #include <glib.h>
19 #include <dbus/dbus-glib-lowlevel.h>
20 #include <dbus/dbus-glib.h>
21 #include "../hald/logger.h"
22 #include "adt_data.h"
24 adt_export_data_t *
25 get_audit_export_data(DBusConnection *bus, const char *invoked_by_syscon_name, size_t *data_size)
27 DBusMessage *message;
28 DBusMessage *reply;
29 DBusMessageIter iter, subiter;
30 DBusError error;
31 int count, bufsize;
32 uchar_t *buf;
33 uchar_t value;
35 message = dbus_message_new_method_call ("org.freedesktop.DBus",
36 "/org/freedesktop/DBus",
37 "org.freedesktop.DBus",
38 "GetAdtAuditSessionData");
39 if (message == NULL) {
40 printf ("cannot get GetAdtAuditSessionData message\n");
41 return NULL;
44 if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &invoked_by_syscon_name,
45 DBUS_TYPE_INVALID)) {
46 dbus_message_unref(message);
47 return NULL;
50 dbus_error_init (&error);
51 reply = dbus_connection_send_with_reply_and_block (bus,
52 message, -1,
53 &error);
54 if (dbus_error_is_set (&error)) {
55 printf ("send failed %s\n", error.message);
56 dbus_error_free (&error);
57 dbus_message_unref (message);
58 return NULL;
60 if (reply == NULL) {
61 dbus_message_unref (message);
62 return NULL;
65 dbus_message_iter_init (reply, &iter);
67 if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY ||
68 dbus_message_iter_get_element_type (&iter) != DBUS_TYPE_BYTE) {
69 printf ("expecting an array of byte entries\n");
70 dbus_message_unref (message);
71 dbus_message_unref (reply);
72 return NULL;
74 dbus_message_iter_recurse (&iter, &subiter);
76 count = 0;
77 bufsize = 256;
78 buf = (uchar_t *)malloc (bufsize);
80 while (dbus_message_iter_get_arg_type (&subiter) == DBUS_TYPE_BYTE) {
81 if (count == bufsize) {
82 bufsize += 256;
83 buf = realloc (buf, bufsize);
84 if (buf == NULL) {
85 dbus_message_unref (message);
86 dbus_message_unref (reply);
87 return NULL;
91 dbus_message_iter_get_basic (&subiter, &value);
92 buf[count++] = value;
93 dbus_message_iter_next(&subiter);
96 dbus_message_unref (message);
97 dbus_message_unref (reply);
99 *data_size = count;
100 if (count == 0) {
101 free (buf);
102 buf = NULL;
105 return (adt_export_data_t *)buf;