123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- /*****************************************************************
- *****************************************************************
- *** **
- *** (C)Copyright 2005-2006, American Megatrends Inc. **
- *** **
- *** All Rights Reserved. **
- *** **
- *** 6145-F, Northbelt Parkway, Norcross, **
- *** **
- *** Georgia - 30071, USA. Phone-(770)-246-8600. **
- *** **
- *****************************************************************
- ******************************************************************
- *
- * AMISmtp.c
- * AMI SMTP extension Implementation
- *
- * Author: shivaranjanic <shivaranjanic@amiindia.co.in>
- *
- ******************************************************************/
- #define ENABLE_DEBUG_MACROS 0
- #include "Support.h"
- //#include "PMConfig.h"
- #include "NVRData.h"
- #include "NVRAccess.h"
- #include "IPMIDefs.h"
- #include "IPMI_AMISmtp.h"
- #include "AMISmtp.h"
- #include "Platform.h"
- #include "Ethaddr.h"
- #include <arpa/inet.h>
- //#include "IPMIConf.h"
- #include "blowfish.h"
- #include "featuredef.h"
- #include "nwcfg.h"
- #define ENABLE_DISABLE_MASK 0xFE
- const INT8U g_SMTPConfigParameterLength [] = {
- 1, /* Enable/disable */
- 4, /* Server IP Address */
- 0xFF, /* User Name */
- 0xFF, /* Passwd */
- 0x1, /* No of destinations */
- 1, /* SMTP user ID*/
- 0xFF, /* Mail subject */
- 0xFF , /* Message */
- 0xFF, /*Sender Email Address */
- 0xFF, /* Machine name */
- 2, /* SMTP Port*/
- 1, /*Enable/Disable SMTP Authentication */
- 16, /* IPV6 server Addess */
- 1, /* Enable/disable */
- 4, /* Server IP Address */
- 0xFF, /* User Name */
- 0XFF, /* Passwd */
- 0xFF, /*Sender Email Address */
- 0xFF, /* Machine name */
- 2, /* SMTP Port*/
- 1, /*Enable/Disable SMTP Authentication */
- 16 /* IPV6 server Addess */
- };
- /* It contain Block selector length and if Block selector length is zero then set selector also must be zero*/
- const INT8U g_SMTPBlockSelectorLength[] ={
- 0, /* Enable/disable */
- 0, /* Server IP Address */
- 0, /* User Name */
- 0, /* Passwd */
- 0, /* No of destinations */
- 0, /* SMTP user ID*/
- MAX_SUB_BLOCKS, /* Mail subject */
- MAX_MSG_BLOCKS, /* Message */
- MAX_EMAIL_ADDR_BLOCKS, /* Sender Address */
- MAX_SRV_NAME_BLOCKS, /* Machine Name*/
- 0, /*SMTP Port*/
- 0, /* Enable/disable SMTP Authentication */
- 16, /* IPV6 Server Address */
- 0, /* Enable/disable */
- 0, /* Server IP Address */
- 0, /* User Name */
- 0, /* Passwd */
- MAX_EMAIL_ADDR_BLOCKS, /* Sender Address */
- MAX_SRV_NAME_BLOCKS, /* Machine Name*/
- 0, /*SMTP Port*/
- 0, /* Enable/disable SMTP Authentication */
- 16 /* IPV6 Server Address */
- };
- int GetSMTP_PrimaryServer(SMTP_STRUCT *mail, INT8U SetSelector, INT8U EthIndex, int BMCInst)
- {
- BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- Smtp_Config_T* pm_Smtp_Config = &pBMCInfo->SmtpConfig[EthIndex];
- int status = 0;
- INT8S decryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
- INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
- if(!pm_Smtp_Config->EnableDisableSMTP )
- {
- return OEM_SMTP_SERVER_DISABLED;
- }
- memset(mail, 0, sizeof(SMTP_STRUCT));
- mail->AuthEnable = pm_Smtp_Config->EnableDisableSmtpAuth;
-
- if(!mail->AuthEnable)
- {
- strcpy((char *)mail->username,"Administrator");
- }
- else
- {
- strcpy((char *)mail->username,(char *)pm_Smtp_Config->UserName );
- }
- if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
- {
- /* Get Encryption Key from the MBMCInfo_t structure */
- LOCK_BMC_SHARED_MEM(BMCInst);
- memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
- UNLOCK_BMC_SHARED_MEM(BMCInst);
- if(DecryptPassword((INT8S *)pm_Smtp_Config->Passwd, MAX_SMTP_PASSWD_LEN-1, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
- {
- TCRIT("\n Error in Decrypting the Primary SMTP Password. \n");
- return -1;
- }
- strncpy((char *)mail->password, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN);
- mail->password[MAX_SMTP_PASSWD_LEN - 1] = '\0';
- }
- else
- {
- strcpy((char *)mail->password, (char *)pm_Smtp_Config->Passwd);
- }
- strcpy((char *)mail->from_addr,(char *)pm_Smtp_Config->SenderAddr);
-
- /* check whether IPv4 Address present */
- if( memcmp( &(pm_Smtp_Config->ServerAddr[0]), &status , IP_ADDR_LEN) !=0 )
- {
- if ( inet_ntop( AF_INET, (char*)pm_Smtp_Config->ServerAddr, (char*) mail->smtp_server, 46) == NULL )
- {
- printf("Error converting smtp server address to presentation format");
- }
- }
- else
- {
- if ( inet_ntop( AF_INET6, (char*)pm_Smtp_Config->IP6_ServerAddr, (char*) mail->smtp_server, 46) == NULL )
- {
- printf("Error converting smtp server address to presentation format");
- }
- }
-
- strcpy((char *)mail->subject, (char *)pm_Smtp_Config->Subject[SetSelector]);
- strcpy((char *)mail->message_body, (char *)pm_Smtp_Config->Msg[SetSelector]);
- mail->UserID = pm_Smtp_Config->UserID[SetSelector];
- strcpy((char *)mail->local_host,(char *)pm_Smtp_Config->Servername);
- mail->retryinterval = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].AlertAckTimeout;
- mail->smtp_retries = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].Retries;
- mail->smtp_portno = pm_Smtp_Config->SmtpPort;
- mail->resptimeout = 30;
- return 0;
-
- }
- int GetSMTP_SecondaryServer(SMTP_STRUCT *mail, INT8U SetSelector, INT8U EthIndex, int BMCInst)
- {
- int status = 0;
- BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- Smtp_Config_T* pm_Smtp_Config = &pBMCInfo->SmtpConfig[EthIndex];
- INT8S decryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
- INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
- if(!pm_Smtp_Config->EnableDisableSMTP2 )
- {
- return OEM_SMTP_SERVER_DISABLED;
- }
- memset(mail, 0, sizeof(SMTP_STRUCT));
- mail->AuthEnable = pm_Smtp_Config->EnableDisableSmtp2Auth;
-
- if(!mail->AuthEnable)
- {
- strcpy((char *)mail->username,"Administrator");
- }
- else
- {
- strcpy((char *)mail->username,(char *)pm_Smtp_Config->UserName2 );
- }
- if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
- {
- /* Get Encryption Key from the MBMCInfo_t structure */
- LOCK_BMC_SHARED_MEM(BMCInst);
- memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
- UNLOCK_BMC_SHARED_MEM(BMCInst);
- if(DecryptPassword((INT8S *)pm_Smtp_Config->Passwd2, MAX_SMTP_PASSWD_LEN, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN, pwdEncKey))
- {
- TCRIT("Error in Decrypting the Secondary SMTP Password. \n");
- return -1;
- }
- strncpy((char *)mail->password, decryptedSMTPPswd, MAX_SMTP_PASSWD_LEN);
- mail->password[MAX_SMTP_PASSWD_LEN - 1] = '\0';
- }
- else
- {
- strcpy((char *)mail->password, (char *)pm_Smtp_Config->Passwd2);
- }
- strcpy((char *)mail->from_addr,(char *)pm_Smtp_Config->Sender2Addr);
-
- /* check whether IPv4 Address present */
- if( memcmp( &(pm_Smtp_Config->Server2Addr[0]), &status , IP_ADDR_LEN) !=0 )
- {
- if ( inet_ntop( AF_INET, (char*)pm_Smtp_Config->Server2Addr, (char*) mail->smtp_server, 46) == NULL )
- {
- printf("Error converting smtp server address to presentation format");
- }
- }
- else if(strlen((char *)pm_Smtp_Config->IP6_Server2Addr) != 0)
- {
- if ( inet_ntop( AF_INET6, (char*)pm_Smtp_Config->IP6_Server2Addr, (char*) mail->smtp_server, 46) == NULL )
- {
- printf("Error converting smtp server address to presentation format");
- }
- }
-
- strcpy((char *)mail->subject, (char *)pm_Smtp_Config->Subject[SetSelector]);
- strcpy((char *)mail->message_body, (char *)pm_Smtp_Config->Msg[SetSelector]);
- mail->UserID = pm_Smtp_Config->UserID[SetSelector];
- strcpy((char *)mail->local_host,(char *)pm_Smtp_Config->Server2name);
- mail->retryinterval = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].AlertAckTimeout;
- mail->smtp_retries = pBMCInfo->LANCfs[EthIndex].DestType[SetSelector - 1].Retries;
- mail->smtp_portno = pm_Smtp_Config->Smtp2Port;
- mail->resptimeout = 30;
- return 0;
- }
- int
- SetSMTPConfigParams (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
- {
- SetSMTPConfigReq_T* pSetSMTPReq = ( SetSMTPConfigReq_T* ) pReq;
- SetSMTPConfigRes_T* pSetSMTPRes = ( SetSMTPConfigRes_T* ) pRes;
- BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- Smtp_Config_T* pm_Smtp_Config;
- INT8S encryptedSMTPPswd[MAX_SMTP_PASSWD_LEN] = {0};
- INT8U pwdEncKey[MAX_SIZE_KEY] = {0};
- int retValue;
- if(0xff ==GetEthIndex(pSetSMTPReq->Channel, BMCInst) || ( pSetSMTPReq->SetSelector > MAX_EMAIL_DESTINATIONS ))
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- else
- {
- pm_Smtp_Config = &pBMCInfo->SmtpConfig[GetEthIndex(pSetSMTPReq->Channel, BMCInst)];
- }
- ReqLen -= 4;
- /* Check the Parameter Selector length */
- if ( 0xFF != g_SMTPConfigParameterLength [pSetSMTPReq->ParameterSelect] )
- {
- if (ReqLen != g_SMTPConfigParameterLength [pSetSMTPReq->ParameterSelect])
- {
- pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- }
- /* Check the Block Selector Value */
- if(pSetSMTPReq->BlockSelector != 0 )
- {
- if(g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] <= pSetSMTPReq->BlockSelector )
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- }else
- {
- /* If g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] =0 means It doesnot need set selector also except for Paramter 5(OEM_PARAM_SMTP_USERID)*/
- /*UserId requires Set selector*/
- if((g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] == 0) && (pSetSMTPReq->ParameterSelect != OEM_PARAM_SMTP_USERID) )
- {
- if(pSetSMTPReq->SetSelector !=0)
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- }
- }
- if( pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_USERID ||
- pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_MSG ||
- pSetSMTPReq->ParameterSelect == OEM_PARAM_SMTP_SUBJECT)
- {
- /*UserID, Message and Subject is allowed to configure only if DestType is LAN_OEM1_ALERT(EMAIL) SMTP alerts types)*/
- if(pBMCInfo->LANCfs[GetEthIndex(pSetSMTPReq->Channel, BMCInst)].DestType [pSetSMTPReq->SetSelector - 1].DestType != LAN_OEM1_ALERT)
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- }
- if (g_PDKHandle[PDK_BEFORESETSMTPCFG] != NULL )
- {
- retValue = ((int(*)(INT8U *, INT8U, INT8U *,int))(g_PDKHandle[PDK_BEFORESETSMTPCFG]))(pReq, ReqLen, pRes, BMCInst);
- if(retValue != 0)
- {
- return retValue;
- }
- }
- switch (pSetSMTPReq->ParameterSelect)
- {
- case OEM_ENABLE_DISABLE_SMTP:
- if (0 != ( pSetSMTPReq-> ConfigData.EnableDisableSMTP & ENABLE_DISABLE_MASK ) )
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- pm_Smtp_Config->EnableDisableSMTP = pSetSMTPReq->ConfigData.EnableDisableSMTP & 0x01;
- break;
- case OEM_PARAM_SMTP_SERVR_ADDR :
- if(ReqLen == IP_ADDR_LEN) /* check for 4 bytes of server address length */
- {
- memset(&(pm_Smtp_Config->ServerAddr),0,IP_ADDR_LEN);
- memcpy ( &(pm_Smtp_Config->ServerAddr),pSetSMTPReq->ConfigData.ServerAddr ,IP_ADDR_LEN);
- memset( &(pm_Smtp_Config->IP6_ServerAddr) , 0 , IP6_ADDR_LEN);
- }
- else
- {
- pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- break;
- case OEM_PARAM_SMTP_USER_NAME:
- if (ReqLen > MAX_SMTP_USERNAME_LEN-1)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset ( &(pm_Smtp_Config->UserName),0,MAX_SMTP_USERNAME_LEN-1 );
- memcpy ( &(pm_Smtp_Config->UserName),pSetSMTPReq->ConfigData.UserName, ReqLen);
- break;
- case OEM_PARAM_SMTP_PASSWD :
- if (ReqLen > MAX_SMTP_PASSWD_LEN -1)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset ( &(pm_Smtp_Config->Passwd),0, MAX_SMTP_PASSWD_LEN-1 );
- if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
- {
- /* Get Encryption Key from the MBMCInfo_t structure */
- LOCK_BMC_SHARED_MEM(BMCInst);
- memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
- UNLOCK_BMC_SHARED_MEM(BMCInst);
- if(EncryptPassword((INT8S *)pSetSMTPReq->ConfigData.Passwd, MAX_SMTP_PASSWD_LEN-1, encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
- {
- TCRIT("Error in encrypting the Primary SMTP password.\n");
- pSetSMTPRes->CompletionCode = CC_UNSPECIFIED_ERR;
- return sizeof(INT8U);
- }
- memcpy(&(pm_Smtp_Config->Passwd), encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1);
- }
- else
- {
- memcpy(&(pm_Smtp_Config->Passwd), pSetSMTPReq->ConfigData.Passwd, ReqLen);
- }
- break;
- case OEM_PARAM_SMTP_NO_OF_DESTINATIONS:
- pSetSMTPRes->CompletionCode = CC_ATTEMPT_TO_SET_RO_PARAM;
- return sizeof (INT8U);
- break;
- case OEM_PARAM_SMTP_USERID :
- pm_Smtp_Config->UserID[pSetSMTPReq->SetSelector]=pSetSMTPReq->ConfigData.UserID;
- break;
- case OEM_PARAM_SMTP_MSG:
- if (ReqLen > MAX_MSG_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset( &(pm_Smtp_Config->Msg[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),0,MAX_MSG_BLOCK_SIZE);
- memcpy ( &(pm_Smtp_Config->Msg[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),&(pSetSMTPReq->ConfigData.Msg),ReqLen );
- break;
- case OEM_PARAM_SMTP_SUBJECT:
- if (ReqLen > MAX_MSG_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset(&(pm_Smtp_Config->Subject[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_SUB_BLOCK_SIZE]),0,MAX_SUB_BLOCK_SIZE);
- memcpy (&(pm_Smtp_Config->Subject[pSetSMTPReq->SetSelector][pSetSMTPReq->BlockSelector*MAX_SUB_BLOCK_SIZE]),&(pSetSMTPReq->ConfigData.Subject ),ReqLen );
- break;
- case OEM_PARAM_SMTP_SENDER_ADDR:
- if (ReqLen > MAX_EMAIL_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset(&(pm_Smtp_Config->SenderAddr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),0 ,MAX_EMAIL_BLOCK_SIZE);
- memcpy ( &(pm_Smtp_Config->SenderAddr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),pSetSMTPReq->ConfigData.SenderAddr ,ReqLen);
- break;
-
- case OEM_PARAM_SMTP_HOST_NAME:
- if (ReqLen > MAX_SRV_NAME_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset ( &(pm_Smtp_Config->Servername[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),0 ,MAX_SRV_NAME_BLOCK_SIZE);
- memcpy ( &(pm_Smtp_Config->Servername[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Servername ,ReqLen);
- break;
- case OEM_PARAM_SMTP_PORT :
- pm_Smtp_Config->SmtpPort= htoipmi_u16(pSetSMTPReq->ConfigData.SmtpPort);
- break;
- case OEM_ENABLE_DISABLE_SMTP_AUTH :
- pm_Smtp_Config->EnableDisableSmtpAuth = pSetSMTPReq->ConfigData.EnableDisableSmtpAuth;
- break;
- case OEM_PARAM_SMTP_IPV6_SERVR_ADDR :
- if( ReqLen == IP6_ADDR_LEN ) /* check for total 16 bytes of IPV6 address length */
- {
- /*Validate the IPv6 address*/
- if(IsValidGlobalIPv6Addr((struct in6_addr*)&pSetSMTPReq->ConfigData.IP6_ServerAddr))
- {
- TCRIT("Invalid Global IPv6 Address\n");
- *pRes = CC_INV_DATA_FIELD;
- return sizeof(INT8U);
- }
- memcpy ( &(pm_Smtp_Config->IP6_ServerAddr),pSetSMTPReq->ConfigData.IP6_ServerAddr ,IP6_ADDR_LEN);
- memset( &(pm_Smtp_Config->ServerAddr) , 0 , IP_ADDR_LEN);
- }
- else /* Invalid Request in length */
- {
- pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- break;
- case OEM_ENABLE_DISABLE_SMTP2 :
- if (0 != ( pSetSMTPReq-> ConfigData.EnableDisableSMTP2 & ENABLE_DISABLE_MASK ) )
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- pm_Smtp_Config->EnableDisableSMTP2 = pSetSMTPReq->ConfigData.EnableDisableSMTP2 & 0x01;
- break;
- case OEM_PARAM_SMTP_2_SERVR_ADDR :
- if(ReqLen == IP_ADDR_LEN) /* check for 4 bytes of server address length */
- {
- memset(&(pm_Smtp_Config->Server2Addr),0,IP_ADDR_LEN);
- memcpy (&(pm_Smtp_Config->Server2Addr),pSetSMTPReq->ConfigData.Server2Addr ,IP_ADDR_LEN);
- memset( &(pm_Smtp_Config->IP6_Server2Addr) , 0 , IP6_ADDR_LEN);
- }
- else
- {
- pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- break;
- case OEM_PARAM_SMTP_2_USER_NAME :
- if (ReqLen > MAX_SMTP_USERNAME_LEN-1)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset ( &(pm_Smtp_Config->UserName2),0,MAX_SMTP_USERNAME_LEN-1 );
- memcpy (&(pm_Smtp_Config->UserName2),pSetSMTPReq->ConfigData.UserName2, ReqLen);
- break;
- case OEM_PARAM_SMTP_2_PASSWD :
- if (ReqLen > MAX_SMTP_PASSWD_LEN -1)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset ( &(pm_Smtp_Config->Passwd2),0, MAX_SMTP_PASSWD_LEN-1 );
- if(IsFeatureEnabled("CONFIG_SPX_FEATURE_ENABLE_USERPSWD_ENCRYPTION"))
- {
- /* Get Encryption Key from the MBMCInfo_t structure */
- LOCK_BMC_SHARED_MEM(BMCInst);
- memcpy(pwdEncKey, &(g_MBMCInfo.PwdEncKey), MAX_SIZE_KEY);
- UNLOCK_BMC_SHARED_MEM(BMCInst);
- if(EncryptPassword((INT8S *)pSetSMTPReq->ConfigData.Passwd2, MAX_SMTP_PASSWD_LEN-1, encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1, pwdEncKey))
- {
- TCRIT("Error in encrypting the Secondary SMTP password.\n");
- pSetSMTPRes->CompletionCode = CC_UNSPECIFIED_ERR;
- return sizeof(INT8U);
- }
- memcpy(&(pm_Smtp_Config->Passwd2), encryptedSMTPPswd, MAX_SMTP_PASSWD_LEN-1);
- }
- else
- {
- memcpy ( &(pm_Smtp_Config->Passwd2),pSetSMTPReq->ConfigData.Passwd2, ReqLen );
- }
- break;
- case OEM_PARAM_SMTP_2_SENDER_ADDR :
- if (ReqLen > MAX_EMAIL_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset(&(pm_Smtp_Config->Sender2Addr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),0 ,MAX_EMAIL_BLOCK_SIZE);
- memcpy (&(pm_Smtp_Config->Sender2Addr[pSetSMTPReq->BlockSelector*MAX_EMAIL_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Sender2Addr ,ReqLen);
- break;
- case OEM_PARAM_SMTP_2_HOST_NAME :
- if (ReqLen > MAX_SRV_NAME_BLOCK_SIZE)
- {
- *pRes = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- memset (&(pm_Smtp_Config->Server2name[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),0 ,MAX_SRV_NAME_BLOCK_SIZE);
- memcpy (&(pm_Smtp_Config->Server2name[pSetSMTPReq->BlockSelector*MAX_SRV_NAME_BLOCK_SIZE]),pSetSMTPReq->ConfigData.Server2name ,ReqLen);
- break;
- case OEM_PARAM_SMTP_2_PORT :
- pm_Smtp_Config->Smtp2Port= htoipmi_u16(pSetSMTPReq->ConfigData.Smtp2Port);
- break;
- case OEM_ENABLE_DISABLE_SMTP_2_AUTH :
- pm_Smtp_Config->EnableDisableSmtp2Auth = pSetSMTPReq->ConfigData.EnableDisableSmtp2Auth;
- break;
- case OEM_PARAM_SMTP_2_IPV6_SERVR_ADDR :
- if( ReqLen == IP6_ADDR_LEN ) /* check for total 16 bytes of IPV6 address length */
- {
- /*Validate the IPv6 address*/
- if(IsValidGlobalIPv6Addr((struct in6_addr*)&pSetSMTPReq->ConfigData.IP6_Server2Addr))
- {
- TCRIT("Invalid Global IPv6 Address\n");
- *pRes = CC_INV_DATA_FIELD;
- return sizeof(INT8U);
- }
- memcpy ( &(pm_Smtp_Config->IP6_Server2Addr),pSetSMTPReq->ConfigData.IP6_Server2Addr ,IP6_ADDR_LEN);
- memset( &(pm_Smtp_Config->Server2Addr) , 0 , IP_ADDR_LEN);
- }
- else /* Invalid Request in length */
- {
- pSetSMTPRes->CompletionCode = CC_REQ_INV_LEN;
- return sizeof (INT8U);
- }
- break;
- default:
- pSetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- pSetSMTPRes->CompletionCode = CC_NORMAL ;
- FlushIPMI((INT8U*)&pBMCInfo->SmtpConfig[0],(INT8U*)&pBMCInfo->SmtpConfig[GetEthIndex(pSetSMTPReq->Channel, BMCInst)],
- pBMCInfo->IPMIConfLoc.SmtpConfigAddr,sizeof(Smtp_Config_T),BMCInst);
- return sizeof (INT8U);
- }
- int
- GetSMTPConfigParams (_NEAR_ INT8U* pReq, INT32U ReqLen, _NEAR_ INT8U* pRes, int BMCInst)
- {
- INT8U ResLen = 0;
- GetSMTPConfigReq_T* pGetSMTPReq = ( GetSMTPConfigReq_T* ) pReq;
- GetSMTPConfigRes_T* pGetSMTPRes = ( GetSMTPConfigRes_T* ) pRes;
- BMCInfo_t *pBMCInfo = &g_BMCInfo[BMCInst];
- Smtp_Config_T* pm_Smtp_Config;
- if(0xff ==GetEthIndex(pGetSMTPReq->Channel, BMCInst) || (pGetSMTPReq->SetSelector > MAX_EMAIL_DESTINATIONS))
- {
- pGetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }else
- {
- pm_Smtp_Config = &pBMCInfo->SmtpConfig[GetEthIndex(pGetSMTPReq->Channel, BMCInst)];
- }
- /* Check the Block Selector Value */
- if(pGetSMTPReq->BlockSelector != 0 )
- {
- if(g_SMTPBlockSelectorLength[pGetSMTPReq->ParameterSelect] <= pGetSMTPReq->BlockSelector )
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- }else
- {
- /* If g_SMTPBlockSelectorLength[pSetSMTPReq->ParameterSelect] =0 means It doesnot need set selector also except for Paramter 5(OEM_PARAM_SMTP_USERID)*/
- /*UserId requires Set selector*/
- if((g_SMTPBlockSelectorLength[pGetSMTPReq->ParameterSelect] == 0) && (pGetSMTPReq->ParameterSelect != OEM_PARAM_SMTP_USERID) )
- {
- if(pGetSMTPReq->SetSelector !=0)
- {
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- }
- }
- switch (pGetSMTPReq->ParameterSelect)
- {
- case OEM_ENABLE_DISABLE_SMTP:
- pGetSMTPRes->ConfigData.EnableDisableSMTP = pm_Smtp_Config->EnableDisableSMTP;
- ResLen = 1;
- break;
- case OEM_PARAM_SMTP_SERVR_ADDR :
- memcpy ( pGetSMTPRes->ConfigData.ServerAddr ,&(pm_Smtp_Config->ServerAddr),IP_ADDR_LEN);
- ResLen = IP_ADDR_LEN;
- break;
- case OEM_PARAM_SMTP_USER_NAME:
- memcpy ( pGetSMTPRes->ConfigData.UserName , &(pm_Smtp_Config->UserName),MAX_SMTP_USERNAME_LEN-1);
- ResLen = MAX_SMTP_USERNAME_LEN-1;
- break;
- case OEM_PARAM_SMTP_PASSWD :
- /* It Write only Parameter */
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- case OEM_PARAM_SMTP_NO_OF_DESTINATIONS:
- pGetSMTPRes->ConfigData.NoofDestinations = MAX_EMAIL_DESTINATIONS;
- ResLen = sizeof (INT8U);
- break;
- case OEM_PARAM_SMTP_USERID:
- pGetSMTPRes->ConfigData.UserID=pm_Smtp_Config->UserID[pGetSMTPReq->SetSelector];
- ResLen = sizeof (INT8U);
- break;
- case OEM_PARAM_SMTP_MSG:
- memcpy(&(pGetSMTPRes->ConfigData.Msg) ,&(pm_Smtp_Config->Msg[pGetSMTPReq->SetSelector][pGetSMTPReq->BlockSelector*MAX_MSG_BLOCK_SIZE]),MAX_MSG_BLOCK_SIZE );
- ResLen = MAX_MSG_BLOCK_SIZE;
- break;
- case OEM_PARAM_SMTP_SUBJECT:
- memcpy ( &(pGetSMTPRes->ConfigData.Subject), &( pm_Smtp_Config->Subject[pGetSMTPReq->SetSelector][pGetSMTPReq->BlockSelector * MAX_SUB_BLOCK_SIZE]),MAX_SUB_BLOCK_SIZE);
- ResLen = MAX_SUB_BLOCK_SIZE;
- break;
- case OEM_PARAM_SMTP_SENDER_ADDR:
- memcpy ( &(pGetSMTPRes->ConfigData.SenderAddr), &( pm_Smtp_Config->SenderAddr[pGetSMTPReq->BlockSelector *MAX_EMAIL_BLOCK_SIZE]),MAX_EMAIL_BLOCK_SIZE);
- ResLen = MAX_EMAIL_BLOCK_SIZE ;
- break;
- case OEM_PARAM_SMTP_HOST_NAME:
- memcpy ( &(pGetSMTPRes->ConfigData.Servername), &( pm_Smtp_Config->Servername[pGetSMTPReq->BlockSelector *MAX_SRV_NAME_BLOCK_SIZE]),MAX_SRV_NAME_BLOCK_SIZE);
- ResLen = MAX_SRV_NAME_BLOCK_SIZE;
- break;
- case OEM_PARAM_SMTP_PORT:
- pGetSMTPRes->ConfigData.SmtpPort = pm_Smtp_Config->SmtpPort;
- ResLen = sizeof(INT16U);
- break;
- case OEM_ENABLE_DISABLE_SMTP_AUTH:
- pGetSMTPRes->ConfigData.EnableDisableSmtpAuth = pm_Smtp_Config->EnableDisableSmtpAuth;
- ResLen = 1;
- break;
- case OEM_PARAM_SMTP_IPV6_SERVR_ADDR :
- memcpy ( pGetSMTPRes->ConfigData.IP6_ServerAddr , &(pm_Smtp_Config->IP6_ServerAddr), IP6_ADDR_LEN);
- ResLen =IP6_ADDR_LEN;
- break;
- case OEM_ENABLE_DISABLE_SMTP2 :
- pGetSMTPRes->ConfigData.EnableDisableSMTP2 = pm_Smtp_Config->EnableDisableSMTP2;
- ResLen = 1;
- break;
- case OEM_PARAM_SMTP_2_SERVR_ADDR :
- memcpy ( pGetSMTPRes->ConfigData.Server2Addr ,&(pm_Smtp_Config->Server2Addr),IP_ADDR_LEN);
- ResLen = IP_ADDR_LEN;
- break;
- case OEM_PARAM_SMTP_2_USER_NAME :
- memcpy ( pGetSMTPRes->ConfigData.UserName2 , &(pm_Smtp_Config->UserName2),MAX_SMTP_USERNAME_LEN-1 );
- ResLen = MAX_SMTP_USERNAME_LEN-1;
- break;
- case OEM_PARAM_SMTP_2_PASSWD :
- /* It Write only Parameter */
- *pRes = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- case OEM_PARAM_SMTP_2_SENDER_ADDR :
- memcpy ( &(pGetSMTPRes->ConfigData.Sender2Addr), &(pm_Smtp_Config->Sender2Addr[pGetSMTPReq->BlockSelector *MAX_EMAIL_BLOCK_SIZE]),MAX_EMAIL_BLOCK_SIZE);
- ResLen = MAX_EMAIL_BLOCK_SIZE ;
- break;
- case OEM_PARAM_SMTP_2_HOST_NAME :
- memcpy ( &(pGetSMTPRes->ConfigData.Server2name), &(pm_Smtp_Config->Server2name[pGetSMTPReq->BlockSelector *MAX_SRV_NAME_BLOCK_SIZE]),MAX_SRV_NAME_BLOCK_SIZE);
- ResLen = MAX_SRV_NAME_BLOCK_SIZE;
- break;
- case OEM_PARAM_SMTP_2_PORT :
- pGetSMTPRes->ConfigData.Smtp2Port = pm_Smtp_Config->Smtp2Port;
- ResLen = sizeof(INT16U);
- break;
- case OEM_ENABLE_DISABLE_SMTP_2_AUTH :
- pGetSMTPRes->ConfigData.EnableDisableSmtp2Auth = pm_Smtp_Config->EnableDisableSmtp2Auth;
- ResLen = 1;
- break;
- case OEM_PARAM_SMTP_2_IPV6_SERVR_ADDR :
- memcpy ( pGetSMTPRes->ConfigData.IP6_Server2Addr , &(pm_Smtp_Config->IP6_Server2Addr), IP6_ADDR_LEN);
- ResLen =IP6_ADDR_LEN;
- break;
- default:
- pGetSMTPRes->CompletionCode = CC_INV_DATA_FIELD;
- return sizeof (INT8U);
- }
- pGetSMTPRes->CompletionCode = 0 ;
- ResLen++; // byte for Completion Code
- return ResLen;
- }
|