UnZip::~UnZip() {
ScopeLogger();
for (auto& x : path_access_map) {
- LoggerD("Setting permission for path: %s [%u] ", x.first.c_str(), x.second);
+ LoggerD("Setting permission for path: %s [%o] ", x.first.c_str(),
+ x.second);
if (chmod(x.first.c_str(), x.second) == -1) {
LoggerE("Couldn't set permissions for: [%s] errno: %s", x.first.c_str(),
GetErrorString(errno).c_str());
void UnZipExtractRequest::storePermissions() {
// hold access information for later set
- // The high 16 bits of the external file attributes seem to be used for OS-specific permissions
+ // The high 16 bits of the external file attributes seem to be used for
+ // OS-specific permissions https://unix.stackexchange.com/a/14727 this answer describes that
+ // structure is:
+ // * 4 bits - file type
+ // * 3 bits - setuid, setgid, sticky
+ // * 9 bits - permissions
__mode_t mode = m_file_info.external_fa >> 16;
- LoggerD("Storing permissions for %s: %u", m_filename_inzip, mode);
+ unsigned int linux_file_type = mode >> 12;
+ __mode_t default_mode = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// check if proper permission mode is provided, if not use default 0775
- if (mode == 0) {
- mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
+ // validation is made for checking if both permissions and file type information is not zero
+ if (mode == 0 || linux_file_type == 0) {
+ mode = default_mode;
+ LoggerW(
+ "File %s has incomplete information for unix filesystem, using "
+ "default file permissions: %o",
+ m_filename_inzip, mode);
}
+ LoggerD("Storing permissions for %s: %o", m_filename_inzip, mode);
m_owner.path_access_map[m_output_filepath.c_str()] = mode;
}