# tspi_ps_tspps.c.patch # This change implements Solaris-specific locations for the # TSS PS (persistent storage), aka TPM keystore. # It is not suitable for upstream use. # # The change to getpwuid_r() uses the "new" POSIX PTHREAD API (as opposed to # the old "Draft6" prototype). It requires -D_POSIX_PTHREAD_SEMANTICS # on S11 and older in order to use (and is the default on S12+). # This change was implemented in-house. # --- src/tspi/ps/tspps.c 2014-04-24 11:05:44.000000000 -0700 +++ src/tspi/ps/tspps.c 2016-04-18 13:55:57.975454990 -0700 @@ -22,6 +22,9 @@ #include #include #include +#ifdef SOLARIS +#include /* mkdirp() */ +#endif #if defined (HAVE_BYTEORDER_H) #include #elif defined(HTOLE_DEFINED) @@ -66,9 +69,12 @@ TSS_RESULT result; char *file_name = NULL, *home_dir = NULL; struct passwd *pwp; -#if (defined (__linux) || defined (linux) || defined(__GLIBC__)) +#if (defined (__linux) || defined (linux) || defined(__GLIBC__) || defined(SOLARIS)) struct passwd pw; #endif +#ifdef SOLARIS + char pwbuf[PASSWD_BUFSIZE]; +#endif struct stat stat_buf; char buf[PASSWD_BUFSIZE]; uid_t euid; @@ -90,9 +96,15 @@ * in the user's home directory, which may be shared * by multiple systems. * - * The directory path on Solaris is /var/tpm/userps/[EUID]/ + * The directory path on Solaris is /var/user/[USERNAME]/tpm/userps */ - rc = snprintf(buf, sizeof (buf), "%s/%d", TSS_USER_PS_DIR, euid); + rc = getpwuid_r(euid, &pw, pwbuf, sizeof (pwbuf), &pwp); + if ((rc != 0) || (pwp == NULL)) { + return TSPERR(TSS_E_INTERNAL_ERROR); + } + rc = snprintf(buf, sizeof (buf), "/var/user/%s/tpm/userps", + pwp->pw_name); + #else setpwent(); while (1) { @@ -138,7 +150,7 @@ if (errno == ENOENT) { errno = 0; /* Create the user's ps directory if it is not there. */ - if ((rc = mkdir(buf, 0700)) == -1) { + if ((rc = mkdirp(buf, 0700)) == -1) { LogDebugFn("USER PS: Error creating dir: %s: %s", buf, strerror(errno)); result = TSPERR(TSS_E_INTERNAL_ERROR); @@ -153,8 +165,8 @@ /* Directory exists or has been created, return the path to the file */ #if defined (SOLARIS) - rc = snprintf(buf, sizeof (buf), "%s/%d/%s", TSS_USER_PS_DIR, euid, - TSS_USER_PS_FILE); + rc = snprintf(buf, sizeof (buf), "/var/user/%s/tpm/userps/%s", + pwp->pw_name, TSS_USER_PS_FILE); #else rc = snprintf(buf, sizeof (buf), "%s/%s/%s", home_dir, TSS_USER_PS_DIR, TSS_USER_PS_FILE);