Deal with pkexec changing to root's home directory when running a command.
Wow, that's not documented anywhere, and seems like a major gotcha in pkexec. Broke enable-tor.
This commit is contained in:
parent
93f53cda08
commit
9a5d9019ba
3 changed files with 38 additions and 21 deletions
|
@ -46,18 +46,19 @@ start os = do
|
|||
#else
|
||||
start _os = do
|
||||
#endif
|
||||
uuid <- getUUID
|
||||
when (uuid == NoUUID) $
|
||||
giveup "This can only be run in a git-annex repository."
|
||||
#ifndef mingw32_HOST_OS
|
||||
curruserid <- liftIO getEffectiveUserID
|
||||
if curruserid == 0
|
||||
then case readish =<< headMaybe os of
|
||||
Nothing -> giveup "Need user-id parameter."
|
||||
Just userid -> go uuid userid
|
||||
then case os of
|
||||
(uid:[]) -> go uid
|
||||
(uid:repodir:_) -> do
|
||||
Annex.changeDirectory repodir
|
||||
go uid
|
||||
_ -> giveup "Need user-id parameter."
|
||||
else starting "enable-tor" (ActionItemOther Nothing) $ do
|
||||
gitannex <- liftIO readProgramFile
|
||||
let ps = [Param (cmdname cmd), Param (show curruserid)]
|
||||
cwd <- liftIO getCurrentDirectory
|
||||
let ps = [Param (cmdname cmd), Param (show curruserid), Param cwd]
|
||||
sucommand <- liftIO $ mkSuCommand gitannex ps
|
||||
maybe noop showLongNote
|
||||
(describePasswordPrompt' sucommand)
|
||||
|
@ -67,14 +68,19 @@ start _os = do
|
|||
[ "Failed to run as root:" , gitannex ] ++ toCommand ps
|
||||
)
|
||||
#else
|
||||
go uuid 0
|
||||
go "0"
|
||||
#endif
|
||||
where
|
||||
go uuid userid = do
|
||||
(onionaddr, onionport) <- liftIO $
|
||||
addHiddenService torAppName userid (fromUUID uuid)
|
||||
storeP2PAddress $ TorAnnex onionaddr onionport
|
||||
stop
|
||||
go suserid = case readish suserid of
|
||||
Nothing -> giveup "Unable to parse user-id parameter."
|
||||
Just userid -> do
|
||||
uuid <- getUUID
|
||||
when (uuid == NoUUID) $
|
||||
giveup "This can only be run in a git-annex repository."
|
||||
(onionaddr, onionport) <- liftIO $
|
||||
addHiddenService torAppName userid (fromUUID uuid)
|
||||
storeP2PAddress $ TorAnnex onionaddr onionport
|
||||
stop
|
||||
|
||||
checkHiddenService :: CommandCleanup
|
||||
checkHiddenService = bracket setup cleanup go
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue