/* * 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 . */ /* * 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 #include #ifndef S_IFDIR #define S_IFDIR 0040000 #endif int trustee_is_subdirs_option(char *s) { if (!s) return(0); 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(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 (tool_strsame(s, "ALL")) { *rights = TRUSTEE_RIGHT_ALL_386; return(0); } if (tool_strsame(s, "N") || tool_strsame(s, "NONE")) { *rights = TRUSTEE_RIGHT_ALL_386; return(0); } if (tool_strsame(s, "S") || tool_strsame(s, "SUPERVISOR")) { *rights |= TRUSTEE_RIGHT_SUPER; return(0); } if (tool_strsame(s, "R") || tool_strsame(s, "READ")) { *rights |= TRUSTEE_RIGHT_READ; return(0); } if (tool_strsame(s, "W") || tool_strsame(s, "WRITE")) { *rights |= TRUSTEE_RIGHT_WRITE; return(0); } if (tool_strsame(s, "C") || tool_strsame(s, "CREATE")) { *rights |= TRUSTEE_RIGHT_CREATE; return(0); } if (tool_strsame(s, "E") || tool_strsame(s, "ERASE") || tool_strsame(s, "D") || tool_strsame(s, "DELETE")) { *rights |= TRUSTEE_RIGHT_DELETE; return(0); } if (tool_strsame(s, "M") || tool_strsame(s, "MODIFY")) { *rights |= TRUSTEE_RIGHT_MODIFY; return(0); } if (tool_strsame(s, "F") || tool_strsame(s, "FILESCAN") || tool_strsame(s, "FILE") || tool_strsame(s, "SCAN")) { *rights |= TRUSTEE_RIGHT_SEARCH; return(0); } if (tool_strsame(s, "A") || tool_strsame(s, "ACCESS") || tool_strsame(s, "CONTROL") || tool_strsame(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 || tool_strsame(path, ".") || tool_strsame(path, ".\\") || tool_strsame(path, "./")) return(1); if (stat(path, &st) == 0) { if (st.st_mode & S_IFDIR) return(1); } return(0); }