AMISyslogConf.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*****************************************************************
  2. *****************************************************************
  3. *** **
  4. *** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. *** **
  6. *** All Rights Reserved. **
  7. *** **
  8. *** 6145-F, Northbelt Parkway, Norcross, **
  9. *** **
  10. *** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. *** **
  12. *****************************************************************
  13. *****************************************************************
  14. ******************************************************************
  15. *
  16. * AMISyslogConf.c
  17. * AMI Syslog configuration related implementation.
  18. *
  19. * Author: Gokula Kannan. S <gokulakannans@amiindia.co.in>
  20. ******************************************************************/
  21. #include "string.h"
  22. #include "stdlib.h"
  23. #include "Debug.h"
  24. #include "Support.h"
  25. #include "IPMIDefs.h"
  26. #include "syslogconf.h"
  27. #include "AMISyslogConf.h"
  28. #include "IPMI_AMISyslogConf.h"
  29. /**
  30. * @fn CheckInputParams
  31. * @brief Check the input parameter and its length.
  32. * @param[in] pSetSyslogConf - pointer to the set syslog conf structure.
  33. * @param[in] ReqLen - Length of the request.
  34. * @retval CC_NORMAL, on success,
  35. * CC_REQ_INV_LEN, if the given length is not valid,
  36. * CC_INV_DATA_FIELD, if the given data is not valid.
  37. */
  38. static INT8U CheckInputParams(AMISetLogConfReq_T *pSetSyslogConf, INT32U ReqLen)
  39. {
  40. if(pSetSyslogConf->Cmd == AUDITLOG)
  41. {
  42. /* Request for Audit log */
  43. if(ReqLen != SIZE_AUDIT)
  44. {
  45. return CC_REQ_INV_LEN;
  46. }
  47. /* Audit log is supported to disable
  48. * or enable local but not remote. */
  49. if(pSetSyslogConf->Status != DISABLE &&
  50. pSetSyslogConf->Status != ENABLE_LOCAL)
  51. return CC_INV_DATA_FIELD;
  52. }
  53. else if(pSetSyslogConf->Cmd == SYSLOG)
  54. {
  55. /* Request for system log */
  56. switch(pSetSyslogConf->Status)
  57. {
  58. case DISABLE:
  59. if(ReqLen != SIZE_SYS_DISABLE)
  60. return CC_REQ_INV_LEN;
  61. break;
  62. case ENABLE_LOCAL:
  63. if(ReqLen != SIZE_SYS_LOCAL)
  64. return CC_REQ_INV_LEN;
  65. break;
  66. case ENABLE_REMOTE:
  67. if(ReqLen != SIZE_SYS_REMOTE)
  68. return CC_REQ_INV_LEN;
  69. break;
  70. default:
  71. return CC_INV_DATA_FIELD;
  72. }
  73. }
  74. else
  75. {
  76. return CC_INV_DATA_FIELD;
  77. }
  78. return CC_NORMAL;
  79. }
  80. /**
  81. * @fn AMIGetLogConf
  82. * @brief Get the log configuration file.
  83. * @param[in] pReq - pointer to the request.
  84. * @param[in] ReqLen - Length of the request.
  85. * @param[out] pRes - pointer to the result.
  86. * @retval CC_NORMAL, on success,
  87. * CC_UNSPECIFIED_ERR, if any unknown errors.
  88. */
  89. int AMIGetLogConf(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes,int BMCInst)
  90. {
  91. INT32U size;
  92. AMIGetLogConfRes_T *pGetSyslogConf = (AMIGetLogConfRes_T *)pRes;
  93. TDBG("Inside AMIGetSyslogConf\n");
  94. memset(pGetSyslogConf, 0, sizeof(AMIGetLogConfRes_T));
  95. pGetSyslogConf->CompletionCode = CC_UNSPECIFIED_ERR;
  96. /* Get the status of the system log and audit log */
  97. GetSyslogConf(&(pGetSyslogConf->SysStatus), &(pGetSyslogConf->AuditStatus),
  98. pGetSyslogConf->Config.Remote.HostName);
  99. /* Get the logrotate and size if the system status is local */
  100. if(pGetSyslogConf->SysStatus == ENABLE_LOCAL)
  101. {
  102. GetLogRotate(&(pGetSyslogConf->Config.Local.Rotate), &size);
  103. pGetSyslogConf->Config.Local.Size = size;
  104. pGetSyslogConf->CompletionCode = CC_NORMAL;
  105. return sizeof(AMIGetLogConfRes_T) - (sizeof(pGetSyslogConf->Config) - sizeof(pGetSyslogConf->Config.Local));
  106. }
  107. pGetSyslogConf->CompletionCode = CC_NORMAL;
  108. return sizeof(AMIGetLogConfRes_T) - (sizeof(pGetSyslogConf->Config) - sizeof(pGetSyslogConf->Config.Remote));
  109. }
  110. /**
  111. * @fn AMISetLogConf
  112. * @brief Set the log configuration file.
  113. * @param[in] pReq - pointer to the request.
  114. * @param[in] ReqLen - Length of the request.
  115. * @param[out] pRes - pointer to the result.
  116. * @retval CC_NORMAL, on success,
  117. * CC_REQ_INV_LEN, if the given length is not valid,
  118. * CC_INV_DATA_FIELD, if the given data is not valid,
  119. * CC_UNSPECIFIED_ERR, if any unknown errors.
  120. */
  121. int AMISetLogConf(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes,int BMCInst)
  122. {
  123. AMISetLogConfReq_T *pSetSyslogConf = (AMISetLogConfReq_T *)pReq;
  124. (*pRes) = CC_NORMAL;
  125. TDBG("Inside AMISetSyslogConf\n");
  126. /* Validate the input parameters */
  127. (*pRes) = CheckInputParams(pSetSyslogConf, ReqLen);
  128. if((*pRes) != CC_NORMAL)
  129. goto end;
  130. if(pSetSyslogConf->Cmd == AUDITLOG)
  131. {
  132. switch(pSetSyslogConf->Status)
  133. {
  134. case DISABLE:
  135. /* Request for audit log disable */
  136. if(AuditlogDisable() != 0)
  137. *pRes = CC_UNSPECIFIED_ERR;
  138. break;
  139. case ENABLE_LOCAL:
  140. /* Request for audit log enable */
  141. if(AuditlogEnable() != 0)
  142. *pRes = CC_UNSPECIFIED_ERR;
  143. break;
  144. default:
  145. *pRes = CC_INV_DATA_FIELD;
  146. }
  147. }
  148. else
  149. {
  150. switch(pSetSyslogConf->Status)
  151. {
  152. case DISABLE:
  153. /* Request for system log disable */
  154. if(SyslogDisable() != 0)
  155. {
  156. (*pRes) = CC_UNSPECIFIED_ERR;
  157. }
  158. break;
  159. case ENABLE_LOCAL:
  160. /* Request for system log enable local */
  161. if((SyslogEnableLocal() != 0) || (SetLogRotate(pSetSyslogConf->Config.Local.Rotate,
  162. pSetSyslogConf->Config.Local.Size) != 0))
  163. {
  164. (*pRes) = CC_UNSPECIFIED_ERR;
  165. }
  166. break;
  167. case ENABLE_REMOTE:
  168. /* Request for system log enable to log in remote syslog server */
  169. if(SyslogEnableRemote(pSetSyslogConf->Config.Remote.HostName) != 0)
  170. {
  171. (*pRes) = CC_UNSPECIFIED_ERR;
  172. }
  173. break;
  174. default:
  175. *pRes = CC_INV_DATA_FIELD;
  176. }
  177. }
  178. end:
  179. return sizeof(*pRes);
  180. }