Badpasswd.c 13 KB

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