print_help() elif o in ['-u', '--user']: config['user'] = v elif o in ['-p', '--password']: config['password'] = v elif o in ['-d', '--domain']: config['domain'] = v elif o in ['-a', '--address']: config['address'] = v if len(config)!=4: print "Too few options specified." print_help() proxy = NTLM_Proxy(config['address'], config['domain']) client = NTLM_Client(config['user'],config['domain'],config['password']) type1 = client.make_ntlm_negotiate() challenge = proxy.negotiate(type1) if not challenge: print "Did not get the challenge!" sys.exit(-2) client.parse_ntlm_challenge(challenge) authenticate = client.make_ntlm_authenticate() if proxy.authenticate(authenticate): print "User %s\\%s was authenticated." % (config['user'], config['domain']) else: print "User %s\\%s was NOT authenticated." % (config['user'], config['domain'])
mechanism (RFC2617). ''' req.log_error('Handling Basic Access Authentication for URI %s' % (req.unparsed_uri)) domain = req.get_options().get('Domain', req.auth_name()) client = NTLM_Client(user, domain, password) type1 = client.make_ntlm_negotiate() try: (proxy, type2) = connect_to_proxy(req, type1) except Exception, e: return apache.HTTP_INTERNAL_SERVER_ERROR client.parse_ntlm_challenge(type2) type3 = client.make_ntlm_authenticate() if proxy.authenticate(type3): req.log_error('PYNTLM: User %s/%s has been authenticated (Basic) to access URI %s' % (domain,user,req.unparsed_uri), apache.APLOG_NOTICE) req.connection.notes.add('BASIC_AUTHORIZED',user) req.user = user return apache.OK else: req.log_error('PYNTLM: User %s/%s at %s failed Basic authentication for URI %s' % ( domain,user,req.connection.remote_ip,req.unparsed_uri)) return apache.HTTP_UNAUTHORIZED def authenhandler(req): '''The request handler called by mod_python in the authentication phase.''' req.log_error("PYNTLM: Handling connection 0x%X from address %s for %s URI %s. %d entries in connection cache." % ( req.connection.id, req.connection.remote_ip,req.method,req.unparsed_uri,len(cache)), apache.APLOG_INFO) # Extract Authorization header, as a list (if present)