Open Source Development

 View Only

 About changing permissions using the gzip command

  • AIX Open Source
Kenichi Oshiro's profile image
Kenichi Oshiro posted 02/10/25 02:07 AM

If anyone knows please let me know.

When the gz file with the following owner and permissions was expanded using the "gzip -dk" command as a general user called awbapp01,
Although the file was extracted, the file was generated with a "Not owner" message and permissions of 600.

(*The owner, halft, is also a general user)

===================================================

-rw-rw-rw-    1 hulft    awbapp01 KHATROI1A000.csv.gz
-rw-------    1 hulft    awbapp01 KHATROI1A000.csv
===================================================

The OS and versions are as follows.

AIX 7.2.5.7

As for what I want to hear

①Is it by design that when a file owned by a general user is expanded by a general user other than the owner, the permissions change?

②Does the behavior change depending on the version of the gzip command?

This is posted using a translation tool.
Please check if you have any questions.


#AIXOpenSource
Stephen Ulmer's profile image
Stephen Ulmer

This is the way file system permissions work in UNIX. The user running the gzip process does not have permission to change the ownership of objects on the file system, so they are written as owned by themselves. If it were not this way, there would be basically no file security at all.

This is not related to the version of the program you’re using in any way.


#AIXOpenSource
Grover Davidson's profile image
Grover Davidson

When we create files in the unix/posix environment, we have to consider who can change the owner of a file. As a general rule, any files you create are with your user id and primary group id. This is documented in the man pages for the open() call:

       O_CREAT
            If the file exists, this flag has no effect, except as noted under the O_EXCL flag. If the file does not exist, a regular file is created
            with the following characteristics:
              *    The owner ID of the file is set to the effective user ID of the process.
              *    The group ID of the file is set to the group ID of the parent directory if the parent directory has the SetGroupID attribute (S_ISGID
                   bit) set. Otherwise, the group ID of the file is set to the effective group ID of the calling process.
              *    The file permission and attribute bits are set to the value of the Mode parameter, modified as follows:
                     *    All bits set in the process file mode creation mask are cleared. (The file creation mask is described in the umask subroutine.)
                     *    The S_ISVTX attribute bit is cleared.
            The file open with the O_CREAT flag by the open64 subroutine must create an encrypted file when the file is within an encrypted directory or
            inheritance schema and the calling process has an open key store. This will have the effect of generating a random symmetric file encryption
            key, wrapping it with the users public key and storing it in the files metadata.

If you want to change the ownership/group/permissions of the file, then you will need root authority. If you restore the files as root, then I would expect the ownership to be preserved as stated on the gzip website:

gzip normally preserves the mode and modification timestamp of a file when compressing or decompressing. If you have appropriate privileges, it also preserves the file’s owner and group.

And we do not recommend you SUID gzip to root. You could break/damage/overwrite system files without knowing OR install a worm/trojan/etc/ If you need the permissions/ownership changed, you can consider using ACLs (Access Control Lists) or you can have a special program run to change the ownership/group/permissions. 


#AIXOpenSource