trustee: use shared tool helpers for generic path handling

Remove generic wrapper helpers from trustee.c and switch GRANT/REMOVE/REVOKE
callers to the shared tools.c helpers directly.

Keep trustee.c focused on Trustee/Rights-specific behavior such as option
parsing, rights parsing/formatting, object lookup and trustee path handling.
The generic string, current directory handle, uppercase and path helper logic
now lives in tools.c where it can be reused by other DOS utilities.
This commit is contained in:
Mario Fetka
2026-05-29 09:44:14 +02:00
parent b3cec8eecf
commit 9ef8aeccc0
4 changed files with 55 additions and 93 deletions

View File

@@ -53,7 +53,7 @@ static void remove_header_path(char *out, char *path, int max)
{
char *p;
trustee_header_path(out, path, max);
tool_header_path(out, path, max);
/* Novell REMOVE displays server and volume as SERVER/SYS: while
* RIGHTS uses SERVER\SYS:. Keep the rest of the path with DOS
@@ -127,12 +127,12 @@ static int remove_subdirs_inner(char *path, uint16 dhandle, uint32 object_id,
rc = 1;
}
trustee_join_path(pattern, path, "*.*", sizeof(pattern));
tool_join_path(pattern, path, "*.*", sizeof(pattern));
if (_dos_findfirst(pattern, _A_SUBDIR, &ff) == 0) {
do {
if ((ff.attrib & _A_SUBDIR) && !trustee_is_dot_dir(ff.name)) {
trustee_join_path(child, path, ff.name, sizeof(child));
if ((ff.attrib & _A_SUBDIR) && !tool_is_dot_dir(ff.name)) {
tool_join_path(child, path, ff.name, sizeof(child));
if (remove_subdirs_inner(child, dhandle, object_id, objtype, objname,
count, 1))
rc = 1;
@@ -165,8 +165,8 @@ static int remove_files(char *path, uint16 dhandle, uint32 object_id,
if (trustee_path_is_dir(path)) {
strmaxcpy(dir, path, sizeof(dir) - 1);
strmaxcpy(pat, "*.*", sizeof(pat) - 1);
} else if (trustee_path_has_wildcards(path)) {
trustee_parent_pattern(dir, pat, path, sizeof(dir), sizeof(pat));
} else if (tool_has_wildcards(path)) {
tool_parent_pattern(dir, pat, path, sizeof(dir), sizeof(pat));
} else {
if (remove_one(path, dhandle, object_id, objtype, objname, 1) == 0)
(*count)++;
@@ -175,11 +175,11 @@ static int remove_files(char *path, uint16 dhandle, uint32 object_id,
return(rc);
}
trustee_join_path(spec, dir, pat, sizeof(spec));
tool_join_path(spec, dir, pat, sizeof(spec));
if (_dos_findfirst(spec, _A_NORMAL | _A_HIDDEN | _A_SYSTEM | _A_ARCH, &ff) == 0) {
do {
if (!(ff.attrib & _A_SUBDIR)) {
trustee_join_path(target, dir, ff.name, sizeof(target));
tool_join_path(target, dir, ff.name, sizeof(target));
if (remove_one(target, dhandle, object_id, objtype, objname, 1) == 0)
(*count)++;
else
@@ -209,7 +209,7 @@ int func_remove(int argc, char *argv[], int mode)
(void)mode;
if (argc < 2 || trustee_is_help(argv[1])) {
if (argc < 2 || tool_is_help_arg(argv[1])) {
if (argc < 2) {
remove_usage_after_error();
return(1);
@@ -218,18 +218,18 @@ int func_remove(int argc, char *argv[], int mode)
return(argc < 2 ? 1 : 0);
}
if (i < argc && trustee_same(argv[i], "USER")) {
if (i < argc && tool_strsame(argv[i], "USER")) {
/* Novell treats "REMOVE USER FROM path" as an object lookup for
* USER, not as a grammar error. */
if ((i + 1) < argc && trustee_same(argv[i + 1], "FROM")) {
if ((i + 1) < argc && tool_strsame(argv[i + 1], "FROM")) {
objtype_given = 0;
} else {
objtype = TRUSTEE_BINDERY_USER;
objtype_given = 1;
i++;
}
} else if (i < argc && trustee_same(argv[i], "GROUP")) {
if ((i + 1) < argc && trustee_same(argv[i + 1], "FROM")) {
} else if (i < argc && tool_strsame(argv[i], "GROUP")) {
if ((i + 1) < argc && tool_strsame(argv[i + 1], "FROM")) {
objtype_given = 0;
} else {
objtype = TRUSTEE_BINDERY_GROUP;
@@ -245,7 +245,7 @@ int func_remove(int argc, char *argv[], int mode)
objname = argv[i++];
if (i < argc && trustee_same(argv[i], "FROM")) {
if (i < argc && tool_strsame(argv[i], "FROM")) {
i++;
if (i >= argc) {
remove_usage_after_error();
@@ -255,7 +255,7 @@ int func_remove(int argc, char *argv[], int mode)
}
while (i < argc) {
if (!trustee_is_option(argv[i])) {
if (!tool_is_option(argv[i])) {
remove_usage_after_error();
return(1);
}
@@ -281,7 +281,7 @@ int func_remove(int argc, char *argv[], int mode)
return(1);
}
if (trustee_current_dhandle(&connid, &dhandle)) {
if (tool_current_dhandle(&connid, &dhandle)) {
fprintf(stdout, "Error: Drive not mapped to network.\n");
return(1);
}
@@ -297,7 +297,7 @@ int func_remove(int argc, char *argv[], int mode)
return(1);
}
trustee_upcopy(objprint, objname, sizeof(objprint));
tool_upcopy(objprint, objname, sizeof(objprint));
if (use_subdirs)
rc = remove_subdirs(path, (uint16)dhandle, object_id, objtype, objprint, &count);

View File

@@ -75,7 +75,7 @@ static void revoke_header_path(char *out, char *path, int max)
{
char *p;
trustee_header_path(out, path, max);
tool_header_path(out, path, max);
/* Novell REVOKE displays server and volume as SERVER/SYS: while
* RIGHTS uses SERVER\SYS:. Keep the rest of the path with DOS
@@ -168,12 +168,12 @@ static int revoke_subdirs_inner(char *path, uint16 dhandle, uint32 object_id,
return(1);
}
trustee_join_path(pattern, path, "*.*", sizeof(pattern));
tool_join_path(pattern, path, "*.*", sizeof(pattern));
if (_dos_findfirst(pattern, _A_SUBDIR, &ff) == 0) {
do {
if ((ff.attrib & _A_SUBDIR) && !trustee_is_dot_dir(ff.name)) {
trustee_join_path(child, path, ff.name, sizeof(child));
if ((ff.attrib & _A_SUBDIR) && !tool_is_dot_dir(ff.name)) {
tool_join_path(child, path, ff.name, sizeof(child));
if (revoke_subdirs_inner(child, dhandle, object_id, revoke_mask,
count, 1))
return(1);
@@ -204,8 +204,8 @@ static int revoke_files(char *path, uint16 dhandle, uint32 object_id,
if (trustee_path_is_dir(path)) {
strmaxcpy(dir, path, sizeof(dir) - 1);
strmaxcpy(pat, "*.*", sizeof(pat) - 1);
} else if (trustee_path_has_wildcards(path)) {
trustee_parent_pattern(dir, pat, path, sizeof(dir), sizeof(pat));
} else if (tool_has_wildcards(path)) {
tool_parent_pattern(dir, pat, path, sizeof(dir), sizeof(pat));
} else {
if (revoke_one(path, dhandle, object_id, revoke_mask, 1) == 0)
(*count)++;
@@ -214,11 +214,11 @@ static int revoke_files(char *path, uint16 dhandle, uint32 object_id,
return(rc);
}
trustee_join_path(spec, dir, pat, sizeof(spec));
tool_join_path(spec, dir, pat, sizeof(spec));
if (_dos_findfirst(spec, _A_NORMAL | _A_HIDDEN | _A_SYSTEM | _A_ARCH, &ff) == 0) {
do {
if (!(ff.attrib & _A_SUBDIR)) {
trustee_join_path(target, dir, ff.name, sizeof(target));
tool_join_path(target, dir, ff.name, sizeof(target));
if (revoke_one(target, dhandle, object_id, revoke_mask, 1) == 0)
(*count)++;
else
@@ -250,7 +250,7 @@ int func_revoke(int argc, char *argv[], int mode)
(void)mode;
if (argc < 2 || trustee_is_help(argv[1])) {
if (argc < 2 || tool_is_help_arg(argv[1])) {
if (argc < 2)
revoke_usage_full(1, 1);
else
@@ -259,9 +259,9 @@ int func_revoke(int argc, char *argv[], int mode)
}
while (i < argc) {
if (trustee_same(argv[i], "FOR") || trustee_same(argv[i], "FROM"))
if (tool_strsame(argv[i], "FOR") || tool_strsame(argv[i], "FROM"))
break;
if (trustee_is_option(argv[i]))
if (tool_is_option(argv[i]))
break;
if (trustee_parse_right_word(argv[i], &rights)) {
fprintf(stdout, "Invalid right specified.\n\n");
@@ -277,7 +277,7 @@ int func_revoke(int argc, char *argv[], int mode)
return(1);
}
if (trustee_same(argv[i], "FOR")) {
if (tool_strsame(argv[i], "FOR")) {
i++;
if (i >= argc) {
revoke_usage_short(0, 1);
@@ -286,17 +286,17 @@ int func_revoke(int argc, char *argv[], int mode)
path = argv[i++];
}
if (i >= argc || !trustee_same(argv[i], "FROM")) {
if (i >= argc || !tool_strsame(argv[i], "FROM")) {
revoke_usage_short(0, 1);
return(1);
}
i++;
if (i < argc && trustee_same(argv[i], "USER")) {
if (i < argc && tool_strsame(argv[i], "USER")) {
objtype = TRUSTEE_BINDERY_USER;
objtype_given = 1;
i++;
} else if (i < argc && trustee_same(argv[i], "GROUP")) {
} else if (i < argc && tool_strsame(argv[i], "GROUP")) {
objtype = TRUSTEE_BINDERY_GROUP;
objtype_given = 1;
i++;
@@ -310,7 +310,7 @@ int func_revoke(int argc, char *argv[], int mode)
objname = argv[i++];
while (i < argc) {
if (!trustee_is_option(argv[i])) {
if (!tool_is_option(argv[i])) {
revoke_usage_short(0, 1);
return(1);
}
@@ -334,7 +334,7 @@ int func_revoke(int argc, char *argv[], int mode)
/* Novell REVOKE does not emit a grammar-specific message for /FILES plus
* /SUBDIRECTORIES. It reports the same directory trustee failure text. */
if (trustee_current_dhandle(&connid, &dhandle)) {
if (tool_current_dhandle(&connid, &dhandle)) {
fprintf(stdout, "Error: Drive not mapped to Network.\n");
return(1);
}
@@ -350,7 +350,7 @@ int func_revoke(int argc, char *argv[], int mode)
return(1);
}
trustee_upcopy(objprint, objname, sizeof(objprint));
tool_upcopy(objprint, objname, sizeof(objprint));
if (use_files && use_subdirs) {
fprintf(stdout, "\aNo trustee for the specified directory.\n");

View File

@@ -33,100 +33,73 @@
int trustee_same(char *a, char *b) { return(tool_strsame(a, b)); }
int trustee_is_help(char *s) { return(tool_is_help_arg(s)); }
int trustee_is_option(char *s) { return(tool_is_option(s)); }
int trustee_current_dhandle(uint8 *connid, uint8 *dhandle)
{
return(tool_current_dhandle(connid, dhandle));
}
void trustee_upcopy(char *dst, char *src, int max) { tool_upcopy(dst, src, max); }
void trustee_basename(char *dst, char *src, int max)
{
tool_basename(dst, src, max);
}
void trustee_header_path(char *out, char *path, int max)
{
tool_header_path(out, path, max);
}
void trustee_join_path(char *out, char *base, char *name, int max)
{
tool_join_path(out, base, name, max);
}
int trustee_is_dot_dir(char *name) { return(tool_is_dot_dir(name)); }
int trustee_path_has_wildcards(char *path) { return(tool_has_wildcards(path)); }
void trustee_parent_pattern(char *dir, char *pattern, char *path,
int maxdir, int maxpat)
{
tool_parent_pattern(dir, pattern, path, maxdir, maxpat);
}
int trustee_is_subdirs_option(char *s)
{
if (!s) return(0);
return(trustee_same(s, "/SUBDIRS") || trustee_same(s, "-SUBDIRS") ||
trustee_same(s, "/SUBDIRECTORIES") || trustee_same(s, "-SUBDIRECTORIES") ||
trustee_same(s, "/S") || trustee_same(s, "-S"));
return(tool_strsame(s, "/SUBDIRS") || tool_strsame(s, "-SUBDIRS") ||
tool_strsame(s, "/SUBDIRECTORIES") || tool_strsame(s, "-SUBDIRECTORIES") ||
tool_strsame(s, "/S") || tool_strsame(s, "-S"));
}
int trustee_is_files_option(char *s)
{
if (!s) return(0);
return(trustee_same(s, "/FILES") || trustee_same(s, "-FILES") ||
trustee_same(s, "/F") || trustee_same(s, "-F"));
return(tool_strsame(s, "/FILES") || tool_strsame(s, "-FILES") ||
tool_strsame(s, "/F") || tool_strsame(s, "-F"));
}
int trustee_parse_right_word(char *s, uint16 *rights)
{
if (trustee_same(s, "ALL")) {
if (tool_strsame(s, "ALL")) {
*rights = TRUSTEE_RIGHT_ALL_386;
return(0);
}
if (trustee_same(s, "N") || trustee_same(s, "NONE")) {
if (tool_strsame(s, "N") || tool_strsame(s, "NONE")) {
*rights = TRUSTEE_RIGHT_ALL_386;
return(0);
}
if (trustee_same(s, "S") || trustee_same(s, "SUPERVISOR")) {
if (tool_strsame(s, "S") || tool_strsame(s, "SUPERVISOR")) {
*rights |= TRUSTEE_RIGHT_SUPER;
return(0);
}
if (trustee_same(s, "R") || trustee_same(s, "READ")) {
if (tool_strsame(s, "R") || tool_strsame(s, "READ")) {
*rights |= TRUSTEE_RIGHT_READ;
return(0);
}
if (trustee_same(s, "W") || trustee_same(s, "WRITE")) {
if (tool_strsame(s, "W") || tool_strsame(s, "WRITE")) {
*rights |= TRUSTEE_RIGHT_WRITE;
return(0);
}
if (trustee_same(s, "C") || trustee_same(s, "CREATE")) {
if (tool_strsame(s, "C") || tool_strsame(s, "CREATE")) {
*rights |= TRUSTEE_RIGHT_CREATE;
return(0);
}
if (trustee_same(s, "E") || trustee_same(s, "ERASE") ||
trustee_same(s, "D") || trustee_same(s, "DELETE")) {
if (tool_strsame(s, "E") || tool_strsame(s, "ERASE") ||
tool_strsame(s, "D") || tool_strsame(s, "DELETE")) {
*rights |= TRUSTEE_RIGHT_DELETE;
return(0);
}
if (trustee_same(s, "M") || trustee_same(s, "MODIFY")) {
if (tool_strsame(s, "M") || tool_strsame(s, "MODIFY")) {
*rights |= TRUSTEE_RIGHT_MODIFY;
return(0);
}
if (trustee_same(s, "F") || trustee_same(s, "FILESCAN") ||
trustee_same(s, "FILE") || trustee_same(s, "SCAN")) {
if (tool_strsame(s, "F") || tool_strsame(s, "FILESCAN") ||
tool_strsame(s, "FILE") || tool_strsame(s, "SCAN")) {
*rights |= TRUSTEE_RIGHT_SEARCH;
return(0);
}
if (trustee_same(s, "A") || trustee_same(s, "ACCESS") ||
trustee_same(s, "CONTROL") || trustee_same(s, "ACCESSCONTROL")) {
if (tool_strsame(s, "A") || tool_strsame(s, "ACCESS") ||
tool_strsame(s, "CONTROL") || tool_strsame(s, "ACCESSCONTROL")) {
*rights |= TRUSTEE_RIGHT_OWNER;
return(0);
}
@@ -173,8 +146,8 @@ int trustee_path_is_dir(char *path)
{
struct stat st;
if (!path || !*path || trustee_same(path, ".") || trustee_same(path, ".\\") ||
trustee_same(path, "./"))
if (!path || !*path || tool_strsame(path, ".") || tool_strsame(path, ".\\") ||
tool_strsame(path, "./"))
return(1);
if (stat(path, &st) == 0) {

View File

@@ -43,22 +43,11 @@
TRUSTEE_RIGHT_DELETE | TRUSTEE_RIGHT_MODIFY | \
TRUSTEE_RIGHT_SEARCH | TRUSTEE_RIGHT_OWNER)
int trustee_same(char *a, char *b);
int trustee_is_help(char *s);
int trustee_is_option(char *s);
int trustee_is_subdirs_option(char *s);
int trustee_is_files_option(char *s);
int trustee_current_dhandle(uint8 *connid, uint8 *dhandle);
void trustee_upcopy(char *dst, char *src, int max);
void trustee_basename(char *dst, char *src, int max);
void trustee_header_path(char *out, char *path, int max);
void trustee_join_path(char *out, char *base, char *name, int max);
int trustee_is_dot_dir(char *name);
int trustee_parse_right_word(char *s, uint16 *rights);
void trustee_rights_bracket(uint16 rights, char *out);
uint32 trustee_lookup_object(char *name, uint16 *objtype, int objtype_given);
int trustee_path_is_dir(char *path);
int trustee_path_has_wildcards(char *path);
void trustee_parent_pattern(char *dir, char *pattern, char *path, int maxdir, int maxpat);
#endif