sudo and doxygen

This commit is contained in:
Guillermo Roche 2020-06-01 23:23:23 +02:00
parent 3387aa7ca1
commit fda48edaf0
9 changed files with 237 additions and 23 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-05-31T02:21:12. --> <!-- Written by QtCreator 4.8.2, 2020-06-01T12:35:56. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -56,7 +56,13 @@
<variable>ProjectExplorer.Project.PluginSettings</variable> <variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"/> <valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey"/>
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value> <value type="bool" key="ClangCodeModel.UseGlobalConfig">false</value>
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.EverythingWithExceptions</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">false</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap> </valuemap>
</data> </data>
<data> <data>

View File

@ -7,10 +7,25 @@ using namespace std;
class conexion class conexion
{ {
public: public:
/**
* @brief conexion
* Object that launch the server and start the sessions
* @param conf Configuration file
*/
conexion(config_reader &conf); conexion(config_reader &conf);
/**
* @brief start_server
* Start the server
*/
virtual void start_server(); virtual void start_server();
protected: protected:
data_acces* data; data_acces* data;
/**
* @brief create_socket
* Create the server socket
* @param port Port to listen the server
* @return File descritor to listen the new conexions
*/
int create_socket(int port); int create_socket(int port);
config_reader* config; config_reader* config;
}; };

View File

@ -7,12 +7,25 @@
class conexion_ssl : public conexion class conexion_ssl : public conexion
{ {
public: public:
/**
* @brief conexion
* Object that launch the secure server and start the secure sessions
* @param conf Configuration file
*/
conexion_ssl(config_reader &conf); conexion_ssl(config_reader &conf);
void start_server(); void start_server();
private: private:
/*void init_openssl(); /**
void cleanup_openssl();*/ * @brief create_context
* Create the SSL context
* @return SSL context
*/
SSL_CTX *create_context(); SSL_CTX *create_context();
/**
* @brief configure_context
* Configure the SSL context
* @param ctx Contest to configure
*/
void configure_context(SSL_CTX *ctx); void configure_context(SSL_CTX *ctx);
}; };

View File

