summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-06-08 13:48:03 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-06-08 13:48:03 -0400
commit4db8f408e025a58ba272f55c8a8373f68bdcb16b (patch)
tree6b51270a334b3adc03bdc75144d8fba9f2014357
parent38da42a980fe460b9e821f4e48b81b639e439406 (diff)
Avoid a crash if getpwuid does not work, when querying the user's full name.
-rw-r--r--CHANGELOG2
-rw-r--r--Utility/UserInfo.hs3
-rw-r--r--doc/forum/git-annex__58___getUserEntryForID__58___does_not_exist___40__no_such_user__41___/comment_1_94d92b7e64ad31db8837dcf3d131cf23._comment28
3 files changed, 32 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 79f07ba61..b9c7792c0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,8 @@ git-annex (6.20160528) UNRELEASED; urgency=medium
drop content from disk before writing location log.
* Fix bad automatic merge conflict resolution between an annexed file
and a directory with the same name when in an adjusted branch.
+ * Avoid a crash if getpwuid does not work, when querying the user's full
+ name.
-- Joey Hess <id@joeyh.name> Fri, 27 May 2016 13:12:48 -0400
diff --git a/Utility/UserInfo.hs b/Utility/UserInfo.hs
index c6010116e..c2edde24e 100644
--- a/Utility/UserInfo.hs
+++ b/Utility/UserInfo.hs
@@ -15,6 +15,7 @@ module Utility.UserInfo (
) where
import Utility.Env
+import Utility.Exception
import System.PosixCompat
import Control.Applicative
@@ -47,7 +48,7 @@ myUserGecos :: IO (Maybe String)
#if defined(__ANDROID__) || defined(mingw32_HOST_OS)
myUserGecos = return Nothing
#else
-myUserGecos = Just <$> myVal [] userGecos
+myUserGecos = catchMaybeIO $ myVal [] userGecos
#endif
myVal :: [String] -> (UserEntry -> String) -> IO String
diff --git a/doc/forum/git-annex__58___getUserEntryForID__58___does_not_exist___40__no_such_user__41___/comment_1_94d92b7e64ad31db8837dcf3d131cf23._comment b/doc/forum/git-annex__58___getUserEntryForID__58___does_not_exist___40__no_such_user__41___/comment_1_94d92b7e64ad31db8837dcf3d131cf23._comment
new file mode 100644
index 000000000..a72c67ea6
--- /dev/null
+++ b/doc/forum/git-annex__58___getUserEntryForID__58___does_not_exist___40__no_such_user__41___/comment_1_94d92b7e64ad31db8837dcf3d131cf23._comment
@@ -0,0 +1,28 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2016-06-08T17:31:41Z"
+ content="""
+IIRC it's supposed to be possible to configure a system such as LDAP
+so that `getpwuid` queries it, instead of failing as it seems to on your
+system, using `/etc/nsswitch.conf`. But I'm not sure about that or how to
+do it and you'd need to be the admin of the system.
+
+git-annex has three calls to `getpwuid` (aka getUserEntryForID`).
+In two of them it first looks at commonly set environment variables
+(HOME and USER/LOGNAME) and only uses `getpwuid` as a fallback.
+It seems reasonable to crash when git-annex can't determine the user's home
+directory or username in code that needs it, especially since all three
+environment variables are almost always going to be set.
+
+The third use is a GECOS lookup, and here there's no corresponding
+environment variable and git-annex can deal without knowing the full name
+of the user. So, I've made that not crash if `getpwuid` fails.
+
+(There's also a little-used code path where `getpwnam` is used
+to expand `~` in a git remote path. Seems best to leave this crashing
+too if used on a system that does not have a working `getpwnam`.)
+
+So, you can try upgrading to an autobuild that has the fix, and if it still
+crashes, check that HOME and USER are set.
+"""]]