String msg = req.getHeader( "Authorization" );
if (DebugFile.trace) DebugFile.writeln("NtlmHipergateFilter Authorization=" + msg);
UniAddress dc;
String user = "", password = "", domain = "";
boolean offerBasic = enableBasic && (insecureBasic || req.isSecure());
if (DebugFile.trace) DebugFile.writeln("offerBasic=" + String.valueOf(offerBasic));
if( msg != null && (msg.startsWith( "NTLM " ) || (offerBasic && msg.startsWith("Basic ")))) {
if( loadBalance ) {
if (DebugFile.trace) DebugFile.writeln("new UniAddress(" + NbtAddress.getByName( domainController, 0x1C, null ) + ")");
dc = new UniAddress( NbtAddress.getByName( domainController, 0x1C, null ));
} else {
if (DebugFile.trace) DebugFile.writeln("UniAddress.getByName( " + domainController + ", true)");
dc = UniAddress.getByName( domainController, true );
}
if (msg.startsWith("NTLM ")) {
req.getSession();
byte[] challenge = SmbSession.getChallenge( dc );
if (( ntlm = NtlmSsp.authenticate( req, resp, challenge )) == null ) {
if (DebugFile.trace) DebugFile.writeln("NtlmPasswordAuthentication = null");
return;
}
} else {
String auth = new String (Base64Decoder.decodeToBytes(msg.substring(6)), "US-ASCII");
int index = auth.indexOf(':');
user = (index != -1) ? auth.substring(0, index) : auth;
if (DebugFile.trace) DebugFile.writeln("user=" + user);
password = (index != -1) ? auth.substring(index + 1) : "";
index = user.indexOf('\\');
if (index == -1) index = user.indexOf('/');
domain = (index != -1) ? user.substring(0, index) : defaultDomain;
if (DebugFile.trace) DebugFile.writeln("domain=" + domain);
user = (index != -1) ? user.substring(index + 1) : user;
ntlm = new NtlmPasswordAuthentication(domain, user, password);
} // fi (msg.startsWith("NTLM "))
try {
if (DebugFile.trace && (dc!=null) && (ntlm!=null))
DebugFile.writeln("SmbSession.logon(" + dc.toString() + "," + ntlm.toString());
SmbSession.logon( dc, ntlm );
} catch( SmbAuthException sae ) {
if (DebugFile.trace) DebugFile.writeln("SmbAuthException" + Gadgets.toHexString(sae.getNtStatus(), 8) + " " + sae.getMessage());