modify ipcbuffer to remove memory leak
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertServiceProxy.cpp
old mode 100644 (file)
new mode 100755 (executable)
index ebb3570..56f5ca1
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -175,7 +174,7 @@ _CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer,
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
 
-       Tizen::Io::_IpcBuffer certBufferIpc;
+       Tizen::Base::ByteBuffer certBufferIpc;
 
        ClearLastResult();
 
@@ -184,9 +183,6 @@ _CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer,
        SysTryReturnResult(NID_SEC_CERT, certType > _CERT_TYPE_NOT_BOUNDED, E_INVALID_ARG, "Invalid certificate type.");
        SysTryReturnResult(NID_SEC_CERT, certType < _CERT_TYPE_MAX, E_INVALID_ARG, "Invalid certificate type.");
 
-       certBufferIpc.pBuffer = null;
-       certBufferIpc.size = 0;
-
        std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_GetNextCertificate(certType, curPos, bufferLen, &certBufferIpc, &curPos, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
@@ -194,8 +190,8 @@ _CertServiceProxy::GetNextCertificate(int certType, int& curPos, byte* pBuffer,
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to send message.", GetErrorMessage(r));
        SysTryReturn(NID_SEC_CERT, !IsFailed(ret), ret, ret, "[%s] Stub function failed on service side.", GetErrorMessage(ret));
 
-       memcpy(pBuffer, certBufferIpc.pBuffer, certBufferIpc.size);
-       bufferLen = certBufferIpc.size;
+       memcpy(pBuffer, certBufferIpc.GetPointer(), certBufferIpc.GetRemaining());
+       bufferLen = certBufferIpc.GetRemaining();
 
        return r;
 }
@@ -406,7 +402,7 @@ _CertServiceProxy::InsertCertificateChainWithPrivateKey(char* pCertchainPrivateK
 }
 
 result
-_CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword)
+_CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12ImportPassword, bool checkPrivilege)
 {
        result r = E_SUCCESS;
        result ret = E_SUCCESS;
@@ -422,7 +418,7 @@ _CertServiceProxy::InsertPkcs12Content(char* pPkcs12FilePath, char* pPkcs12Impor
        pkcs12PasswdBufferIpc.pBuffer = pPkcs12ImportPassword;
        pkcs12PasswdBufferIpc.size = strlen(reinterpret_cast< char* >(pPkcs12ImportPassword)) + 1;
 
-       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, &ret));
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_InstallPkcs12Content(pkcs12FileBufferIpc, pkcs12PasswdBufferIpc, checkPrivilege, &ret));
        SysTryReturnResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
        r = __pIpcClient->SendRequest(pMessage.get());
@@ -549,4 +545,21 @@ _CertServiceProxy::GetUserCertFieldInfoByCertId(int certId, _CertFieldInfos* pCe
 
        return r;
 }
+
+void
+_CertServiceProxy::RestoreRootCaIntegrity(void)
+{
+       result r = E_SUCCESS;
+
+       ClearLastResult();
+
+       SysTryReturnVoidResult(NID_SEC_CERT, __pIpcClient != null, E_SYSTEM, "[%s] IPC instance is not constructed.", GetErrorMessage(E_SYSTEM));
+
+       std::unique_ptr< IPC::Message > pMessage(new (std::nothrow) CertServer_RestoreRootCaIntegrity());
+       SysTryReturnVoidResult(NID_SEC_CERT, pMessage != null, E_OUT_OF_MEMORY, "[%s] Failed to allocate memory.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = __pIpcClient->SendRequest(pMessage.get());
+       SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to send message.", GetErrorMessage(r));
+}
+
 } } }