dosutils: factor shared helpers and update README

Move common DOS utility helper code into tools.c and expose it through
net.h.  This removes duplicated command-local helpers from GRANT,
RIGHTS, FLAG, FLAGDIR and the trustee helper layer.

The shared helpers cover case-insensitive argument comparison, help and
option detection, /FILES and /SUBDIRS parsing, current network directory
handle lookup, current volume prefix formatting, uppercase DOS path
copying, basename/header-path handling, wildcard detection and simple
path joining/splitting.

Keep the command frontends smaller and less coupled so the current
multicall utility can later be split into smaller grouped multicall
binaries, such as trustee tools, login/session tools and file/flag
tools.

Update the DOS utilities README for the newer Client32 and trustee
commands.  Document RIGHTS, GRANT, REVOKE and REMOVE in the status,
feature, command and install sections.  Add command reference entries
for the trustee tools, including Novell-style syntax, supported rights,
recursive/file options and missing-trustee behavior.

Also mention the shared trustee helper layer and common tools.c helpers
used by the newer command frontends.
This commit is contained in:
Mario Fetka
2026-05-24 20:45:56 +02:00
parent 4cafe16980
commit c50202e93b
9 changed files with 502 additions and 846 deletions

91
flag.c
View File

@@ -54,32 +54,6 @@ static uint32 flag_get_dword_lh(uint8 *p)
((uint32)p[3] << 24));
}
static int flag_get_current_drive(void)
{
REGS regs;
regs.h.ah = 0x19; /* DOS get current default drive */
int86(0x21, &regs, &regs); /* AL = 0 for A:, 1 for B:, ... */
return((int)regs.h.al);
}
static int flag_current_dhandle(uint8 *dhandle)
{
uint8 connid = 0;
uint8 flags = 0;
int drive;
drive = flag_get_current_drive();
if (get_drive_info((uint8)drive, &connid, dhandle, &flags))
return(-1);
if (!connid || (flags & 0x80))
return(-1);
return(0);
}
static int flag_add_handle_path(uint8 *p, uint8 dhandle, char *name)
{
int nlen;
@@ -115,11 +89,12 @@ static int flag_ncp87_obtain_attrs(char *name, uint32 *attrs)
uint16 len;
uint8 data[128];
} repl;
uint8 connid = 0;
uint8 dhandle = 0;
uint8 *p;
int hlen;
if (flag_current_dhandle(&dhandle))
if (tool_current_dhandle(&connid, &dhandle))
return(-1);
/*
@@ -169,11 +144,12 @@ static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
uint16 len;
uint8 data[8];
} repl;
uint8 connid = 0;
uint8 dhandle = 0;
uint8 *p;
int hlen;
if (flag_current_dhandle(&dhandle))
if (tool_current_dhandle(&connid, &dhandle))
return(-1);
/*
@@ -241,18 +217,6 @@ static int flag_ncp87_modify_attrs(char *name, uint32 attrs)
#define _A_ARCH 0x20
#endif
static int flag_same(char *a, char *b)
{
while (*a || *b) {
int ca = *a++;
int cb = *b++;
if (ca >= 'a' && ca <= 'z') ca -= 32;
if (cb >= 'a' && cb <= 'z') cb -= 32;
if (ca != cb) return(0);
}
return(1);
}
static void flag_help(void)
{
fprintf(stdout, "USAGE: FLAG [path [ option | [+|-] attribute(s) ] [SUB]]\n");
@@ -294,52 +258,52 @@ static int flag_attr_mask(char *s, uint32 *setbits, uint32 *clearbits)
if (!*p) return(-1);
if (flag_same(p, "RO")) {
if (tool_strsame(p, "RO")) {
if (set) {
*setbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else {
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
}
} else if (flag_same(p, "RW")) {
} else if (tool_strsame(p, "RW")) {
*clearbits |= (NWFA_RO | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "S")) {
} else if (tool_strsame(p, "S")) {
if (set) *setbits |= NWFA_S;
else *clearbits |= NWFA_S;
} else if (flag_same(p, "H")) {
} else if (tool_strsame(p, "H")) {
if (set) *setbits |= NWFA_H;
else *clearbits |= NWFA_H;
} else if (flag_same(p, "SY") || flag_same(p, "SYS") || flag_same(p, "SYSTEM")) {
} else if (tool_strsame(p, "SY") || tool_strsame(p, "SYS") || tool_strsame(p, "SYSTEM")) {
if (set) *setbits |= NWFA_SY;
else *clearbits |= NWFA_SY;
} else if (flag_same(p, "T")) {
} else if (tool_strsame(p, "T")) {
if (set) *setbits |= NWFA_T;
else *clearbits |= NWFA_T;
} else if (flag_same(p, "P")) {
} else if (tool_strsame(p, "P")) {
if (set) *setbits |= NWFA_P;
else *clearbits |= NWFA_P;
} else if (flag_same(p, "A")) {
} else if (tool_strsame(p, "A")) {
if (set) *setbits |= NWFA_A;
else *clearbits |= NWFA_A;
} else if (flag_same(p, "RA")) {
} else if (tool_strsame(p, "RA")) {
if (set) *setbits |= NWFA_RA;
else *clearbits |= NWFA_RA;
} else if (flag_same(p, "WA")) {
} else if (tool_strsame(p, "WA")) {
if (set) *setbits |= NWFA_WA;
else *clearbits |= NWFA_WA;
} else if (flag_same(p, "CI")) {
} else if (tool_strsame(p, "CI")) {
if (set) *setbits |= NWFA_CI;
else *clearbits |= NWFA_CI;
} else if (flag_same(p, "DI")) {
} else if (tool_strsame(p, "DI")) {
if (set) *setbits |= NWFA_DI;
else *clearbits |= NWFA_DI;
} else if (flag_same(p, "RI")) {
} else if (tool_strsame(p, "RI")) {
if (set) *setbits |= NWFA_RI;
else *clearbits |= NWFA_RI;
} else if (flag_same(p, "N") || flag_same(p, "NORMAL")) {
} else if (tool_strsame(p, "N") || tool_strsame(p, "NORMAL")) {
*clearbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
} else if (flag_same(p, "ALL")) {
} else if (tool_strsame(p, "ALL")) {
*setbits |= (NWFA_RO | NWFA_H | NWFA_SY | NWFA_A |
NWFA_S | NWFA_T | NWFA_P |
NWFA_RA | NWFA_WA | NWFA_CI | NWFA_DI | NWFA_RI);
@@ -389,15 +353,6 @@ static void flag_display_one_paged(char *name, uint32 attr,
}
static int flag_has_wildcards(char *s)
{
while (*s) {
if (*s == '*' || *s == '?') return(1);
s++;
}
return(0);
}
static int flag_list(char *pattern)
{
struct find_t ff;
@@ -479,19 +434,19 @@ int func_flag(int argc, char *argv[], int mode)
(void)mode;
if (argc > 1 && (flag_same(argv[1], "/?") || flag_same(argv[1], "-?") ||
flag_same(argv[1], "?"))) {
if (argc > 1 && (tool_strsame(argv[1], "/?") || tool_strsame(argv[1], "-?") ||
tool_strsame(argv[1], "?"))) {
flag_help();
return(0);
}
if (argc > 1) {
path = argv[1];
if (flag_same(path, "SUB")) path = "*.*";
if (tool_strsame(path, "SUB")) path = "*.*";
}
for (i = 2; i < argc; i++) {
if (flag_same(argv[i], "SUB")) continue;
if (tool_strsame(argv[i], "SUB")) continue;
rc = flag_attr_mask(argv[i], &setbits, &clearbits);
if (rc < 0) return(1);