~ubuntu-branches/ubuntu/maverick/hal/maverick

« back to all changes in this revision

Viewing changes to tools/hal-acl-tool.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • mto: (1.5.1 sid)
  • mto: This revision was merged to the branch mainline in revision 90.
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
#include <glib.h>
35
35
#include <libhal.h>
 
36
#include <polkit/polkit.h>
36
37
 
37
38
/* How this works (or "An introduction to this code")
38
39
 *
39
40
 * - all ACL's granted by this tool is kept in /var/lib/hal/acl-list
 
41
 *   See below for the format.
40
42
 *
41
43
 * - every time tool is launched we read this file and keep each line
42
44
 *   as an ACLCurrent instance. These are kept in a list.
52
54
 *     - ACL's to be added are appended to the list and add -> TRUE
53
55
 *   - we then compute the argument vector to setfacl(1) for adding /
54
56
 *     removing ACL's
 
57
 *   - we emit signals ACLAdded and ACLRemoved
55
58
 *   - if setfacl(1) succeeds (rc == 0) then we write the new acl-current-list
56
59
 *
57
60
 * Notably, the HAL daemon will invoke us with --reconfigure on every
83
86
 * of ACL's that have been set by HAL and as such are currently
84
87
 * applied
85
88
 *
86
 
 *   <device-file>    <type>    <uid-or-gid>
 
89
 *   <device-file>    <udi>    <type>    <uid-or-gid>
87
90
 *
88
91
 * where <type>='u'|'g' for respectively uid and gid (the spacing represent tabs).
89
92
 *
90
93
 * Example:
91
94
 *
92
 
 *   /dev/snd/controlC0    u    500
93
 
 *   /dev/snd/controlC0    u    501
94
 
 *   /dev/snd/controlC0    g    1001
 
95
 *   /dev/snd/controlC0    /org/freedesktop/Hal/devices/pci_8086_27d8_alsa_control__1    u    500
 
96
 *   /dev/snd/controlC0    /org/freedesktop/Hal/devices/pci_8086_27d8_alsa_control__1    u    501
 
97
 *   /dev/snd/controlC0    /org/freedesktop/Hal/devices/pci_8086_27d8_alsa_control__1    g    1001
95
98
 */
96
99
typedef struct ACLCurrent_s {
 
100
        char *udi;
97
101
        char *device;
98
102
        int type;
99
103
        union {
100
104
                uid_t uid;
101
105
                gid_t gid;
102
106
        } v;
103
 
 
104
107
        gboolean remove;
105
108
        gboolean add;
106
109
} ACLCurrent;
111
114
        HAL_ACL_GID
112
115
};
113
116
 
 
117
static PolKitContext *pk_context = NULL;
 
118
 
 
119
static LibHalContext *hal_ctx = NULL;
 
120
 
 
121
static gboolean in_device_added = FALSE;
 
122
 
 
123
static gboolean
 
124
ensure_hal_ctx (void)
 
125
{
 
126
        gboolean ret;
 
127
        DBusError error;
 
128
 
 
129
        ret = FALSE;
 
130
        if (hal_ctx != NULL) {
 
131
                ret = TRUE;
 
132
                goto out;
 
133
        }
 
134
 
 
135
        dbus_error_init (&error);
 
136
        if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
 
137
                printf ("%d: Cannot connect to hald: %s: %s\n", getpid (), error.name, error.message);
 
138
                LIBHAL_FREE_DBUS_ERROR (&error);
 
139
                goto out;
 
140
        }
 
141
 
 
142
        ret = TRUE;
 
143
 
 
144
out:
 
145
        return ret;
 
146
}
 
147
 
114
148
static void
115
149
hal_acl_free (ACLCurrent *ha)
116
150
{
 
151
        g_free (ha->udi);
117
152
        g_free (ha->device);
118
153
        g_free (ha);
119
154
}
135
170
        gboolean ret;
136
171
        GError *error = NULL;
137
172
        int exit_status;
 
173
        gboolean messages_were_sent = FALSE;
138
174
 
139
175
        ret = FALSE;
140
176
 
156
192
                                                (ha->type == HAL_ACL_UID) ? 'u' : 'g',
157
193
                                                (ha->type == HAL_ACL_UID) ? ha->v.uid : ha->v.gid,
158
194
                                                ha->device);
159
 
                        continue;
160
195
                }
