| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Licensed Materials - Property of IBM | 3 * Licensed Materials - Property of IBM |
| 4 * | 4 * |
| 5 * trousers - An open source TCG Software Stack | 5 * trousers - An open source TCG Software Stack |
| 6 * | 6 * |
| 7 * (C) Copyright International Business Machines Corp. 2004-2006 | 7 * (C) Copyright International Business Machines Corp. 2004-2006 |
| 8 * | 8 * |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 #include <errno.h> | 12 #include <errno.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
| 15 #include <sys/types.h> | 15 #include <sys/types.h> |
| 16 #include <sys/un.h> |
| 16 #include <netinet/in.h> | 17 #include <netinet/in.h> |
| 17 #include <arpa/inet.h> | 18 #include <arpa/inet.h> |
| 18 #include <netdb.h> | 19 #include <netdb.h> |
| 19 #include <stdlib.h> | 20 #include <stdlib.h> |
| 20 #include <stdio.h> | 21 #include <stdio.h> |
| 21 #include <assert.h> | 22 #include <assert.h> |
| 22 #include <limits.h> | 23 #include <limits.h> |
| 23 | 24 |
| 24 #include "trousers/tss.h" | 25 #include "trousers/tss.h" |
| 25 #include "trousers/trousers.h" | 26 #include "trousers/trousers.h" |
| 26 #include "trousers_types.h" | 27 #include "trousers_types.h" |
| 27 #include "spi_utils.h" | 28 #include "spi_utils.h" |
| 28 #include "capabilities.h" | 29 #include "capabilities.h" |
| 29 #include "tsplog.h" | 30 #include "tsplog.h" |
| 30 #include "hosttable.h" | 31 #include "hosttable.h" |
| 31 #include "tcsd_wrap.h" | 32 #include "tcsd_wrap.h" |
| 32 #include "obj.h" | 33 #include "obj.h" |
| 33 #include "rpc_tcstp_tsp.h" | 34 #include "rpc_tcstp_tsp.h" |
| 34 | 35 |
| 35 | |
| 36 void | 36 void |
| 37 initData(struct tcsd_comm_data *comm, int parm_count) | 37 initData(struct tcsd_comm_data *comm, int parm_count) |
| 38 { | 38 { |
| 39 /* min packet size should be the size of the header */ | 39 /* min packet size should be the size of the header */ |
| 40 memset(&comm->hdr, 0, sizeof(struct tcsd_packet_hdr)); | 40 memset(&comm->hdr, 0, sizeof(struct tcsd_packet_hdr)); |
| 41 comm->hdr.packet_size = sizeof(struct tcsd_packet_hdr); | 41 comm->hdr.packet_size = sizeof(struct tcsd_packet_hdr); |
| 42 if (parm_count > 0) { | 42 if (parm_count > 0) { |
| 43 comm->hdr.type_offset = sizeof(struct tcsd_packet_hdr); | 43 comm->hdr.type_offset = sizeof(struct tcsd_packet_hdr); |
| 44 comm->hdr.parm_offset = comm->hdr.type_offset + | 44 comm->hdr.parm_offset = comm->hdr.type_offset + |
| 45 (sizeof(TCSD_PACKET_TYPE) * parm_count); | 45 (sizeof(TCSD_PACKET_TYPE) * parm_count); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 338 } |
| 339 | 339 |
| 340 TSS_RESULT | 340 TSS_RESULT |
| 341 send_init(struct host_table_entry *hte) | 341 send_init(struct host_table_entry *hte) |
| 342 { | 342 { |
| 343 int sd; | 343 int sd; |
| 344 int recv_size; | 344 int recv_size; |
| 345 BYTE *buffer; | 345 BYTE *buffer; |
| 346 TSS_RESULT result; | 346 TSS_RESULT result; |
| 347 | 347 |
| 348 » struct sockaddr_in addr; | 348 » struct sockaddr_un addr; |
| 349 » struct hostent *hEnt = NULL; | |
| 350 | 349 |
| 351 » sd = socket(PF_INET, SOCK_STREAM, 0); | 350 » sd = socket(PF_UNIX, SOCK_STREAM, 0); |
| 352 if (sd == -1) { | 351 if (sd == -1) { |
| 353 LogError("socket: %s", strerror(errno)); | 352 LogError("socket: %s", strerror(errno)); |
| 354 result = TSPERR(TSS_E_COMM_FAILURE); | 353 result = TSPERR(TSS_E_COMM_FAILURE); |
| 355 goto err_exit; | 354 goto err_exit; |
| 356 } | 355 } |
| 357 | 356 |
| 358 memset(&addr, 0, sizeof(addr)); | 357 memset(&addr, 0, sizeof(addr)); |
| 359 » addr.sin_family = AF_INET; | 358 » addr.sun_family = AF_UNIX; |
| 360 » addr.sin_port = htons(get_port()); | 359 » strcpy(addr.sun_path, TCSD_UNIX_SOCKET); |
| 361 | 360 |
| 362 » LogDebug("Sending TSP packet to host %s.", hte->hostname); | 361 » if (connect(sd, (struct sockaddr *) &addr, |
| 363 | 362 strlen(addr.sun_path) + sizeof (addr.sun_family))) { |
| 364 » /* try to resolve by hostname first */ | |
| 365 » hEnt = gethostbyname((char *)hte->hostname); | |
| 366 » if (hEnt == NULL) { | |
| 367 » » /* if by hostname fails, try by dot notation */ | |
| 368 » » if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) { | |
| 369 » » » LogError("hostname %s does not resolve to a valid addres
s.", hte->hostname); | |
| 370 » » » result = TSPERR(TSS_E_CONNECTION_FAILED); | |
| 371 » » » goto err_exit; | |
| 372 » » } | |
| 373 » } else { | |
| 374 » » memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4); | |
| 375 » } | |
| 376 | |
| 377 » LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr)); | |
| 378 | |
| 379 » if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) { | |
| 380 LogError("connect: %s", strerror(errno)); | 363 LogError("connect: %s", strerror(errno)); |
| 381 result = TSPERR(TSS_E_COMM_FAILURE); | 364 result = TSPERR(TSS_E_COMM_FAILURE); |
| 382 goto err_exit; | 365 goto err_exit; |
| 383 } | 366 } |
| 384 | 367 |
| 385 if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) { | 368 if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) { |
| 386 result = TSPERR(TSS_E_COMM_FAILURE); | 369 result = TSPERR(TSS_E_COMM_FAILURE); |
| 387 goto err_exit; | 370 goto err_exit; |
| 388 } | 371 } |
| 389 | 372 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (env_port == NULL) | 487 if (env_port == NULL) |
| 505 return TCSD_DEFAULT_PORT; | 488 return TCSD_DEFAULT_PORT; |
| 506 | 489 |
| 507 port = atoi(env_port); | 490 port = atoi(env_port); |
| 508 | 491 |
| 509 if (port == 0 || port > 65535) | 492 if (port == 0 || port > 65535) |
| 510 return TCSD_DEFAULT_PORT; | 493 return TCSD_DEFAULT_PORT; |
| 511 | 494 |
| 512 return (short)port; | 495 return (short)port; |
| 513 } | 496 } |
| 514 | |
| OLD | NEW |