Skip to content

Commit fb557e7

Browse files
authored
IFS fixes for retrieving attributes using profile token (#232)
Signed-off-by: Nadir K Amra <[email protected]>
1 parent 254a8d9 commit fb557e7

File tree

2 files changed

+176
-138
lines changed

2 files changed

+176
-138
lines changed

src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java

+173-137
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,9 @@ public int getCCSID(boolean retrieveAll) throws IOException
639639
if (errorRC_ == IFSReturnCodeRep.FILE_NOT_FOUND || errorRC_ == IFSReturnCodeRep.PATH_NOT_FOUND)
640640
throw new ExtendedIOException(path_, ExtendedIOException.PATH_NOT_FOUND);
641641

642-
// Cannot create file handle to object, so let us try the other way
643-
return getCCSID();
642+
// Cannot create file handle to object, so let us try the other way only
643+
if (retrieveAll)
644+
return getCCSID();
644645
}
645646
}
646647
catch (AS400SecurityException e) {
@@ -668,44 +669,52 @@ public int getCCSID() throws IOException
668669
{
669670
// In 7.5 and prior releases, need to create user handle for IFS tables to be initialized.
670671
userHandle = (getSystem().getVRM() <= 0x00070500) ? system_.createUserHandle() : 0;
671-
672-
try
673-
{
674-
byte[] path = getConverter().stringToByteArray(path_);
675-
676-
IFSLookupReq req = new IFSLookupReq(path, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
677-
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
678-
}
679-
catch(ConnectionDroppedException e)
672+
if (userHandle == UNINITIALIZED)
680673
{
681-
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
682-
connectionDropped(e);
683-
}
684-
catch(InterruptedException e)
685-
{
686-
Trace.log(Trace.ERROR, "Interrupted");
687-
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
688-
throwException.initCause(e);
689-
throw throwException;
690-
}
691-
692-
int rc = 0;
693-
if (ds instanceof IFSLookupRep)
694-
{
695-
objectHandle = ((IFSLookupRep) ds).getHandle();
696-
retrieveAttributes(ds, objectHandle);
697-
}
698-
else if (ds instanceof IFSReturnCodeRep)
699-
{
700-
rc = ((IFSReturnCodeRep) ds).getReturnCode();
701-
if (rc != IFSReturnCodeRep.SUCCESS) Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
702-
703-
throw new ExtendedIOException(path_, rc);
674+
IFSListAttrsRep reply = listObjAttrs2(); // the 'ccsid' field is in the OA2 structure
675+
if (reply != null)
676+
fileDataCCSID_ = reply.getCCSID(serverDatastreamLevel_);
704677
}
705678
else
706679
{
707-
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
708-
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
680+
try
681+
{
682+
byte[] path = getConverter().stringToByteArray(path_);
683+
684+
IFSLookupReq req = new IFSLookupReq(path, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
685+
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
686+
}
687+
catch(ConnectionDroppedException e)
688+
{
689+
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
690+
connectionDropped(e);
691+
}
692+
catch(InterruptedException e)
693+
{
694+
Trace.log(Trace.ERROR, "Interrupted");
695+
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
696+
throwException.initCause(e);
697+
throw throwException;
698+
}
699+
700+
int rc = 0;
701+
if (ds instanceof IFSLookupRep)
702+
{
703+
objectHandle = ((IFSLookupRep) ds).getHandle();
704+
retrieveAttributes(ds, objectHandle);
705+
}
706+
else if (ds instanceof IFSReturnCodeRep)
707+
{
708+
rc = ((IFSReturnCodeRep) ds).getReturnCode();
709+
if (rc != IFSReturnCodeRep.SUCCESS) Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
710+
711+
throw new ExtendedIOException(path_, rc);
712+
}
713+
else
714+
{
715+
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
716+
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
717+
}
709718
}
710719
}
711720
finally
@@ -1496,44 +1505,50 @@ public int getASP() throws IOException, AS400SecurityException
14961505
{
14971506
// In 7.5 and prior releases, need to create user handle for IFS tables to be initialized.
14981507
userHandle = (getSystem().getVRM() <= 0x00070500) ? system_.createUserHandle() : 0;
1499-
1500-
try
1501-
{
1502-
// Issue a Look up request to create an object handle.
1503-
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1504-
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1505-
}
1506-
catch(ConnectionDroppedException e)
1507-
{
1508-
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1509-
connectionDropped(e);
1510-
}
1511-
catch(InterruptedException e)
1512-
{
1513-
Trace.log(Trace.ERROR, "Interrupted");
1514-
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1515-
throwException.initCause(e);
1516-
throw throwException;
1517-
}
1518-
1519-
rc = 0;
1520-
if (ds instanceof IFSLookupRep)
1508+
if (userHandle == UNINITIALIZED)
15211509
{
1522-
objectHandle = ((IFSLookupRep) ds).getHandle();
1523-
retrieveAttributes(ds, objectHandle); //@AC7A
1524-
}
1525-
else if (ds instanceof IFSReturnCodeRep)
1526-
{
1527-
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1528-
if (rc != IFSReturnCodeRep.SUCCESS)
1529-
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1530-
1531-
throw new ExtendedIOException(path_, rc);
1510+
// Not sure what to do here...20.0.7 returned -1. So we do that same in 20.0.8.
15321511
}
15331512
else
15341513
{
1535-
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1536-
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1514+
try
1515+
{
1516+
// Issue a Look up request to create an object handle.
1517+
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1518+
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1519+
}
1520+
catch(ConnectionDroppedException e)
1521+
{
1522+
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1523+
connectionDropped(e);
1524+
}
1525+
catch(InterruptedException e)
1526+
{
1527+
Trace.log(Trace.ERROR, "Interrupted");
1528+
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1529+
throwException.initCause(e);
1530+
throw throwException;
1531+
}
1532+
1533+
rc = 0;
1534+
if (ds instanceof IFSLookupRep)
1535+
{
1536+
objectHandle = ((IFSLookupRep) ds).getHandle();
1537+
retrieveAttributes(ds, objectHandle); //@AC7A
1538+
}
1539+
else if (ds instanceof IFSReturnCodeRep)
1540+
{
1541+
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1542+
if (rc != IFSReturnCodeRep.SUCCESS)
1543+
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1544+
1545+
throw new ExtendedIOException(path_, rc);
1546+
}
1547+
else
1548+
{
1549+
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1550+
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1551+
}
15371552
}
15381553
}
15391554
finally
@@ -1566,43 +1581,58 @@ public String getOwnerNameByUserHandle(boolean forceRetrieve) throws IOException
15661581
{
15671582
// In 7.5 and prior releases, need to create user handle for IFS tables to be initialized.
15681583
userHandle = (getSystem().getVRM() <= 0x00070500) ? system_.createUserHandle() : 0;
1569-
1570-
try
1571-
{
1572-
// Issue a Look up request to create an object handle.
1573-
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1574-
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1575-
}
1576-
catch(ConnectionDroppedException e)
1577-
{
1578-
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1579-
connectionDropped(e);
1580-
}
1581-
catch(InterruptedException e)
1582-
{
1583-
Trace.log(Trace.ERROR, "Interrupted");
1584-
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1585-
throwException.initCause(e);
1586-
throw throwException;
1587-
}
1588-
1589-
// Verify that we got a handle back.
1590-
rc = 0;
1591-
if (ds instanceof IFSLookupRep)
1584+
if (userHandle == UNINITIALIZED)
15921585
{
1593-
objectHandle = ((IFSLookupRep) ds).getHandle();
1594-
retrieveAttributes(ds, objectHandle); //@AC7A
1586+
IFSListAttrsRep reply = listObjAttrs1(IFSObjAttrs1.OWNER_NAME_FLAG, 0);
1587+
if (reply != null)
1588+
fileOwnerName_ = reply.getOwnerName(system_.getCcsid());
1589+
else
1590+
{
1591+
if (Trace.traceOn_) Trace.log(Trace.WARNING, "getOwnerNameByUserHandle: IFSReturnCodeRep return code", errorRC_);
1592+
1593+
if (errorRC_ == IFSReturnCodeRep.FILE_NOT_FOUND || errorRC_ == IFSReturnCodeRep.PATH_NOT_FOUND)
1594+
throw new ExtendedIOException(path_, ExtendedIOException.PATH_NOT_FOUND);
1595+
}
15951596
}
1596-
else if (ds instanceof IFSReturnCodeRep)
1597-
{
1598-
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1599-
if (rc != IFSReturnCodeRep.SUCCESS) Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1600-
throw new ExtendedIOException(path_, rc);
1601-
}
16021597
else
16031598
{
1604-
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1605-
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1599+
try
1600+
{
1601+
// Issue a Look up request to create an object handle.
1602+
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1603+
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1604+
}
1605+
catch(ConnectionDroppedException e)
1606+
{
1607+
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1608+
connectionDropped(e);
1609+
}
1610+
catch(InterruptedException e)
1611+
{
1612+
Trace.log(Trace.ERROR, "Interrupted");
1613+
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1614+
throwException.initCause(e);
1615+
throw throwException;
1616+
}
1617+
1618+
// Verify that we got a handle back.
1619+
rc = 0;
1620+
if (ds instanceof IFSLookupRep)
1621+
{
1622+
objectHandle = ((IFSLookupRep) ds).getHandle();
1623+
retrieveAttributes(ds, objectHandle); //@AC7A
1624+
}
1625+
else if (ds instanceof IFSReturnCodeRep)
1626+
{
1627+
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1628+
if (rc != IFSReturnCodeRep.SUCCESS) Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1629+
throw new ExtendedIOException(path_, rc);
1630+
}
1631+
else
1632+
{
1633+
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1634+
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1635+
}
16061636
}
16071637
}
16081638
finally
@@ -1633,44 +1663,50 @@ public String getFileSystemType() throws IOException, AS400SecurityException
16331663
try
16341664
{
16351665
userHandle = (getSystem().getVRM() <= 0x00070500) ? system_.createUserHandle() : 0;
1636-
1637-
try
1638-
{
1639-
// Issue a Look up request to create an object handle.
1640-
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1641-
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1642-
}
1643-
catch(ConnectionDroppedException e)
1666+
if (userHandle == UNINITIALIZED)
16441667
{
1645-
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1646-
connectionDropped(e);
1647-
}
1648-
catch(InterruptedException e)
1649-
{
1650-
Trace.log(Trace.ERROR, "Interrupted");
1651-
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1652-
throwException.initCause(e);
1653-
throw throwException;
1654-
}
1655-
1656-
rc = 0;
1657-
if (ds instanceof IFSLookupRep)
1658-
{
1659-
objectHandle = ((IFSLookupRep) ds).getHandle();
1660-
retrieveAttributes(ds, objectHandle); //@AC7A
1661-
}
1662-
else if (ds instanceof IFSReturnCodeRep)
1663-
{
1664-
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1665-
if (rc != IFSReturnCodeRep.SUCCESS)
1666-
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1667-
1668-
throw new ExtendedIOException(path_, rc);
1668+
// Not sure what to do here...20.0.7 returned null string. For 20.0.8, return unknown.
16691669
}
16701670
else
16711671
{
1672-
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1673-
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1672+
try
1673+
{
1674+
// Issue a Look up request to create an object handle.
1675+
IFSLookupReq req = new IFSLookupReq(pathname, preferredServerCCSID_, userHandle, IFSLookupReq.OA12, IFSObjAttrs1.OWNERANAME_ASP_FLAS, 0);
1676+
ds = (ClientAccessDataStream) server_.sendAndReceive(req);
1677+
}
1678+
catch(ConnectionDroppedException e)
1679+
{
1680+
Trace.log(Trace.ERROR, "Byte stream server connection lost.");
1681+
connectionDropped(e);
1682+
}
1683+
catch(InterruptedException e)
1684+
{
1685+
Trace.log(Trace.ERROR, "Interrupted");
1686+
InterruptedIOException throwException = new InterruptedIOException(e.getMessage());
1687+
throwException.initCause(e);
1688+
throw throwException;
1689+
}
1690+
1691+
rc = 0;
1692+
if (ds instanceof IFSLookupRep)
1693+
{
1694+
objectHandle = ((IFSLookupRep) ds).getHandle();
1695+
retrieveAttributes(ds, objectHandle); //@AC7A
1696+
}
1697+
else if (ds instanceof IFSReturnCodeRep)
1698+
{
1699+
rc = ((IFSReturnCodeRep) ds).getReturnCode();
1700+
if (rc != IFSReturnCodeRep.SUCCESS)
1701+
Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", rc);
1702+
1703+
throw new ExtendedIOException(path_, rc);
1704+
}
1705+
else
1706+
{
1707+
Trace.log(Trace.ERROR, "Unknown reply data stream", ds.getReqRepID());
1708+
throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN);
1709+
}
16741710
}
16751711
}
16761712
finally

src/main/java/com/ibm/as400/security/auth/ProfileTokenEnhancedInfo.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ public ProfileTokenEnhancedInfo(ProfileTokenEnhancedInfo enhancedInfo) {
8686
enhancedInfo.localPort_);
8787
}
8888

89-
public String getVerificationID() { return verificationID_; }
89+
public String getVerificationID() {
90+
return (verificationID_ != null) ? verificationID_ : ProfileTokenCredential.DEFAULT_VERIFICATION_ID;
91+
}
9092
public String getRemoteIPAddress() { return remoteIPAddress_; }
9193
public int getRemotePort() { return remotePort_; }
9294
public String getLocalIPAddress() { return localIPAddress_; }

0 commit comments

Comments
 (0)