Add GPL-2-or-later license headers to the DOS utility source files and document the purpose and local dependencies of each C, header and assembler file. Preserve the original Martin Stover copyright attribution for the historic MARS-NWE utility sources, including files that did not previously carry an explicit header but are part of the original tool set. Add Mario Fetka as the 2026 copyright holder for the current maintenance work, and use Mario-only headers for files without original Martin Stover ownership. Also add a root-level COPYING file containing the GPL-2 license text.
188 lines
5.2 KiB
C
188 lines
5.2 KiB
C
/*
|
|
* mars-nwe-dosutils - NetWare/DOS utility tools.
|
|
*
|
|
* Copyright (C) 2026 Mario Fetka
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/*
|
|
* Purpose: Shared trustee and rights helper implementation for GRANT, REMOVE and REVOKE style tools.
|
|
* Depends on: net.h, trustee.h, c32ncp.h callers, netcall.c requester helpers, tools.c shared utility routines.
|
|
*/
|
|
|
|
#include "net.h"
|
|
#include "trustee.h"
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
#ifndef S_IFDIR
|
|
#define S_IFDIR 0040000
|
|
#endif
|
|
|
|
|
|
|
|
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"));
|
|
}
|
|
|
|
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"));
|
|
}
|
|
|
|
int trustee_parse_right_word(char *s, uint16 *rights)
|
|
{
|
|
if (trustee_same(s, "ALL")) {
|
|
*rights = TRUSTEE_RIGHT_ALL_386;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "N") || trustee_same(s, "NONE")) {
|
|
*rights = TRUSTEE_RIGHT_ALL_386;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "S") || trustee_same(s, "SUPERVISOR")) {
|
|
*rights |= TRUSTEE_RIGHT_SUPER;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "R") || trustee_same(s, "READ")) {
|
|
*rights |= TRUSTEE_RIGHT_READ;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "W") || trustee_same(s, "WRITE")) {
|
|
*rights |= TRUSTEE_RIGHT_WRITE;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "C") || trustee_same(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")) {
|
|
*rights |= TRUSTEE_RIGHT_DELETE;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "M") || trustee_same(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")) {
|
|
*rights |= TRUSTEE_RIGHT_SEARCH;
|
|
return(0);
|
|
}
|
|
|
|
if (trustee_same(s, "A") || trustee_same(s, "ACCESS") ||
|
|
trustee_same(s, "CONTROL") || trustee_same(s, "ACCESSCONTROL")) {
|
|
*rights |= TRUSTEE_RIGHT_OWNER;
|
|
return(0);
|
|
}
|
|
|
|
return(-1);
|
|
}
|
|
|
|
void trustee_rights_bracket(uint16 rights, char *out)
|
|
{
|
|
out[0] = (rights & TRUSTEE_RIGHT_SUPER) ? 'S' : ' ';
|
|
out[1] = (rights & TRUSTEE_RIGHT_READ) ? 'R' : ' ';
|
|
out[2] = (rights & TRUSTEE_RIGHT_WRITE) ? 'W' : ' ';
|
|
out[3] = (rights & TRUSTEE_RIGHT_CREATE) ? 'C' : ' ';
|
|
out[4] = (rights & TRUSTEE_RIGHT_DELETE) ? 'E' : ' ';
|
|
out[5] = (rights & TRUSTEE_RIGHT_MODIFY) ? 'M' : ' ';
|
|
out[6] = (rights & TRUSTEE_RIGHT_SEARCH) ? 'F' : ' ';
|
|
out[7] = (rights & TRUSTEE_RIGHT_OWNER) ? 'A' : ' ';
|
|
out[8] = '\0';
|
|
}
|
|
|
|
uint32 trustee_lookup_object(char *name, uint16 *objtype, int objtype_given)
|
|
{
|
|
uint8 namebuf[48];
|
|
uint32 object_id;
|
|
|
|
strmaxcpy(namebuf, name, sizeof(namebuf) - 1);
|
|
upstr(namebuf);
|
|
|
|
if (objtype_given) {
|
|
return(ncp_17_35(namebuf, *objtype));
|
|
}
|
|
|
|
*objtype = TRUSTEE_BINDERY_USER;
|
|
object_id = ncp_17_35(namebuf, TRUSTEE_BINDERY_USER);
|
|
if (object_id)
|
|
return(object_id);
|
|
|
|
*objtype = TRUSTEE_BINDERY_GROUP;
|
|
object_id = ncp_17_35(namebuf, TRUSTEE_BINDERY_GROUP);
|
|
return(object_id);
|
|
}
|
|
|
|
int trustee_path_is_dir(char *path)
|
|
{
|
|
struct stat st;
|
|
|
|
if (!path || !*path || trustee_same(path, ".") || trustee_same(path, ".\\") ||
|
|
trustee_same(path, "./"))
|
|
return(1);
|
|
|
|
if (stat(path, &st) == 0) {
|
|
if (st.st_mode & S_IFDIR)
|
|
return(1);
|
|
}
|
|
|
|
return(0);
|
|
}
|
|
|