Badpasswd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /******************************************************************
  2. ******************************************************************
  3. *** **
  4. *** (C)Copyright 2006-2009, American Megatrends Inc. **
  5. *** **
  6. *** All Rights Reserved. **
  7. *** **
  8. *** 5555 , Oakbrook Pkwy, Norcross, **
  9. *** **
  10. *** Georgia - 30093, USA. Phone-(770)-246-8600. **
  11. *** **
  12. ******************************************************************
  13. ******************************************************************
  14. ******************************************************************
  15. *
  16. * Badpasswd.c
  17. * Badpasswd related codes
  18. *
  19. * Author: Winston <winstonv@amiindia.co.in>
  20. ******************************************************************/
  21. #define ENABLE_DEBUG_MACROS 0
  22. #include "Types.h"
  23. #include "Debug.h"
  24. #include "PMConfig.h"
  25. #include "Session.h"
  26. #include "MsgHndlr.h"
  27. #include "Ethaddr.h"
  28. #include "Badpasswd.h"
  29. #include "NVRData.h"
  30. #include "NVRAccess.h"
  31. //#include "SensorMonitor.h"
  32. #include "SharedMem.h"
  33. #include "IPMIConf.h"
  34. /*
  35. *@fn CheckPasswordViolation
  36. *@param SerialorLAN - Denotes the channnel number is Serial or LAN
  37. *@param Ch - Channel Number
  38. *@return Returns 0
  39. */
  40. int CheckPasswordViolation(INT8U SerialorLAN,INT8U Ch,int BMCInst)
  41. {
  42. int j,EthIndex=0;
  43. INT8U Index=0,ThresholdVal=0;
  44. ChannelInfo_T*pChannelInfo=NULL;
  45. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  46. ChannelUserInfo_T* pChUserInfo = NULL;
  47. INT16U AttemptResetInterval = 0,LockOutInterval =0;
  48. if(SerialorLAN == LAN_CHANNEL_BADP)
  49. {
  50. EthIndex = GetEthIndex(Ch,BMCInst);
  51. ThresholdVal = pBMCInfo->LANCfs[EthIndex].BadPasswd.ThreshNum;
  52. AttemptResetInterval = pBMCInfo->LANCfs[EthIndex].BadPasswd.ResetInterval;
  53. LockOutInterval = pBMCInfo->LANCfs[EthIndex].BadPasswd.LockoutInterval;
  54. }
  55. else if(SerialorLAN == SERIAL_CHANNEL_BADP)
  56. {
  57. ThresholdVal = pBMCInfo->SMConfig.BadPasswd.ThreshNum;
  58. AttemptResetInterval = pBMCInfo->SMConfig.BadPasswd.ResetInterval;
  59. LockOutInterval = pBMCInfo->SMConfig.BadPasswd.LockoutInterval;
  60. }
  61. else
  62. {
  63. /* Bad Password validation has to be done for only
  64. Serial and LAN Interface */
  65. return 0;
  66. }
  67. if(ThresholdVal != 0)
  68. {
  69. pChannelInfo = getChannelInfo(Ch,BMCInst);
  70. if(NULL == pChannelInfo)
  71. {
  72. TDBG("Unable to get Channel Info to Check Password Violation for channel : %d \n",Ch);
  73. return 0;
  74. }
  75. if(pChannelInfo != NULL)
  76. {
  77. for(j=1;j<=g_BMCInfo[BMCInst].IpmiConfig.MaxUsers;j++)
  78. {
  79. pChUserInfo = getChUserIdInfo(j,&Index,pChannelInfo->ChannelUserInfo,BMCInst);
  80. if(pChUserInfo != NULL)
  81. {
  82. if((pChUserInfo->LockedTime != 0) && (pChUserInfo->Lock == USER_LOCKED)
  83. && (LockOutInterval != 0))
  84. {
  85. if((TimeUpdate() - pChUserInfo->LockedTime) > (10 * LockOutInterval))
  86. {
  87. pChUserInfo->Lock = USER_UNLOCKED;
  88. pChUserInfo->LockedTime = 0;
  89. pChUserInfo->FailureAttempts = 0;
  90. }
  91. }
  92. if((pChUserInfo->LockedTime != 0) && (pChUserInfo->Lock == USER_UNLOCKED)
  93. && (AttemptResetInterval!= 0))
  94. {
  95. if((TimeUpdate() - pChUserInfo->LockedTime) > (10 * AttemptResetInterval))
  96. {
  97. pChUserInfo->LockedTime = 0;
  98. pChUserInfo->FailureAttempts = 0;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. return 0;
  106. }
  107. /*
  108. *@fn MonitorPassword
  109. *@brief This function monitors the invalid password attempts
  110. */
  111. void MonitorPassword(int BMCInst)
  112. {
  113. int i=0;
  114. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  115. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  116. for(i=0;i<MAX_NUM_CHANNELS;i++)
  117. {
  118. if(IsLANChannel(i,BMCInst))
  119. {
  120. CheckPasswordViolation(LAN_CHANNEL_BADP,i,BMCInst);
  121. }
  122. else if(pBMCInfo->IpmiConfig.SerialIfcSupport == 0x1 && pBMCInfo->SERIALch == i)
  123. {
  124. CheckPasswordViolation(SERIAL_CHANNEL_BADP,i,BMCInst);
  125. }
  126. }
  127. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  128. }
  129. /*
  130. *@fn FindUserLockStatus
  131. *@param Userid - UserId to get the status
  132. *@param Channel - Status of the user for the specified channel
  133. *@return Returns 0 success
  134. * Returns -1 on failure
  135. */
  136. int FindUserLockStatus(INT8U Userid,INT8U Channel,int BMCInst)
  137. {
  138. INT8U Index=0;
  139. ChannelInfo_T*pChannelInfo = getChannelInfo(Channel,BMCInst);
  140. if(NULL == pChannelInfo)
  141. {
  142. TDBG("Unable to get Channel Info to Find User Lock Status for channel : %d \n",Channel);
  143. return 0;
  144. }
  145. if(pChannelInfo != NULL)
  146. {
  147. ChannelUserInfo_T *pChUserInfo = getChUserIdInfo (Userid , &Index, pChannelInfo->ChannelUserInfo,BMCInst);
  148. if(pChUserInfo != NULL)
  149. {
  150. if(pChUserInfo->Lock == USER_UNLOCKED)
  151. {
  152. return 0;
  153. }
  154. else
  155. {
  156. return -1;
  157. }
  158. }
  159. else
  160. {
  161. return 0;
  162. }
  163. }
  164. else
  165. {
  166. return 0;
  167. }
  168. /* Control doesn't reach here*/
  169. return 0;
  170. }
  171. /*
  172. * @fn LockUser
  173. * @param Userid - Password to be locked for Userid
  174. * @param Channel - Channel Number
  175. * @return Returns 0 on success
  176. */
  177. int LockUser(INT8U Userid,INT8U Channel,int BMCInst)
  178. {
  179. INT8U Index=0,EthIndex=0;
  180. ChannelInfo_T*pChannelInfo = getChannelInfo(Channel,BMCInst);
  181. if(NULL == pChannelInfo)
  182. {
  183. TDBG("Unable to get Channel Info to Lock User for channel : %d \n",Channel);
  184. return 0;
  185. }
  186. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  187. INT8U ThresholdNum= 0xFF;
  188. if(IsLANChannel(Channel,BMCInst))
  189. {
  190. EthIndex = GetEthIndex(Channel,BMCInst);
  191. ThresholdNum = pBMCInfo->LANCfs[EthIndex].BadPasswd.ThreshNum;
  192. }
  193. else if(pBMCInfo->IpmiConfig.SYSIfcSupport == 1 && pBMCInfo->SERIALch == Channel)
  194. {
  195. ThresholdNum = pBMCInfo->SMConfig.BadPasswd.ThreshNum; //TBD
  196. }
  197. else
  198. {
  199. /*If Channel no: does not belong to LAN or Serial
  200. Locking of User is discarded*/
  201. return 0;
  202. }
  203. ChannelUserInfo_T *pChUserInfo = getChUserIdInfo (Userid , &Index, pChannelInfo->ChannelUserInfo,BMCInst);
  204. if(ThresholdNum != 0 && pChUserInfo != NULL)
  205. {
  206. pChUserInfo->FailureAttempts++;
  207. pChUserInfo->LockedTime = TimeUpdate();
  208. if(pChUserInfo->FailureAttempts >= ThresholdNum)
  209. {
  210. pChUserInfo->Lock = USER_LOCKED;
  211. GenerateLockEvent(Channel,Userid,BMCInst);
  212. }
  213. }
  214. return 0;
  215. }
  216. /*
  217. *@fn UnlockUser
  218. *@param Userid -Password to be unlocked for Userid
  219. *@param Channel - Channel Number
  220. *@return Returns 0 on success
  221. */
  222. int UnlockUser(INT8U Userid,INT8U Channel,int BMCInst)
  223. {
  224. INT8U Index=0,EthIndex=0;
  225. ChannelInfo_T*pChannelInfo = getChannelInfo(Channel,BMCInst);
  226. if(NULL == pChannelInfo)
  227. {
  228. TDBG("Unable to get Channel Info to UnLock User for channel : %d \n",Channel);
  229. return 0;
  230. }
  231. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  232. INT8U ThresholdNum= 0xFF;
  233. if(pChannelInfo != NULL)
  234. {
  235. if(IsLANChannel(Channel,BMCInst))
  236. {
  237. EthIndex = GetEthIndex(Channel,BMCInst);
  238. ThresholdNum = pBMCInfo->LANCfs[EthIndex].BadPasswd.ThreshNum;
  239. }
  240. else if(pBMCInfo->IpmiConfig.SYSIfcSupport == 1 && pBMCInfo->SERIALch == Channel)
  241. {
  242. ThresholdNum = pBMCInfo->SMConfig.BadPasswd.ThreshNum; //TBD
  243. }
  244. else
  245. {
  246. /*If Channel no: does not belong to LAN or Serial
  247. Locking of User is discarded*/
  248. return 0;
  249. }
  250. ChannelUserInfo_T *pChUserInfo = getChUserIdInfo (Userid , &Index, pChannelInfo->ChannelUserInfo,BMCInst);
  251. if(ThresholdNum != 0 && pChUserInfo != NULL)
  252. {
  253. pChUserInfo->FailureAttempts=0;
  254. pChUserInfo->LockedTime = 0;
  255. pChUserInfo->Lock = USER_UNLOCKED;
  256. }
  257. }
  258. return 0;
  259. }
  260. /*
  261. *@fn ClearUserLockAttempts
  262. */
  263. int ClearUserLockAttempts(INT8U SerialorLAN,int BMCInst)
  264. {
  265. int i=0,j=0;
  266. INT8U Index=0;//,EthIndex=0;
  267. ChannelInfo_T*pChannelInfo=NULL;
  268. ChannelUserInfo_T* pChUserInfo = NULL;
  269. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  270. TDBG("Inside ClearUserlock \n");
  271. for(i=0;i<MAX_NUM_CHANNELS;i++)
  272. {
  273. if((IsLANChannel(i,BMCInst) && SerialorLAN == LAN_CHANNEL_BADP) ||
  274. ((pBMCInfo->IpmiConfig.SerialIfcSupport == 0x01) && (pBMCInfo->SERIALch == i) && (SerialorLAN == SERIAL_CHANNEL_BADP)))
  275. {
  276. pChannelInfo = getChannelInfo(i,BMCInst);
  277. if(pChannelInfo != NULL)
  278. {
  279. for(j=1;j<=g_BMCInfo[BMCInst].IpmiConfig.MaxChUsers;j++)
  280. {
  281. pChUserInfo = getChUserIdInfo(j,&Index,pChannelInfo->ChannelUserInfo,BMCInst);
  282. if(pChUserInfo != NULL)
  283. {
  284. TDBG("Unlocking the user \n");
  285. pChUserInfo->LockedTime = 0;
  286. pChUserInfo->FailureAttempts = 0;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. return 0;
  293. }
  294. /*
  295. *@fn GenerateLockEvent
  296. *@param Event -Denotes whether event has to be generated
  297. *@return Returns 0
  298. */
  299. int GenerateLockEvent(INT8U Channel,INT8U UserID,int BMCInst)
  300. {
  301. INT8U EventMsg[9],EthIndex=0,GenEvent=0;
  302. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  303. if(IsLANChannel(Channel,BMCInst))
  304. {
  305. EthIndex = GetEthIndex(Channel,BMCInst);
  306. GenEvent = pBMCInfo->LANCfs[EthIndex].BadPasswd.GenEvent & 0x01;
  307. }
  308. else if(pBMCInfo->IpmiConfig.SYSIfcSupport == 1 && pBMCInfo->SERIALch == Channel)
  309. {
  310. GenEvent = pBMCInfo->SMConfig.BadPasswd.GenEvent & 0x01;
  311. }
  312. if(GenEvent)
  313. {
  314. EventMsg[0] = pBMCInfo->IpmiConfig.BMCSlaveAddr; /* Generator ID */
  315. EventMsg[1] = 0; /* Generator ID */
  316. EventMsg[2] = 4; /* EvM Rev */
  317. EventMsg[3] = 0x2A; /* Sensor Type */
  318. EventMsg[4] = 0; /* Sensor Number*/ //TBD
  319. EventMsg[5] = 0x6F; /* Event Dir | Event Type */
  320. EventMsg[6] = 0x03; /* Event Data 1 */
  321. EventMsg[7] = UserID; /* Event Data 2 */
  322. EventMsg[8] = 0xFF; /* Event Data 3 */
  323. /* Post Event Message */
  324. if ( PostEventMessage(EventMsg,FALSE,sizeof(EventMsg),BMCInst) != 0)
  325. {
  326. TDBG("Generation of Event Message for User Lock failed \n");
  327. }
  328. }
  329. return 0;
  330. }