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

« back to all changes in this revision

Viewing changes to src/tspi/rpc/tcstp/rpc.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 <unistd.h>
 
12
#include <errno.h>
 
13
#include <string.h>
 
14
#include <sys/socket.h>
 
15
#include <sys/types.h>
 
16
#include <netinet/in.h>
 
17
#include <arpa/inet.h>
 
18
#include <netdb.h>
 
19
#include <stdlib.h>
 
20
#include <stdio.h>
 
21
#include <assert.h>
 
22
#include <limits.h>
 
23
 
 
24
#include "trousers/tss.h"
 
25
#include "trousers/trousers.h"
 
26
#include "trousers_types.h"
 
27
#include "spi_utils.h"
 
28
#include "capabilities.h"
 
29
#include "tsplog.h"
 
30
#include "hosttable.h"
 
31
#include "tcsd_wrap.h"
 
32
#include "obj.h"
 
33
#include "rpc_tcstp_tsp.h"
 
34
 
 
35
 
 
36
void
 
37
initData(struct tcsd_comm_data *comm, int parm_count)
 
38
{
 
39
        /* min packet size should be the size of the header */
 
40
        memset(&comm->hdr, 0, sizeof(struct tcsd_packet_hdr));
 
41
        comm->hdr.packet_size = sizeof(struct tcsd_packet_hdr);
 
42
        if (parm_count > 0) {
 
43
                comm->hdr.type_offset = sizeof(struct tcsd_packet_hdr);
 
44
                comm->hdr.parm_offset = comm->hdr.type_offset +
 
45
                                        (sizeof(TCSD_PACKET_TYPE) * parm_count);
 
46
                comm->hdr.packet_size = comm->hdr.parm_offset;
 
47
        }
 
48
 
 
49
        memset(comm->buf, 0, comm->buf_size);
 
50
}
 
51
 
 
52
int
 
53
loadData(UINT64 *offset, TCSD_PACKET_TYPE data_type, void *data, int data_size, BYTE *blob)
 
54
{
 
55
        switch (data_type) {
 
56
                case TCSD_PACKET_TYPE_BYTE:
 
57
                        Trspi_LoadBlob_BYTE(offset, *((BYTE *) (data)), blob);
 
58
                        break;
 
59
                case TCSD_PACKET_TYPE_BOOL:
 
60
                        Trspi_LoadBlob_BOOL(offset, *((TSS_BOOL *) (data)), blob);
 
61
                        break;
 
62
                case TCSD_PACKET_TYPE_UINT16:
 
63
                        Trspi_LoadBlob_UINT16(offset, *((UINT16 *) (data)), blob);
 
64
                        break;
 
65
                case TCSD_PACKET_TYPE_UINT32:
 
66
                        Trspi_LoadBlob_UINT32(offset, *((UINT32 *) (data)), blob);
 
67
                        break;
 
68
                case TCSD_PACKET_TYPE_PBYTE:
 
69
                        Trspi_LoadBlob(offset, data_size, blob, (BYTE *)data);
 
70
                        break;
 
71
                case TCSD_PACKET_TYPE_NONCE:
 
72
                        Trspi_LoadBlob(offset, 20, blob, ((TCPA_NONCE *)data)->nonce);
 
73
                        break;
 
74
                case TCSD_PACKET_TYPE_DIGEST:
 
75
                        Trspi_LoadBlob(offset, 20, blob, ((TCPA_DIGEST *)data)->digest);
 
76
                        break;
 
77
                case TCSD_PACKET_TYPE_AUTH:
 
78
                        LoadBlob_AUTH(offset, blob, ((TPM_AUTH *)data));
 
79
                        break;
 
80
                case TCSD_PACKET_TYPE_UUID:
 
81
                        Trspi_LoadBlob_UUID(offset, blob, *((TSS_UUID *)data));
 
82
                        break;
 
83
                case TCSD_PACKET_TYPE_ENCAUTH:
 
84
                        Trspi_LoadBlob(offset, 20, blob, ((TCPA_ENCAUTH *)data)->authdata);
 
85
                        break;
 
86
                case TCSD_PACKET_TYPE_VERSION:
 
87
                        Trspi_LoadBlob_TCPA_VERSION(offset, blob, *((TCPA_VERSION *)data));
 
88
                        break;
 
89
                case TCSD_PACKET_TYPE_LOADKEY_INFO:
 
90
                        LoadBlob_LOADKEY_INFO(offset, blob, ((TCS_LOADKEY_INFO *)data));
 
91
                        break;
 
92
                case TCSD_PACKET_TYPE_PCR_EVENT:
 
93
                        Trspi_LoadBlob_PCR_EVENT(offset, blob, ((TSS_PCR_EVENT *)data));
 
94
                        break;
 
95
                case TCSD_PACKET_TYPE_COUNTER_VALUE:
 
96
                        Trspi_LoadBlob_COUNTER_VALUE(offset, blob, ((TPM_COUNTER_VALUE *)data));
 
97
                        break;
 
98
                case TCSD_PACKET_TYPE_SECRET:
 
99
                        Trspi_LoadBlob(offset, 20, blob, ((TCPA_SECRET *)data)->authdata);
 
100
                        break;
 
101
                default:
 
102
                        LogError("TCSD packet type unknown! (0x%x)", data_type & 0xff);
 
103
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
104
        }
 
105
 
 
106
        return TSS_SUCCESS;
 
107
}
 
