forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osutil: unify osutil.Find{Uid,Gid} with automatic getent fallback
The fact that osutil.Find{Uid,Gid} was behaving differently depending on if it is build with cgo or not is confusing. So instead of providing Find{Uid,Gid}Getent() unify this into a single function that automatically falls back to getent if we build without cgo.
- Loading branch information
Showing
5 changed files
with
102 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
// +build cgo | ||
|
||
/* | ||
* Copyright (C) 2017-2019 Canonical Ltd | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package osutil | ||
|
||
// The builtin os/user functions use the libc functions when compiled | ||
// with cgo so we use use them here. | ||
|
||
var ( | ||
findUid = findUidNoGetentFallback | ||
findGid = findGidNoGetentFallback | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// -*- Mode: Go; indent-tabs-mode: t -*- | ||
// +build !cgo | ||
|
||
package osutil | ||
|
||
// The builtin os/user functions only look at /etc/passwd and | ||
// /etc/group when building without cgo. | ||
// | ||
// So nothing configured via nsswitch.conf, like extrausers. findUid() | ||
// and findGid() is searched. To fix this behavior we use | ||
// find{Uid,Gid}WithGetentFallback() that perform a 'getent | ||
// <database> <name>' automatically if no local user is found. | ||
|
||
var ( | ||
findUid = findUidWithGetentFallback | ||
findGid = findGidWithGetentFallback | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters