nlitsme / ubidump

Tool for viewing and extracting files from an UBIFS image
MIT License
232 stars 60 forks source link

Flag "--preserve" doesn't preserve UID\GID #26

Closed stich86 closed 3 months ago

stich86 commented 3 months ago

Hi @nlitsme,

is it possible to modify the code and allow the "--preserve" switch to export UID and GID?

I had lot of problem on repacking a firmware from a vendor, because they use some custom UID\GID, and when exported with ubidump, all stuff is owned by root.

I've just change that part in this way:

            if args.preserve and typ != inode.ITYPE_SYMLINK:
                # note: we have to do this after closing the file, since the close after exportfile
                # will update the last-modified time.
                os.utime(fullpath, (inode.atime(), inode.mtime()))
                os.chmod(fullpath, inode.mode)
                os.chown(fullpath, inode.uid, inode.gid)

Adding os.chown function will export files with their original UID\GID.

I can create a pull request if you want.

Thanks!

nlitsme commented 3 months ago

yes, but then I would like it to also work as non-root, so you'd need to catch PermissionError from os.chown, or maybe use a different option, like --preserve-owner.

stich86 commented 3 months ago

yes, but then I would like it to also work as non-root, so you'd need to catch PermissionError from os.chown, or maybe use a different option, like --preserve-owner.

I think run as-root should be necessary, because if you extract files that has root as owner, or stuff like special files or something else..

Do you want to rework it?

nlitsme commented 3 months ago

I also added a try-except PermissionError around os.mknod. I mostly use ubidump to analyze the contents of the filesystem, not nescesarily to exactly reproduce it in my local filesystem. Therefore I think it is nescesary that it keeps working for non-root users.

nlitsme commented 3 months ago

I have pushed an update.

stich86 commented 3 months ago

Thanks mate,

i've tested and works as expected :)

I'm closing the issue!

stich86 commented 2 months ago

hi @nlitsme

have you pushed the mods on PyPi? I'm still see old version

thanks!