108
 
 
109
int
 
110
setData(TCSD_PACKET_TYPE dataType,
 
111
        int index,
 
112
        void *theData,
 
113
        int theDataSize,
 
114
        struct tcsd_comm_data *comm)
 
115
{
 
116
        UINT64 old_offset, offset;
 
117
        TSS_RESULT result;
 
118
        TCSD_PACKET_TYPE *type;
 
119
 
 
120
        /* Calculate the size of the area needed (use NULL for blob address) */
 
121
        offset = 0;
 
122
        if ((result = loadData(&offset, dataType, theData, theDataSize, NULL)))
 
123
                return result;
 
124
        if (((int)comm->hdr.packet_size + (int)offset) < 0) {
 
125
                LogError("Too much data to be transmitted!");
 
126
                return TCSERR(TSS_E_INTERNAL_ERROR);
 
127
        }
 
128
        if (((int)comm->hdr.packet_size + (int)offset) > comm->buf_size) {
 
129
                /* reallocate the buffer */
 
130
                BYTE *buffer;
 
131
                int buffer_size = comm->hdr.packet_size + offset;
 
132
 
 
133
                LogDebug("Increasing communication buffer to %d bytes.", buffer_size);
 
134
                buffer = realloc(comm->buf, buffer_size);
 
135
                if (buffer == NULL) {
 
136
                        LogError("realloc of %d bytes failed.", buffer_size);
 
137
                        return TCSERR(TSS_E_INTERNAL_ERROR);
 
138
                }
 
139
                comm->buf_size = buffer_size;
 
140
                comm->buf = buffer;
 
141
        }
 
142
 
 
143
        offset = old_offset = comm->hdr.parm_offset + comm->hdr.parm_size;
 
144
        if ((result = loadData(&offset, dataType, theData, theDataSize, comm->buf)))
 
145
                return result;
 
146
        type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) + index;
 
147
        *type = dataType;
 
148
        comm->hdr.type_size += sizeof(TCSD_PACKET_TYPE);
 
149
        comm->hdr.parm_size += (offset - old_offset);
 
150
 
 
151
        comm->hdr.packet_size = offset;
 
152
        comm->hdr.num_parms++;
 
153
 
 
154
        return TSS_SUCCESS;
 
155
}
 
156
 
 
157
UINT32
 
158
getData(TCSD_PACKET_TYPE dataType,
 
159
        int index,
 
160
        void *theData,
 
161
        int theDataSize,
 
162
        struct tcsd_comm_data *comm)
 
163
{
 
164
        TSS_RESULT result;
 
165
        UINT64 old_offset, offset;
 
166
        TCSD_PACKET_TYPE *type = (TCSD_PACKET_TYPE *)(comm->buf + comm->hdr.type_offset) + index;
 
167
 
 
168
        if ((UINT32)index >= comm->hdr.num_parms || dataType != *type) {
 
169
                LogDebug("Data type of TCS packet element %d doesn't match.", index);
 
170
                return TSS_TCP_RPC_BAD_PACKET_TYPE;
 
171
        }
 
172
        old_offset = offset = comm->hdr.parm_offset;
 
173
        switch (dataType) {
 
174
                case TCSD_PACKET_TYPE_BYTE:
 
175
                        Trspi_UnloadBlob_BYTE(&offset, (BYTE *)theData, comm->buf);
 
176
                        break;
 
177
                case TCSD_PACKET_TYPE_BOOL:
 
178
                        Trspi_UnloadBlob_BOOL(&offset, (TSS_BOOL *)theData, comm->buf);
 
179
                        break;
 
180
                case TCSD_PACKET_TYPE_UINT16:
 
181
                        Trspi_UnloadBlob_UINT16(&offset, (UINT16 *)theData, comm->buf);
 
182
                        break;
 
183
                case TCSD_PACKET_TYPE_UINT32:
 
184
                        Trspi_UnloadBlob_UINT32(&offset, (UINT32 *)theData, comm->buf);
 
185
                        break;
 
186
                case TCSD_PACKET_TYPE_UINT64:
 
187
                        Trspi_UnloadBlob_UINT64(&offset, (UINT64 *)theData, comm->buf);
 
188
                        break;
 
189
                case TCSD_PACKET_TYPE_PBYTE:
 
190
                        Trspi_UnloadBlob(&offset, theDataSize, comm->buf, (BYTE *)theData);
 
191
                        break;
 
192
                case TCSD_PACKET_TYPE_NONCE:
 
193
                        Trspi_UnloadBlob_NONCE(&offset, comm->buf, (TPM_NONCE *)theData);
 
194
                        break;
 
195
                case TCSD_PACKET_TYPE_DIGEST:
 
196
                        Trspi_UnloadBlob(&offset, sizeof(TCPA_DIGEST), comm->buf,
 
197
                                         ((TCPA_DIGEST *)theData)->digest);
 
198
                        break;
 
199
                case TCSD_PACKET_TYPE_AUTH:
 
200
                        UnloadBlob_AUTH(&offset, comm->buf, ((TPM_AUTH *)theData));
 
201
                        break;
 
202
                case TCSD_PACKET_TYPE_UUID:
 
203
                        Trspi_UnloadBlob_UUID(&offset, comm->buf, ((TSS_UUID *)theData));
 
204
                        break;
 
205
                case TCSD_PACKET_TYPE_ENCAUTH:
 
206
                        Trspi_UnloadBlob(&offset, sizeof(TCPA_ENCAUTH), comm->buf,
 
207
                                         ((TCPA_ENCAUTH *)theData)->authdata);
 
208
                        break;
 
209
                case TCSD_PACKET_TYPE_VERSION:
 
210
                        Trspi_UnloadBlob_TCPA_VERSION(&offset, comm->buf,
 
211
                                                      ((TCPA_VERSION *)theData));
 
212
                        break;
 
213
                case TCSD_PACKET_TYPE_KM_KEYINFO:
 
214
                        if ((result = Trspi_UnloadBlob_KM_KEYINFO(&offset, comm->buf,
 
215
                                                                  ((TSS_KM_KEYINFO *)theData))))
 
216
                                return result;
 
217
                        break;
 
218
                case TCSD_PACKET_TYPE_KM_KEYINFO2:
 
219
                        if ((result = Trspi_UnloadBlob_KM_KEYINFO2(&offset, comm->buf,
 
220
                                                                   ((TSS_KM_KEYINFO2 *)theData))))
 
221
                                return result;
 
222
                        break;
 
223
                case TCSD_PACKET_TYPE_LOADKEY_INFO:
 
224
                        UnloadBlob_LOADKEY_INFO(&offset, comm->buf, ((TCS_LOADKEY_INFO *)theData));
 
225
                        break;
 
226
                case TCSD_PACKET_TYPE_PCR_EVENT:
 
227
                        if ((result = Trspi_UnloadBlob_PCR_EVENT(&offset, comm->buf,
 
228
                                                                 ((TSS_PCR_EVENT *)theData))))
 
229
                                return result;
 
230
                        break;
 
231
                case TCSD_PACKET_TYPE_COUNTER_VALUE:
 
232
                        Trspi_UnloadBlob_COUNTER_VALUE(&offset, comm->buf,
 
233
                                                       ((TPM_COUNTER_VALUE *)theData));
 
234
                        break;
 
235
                case TCSD_PACKET_TYPE_SECRET:
 
236
                        Trspi_UnloadBlob(&offset, sizeof(TCPA_SECRET), comm->buf,
 
237
                                         ((TCPA_SECRET *)theData)->authdata);
 
238
                        break;
 
239
                default:
 
240
                        LogError("unknown data type (%d) in TCSD packet!", dataType);
 
241
                        return -1;
 
242
        }
 
243
        comm->hdr.parm_offset = offset;
 
244
        comm->hdr.parm_size -= (offset - old_offset);
 
245
 
 
246
        return TSS_SUCCESS;
 
247
}
 
