After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-) The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine. The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames... Anyone any idea on how to do this? JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
Would it not just be easier to eliminate all characters you deem not to be "stupid" and then match against the remainder? ie. /[^a-zA-Z.]+/ and then go from there? On Wed, Jul 5, 2023 at 3:23 PM Jonathan Buzzard < jonathan.buzzard@strath.ac.uk> wrote:
After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-)
The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine.
The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames...
Anyone any idea on how to do this?
JAB.
-- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org
Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember.. this was an iterative progress ... 😉 😉 You're right, the doc's are not really self-explaining here.. from my personal notes I found a litte better example: In GPFS 3.5 we introduce an (optional) ESCAPE clause to the EXTERNAL LIST and EXTERNAL POOL rules, which allow the user-administrator to specify that path names and SHOW(strings) within the associated file lists are encoded using an encoding based on the RFC3986 URI-percent-encoding scheme. For example: RULE 'xp' EXTERNAL POOL 'pool-name' EXEC 'script-name' ESCAPE '%' RULE 'xl' EXTERNAL LIST 'list-name' EXEC 'script-name' ESCAPE '%/+@#' ESCAPE '%' specifies that all characters except the "unreserved" characters in the set a-zA-Z0-9-_.~ are encoded as %XX where XX comprises 2 hexadecimal digits. The GPFS ESCAPE clause allows you to add to the set of "unreserved" characters. For example, ESCAPE '%/+@#', specifies that none of the characters in "/+@#" are escaped, so that a path name like "/root/directory/@abc+def#ghi.jkl" will appear in a file list with no escape sequences, whereas under ESCAPE '%', specifying a rigorous RFC3986 encoding yields "%2Froot%2Fdirectory%2F%40abc%2Bdef%23ghi.jkl". at least for us, it was doing the trick (back then) by using ESCAPE.. Maybe it is useful for your case here as well cheers laff ________________________________ Von: gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> im Auftrag von Jonathan Buzzard <jonathan.buzzard@strath.ac.uk> Gesendet: Donnerstag, 6. Juli 2023 00:20 An: gpfsug main discussion list <gpfsug-discuss@gpfsug.org> Betreff: [EXTERNAL] [gpfsug-discuss] Special characters in filenames After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-) The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine. The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames... Anyone any idea on how to do this? JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org
Hi, not exactly to the subject, but here is a C++ function to check if a file name is "bad". It returns a string with the reason, or nullptr if it's fine: const char* hasGoodName(const std::string& name) const { if (isspace(name().front())) { static const char* reason = "spaceInFront"; return reason; } if (isspace(name().back())) { static const char* reason = "spaceInBack"; return reason; } // only relevant if files go to dCache... if (name().size() > (255 - sizeof(".(get)()(checksums)"))) { // to long for dot command magic static const char* reason = "tooLong"; return reason; } size_t n=0; // number of extension-bytes uint32_t code=0; for (auto c : name()) { if (n==0) { // not an extension byte if ((c & 0b1000'0000) == 0) { // ASCII if (! isprint(c)) { static const char* reason = "nonPrintableAScii"; return reason; } if (c == '/') { // this must not be! static const char* reason = "slashInName"; return reason; } } else if ((c & 0b1110'0000) == 0b1100'0000) { // one ext byte code = c & 0b0001'1111; n=1; } else if ((c & 0b1111'0000) == 0b1110'0000) { // two ext bytes code = c & 0b0000'1111; n=2; } else if ((c & 0b1111'1000) == 0b1111'0000) { // three ext bytes code = c & 0b0000'0111; n=3; } else { // no UTF8 coding static const char* reason = "nonUTFStarter"; return reason; } } else { // this is an extension byte if ((c & 0b1100'0000) == 0b1000'0000) { // and well-formed code = (code << 6) | (c & 0b0011'1111); // ' n--; if (n==0) {// last extension byte seen: code finished if (0x0080 <= code && code <= 0x009F) { static const char* reason = "C1ControlCode"; return reason; } else if ((0x200E <= code && code <= 0x200F) || (0x202A <= code && code <= 0x202E)){ static const char* reason = "directionMarks"; return reason; } else if ((0xFFFE <= (code&0xFFFF) && (code&0xFFFF) <= 0xFFFF) || (0xFDD0 <= code && code <= 0xFDEF)) { static const char* reason = "NonCharacter"; return reason; } else if (0xE000 <= code && code <= 0xF8FF) { static const char* reason = "privateUseUTF"; return reason; } else if (0xf0000 <= code && code <= 0xfffff) { static const char* reason = "privateUseAreaA"; return reason; } else if (0x100000 <= code && code <= 0x10fffd) { static const char* reason = "privateUseAreaB"; return reason; } else if (0x110000 <= code) { static const char* reason = "beyondLastPlane"; return reason; } } } else { // ill-formed static const char* reason = "missingExtByte"; return reason; } } } return nullptr; } ----- Original Message -----
From: "Jonathan Buzzard" <jonathan.buzzard@strath.ac.uk> To: "gpfsug-discuss" <gpfsug-discuss@gpfsug.org> Sent: Friday, 7 July, 2023 14:37:26 Subject: Re: [gpfsug-discuss] Special characters in filenames
[Invalid UTF-8]
_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org
The policy code uses a more or less standard linux regexp library, so your regular expressions used for grep should work. The catch is the policy file is preprocessed with M4 which makes writing regexs a bit tricky. I grabbed a comment from the code: Note: The policy SQL parser normally does M4 macro preprocessing with [ ] set as the quote characters. SOOOO.... we highly recommend you add an extra set of [ ] around your REGEX pattern string. Like this: ... WHERE REGEX(name,['^[a-z]*$']) only accept lowercase alphabetic file names Once you’ve gotten past M4, you can either match for not good characters or directly for bad characters REGEX(. FILENAME, [‘[^a-zA-Z0-9\_\-\.]’] ) ### match when you find a character not in the good set REGEX(. FILENAME, [‘[\n\*\\]’] ). ### match when you find a bad character I am not sure which is more difficult to enumerate. The ESCAPE clause described by Olaf is the trick we use to pass file names with bad characters through the surrounding scripts (like mmbackup, mmxcp, etc). There is code in samples/ilm that show how to use it. -Wayne From: gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> on behalf of Olaf Weiser <olaf.weiser@de.ibm.com> Date: Wednesday, July 5, 2023 at 7:06 PM To: gpfsug main discussion list <gpfsug-discuss@gpfsug.org> Subject: [EXTERNAL] Re: [gpfsug-discuss] Special characters in filenames Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember. . this was an iterative progress .. . 😉 😉 You're right, the doc's are ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. Report Suspicious <https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!1e-vr57TRvm6FYv7eAEko...> ‌ ZjQcmQRYFpfptBannerEnd Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember.. this was an iterative progress ... 😉 😉 You're right, the doc's are not really self-explaining here.. from my personal notes I found a litte better example: In GPFS 3.5 we introduce an (optional) ESCAPE clause to the EXTERNAL LIST and EXTERNAL POOL rules, which allow the user-administrator to specify that path names and SHOW(strings) within the associated file lists are encoded using an encoding based on the RFC3986 URI-percent-encoding scheme. For example: RULE 'xp' EXTERNAL POOL 'pool-name' EXEC 'script-name' ESCAPE '%' RULE 'xl' EXTERNAL LIST 'list-name' EXEC 'script-name' ESCAPE '%/+@#' ESCAPE '%' specifies that all characters except the "unreserved" characters in the set a-zA-Z0-9-_.~ are encoded as %XX where XX comprises 2 hexadecimal digits. The GPFS ESCAPE clause allows you to add to the set of "unreserved" characters. For example, ESCAPE '%/+@#', specifies that none of the characters in "/+@#" are escaped, so that a path name like "/root/directory/@abc+def#ghi.jkl" will appear in a file list with no escape sequences, whereas under ESCAPE '%', specifying a rigorous RFC3986 encoding yields "%2Froot%2Fdirectory%2F%40abc%2Bdef%23ghi.jkl". at least for us, it was doing the trick (back then) by using ESCAPE.. Maybe it is useful for your case here as well cheers laff ________________________________ Von: gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> im Auftrag von Jonathan Buzzard <jonathan.buzzard@strath.ac.uk> Gesendet: Donnerstag, 6. Juli 2023 00:20 An: gpfsug main discussion list <gpfsug-discuss@gpfsug.org> Betreff: [EXTERNAL] [gpfsug-discuss] Special characters in filenames After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-) The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine. The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames... Anyone any idea on how to do this? JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org<http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org>
The policy code uses a more or less standard linux regexp library, so your regular expressions used for grep should work. The catch is the policy file is preprocessed with M4 which makes writing regexs a bit tricky. I grabbed a comment from the code: The policy SQL parser normally does M4 macros processing with [ ] set as the quote characters. SOOOO…. We highly recommend you add an extra set of [ ] around your REGEX pattern string like this: . . . WHERE REGEX(name, [‘^[a-z]*$’]) To only match lowercase alphabetic names. Once you’ve gotten past M4, you can either match for not good characters or directly for bad characters REGEX(. FILENAME, [‘[^a-zA-Z0-9\_\-\.]’] ) ### match when you find a character not in the good set REGEX(. FILENAME, [‘[\n\*\\]’] ). ### match when you find a bad character I am not sure which is more difficult to enumerate. The ESCAPE clause described by Olaf is the trick we use to pass file names with bad characters through the surrounding scripts (like mmbackup, mmxcp, etc). There is code in samples/ilm that show how to use it. -Wayne From: gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> on behalf of Olaf Weiser <olaf.weiser@de.ibm.com> Date: Wednesday, July 5, 2023 at 7:06 PM To: gpfsug main discussion list <gpfsug-discuss@gpfsug.org> Subject: [EXTERNAL] Re: [gpfsug-discuss] Special characters in filenames Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember. . this was an iterative progress .. . 😉 😉 You're right, the doc's are ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. Report Suspicious <https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!1e-vr57TRvm6FYv7eAEko...> ‌ ZjQcmQRYFpfptBannerEnd Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember.. this was an iterative progress ... 😉 😉 You're right, the doc's are not really self-explaining here.. from my personal notes I found a litte better example: In GPFS 3.5 we introduce an (optional) ESCAPE clause to the EXTERNAL LIST and EXTERNAL POOL rules, which allow the user-administrator to specify that path names and SHOW(strings) within the associated file lists are encoded using an encoding based on the RFC3986 URI-percent-encoding scheme. For example: RULE 'xp' EXTERNAL POOL 'pool-name' EXEC 'script-name' ESCAPE '%' RULE 'xl' EXTERNAL LIST 'list-name' EXEC 'script-name' ESCAPE '%/+@#' ESCAPE '%' specifies that all characters except the "unreserved" characters in the set a-zA-Z0-9-_.~ are encoded as %XX where XX comprises 2 hexadecimal digits. The GPFS ESCAPE clause allows you to add to the set of "unreserved" characters. For example, ESCAPE '%/+@#', specifies that none of the characters in "/+@#" are escaped, so that a path name like "/root/directory/@abc+def#ghi.jkl" will appear in a file list with no escape sequences, whereas under ESCAPE '%', specifying a rigorous RFC3986 encoding yields "%2Froot%2Fdirectory%2F%40abc%2Bdef%23ghi.jkl". at least for us, it was doing the trick (back then) by using ESCAPE.. Maybe it is useful for your case here as well cheers laff ________________________________ Von: gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> im Auftrag von Jonathan Buzzard <jonathan.buzzard@strath.ac.uk> Gesendet: Donnerstag, 6. Juli 2023 00:20 An: gpfsug main discussion list <gpfsug-discuss@gpfsug.org> Betreff: [EXTERNAL] [gpfsug-discuss] Special characters in filenames After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-) The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine. The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames... Anyone any idea on how to do this? JAB. -- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org<http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org>
Building off of this you could use the file placement engine to give a bad pool name for files that have bad names... Then new files couldn't be created with bad names. However files can still be renamed so you need a policy to deal with those cases. Alec On Fri, Jul 7, 2023, 11:11 AM Wayne Sawdon <wsawdon@us.ibm.com> wrote:
The policy code uses a more or less standard linux regexp library, so your regular expressions used for grep should work. The catch is the policy file is preprocessed with M4 which makes writing regexs a bit tricky. I grabbed a comment from the code:
The policy SQL parser normally does M4 macros processing with [ ] set as the quote characters.
SOOOO…. We highly recommend you add an extra set of [ ] around your REGEX pattern string like this:
. . . WHERE REGEX(name, [‘^[a-z]*$’])
To only match lowercase alphabetic names.
Once you’ve gotten past M4, you can either match for not good characters or directly for bad characters
REGEX(. FILENAME, [‘[^a-zA-Z0-9\_\-\.]’] ) ### match when you find a character not in the good set
REGEX(. FILENAME, [‘[\n\*\\]’] ). ### match when you find a bad character
I am not sure which is more difficult to enumerate.
The ESCAPE clause described by Olaf is the trick we use to pass file names with bad characters through the surrounding scripts (like mmbackup, mmxcp, etc). There is code in samples/ilm that show how to use it.
-Wayne
*From: *gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> on behalf of Olaf Weiser <olaf.weiser@de.ibm.com> *Date: *Wednesday, July 5, 2023 at 7:06 PM *To: *gpfsug main discussion list <gpfsug-discuss@gpfsug.org> *Subject: *[EXTERNAL] Re: [gpfsug-discuss] Special characters in filenames
Hallo Jonathan, I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with ESCAPE In fact, as far as I remember. . this was an iterative progress .. . 😉 😉 You're right, the doc's are
ZjQcmQRYFpfptBannerStart
*This Message Is From an External Sender *
This message came from outside your organization.
* Report Suspicious * <https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!1e-vr57TRvm6FYv7eAEko...> ‌
ZjQcmQRYFpfptBannerEnd
Hallo Jonathan,
I haven't used it for a while, but I can remember a customer, where we masked "all" special characters with *ESCAPE*
In fact, as far as I remember.. this was an iterative progress ... 😉 😉
You're right, the doc's are not really self-explaining here..
from my personal notes I found a litte better example:
In GPFS 3.5 we introduce an (optional) ESCAPE clause to the EXTERNAL LIST and EXTERNAL POOL rules, which allow the user-administrator to specify that path names and SHOW(strings) within the associated file lists are encoded using an encoding based on the RFC3986 URI-percent-encoding scheme. For example:
RULE 'xp' EXTERNAL POOL 'pool-name' EXEC 'script-name' ESCAPE '%'
RULE 'xl' EXTERNAL LIST 'list-name' EXEC 'script-name' ESCAPE '%/+@#'
ESCAPE '%' specifies that all characters except the "unreserved" characters in the set a-zA-Z0-9-_.~ are encoded as %XX where XX comprises 2 hexadecimal digits. The GPFS ESCAPE clause allows you to add to the set of "unreserved" characters.
For example, ESCAPE '%/+@#', specifies that none of the characters in "/+@#" are escaped, so that a path name like "/root/directory/@abc+def#ghi.jkl" will appear in a file list with no escape sequences, whereas under ESCAPE '%', specifying a rigorous RFC3986 encoding yields "%2Froot%2Fdirectory%2F%40abc%2Bdef%23ghi.jkl".
at least for us, it was doing the trick (back then) by using ESCAPE..
Maybe it is useful for your case here as well
cheers
laff
------------------------------
*Von:* gpfsug-discuss <gpfsug-discuss-bounces@gpfsug.org> im Auftrag von Jonathan Buzzard <jonathan.buzzard@strath.ac.uk> *Gesendet:* Donnerstag, 6. Juli 2023 00:20 *An:* gpfsug main discussion list <gpfsug-discuss@gpfsug.org> *Betreff:* [EXTERNAL] [gpfsug-discuss] Special characters in filenames
After another support incident that eventually transpired to be down to the user using what I will call stupid characters in their filenames (we include a section on not doing this in our mandatory training so no excuse) I have been musing on using the policy engine to periodically produce lists of files that have stupid characters in their filenames so we can proactively educate the users and get them to rename their files to something sensible :-)
The issue is of course the stupid characters include all the regular expression wildcard characters in addition to \n, \r and backticks. I am coming up short on escaping them correctly in REGEX() for the policy engine.
The documentation appears to be devoid of help on the subject, because of course only an fool would be including these characters in their filenames...
Anyone any idea on how to do this?
JAB.
-- Jonathan A. Buzzard Tel: +44141-5483420 HPC System Administrator, ARCHIE-WeSt. University of Strathclyde, John Anderson Building, Glasgow. G4 0NG
_______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org _______________________________________________ gpfsug-discuss mailing list gpfsug-discuss at gpfsug.org http://gpfsug.org/mailman/listinfo/gpfsug-discuss_gpfsug.org
participants (5)
-
Alec -
Hannappel, Juergen -
Jonathan Buzzard -
Olaf Weiser -
Wayne Sawdon
