'Building a switch user tool: How to gain root permissions without dependencies

I've been trying to make my own sudo program in Python, but I don't want to have any dependencies (like su or pkexec). How would I gain root access? Ideas:

  1. Have the file always have root access (with chmod +[smth])
  2. Somehow login as root (maybe with subprocess)
  3. Use something built in (kind of a low-level dependency) and pass it the root password.

How would I do any of these or is there a different way? Or is Python even low level enough to do this?



Solution 1:[1]

If it's not a project and the goal is only to not have sudo dependencies while having root access, there are some sudo alternatives. Use at your own risk, I have no experience with these. Also, I don't see pkexec or su being dependencies on the Arch or Ubuntu packages sites, but on Arch you can always force remove packages without removing any dependencies by using sudo pacman -Rdd package_name.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel Archuleta