248
 
 
249
TSS_RESULT
 
250
sendTCSDPacket(struct host_table_entry *hte)
 
251
{
 
252
        TSS_RESULT rc;
 
253
        UINT64 offset = 0;
 
254
 
 
255
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.packet_size, hte->comm.buf);
 
256
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.u.ordinal, hte->comm.buf);
 
257
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.num_parms, hte->comm.buf);
 
258
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_size, hte->comm.buf);
 
259
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.type_offset, hte->comm.buf);
 
260
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_size, hte->comm.buf);
 
261
        Trspi_LoadBlob_UINT32(&offset, hte->comm.hdr.parm_offset, hte->comm.buf);
 
262
 
 
263
#if 0
 
264
        /* ---  Send it */
 
265
        printBuffer(hte->comm.buf, hte->comm.hdr.packet_size);
 
266
        LogInfo("Sending Packet with TCSD ordinal 0x%X", hte->comm.hdr.u.ordinal);
 
267
#endif
 
268
        /* if the ordinal is open context, there are some host table entry
 
269
         * manipulations that must be done, so call _init
 
270
         */
 
271
        if (hte->comm.hdr.u.ordinal == TCSD_ORD_OPENCONTEXT) {
 
272
                if ((rc = send_init(hte))) {
 
273
                        LogError("Failed to send packet");
 
274
                        return rc;
 
275
                }
 
276
        } else {
 
277
                if ((rc = sendit(hte))) {
 
278
                        LogError("Failed to send packet");
 
279
                        return rc;
 
280
                }
 
281
        }
 
282
 
 
283
        /* create a platform version of the tcsd header */
 
284
        offset = 0;
 
285
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.packet_size, hte->comm.buf);
 
286
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.u.result, hte->comm.buf);
 
287
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.num_parms, hte->comm.buf);
 
288
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_size, hte->comm.buf);
 
289
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.type_offset, hte->comm.buf);
 
290
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_size, hte->comm.buf);
 
291
        Trspi_UnloadBlob_UINT32(&offset, &hte->comm.hdr.parm_offset, hte->comm.buf);
 
292
 
 
293
        return TSS_SUCCESS;
 
294
}
 
295
 
 
296
int
 
297
recv_from_socket(int sock, void *buffer, int size)
 
298
{
 
299
        int recv_size = 0, recv_total = 0;
 
300
 
 
301
        while (recv_total < size) {
 
302
                errno = 0;
 
303
                if ((recv_size = recv(sock, buffer+recv_total, size-recv_total, 0)) <= 0) {
 
304
                        if (recv_size < 0) {
 
305
                                if (errno == EINTR)
 
306
                                        continue;
 
307
                                LogError("Socket receive connection error: %s.", strerror(errno));
 
308
                        } else {
 
309
                                LogDebug("Socket connection closed.");
 
310
                        }
 
311
 
 
312
                        return -1;
 
313
                }
 
314
                recv_total += recv_size;
 
315
        }
 
316
 
 
317
        return recv_total;
 
318
}
 
319
 
 
320
int
 
321
send_to_socket(int sock, void *buffer, int size)
 
322
{
 
323
        int send_size = 0, send_total = 0;
 
324
 
 
325
        while (send_total < size) {
 
326
                if ((send_size = send(sock, buffer+send_total, size-send_total, 0)) < 0) {
 
327
                        LogError("Socket send connection error: %s.", strerror(errno));
 
328
                        return -1;
 
329
                }
 
330
                send_total += send_size;
 
331
        }
 
332
 
 
333
        return send_total;
 
334
}
 
335
 
 
336
TSS_RESULT
 
337
send_init(struct host_table_entry *hte)
 
338
{
 
339
        int sd;
 
340
        int recv_size;
 
341
        BYTE *buffer;
 
342
        TSS_RESULT result;
 
343
 
 
344
        struct sockaddr_in addr;
 
345
        struct hostent *hEnt = NULL;
 
346
 
 
347
        sd = socket(PF_INET, SOCK_STREAM, 0);
 
348
        if (sd == -1) {
 
349
                LogError("socket: %s", strerror(errno));
 
350
                result = TSPERR(TSS_E_COMM_FAILURE);
 
351
                goto err_exit;
 
352
        }
 
353
 
 
354
        memset(&addr, 0, sizeof(addr));
 
355
        addr.sin_family = AF_INET;
 
356
        addr.sin_port = htons(get_port());
 
357
 
 
358
        LogDebug("Sending TSP packet to host %s.", hte->hostname);
 
359
 
 
360
        /* try to resolve by hostname first */
 
361
        hEnt = gethostbyname((char *)hte->hostname);
 
362
        if (hEnt == NULL) {
 
363
                /* if by hostname fails, try by dot notation */
 
364
                if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) {
 
365
                        LogError("hostname %s does not resolve to a valid address.", hte->hostname);
 
366
                        result = TSPERR(TSS_E_CONNECTION_FAILED);
 
367
                        goto err_exit;
 
368
                }
 
369
        } else {
 
370
                memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4);
 
371
        }
 
372
 
 
373
        LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr));
 
374
 
 
375
        if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
 
376
                LogError("connect: %s", strerror(errno));
 
377
                result = TSPERR(TSS_E_COMM_FAILURE);
 
378
                goto err_exit;
 
379
        }
 
380
 
 
381
        if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) {
 
382
                result = TSPERR(TSS_E_COMM_FAILURE);
 
383
                goto err_exit;
 
384
        }
 
385
 
 
386
        buffer = hte->comm.buf;
 
387
        recv_size = sizeof(struct tcsd_packet_hdr);
 
388
        if ((recv_size = recv_from_socket(sd, buffer, recv_size)) < 0) {
 
389
                result = TSPERR(TSS_E_COMM_FAILURE);
 
390
                goto err_exit;
 
391
        }
 
392
        buffer += sizeof(struct tcsd_packet_hdr);       /* increment the receive buffer pointer */
 
393
 
 
394
        /* check the packet size */
 
395
        recv_size = Decode_UINT32(hte->comm.buf);
 
396
        if (recv_size < (int)sizeof(struct tcsd_packet_hdr)) {
 
397
                LogError("Packet to receive from socket %d is too small (%d bytes)",
 
398
                                sd, recv_size);
 
399
                result = TSPERR(TSS_E_COMM_FAILURE);
 
400
                goto err_exit;
 
401
        }
 
402
 
 
403
        if (recv_size > hte->comm.buf_size ) {
 
404
                BYTE *new_buffer;
 
405
 
 
406
                LogDebug("Increasing communication buffer to %d bytes.", recv_size);
 
407
                new_buffer = realloc(hte->comm.buf, recv_size);
 
408
                if (new_buffer == NULL) {
 
409
                        LogError("realloc of %d bytes failed.", recv_size);
 
410
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
411
                        goto err_exit;
 
412
                }
 
413
                buffer = new_buffer + sizeof(struct tcsd_packet_hdr);
 
414
                hte->comm.buf_size = recv_size;
 
415
                hte->comm.buf = new_buffer;
 
416
        }
 
