355a11314d16d31e243965227820735062b2a680
Stefan Schuermans add copyright & license

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp   1) /**
libpermissioner/src/Tree.cpp   2)  * Permissioner: set file ownerships and permissions
libpermissioner/src/Tree.cpp   3)  * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
libpermissioner/src/Tree.cpp   4)  * Copyleft: GNU GENERAL PUBLIC LICENSE version 3 (see LICENSE)
libpermissioner/src/Tree.cpp   5)  */
libpermissioner/src/Tree.cpp   6) 
Stefan Schuermans move most sources into libp...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp   7) #include <permissioner/Tree.h>
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp     8) 
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp   9) #include <permissioner/Group.h>
Stefan Schuermans move most sources into libp...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  10) #include <permissioner/Permissions.h>
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  11) #include <permissioner/User.h>
Stefan Schuermans move most sources into libp...

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  12) #include <permissioner/StringUtils.h>
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    13) 
permissionerd/src/Tree.cpp    14) #include <boost/filesystem.hpp>
permissionerd/src/Tree.cpp    15) #include <sstream>
permissionerd/src/Tree.cpp    16) #include <stdexcept>
permissionerd/src/Tree.cpp    17) #include <string>
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  18) #include <unistd.h>
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    19) #include <vector>
permissionerd/src/Tree.cpp    20) 
permissionerd/src/Tree.cpp    21) void Tree::parseParams(std::string const &paramStr) {
permissionerd/src/Tree.cpp    22)   // format of paramStr is: <user> " " <group> " " <permissions> " " <root>
permissionerd/src/Tree.cpp    23)   // user, group, permissions may be - for no change
permissionerd/src/Tree.cpp    24)   std::string userStr, groupStr, permissionsStr, rootStr;
permissionerd/src/Tree.cpp    25) 
permissionerd/src/Tree.cpp    26)   std::string::size_type pos = 0;
permissionerd/src/Tree.cpp    27)   StringUtils::getNextField(paramStr, pos, userStr, "user");
permissionerd/src/Tree.cpp    28)   StringUtils::getNextField(paramStr, pos, groupStr, "group");
permissionerd/src/Tree.cpp    29)   StringUtils::getNextField(paramStr, pos, permissionsStr, "permissions");
permissionerd/src/Tree.cpp    30)   if (pos >= paramStr.length()) {
permissionerd/src/Tree.cpp    31)     std::stringstream msg;
permissionerd/src/Tree.cpp    32)     msg << "<root> field missing in \"" << paramStr << "\"";
permissionerd/src/Tree.cpp    33)     throw std::runtime_error(msg.str());
permissionerd/src/Tree.cpp    34)   }
Stefan Schuermans implement chown/chmod

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  35)   rootStr = paramStr.substr(pos);
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    36) 
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  37)   try {
libpermissioner/src/Tree.cpp  38)     user.parseUserName(userStr);
libpermissioner/src/Tree.cpp  39)   } catch (std::exception const & e) {
libpermissioner/src/Tree.cpp  40)     std::stringstream msg;
libpermissioner/src/Tree.cpp  41)     msg << "invalid <user> field \"" << userStr << "\" in \""
libpermissioner/src/Tree.cpp  42)         << paramStr << "\": " << e.what();
libpermissioner/src/Tree.cpp  43)     throw std::runtime_error(msg.str());
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    44)   }
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  45) 
libpermissioner/src/Tree.cpp  46)   try {
libpermissioner/src/Tree.cpp  47)     group.parseGroupName(groupStr);
libpermissioner/src/Tree.cpp  48)   } catch (std::exception const & e) {
libpermissioner/src/Tree.cpp  49)     std::stringstream msg;
libpermissioner/src/Tree.cpp  50)     msg << "invalid <group> field \"" << groupStr << "\" in \""
libpermissioner/src/Tree.cpp  51)         << paramStr << "\": " << e.what();
libpermissioner/src/Tree.cpp  52)     throw std::runtime_error(msg.str());
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    53)   }
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  54) 
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    55)   try {
permissionerd/src/Tree.cpp    56)     permissions.parseParams(permissionsStr);
permissionerd/src/Tree.cpp    57)   } catch (std::exception const & e) {
permissionerd/src/Tree.cpp    58)     std::stringstream msg;
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  59)     msg << "invalid <permissions> field \"" << permissionsStr << "\" in \""
libpermissioner/src/Tree.cpp  60)         << paramStr << "\": " << e.what();
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    61)     throw std::runtime_error(msg.str());
permissionerd/src/Tree.cpp    62)   }
Stefan Schuermans user/group lookup

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  63) 
Stefan Schuermans canonicalize root paths

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  64)   try {
libpermissioner/src/Tree.cpp  65)     root = boost::filesystem::canonical(rootStr);
libpermissioner/src/Tree.cpp  66)   } catch (std::exception const & e) {
libpermissioner/src/Tree.cpp  67)     std::stringstream msg;
libpermissioner/src/Tree.cpp  68)     msg << "invalid <root> field \"" << rootStr << "\" in \""
libpermissioner/src/Tree.cpp  69)         << paramStr << "\": " << e.what();
libpermissioner/src/Tree.cpp  70)     throw std::runtime_error(msg.str());
libpermissioner/src/Tree.cpp  71)   }
Stefan Schuermans begin of permissioner confi...

Stefan Schuermans authored 4 years ago

permissionerd/src/Tree.cpp    72) }
Stefan Schuermans add config getters

Stefan Schuermans authored 4 years ago

libpermissioner/src/Tree.cpp  73) 
libpermissioner/src/Tree.cpp  74) User const & Tree::getUser() const {
libpermissioner/src/Tree.cpp  75)   return user;
libpermissioner/src/Tree.cpp  76) }
libpermissioner/src/Tree.cpp  77) 
libpermissioner/src/Tree.cpp  78) Group const & Tree::getGroup() const {
libpermissioner/src/Tree.cpp  79)   return group;
libpermissioner/src/Tree.cpp  80) }
libpermissioner/src/Tree.cpp  81) 
libpermissioner/src/Tree.cpp  82) Permissions const & Tree::getPermissions() const {
libpermissioner/src/Tree.cpp  83)   return permissions;
libpermissioner/src/Tree.cpp  84) }
libpermissioner/src/Tree.cpp  85) 
libpermissioner/src/Tree.cpp  86) boost::filesystem::path const & Tree::getRoot() const {
libpermissioner/src/Tree.cpp  87)   return root;
libpermissioner/src/Tree.cpp  88) }