AMIResetPass.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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. * AMIResetPass.c
  17. * AMI REset password related implementation.
  18. *
  19. * Author: Gokula Kannan. S <gokulakannans@amiindia.co.in>
  20. ******************************************************************/
  21. #include "Debug.h"
  22. #include "Support.h"
  23. #include "SharedMem.h"
  24. #include "PMConfig.h"
  25. #include "NVRData.h"
  26. #include "NVRAccess.h"
  27. #include "IPMIDefs.h"
  28. #include "IPMI_AMIResetPass.h"
  29. #include "AMIResetPass.h"
  30. #include "AppDevice.h"
  31. #include "IPMI_AppDevice.h"
  32. #include "IPMI_AMIDevice.h"
  33. #include "ipmi_userifc.h"
  34. #include "smtpclient.h"
  35. #include "nwcfg.h"
  36. #include "Session.h"
  37. #include "IPMI_AMISmtp.h"
  38. #include "AMISmtp.h"
  39. #include "Ethaddr.h"
  40. //#include "IPMIConf.h"
  41. #include "userprivilege.h"
  42. #include "featuredef.h"
  43. #include "blowfish.h"
  44. //Local Macros for Linux root user access
  45. #define LINUX_USER_MIN_PASSWORD_LEN 8
  46. #define LINUX_USER_MAX_PASSWORD_LEN 64
  47. #define OP_ONLY_CMD_LENGTH 1
  48. #define OP_SET_ROOT_PASSWD 2
  49. #define OP_ENABLE_USER_ID 1
  50. #define OP_DISABLE_USER_ID 0
  51. #define LINUX_ROOT_USER_UID 0
  52. static int validate_email(const char *emailaddr)
  53. {
  54. int valid = 0;
  55. const char *pTemp, *domain;
  56. static char *special_char = "()<>@,;:\\\"[]";
  57. /* first we validate the name portion (name@domain) */
  58. for (pTemp= emailaddr; *pTemp; pTemp++)
  59. {
  60. if (*pTemp == '\"' && (pTemp == emailaddr || *(pTemp - 1) == '.' || *(pTemp - 1) ==
  61. '\"')) {
  62. while (*++pTemp) {
  63. if (*pTemp == '\"') break;
  64. else if (*pTemp == '\\' && (*++pTemp == ' ')) continue;
  65. else if (*pTemp < ' ' || *pTemp >= 127) return 0;
  66. }
  67. if (!*pTemp++) return 0;
  68. else if (*pTemp == '@') break;
  69. else if (*pTemp != '.') return 0;
  70. continue;
  71. }
  72. else if (*pTemp == '@') break;
  73. else if (*pTemp <= ' ' || *pTemp >= 127) return 0;
  74. else if (strchr(special_char, *pTemp)) return 0;
  75. }
  76. if (pTemp == emailaddr || *(pTemp - 1) == '.') return 0;
  77. /* next we validate the domain portion (name@domain) */
  78. if (!*(domain = ++pTemp)) return 0;
  79. while (*pTemp)
  80. {
  81. if (*pTemp == '.')
  82. {
  83. if (pTemp == domain || *(pTemp - 1) == '.') return 0;
  84. else if(!*(pTemp +1))return 0;
  85. }
  86. else if (*pTemp <= ' ' || *pTemp >= 127) return 0;
  87. else if (strchr(special_char, *pTemp)) return 0;
  88. pTemp++;
  89. };
  90. if(!*pTemp)
  91. valid++;
  92. return (valid >= 1);
  93. }
  94. int AMISetEmailForUser(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  95. {
  96. AMISetUserEmailReq_T *pSetUserEmail = (AMISetUserEmailReq_T *)pReq;
  97. _FAR_ UserInfo_T* pUserInfo;
  98. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  99. TDBG("Inside AMISetEmailForUser %d \n", pSetUserEmail->UserID);
  100. if ( (0 != pSetUserEmail->EMailID[0]) && (0 == validate_email(pSetUserEmail->EMailID)) )
  101. {
  102. IPMI_WARNING ("Invalid Email address \n");
  103. *pRes = CC_INV_DATA_FIELD;
  104. return sizeof(*pRes);
  105. }
  106. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  107. pUserInfo = getUserIdInfo (pSetUserEmail->UserID, BMCInst);
  108. if ( (NULL == pUserInfo) || (pUserInfo->ID != USER_ID) )
  109. {
  110. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  111. IPMI_WARNING ("Invalid User Id \n");
  112. *pRes = CC_INV_DATA_FIELD;
  113. return sizeof(*pRes);
  114. }
  115. _fmemcpy (pUserInfo->UserEMailID, pSetUserEmail->EMailID, EMAIL_ADDR_SIZE);
  116. FlushIPMI((INT8U*)&pBMCInfo->UserInfo[0],(INT8U*)&pBMCInfo->UserInfo[0],pBMCInfo->IPMIConfLoc.UserInfoAddr,
  117. sizeof(UserInfo_T)*MAX_USER_CFG_MDS,BMCInst);
  118. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  119. *pRes = CC_NORMAL;
  120. return sizeof(*pRes);
  121. }
  122. int AMIGetEmailForUser(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  123. {
  124. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  125. int UserID = *(INT8U *)pReq;
  126. _FAR_ UserInfo_T* pUserInfo;
  127. TDBG("Inside AMIGetEmailForUser %d \n", UserID);
  128. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  129. pUserInfo = getUserIdInfo (UserID, BMCInst);
  130. if ( (NULL == pUserInfo) || (pUserInfo->ID != USER_ID))
  131. {
  132. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  133. IPMI_WARNING ("Invalid User Id \n");
  134. *pRes = CC_INV_DATA_FIELD;
  135. goto end;
  136. }
  137. *pRes = CC_NORMAL;
  138. if( pUserInfo->UserEMailID[0] != 0 )
  139. {
  140. _fmemcpy ((pRes+1), pUserInfo->UserEMailID, EMAIL_ADDR_SIZE);
  141. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  142. return sizeof(AMIGetUserEmailRes_T);
  143. }
  144. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  145. end:
  146. return sizeof(*pRes);
  147. }
  148. int AMIResetPassword(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  149. {
  150. AMIResetPasswordReq_T *pCmdReq = (AMIResetPasswordReq_T *)pReq;
  151. char eMailAdd[EMAIL_ADDR_SIZE];
  152. char userName[MAX_USERNAME_LEN];
  153. SetUserPswdReq_T ReqSetUserPswd;
  154. SetUserPswdRes_T ResSetUserPswd;
  155. char ClearPswd[MAX_PASSWORD_LEN];
  156. _FAR_ UserInfo_T* pUserInfo = NULL;
  157. char OldPswd[MAX_PASSWORD_LEN];
  158. int ret;
  159. int smtpServerFlag=0;// 0 - primary 1- secondary
  160. SMTP_STRUCT mail;
  161. int i, retVal = 0, ethIndex = 0;
  162. char letters_numbers[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  163. char PassLength = 0;
  164. INT8S DecryptedUserPswd[MAX_PASSWORD_LEN] = {0};
  165. INT8U PwdEncKey[MAX_SIZE_KEY] = {0};
  166. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  167. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  168. /* Get the username and E-Mail address */
  169. pUserInfo = getUserIdInfo (pCmdReq->UserID, BMCInst);
  170. if ( (NULL == pUserInfo) || (pUserInfo->ID != USER_ID))
  171. {
  172. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  173. IPMI_WARNING ("Invalid User Id \n");
  174. *(pRes) = CC_INV_DATA_FIELD;
  175. goto end;
  176. }
  177. if( pUserInfo->UserEMailID[0] == 0 )
  178. {
  179. IPMI_ERROR("Email not configured for the user\n");
  180. *(pRes) = OEMCC_EMAIL_NOT_CONFIGURED;
  181. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  182. goto end;
  183. }
  184. _fmemcpy (eMailAdd, pUserInfo->UserEMailID, EMAIL_ADDR_SIZE);
  185. _fmemcpy (userName, pUserInfo->UserName, MAX_USERNAME_LEN);
  186. if (g_corefeatures.userpswd_encryption == ENABLED)
  187. {
  188. /* Get Encryption Key from the MBMCInfo_t structure */
  189. memcpy(PwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  190. if(DecryptPassword((INT8S *)(pBMCInfo->EncryptedUserInfo[pCmdReq->UserID - 1].EncryptedPswd), MAX_PASSWORD_LEN, DecryptedUserPswd, MAX_PASSWORD_LEN, PwdEncKey))
  191. {
  192. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  193. TCRIT("Error in decrypting the IPMI User password for user with ID:%d.\n", pCmdReq->UserID);
  194. *pRes = CC_UNSPECIFIED_ERR;
  195. goto end;
  196. }
  197. memcpy(OldPswd, DecryptedUserPswd, MAX_PASSWORD_LEN);
  198. }
  199. else
  200. {
  201. _fmemcpy (OldPswd, pUserInfo->UserPassword, MAX_PASSWORD_LEN);
  202. }
  203. ethIndex = GetEthIndex(pCmdReq->Channel, BMCInst);
  204. if (ethIndex == 0xff)
  205. {
  206. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  207. *(pRes) = CC_INV_DATA_FIELD;
  208. goto end;
  209. }
  210. if((ret=GetSMTP_PrimaryServer(&mail,0,ethIndex,BMCInst))<0)
  211. {
  212. smtpServerFlag=1;
  213. if(GetSMTP_SecondaryServer(&mail,0,ethIndex,BMCInst)<0)
  214. {
  215. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  216. *(pRes) = OEMCC_SMTP_DISABLED;
  217. goto end;
  218. }
  219. }
  220. /* Generate password */
  221. TDBG("\n The previous user length %d \n",pUserInfo->MaxPasswordSize);
  222. if (pUserInfo->MaxPasswordSize == MAX_PASSWORD_LEN)
  223. {
  224. ReqSetUserPswd.UserID = pCmdReq->UserID | 0x80 ;
  225. PassLength = IPMI_20_PASSWORD_LEN;
  226. }
  227. else
  228. {
  229. ReqSetUserPswd.UserID = pCmdReq->UserID;
  230. PassLength = IPMI_15_PASSWORD_LEN;
  231. }
  232. ReqSetUserPswd.Operation = 0x02;
  233. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  234. memset(&ClearPswd, 0, MAX_PASSWORD_LEN);
  235. srand(time(0));
  236. i = (rand() % (MAX_PASSWORD_LEN-13)) + 8;
  237. TINFO("Random Number Length for Password : %d\n", i);
  238. for (i--; i >= 0; i--)
  239. {
  240. ClearPswd[i] = letters_numbers[(rand() % (sizeof(letters_numbers ) - 1))];
  241. }
  242. strncpy((char*)ReqSetUserPswd.Password, (char*)ClearPswd, MAX_PASSWORD_LEN);
  243. retVal = smtp_test(&mail);
  244. if(smtpServerFlag == 0)
  245. {
  246. if (retVal == ERR_UNABLE_TO_CONNECT_SMTPSERVER)
  247. {
  248. if(GetSMTP_SecondaryServer(&mail,0,ethIndex,BMCInst)<0)
  249. {
  250. *(pRes) = OEMCC_SMTP_DISABLED;
  251. goto end;
  252. }
  253. retVal = smtp_test(&mail);
  254. }
  255. }
  256. if ((retVal) != EMAIL_UNKNOWN)
  257. {
  258. if (retVal == ERR_AUTHENTICATION_FAILURE)
  259. *(pRes) = OEMCC_SEND_EMAIL_AUTH_FAILED;
  260. else if (retVal == ERR_UNABLE_TO_CONNECT_SMTPSERVER)
  261. *(pRes) = OEMCC_UNABLE_TO_CONNECT_SMTPSERVER;
  262. else if(retVal == ERR_UNSUPPORTED_AUTHTYPE)
  263. *(pRes) = OEMCC_UNSUPPORTED_AUTH_TYPE;
  264. else
  265. *(pRes) = OEMCC_SEND_EMAIL_FAILED;
  266. IPMI_ERROR("Test mail Server failed (%s) : %d\n", mail.smtp_server, retVal);
  267. goto end;
  268. }
  269. strcpy((char *)mail.to_addr, eMailAdd);
  270. sprintf((char *)mail.subject, "The %s Login Password has been changed",mail.local_host);
  271. sprintf((char *)mail.message_body, "The password has been reset for %s (host)\nUserName : %s\nPassword : %s\n",
  272. mail.local_host, userName, ClearPswd);
  273. TDBG("UserName : %s, Password : %s, To : %s, From : %s\n", mail.username,
  274. mail.password, mail.to_addr, mail.from_addr);
  275. TDBG("Subject : %s\n", mail.subject);
  276. TDBG("Mail : %s\n", mail.message_body);
  277. TDBG("SMTP Server : %s\n", mail.smtp_server);
  278. TDBG("The %s Login Password has been changed\n", mail.local_host);
  279. TDBG("The password has been reset for %s (host)\n\tUserName : %s\n\tPassword : %s\n",
  280. mail.local_host, userName, ClearPswd);
  281. /* Set user password */
  282. SetUserPassword((INT8U *)&ReqSetUserPswd, PassLength, (INT8U *)&ResSetUserPswd,BMCInst);
  283. if(ResSetUserPswd.CompletionCode != CC_NORMAL)
  284. {
  285. *(pRes) = ResSetUserPswd.CompletionCode;
  286. goto end;
  287. }
  288. /* Send mail */
  289. if ((retVal = smtp_mail(&mail)) != EMAIL_UNKNOWN)
  290. {
  291. if (retVal == ERR_AUTHENTICATION_FAILURE)
  292. *(pRes) = OEMCC_SEND_EMAIL_AUTH_FAILED;
  293. else if (retVal == ERR_UNABLE_TO_CONNECT_SMTPSERVER)
  294. *(pRes) = OEMCC_UNABLE_TO_CONNECT_SMTPSERVER;
  295. else if(retVal == ERR_UNSUPPORTED_AUTHTYPE)
  296. *(pRes) = OEMCC_UNSUPPORTED_AUTH_TYPE;
  297. else
  298. *(pRes) = OEMCC_SEND_EMAIL_FAILED;
  299. strncpy((char*)ReqSetUserPswd.Password, (char*)OldPswd, MAX_PASSWORD_LEN);
  300. /* Preserve Old password */
  301. SetUserPassword((INT8U *)&ReqSetUserPswd, sizeof(SetUserPswdReq_T), (INT8U *)&ResSetUserPswd,BMCInst);
  302. if(ResSetUserPswd.CompletionCode != CC_NORMAL)
  303. {
  304. *(pRes) = ResSetUserPswd.CompletionCode;
  305. goto end;
  306. }
  307. IPMI_ERROR("Send mail failed with the server (%s) : %d\n", mail.smtp_server, retVal);
  308. }
  309. else
  310. {
  311. *(pRes) = CC_NORMAL;
  312. }
  313. end:
  314. return sizeof(*(pRes));
  315. }
  316. int AMISetEmailFormatUser(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  317. {
  318. AMISetUserEmailFormatReq_T *pSetUserEmail = (AMISetUserEmailFormatReq_T *)pReq;
  319. _FAR_ UserInfo_T* pUserInfo;
  320. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  321. int cnt=0;
  322. char nulldata[EMAIL_FORMAT_SIZE]={0};
  323. TDBG("Inside AMISetEmailFormatUser %d \n", pSetUserEmail->UserID);
  324. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  325. pUserInfo = getUserIdInfo (pSetUserEmail->UserID, BMCInst);
  326. if ( (NULL == pUserInfo) || (pUserInfo->ID != USER_ID) )
  327. {
  328. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  329. IPMI_WARNING ("Invalid User Id \n");
  330. *pRes = CC_INV_DATA_FIELD;
  331. return sizeof(*pRes);
  332. }
  333. for(cnt=0;cnt< EmailformatCount;cnt++)
  334. {
  335. if(memcmp(g_PDKEmailFormat[cnt].EmailFormat,pSetUserEmail->EMailFormat,EMAIL_FORMAT_SIZE)==0)
  336. {
  337. break;
  338. }
  339. }
  340. if(cnt==EmailformatCount && (memcmp(pSetUserEmail->EMailFormat,nulldata,EMAIL_FORMAT_SIZE)!=0))//Disabling the EmailFormat if the data contains all zeroes.
  341. {
  342. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  343. IPMI_WARNING ("Invalid Email Format \n");
  344. *pRes = CC_INV_DATA_FIELD;
  345. return sizeof(*pRes);
  346. }
  347. _fmemcpy (pUserInfo->EmailFormat, pSetUserEmail->EMailFormat, EMAIL_FORMAT_SIZE);
  348. FlushIPMI((INT8U*)&pBMCInfo->UserInfo[0],(INT8U*)&pBMCInfo->UserInfo[0],pBMCInfo->IPMIConfLoc.UserInfoAddr,
  349. sizeof(UserInfo_T)*MAX_USER_CFG_MDS,BMCInst);
  350. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  351. *pRes = CC_NORMAL;
  352. return sizeof(*pRes);
  353. }
  354. int AMIGetEmailFormatUser(_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  355. {
  356. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  357. int UserID = *(INT8U *)pReq;
  358. _FAR_ UserInfo_T* pUserInfo;
  359. TDBG("Inside AMIGetEmailFormatUser %d \n", UserID);
  360. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  361. pUserInfo = getUserIdInfo (UserID, BMCInst);
  362. if ( (NULL == pUserInfo) || (pUserInfo->ID != USER_ID))
  363. {
  364. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  365. IPMI_WARNING ("Invalid User Id \n");
  366. *pRes = CC_INV_DATA_FIELD;
  367. return sizeof(*pRes);
  368. }
  369. *pRes = CC_NORMAL;
  370. if( pUserInfo->EmailFormat[0] != 0 )
  371. {
  372. _fmemcpy ((pRes+1), pUserInfo->EmailFormat, EMAIL_FORMAT_SIZE);
  373. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  374. return EMAIL_FORMAT_SIZE+1;
  375. }
  376. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  377. return sizeof(*pRes);
  378. }
  379. /*
  380. *@fn AMIGetRootUserAccess
  381. *@brief This command helps to get linux root user access state
  382. * @param pReq - Request for the command
  383. * @param ReqLen - Request length for the command
  384. * @param pRes - Respose for the command
  385. * @param BMCInst- BMC Instance
  386. * @return Returns size of AMISetRootPasswordRes_T
  387. */
  388. int AMIGetRootUserAccess (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  389. {
  390. _NEAR_ AMIGetRootUserAccessRes_T* pGetRootUserAccessRes = (_NEAR_ AMIGetRootUserAccessRes_T*)pRes;
  391. INT8U UserId,UserAccessState;
  392. INT16S Err = 0;
  393. UserId = LINUX_ROOT_USER_UID;
  394. pGetRootUserAccessRes->CompletionCode = CC_NORMAL;
  395. Err = LINUX_GetUserAccess (UserId,&UserAccessState);
  396. if (0 != Err)
  397. {
  398. IPMI_ERROR ("AMIResetPass.c : Setting password to Linux database failed\n");
  399. *pRes = abs (Err);
  400. return sizeof (*pRes);
  401. }
  402. else
  403. pGetRootUserAccessRes->CurrentUserIDState = UserAccessState ;
  404. return sizeof (AMIGetRootUserAccessRes_T);
  405. }
  406. /*
  407. *@fn SetRootPassword
  408. *@brief This command helps to set linux root user password,enabling root user,
  409. * disabling root user.
  410. * @param pReq - Request for the command
  411. * @param ReqLen - Request length for the command
  412. * @param pRes - Respose for the command
  413. * @param BMCInst- BMC Instance
  414. * @return Returns size of AMISetRootPasswordRes_T
  415. */
  416. int AMISetRootPassword (_NEAR_ INT8U *pReq, INT32U ReqLen, _NEAR_ INT8U *pRes,int BMCInst)
  417. {
  418. _NEAR_ AMISetRootPasswordReq_T* pSetRootPswdReq = (_NEAR_ AMISetRootPasswordReq_T*)pReq;
  419. INT16S Err = 0;
  420. if(ReqLen < OP_ONLY_CMD_LENGTH) //Checking for minimum command Request length
  421. {
  422. *pRes = CC_REQ_INV_LEN;
  423. return sizeof (*pRes);
  424. }
  425. //Checking for Valid operation
  426. if (ReqLen == OP_ONLY_CMD_LENGTH)
  427. {
  428. if ((pSetRootPswdReq->Operation != OP_ENABLE_USER_ID) && (pSetRootPswdReq->Operation != OP_DISABLE_USER_ID))
  429. {
  430. if(pSetRootPswdReq->Operation == OP_SET_ROOT_PASSWD)
  431. *pRes = CC_REQ_INV_LEN;
  432. else
  433. *pRes = CC_INV_DATA_FIELD;
  434. return sizeof (*pRes); //Invalid operation.
  435. }
  436. }
  437. if(ReqLen > OP_ONLY_CMD_LENGTH) //Checking for passwd length
  438. {
  439. if( ( (ReqLen-1) < LINUX_USER_MIN_PASSWORD_LEN) || ( (ReqLen-1) > LINUX_USER_MAX_PASSWORD_LEN) )
  440. {
  441. *pRes = CC_REQ_INV_LEN;
  442. return sizeof (*pRes);
  443. }
  444. pSetRootPswdReq->Password[ReqLen-1] = '\0';
  445. }
  446. *pRes = CC_NORMAL;
  447. Err = LINUX_SetRootPassword( pSetRootPswdReq->Operation, pSetRootPswdReq->Password);
  448. if (0 != Err)
  449. {
  450. IPMI_ERROR ("AMIResetPass.c : Setting password to Linux database failed\n");
  451. *pRes = abs (Err);
  452. return sizeof (*pRes);
  453. }
  454. return sizeof (*pRes);
  455. }
  456. /*
  457. *@fn AMIGetUserShelltype
  458. *@brief This command helps to get users shell
  459. * @param pReq - Request for the command
  460. * @param ReqLen - Request length for the command
  461. * @param pRes - Respose for the command
  462. * @param BMCInst- BMC Instance
  463. * @return Returns size of AMIGetUserShelltypeRes_T
  464. */
  465. int AMIGetUserShelltype(_NEAR_ INT8U *pReq, INT32U ReqLen, _NEAR_ INT8U *pRes,int BMCInst)
  466. {
  467. _NEAR_ AMIGetUserShelltypeReq_T* pGetUserShellReq = (_NEAR_ AMIGetUserShelltypeReq_T*)pReq;
  468. _NEAR_ AMIGetUserShelltypeRes_T* pGetUserShellRes = (_NEAR_ AMIGetUserShelltypeRes_T*)pRes;
  469. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  470. _FAR_ UserInfo_T* pUserInfo = NULL;
  471. INT8U UserId=0;
  472. UserId = pGetUserShellReq->UserID & 0x3F;
  473. /* if user ID exceeded the Max limit */
  474. if (pGetUserShellReq->UserID > pBMCInfo->IpmiConfig.MaxUsers)
  475. {
  476. pGetUserShellRes->CompletionCode = CC_INV_DATA_FIELD ;
  477. return sizeof (*pRes);/* Invalied user id */
  478. }
  479. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  480. pUserInfo = getUserIdInfo(UserId, BMCInst);
  481. /* User with given ID is not created */
  482. if ( NULL == pUserInfo )
  483. {
  484. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  485. *pRes = CC_INV_DATA_FIELD;
  486. return sizeof (*pRes);
  487. }
  488. pGetUserShellRes->CompletionCode = CC_NORMAL;
  489. pGetUserShellRes->Shelltype = pUserInfo->UserShell;
  490. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  491. return sizeof (AMIGetUserShelltypeRes_T);
  492. }
  493. /*
  494. *@fn AMISetUserShelltype
  495. *@brief This command helps to set users shell
  496. * @param pReq - Request for the command
  497. * @param ReqLen - Request length for the command
  498. * @param pRes - Respose for the command
  499. * @param BMCInst- BMC Instance
  500. * @return Returns size of AMISetUserShelltypeRes_T
  501. */
  502. int AMISetUserShelltype(_NEAR_ INT8U *pReq, INT32U ReqLen, _NEAR_ INT8U *pRes,int BMCInst)
  503. {
  504. _NEAR_ AMISetUserShelltypeReq_T* pSetUserShellReq = (_NEAR_ AMISetUserShelltypeReq_T*)pReq;
  505. _FAR_ UserInfo_T* pUserInfo = NULL;
  506. _FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo[BMCInst];
  507. INT8U UserId=0, ShellType;
  508. INT8U oldshell = -1, newshell = -1;
  509. UserId = pSetUserShellReq->UserID & 0x3F;
  510. ShellType = pSetUserShellReq->Shelltype;
  511. /* if user ID exceeded the Max limit */
  512. if (pSetUserShellReq->UserID > pBMCInfo->IpmiConfig.MaxUsers)
  513. {
  514. *pRes = CC_INV_DATA_FIELD ;
  515. return sizeof (*pRes);/* Invalied user id */
  516. }
  517. if((ShellType < 0) || (ShellType > MAX_SHELL_TYPES-1))
  518. {
  519. *pRes = CC_INV_DATA_FIELD;
  520. return sizeof (*pRes); //Invalid shell type
  521. }
  522. OS_THREAD_MUTEX_ACQUIRE(&pBMCInfo->ChUserMutex,WAIT_INFINITE);
  523. pUserInfo = getUserIdInfo(UserId, BMCInst);
  524. /* if User is not created */
  525. if ( NULL == pUserInfo )
  526. {
  527. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  528. *pRes = CC_INV_DATA_FIELD;
  529. return sizeof (*pRes);
  530. }
  531. /*if the user is fixed user */
  532. if (((pUserInfo != NULL) && (pUserInfo->FixedUser == TRUE)))
  533. {
  534. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  535. *pRes = CC_INV_DATA_FIELD ;
  536. return sizeof (*pRes);
  537. }
  538. newshell = ShellType;
  539. oldshell = pUserInfo->UserShell;
  540. pUserInfo->UserShell = newshell;
  541. AddIPMIUsrtoShellGrp((char *)pUserInfo->UserName, oldshell, newshell);
  542. FlushIPMI((INT8U*)&pBMCInfo->UserInfo[0],(INT8U*)&pBMCInfo->UserInfo[0],pBMCInfo->IPMIConfLoc.UserInfoAddr,
  543. sizeof(UserInfo_T)*MAX_USER_CFG_MDS,BMCInst);
  544. OS_THREAD_MUTEX_RELEASE(&pBMCInfo->ChUserMutex);
  545. *pRes = CC_NORMAL;
  546. return sizeof (*pRes);
  547. }