Update of /cvsroot/pywin32/pywin32/win32/Demos/security/sspi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15490/Demos/security/sspi
Modified Files:
Tag: py3k
fetch_url.py simple_auth.py socket_server.py
validate_password.py
Log Message:
Changes to build for Python 3.0
Index: simple_auth.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/security/sspi/simple_auth.py,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -C2 -d -r1.2 -r1.2.4.1
*** simple_auth.py 13 Feb 2006 14:54:43 -0000 1.2
--- simple_auth.py 29 Aug 2008 04:59:25 -0000 1.2.4.1
***************
*** 7,11 ****
def lookup_ret_code(err):
! for k,v in sspicon.__dict__.items():
if k[0:6] in ('SEC_I_','SEC_E_') and v==err:
return k
--- 7,11 ----
def lookup_ret_code(err):
! for k,v in list(sspicon.__dict__.items()):
if k[0:6] in ('SEC_I_','SEC_E_') and v==err:
return k
***************
*** 42,48 ****
# always be the same.
sspiserver.ctxt.ImpersonateSecurityContext()
! print 'Impersonated user: ',win32api.GetUserNameEx(win32api.NameSamCompatible)
sspiserver.ctxt.RevertSecurityContext()
! print 'Reverted to self: ',win32api.GetUserName()
pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES)
--- 42,48 ----
# always be the same.
sspiserver.ctxt.ImpersonateSecurityContext()
! print('Impersonated user: ',win32api.GetUserNameEx(win32api.NameSamCompatible))
sspiserver.ctxt.RevertSecurityContext()
! print('Reverted to self: ',win32api.GetUserName())
pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES)
***************
*** 65,71 ****
encbuf[0].Buffer=msg
sspiclient.ctxt.EncryptMessage(0,encbuf,1)
! print 'Encrypted data:',repr(encbuf[0].Buffer)
sspiserver.ctxt.DecryptMessage(encbuf,1)
! print 'Unencrypted data:',encbuf[0].Buffer
--- 65,71 ----
encbuf[0].Buffer=msg
sspiclient.ctxt.EncryptMessage(0,encbuf,1)
! print('Encrypted data:',repr(encbuf[0].Buffer))
sspiserver.ctxt.DecryptMessage(encbuf,1)
! print('Unencrypted data:',encbuf[0].Buffer)
Index: validate_password.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/security/sspi/validate_password.py,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -C2 -d -r1.3 -r1.3.4.1
*** validate_password.py 24 May 2005 13:26:48 -0000 1.3
--- validate_password.py 29 Aug 2008 04:59:25 -0000 1.3.4.1
***************
*** 21,25 ****
if __name__=='__main__':
if len(sys.argv) not in [2,3,4]:
! print "Usage: %s username [password [domain]]" % (__file__,)
sys.exit(1)
--- 21,25 ----
if __name__=='__main__':
if len(sys.argv) not in [2,3,4]:
! print("Usage: %s username [password [domain]]" % (__file__,))
sys.exit(1)
***************
*** 33,38 ****
try:
validate(sys.argv[1], password, domain)
! print "Validated OK"
! except win32security.error, details:
hr, func, msg = details
! print "Validation failed: %s (%d)" % (msg, hr)
--- 33,38 ----
try:
validate(sys.argv[1], password, domain)
! print("Validated OK")
! except win32security.error as details:
hr, func, msg = details
! print("Validation failed: %s (%d)" % (msg, hr))
Index: socket_server.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/security/sspi/socket_server.py,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -C2 -d -r1.2 -r1.2.4.1
*** socket_server.py 7 Mar 2005 11:16:18 -0000 1.2
--- socket_server.py 29 Aug 2008 04:59:25 -0000 1.2.4.1
***************
*** 23,29 ****
import sys
import struct
! import SocketServer
import win32api
! import httplib
import traceback
--- 23,29 ----
import sys
import struct
! import socketserver
import win32api
! import http.client
import traceback
***************
*** 38,42 ****
try:
return win32api.GetUserName()
! except win32api.error, details:
# Seeing 'access denied' errors here for non-local users (presumably
# without permission to login locally). Get the fully-qualified
--- 38,42 ----
try:
return win32api.GetUserName()
! except win32api.error as details:
# Seeing 'access denied' errors here for non-local users (presumably
# without permission to login locally). Get the fully-qualified
***************
*** 59,65 ****
return s.recv(cb)
! class SSPISocketServer(SocketServer.TCPServer):
def __init__(self, *args, **kw):
! SocketServer.TCPServer.__init__(self, *args, **kw)
self.sa = sspi.ServerAuth(options.package)
--- 59,65 ----
return s.recv(cb)
! class SSPISocketServer(socketserver.TCPServer):
def __init__(self, *args, **kw):
! socketserver.TCPServer.__init__(self, *args, **kw)
self.sa = sspi.ServerAuth(options.package)
***************
*** 73,78 ****
try:
err, sec_buffer = self.sa.authorize(data)
! except sspi.error, details:
! print "FAILED to authorize client:", details
return False
--- 73,78 ----
try:
err, sec_buffer = self.sa.authorize(data)
! except sspi.error as details:
! print("FAILED to authorize client:", details)
return False
***************
*** 84,91 ****
def process_request(self, request, client_address):
# An example using the connection once it is established.
! print "The server is running as user", GetUserName()
self.sa.ctxt.ImpersonateSecurityContext()
try:
! print "Having conversation with client as user", GetUserName()
while 1:
# we need to grab 2 bits of data - the encrypted data, and the
--- 84,91 ----
def process_request(self, request, client_address):
# An example using the connection once it is established.
! print("The server is running as user", GetUserName())
self.sa.ctxt.ImpersonateSecurityContext()
try:
! print("Having conversation with client as user", GetUserName())
while 1:
# we need to grab 2 bits of data - the encrypted data, and the
***************
*** 96,112 ****
break
data = self.sa.decrypt(data, key)
! print "Client sent:", repr(data)
finally:
self.sa.ctxt.RevertSecurityContext()
self.close_request(request)
! print "The server is back to user", GetUserName()
def serve():
s = SSPISocketServer(("localhost", options.port), None)
! print "Running test server..."
s.serve_forever()
def sspi_client():
! c = httplib.HTTPConnection("localhost", options.port)
c.connect()
# Do the auth dance.
--- 96,112 ----
break
data = self.sa.decrypt(data, key)
! print("Client sent:", repr(data))
finally:
self.sa.ctxt.RevertSecurityContext()
self.close_request(request)
! print("The server is back to user", GetUserName())
def serve():
s = SSPISocketServer(("localhost", options.port), None)
! print("Running test server...")
s.serve_forever()
def sspi_client():
! c = http.client.HTTPConnection("localhost", options.port)
c.connect()
# Do the auth dance.
***************
*** 119,123 ****
break
data = _get_msg(c.sock)
! print "Auth dance complete - sending a few encryted messages"
# Assume out data is sensitive - encrypt the message.
for data in "Hello from the client".split():
--- 119,123 ----
break
data = _get_msg(c.sock)
! print("Auth dance complete - sending a few encryted messages")
# Assume out data is sensitive - encrypt the message.
for data in "Hello from the client".split():
***************
*** 126,130 ****
_send_msg(c.sock, key)
c.sock.close()
! print "Client completed."
if __name__=='__main__':
--- 126,130 ----
_send_msg(c.sock, key)
c.sock.close()
! print("Client completed.")
if __name__=='__main__':
***************
*** 176,178 ****
finally:
if options.wait:
! raw_input("Press enter to continue")
--- 176,178 ----
finally:
if options.wait:
! input("Press enter to continue")
Index: fetch_url.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/security/sspi/fetch_url.py,v
retrieving revision 1.1
retrieving revision 1.1.4.1
diff -C2 -d -r1.1 -r1.1.4.1
*** fetch_url.py 6 Mar 2005 23:27:00 -0000 1.1
--- fetch_url.py 29 Aug 2008 04:59:25 -0000 1.1.4.1
***************
*** 9,15 ****
import sys
! import urllib
! import httplib
! import urlparse
from base64 import encodestring, decodestring
--- 9,15 ----
import sys
! import urllib.request, urllib.parse, urllib.error
! import http.client
! import urllib.parse
from base64 import encodestring, decodestring
***************
*** 21,30 ****
def open_url(host, url):
! h = httplib.HTTPConnection(host)
# h.set_debuglevel(9)
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
! print "Initial response is", resp.status, resp.reason
body = resp.read()
if resp.status == 302: # object moved
--- 21,30 ----
def open_url(host, url):
! h = http.client.HTTPConnection(host)
# h.set_debuglevel(9)
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
! print("Initial response is", resp.status, resp.reason)
body = resp.read()
if resp.status == 302: # object moved
***************
*** 34,44 ****
h.endheaders()
resp = h.getresponse()
! print "After redirect response is", resp.status, resp.reason
if options.show_headers:
! print "Initial response headers:"
! for name, val in resp.msg.items():
! print " %s: %s" % (name, val)
if options.show_body:
! print body
if resp.status == 401:
# 401: Unauthorized - here is where the real work starts
--- 34,44 ----
h.endheaders()
resp = h.getresponse()
! print("After redirect response is", resp.status, resp.reason)
if options.show_headers:
! print("Initial response headers:")
! for name, val in list(resp.msg.items()):
! print(" %s: %s" % (name, val))
if options.show_body:
! print(body)
if resp.status == 401:
# 401: Unauthorized - here is where the real work starts
***************
*** 60,66 ****
resp = h.getresponse()
if options.show_headers:
! print "Token dance headers:"
! for name, val in resp.msg.items():
! print " %s: %s" % (name, val)
if err==0:
--- 60,66 ----
resp = h.getresponse()
if options.show_headers:
! print("Token dance headers:")
! for name, val in list(resp.msg.items()):
! print(" %s: %s" % (name, val))
if err==0:
***************
*** 68,77 ****
else:
if resp.status != 401:
! print "Eeek - got response", resp.status
cl = resp.msg.get("content-length")
if cl:
! print repr(resp.read(int(cl)))
else:
! print "no content!"
assert resp.status == 401, resp.status
--- 68,77 ----
else:
if resp.status != 401:
! print("Eeek - got response", resp.status)
cl = resp.msg.get("content-length")
if cl:
! print(repr(resp.read(int(cl))))
else:
! print("no content!")
assert resp.status == 401, resp.status
***************
*** 84,118 ****
break
else:
! print "Could not find scheme '%s' in schemes %r" % (auth_scheme, schemes)
break
resp.read()
! print "Final response status is", resp.status, resp.reason
if resp.status == 200:
# Worked!
# Check we can read it again without re-authenticating.
if resp.will_close:
! print "EEEK - response will close, but NTLM is per connection - it must stay open"
body = resp.read()
if options.show_body:
! print "Final response body:"
! print body
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
! print "Second fetch response is", resp.status, resp.reason
if options.show_headers:
! print "Second response headers:"
! for name, val in resp.msg.items():
! print " %s: %s" % (name, val)
resp.read(int(resp.msg.get("content-length", 0)))
elif resp.status == 500:
! print "Error text"
! print resp.read()
else:
if options.show_body:
cl = resp.msg.get("content-length")
! print resp.read(int(cl))
if __name__=='__main__':
--- 84,118 ----
break
else:
! print("Could not find scheme '%s' in schemes %r" % (auth_scheme, schemes))
break
resp.read()
! print("Final response status is", resp.status, resp.reason)
if resp.status == 200:
# Worked!
# Check we can read it again without re-authenticating.
if resp.will_close:
! print("EEEK - response will close, but NTLM is per connection - it must stay open")
body = resp.read()
if options.show_body:
! print("Final response body:")
! print(body)
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
! print("Second fetch response is", resp.status, resp.reason)
if options.show_headers:
! print("Second response headers:")
! for name, val in list(resp.msg.items()):
! print(" %s: %s" % (name, val))
resp.read(int(resp.msg.get("content-length", 0)))
elif resp.status == 500:
! print("Error text")
! print(resp.read())
else:
if options.show_body:
cl = resp.msg.get("content-length")
! print(resp.read(int(cl)))
if __name__=='__main__':
***************
*** 136,146 ****
options, args = parser.parse_args()
if not args:
! print "Run with --help for usage details"
args = ["http://localhost/localstart.asp"]
for url in args:
! scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
if (scheme != "http") or params or query or fragment:
parser.error("Scheme must be http, URL must be simple")
! print "Opening '%s' from '%s'" % (path, netloc)
r = open_url(netloc, path)
--- 136,146 ----
options, args = parser.parse_args()
if not args:
! print("Run with --help for usage details")
args = ["http://localhost/localstart.asp"]
for url in args:
! scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
if (scheme != "http") or params or query or fragment:
parser.error("Scheme must be http, URL must be simple")
! print("Opening '%s' from '%s'" % (path, netloc))
r = open_url(netloc, path)
|