From 4bdb194630b57b983ccd67cf2ab0e691217ab36d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 19 Apr 2021 04:13:30 +0100 Subject: [PATCH] Implement permissions for AmigaOS. --- setter/src/amiga/attr.c | 2 +- setter/src/amiga/perms.c | 60 +++++++++++++++++++++++++++++++++++++++- setter/src/amiga/perms.h | 58 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 setter/src/amiga/perms.h diff --git a/setter/src/amiga/attr.c b/setter/src/amiga/attr.c index 068b8b3..56473c1 100644 --- a/setter/src/amiga/attr.c +++ b/setter/src/amiga/attr.c @@ -27,5 +27,5 @@ Copyright (C) 2011-2021 Natalia Portillo void FileAttributes(const char* path) { - // TODO + // Is in permissions } diff --git a/setter/src/amiga/perms.c b/setter/src/amiga/perms.c index 6fd4ae5..486383f 100644 --- a/setter/src/amiga/perms.c +++ b/setter/src/amiga/perms.c @@ -22,9 +22,67 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include +#include +#include +#include + +#include "perms.h" + #include "../include/defs.h" +#include "../log.h" void FilePermissions(const char* path) { - // TODO + BPTR pathLock; + BPTR dirLock; + int ret; + BPTR file; + int rc; + int cRc; + int i; + char buffer[256]; + + pathLock = Lock((CONST_STRPTR)path, SHARED_LOCK); + + if(!pathLock) + { + log_write("Error %d changing to specified path.\n", IoErr()); + return; + } + + CurrentDir(pathLock); + + dirLock = CreateDir((CONST_STRPTR) "PERMS"); + + if(!dirLock) + { + log_write("Error %d creating working directory.\n", IoErr()); + return; + } + + CurrentDir(dirLock); + + log_write("Creating permissions files.\n"); + + for(i = 0; i < KNOWN_AMIGA_PERMS; i++) + { + file = Open((CONST_STRPTR)amiga_perms[i].filename, MODE_NEWFILE); + rc = 0; + cRc = 0; + + if(!file) rc = IoErr(); + else + { + memset(buffer, 0, 256); + snprintf(buffer, 256, "%s.\n", amiga_perms[i].description); + Write(file, buffer, 256); + Close(file); + cRc = SetProtection((CONST_STRPTR)amiga_perms[i].filename, amiga_perms[i].mode); + if(!cRc) cRc = IoErr(); + } + + log_write( + "\t%s: name = \"%s\", rc = %d, cRc = %d\n", amiga_perms[i].description, amiga_perms[i].filename, rc, cRc); + } } diff --git a/setter/src/amiga/perms.h b/setter/src/amiga/perms.h new file mode 100644 index 0000000..4ca8063 --- /dev/null +++ b/setter/src/amiga/perms.h @@ -0,0 +1,58 @@ +/**************************************************************************** +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_AMIGA_PERMS_H_ +#define AARU_FSTESTER_SETTER_SRC_AMIGA_PERMS_H_ + +#include + +typedef struct +{ + char filename[256]; + char description[256]; + mode_t mode; +} amiga_perms_tests_t; + +#define KNOWN_AMIGA_PERMS 16 + +static const amiga_perms_tests_t amiga_perms[KNOWN_AMIGA_PERMS] = { + {"NONE", "File with no permissions set", 0}, + {"OR", "File can be read by others", FIBF_OTR_READ}, + {"OW", "File can be written by others", FIBF_OTR_WRITE}, + {"OE", "File can be executed by others", FIBF_OTR_EXECUTE}, + {"OD", "File can be deleted by others", FIBF_OTR_DELETE}, + {"GR", "File can be read by group", FIBF_GRP_READ}, + {"GW", "File can be written by group", FIBF_GRP_WRITE}, + {"GE", "File can be executed by group", FIBF_GRP_EXECUTE}, + {"GD", "File can be deleted by group", FIBF_GRP_DELETE}, + {"SCRIPT", "File is a script", FIBF_SCRIPT}, + {"PURE", "File is reentrant and re-executable", FIBF_PURE}, + {"ARCHIVE", "File has been archived", FIBF_ARCHIVE}, + {"READ", "File cannot be read", FIBF_READ}, + {"WRITE", "File cannot be written", FIBF_WRITE}, + {"EXECUTE", "File cannot be executed", FIBF_EXECUTE}, + {"DELETE", "File cannot be deleted", FIBF_DELETE}, +}; + +#endif // AARU_FSTESTER_SETTER_SRC_AMIGA_PERMS_H_