Commit 5219723c authored by Christian Kellner's avatar Christian Kellner
Browse files

daemon: Security property for device

parent 99edcb54
......@@ -51,7 +51,8 @@ struct _BoltDevice
BoltStatus status;
/* when device is attached */
char *syspath;
char *syspath;
BoltSecurity security;
};
......@@ -63,6 +64,7 @@ enum {
PROP_VENDOR,
PROP_STATUS,
PROP_SYSFS,
PROP_SECURITY,
PROP_LAST
};
......@@ -124,6 +126,10 @@ bolt_device_get_property (GObject *object,
g_value_set_string (value, dev->syspath);
break;
case PROP_SECURITY:
g_value_set_uint (value, dev->security);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
......@@ -195,6 +201,10 @@ bolt_device_class_init (BoltDeviceClass *klass)
PROP_SYSFS,
"sysfs-path");
g_object_class_override_property (gobject_class,
PROP_SECURITY,
"security");
}
/* internal methods */
......@@ -283,6 +293,51 @@ bolt_status_from_udev (struct udev_device *udev)
return BOLT_STATUS_CONNECTED;
}
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;
}
/* device authorization */
typedef void (*AuthCallback) (BoltDevice *dev,
......@@ -496,6 +551,7 @@ bolt_device_new_for_udev (BoltManager *mgr,
NULL);
dev->status = bolt_status_from_udev (udev);
dev->security = security_for_udev (udev);
g_object_add_weak_pointer (G_OBJECT (mgr),
(gpointer *) &dev->mgr);
......
......@@ -100,6 +100,13 @@
</doc:para></doc:description></doc:doc>
</property>
<property name="Security" type="u" access="read">
<doc:doc><doc:description><doc:para>
The security level of the domain the device is
connected to.
</doc:para></doc:description></doc:doc>
</property>
<!-- methods -->
<method name="Authorize">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment