nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 */ 00004 #ifdef HAVE_CONFIG_H 00005 #include "config.h" 00006 #endif 00007 00008 #ifdef _SOLARIS 00009 #include "solaris_port.h" 00010 #endif 00011 00012 #include <stdio.h> 00013 #include <string.h> 00014 #include <pthread.h> 00015 #include <fcntl.h> 00016 #include <sys/file.h> /* for having FNDELAY */ 00017 #include <sys/resource.h> /* for having setrlimit */ 00018 #include <signal.h> /* for sigaction */ 00019 #include "log.h" 00020 #include "ganesha_rpc.h" 00021 #include "fsal.h" 00022 #include "nfs23.h" 00023 #include "nfs4.h" 00024 #include "mount.h" 00025 #include "nfs_core.h" 00026 #include "cache_inode.h" 00027 #include "nfs_file_handle.h" 00028 #include "nfs_exports.h" 00029 #include "nfs_tools.h" 00030 #include "nfs_proto_functions.h" 00031 #include "nfs_dupreq.h" 00032 #include "config_parsing.h" 00033 #include "SemN.h" 00034 00035 int idmap_computer_hash_value(char *name, uint32_t * phashval) 00036 { 00037 char padded_name[PWENT_MAX_LEN+8]; /* +8 to avoid array bounds overflow */ 00038 uint32_t computed_value = 0; 00039 unsigned int i = 0; 00040 unsigned int offset = 0; 00041 uint64_t extract = 0; 00042 uint64_t sum = 0; 00043 uint64_t i1; 00044 uint64_t i2; 00045 uint64_t i3; 00046 uint64_t i4; 00047 uint64_t i5; 00048 uint64_t i6; 00049 uint64_t i7; 00050 uint64_t i8; 00051 uint64_t l; 00052 00053 if(name == NULL || phashval == NULL) 00054 return CLIENT_ID_INVALID_ARGUMENT; 00055 00056 memset(padded_name, 0, PWENT_MAX_LEN+8); 00057 00058 /* Copy the string to the padded one */ 00059 for(i = 0; i < strnlen(name, PWENT_MAX_LEN); padded_name[i] = name[i], i++) ; 00060 00061 LogTest("%s ", padded_name); 00062 00063 /* For each 9 character pack: 00064 * - keep the 7 first bit (the 8th is often 0: ascii string) 00065 * - pack 7x9 bit to 63 bits using xor 00066 * - xor the last 8th bit to a single 0 , or-ed with the rest 00067 * Proceeding with the next 9 bytes pack will produce a new value that is xored with the 00068 * one of the previous iteration */ 00069 00070 for(offset = 0; offset < PWENT_MAX_LEN; offset += 8) 00071 { 00072 /* input name is ascii string, remove 8th bit on each byte, not significant */ 00073 i1 = padded_name[offset + 0]; 00074 i2 = (padded_name[offset + 1]) << 8; 00075 i3 = (padded_name[offset + 2]) << 16; 00076 i4 = (padded_name[offset + 3]) << 24; 00077 i5 = (padded_name[offset + 4]) << 32; 00078 i6 = (padded_name[offset + 5]) << 40; 00079 i7 = (padded_name[offset + 6]) << 48; 00080 i8 = (padded_name[offset + 7]) << 56; 00081 00082 sum = (uint64_t) padded_name[offset + 0] + 00083 (uint64_t) padded_name[offset + 1] + 00084 (uint64_t) padded_name[offset + 2] + 00085 (uint64_t) padded_name[offset + 3] + 00086 (uint64_t) padded_name[offset + 4] + 00087 (uint64_t) padded_name[offset + 5] + 00088 (uint64_t) padded_name[offset + 6] + (uint64_t) padded_name[offset + 7]; 00089 00090 00091 LogTest("|%llx |%llx |%llx |%llx |%llx |%llx |%llx |%llx |%llx | = ", 00092 i1, i2, i3, i4, i5, i6, i7, i8); 00093 00094 /* Get xor combibation of all the 8h bit */ 00095 l = (padded_name[offset + 0]) ^ 00096 (padded_name[offset + 1]) ^ 00097 (padded_name[offset + 2]) ^ 00098 (padded_name[offset + 3]) ^ 00099 (padded_name[offset + 4]) ^ 00100 (padded_name[offset + 5]) ^ 00101 (padded_name[offset + 6]) ^ (padded_name[offset + 7]); 00102 00103 extract = i1 ^ i2 ^ i3 ^ i4 ^ i5 ^ i6 ^ i7 ^ i8 | l; 00104 00105 LogTest("%llx ", extract); 00106 00107 computed_value ^= extract; 00108 computed_value ^= sum; 00109 00110 LogTest(",%x\n ", computed_value); 00111 } 00112 00113 if(computed_value > 0x00000000FFFFFFFFLL) 00114 computed_value = (computed_value >> 32) ^ (computed_value & 0x00000000FFFFFFFFLL); 00115 00116 LogTest("===>%x", computed_value); 00117 00118 *phashval = computed_value; 00119 00120 return CLIENT_ID_SUCCESS; 00121 } /* idmap_computer_hash_value */ 00122 00123 main(int argc, char *argv[]) 00124 { 00125 SetDefaultLogging("TEST"); 00126 SetNamePgm("test"); 00127 00128 char name[30]; 00129 uint32_t valeur; 00130 int i; 00131 00132 if(argc == 1) 00133 exit(0); 00134 00135 for(i = 1; i < argc; i++) 00136 { 00137 strncpy(name, argv[i], 30); 00138 00139 idmap_computer_hash_value(name, &valeur); 00140 LogTest("%s %x", name, valeur); 00141 } 00142 }