sudo and doxygen
This commit is contained in:
		
							parent
							
								
									3387aa7ca1
								
							
						
					
					
						commit
						fda48edaf0
					
				| @ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!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> | ||||
|  <data> | ||||
|   <variable>EnvironmentId</variable> | ||||
| @ -56,7 +56,13 @@ | ||||
|   <variable>ProjectExplorer.Project.PluginSettings</variable> | ||||
|   <valuemap type="QVariantMap"> | ||||
|    <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> | ||||
|  </data> | ||||
|  <data> | ||||
|  | ||||
							
								
								
									
										15
									
								
								conexion.h
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								conexion.h
									
									
									
									
									
								
							| @ -7,10 +7,25 @@ using namespace std; | ||||
| class conexion | ||||
| { | ||||
| public: | ||||
|   /**
 | ||||
|    * @brief conexion | ||||
|    * Object that launch the server and start the sessions | ||||
|    * @param conf Configuration file | ||||
|    */ | ||||
|   conexion(config_reader &conf); | ||||
|   /**
 | ||||
|    * @brief start_server | ||||
|    * Start the server | ||||
|    */ | ||||
|   virtual void start_server(); | ||||
| protected: | ||||
|   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); | ||||
|   config_reader* config; | ||||
| }; | ||||
|  | ||||
| @ -7,12 +7,25 @@ | ||||
| class conexion_ssl : public conexion | ||||
| { | ||||
| public: | ||||
|   /**
 | ||||
|    * @brief conexion | ||||
|    * Object that launch the secure server and start the secure sessions | ||||
|    * @param conf Configuration file | ||||
|    */ | ||||
|     conexion_ssl(config_reader &conf); | ||||
|     void start_server(); | ||||
| private: | ||||
|     /*void init_openssl();
 | ||||
|     void cleanup_openssl();*/ | ||||
|     /**
 | ||||
|      * @brief create_context | ||||
|      * Create the SSL context | ||||
|      * @return SSL context | ||||
|      */ | ||||
|     SSL_CTX *create_context(); | ||||
|     /**
 | ||||
|      * @brief configure_context | ||||
|      * Configure the SSL context | ||||
|      * @param ctx Contest to configure | ||||
|      */ | ||||
|     void configure_context(SSL_CTX *ctx); | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -6,7 +6,17 @@ | ||||
| class config_package | ||||
| { | ||||
| public: | ||||
|   /**
 | ||||
|    * @brief config_package | ||||
|    * Generate a config file, or replace it | ||||
|    * @param name Name of the package | ||||
|    */ | ||||
|   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); | ||||
| private: | ||||
|   std::string name; | ||||
|  | ||||
| @ -6,7 +6,20 @@ | ||||
| class config_reader | ||||
| { | ||||
| 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); | ||||
| private: | ||||
|   std::ifstream file; | ||||
|  | ||||
							
								
								
									
										62
									
								
								data_acces.h
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								data_acces.h
									
									
									
									
									
								
							| @ -7,16 +7,76 @@ | ||||
| class data_acces | ||||
| { | ||||
| public: | ||||
|   /**
 | ||||
|    * @brief data_acces | ||||
|    * Interface to program objects that manage the stored data | ||||
|    */ | ||||
|   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; | ||||
|   /**
 | ||||
|    * @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; | ||||
|   /**
 | ||||
|    * @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; | ||||
|   /**
 | ||||
|    * @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; | ||||
|   /**
 | ||||
|    * @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_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; | ||||
|   /**
 | ||||
|    * @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; | ||||
|   /**
 | ||||
|    * @brief remove_user | ||||
|    * Remove a user | ||||
|    * @param user Name of the user to delete | ||||
|    */ | ||||
|   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); | ||||
| }; | ||||
| #endif // DATA_ACCES_H
 | ||||
|  | ||||
| @ -43,7 +43,7 @@ void session_manager::start_dialog(){ | ||||
|   while(true){ | ||||
|       int n_read=this->read_data(buffer,5); | ||||
|       if(strcmp(buffer, "exec")==0){ | ||||
|           this->execute(); | ||||
|           this->generate_package(); | ||||
|         }else if(strcmp(buffer, "info")==0){ | ||||
|           this->send_information(); | ||||
|         }else if(strcmp(buffer, "remv")==0){ | ||||
| @ -61,7 +61,7 @@ void session_manager::start_dialog(){ | ||||
|   delete[] (buffer); | ||||
| } | ||||
| 
 | ||||
| int session_manager::execute(){ | ||||
| int session_manager::generate_package(){ | ||||
|   char* n_package = new char[250]; | ||||
|   this->read_data(n_package, 5); | ||||
|   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){ | ||||
|   this->args=new char*[4]; | ||||
|     this->args[0]="emerge"; | ||||
|     this->args[1]=comand; | ||||
|     this->args[2]=n_package; | ||||
|     this->args[3]=nullptr; | ||||
|   char** args=new char*[5]; | ||||
|     args[0]="sudo"; | ||||
|     args[1]="emerge"; | ||||
|     args[2]=comand; | ||||
|     args[3]=n_package; | ||||
|     args[4]=nullptr; | ||||
|   int pid = fork(); | ||||
|   int status=-2; | ||||
|   std::string ret; | ||||
|   if(pid==0){ | ||||
|       if(execvp(this->args[0],this->args)==-1){ | ||||
|       if(execvp(args[0],args)==-1){ | ||||
|           std::cout << "error inesperado" << std::endl; | ||||
|         } | ||||
|       exit(0); | ||||
| @ -126,6 +127,7 @@ std::string session_manager::appli_command(char comand[], char* n_package){ | ||||
|         ret = "err"; | ||||
|       } | ||||
|   } | ||||
|   delete [] (args); | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -5,23 +5,99 @@ | ||||
| class session_manager | ||||
| { | ||||
| public: | ||||
|   /**
 | ||||
|    * @brief session_manager::session_manager | ||||
|    *  Object that guide a session | ||||
|    * @param fd Client flie descriptor | ||||
|    */ | ||||
|   session_manager(int fd); | ||||
|   /**
 | ||||
|    * @brief start_dialog | ||||
|    * Start the default state, ready to listen petitions | ||||
|    */ | ||||
|   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(); | ||||
|   /**
 | ||||
|    * @brief send_information | ||||
|    * Send the actual packages generated whit these aplication | ||||
|    */ | ||||
|   void send_information(); | ||||
|   /**
 | ||||
|    * @brief send_user_info | ||||
|    * Send the list of generated users and the privileges | ||||
|    */ | ||||
|   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(); | ||||
|   /**
 | ||||
|    * @brief create_user | ||||
|    * Recive an user and password to create a user | ||||
|    */ | ||||
|   void create_user(); | ||||
|   /**
 | ||||
|    * @brief remove_user | ||||
|    * Recive a user to remove it | ||||
|    */ | ||||
|   void remove_user(); | ||||
|  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); | ||||
|   /**
 | ||||
|    * @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); | ||||
|   /**
 | ||||
|    * @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); | ||||
|   /**
 | ||||
|    * @brief fd | ||||
|    * Socket file desccriptor | ||||
|    */ | ||||
|   int fd; | ||||
|   /**
 | ||||
|    * @brief data | ||||
|    * Object that contain media used to store and read information | ||||
|    */ | ||||
|   data_acces* data; | ||||
|   char** args; | ||||
|   /**
 | ||||
|    * @brief user | ||||
|    * Name of the session owner | ||||
|    */ | ||||
|   std::string user; | ||||
|   /**
 | ||||
|    * @brief admin | ||||
|    * Privileges abut the user | ||||
|    */ | ||||
|   bool admin; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -6,10 +6,29 @@ | ||||
| class session_manager_ssl : public session_manager | ||||
| { | ||||
| 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); | ||||
|   int read_data(char* input, int size); | ||||
|   int write_data(std::string output); | ||||
| 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; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user