unix - Why do I need setuid(0) within a setuid-root C program that calls an administrative program with system()? -


I had to hack some dirty Linux for someone, so that they could have a printer with cupsenable printoname Shell command while being a non root user I did not want to fully use the cuplessable syntax as the root, so I have written a cover which is in the input < Code> argv [1] system . .

I have created the program setuid root, but still, cuplessable failed "permission denied" and then I had a setuid (0) Code> system () and, take it and see, it worked.

The best way to give users control over the printer is probably a better way for me to be interested in chmod u + s vs setuid (0) There are complications of versus system () . Why did this happen?

to man system :

Do not use system () from a program with set-user-id or set-group-id privilege, because the strange values ​​of some environment variables can be used to break the mechanism Integrity Instead of the exec (3) family of tasks, but use execlp (3) or execvp (3) . Actually, those systems will not work properly with programs with set-user-id or set-group-id privileges, on which / bin / sh Bash is version 2, as Bash 2 leaves the privileges at startup.

and man bash from:

If the shell starts with effective user (group) id actual user (group) Id is not equal, and the -p option is not provided, no startup file is read, shell functions are not inherited from the environment; shellopts variable, If it appears in the environment, it is ignored, and the effective user id is real User ID is set.

This your Setuide (0) calls circumvented security.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -