~ubuntu-branches/ubuntu/hardy/trousers/hardy-proposed

« back to all changes in this revision

Viewing changes to src/tcs/rpc/tcstp/rpc_caps_tpm.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-01-23 22:03:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123220300-fhtqja3c0oq0gp6z
Tags: 0.3.1-4
* Added patch from Aaron M. Ucko <ucko@debian.org> to allow trousers to
  build successfully on amd64, and presumably also other 64-bit
  architectures (Closes: #457400).
* Including udev rule for /dev/tpm from William Lima
  <wlima.amadeus@gmail.com> as suggested by David Smith <dds@google.com>
  (Closes: #459682).
* Added lintian overrides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
30
TSS_RESULT
 
31
tcs_wrap_GetCapability(struct tcsd_thread_data *data)
 
32
{
 
33
        TCS_CONTEXT_HANDLE hContext;
 
34
        TCPA_CAPABILITY_AREA capArea;
 
35
        UINT32 subCapSize;
 
36
        BYTE *subCap;
 
37
        UINT32 respSize;
 
38
        BYTE *resp;
 
39
        TSS_RESULT result;
 
40
 
 
41
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
42
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
43
 
 
44
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
45
 
 
46
        if (getData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &data->comm))
 
47
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
48
        if (getData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &data->comm))
 
49
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
50
 
 
51
        if (subCapSize == 0)
 
52
                subCap = NULL;
 
53
        else {
 
54
                subCap = calloc(1, subCapSize);
 
55
                if (subCap == NULL) {
 
56
                        LogError("malloc of %u bytes failed.", subCapSize);
 
57
                        return TCSERR(TSS_E_OUTOFMEMORY);
 
58
                }
 
59
                if (getData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &data->comm)) {
 
60
                        free(subCap);
 
61
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
62
                }
 
63
        }
 
64
 
 
65
        MUTEX_LOCK(tcsp_lock);
 
66
 
 
67
        result = TCSP_GetCapability_Internal(hContext, capArea, subCapSize, subCap, &respSize,
 
68
                                             &resp);
 
69
 
 
70
        MUTEX_UNLOCK(tcsp_lock);
 
71
        free(subCap);
 
72
 
 
73
        if (result == TSS_SUCCESS) {
 
74
                initData(&data->comm, 2);
 
75
                if (setData(TCSD_PACKET_TYPE_UINT32, 0, &respSize, 0, &data->comm)) {
 
76
                        free(resp);
 
77
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
78
                }
 
79
                if (setData(TCSD_PACKET_TYPE_PBYTE, 1, resp, respSize, &data->comm)) {
 
80
                        free(resp);
 
81
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
82
                }
 
83
                free(resp);
 
84
        } else
 
85
                initData(&data->comm, 0);
 
86
 
 
87
        data->comm.hdr.u.result = result;
 
88
        return TSS_SUCCESS;
 
89
}
 
90
 
 
91
TSS_RESULT
 
92
tcs_wrap_GetCapabilityOwner(struct tcsd_thread_data *data)
 
93
{
 
94
        TCS_CONTEXT_HANDLE hContext;
 
95
        TPM_AUTH ownerAuth;
 
96
        TCPA_VERSION version;
 
97
        UINT32 nonVol;
 
98
        UINT32 vol;
 
99
        TSS_RESULT result;
 
100
 
 
101
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
102
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
103
 
 
104
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
105
 
 
106
        if (getData(TCSD_PACKET_TYPE_AUTH, 1, &ownerAuth, 0, &data->comm))
 
107
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
108
 
 
109
        MUTEX_LOCK(tcsp_lock);
 
110
 
 
111
        result = TCSP_GetCapabilityOwner_Internal(hContext, &ownerAuth, &version, &nonVol, &vol);
 
112
 
 
113
        MUTEX_UNLOCK(tcsp_lock);
 
114
 
 
115
        if (result == TSS_SUCCESS) {
 
116
                initData(&data->comm, 4);
 
117
                if (setData(TCSD_PACKET_TYPE_VERSION, 0, &version, 0, &data->comm)) {
 
118
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
119
                }
 
120
                if (setData(TCSD_PACKET_TYPE_UINT32, 1, &nonVol, 0, &data->comm)) {
 
121
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
122
                }
 
123
                if (setData(TCSD_PACKET_TYPE_UINT32, 2, &vol, 0, &data->comm)) {
 
124
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
125
                }
 
126
                if (setData(TCSD_PACKET_TYPE_AUTH, 3, &ownerAuth, 0, &data->comm)) {
 
127
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
128
                }
 
129
        } else
 
130
                initData(&data->comm, 0);
 
131
 
 
132
        data->comm.hdr.u.result = result;
 
133
        return TSS_SUCCESS;
 
134
}
 
