2012-03-15 16:00:19 +00:00
|
|
|
{- git-annex-shell main program
|
|
|
|
-
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
- Copyright 2010-2024 Joey Hess <id@joeyh.name>
|
2012-03-15 16:00:19 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-03-15 16:00:19 +00:00
|
|
|
-}
|
|
|
|
|
2014-01-26 20:25:55 +00:00
|
|
|
module CmdLine.GitAnnexShell where
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2012-03-15 16:00:19 +00:00
|
|
|
import qualified Git.Construct
|
2015-03-06 01:45:42 +00:00
|
|
|
import qualified Git.Config
|
2012-03-15 16:00:19 +00:00
|
|
|
import CmdLine
|
2022-06-29 17:28:08 +00:00
|
|
|
import CmdLine.AnnexSetter
|
2012-03-15 16:00:19 +00:00
|
|
|
import Command
|
|
|
|
import Annex.UUID
|
2015-08-05 18:09:25 +00:00
|
|
|
import CmdLine.GitAnnexShell.Checks
|
2014-01-26 20:32:55 +00:00
|
|
|
import CmdLine.GitAnnexShell.Fields
|
2013-09-24 21:25:47 +00:00
|
|
|
import Remote.GCrypt (getGCryptUUID)
|
2018-05-25 17:17:56 +00:00
|
|
|
import P2P.Protocol (ServerMode(..))
|
2023-09-07 18:36:16 +00:00
|
|
|
import Git.Types
|
2024-07-25 17:15:05 +00:00
|
|
|
import Annex.Proxy
|
2012-03-15 16:00:19 +00:00
|
|
|
|
|
|
|
import qualified Command.ConfigList
|
2014-04-05 20:04:37 +00:00
|
|
|
import qualified Command.NotifyChanges
|
2013-10-01 21:20:51 +00:00
|
|
|
import qualified Command.GCryptSetup
|
2018-03-07 19:15:23 +00:00
|
|
|
import qualified Command.P2PStdIO
|
remove git-annex-shell compat code
* Removed support for accessing git remotes that use versions of
git-annex older than 6.20180312.
* git-annex-shell: Removed several commands that were only needed to
support git-annex versions older than 6.20180312.
(lockcontent, recvkey, sendkey, transferinfo, commit)
The P2P protocol was added in that version, and used ever since, so
this code was only needed for interop with older versions.
"git-annex-shell commit" is used by newer git-annex versions, though
unnecessarily so, because the p2pstdio command makes a single commit at
shutdown. Luckily, it was run with stderr and stdout sent to /dev/null,
and non-zero exit status or other exceptions are caught and ignored. So,
that was able to be removed from git-annex-shell too.
git-annex-shell inannex, recvkey, sendkey, and dropkey are still used by
gcrypt special remotes accessed over ssh, so those had to be kept.
It would probably be possible to convert that to using the P2P protocol,
but it would be another multi-year transition.
Some git-annex-shell fields were able to be removed. I hoped to remove
all of them, and the very concept of them, but unfortunately autoinit
is used by git-annex sync, and gcrypt uses remoteuuid.
The main win here is really in Remote.Git, removing piles of hairy fallback
code.
Sponsored-by: Luke Shumaker
2021-10-11 19:35:54 +00:00
|
|
|
import qualified Command.InAnnex
|
|
|
|
import qualified Command.RecvKey
|
|
|
|
import qualified Command.SendKey
|
|
|
|
import qualified Command.DropKey
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2018-05-25 17:17:56 +00:00
|
|
|
import qualified Data.Map as M
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2018-05-25 17:17:56 +00:00
|
|
|
cmdsMap :: M.Map ServerMode [Command]
|
|
|
|
cmdsMap = M.fromList $ map mk
|
|
|
|
[ (ServeReadOnly, readonlycmds)
|
|
|
|
, (ServeAppendOnly, appendcmds)
|
|
|
|
, (ServeReadWrite, allcmds)
|
2018-03-07 19:15:23 +00:00
|
|
|
]
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2022-06-29 17:28:08 +00:00
|
|
|
readonlycmds = map addAnnexOptions
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
[ notProxyable Command.ConfigList.cmd
|
2018-05-25 17:17:56 +00:00
|
|
|
, gitAnnexShellCheck Command.NotifyChanges.cmd
|
2023-03-14 02:39:16 +00:00
|
|
|
-- p2pstdio checks the environment variables to
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
-- determine the security policy to use, so is safe to
|
|
|
|
-- include in the readonly list even though it is not
|
|
|
|
-- always readonly
|
2024-06-11 17:07:04 +00:00
|
|
|
, gitAnnexShellCheck Command.P2PStdIO.cmd
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
, notProxyable (gitAnnexShellCheck Command.InAnnex.cmd)
|
|
|
|
, notProxyable (gitAnnexShellCheck Command.SendKey.cmd)
|
2018-05-25 17:17:56 +00:00
|
|
|
]
|
2022-06-29 17:28:08 +00:00
|
|
|
appendcmds = readonlycmds ++ map addAnnexOptions
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
[ notProxyable (gitAnnexShellCheck Command.RecvKey.cmd)
|
2018-05-25 17:17:56 +00:00
|
|
|
]
|
2022-06-29 17:28:08 +00:00
|
|
|
allcmds = appendcmds ++ map addAnnexOptions
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
[ notProxyable (gitAnnexShellCheck Command.DropKey.cmd)
|
|
|
|
, notProxyable Command.GCryptSetup.cmd
|
2018-05-25 17:17:56 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
mk (s, l) = (s, map (adddirparam . noMessages) l)
|
2012-11-11 04:51:07 +00:00
|
|
|
adddirparam c = c { cmdparamdesc = "DIRECTORY " ++ cmdparamdesc c }
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2018-05-25 17:17:56 +00:00
|
|
|
cmdsFor :: ServerMode -> [Command]
|
|
|
|
cmdsFor = fromMaybe [] . flip M.lookup cmdsMap
|
|
|
|
|
|
|
|
cmdsList :: [Command]
|
2021-10-11 19:39:55 +00:00
|
|
|
cmdsList = nub $ concat $ M.elems cmdsMap
|
2018-05-25 17:17:56 +00:00
|
|
|
|
2022-06-29 17:28:08 +00:00
|
|
|
addAnnexOptions :: Command -> Command
|
|
|
|
addAnnexOptions c = c { cmdannexoptions = commonShellOptions ++ cmdannexoptions c }
|
2021-02-02 19:55:45 +00:00
|
|
|
|
2022-06-29 17:28:08 +00:00
|
|
|
commonShellOptions :: [AnnexOption]
|
|
|
|
commonShellOptions =
|
|
|
|
annexOption (setAnnexState . checkUUID) (strOption
|
2015-07-10 04:55:53 +00:00
|
|
|
( long "uuid" <> metavar paramUUID
|
|
|
|
<> help "local repository uuid"
|
2015-07-10 06:03:03 +00:00
|
|
|
))
|
2022-06-29 17:28:08 +00:00
|
|
|
: commonOptions
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2013-09-24 21:25:47 +00:00
|
|
|
checkUUID expected = getUUID >>= check
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2013-09-24 21:25:47 +00:00
|
|
|
check NoUUID = checkGCryptUUID expected
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
check u
|
|
|
|
| u == toUUID expected = noop
|
|
|
|
| otherwise =
|
2024-07-25 17:15:05 +00:00
|
|
|
unlessM (checkCanProxy (toUUID expected) u) $
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
unexpectedUUID expected u
|
|
|
|
|
2013-09-27 20:21:56 +00:00
|
|
|
checkGCryptUUID expected = check =<< getGCryptUUID True =<< gitRepo
|
2013-09-24 21:25:47 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
check (Just u) | u == toUUID expected = noop
|
2013-09-24 21:25:47 +00:00
|
|
|
check Nothing = unexpected expected "uninitialized repository"
|
|
|
|
check (Just u) = unexpectedUUID expected u
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
|
2013-09-24 21:25:47 +00:00
|
|
|
unexpectedUUID expected u = unexpected expected $ "UUID " ++ fromUUID u
|
2016-11-16 01:29:54 +00:00
|
|
|
unexpected expected s = giveup $
|
2013-09-24 21:25:47 +00:00
|
|
|
"expected repository UUID " ++ expected ++ " but found " ++ s
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
|
2012-03-15 16:00:19 +00:00
|
|
|
|
|
|
|
run :: [String] -> IO ()
|
|
|
|
run [] = failure
|
|
|
|
-- skip leading -c options, passed by eg, ssh
|
|
|
|
run ("-c":p) = run p
|
|
|
|
-- a command can be either a builtin or something to pass to git-shell
|
|
|
|
run c@(cmd:dir:params)
|
|
|
|
| cmd `elem` builtins = builtin cmd dir params
|
|
|
|
| otherwise = external c
|
|
|
|
run c@(cmd:_)
|
|
|
|
-- Handle the case of being the user's login shell. It will be passed
|
|
|
|
-- a single string containing all the real parameters.
|
|
|
|
| "git-annex-shell " `isPrefixOf` cmd = run $ drop 1 $ shellUnEscape cmd
|
|
|
|
| cmd `elem` builtins = failure
|
|
|
|
| otherwise = external c
|
|
|
|
|
git-annex-shell: accept uuid of remote that proxying is enabled for
For NotifyChanges and also for the fallthrough case where
git-annex-shell passes a command off to git-shell, proxying is currently
ignored. So every remote that is accessed via a proxy will be treated as
the same git repository.
Every other command listed in cmdsMap will need to check if
Annex.proxyremote is set, and if so handle the proxying appropriately.
Probably only P2PStdio will need to support proxying. For now,
everything else refuses to work when proxying.
The part of that I don't like is that there's the possibility a command
later gets added to the list that doesn't check proxying.
When proxying is not enabled, it's important that git-annex-shell not
leak information that it would not have exposed before. Such as the
names or uuids of remotes.
I decided that, in the case where a repository used to have proxying
enabled, but no longer supports any proxies, it's ok to give the user a
clear error message indicating that proxying is not configured, rather
than a confusing uuid mismatch message.
Similarly, if a repository has proxying enabled, but not for the
requested repository, give a clear error message.
A tricky thing here is how to handle the case where there is more than
one remote, with proxying enabled, with the specified uuid. One way to
handle that would be to plumb the proxyRemoteName all the way through
from the remote git-annex to git-annex-shell, eg as a field, and use
only a remote with the same name. That would be very intrusive though.
Instead, I decided to let the proxy pick which remote it uses to access
a given Remote. And so it picks the least expensive one.
The client after all doesn't necessarily know any details about the
proxy's configuration. This does mean though, that if the least
expensive remote is not accessible, but another remote would have
worked, an access via the proxy will fail.
2024-06-10 16:05:03 +00:00
|
|
|
failure :: IO ()
|
|
|
|
failure = giveup $ "bad parameters\n\n" ++ usage h cmdsList
|
|
|
|
where
|
|
|
|
h = "git-annex-shell [-c] command [parameters ...] [option ...]"
|
|
|
|
|
2012-03-15 16:00:19 +00:00
|
|
|
builtins :: [String]
|
2018-05-25 17:17:56 +00:00
|
|
|
builtins = map cmdname cmdsList
|
2012-03-15 16:00:19 +00:00
|
|
|
|
|
|
|
builtin :: String -> String -> [String] -> IO ()
|
|
|
|
builtin cmd dir params = do
|
2018-05-25 17:17:56 +00:00
|
|
|
unless (cmd `elem` map cmdname (cmdsFor ServeReadOnly))
|
2015-08-05 18:09:25 +00:00
|
|
|
checkNotReadOnly
|
2018-05-25 17:17:56 +00:00
|
|
|
unless (cmd `elem` map cmdname (cmdsFor ServeAppendOnly))
|
|
|
|
checkNotAppendOnly
|
2012-11-05 15:29:12 +00:00
|
|
|
checkDirectory $ Just dir
|
2013-03-29 00:34:07 +00:00
|
|
|
let (params', fieldparams, opts) = partitionParams params
|
2015-07-08 16:33:27 +00:00
|
|
|
rsyncopts = ("RsyncOptions", unwords opts)
|
|
|
|
fields = rsyncopts : filter checkField (parseFields fieldparams)
|
addon commands
Seems only fair, that, like git runs git-annex, git-annex runs
git-annex-foo.
Implementation relies on O.forwardOptions, so that any options are passed
through to the addon program. Note that this includes options before the
subcommand, eg: git-annex -cx=y foo
Unfortunately, git-annex eats the --help/-h options.
This is because it uses O.hsubparser, which injects that option into each
subcommand. Seems like this should be possible to avoid somehow, to let
commands display their own --help, instead of the dummy one git-annex
displays.
The two step searching mirrors how git works, it makes finding
git-annex-foo fast when "git annex foo" is run, but will also support fuzzy
matching, once findAllAddonCommands gets implemented.
This commit was sponsored by Dr. Land Raider on Patreon.
2021-02-02 20:32:25 +00:00
|
|
|
dispatch False False (cmd : params') cmdsList fields mkrepo
|
2015-07-09 15:49:52 +00:00
|
|
|
"git-annex-shell"
|
|
|
|
"Restricted login shell for git-annex only SSH access"
|
2013-03-29 00:34:07 +00:00
|
|
|
where
|
2015-03-06 01:45:42 +00:00
|
|
|
mkrepo = do
|
2020-11-04 18:20:37 +00:00
|
|
|
r <- Git.Construct.repoAbsPath (toRawFilePath dir)
|
|
|
|
>>= Git.Construct.fromAbsPath
|
2023-09-07 18:56:26 +00:00
|
|
|
let r' = r { repoPathSpecifiedExplicitly = True }
|
2023-09-07 18:36:16 +00:00
|
|
|
Git.Config.read r'
|
2015-03-06 01:45:42 +00:00
|
|
|
`catchIO` \_ -> do
|
|
|
|
hn <- fromMaybe "unknown" <$> getHostname
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup $ "failed to read git config of git repository in " ++ hn ++ " on " ++ dir ++ "; perhaps this repository is not set up correctly or has moved"
|
2012-03-15 16:00:19 +00:00
|
|
|
|
|
|
|
external :: [String] -> IO ()
|
|
|
|
external params = do
|
2012-11-05 15:29:12 +00:00
|
|
|
{- Normal git-shell commands all have the directory as their last
|
|
|
|
- parameter. -}
|
2012-11-06 00:15:36 +00:00
|
|
|
let lastparam = lastMaybe =<< shellUnEscape <$> lastMaybe params
|
2013-03-29 00:34:07 +00:00
|
|
|
(params', _, _) = partitionParams params
|
2012-11-06 00:15:36 +00:00
|
|
|
checkDirectory lastparam
|
2012-03-15 16:00:19 +00:00
|
|
|
checkNotLimited
|
2013-03-29 00:34:07 +00:00
|
|
|
unlessM (boolSystem "git-shell" $ map Param $ "-c":params') $
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup "git-shell failed"
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2013-03-29 00:34:07 +00:00
|
|
|
{- Split the input list into 3 groups separated with a double dash --.
|
|
|
|
- Parameters between two -- markers are field settings, in the form:
|
2012-07-02 04:53:00 +00:00
|
|
|
- field=value field=value
|
|
|
|
-
|
2013-03-29 00:34:07 +00:00
|
|
|
- Parameters after the last -- are the command itself and its arguments e.g.,
|
|
|
|
- rsync --bandwidth=100.
|
2012-07-02 04:53:00 +00:00
|
|
|
-}
|
2013-03-29 00:34:07 +00:00
|
|
|
partitionParams :: [String] -> ([String], [String], [String])
|
2012-10-16 05:22:09 +00:00
|
|
|
partitionParams ps = case segment (== "--") ps of
|
2013-03-29 00:34:07 +00:00
|
|
|
params:fieldparams:rest -> ( params, fieldparams, intercalate ["--"] rest )
|
|
|
|
[params] -> (params, [], [])
|
|
|
|
_ -> ([], [], [])
|
2012-07-02 04:53:00 +00:00
|
|
|
|
|
|
|
parseFields :: [String] -> [(String, String)]
|
|
|
|
parseFields = map (separate (== '='))
|
2012-03-15 16:00:19 +00:00
|
|
|
|
2012-07-02 05:31:10 +00:00
|
|
|
{- Only allow known fields to be set, ignore others.
|
|
|
|
- Make sure that field values make sense. -}
|
2012-07-02 15:08:50 +00:00
|
|
|
checkField :: (String, String) -> Bool
|
2015-07-09 23:03:21 +00:00
|
|
|
checkField (field, val)
|
|
|
|
| field == fieldName remoteUUID = fieldCheck remoteUUID val
|
2015-08-05 17:49:54 +00:00
|
|
|
| field == fieldName autoInit = fieldCheck autoInit val
|
2012-07-02 15:08:50 +00:00
|
|
|
| otherwise = False
|