1 --- trousers-0.3.11.2/src/tspi/rpc/hosttable.c.orig
2 +++ trousers-0.3.11.2/src/tspi/rpc/hosttable.c
5 static struct host_table *ht = NULL;
11 ht = calloc(1, sizeof(struct host_table));
19 +#ifdef SOLARIS && defined(__SUNPRO_C))
20 +static void my_init(void)
22 void __attribute__ ((constructor)) my_init(void)
25 __tspi_obj_list_init();
32 struct host_table_entry *hte, *next = NULL;
34 + if (ht == NULL) /* no host table to free */
39 for (hte = ht->entries; hte; hte = next) {
47 +#ifdef SOLARIS && defined(__SUNPRO_C))
48 +static void my_fini(void)
50 void __attribute__ ((destructor)) my_fini(void)
57 +#pragma init(my_init)
58 +#pragma fini(my_fini)
62 __tspi_add_table_entry(TSS_HCONTEXT tspContext, BYTE *host, int type, struct host_table_entry **ret)
64 --- trousers-0.3.11.2/src/tcsd/Makefile.am.orig
65 +++ trousers-0.3.11.2/src/tcsd/Makefile.am
68 tcsd_CFLAGS=-DAPPID=\"TCSD\" -DVAR_PREFIX=\"@localstatedir@\" -DETC_PREFIX=\"@sysconfdir@\" -I${top_srcdir}/src/include -fPIE -DPIE
69 tcsd_LDADD=${top_builddir}/src/tcs/libtcs.a ${top_builddir}/src/tddl/libtddl.a -lpthread @CRYPTOLIB@
70 -tcsd_LDFLAGS=-pie -Wl,-z,relro -Wl,-z,now
71 +tcsd_LDFLAGS=-Wl,-z,now
73 tcsd_SOURCES=svrside.c tcsd_conf.c tcsd_threads.c platform.c
75 --- trousers-0.3.11.2/src/tcsd/Makefile.in.orig
76 +++ trousers-0.3.11.2/src/tcsd/Makefile.in
78 mkinstalldirs = $(install_sh) -d
80 CONFIG_CLEAN_VPATH_FILES =
81 -am__installdirs = "$(DESTDIR)$(sbindir)"
82 +am__installdirs = "$(DESTDIR)$(libdir)"
83 PROGRAMS = $(sbin_PROGRAMS)
84 am_tcsd_OBJECTS = tcsd-svrside.$(OBJEXT) tcsd-tcsd_conf.$(OBJEXT) \
85 tcsd-tcsd_threads.$(OBJEXT) tcsd-platform.$(OBJEXT)
88 program_transform_name = @program_transform_name@
92 sharedstatedir = @sharedstatedir@
94 sysconfdir = @sysconfdir@
96 tcsd_CFLAGS = -DAPPID=\"TCSD\" -DVAR_PREFIX=\"@localstatedir@\" \
97 -DETC_PREFIX=\"@sysconfdir@\" -I${top_srcdir}/src/include \
98 -fPIE -DPIE $(am__append_1) $(am__append_2)
99 -tcsd_LDADD = ${top_builddir}/src/tcs/libtcs.a ${top_builddir}/src/tddl/libtddl.a -lpthread @CRYPTOLIB@
100 -tcsd_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now
101 +tcsd_LDADD = ${top_builddir}/src/tcs/libtcs.a ${top_builddir}/src/tddl/libtddl.a \
102 + -lpthread -lbsm -lscf -lresolv @CRYPTOLIB@
103 +tcsd_LDFLAGS = -Wl,-z,now
104 tcsd_SOURCES = svrside.c tcsd_conf.c tcsd_threads.c platform.c
107 --- trousers-0.3.11.2/src/include/tcsd.h.orig
108 +++ trousers-0.3.11.2/src/include/tcsd.h
110 of this TCS System */
114 +#define TCSD_DEFAULT_CONFIG_FILE "/etc/security/tcsd.conf"
116 #define TCSD_DEFAULT_CONFIG_FILE ETC_PREFIX "/tcsd.conf"
118 extern char *tcsd_config_file;
120 #define TSS_USER_NAME "tss"
121 #define TSS_GROUP_NAME "tss"
123 #define TCSD_DEFAULT_MAX_THREADS 10
125 +#define TCSD_DEFAULT_SYSTEM_PS_DIR "/var/tpm/system"
126 +#define TCSD_DEFAULT_SYSTEM_PS_FILE "/var/tpm/system/system.data"
127 +#define TCSD_DEFAULT_SOCKET "/var/tpm/tcsd-socket"
129 #define TCSD_DEFAULT_SYSTEM_PS_FILE VAR_PREFIX "/lib/tpm/system.data"
130 #define TCSD_DEFAULT_SYSTEM_PS_DIR VAR_PREFIX "/lib/tpm"
131 +#endif /* SOLARIS */
132 #define TCSD_DEFAULT_FIRMWARE_LOG_FILE "/sys/kernel/security/tpm0/binary_bios_measurements"
133 #define TCSD_DEFAULT_KERNEL_LOG_FILE "/sys/kernel/security/ima/binary_runtime_measurements"
134 #define TCSD_DEFAULT_FIRMWARE_PCRS 0x00000000
135 --- trousers-0.3.11.2/src/include/tspps.h.orig
136 +++ trousers-0.3.11.2/src/include/tspps.h
139 #define PASSWD_BUFSIZE 4096
142 +#define TSS_USER_PS_DIR "/var/user/"
144 #define TSS_USER_PS_DIR ".trousers"
146 #define TSS_USER_PS_FILE "user.data"
148 TSS_RESULT get_file(int *);
150 -inline TSS_RESULT read_data(int, void *, UINT32);
151 -inline TSS_RESULT write_data(int, void *, UINT32);
152 +TSS_RESULT read_data(int, void *, UINT32);
153 +TSS_RESULT write_data(int, void *, UINT32);
154 UINT32 psfile_get_num_keys(int);
155 TSS_RESULT psfile_get_parent_uuid_by_uuid(int, TSS_UUID *, TSS_UUID *);
156 TSS_RESULT psfile_remove_key_by_uuid(int, TSS_UUID *);
157 --- trousers-0.3.11.2/src/tcsd/svrside.c.orig
158 +++ trousers-0.3.11.2/src/tcsd/svrside.c
160 #include <arpa/inet.h>
172 #include "trousers/tss.h"
173 #include "trousers_types.h"
177 char *tcsd_config_file = NULL;
180 +static int get_event_log_from_kernel(void);
187 (void)req_mgr_final();
191 + /* Not fatal if this fails */
192 + (void) get_event_log_from_kernel();
195 result = owner_evict_init();
196 if (result != TSS_SUCCESS) {
197 @@ -211,16 +228,171 @@
203 +extern int get_device_fd(void);
205 +#define TPM_IOCTL_GETEVTABLE 1
206 +struct tpm_evtable_ioblk {
212 +store_eventlog(char *filename, struct tpm_evtable_ioblk *evlog)
215 + unsigned int bytes = 0;
217 + fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600);
219 + LogError("Error opening logfile %s: %s", filename,
223 + while (bytes < evlog->buflen) {
225 + n = write(fd, evlog->buf, evlog->buflen - bytes);
226 + if (n == -1 && errno != EAGAIN) {
227 + LogError("Error writing logfile %s: %s",
228 + filename, strerror(errno));
241 +get_event_log_from_kernel(void)
243 + int fd = get_device_fd();
244 + struct tpm_evtable_ioblk ioblk;
249 + (void) memset(&ioblk, 0, sizeof (ioblk));
250 + if (ioctl(fd, TPM_IOCTL_GETEVTABLE, &ioblk)) {
251 + LogDebug("Cannot get event log from kernel: %s",
255 + if (ioblk.buflen == 0)
258 + ioblk.buf = calloc(1, ioblk.buflen);
259 + if (ioblk.buf == NULL) {
262 + if (ioctl(fd, TPM_IOCTL_GETEVTABLE, &ioblk)) {
264 + LogDebug("Cannot get event log from kernel: %s",
269 + return (store_eventlog(tcsd_options.firmware_log_file, &ioblk));
273 + * For Solaris, make the tcsd privilege aware and drop
274 + * risky privileges if they are not needed.
279 + priv_set_t *myprivs;
283 + * Drop unneeded privs such as fork/exec.
285 + * Get "basic" privs and remove the ones we don't want.
287 + if ((myprivs = priv_str_to_set("basic", ",", NULL)) == NULL) {
288 + LogError("priv_str_to_set failed: %s", strerror(errno));
291 + (void) priv_delset(myprivs, PRIV_PROC_EXEC);
292 + (void) priv_delset(myprivs, PRIV_PROC_FORK);
293 + (void) priv_delset(myprivs, PRIV_FILE_LINK_ANY);
294 + (void) priv_delset(myprivs, PRIV_PROC_INFO);
295 + (void) priv_delset(myprivs, PRIV_PROC_SESSION);
296 + (void) priv_delset(myprivs, PRIV_PROC_SETID);
299 + (void) priv_addset(myprivs, PRIV_PROC_AUDIT);
301 + if ((rv = setppriv(PRIV_SET, PRIV_PERMITTED, myprivs)))
303 + if ((rv = setppriv(PRIV_SET, PRIV_LIMIT, myprivs)))
305 + if ((rv = setppriv(PRIV_SET, PRIV_INHERITABLE, myprivs)))
308 + (void) priv_freeset(myprivs);
312 +#endif /* SOLARIS */
316 +daemon(int nochdir, int noclose) {
325 + case -1: /* failure: parent process */
327 + case 0: /* success: child process */
329 + default: /* success: parent process */
333 + /* Create a new SID for the child process */
334 + if (setsid() == -1)
336 + /* Prevent cwd from being left open and unremovable */
340 + /* Redirect stdin, stdout, and stderr to /dev/null */
341 + if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
342 + (void) dup2(fd, STDIN_FILENO);
343 + (void) dup2(fd, STDOUT_FILENO);
344 + (void) dup2(fd, STDERR_FILENO);
350 +#endif /* !HAVE_DAEMON */
353 main(int argc, char **argv)
355 - struct sockaddr_in serv_addr, client_addr;
357 + struct sockaddr_in in;
358 + struct sockaddr_un un;
359 + } sockaddr_un_in_t;
360 + sockaddr_un_in_t serv_addr, client_addr;
363 int newsd, c, option_index = 0;
364 - unsigned client_len;
365 + unsigned client_len, serv_len;
366 char *hostname = NULL;
367 - struct passwd *pwd;
368 + struct passwd *pwd = NULL;
369 struct hostent *client_hostent = NULL;
370 struct option long_options[] = {
371 {"help", 0, NULL, 'h'},
372 @@ -256,26 +428,50 @@
373 if ((result = tcsd_startup()))
376 - sd = socket(AF_INET, SOCK_STREAM, 0);
378 - LogError("Failed socket: %s", strerror(errno));
381 + if (tcsd_options.port == 0) { /* UNIX Domain socket */
382 + /* Use UNIX Domain socket instead of TCP/IP socket */
383 + sd = socket(AF_UNIX, SOCK_STREAM, 0);
385 + LogError("Failed socket: %s", strerror(errno));
389 + memset(&serv_addr, 0, sizeof (serv_addr));
390 + serv_addr.un.sun_family = AF_UNIX;
391 + strncpy(serv_addr.un.sun_path, TCSD_DEFAULT_SOCKET,
392 + sizeof (serv_addr.un.sun_path));
393 + (void) unlink(TCSD_DEFAULT_SOCKET);
395 + } else { /* TCP socket */
396 + sd = socket(AF_INET, SOCK_STREAM, 0);
398 + LogError("Failed socket: %s", strerror(errno));
402 - memset(&serv_addr, 0, sizeof (serv_addr));
403 - serv_addr.sin_family = AF_INET;
404 - serv_addr.sin_port = htons(tcsd_options.port);
406 - /* If no remote_ops are defined, restrict connections to localhost
407 - * only at the socket. */
408 - if (tcsd_options.remote_ops[0] == 0)
409 - serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
411 - serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
414 - setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &c, sizeof(c));
415 - if (bind(sd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
416 + memset(&serv_addr, 0, sizeof (serv_addr));
417 + serv_addr.in.sin_family = AF_INET;
418 + serv_addr.in.sin_port = htons(tcsd_options.port);
420 + /* If no remote_ops are defined, restrict connections to localhost
421 + * only at the socket. */
422 + if (tcsd_options.remote_ops[0] == 0)
423 + serv_addr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
425 + serv_addr.in.sin_addr.s_addr = htonl(INADDR_ANY);
428 + setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &c, sizeof(c));
431 + if (tcsd_options.port == 0) { /* UNIX Domain socket */
432 + serv_len = (unsigned)sizeof(serv_addr.un);
433 + client_len = (unsigned)sizeof(client_addr.un);
434 + } else { /* TCP socket */
435 + serv_len = (unsigned)sizeof(serv_addr.in);
436 + client_len = (unsigned)sizeof(client_addr.in);
438 + if (bind(sd, (struct sockaddr *) &serv_addr, serv_len) < 0) {
439 LogError("Failed bind: %s", strerror(errno));
443 LogError("Failed listen: %s", strerror(errno));
446 - client_len = (unsigned)sizeof(client_addr);
448 if (getenv("TCSD_FOREGROUND") == NULL) {
449 if (daemon(0, 0) == -1) {
455 + /* For Solaris, drop privileges for security. */
456 + if ((rv = drop_privs()))
458 +#endif /* SOLARIS */
460 LogInfo("%s: TCSD up and running.", PACKAGE_STRING);
462 newsd = accept(sd, (struct sockaddr *) &client_addr, &client_len);
463 @@ -325,20 +526,22 @@
465 LogDebug("accepted socket %i", newsd);
467 - if ((client_hostent = gethostbyaddr((char *) &client_addr.sin_addr,
468 - sizeof(client_addr.sin_addr),
469 + if (tcsd_options.port != 0) { /* TCP socket */
470 + if ((client_hostent = gethostbyaddr((char *) &client_addr.in.sin_addr,
471 + sizeof(client_addr.in.sin_addr),
474 - uint32_t addr = htonl(client_addr.sin_addr.s_addr);
476 + uint32_t addr = htonl(client_addr.in.sin_addr.s_addr);
478 - snprintf(buf, 16, "%d.%d.%d.%d", (addr & 0xff000000) >> 24,
479 - (addr & 0x00ff0000) >> 16, (addr & 0x0000ff00) >> 8,
480 - addr & 0x000000ff);
481 + snprintf(buf, 16, "%d.%d.%d.%d", (addr & 0xff000000) >> 24,
482 + (addr & 0x00ff0000) >> 16, (addr & 0x0000ff00) >> 8,
483 + addr & 0x000000ff);
485 - LogWarn("Host name for connecting IP %s could not be resolved", buf);
486 - hostname = strdup(buf);
488 - hostname = strdup(client_hostent->h_name);
489 + LogWarn("Host name for connecting IP %s could not be resolved", buf);
490 + hostname = strdup(buf);
492 + hostname = strdup(client_hostent->h_name);
496 tcsd_thread_create(newsd, hostname);
497 --- trousers-0.3.11.2/src/tspi/rpc/tcstp/rpc.c.orig
498 +++ trousers-0.3.11.2/src/tspi/rpc/tcstp/rpc.c
499 @@ -342,41 +342,68 @@
503 - struct sockaddr_in addr;
504 - struct hostent *hEnt = NULL;
505 + if (get_port() == 0) { /* use UNIX Domain socket */
506 + struct sockaddr_un addr;
508 - sd = socket(PF_INET, SOCK_STREAM, 0);
510 - LogError("socket: %s", strerror(errno));
511 - result = TSPERR(TSS_E_COMM_FAILURE);
515 - __tspi_memset(&addr, 0, sizeof(addr));
516 - addr.sin_family = AF_INET;
517 - addr.sin_port = htons(get_port());
519 - LogDebug("Sending TSP packet to host %s.", hte->hostname);
521 - /* try to resolve by hostname first */
522 - hEnt = gethostbyname((char *)hte->hostname);
523 - if (hEnt == NULL) {
524 - /* if by hostname fails, try by dot notation */
525 - if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) {
526 - LogError("hostname %s does not resolve to a valid address.", hte->hostname);
527 - result = TSPERR(TSS_E_CONNECTION_FAILED);
528 + sd = socket(PF_UNIX, SOCK_STREAM, 0);
530 + LogError("socket(PF_UNIX): %s", strerror(errno));
531 + result = TSPERR(TSS_E_COMM_FAILURE);
535 - memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4);
538 - LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr));
539 + __tspi_memset(&addr, 0, sizeof(addr));
540 + addr.sun_family = AF_UNIX;
541 + strncpy(addr.sun_path, TCSD_DEFAULT_SOCKET,
542 + sizeof(addr.sun_path));
544 + LogDebug("Connecting to UNIX Domain socket %s",
545 + TCSD_DEFAULT_SOCKET);
547 + if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
548 + LogError("connect: %s", strerror(errno));
549 + result = TSPERR(TSS_E_COMM_FAILURE);
553 + } else { /* use TCP socket */
554 + struct sockaddr_in addr;
555 + struct hostent *hEnt = NULL;
557 + sd = socket(PF_INET, SOCK_STREAM, 0);
559 + LogError("socket: %s", strerror(errno));
560 + result = TSPERR(TSS_E_COMM_FAILURE);
564 + __tspi_memset(&addr, 0, sizeof(addr));
565 + addr.sin_family = AF_INET;
566 + addr.sin_port = htons(get_port());
568 + LogDebug("Sending TSP packet to host %s.", hte->hostname);
570 + /* try to resolve by hostname first */
571 + hEnt = gethostbyname((char *)hte->hostname);
572 + if (hEnt == NULL) {
573 + /* if by hostname fails, try by dot notation */
574 + if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) {
575 + LogError("hostname %s does not resolve to a valid address.", hte->hostname);
576 + result = TSPERR(TSS_E_CONNECTION_FAILED);
580 + memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4);
583 + LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr));
585 - if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
586 - LogError("connect: %s", strerror(errno));
587 - result = TSPERR(TSS_E_COMM_FAILURE);
589 + if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
590 + LogError("connect: %s", strerror(errno));
591 + result = TSPERR(TSS_E_COMM_FAILURE);
596 if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) {