135
 
 
136
TSS_RESULT
 
137
tcs_wrap_SetCapability(struct tcsd_thread_data *data)
 
138
{
 
139
        TCS_CONTEXT_HANDLE hContext;
 
140
        TCPA_CAPABILITY_AREA capArea;
 
141
        UINT32 subCapSize;
 
142
        BYTE *subCap;
 
143
        UINT32 valueSize;
 
144
        BYTE *value;
 
145
        TSS_RESULT result;
 
146
        TPM_AUTH ownerAuth, *pOwnerAuth;
 
147
 
 
148
        if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
 
149
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
150
 
 
151
        LogDebugFn("thread %zd context %x", THREAD_ID, hContext);
 
152
 
 
153
        if (getData(TCSD_PACKET_TYPE_UINT32, 1, &capArea, 0, &data->comm))
 
154
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
155
        if (getData(TCSD_PACKET_TYPE_UINT32, 2, &subCapSize, 0, &data->comm))
 
156
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
157
 
 
158
        if (subCapSize == 0)
 
159
                subCap = NULL;
 
160
        else {
 
161
                subCap = calloc(1, subCapSize);
 
162
                if (subCap == NULL) {
 
163
                        LogError("malloc of %u bytes failed.", subCapSize);
 
164
                        return TCSERR(TSS_E_OUTOFMEMORY);
 
165
                }
 
166
                if (getData(TCSD_PACKET_TYPE_PBYTE, 3, subCap, subCapSize, &data->comm)) {
 
167
                        free(subCap);
 
168
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
169
                }
 
170
        }
 
171
 
 
172
        if (getData(TCSD_PACKET_TYPE_UINT32, 4, &valueSize, 0, &data->comm))
 
173
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
174
 
 
175
        if (valueSize == 0)
 
176
                value = NULL;
 
177
        else {
 
178
                value = calloc(1, valueSize);
 
179
                if (value == NULL) {
 
180
                        free(subCap);
 
181
                        LogError("malloc of %u bytes failed.", valueSize);
 
182
                        return TCSERR(TSS_E_OUTOFMEMORY);
 
183
                }
 
184
                if (getData(TCSD_PACKET_TYPE_PBYTE, 5, value, valueSize, &data->comm)) {
 
185
                        free(subCap);
 
186
                        free(value);
 
187
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
188
                }
 
189
        }
 
190
 
 
191
        if (getData(TCSD_PACKET_TYPE_AUTH, 6, &ownerAuth, 0, &data->comm))
 
192
                pOwnerAuth = NULL;
 
193
        else
 
194
                pOwnerAuth = &ownerAuth;
 
195
 
 
196
 
 
197
        MUTEX_LOCK(tcsp_lock);
 
198
 
 
199
        result = TCSP_SetCapability_Internal(hContext, capArea, subCapSize, subCap, valueSize,
 
200
                                             value, pOwnerAuth);
 
201
 
 
202
        MUTEX_UNLOCK(tcsp_lock);
 
203
        free(subCap);
 
204
        free(value);
 
205
 
 
206
        if (result == TSS_SUCCESS) {
 
207
                initData(&data->comm, 1);
 
208
                if (pOwnerAuth) {
 
209
                        if (setData(TCSD_PACKET_TYPE_AUTH, 0, pOwnerAuth, 0, &data->comm)) {
 
210
                                return TCSERR(TSS_E_INTERNAL_ERROR);
 
211
                        }
 
212
                }
 
213
        } else
 
214
                initData(&data->comm, 0);
 
215
 
 
216
        data->comm.hdr.u.result = result;
 
217
        return TSS_SUCCESS;
 
218
}