From cc3de0e658bb9acc2da163194baa7bb17f48658d Mon Sep 17 00:00:00 2001 From: petershh Date: Sun, 31 Jul 2022 16:19:31 +0300 Subject: Rename files --- src/shh-portable-utils/deps-exe/chmod | 4 +- src/shh-portable-utils/parse_mode_octal.c | 39 ++++++++ src/shh-portable-utils/parse_mode_symbolic.c | 127 +++++++++++++++++++++++++++ src/shh-portable-utils/parse_octal.c | 39 -------- src/shh-portable-utils/parse_symbolic.c | 127 --------------------------- 5 files changed, 168 insertions(+), 168 deletions(-) create mode 100644 src/shh-portable-utils/parse_mode_octal.c create mode 100644 src/shh-portable-utils/parse_mode_symbolic.c delete mode 100644 src/shh-portable-utils/parse_octal.c delete mode 100644 src/shh-portable-utils/parse_symbolic.c diff --git a/src/shh-portable-utils/deps-exe/chmod b/src/shh-portable-utils/deps-exe/chmod index 939c605..e765767 100644 --- a/src/shh-portable-utils/deps-exe/chmod +++ b/src/shh-portable-utils/deps-exe/chmod @@ -1,4 +1,4 @@ -parse_octal.o -parse_symbolic.o +parse_mode_octal.o +parse_mode_symbolic.o change_mode.o -lskarnet diff --git a/src/shh-portable-utils/parse_mode_octal.c b/src/shh-portable-utils/parse_mode_octal.c new file mode 100644 index 0000000..c969f5f --- /dev/null +++ b/src/shh-portable-utils/parse_mode_octal.c @@ -0,0 +1,39 @@ +#include +#include + +#include "shhfuncs.h" + +mode_t parse_octal(char const *raw_mode) +{ + mode_t mode = 0; + unsigned int m; + if (!uint0_oscan(raw_mode, &m)) + strerr_dief2x(100, "invalid mode: ", raw_mode); + + if (m & 0001) + mode |= S_IXOTH; + if (m & 0002) + mode |= S_IWOTH; + if (m & 0004) + mode |= S_IROTH; + if (m & 0010) + mode |= S_IXGRP; + if (m & 0020) + mode |= S_IWGRP; + if (m & 0040) + mode |= S_IRGRP; + if (m & 0100) + mode |= S_IXUSR; + if (m & 0200) + mode |= S_IWUSR; + if (m & 0400) + mode |= S_IRUSR; + if (m & 01000) + mode |= S_ISVTX; + if (m & 02000) + mode |= S_ISGID; + if (m & 04000) + mode |= S_ISUID; + + return mode; +} diff --git a/src/shh-portable-utils/parse_mode_symbolic.c b/src/shh-portable-utils/parse_mode_symbolic.c new file mode 100644 index 0000000..3c2ea94 --- /dev/null +++ b/src/shh-portable-utils/parse_mode_symbolic.c @@ -0,0 +1,127 @@ +#include +#include + +#include "shhfuncs.h" + +void parse_symbolic(char const *raw, genalloc *directives) +{ + char const *p = raw; + for (;;) { + chmod_directive d = CHMOD_DIRECTIVE_ZERO; + /* stage 1: parse 'who' list */ + for (;;) { + if (*p == 'u') + d.who |= S_IRWXU | S_ISUID; + else if (*p == 'g') + d.who |= S_IRWXG | S_ISGID; + else if (*p == 'o') + d.who |= S_IRWXO; + else if (*p == 'a') + d.who |= S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID; + else + break; + p++; + } + /* stage 2: actions. First cycle is out of the loop. */ + switch(*p) { + case '+': + case '-': + case '=': + d.action = *p; + break; + default: + strerr_dief2x(100, "invalid mode: ", raw); + } + p++; + for (;;) { + if (*p == 'u') + d.permcopy |= 1; + else if (*p == 'g') + d.permcopy |= 2; + else if (*p == 'o') + d.permcopy |= 4; + else if (*p == 'r') + d.perm |= S_IRUSR | S_IRGRP | S_IROTH; + else if (*p == 'w') + d.perm |= S_IWUSR | S_IWGRP | S_IWOTH; + else if (*p == 'x') + d.perm |= S_IXUSR | S_IXGRP | S_IXOTH; + else if (*p == 'X') + d.dir_x = 1; + else if (*p == 's') + d.perm |= S_ISUID | S_ISGID; + else if (*p == 't') + d.perm |= S_ISVTX; + else if (*p == ',') { + p++; + break; + } + else if (*p == '\0') { + if (d.perm && d.permcopy) + strerr_dief2x(100, "invalid mode: ", raw); + if (!genalloc_append(chmod_directive, directives, &d)) + strerr_diefu1sys(111, "parse mode"); + return; + } + p++; + } + + if (d.perm && d.permcopy) + strerr_dief2x(100, "invalid mode: ", raw); + if (!genalloc_append(chmod_directive, directives, &d)) + strerr_diefu1sys(111, "parse mode"); + + for (;;) { + d.action = d.perm = d.permcopy = d.dir_x = 0; + if (*p == '+' || *p == '-' || *p == '=') + d.action = *p; + else if (*p == ',') + break; + else if (*p == '\0') + return; + else + strerr_dief2x(100, "invalid mode: ", raw); + + p++; + + for (;;) { + if (*p == 'u') + d.permcopy |= 1; + else if (*p == 'g') + d.permcopy |= 2; + else if (*p == 'o') + d.permcopy |= 4; + else if (*p == 'r') + d.perm |= S_IRUSR | S_IRGRP | S_IROTH; + else if (*p == 'w') + d.perm |= S_IWUSR | S_IWGRP | S_IWOTH; + else if (*p == 'x') + d.perm |= S_IXUSR | S_IXGRP | S_IXOTH; + else if (*p == 'X') + d.dir_x = 1; + else if (*p == 's') + d.perm |= S_ISUID | S_ISGID; + else if (*p == 't') + d.perm |= S_ISVTX; + else if (*p == ',') { + p++; + break; + } + else if (*p == '\0') { + if (d.perm && d.permcopy) + strerr_dief2x(100, "invalid mode: ", raw); + if (!genalloc_append(chmod_directive, directives, &d)) + strerr_diefu1sys(111, "parse mode"); + return; + } + p++; + } + + if (d.perm && d.permcopy) + strerr_dief2x(100, "invalid mode: ", raw); + if (!genalloc_append(chmod_directive, directives, &d)) + strerr_diefu1sys(111, "parse mode"); + } + } +} + diff --git a/src/shh-portable-utils/parse_octal.c b/src/shh-portable-utils/parse_octal.c deleted file mode 100644 index c969f5f..0000000 --- a/src/shh-portable-utils/parse_octal.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -#include "shhfuncs.h" - -mode_t parse_octal(char const *raw_mode) -{ - mode_t mode = 0; - unsigned int m; - if (!uint0_oscan(raw_mode, &m)) - strerr_dief2x(100, "invalid mode: ", raw_mode); - - if (m & 0001) - mode |= S_IXOTH; - if (m & 0002) - mode |= S_IWOTH; - if (m & 0004) - mode |= S_IROTH; - if (m & 0010) - mode |= S_IXGRP; - if (m & 0020) - mode |= S_IWGRP; - if (m & 0040) - mode |= S_IRGRP; - if (m & 0100) - mode |= S_IXUSR; - if (m & 0200) - mode |= S_IWUSR; - if (m & 0400) - mode |= S_IRUSR; - if (m & 01000) - mode |= S_ISVTX; - if (m & 02000) - mode |= S_ISGID; - if (m & 04000) - mode |= S_ISUID; - - return mode; -} diff --git a/src/shh-portable-utils/parse_symbolic.c b/src/shh-portable-utils/parse_symbolic.c deleted file mode 100644 index 3c2ea94..0000000 --- a/src/shh-portable-utils/parse_symbolic.c +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include - -#include "shhfuncs.h" - -void parse_symbolic(char const *raw, genalloc *directives) -{ - char const *p = raw; - for (;;) { - chmod_directive d = CHMOD_DIRECTIVE_ZERO; - /* stage 1: parse 'who' list */ - for (;;) { - if (*p == 'u') - d.who |= S_IRWXU | S_ISUID; - else if (*p == 'g') - d.who |= S_IRWXG | S_ISGID; - else if (*p == 'o') - d.who |= S_IRWXO; - else if (*p == 'a') - d.who |= S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID; - else - break; - p++; - } - /* stage 2: actions. First cycle is out of the loop. */ - switch(*p) { - case '+': - case '-': - case '=': - d.action = *p; - break; - default: - strerr_dief2x(100, "invalid mode: ", raw); - } - p++; - for (;;) { - if (*p == 'u') - d.permcopy |= 1; - else if (*p == 'g') - d.permcopy |= 2; - else if (*p == 'o') - d.permcopy |= 4; - else if (*p == 'r') - d.perm |= S_IRUSR | S_IRGRP | S_IROTH; - else if (*p == 'w') - d.perm |= S_IWUSR | S_IWGRP | S_IWOTH; - else if (*p == 'x') - d.perm |= S_IXUSR | S_IXGRP | S_IXOTH; - else if (*p == 'X') - d.dir_x = 1; - else if (*p == 's') - d.perm |= S_ISUID | S_ISGID; - else if (*p == 't') - d.perm |= S_ISVTX; - else if (*p == ',') { - p++; - break; - } - else if (*p == '\0') { - if (d.perm && d.permcopy) - strerr_dief2x(100, "invalid mode: ", raw); - if (!genalloc_append(chmod_directive, directives, &d)) - strerr_diefu1sys(111, "parse mode"); - return; - } - p++; - } - - if (d.perm && d.permcopy) - strerr_dief2x(100, "invalid mode: ", raw); - if (!genalloc_append(chmod_directive, directives, &d)) - strerr_diefu1sys(111, "parse mode"); - - for (;;) { - d.action = d.perm = d.permcopy = d.dir_x = 0; - if (*p == '+' || *p == '-' || *p == '=') - d.action = *p; - else if (*p == ',') - break; - else if (*p == '\0') - return; - else - strerr_dief2x(100, "invalid mode: ", raw); - - p++; - - for (;;) { - if (*p == 'u') - d.permcopy |= 1; - else if (*p == 'g') - d.permcopy |= 2; - else if (*p == 'o') - d.permcopy |= 4; - else if (*p == 'r') - d.perm |= S_IRUSR | S_IRGRP | S_IROTH; - else if (*p == 'w') - d.perm |= S_IWUSR | S_IWGRP | S_IWOTH; - else if (*p == 'x') - d.perm |= S_IXUSR | S_IXGRP | S_IXOTH; - else if (*p == 'X') - d.dir_x = 1; - else if (*p == 's') - d.perm |= S_ISUID | S_ISGID; - else if (*p == 't') - d.perm |= S_ISVTX; - else if (*p == ',') { - p++; - break; - } - else if (*p == '\0') { - if (d.perm && d.permcopy) - strerr_dief2x(100, "invalid mode: ", raw); - if (!genalloc_append(chmod_directive, directives, &d)) - strerr_diefu1sys(111, "parse mode"); - return; - } - p++; - } - - if (d.perm && d.permcopy) - strerr_dief2x(100, "invalid mode: ", raw); - if (!genalloc_append(chmod_directive, directives, &d)) - strerr_diefu1sys(111, "parse mode"); - } - } -} - -- cgit v1.2.3