libdm: add "|" to _is_whitelisted_char()
PATCH 1/1 libdm: add "|" to _is_whitelisted_char()
Hello,
please find attached a silly one-liner that was mentioned on #device-mapper yesterday and discussed with asalor today.
It adds "|" to a whitelist of chars allowed in devnode names for the sake of legacy compatibility with EVMS2 LVM plugin which uses to name the nodes like "lvm2|vg|lv".
I'm going to add it to ALT Linux lvm2 package for that matter but would definitely prefer not to fork even a single byte for no good reason.
TIA
Signature · 2 lines
---- WBR, Michael Shigorin <[email protected]> ------ Linux.Kiev http://www.linux.kiev.ua/
From 6c36767acfbc6f72ad7ffed298200088b9bb123b Mon Sep 17 00:00:00 2001
From: Michael Shigorin <[email protected]>
Date: Fri, 23 Nov 2012 17:21:33 +0200
Subject: [PATCH] libdm: add "|" to _is_whitelisted_char()
The issue is that EVMS' lvm2 plugin would yield names like "/dev/mapper/lvm2|vg|lv" and the current libdevmapper will turn these down; this makes migrating legacy environments involving devmapper-aware tools in the target configuration a somewhat harder task than it might be.
There's a potential security consideration with any faulty scripts which wouldn't get device names quoted as noted by asalor on #device-mapper; this is rather mitigated by the fact that one needs to have EVMS activated for the devices in question, even if these are USB flash ones. Speaking of such scripts, these are prone to misbehave upon "=" either.
--- libdm/libdm-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libdm/libdm-common.c +1 -1
@@ -320,7 +320,7 @@ static int _is_whitelisted_char(char c)if ((c >='0' && c <='9' ) || (c >='A' && c <='Z' ) || (c >='a' && c <='z' ) || -strchr ("#+-.:=@_" , c) !=NULL ) +strchr ("#+-.:=@_|" , c) !=NULL )return 1 ;return 0 ;
Signature · 1 line
1.7.12.4
Quoted 7 lines · Michael Shigorin
Hello,
please find attached a silly one-liner that was mentioned on #device-mapper yesterday and discussed with asalor today.It adds "|" to a whitelist of chars allowed in devnode names for the sake of legacy compatibility with EVMS2 LVM plugin which uses to name the nodes like "lvm2|vg|lv".
Actually, that whitelist is taken from udev and any extra character not on the current whitelist is automatically mangled to a form that udev understands by default (which is \xNN, NN being a hex value of the character). So it's all done to conform with udev. Otherwise, if such mangling was not used, udev would replace any blacklisted character with an underscore "_".
Now, if you *really* intend to bypass this mangling and udev, you can use:
dmsetup <dm_command> --manglename none ...
If you have your libdevmapper *compiled with udev support* (configure --enable-udev_sync), then you also need to use extra --noudevrules (to bypass udev rules) and --verifyudev switches (to make a fallback to direct node/symlink creation):
dmsetup <dm_command> --manglename none --noudevrules --verifyudev ...
But, if your system uses udev, try to avoid this as much as possible! Bypassing udev has many side effects, like missing information in udev database (as the symlinks/nodes were not created by udev itself). And this database could be read by other tools and they simply won't see all the state. Reading udev database instead of scanning the /dev directly is very common these days.
Peter
Quoted 5 lines · Peter Rajnoha
Now, if you *really* intend to bypass this mangling and udev, you can use:
dmsetup <
dm_command> --manglename none ...
If you use libdevmapper to handle device-mapper devices, have a look at libdevmapper.h. You can bypass default mangling with dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE):
---
/*
* Mangling support
*
* Character whitelist: 0-9, A-Z, a-z, #+-.:=@_
* HEX mangling format: \xNN, NN being the hex value of the character.
* (whitelist and format supported by udev)
*/
typedef enum {
DM_STRING_MANGLING_NONE, /* do not mangle at all */
DM_STRING_MANGLING_AUTO, /* mangle only if not already mangled with hex, error when mixed */
DM_STRING_MANGLING_HEX /* always mangle with hex encoding, no matter what the input is */
} dm_string_mangling_t;
/*
* Set/get mangling mode used for device-mapper names and uuids. */
int dm_set_name_mangling_mode(dm_string_mangling_t name_mangling); dm_string_mangling_t dm_get_name_mangling_mode(void);
---
Peter