Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: conditional permissions behavior #28

Merged
merged 10 commits into from
Jul 27, 2024

Conversation

yunginnanet
Copy link
Contributor

@yunginnanet yunginnanet commented Jun 16, 2024

Overview

Current behavior asks for sudo password via stdin regardless on if we're root or not.

This PR adds an IsRoot boolean to the configuration struct and adjusts the final message appropriately, as well as other changes listed below.

Change Items

  • Added a check for whether the script is run as root and adjusted operations accordingly.
  • Enhanced error handling and user notifications for permissions and file operations.
    • This involved writing a wrapper for HikariKnight/ls-iommu/pkg/common.ErrorCheck
  • Implemented ExecAndLogSudo function to streamline running commands with elevated permissions.
  • Refactored logging execution flow for exec outputs.
  • Refactored fileio.FileExist to return both a boolean and an error.
  • Updated function comments to clarify their purpose and usage.
  • Ensured consistent commenting style and enhanced readability.
  • Added a test for finalizeNotice function to manually verify output messages.
  • Updated handling of old debug.log to rename to debug_old.log instead of deleting.

@HikariKnight
Copy link
Owner

HikariKnight commented Jun 16, 2024

I also noticed that if we tell people that they can run quickpassthrough itself as root now, we will have to check if the config and backup folders are owned by root and tell them to re-run as root if quickpassthrough is not run through sudo.

I originally designed it to be run as the normal user so i never actually tested running it as sudo then normal user 😅

other than that i like the changes so far 😄

@yunginnanet
Copy link
Contributor Author

Thanks for the feedback! I was actually just checking in to ping you to request comment, so I'm happy to see you replied! I'll take a look :)

@yunginnanet
Copy link
Contributor Author

@HikariKnight take a look when you can, I believe I've addressed your comments

but this is a pretty heavy refactor so I definitely need a second pair of eyes

@yunginnanet
Copy link
Contributor Author

yunginnanet commented Jun 17, 2024

The behavior that actually lead to me starting on this was that I would actually receive silent errors when I ran this command as a user after running it as root. This last commit, 395f5ab, finalizes my major changes for now I believe.

Here's a demo of the behavior the aforementioned commit replaces silent fatal errors with:

Fatal error demonstration

@yunginnanet yunginnanet marked this pull request as ready for review June 17, 2024 07:34
@yunginnanet yunginnanet changed the title Fix: don't need sudo if we're root, other minor changes Feat: conditional permissions behavior Jun 17, 2024
@HikariKnight
Copy link
Owner

this gif looks nice, conveniently i am sick today so i surprisingly has freetime to look at the code once i have the paperwork done

@HikariKnight
Copy link
Owner

This looks good, will do a test build locally later today and test in VMs to make sure things work properly in ubuntu, pop, arch and fedora since this is a big refactor.

@yunginnanet
Copy link
Contributor Author

This looks good, will do a test build locally later today and test in VMs to make sure things work properly in ubuntu, pop, arch and fedora since this is a big refactor.

Yes, this definitely needs to be looked at carefully and tested. Thanks for your efforts, and take care of yourself.

@yunginnanet
Copy link
Contributor Author

^ The code should be easier to review now, as well.

@HikariKnight
Copy link
Owner

Tested and working on Fedora Workstation (Grubby and Dracut test)

@HikariKnight
Copy link
Owner

Archlinux tested and works (pure grub and mkinitcpio test)

only need the pop os test to succeed then we should be good @yunginnanet

@yunginnanet
Copy link
Contributor Author

agreed on all points. adapter function added, complete with unit test

@yunginnanet yunginnanet requested a review from HikariKnight June 19, 2024 21:09
Comment on lines +321 to +323
cmd := fmt.Sprintf("cp -v %s %s", conffile, sysfile)

err := command.ExecAndLogSudo(isRoot, false, cmd)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested everything but i had to patch this into

err := command.ExecAndLogSudo(isRoot, false, "cp", "-v", conffile, sysfile)

in order for everything to work as it got missed when we changed how ExecAndLogSudo worked. i will just patch that after merge

@HikariKnight HikariKnight merged commit 6c48a35 into HikariKnight:main Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants