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_DirWriteAuth(struct tcsd_thread_data *data)
32{
33	TSS_RESULT result;
34	TSS_HCONTEXT hContext;
35	TCPA_DIRINDEX dirIndex;
36	TCPA_DIGEST dirDigest;
37	TPM_AUTH auth;
38
39	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
40		return TCSERR(TSS_E_INTERNAL_ERROR);
41
42	if ((result = ctx_verify_context(hContext)))
43		goto done;
44
45	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
46
47	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &data->comm))
48		return TCSERR(TSS_E_INTERNAL_ERROR);
49	if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &dirDigest, 0, &data->comm))
50		return TCSERR(TSS_E_INTERNAL_ERROR);
51	if (getData(TCSD_PACKET_TYPE_AUTH, 3, &auth, 0, &data->comm))
52		return TCSERR(TSS_E_INTERNAL_ERROR);
53
54	MUTEX_LOCK(tcsp_lock);
55
56	result = TCSP_DirWriteAuth_Internal(hContext, dirIndex, dirDigest, &auth);
57
58	MUTEX_UNLOCK(tcsp_lock);
59
60	if (result == TSS_SUCCESS) {
61		initData(&data->comm, 1);
62		if (setData(TCSD_PACKET_TYPE_AUTH, 0, &auth, 0, &data->comm)) {
63			return TCSERR(TSS_E_INTERNAL_ERROR);
64		}
65	} else
66done:		initData(&data->comm, 0);
67
68	data->comm.hdr.u.result = result;
69
70	return TSS_SUCCESS;
71}
72
73TSS_RESULT
74tcs_wrap_DirRead(struct tcsd_thread_data *data)
75{
76	TSS_RESULT result;
77	TSS_HCONTEXT hContext;
78	TCPA_DIRINDEX dirIndex;
79	TCPA_DIRVALUE dirValue;
80
81	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
82		return TCSERR(TSS_E_INTERNAL_ERROR);
83
84	if ((result = ctx_verify_context(hContext)))
85		goto done;
86
87	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);
88
89	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &dirIndex, 0, &data->comm))
90		return TCSERR(TSS_E_INTERNAL_ERROR);
91
92	MUTEX_LOCK(tcsp_lock);
93
94	result = TCSP_DirRead_Internal(hContext, dirIndex, &dirValue);
95
96	MUTEX_UNLOCK(tcsp_lock);
97
98	if (result == TSS_SUCCESS) {
99		initData(&data->comm, 1);
100		if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &dirValue, 0, &data->comm)) {
101			return TCSERR(TSS_E_INTERNAL_ERROR);
102		}
103	} else
104done:		initData(&data->comm, 0);
105
106	data->comm.hdr.u.result = result;
107
108	return TSS_SUCCESS;
109}
110