Kaydet (Commit) ebaf1046 authored tarafından Guido van Rossum's avatar Guido van Rossum

don't show print passwords in debug output

üst b1c1315b
...@@ -95,7 +95,8 @@ class FTP: ...@@ -95,7 +95,8 @@ class FTP:
# Get the welcome message from the server # Get the welcome message from the server
# (this is read and squirreled away by connect()) # (this is read and squirreled away by connect())
def getwelcome(self): def getwelcome(self):
if self.debugging: print '*welcome*', `self.welcome` if self.debugging:
print '*welcome*', self.sanitize(self.welcome)
return self.welcome return self.welcome
# Set the debugging level. Argument level means: # Set the debugging level. Argument level means:
...@@ -106,15 +107,24 @@ class FTP: ...@@ -106,15 +107,24 @@ class FTP:
self.debugging = level self.debugging = level
debug = set_debuglevel debug = set_debuglevel
# Internal: "sanitize" a string for printing
def sanitize(self, s):
if s[:5] == 'pass ' or s[:5] == 'PASS ':
i = len(s)
while i > 5 and s[i-1] in '\r\n':
i = i-1
s = s[:5] + '*'*(i-5) + s[i:]
return `s`
# Internal: send one line to the server, appending CRLF # Internal: send one line to the server, appending CRLF
def putline(self, line): def putline(self, line):
line = line + CRLF line = line + CRLF
if self.debugging > 1: print '*put*', `line` if self.debugging > 1: print '*put*', self.sanitize(line)
self.sock.send(line) self.sock.send(line)
# Internal: send one command to the server (through putline()) # Internal: send one command to the server (through putline())
def putcmd(self, line): def putcmd(self, line):
if self.debugging: print '*cmd*', `line` if self.debugging: print '*cmd*', self.sanitize(line)
self.putline(line) self.putline(line)
# Internal: return one line from the server, stripping CRLF. # Internal: return one line from the server, stripping CRLF.
...@@ -122,7 +132,7 @@ class FTP: ...@@ -122,7 +132,7 @@ class FTP:
def getline(self): def getline(self):
line = self.file.readline() line = self.file.readline()
if self.debugging > 1: if self.debugging > 1:
print '*get*', `line` print '*get*', self.sanitize(line)
if not line: raise EOFError if not line: raise EOFError
if line[-2:] == CRLF: line = line[:-2] if line[-2:] == CRLF: line = line[:-2]
elif line[-1:] in CRLF: line = line[:-1] elif line[-1:] in CRLF: line = line[:-1]
...@@ -148,7 +158,7 @@ class FTP: ...@@ -148,7 +158,7 @@ class FTP:
# Raise various errors if the response indicates an error # Raise various errors if the response indicates an error
def getresp(self): def getresp(self):
resp = self.getmultiline() resp = self.getmultiline()
if self.debugging: print '*resp*', `resp` if self.debugging: print '*resp*', self.sanitize(resp)
self.lastresp = resp[:3] self.lastresp = resp[:3]
c = resp[:1] c = resp[:1]
if c == '4': if c == '4':
...@@ -171,7 +181,7 @@ class FTP: ...@@ -171,7 +181,7 @@ class FTP:
# tried. Instead, just send the ABOR command as OOB data. # tried. Instead, just send the ABOR command as OOB data.
def abort(self): def abort(self):
line = 'ABOR' + CRLF line = 'ABOR' + CRLF
if self.debugging > 1: print '*put urgent*', `line` if self.debugging > 1: print '*put urgent*', self.sanitize(line)
self.sock.send(line, MSG_OOB) self.sock.send(line, MSG_OOB)
resp = self.getmultiline() resp = self.getmultiline()
if resp[:3] not in ('426', '226'): if resp[:3] not in ('426', '226'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment