rpc_bind.c revision 1.1.1.1
1 2/* 3 * Licensed Materials - Property of IBM 4 * 5 * trousers - An open source TCG Software Stack 6 * 7 * (C) Copyright International Business Machines Corp. 2004-2006 8 * 9 */ 10 11#include <stdlib.h> 12#include <stdio.h> 13#include <syslog.h> 14#include <string.h> 15#include <netdb.h> 16 17#include "trousers/tss.h" 18#include "trousers_types.h" 19#include "tcs_tsp.h" 20#include "tcs_utils.h" 21#include "tcs_int_literals.h" 22#include "capabilities.h" 23#include "tcslog.h" 24#include "tcsd_wrap.h" 25#include "tcsd.h" 26#include "tcs_utils.h" 27#include "rpc_tcstp_tcs.h" 28 29 30TSS_RESULT 31tcs_wrap_UnBind(struct tcsd_thread_data *data) 32{ 33 TCS_CONTEXT_HANDLE hContext; 34 TCS_KEY_HANDLE keyHandle; 35 UINT32 inDataSize; 36 BYTE *inData; 37 38 TPM_AUTH privAuth; 39 TPM_AUTH *pPrivAuth; 40 41 UINT32 outDataSize; 42 BYTE *outData; 43 TSS_RESULT result; 44 45 int i; 46 47 if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm)) 48 return TCSERR(TSS_E_INTERNAL_ERROR); 49 50 LogDebugFn("thread %ld context %x", THREAD_ID, hContext); 51 52 if (getData(TCSD_PACKET_TYPE_UINT32, 1, &keyHandle, 0, &data->comm)) 53 return TCSERR(TSS_E_INTERNAL_ERROR); 54 if (getData(TCSD_PACKET_TYPE_UINT32, 2, &inDataSize, 0, &data->comm)) 55 return TCSERR(TSS_E_INTERNAL_ERROR); 56 57 inData = calloc(1, inDataSize); 58 if (inData == NULL) { 59 LogError("malloc of %u bytes failed.", inDataSize); 60 return TCSERR(TSS_E_OUTOFMEMORY); 61 } 62 if (getData(TCSD_PACKET_TYPE_PBYTE, 3, inData, inDataSize, &data->comm)) { 63 free(inData); 64 return TCSERR(TSS_E_INTERNAL_ERROR); 65 } 66 67 result = getData(TCSD_PACKET_TYPE_AUTH, 4, &privAuth, 0, &data->comm); 68 if (result == TSS_TCP_RPC_BAD_PACKET_TYPE) 69 pPrivAuth = NULL; 70 else if (result) { 71 free(inData); 72 return result; 73 } else 74 pPrivAuth = &privAuth; 75 76 MUTEX_LOCK(tcsp_lock); 77 78 result = TCSP_UnBind_Internal(hContext, keyHandle, inDataSize, inData, 79 pPrivAuth, &outDataSize, &outData); 80 81 MUTEX_UNLOCK(tcsp_lock); 82 free(inData); 83 84 if (result == TSS_SUCCESS) { 85 i = 0; 86 initData(&data->comm, 3); 87 if (pPrivAuth != NULL) { 88 if (setData(TCSD_PACKET_TYPE_AUTH, i++, pPrivAuth, 0, &data->comm)) { 89 return TCSERR(TSS_E_INTERNAL_ERROR); 90 } 91 } 92 if (setData(TCSD_PACKET_TYPE_UINT32, i++, &outDataSize, 0, &data->comm)) { 93 return TCSERR(TSS_E_INTERNAL_ERROR); 94 } 95 if (setData(TCSD_PACKET_TYPE_PBYTE, i++, outData, outDataSize, &data->comm)) { 96 return TCSERR(TSS_E_INTERNAL_ERROR); 97 } 98 free(outData); 99 } else 100 initData(&data->comm, 0); 101 102 data->comm.hdr.u.result = result; 103 104 return TSS_SUCCESS; 105} 106