From 3bb01f5f631992f37a0caa53118e42bf7928f1a9 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Tue, 28 Apr 2026 20:56:04 +0200 Subject: [PATCH] Apply patch: ncpfs-hg-commit-445.patch --- .../ncpfs-2.2.6-r6/ncpfs-hg-commit-445.patch | 146 ++++++++++++++++++ lib/strops.c | 112 ++++++++------ 2 files changed, 214 insertions(+), 44 deletions(-) create mode 100644 .patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-445.patch diff --git a/.patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-445.patch b/.patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-445.patch new file mode 100644 index 0000000..bbcc02d --- /dev/null +++ b/.patches/ncpfs-2.2.6-r6/ncpfs-hg-commit-445.patch @@ -0,0 +1,146 @@ +changeset: 445:66c5f4287bbb +user: Petr Vandrovec +date: Sat Jul 23 21:58:13 2005 +0100 +files: lib/strops.c +description: +Improve ncp_str_to_perms - now it accepts both [RFA] and RFA, +and you can use both nothing, space and '-' for flags which +are not set. + + +diff -r 34ddb26e48fa -r 66c5f4287bbb lib/strops.c +--- a/lib/strops.c Mon Jul 11 02:36:37 2005 +0100 ++++ b/lib/strops.c Sat Jul 23 21:58:13 2005 +0100 +@@ -44,6 +44,7 @@ + + #include + #include ++#include + + #include "private/libintl.h" + #define _(X) dgettext(NCPFS_PACKAGE, (X)) +@@ -419,56 +420,79 @@ char* ncp_perms_to_str(char r[11], const + } + + /* The following function converts a rights string of format [SRWCEMFA] +- into an integer. It will tolerate spaces, lower case and repeated +- letters, even if this takes the length well over 10 characters, but +- must be terminated with square brackets. If such a string containing +- spaces is given as a command line option it will have to be quoted. */ ++ or SRWCEMFA into an integer. It will tolerate spaces, lower case and ++ repeated letters, even if this takes the length well over 10 characters. ++ For unset rights you can use spaces or dashes. For no rights you can ++ use either empty string, '-' or '[]' (or their combination, '[-]' or '[ ]'). */ + + int ncp_str_to_perms(const char *r, u_int16_t *rights) + { + u_int16_t result = 0; +- +- if (*r == '[') { +- do { +- ++r; +- switch (*r) { +- case ' ' : +- case ']' : +- break; +- case 's' : +- case 'S' : +- result |= NCP_PERM_SUPER; break; +- case 'r' : +- case 'R' : +- result |= NCP_PERM_READ; break; +- case 'w' : +- case 'W' : +- result |= NCP_PERM_WRITE; break; +- case 'c' : +- case 'C' : +- result |= NCP_PERM_CREATE; break; +- case 'e' : +- case 'E' : +- result |= NCP_PERM_DELETE; break; +- case 'm' : +- case 'M' : +- result |= NCP_PERM_MODIFY; break; +- case 'f' : +- case 'F' : +- result |= NCP_PERM_SEARCH; break; +- case 'a' : +- case 'A' : +- result |= NCP_PERM_OWNER; break; +- default : ++ int state = 0; ++ ++ while (*r) { ++ int c = *r++; ++ ++ c = toupper(c); ++ if (isspace(c)) { ++ continue; ++ } ++ switch (c) { ++ case '[': ++ if (state != 0) { + return -1; +- } +- } while (*r != ']'); +- /* Now to be generous and ignore trailing spaces */ +- do { ++r; } while (*r == ' '); +- if (*r == '\0') { +- *rights = result; +- return 0; ++ } ++ state = 2; ++ continue; ++ case ']': ++ if (state != 2 && state != 3) { ++ return -1; ++ } ++ state = 4; ++ continue; ++ case '-': ++ break; ++ case 'S': ++ result |= NCP_PERM_SUPER; ++ break; ++ case 'R': ++ result |= NCP_PERM_READ; ++ break; ++ case 'W': ++ result |= NCP_PERM_WRITE; ++ break; ++ case 'C': ++ result |= NCP_PERM_CREATE; ++ break; ++ case 'E': ++ result |= NCP_PERM_DELETE; ++ break; ++ case 'M': ++ result |= NCP_PERM_MODIFY; ++ break; ++ case 'F': ++ result |= NCP_PERM_SEARCH; ++ break; ++ case 'A': ++ result |= NCP_PERM_OWNER; ++ break; ++ default: ++ return -1; + } ++ state |= 1; ++ } ++ /* These states are illegal: ++ state == 2 => [ ++ state == 3 => [SRWCEMFA ++ state == 5 => [SRWCEMFA]SRW ++ These states are allowed: ++ state == 0 => ++ state == 1 => SRWCEMFA ++ state == 4 => [SRWCEMFA] ++ */ ++ if (state == 0 || state == 1 || state == 4) { ++ *rights = result; ++ return 0; + } + return -1; + } + diff --git a/lib/strops.c b/lib/strops.c index a313dbd..a65e766 100644 --- a/lib/strops.c +++ b/lib/strops.c @@ -44,6 +44,7 @@ #include #include +#include #include "private/libintl.h" #define _(X) dgettext(NCPFS_PACKAGE, (X)) @@ -419,56 +420,79 @@ char* ncp_perms_to_str(char r[11], const u_int16_t rights) } /* The following function converts a rights string of format [SRWCEMFA] - into an integer. It will tolerate spaces, lower case and repeated - letters, even if this takes the length well over 10 characters, but - must be terminated with square brackets. If such a string containing - spaces is given as a command line option it will have to be quoted. */ + or SRWCEMFA into an integer. It will tolerate spaces, lower case and + repeated letters, even if this takes the length well over 10 characters. + For unset rights you can use spaces or dashes. For no rights you can + use either empty string, '-' or '[]' (or their combination, '[-]' or '[ ]'). */ int ncp_str_to_perms(const char *r, u_int16_t *rights) { u_int16_t result = 0; + int state = 0; - if (*r == '[') { - do { - ++r; - switch (*r) { - case ' ' : - case ']' : - break; - case 's' : - case 'S' : - result |= NCP_PERM_SUPER; break; - case 'r' : - case 'R' : - result |= NCP_PERM_READ; break; - case 'w' : - case 'W' : - result |= NCP_PERM_WRITE; break; - case 'c' : - case 'C' : - result |= NCP_PERM_CREATE; break; - case 'e' : - case 'E' : - result |= NCP_PERM_DELETE; break; - case 'm' : - case 'M' : - result |= NCP_PERM_MODIFY; break; - case 'f' : - case 'F' : - result |= NCP_PERM_SEARCH; break; - case 'a' : - case 'A' : - result |= NCP_PERM_OWNER; break; - default : - return -1; - } - } while (*r != ']'); - /* Now to be generous and ignore trailing spaces */ - do { ++r; } while (*r == ' '); - if (*r == '\0') { - *rights = result; - return 0; + while (*r) { + int c = *r++; + + c = toupper(c); + if (isspace(c)) { + continue; } + switch (c) { + case '[': + if (state != 0) { + return -1; + } + state = 2; + continue; + case ']': + if (state != 2 && state != 3) { + return -1; + } + state = 4; + continue; + case '-': + break; + case 'S': + result |= NCP_PERM_SUPER; + break; + case 'R': + result |= NCP_PERM_READ; + break; + case 'W': + result |= NCP_PERM_WRITE; + break; + case 'C': + result |= NCP_PERM_CREATE; + break; + case 'E': + result |= NCP_PERM_DELETE; + break; + case 'M': + result |= NCP_PERM_MODIFY; + break; + case 'F': + result |= NCP_PERM_SEARCH; + break; + case 'A': + result |= NCP_PERM_OWNER; + break; + default: + return -1; + } + state |= 1; + } + /* These states are illegal: + state == 2 => [ + state == 3 => [SRWCEMFA + state == 5 => [SRWCEMFA]SRW + These states are allowed: + state == 0 => + state == 1 => SRWCEMFA + state == 4 => [SRWCEMFA] + */ + if (state == 0 || state == 1 || state == 4) { + *rights = result; + return 0; } return -1; }