-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quoted passwords #13
base: master
Are you sure you want to change the base?
Quoted passwords #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password """" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""multi-word password"" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "multi-word password", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""multi-word password"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unescape \\ backslash"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "unescape \\ backslash", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unescape \\ backslash"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unescape \" quote"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "unescape \" quote", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unescape \" quote"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unclosed-double-quotes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "\"\"unclosed-double-quotes", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""unclosed-double-quotes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""password with # comment"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "password with # comment", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password ""password with # comment"" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password "single # quote should be treated as normal password" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Right (NetRc {nrHosts = [NetRcHost {nrhName = "", nrhLogin = "abc", nrhPassword = "\"single", nrhAccount = "", nrhMacros = []}], nrMacros = []}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default login abc password "single |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ | |
-- and after @machine@\/@default@\/@macdef@ entries. Be aware though | ||
-- that such @#@-comment are not supported by all @.netrc@-aware | ||
-- applications, including @ftp(1)@. | ||
-- | ||
-- Passwords can contain spaces only if they are double-quoted, in which | ||
-- case backslashes and quotes are to be escaped with a preceding backslash. | ||
|
||
module Network.NetRc | ||
( -- * Types | ||
NetRc(..) | ||
|
@@ -128,7 +132,19 @@ netRcToBuilder (NetRc ms ds) = | |
| otherwise = BB.byteString "machine" <> spc <> BB.byteString nrhName | ||
|
||
prop lab val | B.null val = mempty | ||
| otherwise = spc <> BB.byteString lab <> spc <> BB.byteString val | ||
| otherwise = spc <> BB.byteString lab <> spc <> valString lab val | ||
|
||
valString "password" val | ||
| BC.elem ' ' val || BC.elem '\t' val | ||
= BB.byteString "\"\"" | ||
<> BB.byteString (BC.concatMap (BC.pack . escape) val) | ||
<> BB.byteString "\"\"" | ||
| otherwise = BB.byteString val | ||
where | ||
escape '\\' = "\\\\" | ||
escape '\"' = "\\\"" | ||
escape x = [ x ] | ||
valString _ val = BB.byteString val | ||
|
||
netRcMacDefToBuilder (NetRcMacDef {..}) | ||
= BB.byteString "macdef" <> spc <> BB.byteString nrmName <> | ||
|
@@ -238,10 +254,14 @@ hostEnt = do | |
-- pval := ((account|username|password) WS+ <value>) | ||
pval = hlp "login" PValLogin <|> | ||
hlp "account" PValAccount <|> | ||
hlp "password" PValPassword | ||
hlpPassword | ||
where | ||
hlp tnam cons = P.try (P.string tnam) *> wsChars1 *> | ||
(cons <$> tok P.<?> (tnam ++ "-value")) | ||
hlpPassword = P.try (P.string "password") *> wsChars1 *> | ||
(PValPassword <$> password P.<?> "password-value") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to parametrize |
||
password = P.try quotedPassword <|> tok | ||
|
||
|
||
setFld n (PValLogin v) = n { nrhLogin = v } | ||
setFld n (PValAccount v) = n { nrhAccount = v } | ||
|
@@ -250,6 +270,14 @@ hostEnt = do | |
tok :: P.Parser ByteString | ||
tok = BC.pack <$> P.many1 notWsChar P.<?> "token" | ||
|
||
quotedPassword :: P.Parser ByteString | ||
quotedPassword = do | ||
BC.pack <$> (P.string "\"\"" *> P.many chars <* P.string "\"\"") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thing this should be |
||
where | ||
chars = escaped <|> P.noneOf "\"" | ||
escaped = P.char '\\' >> P.choice [ P.char '\\' >> return '\\' | ||
, P.char '"' >> return '"' ] | ||
|
||
data PVal = PValLogin !ByteString | ||
| PValAccount !ByteString | ||
| PValPassword !ByteString | ||
|
@@ -288,3 +316,4 @@ splitEithers = goL | |
isLeft (Right _) = False | ||
|
||
isRight = not . isLeft | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
"multi-word password"
, like a string in double-quotes?Now it is double double-quotes...