Commit 305940d5 authored by Christian Kellner's avatar Christian Kellner
Browse files

sysfs: security_for_device returns an error object

It also handles the case that the device supplied is the domain
itself.
parent e1b78d6b
...@@ -1003,7 +1003,7 @@ bolt_device_new_for_udev (struct udev_device *udev, ...@@ -1003,7 +1003,7 @@ bolt_device_new_for_udev (struct udev_device *udev,
ct = (guint64) bolt_sysfs_device_get_time (udev, BOLT_ST_CTIME); ct = (guint64) bolt_sysfs_device_get_time (udev, BOLT_ST_CTIME);
parent = bolt_sysfs_get_parent_uid (udev); parent = bolt_sysfs_get_parent_uid (udev);
security = bolt_sysfs_security_for_device (udev); security = bolt_sysfs_security_for_device (udev, NULL);
status = bolt_status_from_udev (udev); status = bolt_status_from_udev (udev);
at = bolt_status_is_authorized (status) ? ct : 0; at = bolt_status_is_authorized (status) ? ct : 0;
...@@ -1063,7 +1063,7 @@ bolt_device_connected (BoltDevice *dev, ...@@ -1063,7 +1063,7 @@ bolt_device_connected (BoltDevice *dev,
syspath = udev_device_get_syspath (udev); syspath = udev_device_get_syspath (udev);
status = bolt_status_from_udev (udev); status = bolt_status_from_udev (udev);
security = bolt_sysfs_security_for_device (udev); security = bolt_sysfs_security_for_device (udev, NULL);
parent = bolt_sysfs_get_parent_uid (udev); parent = bolt_sysfs_get_parent_uid (udev);
ct = (guint64) bolt_sysfs_device_get_time (udev, BOLT_ST_CTIME); ct = (guint64) bolt_sysfs_device_get_time (udev, BOLT_ST_CTIME);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "bolt-sysfs.h" #include "bolt-sysfs.h"
#include "bolt-error.h"
#include "bolt-str.h" #include "bolt-str.h"
#include "bolt-log.h" #include "bolt-log.h"
...@@ -57,17 +58,23 @@ bolt_sysfs_domain_for_device (struct udev_device *udev) ...@@ -57,17 +58,23 @@ bolt_sysfs_domain_for_device (struct udev_device *udev)
} }
BoltSecurity BoltSecurity
bolt_sysfs_security_for_device (struct udev_device *udev) bolt_sysfs_security_for_device (struct udev_device *udev,
GError **error)
{ {
struct udev_device *parent = NULL; struct udev_device *parent = NULL;
const char *v; const char *v;
BoltSecurity s; BoltSecurity s;
parent = bolt_sysfs_domain_for_device (udev); if (bolt_sysfs_device_is_domain (udev))
parent = udev;
else
parent = bolt_sysfs_domain_for_device (udev);
if (parent == NULL) if (parent == NULL)
{ {
bolt_warn ("failed to determine domain device"); g_set_error_literal (error, BOLT_ERROR, BOLT_ERROR_UDEV,
return BOLT_SECURITY_NONE; "failed to determine domain device");
return BOLT_SECURITY_INVALID;
} }
v = udev_device_get_sysattr_value (parent, "security"); v = udev_device_get_sysattr_value (parent, "security");
...@@ -75,8 +82,9 @@ bolt_sysfs_security_for_device (struct udev_device *udev) ...@@ -75,8 +82,9 @@ bolt_sysfs_security_for_device (struct udev_device *udev)
if (!bolt_security_validate (s)) if (!bolt_security_validate (s))
{ {
bolt_warn ("invalid security: %s", v); g_set_error (error, BOLT_ERROR, BOLT_ERROR_UDEV,
s = BOLT_SECURITY_NONE; "unknown security level '%s'", v);
s = BOLT_SECURITY_INVALID;
} }
return s; return s;
......
...@@ -30,7 +30,10 @@ struct udev_device; ...@@ -30,7 +30,10 @@ struct udev_device;
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean bolt_sysfs_device_is_domain (struct udev_device *udev); gboolean bolt_sysfs_device_is_domain (struct udev_device *udev);
struct udev_device * bolt_sysfs_domain_for_device (struct udev_device *udev); struct udev_device * bolt_sysfs_domain_for_device (struct udev_device *udev);
BoltSecurity bolt_sysfs_security_for_device (struct udev_device *udev);
BoltSecurity bolt_sysfs_security_for_device (struct udev_device *udev,
GError **error);
G_END_DECLS G_END_DECLS
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