networkservice
Public Member Functions | Private Attributes | List of all members
utils::command::Executor Class Reference

A helper class to execute shell commands securely. More...

#include "utils/command/executor/Executor.h"

Inheritance diagram for utils::command::Executor:
Inheritance graph
[legend]
Collaboration diagram for utils::command::Executor:
Collaboration graph
[legend]

Public Member Functions

 Executor (const osal::IOsal &osal, Flags flags=Flags::WAIT_COMMAND)
 
 ~Executor () override
 
 Executor (const Executor &)=delete
 
Executoroperator= (const Executor &)=delete
 
 Executor (Executor &&)=delete
 
Executoroperator= (Executor &&)=delete
 
void executeProgram (const ProgramParams &params) const override
 Execute the program pointed to by pathname. More...
 
- Public Member Functions inherited from utils::command::IExecutor
 IExecutor (Flags flags)
 
virtual ~IExecutor ()=default
 
 IExecutor (const IExecutor &)=delete
 
IExecutoroperator= (const IExecutor &)=delete
 
 IExecutor (IExecutor &&)=delete
 
IExecutoroperator= (IExecutor &&)=delete
 

Private Attributes

std::unique_ptr< Internal > m_internal
 

Additional Inherited Members

- Public Types inherited from utils::command::IExecutor
enum  Flags : unsigned int {
  WAIT_COMMAND = (1u << 0u), RESEED_PRNG = (1u << 1u), SANITIZE_FILES = (1u << 2u), DROP_PRIVILEGES = (1u << 3u),
  ALL = (WAIT_COMMAND | RESEED_PRNG | SANITIZE_FILES | DROP_PRIVILEGES)
}
 Bitmasks to give control on how this class is handling requests. More...
 
- Protected Attributes inherited from utils::command::IExecutor
Flags m_flags
 

Detailed Description

A helper class to execute shell commands securely.

This class is the "low level class" that implements IExecutor.h

Note
Copy contructor, copy-assignment operator, move constructor and move-assignment operator are defined to be compliant with the "Rule of five"
See also
https://en.cppreference.com/w/cpp/language/rule_of_three
Author
Boubacar DIENE bouba.nosp@m.car..nosp@m.diene.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Date
April 2020

Constructor & Destructor Documentation

◆ Executor() [1/3]

utils::command::Executor::Executor ( const osal::IOsal osal,
Flags  flags = Flags::WAIT_COMMAND 
)
explicit

Class constructor

Parameters
osalOS abstract layer's implementation to use. This is passed to the constructor to ease unit testing of Executor class.
flagsA set of masks of type IExecutor::Flags

◆ ~Executor()

utils::command::Executor::~Executor ( )
override

Class destructor

Note
The override specifier aims at making the compiler warn if the base class's destructor is not virtual.

◆ Executor() [2/3]

utils::command::Executor::Executor ( const Executor )
delete

Class copy constructor

◆ Executor() [3/3]

utils::command::Executor::Executor ( Executor &&  )
delete

Class move constructor

Member Function Documentation

◆ executeProgram()

void utils::command::Executor::executeProgram ( const ProgramParams params) const
overridevirtual

Execute the program pointed to by pathname.

This function performs a fork+execve in a secure way (re-initialize the random number generator, close file descriptors, ...) depending on Flags. All input parameters have the same meaning as in execve() manpage.

Parameters
paramsAn object of type IExecutor::ProgramParams
See also
http://man7.org/linux/man-pages/man2/execve.2.html

Implements utils::command::IExecutor.

◆ operator=() [1/2]

Executor& utils::command::Executor::operator= ( const Executor )
delete

Class copy-assignment operator

◆ operator=() [2/2]

Executor& utils::command::Executor::operator= ( Executor &&  )
delete

Class move-assignment operator

Member Data Documentation

◆ m_internal

std::unique_ptr<Internal> utils::command::Executor::m_internal
private

The documentation for this class was generated from the following file: