summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmds/ntux_cmd_chmod.c78
1 files changed, 60 insertions, 18 deletions
diff --git a/src/cmds/ntux_cmd_chmod.c b/src/cmds/ntux_cmd_chmod.c
index 04ebad6..7be2bc8 100644
--- a/src/cmds/ntux_cmd_chmod.c
+++ b/src/cmds/ntux_cmd_chmod.c
@@ -22,10 +22,16 @@
#include "ntux_driver_impl.h"
#include "ntux_nolibc_impl.h"
#include "ntux_errinfo_impl.h"
+#include "nolibc/stdbool.h"
#define __SID_SYSTEM {1,1,{{0,0,0,0,0,5}},{18}}
#define __SID_ADMINISTRATORS {1,2,{{0,0,0,0,0,5}},{32,544}}
+#define NTUX_OPT_MODE_NEUTRAL (0)
+#define NTUX_OPT_MODE_EQUAL (1)
+#define NTUX_OPT_MODE_PLUS (2)
+#define NTUX_OPT_MODE_MINUS (3)
+
static const nt_sid sid_system = __SID_SYSTEM;
static const nt_sid_os sid_admins = __SID_ADMINISTRATORS;
@@ -61,6 +67,9 @@ int ntux_cmd_chmod(const struct ntux_driver_ctx * dctx, const char * dunit)
int32_t status;
int fdout;
int fdcwd;
+ int optmode;
+ const char * strmode;
+ const char * chmode;
const unsigned char * unit;
nt_sd * srcsd;
nt_sd_common_buffer dstsd;
@@ -77,24 +86,57 @@ int ntux_cmd_chmod(const struct ntux_driver_ctx * dctx, const char * dunit)
int fd = -1;
struct __ofd * ofd = 0;
void * hasync = 0;
- uint32_t buf[0x300];
-
- /* ACE propagation: +p, -p */
- if (!dctx->cctx->strmode)
- ace_flags = 0;
-
- else if (!strcmp(dctx->cctx->strmode,"+p"))
- ace_flags = NT_ACE_CONTAINER_INHERIT | NT_ACE_OBJECT_INHERIT;
-
- else if (!strcmp(dctx->cctx->strmode,"-p"))
- ace_flags = 0;
-
- else
- return ntux_cmd_chmod_ret(
- 0,0,0,
- NTUX_CUSTOM_ERROR(
- dctx,
- NTUX_ERR_FLEE_ERROR));
+ uint32_t buf[0x300] = {0};
+
+ /* strmode */
+ strmode = dctx->cctx->strmode ? dctx->cctx->strmode : (char *)buf;
+ optmode = NTUX_OPT_MODE_NEUTRAL;
+ ace_flags = 0;
+
+ for (chmode=strmode; *chmode; chmode++) {
+ switch (*chmode) {
+ case '=':
+ optmode = NTUX_OPT_MODE_EQUAL;
+ ace_flags = 0;
+ break;
+
+ case '+':
+ optmode = NTUX_OPT_MODE_PLUS;
+ break;
+
+ case '-':
+ optmode = NTUX_OPT_MODE_MINUS;
+ break;
+
+ case 'p':
+ switch (optmode) {
+ case NTUX_OPT_MODE_EQUAL:
+ case NTUX_OPT_MODE_PLUS:
+ ace_flags = NT_ACE_CONTAINER_INHERIT | NT_ACE_OBJECT_INHERIT;
+ break;
+
+ case NTUX_OPT_MODE_MINUS:
+ ace_flags = 0;
+ break;
+
+ default:
+ return ntux_cmd_chmod_ret(
+ 0,0,0,
+ NTUX_CUSTOM_ERROR(
+ dctx,
+ NTUX_ERR_FLEE_ERROR));
+ }
+
+ break;
+
+ default:
+ return ntux_cmd_chmod_ret(
+ 0,0,0,
+ NTUX_CUSTOM_ERROR(
+ dctx,
+ NTUX_ERR_FLEE_ERROR));
+ }
+ }
/* initial --owner and --group support: Administrators, SYSTEM */
owner = 0;