diff --git a/setter/CMakeLists.txt b/setter/CMakeLists.txt index 6dceac7..620a44f 100644 --- a/setter/CMakeLists.txt +++ b/setter/CMakeLists.txt @@ -3,4 +3,4 @@ project(setter C) set(CMAKE_C_STANDARD 90) -add_executable(setter src/include/consts.h src/include/defs.h src/main.h src/dosos2.h src/os2_16.h src/os2_32.h src/main.c src/dos.c src/os2_16.c src/os2_32.c src/win32.c src/win32.h src/macos.c src/macos.h src/unix/unix.h src/linux/linux.h src/netware.c src/netware.h src/linux/xattr.c src/linux/xattr.c src/linux/sparse.c src/linux/attr.c src/unix/os.c src/unix/volume.c src/unix/attr.c src/unix/perms.c src/unix/xattr.c src/unix/rsrcfork.c src/unix/filename.c src/unix/time.c src/unix/dirdepth.c src/unix/frag.c src/unix/sparse.c src/unix/links.c src/unix/files.c src/unix/deleted.c) \ No newline at end of file +add_executable(setter src/include/consts.h src/include/defs.h src/main.h src/dosos2.h src/os2_16.h src/os2_32.h src/main.c src/dos.c src/os2_16.c src/os2_32.c src/win32.c src/win32.h src/macos.c src/macos.h src/unix/unix.h src/linux/linux.h src/netware.c src/netware.h src/linux/xattr.c src/linux/xattr.c src/linux/sparse.c src/linux/attr.c src/unix/os.c src/unix/volume.c src/unix/attr.c src/unix/perms.c src/unix/xattr.c src/unix/rsrcfork.c src/unix/filename.c src/unix/time.c src/unix/dirdepth.c src/unix/frag.c src/unix/sparse.c src/unix/links.c src/unix/files.c src/unix/deleted.c src/unix/perms.h src/linux/attr.h) \ No newline at end of file diff --git a/setter/src/unix/perms.c b/setter/src/unix/perms.c index 6b5123c..fbd1f1b 100644 --- a/setter/src/unix/perms.c +++ b/setter/src/unix/perms.c @@ -34,6 +34,8 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include +#include "perms.h" + #include "../include/defs.h" void FilePermissions(const char* path) @@ -42,6 +44,7 @@ void FilePermissions(const char* path) FILE* file; int rc; int cRc; + int i; ret = chdir(path); @@ -69,161 +72,22 @@ void FilePermissions(const char* path) printf("Creating attributes files.\n"); - file = fopen("NONE", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else + for(i = 0; i < KNOWN_UNIX_PERMS; i++) { - fprintf(file, "File with no permissions.\n"); - fclose(file); - cRc = chmod("NONE", 0); - } - printf("\tFile with no permissions: name = \"%s\", rc = %d, cRc = %d\n", "NONE", rc, cRc); + file = fopen(unix_perms[i].filename, "w+"); + rc = 0; + cRc = 0; - file = fopen("04000", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with set-user-ID.\n"); - fclose(file); - cRc = chmod("04000", 04000); - } - printf("\tFile with set-user-ID: name = \"%s\", rc = %d, cRc = %d\n", "04000", rc, cRc); + if(!file) rc = errno; + else + { + fprintf(file, "%s.\n", unix_perms[i].description); + fclose(file); + cRc = chmod(unix_perms[i].filename, unix_perms[i].mode); + } - file = fopen("02000", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with set-group-ID.\n"); - fclose(file); - cRc = chmod("02000", 02000); + printf("\t%s: name = \"%s\", rc = %d, cRc = %d\n", unix_perms[i].description, unix_perms[i].filename, rc, cRc); } - printf("\tFile with set-group-ID: name = \"%s\", rc = %d, cRc = %d\n", "02000", rc, cRc); - - file = fopen("01000", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with sticky bit.\n"); - fclose(file); - cRc = chmod("01000", 01000); - } - printf("\tFile with sticky bit: name = \"%s\", rc = %d, cRc = %d\n", "01000", rc, cRc); - - file = fopen("00400", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with read by owner.\n"); - fclose(file); - cRc = chmod("00400", 00400); - } - printf("\tFile with read by owner: name = \"%s\", rc = %d, cRc = %d\n", "00400", rc, cRc); - - file = fopen("00200", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with write by owner.\n"); - fclose(file); - cRc = chmod("00200", 00200); - } - printf("\tFile with write by owner: name = \"%s\", rc = %d, cRc = %d\n", "00200", rc, cRc); - - file = fopen("00100", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with execute by owner.\n"); - fclose(file); - cRc = chmod("00100", 00100); - } - printf("\tFile with execute by owner: name = \"%s\", rc = %d, cRc = %d\n", "00100", rc, cRc); - - file = fopen("00040", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with read by group.\n"); - fclose(file); - cRc = chmod("00040", 00040); - } - printf("\tFile with read by group: name = \"%s\", rc = %d, cRc = %d\n", "00040", rc, cRc); - - file = fopen("00020", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with write by group.\n"); - fclose(file); - cRc = chmod("00020", 00020); - } - printf("\tFile with write by group: name = \"%s\", rc = %d, cRc = %d\n", "00020", rc, cRc); - - file = fopen("00010", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with execute by group.\n"); - fclose(file); - cRc = chmod("00010", 00010); - } - printf("\tFile with execute by group: name = \"%s\", rc = %d, cRc = %d\n", "00010", rc, cRc); - - file = fopen("00004", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with read by others.\n"); - fclose(file); - cRc = chmod("00004", 00004); - } - printf("\tFile with read by others: name = \"%s\", rc = %d, cRc = %d\n", "00004", rc, cRc); - - file = fopen("00002", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with write by others.\n"); - fclose(file); - cRc = chmod("00002", 00002); - } - printf("\tFile with write by others: name = \"%s\", rc = %d, cRc = %d\n", "00002", rc, cRc); - - file = fopen("00001", "w+"); - rc = 0; - cRc = 0; - if(!file) { rc = errno; } - else - { - fprintf(file, "File with execute by others.\n"); - fclose(file); - cRc = chmod("00001", 00001); - } - printf("\tFile with execute by others: name = \"%s\", rc = %d, cRc = %d\n", "00001", rc, cRc); } #endif diff --git a/setter/src/unix/perms.h b/setter/src/unix/perms.h new file mode 100644 index 0000000..c79c7fd --- /dev/null +++ b/setter/src/unix/perms.h @@ -0,0 +1,58 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + +Filename : perms.h +Author(s) : Natalia Portillo + +--[ Description ] ----------------------------------------------------------- + +Contains common implementations for UNIX family and compatibles + +--[ 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 SETTER_SRC_UNIX_PERMS_H_ +#define SETTER_SRC_UNIX_PERMS_H_ + +typedef struct +{ + char filename[256]; + char description[256]; + mode_t mode; +} unix_perms_tests_t; + +#define KNOWN_UNIX_PERMS 14 + +static const unix_perms_tests_t unix_perms[KNOWN_UNIX_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 // SETTER_SRC_UNIX_PERMS_H_