Permalink
Browse files

Merge pull request #9 from deian/no-user-ok

work with public pulls/clones
  • Loading branch information...
2 parents 5d77f4e + fd492ae commit ec2b722c1049df2649b5986ad4ff2c72449e1b1b @deian deian committed May 11, 2012
Showing with 20 additions and 9 deletions.
  1. +1 −1 gitstar-ssh.cabal
  2. +19 −8 gitstarSsh.hs
View
@@ -1,5 +1,5 @@
Name: gitstar-ssh
-Version: 0.1
+Version: 0.1.2
build-type: Simple
License: GPL-2
License-File: LICENSE
View
@@ -160,14 +160,19 @@ checkReadAccess owner pName = do
| otherwise -> True
Nothing -> False
cs <- lookup "collaborators" p
- return $ isPub || usr `elem` o:(rs ++ cs)
+ let readerOrCollab = usr `elem` o:(rs ++ cs)
+ return $ isPub || if usr == anonymous
+ then False
+ else readerOrCollab
-- | Very current user has write access to @/owner/pName@.
checkWriteAccess :: String -> String -> Channel Bool
checkWriteAccess owner pName = do
usr <- gets csUser
- mp <- liftIO $ getProject owner pName
- return $ fromMaybe False $ isWriter usr mp
+ if usr == anonymous
+ then return False -- Anonymous cannot write
+ else do mp <- liftIO $ getProject owner pName
+ return $ fromMaybe False $ isWriter usr mp
where isWriter usr mp = do
p <- mp
o <- lookup "owner" p
@@ -206,15 +211,21 @@ bsonDocFromBody resp = do
sshAuthorize :: Authorize -> Session Bool
sshAuthorize (PublicKey uName key) = liftIO $ do
hPutStr stderr $ "Authenticating " ++ uName ++ "..."
- verifyOk <- verifyUserKey uName key
- if verifyOk
- then hPutStrLn stderr "OK!"
- else hPutStrLn stderr "FAILED!"
- return verifyOk
+ if uName == anonymous
+ then hPutStrLn stderr "" >> return True
+ else do verifyOk <- verifyUserKey uName key
+ if verifyOk
+ then hPutStrLn stderr "OK!"
+ else hPutStrLn stderr "FAILED!"
+ return verifyOk
sshAuthorize _ = do
liftIO $ hPutStrLn stderr "Expected public-key authentication."
return False
+-- | Anonymous user can read public repos
+anonymous :: String
+anonymous = "anonymous"
+
-- | Find a user based and verify their public key.
verifyUserKey :: String -> PublicKey -> IO Bool
verifyUserKey uName key = do

0 comments on commit ec2b722

Please sign in to comment.