@ -6,7 +6,17 @@
class config_package class config_package
{ {
public: public:
/**
* @brief config_package
* Generate a config file, or replace it
* @param name Name of the package
*/
config_package(std::string name); config_package(std::string name);
/**
* @brief change_uses
* Write a config file
* @param remote_uses Info to write in the file
*/
void change_uses(std::string remote_uses); void change_uses(std::string remote_uses);
private: private:
std::string name; std::string name;

View File

@ -6,7 +6,20 @@
class config_reader class config_reader
{ {
public: public:
config_reader(std::string);
/**
* @brief config_reader
* Generate a objet to extract info to a config file
* @param path File path to extract the file
*/
config_reader(std::string path);
/**
* @brief get_param
* Permit extract a value in a config file
* @param variable Name of a field to extract the info
* @param value Info extracted
* @return True if the field exists, false if not
*/
bool get_param(std::string variable, std::string &value); bool get_param(std::string variable, std::string &value);
private: private:
std::ifstream file; std::ifstream file;

View File

@ -7,16 +7,76 @@
class data_acces class data_acces
{ {
public: public:
/**
* @brief data_acces
* Interface to program objects that manage the stored data
*/
data_acces(); data_acces();
/**
* @brief get_passwd
* Get the hash of the password that use the user
* @param username User whose password you want to know
* @return The hash of the password
*/
virtual std::string get_passwd(std::string username) = 0; virtual std::string get_passwd(std::string username) = 0;
/**
* @brief get_admin
* Get if the user is a admin or not
* @return true if is an admin, false if not
*/
virtual bool get_admin(std::string)=0; virtual bool get_admin(std::string)=0;
/**
* @brief get_pinfo
* Get a list of the generated packages and the information about that
* @return A list of the generated packages and the information about that
*/
virtual std::list<std::string> get_pinfo()=0; virtual std::list<std::string> get_pinfo()=0;
/**
* @brief get_uinfo
* Get a list of the users and if they are admins or not
* @return A list of the users and if they are admins or not
*/
virtual std::list<std::string> get_uinfo()=0; virtual std::list<std::string> get_uinfo()=0;
/**
* @brief write_install
* Store information about package generation
* @param package Name of the package generated
* @param user User that generated te package
*/
virtual void write_install(std::string package, std::string user)=0; virtual void write_install(std::string package, std::string user)=0;
virtual void write_remove(std::string)=0; /**
* @brief write_remove
* Remove the information about generated package
* @param package Name of the package generated
*/
virtual void write_remove(std::string package)=0;
/**
* @brief get_package_exists
* Search if the package exists
* @param package Name of the package to search
* @return True if the package exists, false if not
*/
virtual bool get_package_exists(std::string package)=0; virtual bool get_package_exists(std::string package)=0;
/**
* @brief create_user
* Create a new user with the passed data
* @param user Name of the passed user
* @param pass Password of the new user
* @param admin Admin status of a new user
*/
virtual void create_user(std::string user, std::string pass, bool admin)=0; virtual void create_user(std::string user, std::string pass, bool admin)=0;
/**
* @brief remove_user
* Remove a user
* @param user Name of the user to delete
*/
virtual void remove_user(std::string user)=0; virtual void remove_user(std::string user)=0;
/**
* @brief get_hash
* Generate a hash with the pased data
* @param data Data to hash
* @return Data hased
*/
static char* get_hash(char *data); static char* get_hash(char *data);
}; };
#endif // DATA_ACCES_H #endif // DATA_ACCES_H

View File

@ -43,7 +43,7 @@ void session_manager::start_dialog(){
while(true){ while(true){
int n_read=this->read_data(buffer,5); int n_read=this->read_data(buffer,5);
if(strcmp(buffer, "exec")==0){ if(strcmp(buffer, "exec")==0){
this->execute(); this->generate_package();
}else if(strcmp(buffer, "info")==0){ }else if(strcmp(buffer, "info")==0){
this->send_information(); this->send_information();
}else if(strcmp(buffer, "remv")==0){ }else if(strcmp(buffer, "remv")==0){
@ -61,7 +61,7 @@ void session_manager::start_dialog(){
delete[] (buffer); delete[] (buffer);
} }
int session_manager::execute(){ int session_manager::generate_package(){
char* n_package = new char[250]; char* n_package = new char[250];
this->read_data(n_package, 5); this->read_data(n_package, 5);
this->read_data(n_package, 250); this->read_data(n_package, 250);
@ -103,16 +103,17 @@ int session_manager::remove(){
} }
std::string session_manager::appli_command(char comand[], char* n_package){ std::string session_manager::appli_command(char comand[], char* n_package){
this->args=new char*[4]; char** args=new char*[5];
this->args[0]="emerge"; args[0]="sudo";
this->args[1]=comand; args[1]="emerge";
this->args[2]=n_package; args[2]=comand;
this->args[3]=nullptr; args[3]=n_package;
args[4]=nullptr;
int pid = fork(); int pid = fork();
int status=-2; int status=-2;
std::string ret; std::string ret;
if(pid==0){ if(pid==0){
if(execvp(this->args[0],this->args)==-1){ if(execvp(args[0],args)==-1){
std::cout << "error inesperado" << std::endl; std::cout << "error inesperado" << std::endl;
} }
exit(0); exit(0);
@ -126,6 +127,7 @@ std::string session_manager::appli_command(char comand[], char* n_package){
ret = "err"; ret = "err";
} }
} }
delete [] (args);
return ret; return ret;
} }

View File

@ -5,23 +5,99 @@
class session_manager class session_manager
{ {
public: public:
/**
* @brief session_manager::session_manager
* Object that guide a session
* @param fd Client flie descriptor
*/
session_manager(int fd); session_manager(int fd);
/**
* @brief start_dialog
* Start the default state, ready to listen petitions
*/
void start_dialog(); void start_dialog();
int execute(); /**
* @brief generate_package
* Generate a package
* @return Positive if the package has been installed well
*/
int generate_package();
/**
* @brief remove
* Remove a package
* @return Positive if the package has been removed well
*/
int remove(); int remove();
/**
* @brief send_information
* Send the actual packages generated whit these aplication
*/
void send_information(); void send_information();
/**
* @brief send_user_info
* Send the list of generated users and the privileges
*/
void send_user_info(); void send_user_info();
/**
* @brief validate_pass
* Recive an user and password and check if these mach with the users database
* @return If the pass mach with the user, return true, if not, return false
*/
bool validate_pass(); bool validate_pass();
/**
* @brief create_user
* Recive an user and password to create a user
*/
void create_user(); void create_user();
/**
* @brief remove_user
* Recive a user to remove it
*/
void remove_user(); void remove_user();
private: private:
/**
* @brief appli_command
* Execute emerge with the passed parameter
* @param comand Parameter that recive emerge
* @param n_package Name ot the package
* @return The name of the package or err if he process fail
*/
std::string appli_command(char comand[], char* n_package); std::string appli_command(char comand[], char* n_package);
/**
* @brief read_data
* Recive data from a socket
* @param input Buffer to deposite the info
* @param size Max size of a info readed
* @return Number of bytes readed
*/
virtual int read_data(char* input, int size); virtual int read_data(char* input, int size);
/**
* @brief write_data
* Write data using a socket
* @param output
* String to have te info to send
* @return Number of bytes writed
*/
virtual int write_data(std::string output); virtual int write_data(std::string output);
/**
* @brief fd
* Socket file desccriptor
*/
int fd; int fd;
/**
* @brief data
* Object that contain media used to store and read information
*/
data_acces* data; data_acces* data;
char** args; /**
* @brief user
* Name of the session owner
*/
std::string user; std::string user;
/**
* @brief admin
* Privileges abut the user
*/
bool admin; bool admin;
}; };

View File

@ -6,10 +6,29 @@
class session_manager_ssl : public session_manager class session_manager_ssl : public session_manager
{ {
public: public:
/**
* @brief session_manager_ssl
* Object that gide a secure session
* @param fd File desccriptor used in the ssl conexion
*/
session_manager_ssl(SSL* fd); session_manager_ssl(SSL* fd);
int read_data(char* input, int size);
int write_data(std::string output);
private: private:
/**
* @brief read_data
* Recive data from a secure socket
* @param input Buffer to deposite the info
* @param size Max size of a info readed
* @return Number of bytes readed
*/
int read_data(char* input, int size);
/**
* @brief write_data
* Write data using a secure socket
* @param output
* String to have te info to send
* @return Number of bytes writed
*/
int write_data(std::string output);
SSL* sfd; SSL* sfd;
}; };