Skip to content

Commit

Permalink
Determine JDBC system version when port number specified
Browse files Browse the repository at this point in the history
Signed-off-by: John Eberhard <[email protected]>
  • Loading branch information
jeber-ibm committed Jun 20, 2024
1 parent aa76b3a commit f2cd6ae
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 23 deletions.
18 changes: 17 additions & 1 deletion src/main/java/com/ibm/as400/access/AS400.java
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,21 @@ public int getVRM() throws AS400SecurityException, IOException

return vrm;
}

/**
* Sets the VRM for the object, creating a signonInfo as needed
*
*/
protected void setVRM(int v, int r, int m) {
if (signonInfo_ == null) {
signonInfo_ = new SignonInfo((v << 16 ) + (r << 8) + m);
} else {
signonInfo_.version.setVersionReleaseModification((v << 16) + (r << 8) + m);
}
if (impl_ != null) {
impl_.setVRM(v,r,m);
}

}
/**
Initialize conversion table for the given CCSID. The default EBCDIC to unicode converters are not shipped with some browsers. This method can be used to check and download converters if they are not available locally.
@param ccsid the CCSID for the conversion table to initialize.
Expand Down Expand Up @@ -5332,6 +5346,8 @@ public void setEnabledCipherSuites(String[] suites)
newCipherSuites = suites;
}
}



// ======== END =================
// Previous chunk of code moved from SecureAS400
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/ibm/as400/access/AS400Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ interface AS400Impl
SignonInfo skipSignon(String systemName, boolean systemNameLocal,
String userId_, CredentialVault tempVault, String gssName) throws AS400SecurityException, IOException;

String getSystemName();
String getSystemName();
/* Set the VRM for the object. Only set for the remote Impl */
void setVRM(int v, int r, int m);

}
5 changes: 5 additions & 0 deletions src/main/java/com/ibm/as400/access/AS400ImplProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,9 @@ public int getBidiStringType(){
public String getSystemName() {
return connection_.getSystemName();
}

@Override
public void setVRM(int v, int r, int m) {
// Does nothing for the proxy class
}
}
35 changes: 30 additions & 5 deletions src/main/java/com/ibm/as400/access/AS400ImplRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,19 @@ synchronized AS400Server getConnection(int service, int overridePort, boolean fo
SocketContainer socketContainer = null;
if (connectViaHCS)
{

if (HCSAuthdServer_ == null)
generateHCSServerDaemon(skipSignonServer);

try {
generateHCSServerDaemon(skipSignonServer,overridePort);
} catch (Exception ex) {
// If we specified a port number and got an exception,
// then ignore the error from the HCS.
if (overridePort > 0) {
HCSAuthdServer_ = null;
} else {
throw ex;
}
}
if (HCSAuthdServer_ == null)
{
connectViaHCS = false;
Expand Down Expand Up @@ -1876,7 +1886,7 @@ synchronized AS400Server getConnection(int service, int overridePort, boolean fo
return server;
}

synchronized private void generateHCSServerDaemon(boolean skipSignonServer) throws AS400SecurityException, IOException
synchronized private void generateHCSServerDaemon(boolean skipSignonServer, int overridePort) throws AS400SecurityException, IOException
{
if (HCSAuthdServer_ != null)
return;
Expand All @@ -1888,7 +1898,7 @@ synchronized private void generateHCSServerDaemon(boolean skipSignonServer) thro
try
{
socketContainer = PortMapper.getServerSocket(
(systemNameLocal_) ? "localhost" : systemName_, AS400.HOSTCNN, -1,
(systemNameLocal_) ? "localhost" : systemName_, AS400.HOSTCNN, overridePort,
useSSLConnection_, socketProperties_, mustUseNetSockets_);

connectionID = socketContainer.hashCode();
Expand All @@ -1910,6 +1920,7 @@ synchronized private void generateHCSServerDaemon(boolean skipSignonServer) thro
AS400XChgRandSeedReplyDS xChgReply = new AS400XChgRandSeedReplyDS();
if (Trace.traceOn_)
xChgReply.setConnectionID(connectionID);

xChgReply.read(inStream);

if (xChgReply.getRC() != 0)
Expand Down Expand Up @@ -1986,11 +1997,15 @@ synchronized private void generateHCSServerDaemon(boolean skipSignonServer) thro

HCSAuthdServer_ = new AS400NoThreadServer(this, AS400.HOSTCNN, socketContainer, jobString);
}
catch (ConnectException e)
catch (ConnectException e)
{
forceDisconnect(e, HCSAuthdServer_, socketContainer);
HCSAuthdServer_ = null;
}
catch (java.net.SocketException e) {
forceDisconnect(e, HCSAuthdServer_, socketContainer);
HCSAuthdServer_ = null;
}
catch (IOException | AS400SecurityException | RuntimeException e)
{
forceDisconnect(e, HCSAuthdServer_, socketContainer);
Expand Down Expand Up @@ -5181,4 +5196,14 @@ private static byte[] generateSha512Protected(byte[] bytes, byte[] token,
return protectedPassword;
}
//@AF2 End

@Override
public void setVRM(int v, int r, int m) {
if (signonInfo_ == null) {
signonInfo_ = new SignonInfo((v << 16) + (r << 8) + m);
} else {
signonInfo_.version.setVersionReleaseModification((v << 16) + (r << 8) + m);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4384,7 +4384,7 @@ else if (lobThreshold >= 15728640) // @E6A
JDTrace.logInformation(this, "True auto-commit supported = true");
JDTrace.logInformation(this, "128 byte column names supported = true");
JDTrace.logInformation(this, "128 length schema names supported = true");
JDTrace.logInformation(this, "client support 0x04000000 set");
JDTrace.logInformation(this, "client support 0x04000000 boolean");
JDTrace.logInformation(this, "client support 0x02000000 multiple SQLCAs");
}

Expand Down
36 changes: 35 additions & 1 deletion src/main/java/com/ibm/as400/access/AS400JDBCDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.ResultSet;
import java.sql.SQLException;
/* ifdef JDBC40 */
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.logging.Logger;
/* endif */
import java.util.Properties;
Expand Down Expand Up @@ -1447,7 +1449,14 @@ public boolean jdbcCompliant ()

//@B6A -- This logic was formerly in the initializeConnection() method.
private Connection prepareConnection(AS400 as400, JDDataSourceURL dataSourceUrl,
JDProperties jdProperties)
JDProperties jdProperties) throws SQLException {
return prepareConnection(as400,dataSourceUrl, jdProperties, false);
}


private Connection prepareConnection(AS400 as400, JDDataSourceURL dataSourceUrl,
JDProperties jdProperties,
boolean vrmSet)
throws SQLException
{

Expand Down Expand Up @@ -1548,6 +1557,31 @@ private Connection prepareConnection(AS400 as400, JDDataSourceURL dataSourceUrl,
throw sqlex;
}
}
//
// If the signon server was skipped, we need to manually determine the release
// This is important for boolean support
//
if (as400.skipSignonServer & ! vrmSet) {
try {
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("SELECT OS_VERSION,OS_RELEASE FROM SYSIBMADM.ENVSYSINFO");
if (rs.next()) {
int version = rs.getInt(1);
int release = rs.getInt(2);
as400.setVRM(version,release,0);
}
rs.close();
s.close();
} catch (SQLException sqlex) {
// Log and ignore
}
//
// Connect again to get the correct settings
// This didn't work!!!! TODO;
//
connection.close();
return prepareConnection(as400,dataSourceUrl, jdProperties, true);
}
return connection;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/as400/access/JobCCSIDNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int retrieveCcsid() throws ErrorCompletingRequestException
{
try
{
if (AS400.nativeVRM.vrm_ < 0x00050300)
if (AS400.nativeVRM.getVersionReleaseModification() < 0x00050300)
{
return new NLSImplNative().ccsidNative();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ibm/as400/access/PortMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static boolean canUseUnixSocket(String systemName, int service, boolean
{
if (AS400.onAS400 && unixSocketAvailable && !mustUseNetSockets && service != AS400.FILE && (systemName.equalsIgnoreCase("localhost") || systemName.equalsIgnoreCase("ipv6-localhost")))
{
if (service == AS400.DATABASE && AS400.nativeVRM.vrm_ < 0x00060100) return false;
if (service == AS400.DATABASE && AS400.nativeVRM.getVersionReleaseModification() < 0x00060100) return false;
return true;
}
return false;
Expand All @@ -142,7 +142,7 @@ static SocketContainer getServerSocket(String systemName,
try
{
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Starting a local socket to " + serviceName);
sc = AS400.nativeVRM.vrm_ < 0x00050400 ? (SocketContainer)AS400.loadImpl("com.ibm.as400.access.SocketContainerUnix") : (SocketContainer)AS400.loadImpl("com.ibm.as400.access.SocketContainerUnix2");
sc = AS400.nativeVRM.getVersionReleaseModification()< 0x00050400 ? (SocketContainer)AS400.loadImpl("com.ibm.as400.access.SocketContainerUnix") : (SocketContainer)AS400.loadImpl("com.ibm.as400.access.SocketContainerUnix2");
if (sc != null)
{
sc.setProperties(null, serviceName, null, 0, null);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/ibm/as400/access/RemoteCommandImplNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ protected void openOnThread() throws AS400SecurityException, ErrorCompletingRequ
{
converter_ = ConverterImplRemote.getConverter(system_.getCcsid(), system_);
}
if (AS400.nativeVRM.vrm_ >= 0x00050300)
if (AS400.nativeVRM.getVersionReleaseModification()>= 0x00050300)
{
if (AS400.nativeVRM.vrm_ >= 0x00060100)
if (AS400.nativeVRM.getVersionReleaseModification()>= 0x00060100)
{
serverDataStreamLevel_ = 10;
if (unicodeConverter_ == null) {
Expand Down Expand Up @@ -345,7 +345,7 @@ private boolean runCommandOnThread(String command, int messageOption, boolean cu
}
if (!currentlyOpeningOnThisThread) openOnThread();

if (AS400.nativeVRM.vrm_ >= 0x00060100)
if (AS400.nativeVRM.getVersionReleaseModification()>= 0x00060100)
{
return runCommandOnThread(unicodeConverter_.stringToByteArray(command), messageOption, 1200);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ private boolean runCommandOnThread(byte[] commandBytes, int messageOption, int c
try
{
if (Trace.traceOn_) Trace.log(Trace.INFORMATION, "Invoking native method.");
if (AS400.nativeVRM.vrm_ < 0x00050300)
if (AS400.nativeVRM.getVersionReleaseModification()< 0x00050300)
{
try
{
Expand All @@ -405,7 +405,7 @@ private boolean runCommandOnThread(byte[] commandBytes, int messageOption, int c
{
try
{
byte[] replyBytes = AS400.nativeVRM.vrm_ < 0x00060100 ? runCommandNativeV5R3(commandBytes, messageOption) : NativeMethods.runCommand(commandBytes, ccsid, messageOption);
byte[] replyBytes = AS400.nativeVRM.getVersionReleaseModification()< 0x00060100 ? runCommandNativeV5R3(commandBytes, messageOption) : NativeMethods.runCommand(commandBytes, ccsid, messageOption);
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Native reply bytes:", replyBytes);

// Get info from reply.
Expand Down Expand Up @@ -479,7 +479,7 @@ protected boolean runProgramOnThread(String library, String name, ProgramParamet
// Run the program on-thread.
if (!currentlyOpeningOnThisThread) openOnThread();

if (AS400.nativeVRM.vrm_ < 0x00050300)
if (AS400.nativeVRM.getVersionReleaseModification()< 0x00050300)
{
// Create a "call program" request, and write it as raw bytes to a byte array.
// Set up the buffer that contains the program to call. The buffer contains three items:
Expand Down Expand Up @@ -640,7 +640,7 @@ protected boolean runProgramOnThread(String library, String name, ProgramParamet
{
// Call native method.
if (Trace.traceOn_) Trace.log(Trace.INFORMATION, "Invoking native method.");
byte[] replyBytes = AS400.nativeVRM.vrm_ < 0x00060100 ? runProgramNativeV5R3(nameBytes, libraryBytes, parameterList.length, offsetArray, programParameters, messageOption) : NativeMethods.runProgram(nameBytes, libraryBytes, parameterList.length, offsetArray, programParameters, messageOption);
byte[] replyBytes = AS400.nativeVRM.getVersionReleaseModification()< 0x00060100 ? runProgramNativeV5R3(nameBytes, libraryBytes, parameterList.length, offsetArray, programParameters, messageOption) : NativeMethods.runProgram(nameBytes, libraryBytes, parameterList.length, offsetArray, programParameters, messageOption);
if (Trace.traceOn_) Trace.log(Trace.DIAGNOSTIC, "Native reply bytes:", replyBytes);

// Reset the message list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ public int getThreadsafeIndicator(String command) throws AS400SecurityException,
// If the command is not a proxy command, retrieve information for the specified command. //@A1A

int numParms;
if ((AS400.nativeVRM.vrm_ >= 0x00060100) ||
(AS400.nativeVRM.vrm_ >= 0x00050400 && !system_.isMissingPTF())) {
if ((AS400.nativeVRM.getVersionReleaseModification()>= 0x00060100) ||
(AS400.nativeVRM.getVersionReleaseModification()>= 0x00050400 && !system_.isMissingPTF())) {
numParms = 6; // @A1C - added support for proxy commands
}
else numParms = 5;
Expand All @@ -252,7 +252,7 @@ public int getThreadsafeIndicator(String command) throws AS400SecurityException,
{
// If the exception is "MCH0802: Total parameters passed does not match number required" and we're running to V5R4, that means that the user hasn't applied PTF SI29629. In that case, we will re-issue the program call, minus the new "follow proxy chain" parameter.
if (numParms > 5 &&
AS400.nativeVRM.vrm_ < 0x00060100 && AS400.nativeVRM.vrm_ >= 0x00050400 &&
AS400.nativeVRM.getVersionReleaseModification()< 0x00060100 && AS400.nativeVRM.getVersionReleaseModification()>= 0x00050400 &&
messageList_[messageList_.length - 1].getID().equals("MCH0802"))
{
if (Trace.traceOn_) Trace.log(Trace.WARNING, "PTF SI29629 is not installed: (MCH0802) " + messageList_[messageList_.length - 1].getText());
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/ibm/as400/access/ServerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ServerVersion implements Serializable
private static final String copyright = "Copyright (C) 1997-2000 International Business Machines Corporation and others.";

static final long serialVersionUID = 4L;
int vrm_;
private int vrm_;

// Create a version object.
// @param int version/release/modification. High 16 bits represent version next 8 bits represent release, low 8 bits represent modification. Thus Version 3, release 1, modification level 0 is 0x00030100.
Expand Down Expand Up @@ -56,4 +56,10 @@ int getVersionReleaseModification()
{
return vrm_;
}

void setVersionReleaseModification(int vrm)
{
vrm_ = vrm;
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/ibm/as400/access/SignonInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class SignonInfo implements Serializable
// Note: not maintained as com.ibm.as400.security.auth.ProfileToken. Class is currently not available in proxy environments, so don't want to force instantiation during signon.
Object profileToken;
String userId;

SignonInfo() { }

SignonInfo(int vrm) {
version = new ServerVersion(vrm);
}
}

0 comments on commit f2cd6ae

Please sign in to comment.