libipmi_usermgmt.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*****************************************************************
  2. ******************************************************************
  3. *** ***
  4. *** (C)Copyright 2008, American Megatrends Inc. ***
  5. *** ***
  6. *** All Rights Reserved ***
  7. *** ***
  8. *** 5555 Oakbrook Parkway, Norcross, GA 30093, USA ***
  9. *** ***
  10. *** Phone 770.246.8600 ***
  11. *** ***
  12. ******************************************************************
  13. ******************************************************************
  14. ******************************************************************
  15. *
  16. * Filename: libipmi_usermgmt.c
  17. *
  18. ******************************************************************/
  19. #include "libipmi_session.h"
  20. #include "libipmi_errorcodes.h"
  21. #include "libipmi_usermgmt.h"
  22. #include "com_IPMIDefs.h"
  23. #include "com_IPMI_App.h"
  24. #include "string.h"
  25. #include "com_IPMI_AppDevice.h"
  26. #include "com_IPMI_Storlead.h"
  27. uint16_t LIBIPMI_SetUser( IPMI20_UDS_SESSION_T *pUDSSession, char *pszUsername, uint8_t byID, int timeout )
  28. {
  29. SetUser_T UserInfo;
  30. int nUserNameLen;
  31. char byRes[MAX_RESPONSE_SIZE];
  32. uint32_t dwResLen;
  33. uint16_t wRet;
  34. if(byID > MAX_USER_NUM)
  35. {
  36. printf("Invalid UserID\n");
  37. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_ID);
  38. }
  39. else if( ((nUserNameLen=strlen(pszUsername)) == 0 ) || (nUserNameLen > MAX_USERNAME_LEN))
  40. {
  41. printf("Invalid UserName\n");
  42. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_NAME);
  43. }
  44. memset(&UserInfo, 0, sizeof(SetUser_T) );
  45. /* IPMI Spec Table 22-33 */
  46. UserInfo.byUserID = byID & ~(0xC0);
  47. strcpy(UserInfo.szUserName, pszUsername);
  48. /* Call RAW IPMI Command */
  49. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  50. DEFAULT_NET_FN_LUN, CMD_SET_USER_NAME,
  51. (uint8_t*)&UserInfo, sizeof(SetUser_T),
  52. byRes, &dwResLen,
  53. timeout);
  54. if(byRes[0] != 0)
  55. {
  56. printf("Delete user fail!\n");
  57. return -1;
  58. }
  59. if(wRet == LIBIPMI_E_SUCCESS)
  60. return STATUS_CODE(LIBIPMI_STATUS_SUCCESS, byRes[0]);
  61. return wRet;
  62. }
  63. uint16_t LIBIPMI_GetUser( IPMI20_UDS_SESSION_T *pUDSSession, char *pszUsername, uint8_t byID, int timeout )
  64. {
  65. GetUser_T UserInfo;
  66. uint32_t dwRetLen;
  67. uint16_t wRet;
  68. if(byID >= MAX_USER_NUM)
  69. {
  70. printf("Invalid UserID\n");
  71. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_ID);
  72. }
  73. memset(&UserInfo, 0, sizeof(GetUser_T) );
  74. dwRetLen = sizeof(GetUser_T);
  75. byID &= ~(0xC0);
  76. /* Call RAW IPMI Command */
  77. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  78. DEFAULT_NET_FN_LUN, CMD_GET_USER_NAME,
  79. &byID, sizeof(uint8_t),
  80. (uint8_t *)&UserInfo, &dwRetLen,
  81. timeout);
  82. if(wRet == LIBIPMI_E_SUCCESS)
  83. {
  84. strcpy(pszUsername, UserInfo.szUserName);
  85. return STATUS_CODE(LIBIPMI_STATUS_SUCCESS, UserInfo.byCompletionCode);
  86. }
  87. else
  88. {
  89. pszUsername[0] = (char)0;
  90. }
  91. return wRet;
  92. }
  93. uint16_t LIBIPMI_GetAllUserInfo( IPMI20_UDS_SESSION_T *pUDSSession, UserInfo_T *userInfoTbl, int timeout )
  94. {
  95. uint16_t wRet;
  96. uint32_t dwRetLen;
  97. uint8_t maxUser;
  98. uint8_t userID;
  99. GetUserNameRes_T UserInfo;
  100. int i;
  101. for(i=0;i<MAX_USER_NUM;i++)
  102. {
  103. userID = i+1;
  104. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  105. DEFAULT_NET_FN_LUN, CMD_GET_USER_NAME,
  106. (uint8_t *)&userID, 1,
  107. (uint8_t *)&UserInfo, &dwRetLen,
  108. timeout);
  109. if((wRet != 0) || (UserInfo.CompletionCode != 0))
  110. {
  111. userInfoTbl[i].UserStatus = FALSE;
  112. continue;
  113. }
  114. userInfoTbl[i].UserStatus = TRUE;
  115. userInfoTbl[i].UserId = i+1;
  116. memcpy(userInfoTbl[i].UserName, UserInfo.UserName, MAX_USERNAME_LEN);
  117. }
  118. return 0;
  119. }
  120. //uint8_t == bool
  121. uint8_t LIBIPMI_AuthorVerify( IPMI20_UDS_SESSION_T *pUDSSession, char *username, char *password, int timeout )
  122. {
  123. AuthorVerify_T req;
  124. uint8_t res;
  125. uint32_t dwRetLen;
  126. uint16_t wRet;
  127. if((username == NULL) || (username[0] == 0))
  128. {
  129. printf("username is NULL\n");
  130. return FALSE;
  131. }
  132. if(strlen(username) > MAX_USERNAME_LEN)
  133. {
  134. printf("username is too long!\n");
  135. return FALSE;
  136. }
  137. if(strlen(password) > MAX_PASSWORD_LEN)
  138. {
  139. printf("password is too long!\n");
  140. return FALSE;
  141. }
  142. memset(&req, 0, sizeof(AuthorVerify_T));
  143. strcpy(req.name, username);
  144. strcpy(req.password, password);
  145. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  146. NETFNLUN_IPMI_STORLEAD, CMD_AUTHOR_VERIFY,
  147. (uint8_t *)&req, sizeof(AuthorVerify_T),
  148. (uint8_t *)&res, &dwRetLen,
  149. timeout);
  150. if((wRet == 0) && (res == 0))
  151. {
  152. //verify ok
  153. return TRUE;
  154. }
  155. return FALSE;
  156. }
  157. uint16_t LIBIPMI_SetPassword( IPMI20_UDS_SESSION_T *pUDSSession, uint8_t userid, char *password, int timeout )
  158. {
  159. SetUserPswdReq_T req;
  160. SetUserPswdRes_T res;
  161. uint32_t dwRetLen;
  162. uint16_t wRet;
  163. if((userid <= 0) || (userid > MAX_USER_NUM))
  164. {
  165. printf("Invalid userid: %d\n", userid);
  166. return -1;
  167. }
  168. if (strlen(password) > MAX_PASSWORD_LEN)
  169. {
  170. printf("Invalid password Length: %d\n", strlen(password));
  171. return -1;
  172. }
  173. if((password == NULL) || (password[0] == 0))
  174. {
  175. printf("password is null!\n");
  176. return -1;
  177. }
  178. req.UserID = userid;
  179. req.Operation = 0x02;
  180. strcpy(req.Password, password);
  181. printf("---> req: %s, password: %s\n", req.Password, password);
  182. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,
  183. DEFAULT_NET_FN_LUN, CMD_SET_USER_PASSWORD,
  184. (uint8_t *)&req, sizeof(SetUserPswdReq_T),
  185. (uint8_t *)&res, &dwRetLen,
  186. timeout);
  187. if((wRet != 0) || (res.CompletionCode != 0))
  188. {
  189. printf("Ser password fail!\n");
  190. return -1;
  191. }
  192. return 0;
  193. }