161
196
 
162
197
                if (ha->add) {
167
202
                                                (ha->type == HAL_ACL_UID) ? 'u' : 'g',
168
203
                                                (ha->type == HAL_ACL_UID) ? ha->v.uid : ha->v.gid,
169
204
                                                ha->device);
 
205
 
170
206
                }
171
207
 
172
 
                g_string_append_printf (str, 
173
 
                                        "%s\t%c\t%d\n",
174
 
                                        ha->device,
175
 
                                        (ha->type == HAL_ACL_UID) ? 'u' : 'g',
176
 
                                        (ha->type == HAL_ACL_UID) ? ha->v.uid : ha->v.gid);
 
208
                if (!ha->remove) {
 
209
                        g_string_append_printf (str, 
 
210
                                                "%s\t%s\t%c\t%d\n",
 
211
                                                ha->device,
 
212
                                                ha->udi,
 
213
                                                (ha->type == HAL_ACL_UID) ? 'u' : 'g',
 
214
                                                (ha->type == HAL_ACL_UID) ? ha->v.uid : ha->v.gid);
 
215
                }
177
216
        }
178
217
        new_acl_file_contents = g_string_free (str, FALSE);
179
218
 
224
263
                             strlen (new_acl_file_contents),
225
264
                             NULL);
226
265
 
 
266
        /* now that we've added/removed ACL's: emit D-Bus signals.. we need to do this _after_ 
 
267
         * having updated the ACL - to avoid possible race conditions 
 
268
         */
 
269
        messages_were_sent = FALSE;
 
270
        for (i = new_acl_list; i != NULL; i = g_slist_next (i)) {
 
271
                ACLCurrent *ha = (ACLCurrent *) i->data;
 
272
 
 
273
                /* emit signal ACLGranted or ACLRemoved - but avoid doing it on device add because the device
 
274
                 * object doesn't exist just yet
 
275
                 */
 
276
                if (ha->type == HAL_ACL_UID && ha->udi != NULL && (ha->add || ha->remove) && !in_device_added) {
 
277
                        DBusMessage *message;
 
278
                        DBusConnection *connection;
 
279
 
 
280
                        printf ("Emmitting %s for udi %s, uid %d\n", 
 
281
                                ha->add ? "ACLAdded" : "ACLRemoved",
 
282
                                ha->udi,
 
283
                                ha->v.uid);
 
284
 
 
285
                        if (!ensure_hal_ctx ()) {
 
286
                                printf ("%d: cannot get libhal context\n", getpid ());
 
287
                                goto no_dbus_signal;
 
288
                        }
 
289
 
 
290
                        connection = libhal_ctx_get_dbus_connection (hal_ctx);
 
291
                        if (connection == NULL) {
 
292
                                printf ("%d: cannot get D-Bus connection\n", getpid());
 
293
                                goto no_dbus_signal;
 
294
                        }
 
295
 
 
296
                        message = dbus_message_new_signal (ha->udi,
 
297
                                                           "org.freedesktop.Hal.Device.AccessControl",
 
298
                                                           ha->add ? "ACLAdded" : "ACLRemoved");
 
299
                        if (message == NULL) {
 
300
                                printf ("%d: cannot create message\n", getpid());
 
301
                                goto no_dbus_signal;
 
302
                        }
 
303
 
 
304
                        if (!dbus_message_append_args (message, 
 
305
                                                       DBUS_TYPE_UINT32, &(ha->v.uid),
 
306
                                                       DBUS_TYPE_INVALID)) {
 
307
                                printf ("%d: cannot append to message\n", getpid());
 
308
                                dbus_message_unref (message);
 
309
                                goto no_dbus_signal;
 
310
                        }
 
311
 
 
312
                        if (!dbus_connection_send (connection, message, NULL)) {
 
313
                                printf ("%d: cannot send message\n", getpid());
 
314
                                dbus_message_unref (message);
 
315
                                goto no_dbus_signal;
 
316
                        }
 
317
                        dbus_message_unref (message);
 
318
 
 
319
                        messages_were_sent = TRUE;
 
320
                }
 
321
 
 
322
        no_dbus_signal:
 
323
                ;
 
324
        }
 
325
 
 
326
        /* apparently we need to flush the signals - otherwise they
 
327
         * may be lost because we're exiting right after this
 
328
         */
 