417
 
 
418
        /* get the rest of the packet */
 
419
        recv_size -= sizeof(struct tcsd_packet_hdr);    /* already received the header */
 
420
        if ((recv_size = recv_from_socket(sd, buffer, recv_size)) < 0) {
 
421
                result = TSPERR(TSS_E_COMM_FAILURE);
 
422
                goto err_exit;
 
423
        }
 
424
 
 
425
        hte->socket = sd;
 
426
 
 
427
        return TSS_SUCCESS;
 
428
 
 
429
err_exit:
 
430
        close(sd);
 
431
        return result;
 
432
}
 
433
 
 
434
TSS_RESULT
 
435
sendit(struct host_table_entry *hte)
 
436
{
 
437
        int recv_size;
 
438
        BYTE *buffer;
 
439
        TSS_RESULT result;
 
440
 
 
441
        if (send_to_socket(hte->socket, hte->comm.buf, hte->comm.hdr.packet_size) < 0) {
 
442
                result = TSPERR(TSS_E_COMM_FAILURE);
 
443
                goto err_exit;
 
444
        }
 
445
 
 
446
        buffer = hte->comm.buf;
 
447
        recv_size = sizeof(struct tcsd_packet_hdr);
 
448
        if ((recv_size = recv_from_socket(hte->socket, buffer, recv_size)) < 0) {
 
449
                result = TSPERR(TSS_E_COMM_FAILURE);
 
450
                goto err_exit;
 
451
        }
 
452
        buffer += recv_size;            /* increment the receive buffer pointer */
 
453
 
 
454
        /* check the packet size */
 
455
        recv_size = Decode_UINT32(hte->comm.buf);
 
456
        if (recv_size < (int)sizeof(struct tcsd_packet_hdr)) {
 
457
                LogError("Packet to receive from socket %d is too small (%d bytes)",
 
458
                                hte->socket, recv_size);
 
459
                result = TSPERR(TSS_E_COMM_FAILURE);
 
460
                goto err_exit;
 
461
        }
 
462
 
 
463
        if (recv_size > hte->comm.buf_size ) {
 
464
                BYTE *new_buffer;
 
465
 
 
466
                LogDebug("Increasing communication buffer to %d bytes.", recv_size);
 
467
                new_buffer = realloc(hte->comm.buf, recv_size);
 
468
                if (new_buffer == NULL) {
 
469
                        LogError("realloc of %d bytes failed.", recv_size);
 
470
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
471
                        goto err_exit;
 
472
                }
 
473
                buffer = new_buffer + sizeof(struct tcsd_packet_hdr);
 
474
                hte->comm.buf_size = recv_size;
 
475
                hte->comm.buf = new_buffer;
 
476
        }
 
477
 
 
478
        /* get the rest of the packet */
 
479
        recv_size -= sizeof(struct tcsd_packet_hdr);    /* already received the header */
 
480
        if ((recv_size = recv_from_socket(hte->socket, buffer, recv_size)) < 0) {
 
481
                result = TSPERR(TSS_E_COMM_FAILURE);
 
482
                goto err_exit;
 
483
        }
 
484
 
 
485
        return TSS_SUCCESS;
 
486
 
 
487
err_exit:
 
488
        return result;
 
489
}
 
490
 
 
491
/* XXX this should be moved out of an RPC-specific file */
 
492
short
 
493
get_port(void)
 
494
{
 
495
        char *env_port;
 
496
        int port = 0;
 
497
 
 
498
        env_port = getenv("TSS_TCSD_PORT");
 
499
 
 
500
        if (env_port == NULL)
 
501
                return TCSD_DEFAULT_PORT;
 
502
 
 
503
        port = atoi(env_port);
 
504
 
 
505
        if (port == 0 || port > 65535)
 
506
                return TCSD_DEFAULT_PORT;
 
507
 
 
508
        return (short)port;
 
509
}
 
510