Coder Social home page Coder Social logo

nsscache-go's Introduction

nsscache-go

GoDoc Build Status Coverage Status

Implementation of nsscache in Go. The main goal of this library is too allow to write easily new program which can populate the nsscache files from not yet supported sources or to use your custom logic to generate those cache files.

Running the test

To run the test against libnss-cache, you need to have docker installer, and build the test image.

cd docker
docker build -t nsscache-go:latest .

See

nsscache-go's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nsscache-go's Issues

Indexes are not generated

This library is pretty good so far for my use cases, but it doesn't seem to generate the indexes that are specified in the libnss-cache documentation. I can PR in this functionality if you'd like, or you can use the functions I've provided below which can be used to generate the indexes.

func genIndex(lines []string, indexCol int) map[string]int {
	iMap := make(map[string]int)
	offset := 0

	for _, l := range lines {
		key := strings.Split(l, ":")[indexCol]
		iMap[key] = offset
		offset += len(l) + 1
	}
	return iMap
}

func writeIndex(index map[string]int, location string) error {
	keyList := []string{}
	for k := range index {
		keyList = append(keyList, k)
	}

	sort.Strings(keyList)

	var b bytes.Buffer
	for _, key := range keyList {
		value := index[key]
		fmt.Fprintf(&b, "%s", key)
		fmt.Fprintf(&b, "\x00")
		fmt.Fprintf(&b, "%08d", int64(value))
		for i := 0; i < 32-len(key)-1; i++ {
			fmt.Fprint(&b, "\x00")
		}
		fmt.Fprintf(&b, "\n")
	}
	return ioutil.WriteFile(location, b.Bytes(), 0644)
}

Four indexes in total need to be generated, two each for passwd and group, each by both the string representation and the number. The reason this works right now is that if the indexes aren't present libnss-cache will fall back to trying a linear search through the maps, but this will fail for maps beyond a certain size.

Release 0.1.0

I'd like to use this library to replace the hacky string processing in NetAuth/nsscache, but to do that, I'd feel much comfortable if I could lock to a particular release of this library. Would you consider releasing 0.1 to facilitate this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.