AMISmtp.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. * AMISmtp.c
  16. * AMI SMTP extension Implementation
  17. *
  18. * Author: shivaranjanic <shivaranjanic@amiindia.co.in>
  19. *
  20. ******************************************************************/
  21. #define ENABLE_DEBUG_MACROS 0
  22. #include "Support.h"
  23. //#include "PMConfig.h"
  24. #include "NVRData.h"
  25. #include "NVRAccess.h"
  26. #include "IPMIDefs.h"
  27. #include "IPMI_AMISmtp.h"
  28. #include "AMISmtp.h"
  29. #include "Platform.h"
  30. #include "Ethaddr.h"
  31. #include <arpa/inet.h>
  32. //#include "IPMIConf.h"
  33. #include "blowfish.h"
  34. #include "featuredef.h"
  35. #include "nwcfg.h"
  36. #define ENABLE_DISABLE_MASK 0xFE
  37. const INT8U g_SMTPConfigParameterLength [] = {
  38. 1, /* Enable/disable */
  39. 4, /* Server IP Address */
  40. 0xFF, /* User Name */
  41. 0xFF, /* Passwd */
  42. 0x1, /* No of destinations */
  43. 1, /* SMTP user ID*/
  44. 0xFF, /* Mail subject */
  45. 0xFF , /* Message */
  46. 0xFF, /*Sender Email Address */
  47. 0xFF, /* Machine name */
  48. 2, /* SMTP Port*/
  49. 1, /*Enable/Disable SMTP Authentication */
  50. 16, /* IPV6 server Addess */
  51. 1, /* Enable/disable */
  52. 4, /* Server IP Address */
  53. 0xFF, /* User Name */
  54. 0XFF, /* Passwd */
  55. 0xFF, /*Sender Email Address */
  56. 0xFF, /* Machine name */
  57. 2, /* SMTP Port*/
  58. 1, /*Enable/Disable SMTP Authentication */
  59. 16 /* IPV6 server Addess */
  60. };
  61. /* It contain Block selector length and if Block selector length is zero then set selector also must be zero*/
  62. const INT8U g_SMTPBlockSelectorLength[] ={
  63. 0, /* Enable/disable */
  64. 0, /* Server IP Address */
  65. 0, /* User Name */
  66. 0, /* Passwd */
  67. 0, /* No of destinations */
  68. 0, /* SMTP user ID*/
  69. MAX_SUB_BLOCKS, /* Mail subject */
  70. MAX_MSG_BLOCKS, /* Message */
  71. MAX_EMAIL_ADDR_BLOCKS, /* Sender Address */
  72. MAX_SRV_NAME_BLOCKS, /* Machine Name*/
  73. 0, /*SMTP Port*/
  74. 0, /* Enable/disable SMTP Authentication */
  75. 16, /* IPV6 Server Address */
  76. 0, /* Enable/disable */
  77. 0, /* Server IP Address */
  78. 0, /* User Name */
  79. 0, /* Passwd */
  80. MAX_EMAIL_ADDR_BLOCKS, /* Sender Address */
  81. MAX_SRV_NAME_BLOCKS, /* Machine Name*/
  82. 0, /*SMTP Port*/
  83. 0, /* Enable/disable SMTP Authentication */
  84. 16 /* IPV6 Server Address */
  85. };
  86. int GetSMTP_PrimaryServer(SMTP_STRUCT *mail, INT8U SetSelector, INT8U EthIndex, int BMCInst)
  87. {
  88. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  89. Smtp_Config_T* pm_Smtp_Config = &pBMCInfo->SmtpConfig[EthIndex];
  90. int status = 0;
  91. INT8S decryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
  92. INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
  93. if(!pm_Smtp_Config->EnableDisableSMTP )
  94. {
  95. return OEM_SMTP_SERVER_DISABLED;
  96. }
  97. memset(mail, 0, sizeof(SMTP_STRUCT));
  98. mail->AuthEnable = pm_Smtp_Config->EnableDisableSmtpAuth;
  99. if(!mail->AuthEnable)
  100. {
  101. strcpy((char *)mail->username,"Administrator");
  102. }
  103. else
  104. {
  105. strcpy((char *)mail->username,(char *)pm_Smtp_Config->UserName );
  106. }
  107. if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
  108. {
  109. /* Get Encryption Key from the MBMCInfo_t structure */
  110. LOCK_BMC_SHARED_MEM(BMCInst);
  111. memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  112. UNLOCK_BMC_SHARED_MEM(BMCInst);
  113. if(DecryptPassword((INT8S *)pm_Smtp_Config->Passwd, MAX_SMTP_PASSWD_LEN-1, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
  114. {
  115. TCRIT("\n Error in Decrypting the Primary SMTP Password. \n");
  116. return -1;
  117. }
  118. strncpy((char *)mail->password, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN);
  119. mail->password[MAX_SMTP_PASSWD_LEN - 1] = '\0';
  120. }
  121. else
  122. {
  123. strcpy((char *)mail->password, (char *)pm_Smtp_Config->Passwd);
  124. }
  125. strcpy((char *)mail->from_addr,(char *)pm_Smtp_Config->SenderAddr);
  126. /* check whether IPv4 Address present */
  127. if( memcmp( &(pm_Smtp_Config->ServerAddr[0]), &status , IP_ADDR_LEN) !=0 )
  128. {
  129. if ( inet_ntop( AF_INET, (char*)pm_Smtp_Config->ServerAddr, (char*) mail->smtp_server, 46) == NULL )
  130. {
  131. printf("Error converting smtp server address to presentation format");
  132. }
  133. }
  134. else
  135. {
  136. if ( inet_ntop( AF_INET6, (char*)pm_Smtp_Config->IP6_ServerAddr, (char*) mail->smtp_server, 46) == NULL )
  137. {
  138. printf("Error converting smtp server address to presentation format");
  139. }
  140. }
  141. strcpy((char *)mail->subject, (char *)pm_Smtp_Config->Subject[SetSelector]);
  142. strcpy((char *)mail->message_body, (char *)pm_Smtp_Config->Msg[SetSelector]);
  143. mail->UserID = pm_Smtp_Config->UserID[SetSelector];
  144. strcpy((char *)mail->local_host,(char *)pm_Smtp_Config->Servername);
  145. mail->retryinterval = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].AlertAckTimeout;
  146. mail->smtp_retries = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].Retries;
  147. mail->smtp_portno = pm_Smtp_Config->SmtpPort;
  148. mail->resptimeout = 30;
  149. return 0;
  150. }
  151. int GetSMTP_SecondaryServer(SMTP_STRUCT *mail, INT8U SetSelector, INT8U EthIndex, int BMCInst)
  152. {
  153. int status = 0;
  154. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  155. Smtp_Config_T* pm_Smtp_Config = &pBMCInfo->SmtpConfig[EthIndex];
  156. INT8S decryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
  157. INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
  158. if(!pm_Smtp_Config->EnableDisableSMTP2 )
  159. {
  160. return OEM_SMTP_SERVER_DISABLED;
  161. }
  162. memset(mail, 0, sizeof(SMTP_STRUCT));
  163. mail->AuthEnable = pm_Smtp_Config->EnableDisableSmtp2Auth;
  164. if(!mail->AuthEnable)
  165. {
  166. strcpy((char *)mail->username,"Administrator");
  167. }
  168. else
  169. {
  170. strcpy((char *)mail->username,(char *)pm_Smtp_Config->UserName2 );
  171. }
  172. if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
  173. {
  174. /* Get Encryption Key from the MBMCInfo_t structure */
  175. LOCK_BMC_SHARED_MEM(BMCInst);
  176. memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  177. UNLOCK_BMC_SHARED_MEM(BMCInst);
  178. if(DecryptPassword((INT8S *)pm_Smtp_Config->Passwd2, MAX_SMTP_PASSWD_LEN, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN, pwdEncKey))
  179. {
  180. TCRIT("Error in Decrypting the Secondary SMTP Password. \n");
  181. return -1;
  182. }
  183. strncpy((char *)mail->password, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN);
  184. mail->password[MAX_SMTP_PASSWD_LEN - 1] = '\0';
  185. }
  186. else
  187. {
  188. strcpy((char *)mail->password, (char *)pm_Smtp_Config->Passwd2);
  189. }
  190. strcpy((char *)mail->from_addr,(char *)pm_Smtp_Config->Sender2Addr);
  191. /* check whether IPv4 Address present */
  192. if( memcmp( &(pm_Smtp_Config->Server2Addr[0]), &status , IP_ADDR_LEN) !=0 )
  193. {
  194. if ( inet_ntop( AF_INET, (char*)pm_Smtp_Config->Server2Addr, (char*) mail->smtp_server, 46) == NULL )
  195. {
  196. printf("Error converting smtp server address to presentation format");
  197. }
  198. }
  199. else if(strlen((char *)pm_Smtp_Config->IP6_Server2Addr) != 0)
  200. {
  201. if ( inet_ntop( AF_INET6, (char*)pm_Smtp_Config->IP6_Server2Addr, (char*) mail->smtp_server, 46) == NULL )
  202. {
  203. printf("Error converting smtp server address to presentation format");
  204. }
  205. }
  206. strcpy((char *)mail->subject, (char *)pm_Smtp_Config->Subject[SetSelector]);
  207. strcpy((char *)mail->message_body, (char *)pm_Smtp_Config->Msg[SetSelector]);
  208. mail->UserID = pm_Smtp_Config->UserID[SetSelector];
  209. strcpy((char *)mail->local_host,(char *)pm_Smtp_Config->Server2name);
  210. mail->retryinterval = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].AlertAckTimeout;
  211. mail->smtp_retries = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].Retries;
  212. mail->smtp_portno = pm_Smtp_Config->Smtp2Port;
  213. mail->resptimeout = 30;
  214. return 0;
  215. }
  216. int
  217. SetSMTPConfigParams (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  218. {
  219. SetSMTPConfigReq_T* pSetSMTPReq = ( SetSMTPConfigReq_T* ) pReq;
  220. SetSMTPConfigRes_T* pSetSMTPRes = ( SetSMTPConfigRes_T* ) pRes;
  221. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  222. Smtp_Config_T* pm_Smtp_Config;
  223. INT8S encryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
  224. INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
  225. int retValue;
  226. if(0xff ==GetEthIndex(pSetSMTPReq->Channel, BMCInst) || ( pSetSMTPReq->SetSelector > MAX_EMAIL_DESTINATIONS ))
  227. {
  228. *pRes = CC_INV_DATA_FIELD;
  229. return sizeof (INT8U);
  230. }
  231. else
  232. {
  233. pm_Smtp_Config = &pBMCInfo->SmtpConfig[GetEthIndex(pSetSMTPReq->Channel, BMCInst)];
  234. }
  235. ReqLen -= 4;
  236. /* Check the Parameter Selector length */
  237. if ( 0xFF != g_SMTPConfigParameterLength [pSetSMTPReq->ParameterSelect] )
  238. {
  239. if (ReqLen != g_SMTPConfigParameterLength [pSetSMTPReq->ParameterSelect])
  240. {
  241. pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
  242. return sizeof (INT8U);
  243. }
  244. }
  245. /* Check the Block Selector Value */
  246. if(pSetSMTPReq->BlockSelector != 0 )
  247. {
  248. if(g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] <= pSetSMTPReq->BlockSelector )
  249. {
  250. *pRes = CC_INV_DATA_FIELD;
  251. return sizeof (INT8U);
  252. }
  253. }else
  254. {
  255. /* If g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] =0 means It doesnot need set selector also except for Paramter 5(OEM_PARAM_SMTP_USERID)*/
  256. /*UserId requires Set selector*/
  257. if((g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] == 0) && (pSetSMTPReq->ParameterSelect != OEM_PARAM_SMTP_USERID) )
  258. {
  259. if(pSetSMTPReq->SetSelector !=0)
  260. {
  261. *pRes = CC_INV_DATA_FIELD;
  262. return sizeof (INT8U);
  263. }
  264. }
  265. }
  266. if( pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_USERID ||
  267. pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_MSG ||
  268. pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_SUBJECT)
  269. {
  270. /*UserID, Message and Subject is allowed to configure only if DestType is LAN_OEM1_ALERT(EMAIL) SMTP alerts types)*/
  271. if(pBMCInfo->LANCfs[GetEthIndex(pSetSMTPReq->Channel, BMCInst)].DestType [pSetSMTPReq->SetSelector - 1].DestType != LAN_OEM1_ALERT)
  272. {
  273. *pRes = CC_INV_DATA_FIELD;
  274. return sizeof (INT8U);
  275. }
  276. }
  277. if (g_PDKHandle[PDK_BEFORESETSMTPCFG] != NULL )
  278. {
  279. retValue = ((int(*)(INT8U *, INT8U, INT8U *,int))(g_PDKHandle[PDK_BEFORESETSMTPCFG]))(pReq, ReqLen, pRes, BMCInst);
  280. if(retValue != 0)
  281. {
  282. return retValue;
  283. }
  284. }
  285. switch (pSetSMTPReq->ParameterSelect)
  286. {
  287. case OEM_ENABLE_DISABLE_SMTP:
  288. if (0 != ( pSetSMTPReq-> ConfigData.EnableDisableSMTP & ENABLE_DISABLE_MASK ) )
  289. {
  290. *pRes = CC_INV_DATA_FIELD;
  291. return sizeof (INT8U);
  292. }
  293. pm_Smtp_Config->EnableDisableSMTP = pSetSMTPReq->ConfigData.EnableDisableSMTP & 0x01;
  294. break;
  295. case OEM_PARAM_SMTP_SERVR_ADDR :
  296. if(ReqLen == IP_ADDR_LEN) /* check for 4 bytes of server address length */
  297. {
  298. memset(&(pm_Smtp_Config->ServerAddr),0,IP_ADDR_LEN);
  299. memcpy ( &(pm_Smtp_Config->ServerAddr),pSetSMTPReq->ConfigData.ServerAddr ,IP_ADDR_LEN);
  300. memset( &(pm_Smtp_Config->IP6_ServerAddr) , 0 , IP6_ADDR_LEN);
  301. }
  302. else
  303. {
  304. pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
  305. return sizeof (INT8U);
  306. }
  307. break;
  308. case OEM_PARAM_SMTP_USER_NAME:
  309. if (ReqLen > MAX_SMTP_USERNAME_LEN-1)
  310. {
  311. *pRes = CC_REQ_INV_LEN;
  312. return sizeof (INT8U);
  313. }
  314. memset ( &(pm_Smtp_Config->UserName),0,MAX_SMTP_USERNAME_LEN-1 );
  315. memcpy ( &(pm_Smtp_Config->UserName),pSetSMTPReq->ConfigData.UserName, ReqLen);
  316. break;
  317. case OEM_PARAM_SMTP_PASSWD :
  318. if (ReqLen > MAX_SMTP_PASSWD_LEN -1)
  319. {
  320. *pRes = CC_REQ_INV_LEN;
  321. return sizeof (INT8U);
  322. }
  323. memset ( &(pm_Smtp_Config->Passwd),0, MAX_SMTP_PASSWD_LEN-1 );
  324. if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
  325. {
  326. /* Get Encryption Key from the MBMCInfo_t structure */
  327. LOCK_BMC_SHARED_MEM(BMCInst);
  328. memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  329. UNLOCK_BMC_SHARED_MEM(BMCInst);
  330. if(EncryptPassword((INT8S *)pSetSMTPReq->ConfigData.Passwd, MAX_SMTP_PASSWD_LEN-1, encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
  331. {
  332. TCRIT("Error in encrypting the Primary SMTP password.\n");
  333. pSetSMTPRes->CompletionCode = CC_UNSPECIFIED_ERR;
  334. return sizeof(INT8U);
  335. }
  336. memcpy(&(pm_Smtp_Config->Passwd), encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1);
  337. }
  338. else
  339. {
  340. memcpy(&(pm_Smtp_Config->Passwd), pSetSMTPReq->ConfigData.Passwd, ReqLen);
  341. }
  342. break;
  343. case OEM_PARAM_SMTP_NO_OF_DESTINATIONS:
  344. pSetSMTPRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
  345. return sizeof (INT8U);
  346. break;
  347. case OEM_PARAM_SMTP_USERID :
  348. pm_Smtp_Config->UserID[pSetSMTPReq->SetSelector]=pSetSMTPReq->ConfigData.UserID;
  349. break;
  350. case OEM_PARAM_SMTP_MSG:
  351. if (ReqLen > MAX_MSG_BLOCK_SIZE)
  352. {
  353. *pRes = CC_REQ_INV_LEN;
  354. return sizeof (INT8U);
  355. }
  356. memset( &(pm_Smtp_Config->Msg[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),0,MAX_MSG_BLOCK_SIZE);
  357. memcpy ( &(pm_Smtp_Config->Msg[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),&(pSetSMTPReq->ConfigData.Msg),ReqLen );
  358. break;
  359. case OEM_PARAM_SMTP_SUBJECT:
  360. if (ReqLen > MAX_MSG_BLOCK_SIZE)
  361. {
  362. *pRes = CC_REQ_INV_LEN;
  363. return sizeof (INT8U);
  364. }
  365. memset(&(pm_Smtp_Config->Subject[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_SUB_BLOCK_SIZE]),0,MAX_SUB_BLOCK_SIZE);
  366. memcpy (&(pm_Smtp_Config->Subject[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_SUB_BLOCK_SIZE]),&(pSetSMTPReq->ConfigData.Subject ),ReqLen );
  367. break;
  368. case OEM_PARAM_SMTP_SENDER_ADDR:
  369. if (ReqLen > MAX_EMAIL_BLOCK_SIZE)
  370. {
  371. *pRes = CC_REQ_INV_LEN;
  372. return sizeof (INT8U);
  373. }
  374. memset(&(pm_Smtp_Config->SenderAddr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),0 ,MAX_EMAIL_BLOCK_SIZE);
  375. memcpy ( &(pm_Smtp_Config->SenderAddr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),pSetSMTPReq->ConfigData.SenderAddr ,ReqLen);
  376. break;
  377. case OEM_PARAM_SMTP_HOST_NAME:
  378. if (ReqLen > MAX_SRV_NAME_BLOCK_SIZE)
  379. {
  380. *pRes = CC_REQ_INV_LEN;
  381. return sizeof (INT8U);
  382. }
  383. memset ( &(pm_Smtp_Config->Servername[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),0 ,MAX_SRV_NAME_BLOCK_SIZE);
  384. memcpy ( &(pm_Smtp_Config->Servername[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Servername ,ReqLen);
  385. break;
  386. case OEM_PARAM_SMTP_PORT :
  387. pm_Smtp_Config->SmtpPort= htoipmi_u16(pSetSMTPReq->ConfigData.SmtpPort);
  388. break;
  389. case OEM_ENABLE_DISABLE_SMTP_AUTH :
  390. pm_Smtp_Config->EnableDisableSmtpAuth = pSetSMTPReq->ConfigData.EnableDisableSmtpAuth;
  391. break;
  392. case OEM_PARAM_SMTP_IPV6_SERVR_ADDR :
  393. if( ReqLen == IP6_ADDR_LEN ) /* check for total 16 bytes of IPV6 address length */
  394. {
  395. /*Validate the IPv6 address*/
  396. if(IsValidGlobalIPv6Addr((struct in6_addr*)&pSetSMTPReq->ConfigData.IP6_ServerAddr))
  397. {
  398. TCRIT("Invalid Global IPv6 Address\n");
  399. *pRes = CC_INV_DATA_FIELD;
  400. return sizeof(INT8U);
  401. }
  402. memcpy ( &(pm_Smtp_Config->IP6_ServerAddr),pSetSMTPReq->ConfigData.IP6_ServerAddr ,IP6_ADDR_LEN);
  403. memset( &(pm_Smtp_Config->ServerAddr) , 0 , IP_ADDR_LEN);
  404. }
  405. else /* Invalid Request in length */
  406. {
  407. pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
  408. return sizeof (INT8U);
  409. }
  410. break;
  411. case OEM_ENABLE_DISABLE_SMTP2 :
  412. if (0 != ( pSetSMTPReq-> ConfigData.EnableDisableSMTP2 & ENABLE_DISABLE_MASK ) )
  413. {
  414. *pRes = CC_INV_DATA_FIELD;
  415. return sizeof (INT8U);
  416. }
  417. pm_Smtp_Config->EnableDisableSMTP2 = pSetSMTPReq->ConfigData.EnableDisableSMTP2 & 0x01;
  418. break;
  419. case OEM_PARAM_SMTP_2_SERVR_ADDR :
  420. if(ReqLen == IP_ADDR_LEN) /* check for 4 bytes of server address length */
  421. {
  422. memset(&(pm_Smtp_Config->Server2Addr),0,IP_ADDR_LEN);
  423. memcpy (&(pm_Smtp_Config->Server2Addr),pSetSMTPReq->ConfigData.Server2Addr ,IP_ADDR_LEN);
  424. memset( &(pm_Smtp_Config->IP6_Server2Addr) , 0 , IP6_ADDR_LEN);
  425. }
  426. else
  427. {
  428. pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
  429. return sizeof (INT8U);
  430. }
  431. break;
  432. case OEM_PARAM_SMTP_2_USER_NAME :
  433. if (ReqLen > MAX_SMTP_USERNAME_LEN-1)
  434. {
  435. *pRes = CC_REQ_INV_LEN;
  436. return sizeof (INT8U);
  437. }
  438. memset ( &(pm_Smtp_Config->UserName2),0,MAX_SMTP_USERNAME_LEN-1 );
  439. memcpy (&(pm_Smtp_Config->UserName2),pSetSMTPReq->ConfigData.UserName2, ReqLen);
  440. break;
  441. case OEM_PARAM_SMTP_2_PASSWD :
  442. if (ReqLen > MAX_SMTP_PASSWD_LEN -1)
  443. {
  444. *pRes = CC_REQ_INV_LEN;
  445. return sizeof (INT8U);
  446. }
  447. memset ( &(pm_Smtp_Config->Passwd2),0, MAX_SMTP_PASSWD_LEN-1 );
  448. if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
  449. {
  450. /* Get Encryption Key from the MBMCInfo_t structure */
  451. LOCK_BMC_SHARED_MEM(BMCInst);
  452. memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
  453. UNLOCK_BMC_SHARED_MEM(BMCInst);
  454. if(EncryptPassword((INT8S *)pSetSMTPReq->ConfigData.Passwd2, MAX_SMTP_PASSWD_LEN-1, encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
  455. {
  456. TCRIT("Error in encrypting the Secondary SMTP password.\n");
  457. pSetSMTPRes->CompletionCode = CC_UNSPECIFIED_ERR;
  458. return sizeof(INT8U);
  459. }
  460. memcpy(&(pm_Smtp_Config->Passwd2), encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1);
  461. }
  462. else
  463. {
  464. memcpy ( &(pm_Smtp_Config->Passwd2),pSetSMTPReq->ConfigData.Passwd2, ReqLen );
  465. }
  466. break;
  467. case OEM_PARAM_SMTP_2_SENDER_ADDR :
  468. if (ReqLen > MAX_EMAIL_BLOCK_SIZE)
  469. {
  470. *pRes = CC_REQ_INV_LEN;
  471. return sizeof (INT8U);
  472. }
  473. memset(&(pm_Smtp_Config->Sender2Addr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),0 ,MAX_EMAIL_BLOCK_SIZE);
  474. memcpy (&(pm_Smtp_Config->Sender2Addr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Sender2Addr ,ReqLen);
  475. break;
  476. case OEM_PARAM_SMTP_2_HOST_NAME :
  477. if (ReqLen > MAX_SRV_NAME_BLOCK_SIZE)
  478. {
  479. *pRes = CC_REQ_INV_LEN;
  480. return sizeof (INT8U);
  481. }
  482. memset (&(pm_Smtp_Config->Server2name[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),0 ,MAX_SRV_NAME_BLOCK_SIZE);
  483. memcpy (&(pm_Smtp_Config->Server2name[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Server2name ,ReqLen);
  484. break;
  485. case OEM_PARAM_SMTP_2_PORT :
  486. pm_Smtp_Config->Smtp2Port= htoipmi_u16(pSetSMTPReq->ConfigData.Smtp2Port);
  487. break;
  488. case OEM_ENABLE_DISABLE_SMTP_2_AUTH :
  489. pm_Smtp_Config->EnableDisableSmtp2Auth = pSetSMTPReq->ConfigData.EnableDisableSmtp2Auth;
  490. break;
  491. case OEM_PARAM_SMTP_2_IPV6_SERVR_ADDR :
  492. if( ReqLen == IP6_ADDR_LEN ) /* check for total 16 bytes of IPV6 address length */
  493. {
  494. /*Validate the IPv6 address*/
  495. if(IsValidGlobalIPv6Addr((struct in6_addr*)&pSetSMTPReq->ConfigData.IP6_Server2Addr))
  496. {
  497. TCRIT("Invalid Global IPv6 Address\n");
  498. *pRes = CC_INV_DATA_FIELD;
  499. return sizeof(INT8U);
  500. }
  501. memcpy ( &(pm_Smtp_Config->IP6_Server2Addr),pSetSMTPReq->ConfigData.IP6_Server2Addr ,IP6_ADDR_LEN);
  502. memset( &(pm_Smtp_Config->Server2Addr) , 0 , IP_ADDR_LEN);
  503. }
  504. else /* Invalid Request in length */
  505. {
  506. pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
  507. return sizeof (INT8U);
  508. }
  509. break;
  510. default:
  511. pSetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
  512. return sizeof (INT8U);
  513. }
  514. pSetSMTPRes->CompletionCode = CC_NORMAL ;
  515. FlushIPMI((INT8U*)&pBMCInfo->SmtpConfig[0],(INT8U*)&pBMCInfo->SmtpConfig[GetEthIndex(pSetSMTPReq->Channel, BMCInst)],
  516. pBMCInfo->IPMIConfLoc.SmtpConfigAddr,sizeof(Smtp_Config_T),BMCInst);
  517. return sizeof (INT8U);
  518. }
  519. int
  520. GetSMTPConfigParams (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
  521. {
  522. INT8U ResLen = 0;
  523. GetSMTPConfigReq_T* pGetSMTPReq = ( GetSMTPConfigReq_T* ) pReq;
  524. GetSMTPConfigRes_T* pGetSMTPRes = ( GetSMTPConfigRes_T* ) pRes;
  525. BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
  526. Smtp_Config_T* pm_Smtp_Config;
  527. if(0xff ==GetEthIndex(pGetSMTPReq->Channel, BMCInst) || (pGetSMTPReq->SetSelector > MAX_EMAIL_DESTINATIONS))
  528. {
  529. pGetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
  530. return sizeof (INT8U);
  531. }else
  532. {
  533. pm_Smtp_Config = &pBMCInfo->SmtpConfig[GetEthIndex(pGetSMTPReq->Channel, BMCInst)];
  534. }
  535. /* Check the Block Selector Value */
  536. if(pGetSMTPReq->BlockSelector != 0 )
  537. {
  538. if(g_SMTPBlockSelectorLength[pGetSMTPReq->ParameterSelect] <= pGetSMTPReq->BlockSelector )
  539. {
  540. *pRes = CC_INV_DATA_FIELD;
  541. return sizeof (INT8U);
  542. }
  543. }else
  544. {
  545. /* If g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] =0 means It doesnot need set selector also except for Paramter 5(OEM_PARAM_SMTP_USERID)*/
  546. /*UserId requires Set selector*/
  547. if((g_SMTPBlockSelectorLength[pGetSMTPReq->ParameterSelect] == 0) && (pGetSMTPReq->ParameterSelect != OEM_PARAM_SMTP_USERID) )
  548. {
  549. if(pGetSMTPReq->SetSelector !=0)
  550. {
  551. *pRes = CC_INV_DATA_FIELD;
  552. return sizeof (INT8U);
  553. }
  554. }
  555. }
  556. switch (pGetSMTPReq->ParameterSelect)
  557. {
  558. case OEM_ENABLE_DISABLE_SMTP:
  559. pGetSMTPRes->ConfigData.EnableDisableSMTP = pm_Smtp_Config->EnableDisableSMTP;
  560. ResLen = 1;
  561. break;
  562. case OEM_PARAM_SMTP_SERVR_ADDR :
  563. memcpy ( pGetSMTPRes->ConfigData.ServerAddr ,&(pm_Smtp_Config->ServerAddr),IP_ADDR_LEN);
  564. ResLen = IP_ADDR_LEN;
  565. break;
  566. case OEM_PARAM_SMTP_USER_NAME:
  567. memcpy ( pGetSMTPRes->ConfigData.UserName , &(pm_Smtp_Config->UserName),MAX_SMTP_USERNAME_LEN-1);
  568. ResLen = MAX_SMTP_USERNAME_LEN-1;
  569. break;
  570. case OEM_PARAM_SMTP_PASSWD :
  571. /* It Write only Parameter */
  572. *pRes = CC_INV_DATA_FIELD;
  573. return sizeof (INT8U);
  574. case OEM_PARAM_SMTP_NO_OF_DESTINATIONS:
  575. pGetSMTPRes->ConfigData.NoofDestinations = MAX_EMAIL_DESTINATIONS;
  576. ResLen = sizeof (INT8U);
  577. break;
  578. case OEM_PARAM_SMTP_USERID:
  579. pGetSMTPRes->ConfigData.UserID=pm_Smtp_Config->UserID[pGetSMTPReq->SetSelector];
  580. ResLen = sizeof (INT8U);
  581. break;
  582. case OEM_PARAM_SMTP_MSG:
  583. memcpy(&(pGetSMTPRes->ConfigData.Msg) ,&(pm_Smtp_Config->Msg[pGetSMTPReq->SetSelector][pGetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),MAX_MSG_BLOCK_SIZE );
  584. ResLen = MAX_MSG_BLOCK_SIZE;
  585. break;
  586. case OEM_PARAM_SMTP_SUBJECT:
  587. memcpy ( &(pGetSMTPRes->ConfigData.Subject), &( pm_Smtp_Config->Subject[pGetSMTPReq->SetSelector][pGetSMTPReq->BlockSelector * MAX_SUB_BLOCK_SIZE]),MAX_SUB_BLOCK_SIZE);
  588. ResLen = MAX_SUB_BLOCK_SIZE;
  589. break;
  590. case OEM_PARAM_SMTP_SENDER_ADDR:
  591. memcpy ( &(pGetSMTPRes->ConfigData.SenderAddr), &( pm_Smtp_Config->SenderAddr[pGetSMTPReq->BlockSelector *MAX_EMAIL_BLOCK_SIZE]),MAX_EMAIL_BLOCK_SIZE);
  592. ResLen = MAX_EMAIL_BLOCK_SIZE ;
  593. break;
  594. case OEM_PARAM_SMTP_HOST_NAME:
  595. memcpy ( &(pGetSMTPRes->ConfigData.Servername), &( pm_Smtp_Config->Servername[pGetSMTPReq->BlockSelector *MAX_SRV_NAME_BLOCK_SIZE]),MAX_SRV_NAME_BLOCK_SIZE);
  596. ResLen = MAX_SRV_NAME_BLOCK_SIZE;
  597. break;
  598. case OEM_PARAM_SMTP_PORT:
  599. pGetSMTPRes->ConfigData.SmtpPort = pm_Smtp_Config->SmtpPort;
  600. ResLen = sizeof(INT16U);
  601. break;
  602. case OEM_ENABLE_DISABLE_SMTP_AUTH:
  603. pGetSMTPRes->ConfigData.EnableDisableSmtpAuth = pm_Smtp_Config->EnableDisableSmtpAuth;
  604. ResLen = 1;
  605. break;
  606. case OEM_PARAM_SMTP_IPV6_SERVR_ADDR :
  607. memcpy ( pGetSMTPRes->ConfigData.IP6_ServerAddr , &(pm_Smtp_Config->IP6_ServerAddr), IP6_ADDR_LEN);
  608. ResLen =IP6_ADDR_LEN;
  609. break;
  610. case OEM_ENABLE_DISABLE_SMTP2 :
  611. pGetSMTPRes->ConfigData.EnableDisableSMTP2 = pm_Smtp_Config->EnableDisableSMTP2;
  612. ResLen = 1;
  613. break;
  614. case OEM_PARAM_SMTP_2_SERVR_ADDR :
  615. memcpy ( pGetSMTPRes->ConfigData.Server2Addr ,&(pm_Smtp_Config->Server2Addr),IP_ADDR_LEN);
  616. ResLen = IP_ADDR_LEN;
  617. break;
  618. case OEM_PARAM_SMTP_2_USER_NAME :
  619. memcpy ( pGetSMTPRes->ConfigData.UserName2 , &(pm_Smtp_Config->UserName2),MAX_SMTP_USERNAME_LEN-1 );
  620. ResLen = MAX_SMTP_USERNAME_LEN-1;
  621. break;
  622. case OEM_PARAM_SMTP_2_PASSWD :
  623. /* It Write only Parameter */
  624. *pRes = CC_INV_DATA_FIELD;
  625. return sizeof (INT8U);
  626. case OEM_PARAM_SMTP_2_SENDER_ADDR :
  627. memcpy ( &(pGetSMTPRes->ConfigData.Sender2Addr), &(pm_Smtp_Config->Sender2Addr[pGetSMTPReq->BlockSelector *MAX_EMAIL_BLOCK_SIZE]),MAX_EMAIL_BLOCK_SIZE);
  628. ResLen = MAX_EMAIL_BLOCK_SIZE ;
  629. break;
  630. case OEM_PARAM_SMTP_2_HOST_NAME :
  631. memcpy ( &(pGetSMTPRes->ConfigData.Server2name), &(pm_Smtp_Config->Server2name[pGetSMTPReq->BlockSelector *MAX_SRV_NAME_BLOCK_SIZE]),MAX_SRV_NAME_BLOCK_SIZE);
  632. ResLen = MAX_SRV_NAME_BLOCK_SIZE;
  633. break;
  634. case OEM_PARAM_SMTP_2_PORT :
  635. pGetSMTPRes->ConfigData.Smtp2Port = pm_Smtp_Config->Smtp2Port;
  636. ResLen = sizeof(INT16U);
  637. break;
  638. case OEM_ENABLE_DISABLE_SMTP_2_AUTH :
  639. pGetSMTPRes->ConfigData.EnableDisableSmtp2Auth = pm_Smtp_Config->EnableDisableSmtp2Auth;
  640. ResLen = 1;
  641. break;
  642. case OEM_PARAM_SMTP_2_IPV6_SERVR_ADDR :
  643. memcpy ( pGetSMTPRes->ConfigData.IP6_Server2Addr , &(pm_Smtp_Config->IP6_Server2Addr), IP6_ADDR_LEN);
  644. ResLen =IP6_ADDR_LEN;
  645. break;
  646. default:
  647. pGetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
  648. return sizeof (INT8U);
  649. }
  650. pGetSMTPRes->CompletionCode = 0 ;
  651. ResLen++; // byte for Completion Code
  652. return ResLen;
  653. }