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:
226
trustee.c
226
trustee.c
@@ -9,28 +9,34 @@
|
||||
#define S_IFDIR 0040000
|
||||
#endif
|
||||
|
||||
int trustee_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);
|
||||
}
|
||||
|
||||
int trustee_is_help(char *s)
|
||||
{
|
||||
if (!s) return(0);
|
||||
return(trustee_same(s, "/?") || trustee_same(s, "-?") || trustee_same(s, "?"));
|
||||
}
|
||||
|
||||
int trustee_is_option(char *s)
|
||||
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)
|
||||
{
|
||||
if (!s) return(0);
|
||||
return(s[0] == '/' || s[0] == '-');
|
||||
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)
|
||||
@@ -48,155 +54,6 @@ int trustee_is_files_option(char *s)
|
||||
trustee_same(s, "/F") || trustee_same(s, "-F"));
|
||||
}
|
||||
|
||||
static int trustee_get_current_drive(void)
|
||||
{
|
||||
REGS regs;
|
||||
|
||||
regs.h.ah = 0x19;
|
||||
int86(0x21, ®s, ®s);
|
||||
return((int)regs.h.al);
|
||||
}
|
||||
|
||||
int trustee_current_dhandle(uint8 *connid, uint8 *dhandle)
|
||||
{
|
||||
uint8 flags = 0;
|
||||
int drive = trustee_get_current_drive();
|
||||
|
||||
if (get_drive_info((uint8)drive, connid, dhandle, &flags))
|
||||
return(-1);
|
||||
|
||||
if (!*connid || (flags & 0x80))
|
||||
return(-1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int trustee_current_prefix(char *out, int max)
|
||||
{
|
||||
uint8 connid = 0;
|
||||
uint8 dhandle = 0;
|
||||
uint8 flags = 0;
|
||||
int drive;
|
||||
char server[52];
|
||||
char dpath[260];
|
||||
char volume[32];
|
||||
char *p;
|
||||
int i = 0;
|
||||
|
||||
if (!out || max < 8)
|
||||
return(-1);
|
||||
|
||||
out[0] = '\0';
|
||||
|
||||
drive = trustee_get_current_drive();
|
||||
if (get_drive_info((uint8)drive, &connid, &dhandle, &flags))
|
||||
return(-1);
|
||||
|
||||
if (!connid || (flags & 0x80))
|
||||
return(-1);
|
||||
|
||||
server[0] = '\0';
|
||||
if (get_fs_name(connid, server))
|
||||
server[0] = '\0';
|
||||
|
||||
dpath[0] = '\0';
|
||||
if (get_dir_path(dhandle, dpath) || !dpath[0])
|
||||
return(-1);
|
||||
|
||||
p = strchr(dpath, ':');
|
||||
if (!p)
|
||||
return(-1);
|
||||
|
||||
while (dpath + i < p && i < (int)sizeof(volume) - 1) {
|
||||
volume[i] = dpath[i];
|
||||
i++;
|
||||
}
|
||||
volume[i] = '\0';
|
||||
|
||||
if (!volume[0])
|
||||
return(-1);
|
||||
|
||||
if (server[0])
|
||||
sprintf(out, "%s/%s:", server, volume);
|
||||
else
|
||||
sprintf(out, "%s:", volume);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void trustee_upcopy(char *dst, char *src, int max)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (!src) src = "";
|
||||
|
||||
while (*src && i < max - 1) {
|
||||
char c = *src++;
|
||||
if (c == '/') c = '\\';
|
||||
if (c >= 'a' && c <= 'z') c -= 32;
|
||||
dst[i++] = c;
|
||||
}
|
||||
dst[i] = 0;
|
||||
}
|
||||
|
||||
void trustee_basename(char *dst, char *src, int max)
|
||||
{
|
||||
char up[260];
|
||||
char *p;
|
||||
|
||||
trustee_upcopy(up, src, sizeof(up));
|
||||
p = strrchr(up, '\\');
|
||||
if (!p) p = strrchr(up, ':');
|
||||
|
||||
if (p)
|
||||
strmaxcpy(dst, p + 1, max - 1);
|
||||
else
|
||||
strmaxcpy(dst, up, max - 1);
|
||||
}
|
||||
|
||||
void trustee_header_path(char *out, char *path, int max)
|
||||
{
|
||||
char prefix[90];
|
||||
char up[260];
|
||||
|
||||
if (trustee_current_prefix(prefix, sizeof(prefix)))
|
||||
prefix[0] = '\0';
|
||||
|
||||
trustee_upcopy(up, path, sizeof(up));
|
||||
|
||||
strmaxcpy(out, prefix, max - 1);
|
||||
if ((int)(strlen(out) + strlen(up)) < max - 1)
|
||||
strcat(out, up);
|
||||
}
|
||||
|
||||
void trustee_join_path(char *out, char *base, char *name, int max)
|
||||
{
|
||||
int len;
|
||||
|
||||
out[0] = '\0';
|
||||
strmaxcpy(out, base, max - 1);
|
||||
len = strlen(out);
|
||||
|
||||
if (len > 0 && out[len - 1] != '\\' && out[len - 1] != '/' &&
|
||||
out[len - 1] != ':') {
|
||||
if (len < max - 1) {
|
||||
out[len++] = '\\';
|
||||
out[len] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)(strlen(out) + strlen(name)) < max - 1)
|
||||
strcat(out, name);
|
||||
}
|
||||
|
||||
int trustee_is_dot_dir(char *name)
|
||||
{
|
||||
if (!name) return(0);
|
||||
if (name[0] == '.' && name[1] == '\0') return(1);
|
||||
if (name[0] == '.' && name[1] == '.' && name[2] == '\0') return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
int trustee_parse_right_word(char *s, uint16 *rights)
|
||||
{
|
||||
if (trustee_same(s, "ALL")) {
|
||||
@@ -306,36 +163,3 @@ int trustee_path_is_dir(char *path)
|
||||
return(0);
|
||||
}
|
||||
|
||||
int trustee_path_has_wildcards(char *path)
|
||||
{
|
||||
if (!path) return(0);
|
||||
while (*path) {
|
||||
if (*path == '*' || *path == '?') return(1);
|
||||
path++;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void trustee_parent_pattern(char *dir, char *pattern, char *path, int maxdir, int maxpat)
|
||||
{
|
||||
char tmp[260];
|
||||
char *p;
|
||||
|
||||
trustee_upcopy(tmp, path, sizeof(tmp));
|
||||
p = strrchr(tmp, '\\');
|
||||
if (!p) p = strrchr(tmp, ':');
|
||||
|
||||
if (p) {
|
||||
char save = *p;
|
||||
*p = '\0';
|
||||
strmaxcpy(pattern, p + 1, maxpat - 1);
|
||||
if (save == ':') {
|
||||
*p = ':';
|
||||
*(p + 1) = '\0';
|
||||
}
|
||||
strmaxcpy(dir, tmp, maxdir - 1);
|
||||
} else {
|
||||
strmaxcpy(dir, ".", maxdir - 1);
|
||||
strmaxcpy(pattern, tmp, maxpat - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user