RioUser Class Reference

#include <UserManager.h>

Public Member Functions

 ~RioUser ()
int CheckAccess (const char *Path, const int action=0)
int GetUserHome (char **Path)
int GetUser (char **User)
 Nome funcao para obter o nome do ususario.

Private Member Functions

 RioUser ()
 RioUser (CUserManager *mgr)

Private Attributes

char * user
char * user_home
CUserManageru_mgr

Friends

class CUserManager

Detailed Description

Definition at line 107 of file UserManager.h.


Constructor & Destructor Documentation

RioUser::RioUser (  )  [private]

Definition at line 1059 of file UserManager.cpp.

01060 {
01061     u_mgr     = NULL;
01062     user_home = NULL;
01063     user      = NULL;
01064 }

RioUser::RioUser ( CUserManager mgr  )  [private]

Definition at line 1067 of file UserManager.cpp.

01068 {
01069     u_mgr     = mgr;
01070     user_home = NULL;
01071     user      = NULL;
01072 }

RioUser::~RioUser (  ) 

Definition at line 1075 of file UserManager.cpp.

01076 {
01077     #ifdef RIO_DEBUG2
01078     if( u_mgr->m_log.is_open() )
01079         u_mgr->m_log << "User " << user_home << " log out.";
01080     #endif
01081     // ------------------------------------------------------------------------
01082     if( user_home != 0 )
01083     {
01084         delete [] user_home;
01085         user_home = 0;
01086     }
01087 
01088     if( user != 0 )
01089     {
01090         delete [] user;
01091         user = 0;
01092     }
01093 }


Member Function Documentation

int RioUser::CheckAccess ( const char *  Path,
const int  action = 0 
)

Definition at line 1111 of file UserManager.cpp.

01112 {
01113     int status = ERROR_CONNECTIONMANAGER + ERROR_PERMISSION_DENIED;
01114 
01115     // Stream opened to write
01116     if( action == 1 )
01117     {
01118         // Mudanca para adequar ao novo formato, onde o nome do usuario e dado
01119         // em user (atualmente este valor e igual ao de user_home).
01120         if( strcmp( user, "root" ) == 0 )
01121         {
01122             #ifdef RIO_DEBUG2
01123             RioErr << "RioUser::CheckAccess o usuario " << user << " pode "
01124                    << "sempre acessar para escrita qualquer caminho, incluindo "
01125                    << Path << "!" << endl;
01126             #endif
01127 
01128             status = S_OK;
01129         }
01130         else
01131         {
01132             // Armazena a string com a copia do inicio do caminho (nao podemos
01133             // alterar Path, porque e um const char).
01134             char *FirstPathComponent;
01135             // Armazena os ponteiros para inicio e o final da primeira
01136             // componente do caminho em Path.
01137             const char *StartFirstComponent, *EndFirstComponent;
01138             // Armazena o tamanho do primeiro componente.
01139             unsigned int FirstPathComponentSize;
01140 
01141             // Primeiramente descobrimos o inicio e o final do primeiro
01142             // componente do caminho.
01143             if( Path[ 0 ] == '/' )
01144                 StartFirstComponent = &Path[ 1 ];
01145             else
01146                 StartFirstComponent = Path;
01147 
01148             // Agora descobrimos o componente final, se existir.
01149             EndFirstComponent = strchr( StartFirstComponent, '/' );
01150             if( EndFirstComponent == NULL )
01151                 EndFirstComponent = &Path[ strlen( Path ) ];
01152 
01153             // Determina o tamanho do primeiro componente.
01154             FirstPathComponentSize = EndFirstComponent - StartFirstComponent;
01155 
01156             // Agora, alocamos a string temporaria, e copiamos o componente para
01157             // ela, se o tamanho for diferente de 0. Se o tamanho for igual a
01158             // 0, entao Path e igual a "/" ou "", indicando o diretorio raiz,
01159             // que nao pode ser acessado para escrita por um usuario diferente
01160             // do root.
01161             if( FirstPathComponentSize > 0 )
01162             {
01163                 try
01164                 {
01165                     FirstPathComponent = new char[ FirstPathComponentSize + 1 ];
01166 
01167                     // Copia o primeiro componente, e finaliza a string.
01168                     strncpy( FirstPathComponent, StartFirstComponent,
01169                              FirstPathComponentSize );
01170                     FirstPathComponent[ FirstPathComponentSize ] = 0;
01171 
01172                     #ifdef RIO_DEBUG2
01173                     RioErr << "RioUser::CheckAccess verificando se o usuario "
01174                            << user << " pode acessar para escrita o caminho "
01175                            << Path << ", sendo a primeira componente do "
01176                            << "caminho igual a " << FirstPathComponent << " e "
01177                            << "o caminho do diretorio do usuario sendo "
01178                            << user_home << ": ";
01179                     #endif
01180 
01181                     // Verifica se a componente pode ser acessada, ou seja, se e
01182                     // igual ao diretorio do usuario ou igual a var.
01183                     if( ( strcmp( FirstPathComponent, "var") == 0 ) ||
01184                         ( strcmp( FirstPathComponent, user_home) == 0 ) )
01185                     {
01186                         #ifdef RIO_DEBUG2
01187                         RioErr << "O usuario pode acessar o caminho!" << endl;
01188                         #endif
01189 
01190                         status = S_OK;
01191                     }
01192                     #ifdef RIO_DEBUG2
01193                     else
01194                         RioErr << "O usuario nao pode acessar o caminho!"
01195                                << endl;
01196                     #endif
01197 
01198                     // Remove a string com o primeiro componente.
01199                     delete[] FirstPathComponent;
01200                 }
01201                 catch( bad_alloc &ba )
01202                 {
01203                     if( u_mgr->m_log.is_open() )
01204                         u_mgr->m_log << "[RioUser] Memory error when cheking"
01205                                      << " if user " << user << "can access "
01206                                      << "path " << Path << " (bad_alloc="
01207                                      << ba.what() << "). Returning permission "
01208                                      << "denied error!" << endl;
01209                 }
01210             }
01211         }
01212     }
01213     else
01214     {
01215         #ifdef RIO_DEBUG2
01216         RioErr << "RioUser::CheckAccess o usuario " << user << " pode "
01217                << "sempre acessar para leitura qualquer caminho, incluindo "
01218                << Path << "!" << endl;
01219         #endif
01220 
01221         status = S_OK;
01222     }
01223 
01224     return status;
01225 }

int RioUser::GetUser ( char **  User  ) 

Nome funcao para obter o nome do ususario.

Parameters:
User ponteiro para um ponteiro apontado para o inicio da string com o nome do usuario.
Returns:
S_OK.

Definition at line 1103 of file UserManager.cpp.

01104 {
01105     *User = user;
01106     return S_OK;
01107 }

int RioUser::GetUserHome ( char **  Path  ) 

Definition at line 1096 of file UserManager.cpp.

01097 {
01098     *Path = user_home;
01099     return S_OK;
01100 }


Friends And Related Function Documentation

friend class CUserManager [friend]

Definition at line 118 of file UserManager.h.


Field Documentation

Definition at line 113 of file UserManager.h.

char* RioUser::user [private]

Definition at line 110 of file UserManager.h.

char* RioUser::user_home [private]

Definition at line 112 of file UserManager.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:37 2012 for RIO by  doxygen 1.6.3