From f59b7ea474fab87c7615ed8c48c308558156efde Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 25 Apr 2021 20:00:07 +0100 Subject: [PATCH] Implement permissions for Atari ST. --- setter/src/atarist/CMakeLists.txt | 2 +- setter/src/atarist/perms.c | 69 ++++++++++++++++++++++++++++++- setter/src/atarist/perms.h | 53 ++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 setter/src/atarist/perms.h diff --git a/setter/src/atarist/CMakeLists.txt b/setter/src/atarist/CMakeLists.txt index 3f6944e..39e7b34 100644 --- a/setter/src/atarist/CMakeLists.txt +++ b/setter/src/atarist/CMakeLists.txt @@ -26,4 +26,4 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "MiNT") return() endif() -add_sources(attr.c attr.h deleted.c dirdepth.c filename.c files.c frag.c links.c os.c os.h perms.c rsrcfork.c sparse.c time.c tostime.h volume.c xattr.c) +add_sources(attr.c attr.h deleted.c dirdepth.c filename.c files.c frag.c links.c os.c os.h perms.c perms.h rsrcfork.c sparse.c time.c tostime.h volume.c xattr.c) diff --git a/setter/src/atarist/perms.c b/setter/src/atarist/perms.c index a9162ad..95cbef0 100644 --- a/setter/src/atarist/perms.c +++ b/setter/src/atarist/perms.c @@ -22,8 +22,75 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +#include "perms.h" + #include "../include/defs.h" +#include "../log.h" void FilePermissions(const char* path) -{ // TODO: MiNT. MagiC? +{ + long** cookieJar = _p_cookies; + long cookie; + int rc, cRc; + FILE* file; + char driveNo = path[0] - '@'; + + // Check for a cookie jar + if(*cookieJar == 0) return; + + // Check if MiNT or MagiC + rc = (Getcookie(C_MiNT, &cookie) == E_OK) || (Getcookie(C_MagX, &cookie) == E_OK) || + (Getcookie(C_MgMc, &cookie) == E_OK) || (Getcookie(C_MgMx, &cookie) == E_OK) || + (Getcookie(C_MgPC, &cookie) == E_OK); + + if(rc == 0) return; + + if(driveNo > 32) driveNo -= 32; + + Dsetdrv(driveNo); + Dsetpath("\\"); + + rc = Dcreate("PERMS"); + + if(rc != E_OK) + { + log_write("Error %d creating working directory.\n", rc); + return; + } + + rc = Dsetpath("PERMS"); + + if(rc != E_OK) + { + log_write("Error %d changing to working directory.\n", rc); + return; + } + + log_write("Creating permission files.\n"); + + for(i = 0; i < KNOWN_ATARI_PERMS; i++) + { + file = fopen(atari_perms[i].filename, "w+"); + rc = 0; + cRc = 0; + + if(!file) rc = errno; + else + { + fprintf(file, "%s.\n", atari_perms[i].description); + fclose(file); + cRc = Fchmod(atari_perms[i].filename, atari_perms[i].mode); + } + + log_write( + "\t%s: name = \"%s\", rc = %d, cRc = %d\n", atari_perms[i].description, atari_perms[i].filename, rc, cRc); + } } diff --git a/setter/src/atarist/perms.h b/setter/src/atarist/perms.h new file mode 100644 index 0000000..bf98bd8 --- /dev/null +++ b/setter/src/atarist/perms.h @@ -0,0 +1,53 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ License ] --------------------------------------------------------------- + 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 3 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 . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_SETTER_SRC_ATARI_PERMS_H_ +#define AARU_FSTESTER_SETTER_SRC_ATARI_PERMS_H_ + +typedef struct +{ + char filename[256]; + char description[256]; + mode_t mode; +} atari_perms_tests_t; + +#define KNOWN_ATARI_PERMS 14 + +static const atari_perms_tests_t atari_perms[KNOWN_ATARI_PERMS] = { + {"NONE", "File with no permissions", 0}, + {"04000", "File with set-user-ID", 04000}, + {"02000", "File with set-group-ID", 02000}, + {"01000", "File with sticky bit", 01000}, + {"00400", "File with read by owner", 00400}, + {"00200", "File with write by owner", 00200}, + {"00100", "File with execute by owner", 00100}, + {"00040", "File with read by group", 00040}, + {"00020", "File with write by group", 00020}, + {"00010", "File with execute by group", 00010}, + {"00004", "File with read by others", 00004}, + {"00002", "File with write by others", 00002}, + {"00001", "File with execute by others", 00001}, +}; + +#endif // AARU_FSTESTER_SETTER_SRC_ATARI_PERMS_H_