user/shadow.go
func (*Shadow) lookUp(line string, f field, value interface{}) interface{} {
	_field := f.(shadowField)
	allField := strings.Split(line, ":")
	intField := make(map[int]int)

	// Check integers
	changed, err := parseChange(allField[2])
	if err != nil {
		panic(atoiError{_SHADOW_FILE, line, "changed"})
	}
	if intField[3], err = strconv.Atoi(allField[3]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Min"})
	}
	if intField[4], err = strconv.Atoi(allField[4]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Max"})
	}
	if intField[5], err = strconv.Atoi(allField[5]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Warn"})
	}
	// These fields could be empty.
	if allField[6] != "" {
		if intField[6], err = strconv.Atoi(allField[6]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "Inactive"})
		}
	}
	if allField[7] != "" {
		if intField[7], err = strconv.Atoi(allField[7]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "expire"})
		}
	}
	if allField[8] != "" {
		if intField[8], err = strconv.Atoi(allField[8]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "flag"})
		}
	}

	// Check fields
	var isField bool
	if S_NAME&_field != 0 && allField[0] == value.(string) {
		isField = true
	} else if S_PASSWD&_field != 0 && allField[1] == value.(string) {
		isField = true
	} else if S_CHANGED&_field != 0 && int(changed) == value.(int) {
		isField = true
	} else if S_MIN&_field != 0 && intField[3] == value.(int) {
		isField = true
	} else if S_MAX&_field != 0 && intField[4] == value.(int) {
		isField = true
	} else if S_WARN&_field != 0 && intField[5] == value.(int) {
		isField = true
	} else if S_INACTIVE&_field != 0 && intField[6] == value.(int) {
		isField = true
	} else if S_EXPIRE&_field != 0 && intField[7] == value.(int) {
		isField = true
	} else if S_FLAG&_field != 0 && intField[8] == value.(int) {
		isField = true
	} else if S_ALL&_field != 0 {
		isField = true
	}

	if isField {
		return &Shadow{
			allField[0],
			allField[1],
			changed,
			intField[3],
			intField[4],
			intField[5],
			intField[6],
			intField[7],
			intField[8],
		}
	}
	return nil
}
func (*Shadow) lookUp(line string, f field, value interface{}) interface{} {
	_field := f.(shadowField)
	allField := strings.Split(line, ":")
	intField := make(map[int]int)

	// Check integers
	changed, err := parseChange(allField[2])
	if err != nil {
		panic(atoiError{_SHADOW_FILE, line, "changed"})
	}
	if intField[3], err = strconv.Atoi(allField[3]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Min"})
	}
	if intField[4], err = strconv.Atoi(allField[4]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Max"})
	}
	if intField[5], err = strconv.Atoi(allField[5]); err != nil {
		panic(atoiError{_SHADOW_FILE, line, "Warn"})
	}
	// These fields could be empty.
	if allField[6] != "" {
		if intField[6], err = strconv.Atoi(allField[6]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "Inactive"})
		}
	}
	if allField[7] != "" {
		if intField[7], err = strconv.Atoi(allField[7]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "expire"})
		}
	}
	if allField[8] != "" {
		if intField[8], err = strconv.Atoi(allField[8]); err != nil {
			panic(atoiError{_SHADOW_FILE, line, "flag"})
		}
	}

	// Check fields
	var isField bool
	if S_NAME&_field != 0 && allField[0] == value.(string) {
		isField = true
	} else if S_PASSWD&_field != 0 && allField[1] == value.(string) {
		isField = true
	} else if S_CHANGED&_field != 0 && int(changed) == value.(int) {
		isField = true
	} else if S_MIN&_field != 0 && intField[3] == value.(int) {
		isField = true
	} else if S_MAX&_field != 0 && intField[4] == value.(int) {
		isField = true
	} else if S_WARN&_field != 0 && intField[5] == value.(int) {
		isField = true
	} else if S_INACTIVE&_field != 0 && intField[6] == value.(int) {
		isField = true
	} else if S_EXPIRE&_field != 0 && intField[7] == value.(int) {
		isField = true
	} else if S_FLAG&_field != 0 && intField[8] == value.(int) {
		isField = true
	} else if S_ALL&_field != 0 {
		isField = true
	}

	if isField {
		return &Shadow{
			allField[0],
			allField[1],
			changed,
			intField[3],
			intField[4],
			intField[5],
			intField[6],
			intField[7],
			intField[8],
		}
	}
	return nil
}
func ( * Shadow ) lookUp ( line string , f field , value interface { } ) interface { } { _field := f . ( shadowField ) allField := strings . Split ( line , " " ) intField := make ( map [ int ] int ) // Check integers changed , err := parseChange ( allField [ 2 ] ) if err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } if intField [ 3 ] , err = strconv . Atoi ( allField [ 3 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } if intField [ 4 ] , err = strconv . Atoi ( allField [ 4 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } if intField [ 5 ] , err = strconv . Atoi ( allField [ 5 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } // These fields could be empty. if allField [ 6 ] != " " { if intField [ 6 ] , err = strconv . Atoi ( allField [ 6 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } } if allField [ 7 ] != " " { if intField [ 7 ] , err = strconv . Atoi ( allField [ 7 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } } if allField [ 8 ] != " " { if intField [ 8 ] , err = strconv . Atoi ( allField [ 8 ] ) ; err != nil { panic ( atoiError { _SHADOW_FILE , line , " " } ) } } // Check fields var isField bool if S_NAME & _field != 0 && allField [ 0 ] == value . ( string ) { isField = true } else if S_PASSWD & _field != 0 && allField [ 1 ] == value . ( string ) { isField = true } else if S_CHANGED & _field != 0 && int ( changed ) == value . ( int ) { isField = true } else if S_MIN & _field != 0 && intField [ 3 ] == value . ( int ) { isField = true } else if S_MAX & _field != 0 && intField [ 4 ] == value . ( int ) { isField = true } else if S_WARN & _field != 0 && intField [ 5 ] == value . ( int ) { isField = true } else if S_INACTIVE & _field != 0 && intField [ 6 ] == value . ( int ) { isField = true } else if S_EXPIRE & _field != 0 && intField [ 7 ] == value . ( int ) { isField = true } else if S_FLAG & _field != 0 && intField [ 8 ] == value . ( int ) { isField = true } else if S_ALL & _field != 0 { isField = true } if isField { return & Shadow { allField [ 0 ] , allField [ 1 ] , changed , intField [ 3 ] , intField [ 4 ] , intField [ 5 ] , intField [ 6 ] , intField [ 7 ] , intField [ 8 ] , } } return nil }
// == Lookup
//
// lookUp parses the shadow passwd line searching a value into the field.
// Returns nil if is not found.
== Lookup lookUp parses the shadow passwd line searching a value into the field . Returns nil if is not found .