networkservice
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
utils::command::IExecutor Interface Referenceabstract

A helper class to execute shell commands securely. This class is a high level interface added to ease testability of component that use it. More...

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

Inheritance diagram for utils::command::IExecutor:
Inheritance graph
[legend]

Classes

struct  ProgramParams
 A data structure containing all input parameters expected by execProgram() method. More...
 

Public Types

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...
 

Public Member Functions

 IExecutor (Flags flags)
 
virtual ~IExecutor ()=default
 
 IExecutor (const IExecutor &)=delete
 
IExecutoroperator= (const IExecutor &)=delete
 
 IExecutor (IExecutor &&)=delete
 
IExecutoroperator= (IExecutor &&)=delete
 
virtual void executeProgram (const ProgramParams &params) const =0
 Execute the program pointed to by pathname. More...
 

Protected Attributes

Flags m_flags
 

Detailed Description

A helper class to execute shell commands securely. This class is a high level interface added to ease testability of component that use it.

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
May 2020

Member Enumeration Documentation

◆ Flags

enum utils::command::IExecutor::Flags : unsigned int

Bitmasks to give control on how this class is handling requests.

Enumerator
WAIT_COMMAND 

Wait until command is completed

RESEED_PRNG 

Re-initialize the Random number Generator

SANITIZE_FILES 

Closed file descriptors, ...

DROP_PRIVILEGES 

Drop the process's privileges

ALL 

Constructor & Destructor Documentation

◆ IExecutor() [1/3]

utils::command::IExecutor::IExecutor ( Flags  flags)
inlineexplicit

Class constructor

Parameters
flagsA set of masks of type Flags

◆ ~IExecutor()

virtual utils::command::IExecutor::~IExecutor ( )
virtualdefault

Class destructor

◆ IExecutor() [2/3]

utils::command::IExecutor::IExecutor ( const IExecutor )
delete

Class copy constructor

◆ IExecutor() [3/3]

utils::command::IExecutor::IExecutor ( IExecutor &&  )
delete

Class move constructor

Member Function Documentation

◆ executeProgram()

virtual void utils::command::IExecutor::executeProgram ( const ProgramParams params) const
pure virtual

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 ProgramParams
See also
http://man7.org/linux/man-pages/man2/execve.2.html

Implemented in utils::command::Executor.

◆ operator=() [1/2]

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

Class copy-assignment operator

◆ operator=() [2/2]

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

Class move-assignment operator

Member Data Documentation

◆ m_flags

Flags utils::command::IExecutor::m_flags
protected

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