Home Download Docs Code Community
     1	// +build !nocgo
     2	
     3	/*
     4	Copyright 2016 The Perkeep Authors.
     5	
     6	Licensed under the Apache License, Version 2.0 (the "License");
     7	you may not use this file except in compliance with the License.
     8	You may obtain a copy of the License at
     9	
    10	     http://www.apache.org/licenses/LICENSE-2.0
    11	
    12	Unless required by applicable law or agreed to in writing, software
    13	distributed under the License is distributed on an "AS IS" BASIS,
    14	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15	See the License for the specific language governing permissions and
    16	limitations under the License.
    17	*/
    18	
    19	package schema
    20	
    21	import (
    22		"os/user"
    23		"strconv"
    24	)
    25	
    26	func lookupUserToId(name string) (uid int, ok bool) {
    27		u, err := user.Lookup(name)
    28		if err == nil {
    29			uid, err := strconv.Atoi(u.Uid)
    30			if err == nil {
    31				return uid, true
    32			}
    33		}
    34		return
    35	}
    36	
    37	// lookupMu is held
    38	func lookupUserid(id int) string {
    39		u, err := user.LookupId(strconv.Itoa(id))
    40		if err == nil {
    41			return u.Username
    42		}
    43		if _, ok := err.(user.UnknownUserIdError); ok {
    44			return ""
    45		}
    46		if parsedPasswd {
    47			return ""
    48		}
    49		parsedPasswd = true
    50		populateMap(uidName, nil, "/etc/passwd")
    51		return uidName[id]
    52	}
Website layout inspired by memcached.
Content by the authors.