libipmi_usermgmt.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_api.h"
  22. #include "libipmi_usermgmt.h"
  23. #include "string.h"
  24. uint16_t LIBIPMI_SetUser( IPMI20_SESSION_T *pSession, char *pszUsername, uint8_t byID, int timeout )
  25. {
  26. SetUser_T UserInfo;
  27. int nUserNameLen;
  28. char byRes[MAX_RESPONSE_SIZE];
  29. uint32_t dwResLen;
  30. uint16_t wRet;
  31. if(byID >= MAX_USER_NUM)
  32. {
  33. printf("Invalid UserID\n");
  34. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_ID);
  35. }
  36. else if( (nUserNameLen=strlen(pszUsername)) == 0 )
  37. {
  38. printf("Invalid UserName\n");
  39. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_NAME);
  40. }
  41. memset(&UserInfo, 0, sizeof(SetUser_T) );
  42. /* Truncate the username to 16 chars */
  43. (nUserNameLen > MAX_USER_NAME_LEN)?nUserNameLen = MAX_USER_NAME_LEN:nUserNameLen;
  44. /* IPMI Spec Table 22-33 */
  45. UserInfo.byUserID = byID & ~(0xC0);
  46. memcpy(UserInfo.szUserName, pszUsername, nUserNameLen);
  47. dwResLen = 1;
  48. /* Call RAW IPMI Command */
  49. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pSession, PAYLOAD_TYPE_IPMI,
  50. DEFAULT_NET_FN_LUN, CMD_SET_USER_NAME,
  51. (uint8_t*)&UserInfo, sizeof(SetUser_T),
  52. byRes, &dwResLen,
  53. timeout);
  54. if(wRet == LIBIPMI_E_SUCCESS)
  55. return STATUS_CODE(LIBIPMI_STATUS_SUCCESS, byRes[0]);
  56. return wRet;
  57. }
  58. uint16_t LIBIPMI_GetUser( IPMI20_SESSION_T *pSession, char *pszUsername, uint8_t byID, int timeout )
  59. {
  60. GetUser_T UserInfo;
  61. uint32_t dwRetLen;
  62. uint16_t wRet;
  63. if(byID >= MAX_USER_NUM)
  64. {
  65. printf("Invalid UserID\n");
  66. return STATUS_CODE(0, LIBIPMI_E_INVALID_USER_ID);
  67. }
  68. memset(&UserInfo, 0, sizeof(GetUser_T) );
  69. dwRetLen = sizeof(GetUser_T);
  70. byID &= ~(0xC0);
  71. /* Call RAW IPMI Command */
  72. wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pSession, PAYLOAD_TYPE_IPMI,
  73. DEFAULT_NET_FN_LUN, CMD_GET_USER_NAME,
  74. &byID, sizeof(uint8_t),
  75. (uint8_t *)&UserInfo, &dwRetLen,
  76. timeout);
  77. if(wRet == LIBIPMI_E_SUCCESS)
  78. {
  79. strcpy(pszUsername, UserInfo.szUserName);
  80. return STATUS_CODE(LIBIPMI_STATUS_SUCCESS, UserInfo.byCompletionCode);
  81. }
  82. else
  83. {
  84. pszUsername[0] = (char)0;
  85. }
  86. return wRet;
  87. }