bolt-device.c 20.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright © 2017 Red Hat, Inc
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Christian J. Kellner <christian@kellner.me>
 */

#include "config.h"

23
#include "bolt-dbus.h"
24
#include "bolt-device.h"
25
#include "bolt-enums.h"
26
#include "bolt-error.h"
27
#include "bolt-io.h"
28
#include "bolt-manager.h"
29
#include "bolt-store.h"
30

31
#include <dirent.h>
32 33
#include <libudev.h>

34 35 36 37 38
/* dbus method calls */
static gboolean    handle_authorize (BoltDBusDevice        *object,
                                     GDBusMethodInvocation *invocation,
                                     gpointer               user_data);

39 40 41 42 43

static gboolean    handle_forget (BoltDBusDevice        *object,
                                  GDBusMethodInvocation *invocation,
                                  gpointer               user_data);

44 45 46 47
struct _BoltDevice
{
  BoltDBusDeviceSkeleton object;

48 49
  /* weak reference */
  BoltManager *mgr;
50

51 52 53 54 55
  char        *dbus_path;

  char        *uid;
  char        *name;
  char        *vendor;
56

57 58
  BoltStatus   status;

59
  /* when device is attached */
60 61
  char        *syspath;
  BoltSecurity security;
62 63

  /* when device is stored */
64
  BoltStore   *store;
65 66
  BoltPolicy   policy;
  BoltKeyState key;
67 68 69 70 71 72
};


enum {
  PROP_0,

73
  PROP_MANAGER,
74 75 76 77 78
  PROP_STORE,

  PROP_LAST,

  /* overridden */
79
  PROP_UID,
80 81
  PROP_NAME,
  PROP_VENDOR,
82
  PROP_STATUS,
83

84
  PROP_SYSFS,
85
  PROP_SECURITY,
86

87 88 89
  PROP_STORED,
  PROP_POLICY,
  PROP_HAVE_KEY,
90 91
};

92
static GParamSpec *props[PROP_LAST] = {NULL, };
93

94 95 96 97 98 99 100
enum {
  SIGNAL_STATUS_CHANGED,
  SIGNAL_LAST
};

static guint signals[SIGNAL_LAST] = {0};

101 102 103 104 105 106 107 108 109
G_DEFINE_TYPE (BoltDevice,
               bolt_device,
               BOLT_DBUS_TYPE_DEVICE_SKELETON)

static void
bolt_device_finalize (GObject *object)
{
  BoltDevice *dev = BOLT_DEVICE (object);

110 111
  g_clear_object (&dev->store);

112 113
  g_free (dev->dbus_path);

114
  g_free (dev->uid);
115 116 117
  g_free (dev->name);
  g_free (dev->vendor);
  g_free (dev->syspath);
118 119 120 121 122

  G_OBJECT_CLASS (bolt_device_parent_class)->finalize (object);
}

static void
123
bolt_device_init (BoltDevice *dev)
124
{
125 126
  g_signal_connect (dev, "handle-authorize",
                    G_CALLBACK (handle_authorize), NULL);
127 128
  g_signal_connect (dev, "handle-forget",
                    G_CALLBACK (handle_forget), NULL);
129 130 131 132 133 134 135 136 137 138 139 140
}

static void
bolt_device_get_property (GObject    *object,
                          guint       prop_id,
                          GValue     *value,
                          GParamSpec *pspec)
{
  BoltDevice *dev = BOLT_DEVICE (object);

  switch (prop_id)
    {
141 142 143 144
    case PROP_MANAGER:
      g_value_set_object (value, dev->mgr);
      break;

145 146 147 148
    case PROP_STORE:
      g_value_set_object (value, dev->store);
      break;

149 150 151 152
    case PROP_UID:
      g_value_set_string (value, dev->uid);
      break;

153 154 155 156 157 158 159 160
    case PROP_NAME:
      g_value_set_string (value, dev->name);
      break;

    case PROP_VENDOR:
      g_value_set_string (value, dev->vendor);
      break;

161 162 163 164
    case PROP_STATUS:
      g_value_set_uint (value, dev->status);
      break;

165 166 167 168
    case PROP_SYSFS:
      g_value_set_string (value, dev->syspath);
      break;

169 170 171 172
    case PROP_SECURITY:
      g_value_set_uint (value, dev->security);
      break;

173
    case PROP_STORED:
174
      g_value_set_boolean (value, dev->store != NULL);
175 176 177 178 179 180 181 182 183 184
      break;

    case PROP_POLICY:
      g_value_set_uint (value, dev->policy);
      break;

    case PROP_HAVE_KEY:
      g_value_set_uint (value, dev->key);
      break;

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
bolt_device_set_property (GObject      *object,
                          guint         prop_id,
                          const GValue *value,
                          GParamSpec   *pspec)
{
  BoltDevice *dev = BOLT_DEVICE (object);

  switch (prop_id)
    {
200

201 202 203 204 205 206 207
    case PROP_MANAGER:
      g_return_if_fail (dev->mgr == NULL);
      dev->mgr = g_value_get_object (value);
      g_object_add_weak_pointer (G_OBJECT (dev->mgr),
                                 (gpointer *) &dev->mgr);
      break;

208 209 210 211 212
    case PROP_STORE:
      dev->store = g_value_dup_object (value);
      g_object_notify (object, "stored");
      break;

213
    case PROP_UID:
214
      g_return_if_fail (dev->uid == NULL);
215 216 217
      dev->uid = g_value_dup_string (value);
      break;

218
    case PROP_NAME:
219
      g_clear_pointer (&dev->name, g_free);
220
      dev->name = g_value_dup_string (value);
221 222 223
      break;

    case PROP_VENDOR:
224
      g_clear_pointer (&dev->vendor, g_free);
225
      dev->vendor = g_value_dup_string (value);
226 227
      break;

228
    case PROP_STATUS:
229 230 231 232 233 234 235 236 237 238 239 240 241
      {
        BoltStatus old = dev->status;
        BoltStatus now = g_value_get_uint (value);
        if (old == now)
          break;

        dev->status = now;
        g_signal_emit (dev,
                       signals[SIGNAL_STATUS_CHANGED],
                       0,
                       old);
        break;
      }
242

243
    case PROP_SYSFS:
244
      g_clear_pointer (&dev->syspath, g_free);
245 246
      dev->syspath = g_value_dup_string (value);
      break;
247 248 249 250

    case PROP_SECURITY:
      dev->security = g_value_get_uint (value);
      break;
251

252 253 254 255 256 257 258 259
    case PROP_POLICY:
      dev->policy = g_value_get_uint (value);
      break;

    case PROP_HAVE_KEY:
      dev->key = g_value_get_uint (value);
      break;

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}


static void
bolt_device_class_init (BoltDeviceClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

  gobject_class->finalize = bolt_device_finalize;

  gobject_class->get_property = bolt_device_get_property;
  gobject_class->set_property = bolt_device_set_property;

276 277 278 279 280 281 282
  props[PROP_MANAGER] =
    g_param_spec_object ("manager",
                         NULL, NULL,
                         BOLT_TYPE_MANAGER,
                         G_PARAM_READWRITE |
                         G_PARAM_STATIC_NICK);

283 284 285 286 287 288 289 290 291 292 293
  props[PROP_STORE] =
    g_param_spec_object ("store",
                         NULL, NULL,
                         BOLT_TYPE_STORE,
                         G_PARAM_READWRITE |
                         G_PARAM_STATIC_NICK);

  g_object_class_install_properties (gobject_class,
                                     PROP_LAST,
                                     props);

294 295 296
  g_object_class_override_property (gobject_class,
                                    PROP_UID,
                                    "uid");
297 298 299 300 301 302 303 304 305

  g_object_class_override_property (gobject_class,
                                    PROP_NAME,
                                    "name");

  g_object_class_override_property (gobject_class,
                                    PROP_VENDOR,
                                    "vendor");

306 307 308 309
  g_object_class_override_property (gobject_class,
                                    PROP_STATUS,
                                    "status");

310 311 312 313
  g_object_class_override_property (gobject_class,
                                    PROP_SYSFS,
                                    "sysfs-path");

314 315 316 317
  g_object_class_override_property (gobject_class,
                                    PROP_SECURITY,
                                    "security");

318 319
  g_object_class_override_property (gobject_class,
                                    PROP_STORED,
320
                                    "stored");
321 322 323 324 325 326 327 328 329

  g_object_class_override_property (gobject_class,
                                    PROP_POLICY,
                                    "policy");

  g_object_class_override_property (gobject_class,
                                    PROP_HAVE_KEY,
                                    "key");

330 331 332 333 334 335 336 337 338 339 340

  signals[SIGNAL_STATUS_CHANGED] =
    g_signal_new ("status-changed",
                  G_TYPE_FROM_CLASS (gobject_class),
                  G_SIGNAL_RUN_LAST,
                  0,
                  NULL, NULL,
                  NULL,
                  G_TYPE_NONE,
                  1, BOLT_TYPE_STATUS);

341
}
342 343 344

/* internal methods */

345 346
static const char *
read_sysattr_name (struct udev_device *udev, const char *attr, GError **error)
347 348
{
  g_autofree char *s = NULL;
349
  const char *v;
350 351

  s = g_strdup_printf ("%s_name", attr);
352 353 354 355 356 357
  v = udev_device_get_sysattr_value (udev, s);

  if (v != NULL)
    return v;

  v = udev_device_get_sysattr_value (udev, attr);
358

359
  if (v == NULL)
360 361 362
    g_set_error (error,
                 BOLT_ERROR, BOLT_ERROR_UDEV,
                 "failed to get sysfs attr: %s", attr);
363 364

  return v;
365 366
}

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
static gint
read_sysfs_attr_int (struct udev_device *device, const char *attr)
{
  const char *str;
  char *end;
  gint64 val;

  str = udev_device_get_sysattr_value (device, attr);

  if (str == NULL)
    return 0;

  val = g_ascii_strtoull (str, &end, 0);

  if (str == end)
    return 0;

  if (val > G_MAXINT || val < G_MININT)
    {
      g_warning ("value read from sysfs outside of guint's range.");
      val = 0;
    }

  return (gint) val;
}

static gboolean
string_nonzero (const char *str)
{
  return str != NULL && str[0] != '\0';
}

static BoltStatus
bolt_status_from_udev (struct udev_device *udev)
{
  gint authorized;
  const char *key;
  gboolean have_key;

  authorized = read_sysfs_attr_int (udev, "authorized");

  if (authorized == 2)
    return BOLT_STATUS_AUTHORIZED_SECURE;

  key = udev_device_get_sysattr_value (udev, "key");
  have_key = string_nonzero (key);

  if (authorized == 1)
    {
      if (have_key)
        return BOLT_STATUS_AUTHORIZED_NEWKEY;
      else
        return BOLT_STATUS_AUTHORIZED;
    }
  else if (authorized == 0 && have_key)
    {
      return BOLT_STATUS_AUTH_ERROR;
    }

  return BOLT_STATUS_CONNECTED;
}

429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473

static struct udev_device *
domain_for_device (struct udev_device *udev)
{
  struct udev_device *parent;
  gboolean found;

  found = FALSE;
  parent = udev;
  do
    {
      const char *name;
      parent = udev_device_get_parent (parent);
      if (!parent)
        break;

      name = udev_device_get_sysname (parent);
      found = g_str_has_prefix (name, "domain");

    }
  while (!found);

  return found ? parent : NULL;
}

static BoltSecurity
security_for_udev (struct udev_device *udev)
{
  struct udev_device *parent = NULL;
  const char *v;
  BoltSecurity s;

  parent = domain_for_device (udev);
  if (parent == NULL)
    {
      g_warning ("Failed to determine domain device");
      return BOLT_SECURITY_NONE;
    }

  v = udev_device_get_sysattr_value (parent, "security");
  s = bolt_security_from_string (v);

  return s;
}

474 475 476 477
/*  device authorization */

typedef struct
{
478 479 480
  BoltSecurity level;
  BoltKey     *key;
  BoltPolicy   policy;
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496

  /* the outer callback  */
  AuthCallback callback;
  gpointer     user_data;

} AuthData;

static void
auth_data_free (gpointer data)
{
  AuthData *auth = data;

  g_debug ("freeing auth data");
  g_slice_free (AuthData, auth);
}

497 498 499 500
static gboolean
authorize_device_internal (BoltDevice *dev,
                           AuthData   *auth,
                           GError    **error)
501 502 503 504
{
  g_autoptr(DIR) devdir = NULL;
  gboolean ok;

505
  devdir = bolt_opendir (dev->syspath, error);
506
  if (devdir == NULL)
507
    return FALSE;
508

509
  ok = bolt_verify_uid (dirfd (devdir), dev->uid, error);
510
  if (!ok)
511 512 513
    return FALSE;

  if (auth->key)
514
    {
515 516 517 518 519 520 521 522 523 524 525
      int keyfd;

      g_debug ("[%s] writing key", dev->uid);
      keyfd = bolt_openat (dirfd (devdir), "key", O_WRONLY | O_CLOEXEC, error);
      if (keyfd < 0)
        return FALSE;

      ok = bolt_key_write_to (auth->key, keyfd, &auth->level, error);
      close (keyfd);
      if (!ok)
        return FALSE;
526 527
    }

528
  g_debug ("[%s] writing authorization", dev->uid);
529 530 531
  ok = bolt_write_char_at (dirfd (devdir),
                           "authorized",
                           auth->level,
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
                           error);

  return ok;
}

static void
authorize_in_thread (GTask        *task,
                     gpointer      source,
                     gpointer      context,
                     GCancellable *cancellable)
{
  g_autoptr(GError) error = NULL;
  BoltDevice *dev = source;
  AuthData *auth = context;
  gboolean ok;

  ok = authorize_device_internal (dev, auth, &error);
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

  if (!ok)
    {
      g_task_return_new_error (task,
                               BOLT_ERROR, BOLT_ERROR_FAILED,
                               "failed to authorize device: %s",
                               error->message);
    }
  else
    {
      g_task_return_boolean (task, TRUE);
    }
}

static void
authorize_thread_done (GObject      *object,
                       GAsyncResult *res,
                       gpointer      user_data)
{
568
  g_autoptr(GError) error = NULL;
569 570 571
  BoltDevice *dev = BOLT_DEVICE (object);
  GTask *task = G_TASK (res);
  AuthData *auth;
572
  BoltStatus status;
573 574 575 576 577 578
  gboolean ok;

  auth = g_task_get_task_data (task);
  ok = g_task_propagate_boolean (task, &error);

  if (ok)
579 580
    {
      if (auth->level == BOLT_SECURITY_SECURE)
581
        status = BOLT_STATUS_AUTHORIZED_SECURE;
582
      else if (auth->key)
583
        status = BOLT_STATUS_AUTHORIZED_NEWKEY;
584
      else
585
        status = BOLT_STATUS_AUTHORIZED;
586

587
      if (!dev->store)
588
        {
589 590 591
          BoltStore *store;

          store = bolt_manager_get_store (dev->mgr);
592 593 594 595 596 597 598
          ok = bolt_store_put_device (store,
                                      dev,
                                      BOLT_POLICY_AUTO,
                                      auth->key,
                                      &error);
        }
    }
599
  else
600
    {
601
      status = BOLT_STATUS_AUTH_ERROR;
602 603
    }

604
  g_object_set (dev, "status", status, NULL);
605 606 607

  if (auth->callback)
    auth->callback (dev, ok, &error, auth->user_data);
608

609 610
}

611
gboolean
612 613 614 615 616 617
bolt_device_authorize (BoltDevice  *dev,
                       AuthCallback callback,
                       gpointer     user_data,
                       GError     **error)
{
  AuthData *auth_data;
618 619
  BoltSecurity level;
  BoltKey *key;
620 621 622 623 624 625 626 627 628 629
  GTask *task;

  if (dev->status != BOLT_STATUS_CONNECTED &&
      dev->status != BOLT_STATUS_AUTH_ERROR)
    {
      g_set_error (error, BOLT_ERROR, BOLT_ERROR_FAILED,
                   "wrong device state: %u", dev->status);
      return FALSE;
    }

630 631
  level = dev->security;
  key = NULL;
632

633 634
  if (level == BOLT_SECURITY_SECURE)
    {
635
      if (dev->store == NULL)
636
        key = bolt_key_new ();
637
      else if (dev->key)
638
        key = bolt_store_get_key (dev->store, dev->uid, error);
639 640 641 642 643 644 645 646
      else
        level = BOLT_SECURITY_USER;
    }

  if (level == BOLT_SECURITY_SECURE && key == NULL)
    return FALSE;

  task = g_task_new (dev, NULL, authorize_thread_done, NULL);
647
  auth_data = g_slice_new (AuthData);
648 649
  auth_data->level = level;
  auth_data->key = key;
650 651 652 653
  auth_data->callback = callback;
  auth_data->user_data = user_data;
  g_task_set_task_data (task, auth_data, auth_data_free);

654
  g_object_set (dev, "status", BOLT_STATUS_AUTHORIZING, NULL);
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

  g_task_run_in_thread (task, authorize_in_thread);
  g_object_unref (task);

  return TRUE;
}


/* dbus methods */

static void
handle_authorize_done (BoltDevice *dev,
                       gboolean    ok,
                       GError    **error,
                       gpointer    user_data)
{
  GDBusMethodInvocation *invocation = user_data;

  if (ok)
    {
      bolt_dbus_device_complete_authorize (BOLT_DBUS_DEVICE (dev),
                                           invocation);
    }
  else
    {
      g_dbus_method_invocation_take_error (invocation, *error);
      error = NULL;
    }
}

static gboolean
handle_authorize (BoltDBusDevice        *object,
                  GDBusMethodInvocation *invocation,
                  gpointer               user_data)
{
  BoltDevice *dev = BOLT_DEVICE (object);
  GError *error = NULL;
  gboolean ok;

  ok = bolt_device_authorize (dev,
                              handle_authorize_done,
                              invocation,
                              &error);

  if (!ok)
    g_dbus_method_invocation_take_error (invocation, error);

  return TRUE;
}

705 706 707 708 709 710 711 712 713 714 715 716
static gboolean
handle_forget (BoltDBusDevice        *object,
               GDBusMethodInvocation *inv,
               gpointer               user_data)
{
  g_autoptr(GError) key_err = NULL;
  g_autoptr(GError) dev_err = NULL;
  BoltDevice *dev;
  gboolean key_ok, dev_ok;

  dev = BOLT_DEVICE (object);

717
  key_ok = bolt_store_del_key (dev->store, dev->uid, &key_err);
718 719 720
  if (!key_ok && bolt_err_notfound (key_err))
    key_ok = TRUE;

721
  dev_ok = bolt_store_del_device (dev->store, dev->uid, &dev_err);
722 723 724 725 726 727 728 729 730 731 732 733 734

  g_debug ("[%s] forgetting: key: %d, dev: %d", dev->uid, key_ok, dev_ok);

  if (!dev_ok)
    g_dbus_method_invocation_take_error (inv, g_steal_pointer (&dev_err));
  else if (!key_ok)
    g_dbus_method_invocation_take_error (inv, g_steal_pointer (&key_err));
  else
    bolt_dbus_device_complete_forget (BOLT_DBUS_DEVICE (dev), inv);

  return TRUE;
}

735 736 737
/* public methods */

BoltDevice *
738
bolt_device_new_for_udev (struct udev_device *udev,
739 740
                          GError            **error)
{
741 742 743 744
  const char *uid;
  const char *name;
  const char *vendor;
  const char *syspath;
745
  BoltDevice *dev;
746 747


748 749 750 751 752 753 754
  uid = udev_device_get_sysattr_value (udev, "unique_id");
  if (udev == NULL)
    {
      g_set_error (error, BOLT_ERROR, BOLT_ERROR_UDEV,
                   "could not get unique_id for udev");
      return NULL;
    }
755

756 757
  syspath = udev_device_get_syspath (udev);
  g_return_val_if_fail (syspath != NULL, NULL);
758

759
  name = read_sysattr_name (udev, "device", error);
760 761 762
  if (name == NULL)
    return NULL;

763
  vendor = read_sysattr_name (udev, "vendor", error);
764 765
  if (vendor == NULL)
    return NULL;
766 767

  dev = g_object_new (BOLT_TYPE_DEVICE,
768 769 770 771
                      "uid", uid,
                      "name", name,
                      "vendor", vendor,
                      "sysfs-path", syspath,
772 773
                      NULL);

774
  dev->status = bolt_status_from_udev (udev);
775
  dev->security = security_for_udev (udev);
776

777 778 779
  return dev;
}

780
const char *
781 782 783 784
bolt_device_export (BoltDevice      *device,
                    GDBusConnection *connection,
                    GError         **error)
{
785
  const char *path;
786
  gboolean ok;
787 788

  g_return_val_if_fail (BOLT_IS_DEVICE (device), FALSE);
789

790
  path = bolt_device_get_object_path (device);
791

792 793 794 795 796
  ok = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (device),
                                         connection,
                                         path,
                                         error);
  return ok ? path : NULL;
797 798 799 800 801 802 803
}

void
bolt_device_unexport (BoltDevice *device)
{
  g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (device));
}
804

805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

BoltStatus
bolt_device_connected (BoltDevice         *dev,
                       struct udev_device *udev)
{
  const char *syspath;
  BoltSecurity security;
  BoltStatus status;

  syspath = udev_device_get_syspath (udev);
  status = bolt_status_from_udev (udev);
  security = security_for_udev (udev);

  g_object_set (G_OBJECT (dev),
                "sysfs-path", syspath,
                "security", security,
                "status", status,
                NULL);

  return status;
}

BoltStatus
bolt_device_disconnected (BoltDevice *dev)
{
  g_object_set (G_OBJECT (dev),
                "sysfs-path", NULL,
                "security", BOLT_SECURITY_NONE,
                "status", BOLT_STATUS_DISCONNECTED,
                NULL);

  return dev->status;
}

gboolean
bolt_device_is_connected (BoltDevice *device)
{
842
  return bolt_status_is_connected (device->status);
843 844
}

845 846 847 848 849 850 851 852 853 854 855 856 857
BoltStatus
bolt_device_update_from_udev (BoltDevice         *dev,
                              struct udev_device *udev)
{
  BoltStatus status = bolt_status_from_udev (udev);

  g_object_set (G_OBJECT (dev),
                "status", status,
                NULL);

  return status;
}

858
BoltKeyState
859 860 861 862 863
bolt_device_get_key (BoltDevice *dev)
{
  return dev->key;
}

864 865 866 867 868 869
const char *
bolt_device_get_name (BoltDevice *dev)
{
  return dev->name;
}

870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
const char *
bolt_device_get_object_path (BoltDevice *device)
{
  g_return_val_if_fail (BOLT_IS_DEVICE (device), FALSE);

  if (device->dbus_path == NULL)
    {
      char *path = NULL;

      path = g_strdup_printf ("/org/freedesktop/Bolt/devices/%s", device->uid);
      g_strdelimit (path, "-", '_');

      device->dbus_path = path;
    }

  return device->dbus_path;
}
887

888 889 890 891 892 893
BoltPolicy
bolt_device_get_policy (BoltDevice *dev)
{
  return dev->policy;
}

894 895 896 897 898 899
const char *
bolt_device_get_uid (BoltDevice *dev)
{
  return dev->uid;
}

900 901 902 903 904 905
BoltSecurity
bolt_device_get_security (BoltDevice *dev)
{
  return dev->security;
}

Christian Kellner's avatar
Christian Kellner committed
906 907 908 909 910 911
BoltStatus
bolt_device_get_status (BoltDevice *dev)
{
  return dev->status;
}

912 913
gboolean
bolt_device_get_stored (BoltDevice *dev)
914
{
915
  return dev->store != NULL;
916 917
}

918 919 920 921 922
const char *
bolt_device_get_syspath (BoltDevice *dev)
{
  return dev->syspath;
}
923 924 925 926 927 928

const char *
bolt_device_get_vendor (BoltDevice *dev)
{
  return dev->vendor;
}