Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35812

Re: Tarfile and usernames

References <CAAu18heZvrTXWTNDP-Cm116nO--9EUyxzRHOwwjpt4mZGBjj_A@mail.gmail.com> <1356898025.24306.140661171657165.332324AA@webmail.messagingengine.com>
Date 2012-12-30 20:48 +0000
Subject Re: Tarfile and usernames
From Nicholas Cole <nicholas.cole@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1472.1356900490.29569.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Sun, Dec 30, 2012 at 8:07 PM, Albert Hopkins <marduk@letterboxes.org>wrote:
>
>
> On Sun, Dec 30, 2012, at 01:57 PM, Nicholas Cole wrote:
>
> Dear List,
>
> I'm hoping to use the tarfile module in the standard library to move some
> files between computers.
>
> I can't see documented anywhere what this library does with userids and
> groupids.  I can't guarantee that the computers involved will have the same
> users and groups, and would like the archives to be extracted so that the
> files are all owned by the extracting user.
>
> Essentially, I do *not* with to preserve the owner and groups specified in
> the archives.
>
>
> Each "member" in the tar file has misc. metadata associated with it, which
> can be retrieved with the get_info() method.  You can add/modify this
> metadata if creating a TarFile.
>
> However, it should be stated that by default (on *nix anyway) if the user
> is not root then user/groups are assigned to the user exctracting the file
> (because only root can assign userids/non-member-groups).   The TarFile
> extract*() methods pretty much inherit the same behavior as the *nix tar
> command.  So if you are extracting as a non-root user, you should expect
> the same behavoir.  If you are extracting as root but don't want to change
> user/groups may have to extract it manually or create your own class by
> inheriting TarFile and overriding the .chown() method.
>
>

Thank you for this.  I guess that since the behaviour is not defined in the
documentation, it would probably be safest to inherit and change chown into
a no op.

I know that on *most* systems these days ordinary users cannot chown, and
also that people shouldn't be running things as root.  But you can't be too
careful - and predicting what a given user will do is always dangerous!

Best wishes,

N.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Tarfile and usernames Nicholas Cole <nicholas.cole@gmail.com> - 2012-12-30 20:48 +0000

csiph-web