Purpose: Open a LogChannel to use a public logfile
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzLogger::OpenPublic | (const char*,hzLogRotate,) |
Declared in file: hzProcess.h
Defined in file : hzLogger.cpp
Function Logic:
Function body:
hzEcode hzLogger::OpenPublic (const char* fpath)hzLogRotate eRotate,
{
// Purpose: Open a LogChannel to use a public logfile
//
// Arguments: 1) fpath The logfile's publicly known path which must be in /etc/logserver.d/public_logs.conf
// 2) eRotate The log rotate edict
//
// Returns: E_HOSTFAIL If no connection to the logserver could be established
// E_SENDFAIL If the open command could not be sent to the logserver
// E_RECVFAIL If the logserver's response could not be received
// E_WRITEFAIL If the logserver fails to find the named public logfile
// E_PROTOCOL If the uid of the calling process is not permitted to write to the file
// E_OK If the logserver has opened a channel to the named public logfile
_hzfunc("hzLogger::OpenPublic") ;
uint32_t nSize ; // Size of logserver client request
uint32_t nUsr ; // UNIX user id
uint32_t nGrp ; // UNIX group id
uint32_t nProcID ; // Caller process id
uchar* u ; // Pointer into message buffer
// Connect to the logserver
m_pConnection = new hzTcpClient() ;
if (m_pConnection->ConnectStd(s_LocalHost, PORT_LOGSERVER) != E_OK)
return E_HOSTFAIL ;
// Prepare header
nSize = 16+strlen(fpath) ;
nProcID = getpid() ;
nUsr = geteuid() ;
nGrp = getegid() ;
u = (uchar*) m_cvData ;
// Command
u[0]= LS_OPEN_PUB ;
// Size of message
u[1]= (nSize & 0xff00)>>8;
u[2]= (nSize & 0xff);
// Process ID
u[3]= (nProcID & 0xff000000)>>24;
u[4]= (nProcID & 0xff0000)>>16;
u[5]= (nProcID & 0xff00)>>8;
u[6]= (nProcID & 0xff);
// User ID
u[7]= (nUsr & 0xff000000)>>24;
u[8]= (nUsr & 0xff0000)>>16;
u[9]= (nUsr & 0xff00)>>8;
u[10]=(nUsr & 0xff);
// Group ID
u[11]=(nGrp & 0xff000000)>>24;
u[12]=(nGrp & 0xff0000)>>16;
u[13]=(nGrp & 0xff00)>>8;
u[14]=(nGrp & 0xff);
// Filename
strncpy(m_cvData + 15,fpath,HZ_MAXPATHLEN) ;
// Send message and recv response
if (m_pConnection->Send(m_cvData, nSize) != E_OK)
return E_SENDFAIL ;
if (m_pConnection->Recv(m_cvData, nSize, 64)!=E_OK)
return E_RECVFAIL ;
if (nSize == 4&& m_cvData[0]== LS_OK)
{
m_nSessID = 0;
m_nSessID |= (u[1]<< 16);
m_nSessID |= (u[2]<< 8);
m_nSessID |= u[3];
return E_OK ;
}
if (m_cvData[0]== LS_ERR_PERM)
return E_WRITEFAIL ;
// Set data pointer
m_pDataPtr = m_cvData + 10;
return E_PROTOCOL ;
}