22.3.5 Executing programs with another’s profile privileges

Function: mbfl_program_enable_sudo

Declare the intention to use sudo and other commands required to use it. The declared programs are: sudo, whoami.

This function does not use mbfl_declare_program().

Function: mbfl_program_declare_sudo_user PERSONA

Register PERSONA as the user under which to execute the next program through sudo; the user will be selected using the -u option of sudo. This function will:

  1. Check that the string PERSONA satisfies the function mbfl_string_is_username(), else the function will print an error message to stderr and exit with exit_because_invalid_sudo_username().
  2. Check that the built–in file system pathname for sudo references an existent and executable file; otherwise call exit_because_program_not_found(). Preselected program pathnames.
  3. Check that the built–in file system pathname for whoami references an existent and executable file; otherwise call exit_because_program_not_found(). Preselected program pathnames.
  4. Execute whoami to determine the current effective user name. If an error occurs call exit_because_failure().
  5. If the string PERSONA is different from the current effective user name: select PERSONA as the user for the next sudo execution and call return_success(); otherwise set the internal state so that the next program execution will not use sudo, then call return_because_failure().
Function: mbfl_program_reset_sudo_user

Reset the previously requested sudo user to a value that will cause sudo not to be used in the next program invocation. This is useful to abort a user request.

Function: mbfl_program_sudo_user

Print the current sudo user. This function is for debugging purposes.

Function: mbfl_program_requested_sudo

Return true if the usage of sudo has been requested for the next command execution.

Function: mbfl_program_set_sudo_options OPT
Function: mbfl_program_declare_sudo_options OPT

Select additional command line options to use on the next invocation of sudo. These values are consumed by the first use of mbfl_program_exec().

Function: mbfl_program_reset_sudo_options

Clean the options previously set by mbfl_program_declare_sudo_options().

Function: exit_because_invalid_sudo_username
Alias: return_because_invalid_sudo_username

Exit or return with code 90.


This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.