add copyright & license
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 1) /**
libpermissioner/src/Permissions.cpp 2) * Permissioner: set file ownerships and permissions
libpermissioner/src/Permissions.cpp 3) * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
libpermissioner/src/Permissions.cpp 4) * Copyleft: GNU GENERAL PUBLIC LICENSE version 3 (see LICENSE)
libpermissioner/src/Permissions.cpp 5) */
libpermissioner/src/Permissions.cpp 6)
|
move most sources into libp...
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 7) #include <permissioner/Permissions.h>
|
begin of permissioner confi...
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 8)
|
implement chown/chmod
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 9) #include <boost/filesystem.hpp>
|
user/group lookup
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 10) #include <sstream>
libpermissioner/src/Permissions.cpp 11) #include <stdexcept>
|
begin of permissioner confi...
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 12) #include <string>
permissionerd/src/Permissions.cpp 13)
permissionerd/src/Permissions.cpp 14) void Permissions::parseParams(std::string const ¶mStr) {
|
permission parsing
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 15) // reset permission flags
permissionerd/src/Permissions.cpp 16) set = 0;
permissionerd/src/Permissions.cpp 17) setCond = 0;
permissionerd/src/Permissions.cpp 18) clear = 0;
permissionerd/src/Permissions.cpp 19) clearCond = 0;
permissionerd/src/Permissions.cpp 20) // parse comma-separated groups of [ugoa][+-][rwxX] settings
permissionerd/src/Permissions.cpp 21) Flags who = 0, what = 0, whatCond = 0;
permissionerd/src/Permissions.cpp 22) char action = ' ';
permissionerd/src/Permissions.cpp 23) // append comma at end to process last group
permissionerd/src/Permissions.cpp 24) for (char c : paramStr + ",") {
permissionerd/src/Permissions.cpp 25) switch (c) {
permissionerd/src/Permissions.cpp 26) case ',':
permissionerd/src/Permissions.cpp 27) switch (action) {
permissionerd/src/Permissions.cpp 28) case '=':
permissionerd/src/Permissions.cpp 29) set = who * what;
permissionerd/src/Permissions.cpp 30) setCond = who * whatCond;
permissionerd/src/Permissions.cpp 31) clear = who * (what ^ (flagRead | flagWrite | flagExecute));
|
complete config text, fix c...
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 32) clearCond = 0;
|
permission parsing
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 33) break;
permissionerd/src/Permissions.cpp 34) case '+':
permissionerd/src/Permissions.cpp 35) set = who * what;
permissionerd/src/Permissions.cpp 36) setCond = who * whatCond;
permissionerd/src/Permissions.cpp 37) break;
permissionerd/src/Permissions.cpp 38) case '-':
permissionerd/src/Permissions.cpp 39) clear = who * what;
permissionerd/src/Permissions.cpp 40) clearCond = who * whatCond;
permissionerd/src/Permissions.cpp 41) break;
permissionerd/src/Permissions.cpp 42) }
permissionerd/src/Permissions.cpp 43) who = 0;
permissionerd/src/Permissions.cpp 44) what = 0;
permissionerd/src/Permissions.cpp 45) whatCond = 0;
permissionerd/src/Permissions.cpp 46) action = ' ';
permissionerd/src/Permissions.cpp 47) break;
permissionerd/src/Permissions.cpp 48) case 'u':
permissionerd/src/Permissions.cpp 49) who |= flagUser;
permissionerd/src/Permissions.cpp 50) break;
permissionerd/src/Permissions.cpp 51) case 'g':
permissionerd/src/Permissions.cpp 52) who |= flagGroup;
permissionerd/src/Permissions.cpp 53) break;
permissionerd/src/Permissions.cpp 54) case 'o':
permissionerd/src/Permissions.cpp 55) who |= flagOther;
permissionerd/src/Permissions.cpp 56) break;
permissionerd/src/Permissions.cpp 57) case 'a':
permissionerd/src/Permissions.cpp 58) who |= flagUser | flagGroup | flagOther;
permissionerd/src/Permissions.cpp 59) break;
permissionerd/src/Permissions.cpp 60) case '=':
permissionerd/src/Permissions.cpp 61) case '+':
permissionerd/src/Permissions.cpp 62) case '-':
permissionerd/src/Permissions.cpp 63) action = c;
permissionerd/src/Permissions.cpp 64) break;
permissionerd/src/Permissions.cpp 65) case 'r':
permissionerd/src/Permissions.cpp 66) what |= flagRead;
permissionerd/src/Permissions.cpp 67) break;
permissionerd/src/Permissions.cpp 68) case 'w':
permissionerd/src/Permissions.cpp 69) what |= flagWrite;
permissionerd/src/Permissions.cpp 70) break;
permissionerd/src/Permissions.cpp 71) case 'x':
permissionerd/src/Permissions.cpp 72) what |= flagExecute;
permissionerd/src/Permissions.cpp 73) break;
permissionerd/src/Permissions.cpp 74) case 'X':
permissionerd/src/Permissions.cpp 75) whatCond |= flagExecute;
permissionerd/src/Permissions.cpp 76) break;
|
user/group lookup
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 77) default:
libpermissioner/src/Permissions.cpp 78) {
libpermissioner/src/Permissions.cpp 79) std::stringstream msg;
libpermissioner/src/Permissions.cpp 80) msg << "invalid character \"" << c << "\" in permission string \""
libpermissioner/src/Permissions.cpp 81) << paramStr << "\"";
libpermissioner/src/Permissions.cpp 82) throw std::runtime_error(msg.str());
libpermissioner/src/Permissions.cpp 83) }
|
permission parsing
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 84) }
|
begin of permissioner confi...
Stefan Schuermans authored 4 years ago
|
permissionerd/src/Permissions.cpp 85) }
permissionerd/src/Permissions.cpp 86) }
|
implement chown/chmod
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 87)
libpermissioner/src/Permissions.cpp 88) void Permissions::apply(boost::filesystem::path const &path) const {
libpermissioner/src/Permissions.cpp 89) // only process regular files and directories (especially no symlinks)
libpermissioner/src/Permissions.cpp 90) if (! boost::filesystem::is_regular_file(path) &&
libpermissioner/src/Permissions.cpp 91) ! boost::filesystem::is_directory(path)) {
libpermissioner/src/Permissions.cpp 92) return;
libpermissioner/src/Permissions.cpp 93) }
libpermissioner/src/Permissions.cpp 94)
libpermissioner/src/Permissions.cpp 95) // get permissions
libpermissioner/src/Permissions.cpp 96) boost::filesystem::file_status st = boost::filesystem::status(path);
libpermissioner/src/Permissions.cpp 97) boost::filesystem::perms perms = st.permissions();
libpermissioner/src/Permissions.cpp 98)
libpermissioner/src/Permissions.cpp 99) // compute updated permissions
libpermissioner/src/Permissions.cpp 100) Flags doSet = set, doClear = clear;
libpermissioner/src/Permissions.cpp 101) if (perms & boost::filesystem::perms::owner_exe) {
libpermissioner/src/Permissions.cpp 102) doSet |= setCond;
libpermissioner/src/Permissions.cpp 103) doClear |= clearCond;
libpermissioner/src/Permissions.cpp 104) }
libpermissioner/src/Permissions.cpp 105) perms &= boost::filesystem::perms::all_all ^ flags2perms(doClear);
libpermissioner/src/Permissions.cpp 106) perms |= flags2perms(doSet);
libpermissioner/src/Permissions.cpp 107)
libpermissioner/src/Permissions.cpp 108) // set new permissions if they changed
libpermissioner/src/Permissions.cpp 109) if (perms != st.permissions()) {
libpermissioner/src/Permissions.cpp 110) boost::filesystem::permissions(path, perms);
libpermissioner/src/Permissions.cpp 111) }
libpermissioner/src/Permissions.cpp 112) }
libpermissioner/src/Permissions.cpp 113)
|
permissions getter methods
Stefan Schuermans authored 4 years ago
|
libpermissioner/src/Permissions.cpp 114) Permissions::Flags Permissions::getSet() const {
libpermissioner/src/Permissions.cpp 115) return set;
libpermissioner/src/Permissions.cpp 116) }
libpermissioner/src/Permissions.cpp 117)
libpermissioner/src/Permissions.cpp 118) Permissions::Flags Permissions::getSetCond() const {
libpermissioner/src/Permissions.cpp 119) return setCond;
libpermissioner/src/Permissions.cpp 120) }
libpermissioner/src/Permissions.cpp 121)
libpermissioner/src/Permissions.cpp 122) Permissions::Flags Permissions::getClear() const {
libpermissioner/src/Permissions.cpp 123) return clear;
libpermissioner/src/Permissions.cpp 124) }
libpermissioner/src/Permissions.cpp 125)
libpermissioner/src/Permissions.cpp 126) Permissions::Flags Permissions::getClearCond() const {
libpermissioner/src/Permissions.cpp 127) return clearCond;
libpermissioner/src/Permissions.cpp 128) }
libpermissioner/src/Permissions.cpp 129)
|