I'm trying to add index support to
github.com/MiLk/nsscache-go and I've managed to psych myself out that the format I'm writing is wrong. Currently for the following cache:
entity10:x:2010:2000::/tmp/entity10:/bin/sh
entity9:x:2009:2000::/tmp/entity9:/bin/sh
dummy1:x:2000:2000::/tmp/dummy1:/bin/sh
entity6:x:2006:2000::/tmp/entity6:/bin/sh
entity7:x:2007:2000::/tmp/entity7:/bin/sh
entity8:x:2008:2000::/tmp/entity8:/bin/sh
entity1:x:2001:2000::/tmp/entity1:/bin/sh
entity2:x:2002:2000::/tmp/entity2:/bin/sh
entity3:x:2003:2000::/tmp/entity3:/bin/sh
entity4:x:2004:2000::/tmp/entity4:/bin/sh
entity5:x:2005:2000::/tmp/entity5:/bin/sh
I would generate the following index:
dummy100000087
entity100000253
entity1000000001
entity200000295
entity300000337
entity400000379
entity500000421
entity600000127
entity700000169
entity800000211
entity900000045
These values are off by one as far as I can tell from the nsscache implementation Google provides, but I cannot figure out why. To the best of my understanding, the number that comes after the key in the index should be piped to fseek() by line 159 of nss_cache.c. So from my perspective, I think I should be able to do something like "tail -c +$OFFSET passwd.cache" to see what the line is that should be read, as that should advance the cursor to where libnss-cache would commence reading from. This is not, however, how the nsscache implementation in python does it, and when I ported the index generation somewhat blindly to Go about a year ago I added the addition of the 1 there as well. This doesn't seem right though, and I have the suspicioun that the indexes are being ignored and libnss-cache is falling back to a linear search.
Some explanation on what the index file format actually is would be very nice, and even nicer would be why it appears to be designed with a built in off by one error.
Thanks in advance!