329
        if (messages_were_sent) {
 
330
                if (ensure_hal_ctx ()) {
 
331
                        DBusConnection *connection;
 
332
                        connection = libhal_ctx_get_dbus_connection (hal_ctx);
 
333
                        if (connection != NULL) {
 
334
                                dbus_connection_flush (connection);
 
335
                        }
 
336
                }
 
337
        }
 
338
 
227
339
        ret = TRUE;
228
340
 
229
341
out:
258
370
                ACLCurrent *ha;
259
371
                char **val;
260
372
                char *endptr;
 
373
                gboolean old_format = FALSE;
 
374
                int n;
 
375
 
 
376
                /* supporting the old format is important; because at hald startup we call hal-acl-tool --remove-all */
261
377
 
262
378
                ha = g_new0 (ACLCurrent, 1);
263
379
                val = g_strsplit(buf, "\t", 0);
264
 
                if (g_strv_length (val) != 3) {
265
 
                        printf ("Line is malformed: '%s'\n", buf);
266
 
                        g_strfreev (val);
267
 
                        goto out;
268
 
                }
269
 
 
270
 
                ha->device = g_strdup (val[0]);
271
 
                if (strcmp (val[1], "u") == 0) {
 
380
                if (g_strv_length (val) == 3) {
 
381
                        printf ("Line is from old format: '%s'\n", buf);
 
382
                        old_format = TRUE;
 
383
                } else {
 
384
                        if (g_strv_length (val) != 4) {
 
385
                                printf ("Line is malformed: '%s'\n", buf);
 
386
                                g_strfreev (val);
 
387
                                goto out;
 
388
                        }
 
389
                }
 
390
 
 
391
                n = 0;
 
392
 
 
393
                ha->device = g_strdup (val[n++]);
 
394
 
 
395
                if (old_format) {
 
396
                        ha->udi = NULL;
 
397
                } else {
 
398
                        ha->udi = g_strdup (val[n++]);
 
399
                }
 
400
 
 
401
                if (strcmp (val[n], "u") == 0) {
272
402
                        ha->type = HAL_ACL_UID;
273
 
                        ha->v.uid = strtol (val[2], &endptr, 10);
 
403
                        ha->v.uid = strtol (val[n + 1], &endptr, 10);
274
404
                        if (*endptr != '\0' && *endptr != '\n') {
275
405
                                printf ("Line is malformed: '%s'\n", buf);
276
406
                                g_strfreev (val);
277
407
                                goto out;
278
408
                        }
279
 
                } else if (strcmp (val[1], "g") == 0) {
 
409
                } else if (strcmp (val[n], "g") == 0) {
280
410
                        ha->type = HAL_ACL_GID;
281
 
                        ha->v.gid = strtol (val[2], &endptr, 10);
 
411
                        ha->v.gid = strtol (val[n + 1], &endptr, 10);
282
412
                        if (*endptr != '\0' && *endptr != '\n') {
283
413
                                printf ("Line is malformed: '%s'\n", buf);
284
414
                                g_strfreev (val);
336
466
        /* for all seats */
337
467
        for (i = 0; seats[i] != NULL; i++) {
338
468
                char *seat = seats[i];
 
469
                char *seat_id;
339
470
                char **sessions;
340
471
                int num_sessions_on_seat;
341
472
 
349
480
                sessions = g_strsplit (s, "\t", 0);
350
481
                num_sessions_on_seat = g_strv_length (sessions);
351
482
 
352
 
                visitor_cb (seat, num_sessions_on_seat, NULL, 0, FALSE, FALSE, user_data);
 
483
                seat_id = g_strdup_printf ("/org/freedesktop/ConsoleKit/%s", seat);
 
484
                visitor_cb (seat_id, num_sessions_on_seat, NULL, 0, FALSE, FALSE, user_data);
353
485
 
354
486
                /* for all sessions on seat */
355
487
                for (j = 0; sessions[j] != NULL; j++) {
356
488
                        char *session = sessions[j];
 
489
                        char *session_id;
357
490
                        gboolean session_is_local;
358
491
                        gboolean session_is_active;
359
492
                        uid_t session_uid;
390
523
                                goto out;
391
524
                        }
392
525
 
393
 
                        visitor_cb (seat, num_sessions_on_seat, 
394
 
                                    session, session_uid, session_is_local, session_is_active, user_data);
395
 
 
 
526
                        session_id = g_strdup_printf ("/org/freedesktop/ConsoleKit/%s", session);
 
527
 
 
528
                        visitor_cb (seat_id, num_sessions_on_seat, 
 
529
                                    session_id, session_uid, session_is_local, session_is_active, user_data);
 
530
 
 
531
                        g_free (session_id);
396
532
                }
397
533
                g_strfreev (sessions);
 
534
                g_free (seat_id);
398
535
        }
399
536
        g_strfreev (seats);
400
537
 
409
546
        /* identifying the device */
410
547
        char *udi;      /* HAL UDI of device */
411
548
        char *device;   /* device file */
412
 
 
413
 
        /* policy for how to apply ACL's (must be set by the caller prior to visiting the device) */
414
 
 
415
 
        /* access is granted to any session on a local seat */
416
 
        gboolean grant_to_local_seat;
417
 
 
418
 
        /* access is granted only to active sessions on local seats */
419
 
        gboolean grant_to_local_seat_active_only;
 
549
        char *type;     /* type of device, access_control.type - used by PolicyKit */
420
550
 
421
551
        /* will be set by the visitor */
422
552
        GSList *uid;    /* list of uid's (int) that should have access to this device */
569
699
}
570
700
 
571
701
static void
 
702
acl_for_device_set_type (ACLForDevice *afd, const char *type)
 
703
{
 
704
        afd->type = g_strdup (type);
 
705
}
 
706
 
 
707
static void
572
708
acl_for_device_free (ACLForDevice* afd)
573
709
{
574
710
        g_free (afd->udi);
575
711
        g_free (afd->device);
 
712
        g_free (afd->type);
576
713
        g_slist_free (afd->uid);
577
714
        g_slist_free (afd->gid);
578
715
        g_free (afd);
607
744
         */
608
745
        for (i = afd_list; i != NULL; i = g_slist_next (i)) {
609
746
                ACLForDevice *afd = (ACLForDevice *) i->data;
 
747
                PolKitResult pk_result;
 
748
                PolKitSeat *pk_seat;
 
749
                PolKitSession *pk_session;
 
750
                PolKitAction *pk_action;
 
751
                char *priv_name;
610
752
 
611
753
                if (session_id == NULL) {
612
754
                        /* we only grant access to sessions - someone suggested that if a device is tied
619
761
                        continue;
620
762
                }
621
763
 
622
 
 
623
 
                /* apply the policy defined by grant_to_local_seat and grant_to_local_seat_active_only */
624
 
 
625
 
                /* we only grant access to local seats... */
626
 
                if (!session_is_local)
627
 
                        continue;
628
 
 
629
 
                /* don't bother giving ACL's to root - he's almighty anyway */
630
 
                if (session_uid == 0)
631
 
                        continue;
632
 
 
633
 
                if (afd->grant_to_local_seat)
 
764
                pk_seat = polkit_seat_new ();
 
765
                polkit_seat_set_ck_objref (pk_seat, seat_id);
 
766
 
 
767
                pk_session = polkit_session_new ();
 
768
                polkit_session_set_seat (pk_session, pk_seat);
 
769
                polkit_seat_unref (pk_seat);
 
770
                polkit_session_set_ck_objref (pk_session, session_id);
 
771
                polkit_session_set_uid (pk_session, session_uid);
 
772
                polkit_session_set_ck_is_active (pk_session, session_is_active);
 
773
                polkit_session_set_ck_is_local (pk_session, session_is_local);
 
774
                /* TODO: FIXME: polkit_session_set_ck_remote_host (pk_session, );*/ 
 
775
 
 
776
                pk_action = polkit_action_new();
 
777
                priv_name = g_strdup_printf ("org.freedesktop.hal.device-access.%s", afd->type);
 
778
                polkit_action_set_action_id (pk_action, priv_name);
 
779
                g_free (priv_name);
 
780
 
 
781
                /* Now ask PolicyKit if the given session should have access */
 
782
                pk_result = polkit_context_can_session_do_action (pk_context, 
 
783
                                                                  pk_action,
 
784
                                                                  pk_session);
 
785
                if (pk_result == POLKIT_RESULT_YES) {
634
786
                        afd_grant_to_uid (afd, session_uid);
635
 
                else {
636
 
                        if (afd->grant_to_local_seat_active_only) {
637
 
                                if (session_is_active) {
638
 
                                        afd_grant_to_uid (afd, session_uid);
639
 
                                }
640
 
                        }
641
 
                }
 
787
                }
 
788
 
 
789
                polkit_action_unref (pk_action);
 
790
                polkit_session_unref (pk_session);
642
791
        }
643
792
 
644
793
}
733
882
                 */
734
883
                for (j = afd->uid; j != NULL; j = g_slist_next (j)) {
735
884
                        ACLCurrent *ha;
 
885
                        uid_t uid;
 
886
 
 
887
                        uid = GPOINTER_TO_INT (j->data);
 
888
                        /* never grant ACL's to the super user */
 
889
                        if (uid == 0)
 
890
                                continue;
 
891
 
736
892
                        ha = g_new0 (ACLCurrent, 1);
737
893
                        ha->add = TRUE;
738
894
                        ha->device = g_strdup (afd->device);
 
895
                        ha->udi = g_strdup (afd->udi);
739
896
                        ha->type = HAL_ACL_UID;
740
 
                        ha->v.uid = GPOINTER_TO_INT (j->data);
 
897
                        ha->v.uid = uid;
741
898
                        current_acl_list = g_slist_prepend (current_acl_list, ha);
742
899
                }
743
900
                for (j = afd->gid; j != NULL; j = g_slist_next (j)) {
745
902
                        ha = g_new0 (ACLCurrent, 1);
746
903
                        ha->add = TRUE;
747
904
                        ha->device = g_strdup (afd->device);
 
905
                        ha->udi = g_strdup (afd->udi);
748
906
                        ha->type = HAL_ACL_GID;
749
907
                        ha->v.gid = GPOINTER_TO_INT (j->data);
750
908
                        current_acl_list = g_slist_prepend (current_acl_list, ha);
778
936
        char *s;
779
937
        char *udi;
780
938
        char *device;
 
939
        char *type;
781
940
        GSList *afd_list = NULL;
782
941
        ACLForDevice *afd = NULL;
783
942
 
 
943
        in_device_added = TRUE;
 
944
 
784
945
        /* we can avoid round-trips to the HAL daemon by using what's in the environment */
785
946
 
786
947
        if ((udi = getenv ("UDI")) == NULL)
789
950
        if ((device = getenv ("HAL_PROP_ACCESS_CONTROL_FILE")) == NULL)
790
951
                goto out;
791
952
 
 
953
        if ((type = getenv ("HAL_PROP_ACCESS_CONTROL_TYPE")) == NULL)
 
954
                goto out;
 
955
 
792
956
        afd = acl_for_device_new (udi);
793
957
        acl_for_device_set_device (afd, device);
 
958
        acl_for_device_set_type (afd, type);
794
959
        afd_list = g_slist_prepend (NULL, afd);
795
960
 
796
961
        /* get ACL granting policy from HAL properties */
797
 
        if ((s = getenv ("HAL_PROP_ACCESS_CONTROL_GRANT_LOCAL_SESSION")) != NULL) {
798
 
                afd->grant_to_local_seat = (strcmp (s, "true") == 0);
799
 
        }
800
 
        if ((s = getenv ("HAL_PROP_ACCESS_CONTROL_GRANT_LOCAL_ACTIVE_SESSION")) != NULL) {
801
 
                afd->grant_to_local_seat_active_only = (strcmp (s, "true") == 0);
802
 
        }
803
962
        if ((s = getenv ("HAL_PROP_ACCESS_CONTROL_GRANT_USER")) != NULL) {
804
963
                char **sv;
805
964
                sv = g_strsplit (s, "\t", 0);
879
1038
        int num_devices;
880
1039
        char **udis;
881
1040
        DBusError error;
882
 
        LibHalContext *hal_ctx;
883
1041
        GSList *afd_list = NULL;
884
1042
 
885
1043
        printf ("%d: reconfiguring all ACL's\n", getpid ());
886
1044
 
 
1045
        if (!ensure_hal_ctx ())
 
1046
                goto out;
 
1047
 
887
1048
        dbus_error_init (&error);
888
 
        if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
889
 
                printf ("%d: Cannot connect to hald: %s: %s\n", getpid (), error.name, error.message);
890
 
                LIBHAL_FREE_DBUS_ERROR (&error);
891
 
                goto out;
892
 
        }
893
 
 
894
1049
        if ((udis = libhal_find_device_by_capability (hal_ctx, "access_control", &num_devices, &error)) == NULL) {
895
1050
                printf ("%d: Cannot get list of devices of capability 'acl'\n", getpid ());
896
1051
                goto out;
900
1055
                LibHalPropertySet *props;
901
1056
                LibHalPropertySetIterator psi;
902
1057
                char *device = NULL;
 
1058
                char *type = NULL;
903
1059
                ACLForDevice *afd;
904
1060
                char **sv;
905
1061
 
916
1072
                        key = libhal_psi_get_key (&psi);
917
1073
                        if (strcmp (key, "access_control.file") == 0) {
918
1074
                                device = libhal_psi_get_string (&psi);
919
 
                        } else if (strcmp (key, "access_control.grant_local_session") == 0) {
920
 
                                afd->grant_to_local_seat = libhal_psi_get_bool (&psi);
921
 
                        } else if (strcmp (key, "access_control.grant_local_active_session") == 0) {
922
 
                                afd->grant_to_local_seat_active_only = libhal_psi_get_bool (&psi);
 
1075
                        } else if (strcmp (key, "access_control.type") == 0) {
 
1076
                                type = libhal_psi_get_string (&psi);
923
1077
                        } else if (strcmp (key, "access_control.grant_user") == 0) {
924
1078
                                sv = libhal_psi_get_strlist (&psi);
925
1079
                                afd_grant_to_uid_from_userlist (afd, sv);
932
1086
 
933
1087
                if (device == NULL) {
934
1088
                        printf ("%d: access_control.file not set for '%s'\n", getpid (), udis[i]);
935
 
                        goto out;
936
 
                } else {
937
 
                        acl_for_device_set_device (afd, device);
938
 
                        afd_list = g_slist_prepend (afd_list, afd);
939
 
                }
940
 
 
 
1089
                        if (type != NULL)
 
1090
                                libhal_free_string (type);
 
1091
                        acl_for_device_free (afd);
 
1092
                        goto skip;
 
1093
                }
 
1094
 
 
1095
                if (type == NULL) {
 
1096
                        printf ("%d: access_control.type not set for '%s'\n", getpid (), udis[i]);
 
1097
                        if (device != NULL)
 
1098
                                libhal_free_string (device);
 
1099
                        if (type != NULL)
 
1100
                                libhal_free_string (type);
 
1101
                        acl_for_device_free (afd);
 
1102
                        goto skip;
 
1103
                }
 
1104
 
 
1105
                acl_for_device_set_device (afd, device);
 
1106
                acl_for_device_set_type (afd, type);
 
1107
                afd_list = g_slist_prepend (afd_list, afd);
 
1108
        skip:
941
1109
                libhal_free_property_set (props);
942
1110
        }
943
1111
        libhal_free_string_array (udis);
989
1157
 
990
1158
        printf ("%d: attempting to get lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
991
1159
 
992
 
        lock_acl_fd = open (PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list", O_CREAT | O_RDWR);
 
1160
        lock_acl_fd = open (PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list", O_CREAT | O_RDWR, 0644);
993
1161
        if (lock_acl_fd < 0) {
994
1162
                printf ("%d: error opening/creating " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
995
1163
                return FALSE;
1025
1193
        printf ("%d: released lock on " PACKAGE_LOCALSTATEDIR "/lib/hal/acl-list\n", getpid ());
1026
1194
}
1027
1195
 
1028
 
 
1029
1196
int
1030
1197
main (int argc, char *argv[])
1031
1198
{
 
1199
        PolKitError *p_error;
 
1200
 
1032
1201
        if (argc != 2) {
1033
1202
                printf ("hal-acl-tool should only be invoked by hald\n");
1034
1203
                goto out;
1038
1207
                goto out;
1039
1208
        }
1040
1209
 
 
1210
        p_error = NULL;
 
1211
        pk_context = polkit_context_new ();
 
1212
        if (!polkit_context_init (pk_context, &p_error)) {
 
1213
                printf ("Could not init PolicyKit context: %s\n", polkit_error_get_error_message (p_error));
 
1214
                goto out;
 
1215
        }
 
1216
 
1041
1217
        if (strcmp (argv[1], "--add-device") == 0) {
1042
1218
                acl_device_added ();
1043
1219
        } else if (strcmp (argv[1], "--remove-device") == 0) {