mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
Merge pull request #18734 from poettering/cryptsetup-description-escape
cryptsetup: unescape ID_PART_ENTRY_NAME udev field
This commit is contained in:
commit
e82a0ef1cf
@ -419,7 +419,6 @@ static int parse_options(const char *options) {
|
||||
|
||||
static char* disk_description(const char *path) {
|
||||
static const char name_fields[] =
|
||||
"ID_PART_ENTRY_NAME\0"
|
||||
"DM_NAME\0"
|
||||
"ID_MODEL_FROM_DATABASE\0"
|
||||
"ID_MODEL\0";
|
||||
@ -427,6 +426,7 @@ static char* disk_description(const char *path) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||
const char *i, *name;
|
||||
struct stat st;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
|
||||
@ -436,9 +436,27 @@ static char* disk_description(const char *path) {
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return NULL;
|
||||
|
||||
if (sd_device_new_from_devnum(&device, 'b', st.st_rdev) < 0)
|
||||
if (sd_device_new_from_stat_rdev(&device, &st) < 0)
|
||||
return NULL;
|
||||
|
||||
if (sd_device_get_property_value(device, "ID_PART_ENTRY_NAME", &name) >= 0) {
|
||||
_cleanup_free_ char *unescaped = NULL;
|
||||
|
||||
/* ID_PART_ENTRY_NAME uses \x style escaping, using libblkid's blkid_encode_string(). Let's
|
||||
* reverse this here to make the string more human friendly in case people embed spaces or
|
||||
* other weird stuff. */
|
||||
|
||||
r = cunescape(name, UNESCAPE_RELAX, &unescaped);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to unescape ID_PART_ENTRY_NAME, skipping device: %m");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!isempty(unescaped) && !string_has_cc(unescaped, NULL))
|
||||
return TAKE_PTR(unescaped);
|
||||
}
|
||||
|
||||
/* These need no unescaping. */
|
||||
NULSTR_FOREACH(i, name_fields)
|
||||
if (sd_device_get_property_value(device, i, &name) >= 0 &&
|
||||
!isempty(name))
|
||||
|
@ -287,7 +287,7 @@ static int run(int argc, char *argv[]) {
|
||||
"%s is not a block device.",
|
||||
device);
|
||||
|
||||
r = sd_device_new_from_devnum(&dev, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&dev, &st);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to detect device %s: %m", device);
|
||||
|
||||
|
@ -2711,7 +2711,7 @@ static int home_get_image_path_seat(Home *h, char **ret) {
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return -ENOTBLK;
|
||||
|
||||
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&d, &st);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -929,7 +929,7 @@ static int umount_by_device(sd_bus *bus, const char *what) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK),
|
||||
"Not a block device: %s", what);
|
||||
|
||||
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&d, &st);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device from device number: %m");
|
||||
|
||||
@ -1270,7 +1270,7 @@ static int discover_loop_backing_file(void) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid file type: %s", loop_dev);
|
||||
|
||||
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&d, &st);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device from device number: %m");
|
||||
|
||||
@ -1314,7 +1314,7 @@ static int discover_device(void) {
|
||||
"Invalid file type: %s",
|
||||
arg_mount_what);
|
||||
|
||||
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&d, &st);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device from device number: %m");
|
||||
|
||||
|
@ -532,7 +532,7 @@ int dissect_image(
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return -ENOTBLK;
|
||||
|
||||
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(&d, &st);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -136,7 +136,7 @@ static int device_new_from_dev_path(const char *devlink, sd_device **ret_device)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK),
|
||||
"%s does not point to a block device: %m", devlink);
|
||||
|
||||
r = sd_device_new_from_devnum(ret_device, 'b', st.st_rdev);
|
||||
r = sd_device_new_from_stat_rdev(ret_device, &st);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to initialize device from %s: %m", devlink);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user