usr/src/lib/trousers/Patches/ps_utils.c.patch
changeset 10 612517e396e0
parent 0 b34509ac961f
equal deleted inserted replaced
9:502b128296a2 10:612517e396e0
     1 --- src/tcs/ps/ps_utils.c.old	Wed Aug  5 11:44:32 2009
     1 --- src/tcs/ps/ps_utils.c.orig	Tue Sep  8 07:39:30 2009
     2 +++ src/tcs/ps/ps_utils.c	Wed Aug  5 11:51:15 2009
     2 +++ src/tcs/ps/ps_utils.c	Mon Feb  1 06:18:11 2010
     3 @@ -14,6 +14,9 @@
     3 @@ -1,4 +1,3 @@
       
     4 -
       
     5  /*
       
     6   * Licensed Materials - Property of IBM
       
     7   *
       
     8 @@ -14,6 +13,18 @@
     4  #include <unistd.h>
     9  #include <unistd.h>
     5  #include <sys/types.h>
    10  #include <sys/types.h>
     6  #include <sys/stat.h>
    11  #include <sys/stat.h>
     7 +#ifdef SOLARIS
    12 +#if defined(HAVE_BYTEORDER_H)
     8 +#include <sys/byteorder.h>
    13 +#include <sys/byteorder.h>
       
    14 +#elif defined(HAVE_ENDIAN_H)
       
    15 +#include <endian.h>
       
    16 +#define LE_16 htole16
       
    17 +#define LE_32 htole32
       
    18 +#define LE_64 htole64
       
    19 +#else
       
    20 +#define LE_16(x) (x)
       
    21 +#define LE_32(x) (x)
       
    22 +#define LE_64(x) (x)
     9 +#endif
    23 +#endif
    10  #include <fcntl.h>
    24  #include <fcntl.h>
    11  #include <string.h>
    25  #include <string.h>
    12  #include <limits.h>
    26  #include <limits.h>
    13 @@ -160,6 +163,9 @@
    27 @@ -133,6 +144,7 @@
       
    28  
       
    29  	/* read the number of keys */
       
    30  	rc = read(fd, &num_keys, sizeof(UINT32));
       
    31 +	num_keys = LE_32(num_keys);
       
    32  	if (rc == -1) {
       
    33  		LogError("read of %zd bytes: %s", sizeof(UINT32), strerror(errno));
       
    34  		return -1;
       
    35 @@ -160,6 +172,7 @@
    14  			return -1;
    36  			return -1;
    15  		}
    37  		}
    16  
    38  
    17 +#if defined (_BIG_ENDIAN)
    39 +                num_keys = LE_32(num_keys);
    18 +                num_keys = BSWAP_32(num_keys);
       
    19 +#endif
       
    20  		if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
    40  		if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
    21  			LogError("%s", __FUNCTION__);
    41  			LogError("%s", __FUNCTION__);
    22  			return rc;
    42  			return rc;
    23 @@ -168,6 +174,10 @@
    43 @@ -187,7 +200,7 @@
    24  		/* return the offset */
       
    25  		return (TSSPS_NUM_KEYS_OFFSET + sizeof(UINT32));
       
    26  	}
       
    27 +#if defined (_BIG_ENDIAN)
       
    28 +        else
       
    29 +                num_keys = BSWAP_32(num_keys);
       
    30 +#endif
       
    31  
       
    32  	/* if there is a hole in the file we can write to, find it */
       
    33  	offset = find_write_offset(pub_data_size, blob_size, vendor_data_size);
       
    34 @@ -187,7 +197,9 @@
       
    35  			LogError("lseek: %s", strerror(errno));
    44  			LogError("lseek: %s", strerror(errno));
    36  			return -1;
    45  			return -1;
    37  		}
    46  		}
    38 -
    47 -
    39 +#if defined(_BIG_ENDIAN)
    48 +                num_keys = LE_32(num_keys);
    40 +                num_keys = BSWAP_32(num_keys);
       
    41 +#endif
       
    42  		if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
    49  		if ((rc = write_data(fd, &num_keys, sizeof(UINT32)))) {
    43  			LogError("%s", __FUNCTION__);
    50  			LogError("%s", __FUNCTION__);
    44  			return rc;
    51  			return rc;
    45 @@ -274,6 +286,9 @@
    52 @@ -274,6 +287,7 @@
    46  	} else if ((unsigned)rc < sizeof(UINT32)) {
    53  	} else if ((unsigned)rc < sizeof(UINT32)) {
    47  		num_keys = 0;
    54  		num_keys = 0;
    48  	}
    55  	}
    49 +#if defined(_BIG_ENDIAN)
    56 +        num_keys = LE_32(num_keys);
    50 +        num_keys = BSWAP_32(num_keys);
       
    51 +#endif
       
    52  
    57  
    53  	return num_keys;
    58  	return num_keys;
    54  }
    59  }
    55 @@ -403,6 +418,9 @@
    60 @@ -403,6 +417,7 @@
    56  			LogError("%s", __FUNCTION__);
    61  			LogError("%s", __FUNCTION__);
    57  			goto err_exit;
    62  			goto err_exit;
    58  		}
    63  		}
    59 +#if defined(_BIG_ENDIAN)
    64 +                tmp->pub_data_size = LE_16(tmp->pub_data_size);
    60 +                tmp->pub_data_size = BSWAP_16(tmp->pub_data_size);
       
    61 +#endif
       
    62  
    65  
    63  		DBG_ASSERT(tmp->pub_data_size <= 2048 && tmp->pub_data_size > 0);
    66  		DBG_ASSERT(tmp->pub_data_size <= 2048 && tmp->pub_data_size > 0);
    64  
    67  
    65 @@ -411,7 +429,9 @@
    68 @@ -411,7 +426,7 @@
    66  			LogError("%s", __FUNCTION__);
    69  			LogError("%s", __FUNCTION__);
    67  			goto err_exit;
    70  			goto err_exit;
    68  		}
    71  		}
    69 -
    72 -
    70 +#if defined(_BIG_ENDIAN)
    73 +                tmp->blob_size = LE_16(tmp->blob_size);
    71 +                tmp->blob_size = BSWAP_16(tmp->blob_size);
       
    72 +#endif
       
    73  		DBG_ASSERT(tmp->blob_size <= 4096 && tmp->blob_size > 0);
    74  		DBG_ASSERT(tmp->blob_size <= 4096 && tmp->blob_size > 0);
    74  
    75  
    75  		/* vendor data size */
    76  		/* vendor data size */
    76 @@ -419,6 +439,9 @@
    77 @@ -419,6 +434,7 @@
    77  			LogError("%s", __FUNCTION__);
    78  			LogError("%s", __FUNCTION__);
    78  			goto err_exit;
    79  			goto err_exit;
    79  		}
    80  		}
    80 +#if defined(_BIG_ENDIAN)
    81 +                tmp->vendor_data_size = LE_32(tmp->vendor_data_size);
    81 +                tmp->vendor_data_size = BSWAP_32(tmp->vendor_data_size);
       
    82 +#endif
       
    83  
    82  
    84  		/* cache flags */
    83  		/* cache flags */
    85  		if ((rc = read_data(fd, &tmp->flags, sizeof(UINT16)))) {
    84  		if ((rc = read_data(fd, &tmp->flags, sizeof(UINT16)))) {
    86 @@ -425,6 +448,9 @@
    85 @@ -425,6 +441,7 @@
    87  			LogError("%s", __FUNCTION__);
    86  			LogError("%s", __FUNCTION__);
    88  			goto err_exit;
    87  			goto err_exit;
    89  		}
    88  		}
    90 +#if defined(_BIG_ENDIAN)
    89 +                tmp->flags = LE_16(tmp->flags);
    91 +                tmp->flags = BSWAP_16(tmp->flags);
       
    92 +#endif
       
    93  
    90  
    94  #ifdef TSS_DEBUG
    91  #ifdef TSS_DEBUG
    95  		if (tmp->flags & CACHE_FLAG_VALID)
    92  		if (tmp->flags & CACHE_FLAG_VALID)