You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by sa...@apache.org on 2016/03/02 07:36:45 UTC
[1/5] incubator-trafodion git commit: TRAFODION-1856: Revoke - object
and column privilege checks not integrated for constraints
Repository: incubator-trafodion
Updated Branches:
refs/heads/master cad7ab693 -> 39d3a0c44
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/PrivMgrPrivileges.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
index f3462b9..335f736 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp
@@ -237,25 +237,24 @@ public:
// sets the privilege and grantable bitmaps to 0
void clearVisited()
{
- visited_.columnOrdinal = columnOrdinal_;
- visited_.privsBitmap.reset();
- visited_.grantableBitmap.reset();
+ visited_.setColumnOrdinal(columnOrdinal_);
+ visited_.getPrivDesc().setAllPrivAndWgo(false);
}
// sets the current entry to match the original privileges
// before they are adjusted by a revoke command
void setCurrentToOriginal()
{
- current_.columnOrdinal = columnOrdinal_;
- current_.privsBitmap = privsBitmap_;
- current_.grantableBitmap = grantableBitmap_;
+ current_.setColumnOrdinal(columnOrdinal_);
+ current_.setPrivBitmap(privsBitmap_);
+ current_.setGrantableBitmap(grantableBitmap_);
}
-// compares the current privileges with the regenerated grant tree to
+// compares the current privileges with the visited grant tree to
// see if there are any broken branches
NABoolean anyNotVisited()
- {return current_.privsBitmap != visited_.privsBitmap ||
- current_.grantableBitmap != visited_.grantableBitmap;}
+ {return current_.getPrivBitmap() != visited_.getPrivBitmap() ||
+ current_.getGrantableBitmap() != visited_.getGrantableBitmap();}
// -------------------------------------------------------------------
@@ -319,30 +318,6 @@ private:
ColumnPrivsMDRow &rowOut);
};
-class ColObjectGrants
-{
-public:
- ColObjectGrants(int64_t objectUID) : object_uid_(objectUID) {};
- ~ColObjectGrants();
-
- const ColPrivEntry * getColPrivGrant(int32_t columnOrdinal) const
- {
- for (size_t i = 0; i < colPrivGrants_.size(); i++)
- if (colPrivGrants_[i].columnOrdinal == columnOrdinal)
- return &colPrivGrants_[i];
- return NULL;
- }
-
- void clear()
- {
- colPrivGrants_.clear();
- }
-
-private:
- int64_t object_uid_;
- std::vector<ColPrivEntry> colPrivGrants_;
-};
-
// *****************************************************************************
// * PrivMgrPrivileges.cpp static function declarations *
// *****************************************************************************
@@ -417,18 +392,16 @@ ColPrivEntry::ColPrivEntry ( const PrivMgrMDRow &row )
{
PrivMgrMDRow theRow = row;
ColumnPrivsMDRow &columnRow = static_cast<ColumnPrivsMDRow &> (theRow);
- columnOrdinal = columnRow.columnOrdinal_;
- privsBitmap = columnRow.privsBitmap_;
- grantableBitmap = columnRow.grantableBitmap_;
- isUpdate = false;
+ privDesc_.setColumnOrdinal(columnRow.columnOrdinal_);
+ privDesc_.setPrivBitmap(columnRow.privsBitmap_);
+ privDesc_.setWgoBitmap(columnRow.grantableBitmap_);
+ isUpdate_ = false;
}
ColPrivEntry::ColPrivEntry ( const ColPrivEntry &other)
{
- columnOrdinal = other.columnOrdinal;
- privsBitmap = other.privsBitmap;
- grantableBitmap = other.grantableBitmap;
- isUpdate = other.isUpdate;
+ privDesc_ = other.privDesc_;
+ isUpdate_ = other.isUpdate_;
}
// *****************************************************************************
@@ -635,6 +608,40 @@ PrivStatus PrivMgrPrivileges::getColPrivsForUser(
return STATUS_GOOD;
}
+// *****************************************************************************
+// Function: getColRowsForGranteeOrdinal
+//
+// Returns the list of column privileges granted for the object that have
+// been granted to the granteeID for a particular column
+//
+// Parameters:
+//
+// <granteeID> is the authID granted the privileges.
+// <columnOrdinal> is the column number to gather privileges
+// <roleIDs> is the list of roles assigned the granteeID
+// <rowList> the privileges granted to <granteeID> on <columnOrdinal>.
+//
+// *****************************************************************************
+void PrivMgrPrivileges::getColRowsForGranteeOrdinal(
+ const int32_t granteeID,
+ const int32_t columnOrdinal,
+ const std::vector<int32_t> &roleIDs,
+ std::vector<PrivMgrMDRow *> &rowList)
+{
+ for (size_t i = 0; i < columnRowList_.size(); ++i)
+ {
+ ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*columnRowList_[i]);
+ ColPrivEntry colPrivGrant;
+
+ if (row.granteeID_ == granteeID && row.columnOrdinal_ == columnOrdinal)
+ {
+ ColumnPrivsMDRow *pRow = new ColumnPrivsMDRow();
+ *pRow = row;
+ rowList.push_back(pRow);
+ }
+ }
+}
+
// *****************************************************************************
// * Method: getPrivRowsForObject
@@ -1055,17 +1062,8 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
return privStatus;
- // Determine if the grantor has WITH GRANT OPTION (WGO) for all the
- // columns to be granted. If not, return an error.
- ObjectPrivsMDTable objectPrivsTable(objectTableName_,pDiags_);
- ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
-
// Grantor may have WGO from two sources, object-level grants on the object,
- // and column-level grants. First check the object-level grants. If there
- // are privileges still to grant, check for requisite column-level grants.
-
- std::vector<ColPrivEntry> grantedColPrivs;
-
+ // and column-level grants. hasColumnWGO checks both
if (!hasColumnWGO(colPrivsArrayIn,roleIDs,privStatus))
{
if (privStatus == STATUS_NOTFOUND)
@@ -1079,6 +1077,7 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
// the grants are already present. (may be adding WGO)
// Get existing column grants from grantor to the specified grantee.
+ std::vector<ColPrivEntry> grantedColPrivs;
getColRowsForGranteeGrantor(columnRowList_,
granteeID,grantorID_,
grantedColPrivs);
@@ -1098,24 +1097,23 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
std::vector<ColPrivEntry> colPrivsToGrant;
for (size_t i = 0; i < colPrivsArray.size(); i++)
{
- const ColPrivSpec &colPrivEntry = colPrivsArray[i];
+ const ColPrivSpec &colPrivSpec = colPrivsArray[i];
- ColPrivEntry *existingEntry = findColumnEntry(colPrivsToGrant,
- colPrivEntry.columnOrdinal);
- if (existingEntry != NULL)
- {
- existingEntry->privsBitmap.set(colPrivEntry.privType);
- if (isWGOSpecified)
- existingEntry->grantableBitmap.set(colPrivEntry.privType);
- }
- else
- {
- ColPrivEntry colPrivToGrant;
-
- colPrivToGrant.columnOrdinal = colPrivEntry.columnOrdinal;
- colPrivToGrant.privsBitmap.set(colPrivEntry.privType);
- if (isWGOSpecified)
- colPrivToGrant.grantableBitmap.set(colPrivEntry.privType);
+ ColPrivEntry *existingEntry = findColumnEntry(colPrivsToGrant,
+ colPrivSpec.columnOrdinal);
+ if (existingEntry != NULL)
+ {
+ existingEntry->setPriv(colPrivSpec.privType, true);
+ if (isWGOSpecified)
+ existingEntry->setGrantable(colPrivSpec.privType, true);
+ }
+ else
+ {
+ ColPrivEntry colPrivToGrant;
+ colPrivToGrant.setColumnOrdinal(colPrivSpec.columnOrdinal);
+ colPrivToGrant.setPriv(colPrivSpec.privType, true);
+ if (isWGOSpecified)
+ colPrivToGrant.setGrantable(colPrivSpec.privType, true);
colPrivsToGrant.push_back(colPrivToGrant);
}
@@ -1135,76 +1133,65 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
whereBase += authIDToString(granteeID);
whereBase += " AND column_number = ";
- for (size_t i = 0; i < colPrivsToGrant.size(); i++)
- {
- ColPrivEntry &colPrivToGrant = colPrivsToGrant[i];
- bool updateOperation = false;
- bool skipOperation = false;
+ ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
- // Look for any existing granted privileges on the column for which
- // privileges are to be granted.
- for (size_t g = 0; g < grantedColPrivs.size(); g++)
- {
- const ColPrivEntry &grantedColPriv = grantedColPrivs[g];
- // See if there is an existing column privilege granted for this column.
- // If not, check the next granted column privilege. If none are found
- // for this column, it is an insert operation.
- if (colPrivToGrant.columnOrdinal != grantedColPriv.columnOrdinal)
- continue;
-
- // An existing row with the same column has been found, it is one of four cases:
- //
- // 1) Adding a privilege (e.g., authID had SELECT, now granting INSERT) [update operation]
- // 2) AuthID had privilege, now adding WGO [update operation]
- // 3) AuthID already has privilege and/or WGO specified [skip operation]
- // 4) AuthID had privilege and WGO, now trying to take away WGO [error]
-
- // If the privilege bitmaps are not the same, adding a privilege.
- // This is an update operation, break out of for loop.
- if (colPrivToGrant.privsBitmap != grantedColPriv.privsBitmap)
- {
- updateOperation = true; // Case #1
- colPrivToGrant.privsBitmap |= grantedColPriv.privsBitmap;
- colPrivToGrant.grantableBitmap |= grantedColPriv.grantableBitmap;
- break;
- }
-
- // Privilege bitmaps are the same, could be adding WGO.
- if (colPrivToGrant.grantableBitmap.any())
- {
- // If WGO was specified, and adding, this is an update.
- // If user already has WGO, it is a NOP, so skip this entry.
- if (colPrivToGrant.grantableBitmap == grantedColPriv.grantableBitmap)
- {
- skipOperation = true; //Case #3
- break;
- }
- // Adding WGO
- updateOperation = true; //Case #2
- }
- else // WGO not specified
- {
- // If user already has WGO, error. Cannot revoke WGO via GRANT.
- if (grantedColPriv.grantableBitmap.any())
- {
- *pDiags_ << DgSqlCode(-CAT_PRIVILEGE_NOT_GRANTED); //TODO: Add error for removing WGO in GRANT
- return STATUS_ERROR; // Case #4
- }
- // WGO not specified, current privs same as privs to grant,
- // nothing to do.
- skipOperation = true; //Case #3
- break;
- }
+ for (size_t i = 0; i < colPrivsToGrant.size(); i++)
+ {
+ ColPrivEntry &colPrivToGrant = colPrivsToGrant[i];
+
+ colPrivToGrant.describe(traceMsg);
+ log (__FILE__, traceMsg, i);
+
+ bool updateOperation = false;
+ bool skipOperation = false;
+
+ ColPrivEntry *grantedColPriv = findColumnEntry(grantedColPrivs, colPrivToGrant.getColumnOrdinal());
+ if (grantedColPriv)
+ {
+ // An existing row with the same column has been found, it is one of four cases:
+ //
+ // 1) AuthID had WGO, now trying to take away WGO [error]
+ // 2) Adding a privilege (e.g., authID had SELECT, now granting INSERT) [update operation]
+ // 3) AuthID had privilege, now adding WGO [update operation]
+ // 4) AuthID already has privilege and/or WGO specified [skip operation]
- updateOperation = true;
- colPrivToGrant.privsBitmap |= grantedColPriv.privsBitmap;
- colPrivToGrant.grantableBitmap |= grantedColPriv.grantableBitmap;
- // Found an existing row for this column ordinal, so break out of loop.
- break;
+ // case 1: see if trying to take away WGO - anyNotSet returns true iff any
+ // WGO bit set in grantedColPriv is not set in colPrivToGrant - can this
+ // really occur?
+ if (colPrivToGrant.getPrivBitmap() == grantedColPriv->getPrivBitmap() &&
+ grantedColPriv->getPrivDesc().anyNotSet(colPrivToGrant.getPrivDesc()))
+ {
+ PRIVMGR_INTERNAL_ERROR("trying to remove WGO during grant");
+ return STATUS_ERROR;
}
+
+ // Case 2: If the privilege bitmaps are not the same, adding a privilege.
+ // This is an update operation
+ if (colPrivToGrant.getPrivBitmap() != grantedColPriv->getPrivBitmap())
+ {
+ updateOperation = true; // Case #1
+ colPrivToGrant.getPrivDesc().unionOfPrivs(grantedColPriv->getPrivDesc());
+ }
+
+ // Privilege bitmaps are the same
+ else
+ // Case 3: the privileges match, see if there are any additional WGO privs
+ // to set and mark updatable
+ // anyNotSet returns true iff any WGO bit set in colPrivToGrant is not set in
+ // grantedColPriv, this means more WGO bits need to be set.
+ if (colPrivToGrant.getPrivDesc().anyNotSet(grantedColPriv->getPrivDesc()))
+ {
+ updateOperation = true;
+ colPrivToGrant.getPrivDesc().unionOfPrivs(grantedColPriv->getPrivDesc());
+ }
+ // Case 4: no changes to priv or WGO bits - no updates required - skip
+ else
+ skipOperation = true;
+ }
- if (skipOperation)
- continue;
+ // Done with this entry, go to the next one
+ if (skipOperation)
+ continue;
// TBD: need to get the list of referencing views that need to have this
// privilege progated.
@@ -1232,9 +1219,9 @@ PrivStatus PrivMgrPrivileges::grantColumnPrivileges(
row.granteeName_ = granteeName;
row.grantorID_ = grantorID_;
row.grantorName_ = grantorName;
- row.privsBitmap_ = colPrivToGrant.privsBitmap;
- row.grantableBitmap_ = colPrivToGrant.grantableBitmap;
- row.columnOrdinal_ = colPrivToGrant.columnOrdinal;
+ row.privsBitmap_ = colPrivToGrant.getPrivBitmap();
+ row.grantableBitmap_ = colPrivToGrant.getGrantableBitmap();
+ row.columnOrdinal_ = colPrivToGrant.getColumnOrdinal();
if (updateOperation)
privStatus = columnPrivsTable.updateColumnRow(row,whereBase);
@@ -1334,6 +1321,10 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
if (generateObjectRowList() == STATUS_ERROR)
return STATUS_ERROR;
+ // generate the list of privileges granted to columns and store in class
+ if (generateColumnRowList() == STATUS_ERROR)
+ return STATUS_ERROR;
+
// get roleIDs for the grantor
std::vector<int_32> roleIDs;
retcode = getRoleIDsForUserID(grantorID_,roleIDs);
@@ -1483,6 +1474,7 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
}
ObjectPrivsMDTable objectPrivsTable (objectTableName_, pDiags_);
+ ColumnPrivsMDTable columnPrivsTable(columnTableName_,pDiags_);
char buf[1000];
if (foundRow)
@@ -1493,6 +1485,7 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
objectUsage.grantorIsSystem = false;
objectUsage.objectName = row.objectName_;
objectUsage.objectType = row.objectType_;
+ objectUsage.columnReferences = NULL;
PrivMgrDesc originalPrivs (row.granteeID_);
originalPrivs.setTablePrivs(savedOriginalPrivs);
@@ -1517,9 +1510,9 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
// update the OBJECT_PRIVILEGES row for each effected object
for (size_t i = 0; i < listOfObjects.size(); i++)
{
- ObjectUsage *pObj = listOfObjects[i];
+ ObjectUsage *pObjectUsage = listOfObjects[i];
- pObj->describe(traceMsg);
+ pObjectUsage->describe(traceMsg);
log (__FILE__, traceMsg, i);
// Determine the grantor:
@@ -1538,10 +1531,10 @@ PrivStatus PrivMgrPrivileges::grantObjectPriv(
//
// The listOfObjects contains referencing views that meet the above
// criteria.
- int32_t theGrantor = (pObj->grantorIsSystem) ? SYSTEM_USER : grantorID_;
- int32_t theGrantee = pObj->granteeID;
- int64_t theUID = pObj->objectUID;
- PrivMgrCoreDesc thePrivs = pObj->updatedPrivs.getTablePrivs();
+ int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
+ int32_t theGrantee = pObjectUsage->granteeID;
+ int64_t theUID = pObjectUsage->objectUID;
+ PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
sprintf(buf, "where grantee_id = %d and grantor_id = %d and object_uid = %ld",
theGrantee, theGrantor, theUID);
@@ -1787,7 +1780,6 @@ PrivStatus PrivMgrPrivileges::insertPrivRowsForObject(
}
-
// ****************************************************************************
// method: dealWithConstraints
//
@@ -1831,32 +1823,36 @@ PrivStatus PrivMgrPrivileges::dealWithConstraints(
if (retcode == STATUS_ERROR)
return retcode;
- // objectList contain ObjectReferences for all tables that reference the
- // ObjectUsage (object losing privilege) through an RI constraint
- PrivMgrDesc originalPrivs;
- PrivMgrDesc currentPrivs;
int32_t lastObjectOwnerID = 0;
std::vector<int32_t> roleIDs;
+ // objectList contains the list of objects referencing the referenced table,
+ // see if the requested privilege change causes an RI constraint to be invalid
for (size_t i = 0; i < objectList.size(); i++)
{
- ObjectReference *pObj = objectList[i];
+ ObjectReference *pObjectRef = objectList[i];
+ PrivMgrDesc originalPrivs;
+ PrivMgrDesc currentPrivs;
- pObj->describe(traceMsg);
+ pObjectRef->describe(traceMsg);
log (__FILE__, traceMsg, i);
-
- if (lastObjectOwnerID != pObj->objectOwner)
+
+ // getRoleIDsForUserID does I/O to get information. The referencing
+ // list is returned by object owner to avoid rereading information for
+ // the same user
+ // At some time, we should cache user and role information
+ if (lastObjectOwnerID != pObjectRef->objectOwner)
{
roleIDs.clear();
- retcode = getRoleIDsForUserID(pObj->objectOwner,roleIDs);
+ retcode = getRoleIDsForUserID(pObjectRef->objectOwner,roleIDs);
if (retcode == STATUS_ERROR)
return retcode;
}
// get the summarized original and current privs for the referencing table
- // current privs contains any adjustments
- retcode = summarizeCurrentAndOriginalPrivs(pObj->objectUID,
- pObj->objectOwner,
+ // current privs contains any adjustments due to the privilege change
+ retcode = summarizeCurrentAndOriginalPrivs(pObjectRef->objectUID,
+ pObjectRef->objectOwner,
roleIDs,
listOfAffectedObjects,
originalPrivs,
@@ -1864,25 +1860,66 @@ PrivStatus PrivMgrPrivileges::dealWithConstraints(
if (retcode != STATUS_GOOD)
return retcode;
- // If the underlying table no long has REFERENCES privileges return
- // a dependency error.
- PrivMgrCoreDesc thePrivs = objectUsage.updatedPrivs.getTablePrivs();
+ PrivMgrCoreDesc thePrivs = currentPrivs.getTablePrivs();
if (!thePrivs.getPriv(REFERENCES_PRIV))
{
- std::string referencingTable;
- if (admin.getConstraintName(objectUsage.objectUID, pObj->objectUID, referencingTable) == false)
+ log (__FILE__, "User does not have reference privilege on the object", -1);
+
+ // no longer have REFERENCES privilege on the table,
+ // see if privileges are granted on all required columns
+ std::vector<ColumnReference *> summarizedColRefs;
+ summarizeColPrivs(*pObjectRef, roleIDs, listOfAffectedObjects, summarizedColRefs);
+
+ // check summarized privileges to see if still have priv through other privs
+ std::vector<ColumnReference *> neededColRefs = *pObjectRef->columnReferences;
+ for (size_t i = 0; i < neededColRefs.size(); i++)
{
- referencingTable = "UNKNOWN, Referencing table ID is ";
- referencingTable += UIDToString(pObj->objectUID);
+
+ // neededColRefs contains the list of all columns referenced by this object
+ // summarizedColRefs are the current privileges with the privilege change
+ // incorporated.
+ // if user still has necessary privilege through column privileges, then
+ // revoke can proceed
+ ColumnReference *neededColRef = neededColRefs[i];
+ for (size_t j = 0; j < summarizedColRefs.size(); j++)
+ {
+ ColumnReference *existingRef = summarizedColRefs[j];
+ traceMsg = "Checking if have references for col: ";
+ traceMsg += to_string((long long int)existingRef->columnOrdinal);
+ log (__FILE__, traceMsg, -1);
+ if (existingRef->columnOrdinal == neededColRef->columnOrdinal)
+ {
+ PrivMgrCoreDesc colPrivs = existingRef->updatedPrivs;
+ traceMsg = "References setting: ";
+ traceMsg += (colPrivs.getPriv(REFERENCES_PRIV) ? "y" : "n");
+ log (__FILE__, traceMsg, -1);
+ if (!colPrivs.getPriv(REFERENCES_PRIV))
+ {
+ std::string referencingTable;
+ if (!admin.getConstraintName(objectUsage.objectUID,
+ pObjectRef->objectUID,
+ neededColRef->columnOrdinal, referencingTable))
+ {
+ referencingTable = "UNKNOWN, Referencing table ID is ";
+ referencingTable += UIDToString(pObjectRef->objectUID );
+ }
+
+ *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
+ << DgString0 (referencingTable.c_str());
+ retcode = STATUS_ERROR;
+ }
+ break;
+ }
+ }
}
- *pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
- << DgString0 (referencingTable.c_str());
- return STATUS_ERROR;
+ // remove list of summarized columns
+ while (!summarizedColRefs.empty())
+ delete summarizedColRefs.back(), summarizedColRefs.pop_back();
}
}
- return STATUS_GOOD;
+ return retcode;
}
@@ -1960,9 +1997,9 @@ PrivStatus PrivMgrPrivileges::dealWithUdrs(
{
// There could be multiple udrs, just pick the first one in the list
// for the error message.
- ObjectReference *pObj = objectList[0];
+ ObjectReference *pObjectRef = objectList[0];
*pDiags_ << DgSqlCode (-CAT_DEPENDENT_OBJECTS_EXIST)
- << DgString0 (pObj->objectName.c_str());
+ << DgString0 (pObjectRef->objectName.c_str());
return STATUS_ERROR;
}
}
@@ -2127,15 +2164,15 @@ PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
for (size_t i = 0; i < objectList.size(); i++)
{
- ObjectReference *pObj = objectList[i];
+ ObjectReference *pObjectRef = objectList[i];
- pObj->describe(traceMsg);
+ pObjectRef->describe(traceMsg);
log (__FILE__, traceMsg, i);
- if (lastObjectOwnerID != pObj->objectOwner)
+ if (lastObjectOwnerID != pObjectRef->objectOwner)
{
roleIDs.clear();
- retcode = getRoleIDsForUserID(pObj->objectOwner,roleIDs);
+ retcode = getRoleIDsForUserID(pObjectRef->objectOwner,roleIDs);
if (retcode == STATUS_ERROR)
return retcode;
}
@@ -2143,7 +2180,7 @@ PrivStatus PrivMgrPrivileges::gatherViewPrivileges(
// referenced object that have been granted to the view owner
// listOfAffectedObjects contain the privilege adjustments needed
// to generate the current privs
- retcode = summarizeCurrentAndOriginalPrivs(pObj->objectUID,
+ retcode = summarizeCurrentAndOriginalPrivs(pObjectRef->objectUID,
viewUsage.viewOwner,
roleIDs,
listOfAffectedObjects,
@@ -2285,15 +2322,20 @@ PrivStatus PrivMgrPrivileges::getAffectedObjects(
pUsage->objectType = objectUsage.objectType;
pUsage->originalPrivs = objectUsage.originalPrivs;
pUsage->updatedPrivs = objectUsage.updatedPrivs;
+ pUsage->columnReferences = objectUsage.columnReferences;
+
listOfAffectedObjects.push_back(pUsage);
+
// Find list of affected constraints
if (command != PrivCommand::GRANT_OBJECT)
{
+ // TBD optimization: if no "references" privilege has been revoked, skip
retcode = dealWithConstraints (objectUsage, listOfAffectedObjects);
- if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
+ if (retcode == STATUS_ERROR)
return retcode;
+ // TBD optimization: if no "execute" privilege has been revoked, skip
retcode = dealWithUdrs (objectUsage, listOfAffectedObjects);
if (retcode != STATUS_GOOD && retcode != STATUS_WARNING)
return retcode;
@@ -2505,6 +2547,10 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
std::string privilege;
std::vector<ColPrivEntry> grantedColPrivs;
+ // get the list of object privileges for the object
+ if (generateObjectRowList() == STATUS_ERROR)
+ return STATUS_ERROR;
+
// get the list of column privileges for the object
if (generateColumnRowList() == STATUS_ERROR)
return STATUS_ERROR;
@@ -2533,13 +2579,14 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
// Create a privsToRevoke array using the passed in revoke entries and the
// list of currently granted column privileges. Combine multiple privileges
// for the same column into one entry.
+
std::vector<ColPrivEntry> colPrivsToRevoke;
for (size_t i = 0; i < colPrivsArray.size(); i++)
{
- const ColPrivSpec &colPrivSpecEntry = colPrivsArray[i];
- PrivType privType = colPrivSpecEntry.privType;
- int32_t columnOrdinal = colPrivSpecEntry.columnOrdinal;
+ const ColPrivSpec &colPrivSpec = colPrivsArray[i];
+ PrivType privType = colPrivSpec.privType;
+ int32_t columnOrdinal = colPrivSpec.columnOrdinal;
// Find the priv details from metadata
ColPrivEntry *metadataEntry = findColumnEntry(grantedColPrivs,
@@ -2555,33 +2602,76 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
columnOrdinal);
if (existingEntry != NULL)
{
- existingEntry->privsBitmap.set(privType);
+ existingEntry->setPriv(privType, true);
// if revoking a privilege and auth ID has WGO, then revoke
// the WGO bit also
- PrivColumnBitmap grantableBitmap = metadataEntry->grantableBitmap;
- existingEntry->grantableBitmap.set(privType, grantableBitmap.test(privType));
+ PrivColumnBitmap grantableBitmap = metadataEntry->getGrantableBitmap();
+ existingEntry->setGrantable(privType, grantableBitmap.test(privType));
}
else
{
ColPrivEntry colPrivToRevoke;
- colPrivToRevoke.columnOrdinal = columnOrdinal;
- colPrivToRevoke.privsBitmap.set(privType);
-
+ colPrivToRevoke.setColumnOrdinal(columnOrdinal);
+ colPrivToRevoke.setPriv(privType,true);
+
// if revoking a privilege and auth ID has WGO, then revoke
// the WGO bit also
- colPrivToRevoke.grantableBitmap.set(privType, metadataEntry->grantableBitmap.test(privType));
+ colPrivToRevoke.setGrantable(privType, metadataEntry->getGrantableBitmap().test(privType));
colPrivsToRevoke.push_back(colPrivToRevoke);
}
}
+
+ // checks to see if can revoke if there are referenced items when
+ // revoke cascade is supported, this returns the list of referenced
+ // items that need to change.
+ ObjectUsage objectUsage;
+ objectUsage.objectUID = objectUID_;
+ objectUsage.granteeID = granteeID;
+ objectUsage.objectName = objectName_;
+ objectUsage.objectType = objectType;
+
+ // Create list of ColumnReferences
+ objectUsage.columnReferences = new std::vector<ColumnReference *>;
+ for (size_t i = 0; i < colPrivsToRevoke.size(); i++)
+ {
+ ColPrivEntry &colPrivToRevoke = colPrivsToRevoke[i];
+ ColPrivEntry *grantedColPriv = findColumnEntry(grantedColPrivs, colPrivToRevoke.getColumnOrdinal());
+ if (grantedColPriv)
+ {
+ ColumnReference *adjustedCol = new ColumnReference;
+ adjustedCol->columnOrdinal = colPrivToRevoke.getColumnOrdinal();
+ adjustedCol->originalPrivs = grantedColPriv->getPrivDesc();
+ PrivMgrCoreDesc adjustedPrivs = grantedColPriv->getPrivDesc();
+ adjustedPrivs.AndNot(colPrivToRevoke.getPrivDesc());
+ adjustedCol->updatedPrivs = adjustedPrivs;
+ objectUsage.columnReferences->push_back(adjustedCol);
+ }
+ }
+
+ // get privileges for the object, if they exist
+ ObjectPrivsMDRow row;
+ privStatus = getGrantedPrivs(granteeID, row);
+ if (privStatus == STATUS_GOOD)
+ {
+ PrivMgrCoreDesc coreDesc(row.privsBitmap_, row.grantableBitmap_);
+ objectUsage.originalPrivs.setTablePrivs(coreDesc);
+ objectUsage.updatedPrivs.setTablePrivs(coreDesc);
+ }
- // Verify that the existing grant tree stays intact (i.e. no broken branches)
- // if the requested privileges are revokew.
- if (checkColumnRevokeRestrict (granteeID, colPrivsToRevoke, columnRowList_))
- return STATUS_ERROR;
+ std::vector<ObjectUsage *> listOfObjects;
+ privStatus = getAffectedObjects(objectUsage,
+ PrivCommand::REVOKE_OBJECT_RESTRICT,
+ listOfObjects);
+ if (privStatus == STATUS_ERROR)
+ {
+ deleteListOfAffectedObjects(listOfObjects);
+ return privStatus;
+ }
+
// At this point we have an array of privsToRevoke with column ordinal and
// priv bitmap.
//
@@ -2599,6 +2689,11 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
// F 1 Not equal Revoking some privs on this column plus
// WGO for the revoked privs. Reset bits in
// both bitmaps. Update operation.
+
+
+ if (checkColumnRevokeRestrict (granteeID, colPrivsToRevoke, columnRowList_))
+ return STATUS_ERROR;
+
bool rowRevoked = false;
PrivColumnBitmap revokedPrivs;
@@ -2619,54 +2714,48 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
// Look for any existing granted privileges on the column for which
// privileges are to be granted.
- for (size_t g = 0; g < grantedColPrivs.size(); g++)
+ ColPrivEntry *grantedColPriv = findColumnEntry(grantedColPrivs, colPrivToRevoke.getColumnOrdinal());
+ if (grantedColPriv)
{
- const ColPrivEntry &grantedColPriv = grantedColPrivs[g];
- // See if there is an existing column privilege granted for this column.
- // If not, check the next granted column privilege. If none are found
- // for this column, it is an internal error.
- if (colPrivToRevoke.columnOrdinal != grantedColPriv.columnOrdinal)
- continue;
-
// Found row with grant for this column.
- // Verify privilge(s) being revoked was/were granted. If not, internal error.
- if ((colPrivToRevoke.privsBitmap & grantedColPriv.privsBitmap) == 0)
+ // Verify privilege(s) being revoked was/were granted. If not, internal error.
+ if ((colPrivToRevoke.getPrivBitmap() & grantedColPriv->getPrivBitmap()) == 0)
{
PRIVMGR_INTERNAL_ERROR("Privilege to revoke not found");
return STATUS_ERROR;
}
- if (isWGOSpecified)
- {
- // We want to clear the corresponding bits in the grantable bitmap.
- // Flip the bits of the privs to revoke bitmap, then and the
- // negation with the current grantable bitmap. Not revoking any
- // privileges, so update with current priv bitmap.
- PrivColumnBitmap revokeBitmap = ~colPrivToRevoke.privsBitmap;
- colPrivToRevoke.privsBitmap = grantedColPriv.privsBitmap;
- colPrivToRevoke.grantableBitmap = grantedColPriv.grantableBitmap & revokeBitmap;
- updateRow = true;
- }
+ // If all privileges are revoked, delete corresponding row
+ if (!isWGOSpecified &&
+ (colPrivToRevoke.getPrivBitmap() == grantedColPriv->getPrivBitmap()))
+ deleteRow = true;
else
- {
- if (colPrivToRevoke.privsBitmap == grantedColPriv.privsBitmap)
- deleteRow = true;
- else
- {
- PrivColumnBitmap revokeBitmap = ~colPrivToRevoke.privsBitmap;
- colPrivToRevoke.privsBitmap = grantedColPriv.privsBitmap & revokeBitmap;
- colPrivToRevoke.grantableBitmap = grantedColPriv.grantableBitmap & revokeBitmap;
- updateRow = true;
- }
- revokedPrivs |= colPrivToRevoke.privsBitmap;
- }
- break;
+ updateRow = true;
+
+ // generate the final bitmaps to store in metadata
+ // removing any privileges that already have been revoked
+ PrivMgrCoreDesc adjustedPrivs = grantedColPriv->getPrivDesc();
+ adjustedPrivs.AndNot(colPrivToRevoke.getPrivDesc());
+
+ // If only removing WGO, then the privsBitmap does not change
+ // Not sure if this is needed ??
+ if (isWGOSpecified)
+ adjustedPrivs.setPrivBitmap(grantedColPriv->getPrivBitmap());
+
+ // set adjusted privileges
+ colPrivToRevoke.setPrivBitmap(adjustedPrivs.getPrivBitmap());
+ colPrivToRevoke.setGrantableBitmap(adjustedPrivs.getWgoBitmap());
+
+ // Using the list of privs to revoke, change so adjustedPrivs contains
+ // Some privileges may have been requested to revoke that aren't
+ // currently granted - flip adjusted bits to final list of privs
+ revokedPrivs |= adjustedPrivs.getPrivBitmap();
}
if (deleteRow)
{
- std::string whereClause(whereBase + authIDToString(colPrivToRevoke.columnOrdinal));
+ std::string whereClause(whereBase + authIDToString(colPrivToRevoke.getColumnOrdinal()));
privStatus = columnPrivsTable.deleteWhere(whereClause);
if (privStatus == STATUS_ERROR)
@@ -2690,9 +2779,9 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
row.granteeName_ = granteeName;
row.grantorID_ = grantorID_;
row.grantorName_ = grantorName;
- row.privsBitmap_ = colPrivToRevoke.privsBitmap;
- row.grantableBitmap_ = colPrivToRevoke.grantableBitmap;
- row.columnOrdinal_ = colPrivToRevoke.columnOrdinal;
+ row.privsBitmap_ = colPrivToRevoke.getPrivBitmap();
+ row.grantableBitmap_ = colPrivToRevoke.getGrantableBitmap();
+ row.columnOrdinal_ = colPrivToRevoke.getColumnOrdinal();
privStatus = columnPrivsTable.updateColumnRow(row,whereBase);
@@ -2725,15 +2814,15 @@ PrivStatus PrivMgrPrivileges::revokeColumnPrivileges(
if (siIndex > 0)
SQL_EXEC_SetSecInvalidKeys(siIndex,siKeyList);
-// if (!rowRevoked)
- // Warning
- // ;
+ // if (!rowRevoked)
+ // Warning
return STATUS_GOOD;
}
//************* End of PrivMgrPrivileges::revokeColumnPrivileges ***************
+
// *****************************************************************************
// * Method: revokeObjectPriv
// *
@@ -2822,6 +2911,10 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
if (generateObjectRowList() == STATUS_ERROR)
return STATUS_ERROR;
+ // generate the list of privileges granted to columns and store in class
+ if (generateColumnRowList() == STATUS_ERROR)
+ return STATUS_ERROR;
+
// get privileges for the grantor and make sure the grantor can revoke
// at least one of the requested privileges
PrivMgrDesc privsOfTheGrantor(grantorID_);
@@ -2936,8 +3029,8 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
// update the OBJECT_PRIVILEGES row for each effected object
for (size_t i = 0; i < listOfObjects.size(); i++)
{
- ObjectUsage *pObj = listOfObjects[i];
- PrivMgrCoreDesc thePrivs = pObj->updatedPrivs.getTablePrivs();
+ ObjectUsage *pObjectUsage = listOfObjects[i];
+ PrivMgrCoreDesc thePrivs = pObjectUsage->updatedPrivs.getTablePrivs();
// Determine the grantor:
// SQL ANSI general rules state
@@ -2954,9 +3047,9 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
//
// The listOfObjects contains referencing views that meet the above
// criteria.
- int32_t theGrantor = (pObj->grantorIsSystem) ? SYSTEM_USER : grantorID_;
- int32_t theGrantee = pObj->granteeID;
- int64_t theUID = pObj->objectUID;
+ int32_t theGrantor = (pObjectUsage->grantorIsSystem) ? SYSTEM_USER : grantorID_;
+ int32_t theGrantee = pObjectUsage->granteeID;
+ int64_t theUID = pObjectUsage->objectUID;
sprintf(buf, "where grantee_id = %d and grantor_id = %d and object_uid = %ld",
theGrantee, theGrantor, theUID);
@@ -2964,7 +3057,7 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
if (thePrivs.isNull())
{
- pObj->describe(traceMsg);
+ pObjectUsage->describe(traceMsg);
traceMsg.insert (0, "deleted object usage ");
// delete the row
@@ -2974,13 +3067,6 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
deleteListOfAffectedObjects(listOfObjects);
return retcode;
}
- // Delete any corresponding column-level privileges.
- retcode = columnPrivsTable.deleteWhere(whereClause);
- if (retcode == STATUS_ERROR)
- {
- deleteListOfAffectedObjects(listOfObjects);
- return retcode;
- }
}
else
{
@@ -2989,7 +3075,7 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
thePrivs.getWgoBitmap().to_ulong());
std::string setClause (buf);
- pObj->describe(traceMsg);
+ pObjectUsage->describe(traceMsg);
traceMsg.insert (0, "updated object usage ");
// update the row
retcode = objectPrivsTable.updateWhere(setClause, whereClause);
@@ -2998,13 +3084,6 @@ PrivStatus PrivMgrPrivileges::revokeObjectPriv (const ComObjectType objectType,
deleteListOfAffectedObjects(listOfObjects);
return retcode;
}
- // Update any corresponding column-level privileges.
- retcode = columnPrivsTable.updateWhere(setClause,whereClause);
- if (retcode == STATUS_ERROR)
- {
- deleteListOfAffectedObjects(listOfObjects);
- return retcode;
- }
}
}
@@ -3314,12 +3393,12 @@ bool PrivMgrPrivileges::checkColumnRevokeRestrict (
{
ColPrivEntry updatedEntry = (ColPrivEntry)colPrivsToRevoke[j];
- if (updatedEntry.columnOrdinal == currentRow.columnOrdinal_)
+ if (updatedEntry.getColumnOrdinal() == currentRow.columnOrdinal_)
{
- PrivColumnBitmap newPrivsBitmap = updatedEntry.privsBitmap ^= currentRow.privsBitmap_;
- PrivColumnBitmap newGrantableBitmap = updatedEntry.grantableBitmap ^= currentRow.grantableBitmap_;
- currentRow.current_.privsBitmap = newPrivsBitmap;
- currentRow.current_.grantableBitmap = newGrantableBitmap;
+ PrivColumnBitmap newPrivBitmap = updatedEntry.getPrivBitmap() ^= currentRow.privsBitmap_;
+ PrivColumnBitmap newGrantableBitmap = updatedEntry.getGrantableBitmap() ^= currentRow.grantableBitmap_;
+ currentRow.current_.setPrivBitmap(newPrivBitmap);
+ currentRow.current_.setGrantableBitmap(newGrantableBitmap);
traceMsg = "Adjusted current_ to reflect revoked privileges";
traceMsg += ", grantor is ";
traceMsg += to_string((long long int)currentRow.grantorID_);
@@ -3348,8 +3427,8 @@ bool PrivMgrPrivileges::checkColumnRevokeRestrict (
std::set<int32_t> listOfColumnOrdinals;
for ( size_t i = 0; i < colPrivsToRevoke.size(); i++)
{
- const ColPrivEntry colPrivToRevoke = colPrivsToRevoke[i];
- listOfColumnOrdinals.insert(colPrivToRevoke.columnOrdinal);
+ ColPrivEntry colPrivToRevoke = colPrivsToRevoke[i];
+ listOfColumnOrdinals.insert(colPrivToRevoke.getColumnOrdinal());
}
// Reconstruct tree
@@ -3444,23 +3523,23 @@ void PrivMgrPrivileges::scanColumnBranch( const PrivType pType,
// The listOfColumnOrdinals has this list
ColPrivEntry current = currentRow.current_;
std::set<int32_t>::iterator it;
- it = std::find(listOfColumnOrdinals.begin(), listOfColumnOrdinals.end(), current.columnOrdinal);
+ it = std::find(listOfColumnOrdinals.begin(), listOfColumnOrdinals.end(), current.getColumnOrdinal());
if (it != listOfColumnOrdinals.end())
{
- if ( current.privsBitmap.test(pType) )
+ if ( current.getPrivBitmap().test(pType) )
{
// This grantee has priv. Set corresponding visited flag.
- currentRow.visited_.privsBitmap.set(pType, true);
+ currentRow.visited_.setPriv(pType, true);
- if ( current.grantableBitmap.test(pType))
+ if ( current.getGrantableBitmap().test(pType))
{
// This grantee has wgo.
- if ( currentRow.visited_.grantableBitmap.test(pType) )
+ if ( currentRow.visited_.getGrantableBitmap().test(pType) )
{ // Already processed this subtree.
}
else
{
- currentRow.visited_.grantableBitmap.set(pType, true);
+ currentRow.visited_.setGrantable(pType, true);
// To check: since column level privileges do not have
// an anchor, we choose the object owner as the root.
@@ -3510,17 +3589,17 @@ void PrivMgrPrivileges::scanColumnPublic(
// The listOfColumnOrdinals has this list
ColPrivEntry current = currentRow.current_;
std::set<int32_t>::iterator it;
- it = std::find(listOfColumnOrdinals.begin(), listOfColumnOrdinals.end(), current.columnOrdinal);
+ it = std::find(listOfColumnOrdinals.begin(), listOfColumnOrdinals.end(), current.getColumnOrdinal());
if (it != listOfColumnOrdinals.end())
{
- if ( current.privsBitmap.test(pType) )
+ if ( current.getPrivBitmap().test(pType) )
{
// This grantee has priv. Set corresponding visited flag.
- currentRow.visited_.privsBitmap.set(pType, true);
+ currentRow.visited_.setPriv(pType, true);
// This grantee has wgo.
- if ( currentRow.visited_.grantableBitmap.test(pType) )
- currentRow.visited_.grantableBitmap.set(pType, true);
+ if ( currentRow.visited_.getGrantableBitmap().test(pType) )
+ currentRow.visited_.setGrantable(pType, true);
}
}
} // end scan privsList over all Grantees/Grantors
@@ -4093,6 +4172,84 @@ PrivStatus PrivMgrPrivileges::getRowsForGrantee(
return STATUS_GOOD;
}
+// ****************************************************************************
+// method: summarizeColPrivs
+//
+// This method summarizes column privileges across all grantors.
+//
+// Params:
+// objectReference - the affected object
+// roleIDs - list of roles for the current object owner
+// listOfAffectedObjects - list of affected objects
+// summarizedColRefs - a list of ColumnReference pointers that contain the
+// summarized privileges (the caller is responsible
+// for deleting memory for this parameter
+// ****************************************************************************
+void PrivMgrPrivileges::summarizeColPrivs(
+ const ObjectReference &objReference,
+ const std::vector<int32_t> &roleIDs,
+ const std::vector<ObjectUsage *> &listOfAffectedObjects,
+ std::vector<ColumnReference *> &summarizedColRefs)
+{
+ std::string traceMsg;
+ objReference.describe(traceMsg);
+ traceMsg.insert (0, "summarizing column privileges ");
+ log (__FILE__, traceMsg, -1);
+
+ // objReference.columnReferences is the list of columns for RI constraints
+ // referencing the referenced table
+ std::vector<ColumnReference *> *colRefs = objReference.columnReferences;
+ for (size_t i = 0; i < colRefs->size(); i++)
+ {
+ ColumnReference *colRef = (*colRefs)[i];
+ colRef->describe(traceMsg);
+ log (__FILE__, traceMsg, i);
+
+ // get COLUMN_PRIVILEGES rows where the grantee for the column has received
+ // privileges - the row list is in memory so this does not require I/O
+ std::vector<PrivMgrMDRow *> rowList;
+ getColRowsForGranteeOrdinal(objReference.objectOwner,
+ colRef->columnOrdinal,
+ roleIDs,
+ rowList);
+
+ // go through the rowList to summarize the original and current privileges
+ // We do a union operation to capture privileges from all grantors
+ ColumnReference *summarized = new ColumnReference;
+ summarized->columnOrdinal = colRef->columnOrdinal;
+ for (int32_t i = 0; i < rowList.size();++i)
+ {
+ ColumnPrivsMDRow &row = static_cast<ColumnPrivsMDRow &> (*rowList[i]);
+ PrivMgrCoreDesc originalPrivs(row.privsBitmap_, row.grantableBitmap_);
+
+ ColumnReference ref;
+ ref.columnOrdinal = row.columnOrdinal_;
+ ref.originalPrivs = originalPrivs;
+ ref.updatedPrivs = originalPrivs;
+
+ // Update if privileges have been changed by request
+ for (size_t j = 0; j < listOfAffectedObjects.size(); j++)
+ {
+ ObjectUsage *currentObj = listOfAffectedObjects[j];
+ if (currentObj->objectUID == row.objectUID_ &&
+ grantorID_ == row.grantorID_ &&
+ objReference.objectOwner == row.granteeID_ )
+ {
+ ColumnReference *changedRef = currentObj->findColumn(row.columnOrdinal_);
+ if (changedRef)
+ ref.updatedPrivs = changedRef->updatedPrivs;
+ }
+ }
+
+ summarized->originalPrivs.unionOfPrivs(ref.originalPrivs);
+ summarized->updatedPrivs.unionOfPrivs(ref.updatedPrivs);
+ }
+
+ // Add column ref to the list
+ summarizedColRefs.push_back(summarized);
+ }
+}
+
// *****************************************************************************
// * Method: summarizeCurrentAndOriginalPrivs
// *
@@ -4137,12 +4294,12 @@ PrivStatus PrivMgrPrivileges::summarizeCurrentAndOriginalPrivs(
PrivMgrCoreDesc current = original;
for (size_t j = 0; j < listOfChangedPrivs.size(); j++)
{
- ObjectUsage *pObj = listOfChangedPrivs[j];
- if (pObj->objectUID == row.objectUID_ &&
+ ObjectUsage *pObjectUsage = listOfChangedPrivs[j];
+ if (pObjectUsage->objectUID == row.objectUID_ &&
grantorID_ == row.grantorID_ &&
- pObj->granteeID == row.granteeID_ )
+ pObjectUsage->granteeID == row.granteeID_ )
{
- current = pObj->updatedPrivs.getTablePrivs();
+ current = pObjectUsage->updatedPrivs.getTablePrivs();
}
}
summarizedOriginalPrivs.unionOfPrivs(original);
@@ -4861,7 +5018,7 @@ static ColPrivEntry * findColumnEntry(
{
for (size_t i = 0; i < colPrivEntries.size(); i++)
- if (colPrivEntries[i].columnOrdinal == columnOrdinal)
+ if (colPrivEntries[i].getColumnOrdinal() == columnOrdinal)
return & colPrivEntries[i];
return NULL;
@@ -4979,9 +5136,9 @@ static void getColRowsForGranteeGrantor(
if (row.grantorID_ == grantorID && row.granteeID_ == granteeID)
{
- colPrivGrant.columnOrdinal = row.columnOrdinal_;
- colPrivGrant.privsBitmap = row.privsBitmap_.to_ulong();
- colPrivGrant.grantableBitmap = row.grantableBitmap_.to_ulong();
+ colPrivGrant.setColumnOrdinal(row.columnOrdinal_);
+ colPrivGrant.setPrivBitmap(row.privsBitmap_.to_ulong());
+ colPrivGrant.setGrantableBitmap(row.grantableBitmap_.to_ulong());
grantedColPrivs.push_back(colPrivGrant);
}
@@ -5085,58 +5242,58 @@ std::vector<ColPrivSpec> &colPrivsArray =
privStatus = STATUS_GOOD;
-// Grantor may have column WGO from two sources, object-level grants on the
-// object and column-level grants. First check the object-level grants.
+ // Grantor may have column WGO from two sources, object-level grants on the
+ // object and column-level grants. First check the object-level grants.
-std::vector<PrivMgrMDRow *> objRowList;
+ std::vector<PrivMgrMDRow *> objRowList;
- // Get object privileges that the grantor has been granted - that is, the
- // grantor becomes the grantee.
- privStatus = getRowsForGrantee(objectUID_,grantorID_,true,roleIDs,objRowList,NULL);
- if (privStatus == STATUS_ERROR)
- return privStatus;
+ // Get object privileges that the grantor has been granted - that is, the
+ // grantor becomes the grantee.
+ privStatus = getRowsForGrantee(objectUID_,grantorID_,true,roleIDs,objRowList,NULL);
+ if (privStatus == STATUS_ERROR)
+ return privStatus;
-// For each privilege to grant, see if the grantor has been granted that
-// privilege WITH GRANT OPTION (WGO). If so, note it in the colPrivsArray entry.
-// If the grantor does not have WGO, note that we have to check column
-// privileges for at least one grant.
-bool checkColumnPrivs = false;
+ // For each privilege to grant, see if the grantor has been granted that
+ // privilege WITH GRANT OPTION (WGO). If so, note it in the colPrivsArray entry.
+ // If the grantor does not have WGO, note that we have to check column
+ // privileges for at least one grant.
+ bool checkColumnPrivs = false;
for (size_t i = 0; i < colPrivsArray.size(); i++)
{
- ColPrivSpec &colPrivEntry = colPrivsArray[i];
- colPrivEntry.grantorHasWGO = false;
+ ColPrivSpec &colPrivSpec = colPrivsArray[i];
+ colPrivSpec.grantorHasWGO = false;
for (size_t j = 0; j < objRowList.size(); j++)
{
ObjectPrivsMDRow &objectRow = static_cast<ObjectPrivsMDRow &> (*objRowList[j]);
- if (objectRow.grantableBitmap_.test(colPrivEntry.privType))
+ if (objectRow.grantableBitmap_.test(colPrivSpec.privType))
{
- colPrivEntry.grantorHasWGO = true;
+ colPrivSpec.grantorHasWGO = true;
break;
}
}
- if (!colPrivEntry.grantorHasWGO)
+ if (!colPrivSpec.grantorHasWGO)
checkColumnPrivs = true;
}
-// If object-level privileges are sufficient to grant the column-level
-// privileges, no need to read COLUMN_PRIVILEGES table.
+ // If object-level privileges are sufficient to grant the column-level
+ // privileges, no need to read COLUMN_PRIVILEGES table.
if (!checkColumnPrivs)
return true;
-// The grantor did not have WGO at the object level for at least one
-// of the privileges to be granted; see if they have the column privilege WGO.
+ // The grantor did not have WGO at the object level for at least one
+ // of the privileges to be granted; see if they have the column privilege WGO.
-// Fetch any relevant WGO rows from COLUMN_PRIVILEGES.
-std::vector<PrivMgrMDRow *> colRowList;
+ // Fetch any relevant WGO rows from COLUMN_PRIVILEGES.
+ std::vector<PrivMgrMDRow *> colRowList;
- // Get object privileges that the grantor has been granted - that is, the
- // grantor becomes the grantee.
- privStatus = getRowsForGrantee(objectUID_,grantorID_,false,roleIDs,colRowList,NULL);
- if (privStatus == STATUS_ERROR)
- return privStatus;
+ // Get object privileges that the grantor has been granted - that is, the
+ // grantor becomes the grantee.
+ privStatus = getRowsForGrantee(objectUID_,grantorID_,false,roleIDs,colRowList,NULL);
+ if (privStatus == STATUS_ERROR)
+ return privStatus;
for (size_t i = 0; i < colPrivsArray.size(); i++)
{
@@ -5145,21 +5302,21 @@ std::vector<PrivMgrMDRow *> colRowList;
if (colPrivsArray[i].grantorHasWGO)
continue;
- ColPrivSpec &colPrivEntry = colPrivsArray[i];
+ ColPrivSpec &colPrivSpec = colPrivsArray[i];
// See if the grantor has been granted WGO at column-level for priv.
for (size_t j = 0; j < colRowList.size(); j++)
{
ColumnPrivsMDRow &columnRow = static_cast<ColumnPrivsMDRow &> (*colRowList[i]);
- if (columnRow.grantableBitmap_.test(colPrivEntry.privType))
+ if (columnRow.grantableBitmap_.test(colPrivSpec.privType))
{
- colPrivEntry.grantorHasWGO = true;
+ colPrivSpec.grantorHasWGO = true;
break;
}
}
// If the grantor does not have an object-level or column-level WGO
// for one of the privs to grant, return an error.
- if (!colPrivEntry.grantorHasWGO)
+ if (!colPrivSpec.grantorHasWGO)
{
privStatus = STATUS_NOTFOUND;
return false;
@@ -5234,7 +5391,7 @@ static bool hasGrantedColumnPriv(
for (size_t i = 0; i < colPrivsArray.size(); i++)
{
- const ColPrivSpec &colPrivEntry = colPrivsArray[i];
+ const ColPrivSpec &colPrivSpec = colPrivsArray[i];
bool grantFound = false;
for (size_t j = 0; j < colRowList.size(); j++)
{
@@ -5243,8 +5400,8 @@ static bool hasGrantedColumnPriv(
// Only look at rows with the requested grantor and grantee
if (columnRow.grantorID_ == grantorID && columnRow.granteeID_ == granteeID)
{
- if (columnRow.columnOrdinal_ == colPrivEntry.columnOrdinal &&
- columnRow.privsBitmap_.test(colPrivEntry.privType))
+ if (columnRow.columnOrdinal_ == colPrivSpec.columnOrdinal &&
+ columnRow.privsBitmap_.test(colPrivSpec.privType))
{
grantFound = true;
break;
@@ -5254,7 +5411,7 @@ static bool hasGrantedColumnPriv(
if (!grantFound)
{
- privilege = PrivMgrUserPrivs::convertPrivTypeToLiteral((PrivType)colPrivEntry.privType);
+ privilege = PrivMgrUserPrivs::convertPrivTypeToLiteral((PrivType)colPrivSpec.privType);
privStatus = STATUS_NOTFOUND;
return false;
}
@@ -5269,9 +5426,9 @@ static bool hasGrantedColumnPriv(
{
ColPrivEntry grantedColPriv;
- grantedColPriv.columnOrdinal = columnRow.columnOrdinal_;
- grantedColPriv.grantableBitmap = columnRow.grantableBitmap_;
- grantedColPriv.privsBitmap = columnRow.privsBitmap_;
+ grantedColPriv.setColumnOrdinal(columnRow.columnOrdinal_);
+ grantedColPriv.setGrantableBitmap(columnRow.grantableBitmap_);
+ grantedColPriv.setPrivBitmap(columnRow.privsBitmap_);
grantedColPrivs.push_back(grantedColPriv);
}
}
@@ -6282,3 +6439,5 @@ char whereClause[1000];
+
+
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/PrivMgrPrivileges.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.h b/core/sql/sqlcomp/PrivMgrPrivileges.h
index 473e2cd..c62c0e4 100644
--- a/core/sql/sqlcomp/PrivMgrPrivileges.h
+++ b/core/sql/sqlcomp/PrivMgrPrivileges.h
@@ -64,14 +64,40 @@ public:
class ColPrivEntry
{
public:
- int32_t columnOrdinal;
- PrivColumnBitmap privsBitmap;
- PrivColumnBitmap grantableBitmap;
- bool isUpdate;
+ PrivMgrCoreDesc privDesc_;
+ bool isUpdate_;
+
ColPrivEntry()
- : columnOrdinal(0),isUpdate(false){};
+ : isUpdate_(false){};
ColPrivEntry(const PrivMgrMDRow &row);
ColPrivEntry(const ColPrivEntry &other);
+
+ PrivMgrCoreDesc &getPrivDesc (void) { return privDesc_; }
+
+ int32_t getColumnOrdinal (void) { return privDesc_.getColumnOrdinal(); }
+ PrivColumnBitmap getPrivBitmap (void) { return privDesc_.getPrivBitmap(); }
+ PrivColumnBitmap getGrantableBitmap (void) { return privDesc_.getWgoBitmap(); }
+
+ void setColumnOrdinal (int32_t columnOrdinal)
+ { privDesc_.setColumnOrdinal(columnOrdinal); }
+
+ void setPrivBitmap(PrivMgrBitmap privBitmap)
+ { privDesc_.setPrivBitmap(privBitmap); }
+ void setGrantableBitmap(PrivMgrBitmap grantableBitmap)
+ { privDesc_.setWgoBitmap(grantableBitmap);}
+
+ void setPriv (PrivType privType, bool value)
+ { privDesc_.setPriv(privType, value); }
+ void setGrantable (PrivType privType, bool value)
+ { privDesc_.setWgo(privType, value); }
+
+ void describe (std::string &details) const
+ {
+ details = "column usage - column number is ";
+ details += to_string((long long int) privDesc_.getColumnOrdinal());
+ details += ", isUpdate is ";
+ details += (isUpdate_) ? "true " : "false ";
+ }
};
// *****************************************************************************
@@ -326,6 +352,12 @@ private:
const PrivCommand command,
std::vector<ObjectUsage *> &listOfAffectedObjects);
+ void getColRowsForGranteeOrdinal(
+ const int32_t granteeID,
+ const int32_t columnOrdinal,
+ const std::vector<int32_t> &roleIDs,
+ std::vector<PrivMgrMDRow *> &rowList);
+
PrivStatus getGrantedPrivs(
const int32_t granteeID,
PrivMgrMDRow &row);
@@ -376,6 +408,12 @@ private:
const PrivType pType, // in
const std::vector<PrivMgrMDRow *>& rowList ); // in
+ void summarizeColPrivs(
+ const ObjectReference &objRef,
+ const std::vector<int32_t> &roleIDs,
+ const std::vector<ObjectUsage *> &listOfAffectedObjects,
+ std::vector<ColumnReference *> &columnReferences);
+
PrivStatus summarizeCurrentAndOriginalPrivs(
const int64_t objectUID,
const int32_t granteeID,
[2/5] incubator-trafodion git commit: TRAFODION-1856: Revoke - object
and column privilege checks not integrated for constraints
Posted by sa...@apache.org.
TRAFODION-1856: Revoke - object and column privilege checks not integrated for constraints
Today, when revoking the object REFERENCES privilege, the revoke fails if there
are any RI constraints that require the privilege. However, there may be column
level privileges that exist that would still allow the constraint to be present.
Conversely, when revoking column REFERENCES privilege, the revoke does not
check to see if REFERENCES privilege has been granted at the object level.
In fact, the revoke operation does not check for dependencies on constraints
correctly.
For example:
user1:
create table dept( dept_no int not null primary key, dept_name char(50));
grant references on table dept to user2;
grant references(dept_no) to user2;
user2:
create table empl(empl_no int not null primary key, dept_no int not null);
alter table empl add constraint empl_dept
foreign key (dept_no) references dept;
user1 should be able to "revoke references on table dept from user2" because
user2 still has the references privileges on column dept_no. Vice versa, user1
should be able to "revoke references(dept_no) on dept from user2" because user2
still has the references privilege on table dept.
To make this work, several changes were implemented:
In the existing code, object level privileges use one set of structures to
manage privileges (PrivMgrCoreDesc) and column level privileges use another
(ColPrivEntry). The ColPrivEntry class was changed to use the same base
"PrivMgrCoreDesc" structure as object privileges. This makes comparing things
between objects and columns easier. There is still more work to do in this
area.
There is a method called dealWithConstraints that, among other things, checks
to see if the revoke can occur. Changes were made to check for column level
privileges if object level privileges were no longer available. Revoking
column level privilege now calls this method to make sure the revoke can
proceed.
The dealWithConstraints change required updates to the query that retrieved
referenced table information. In addition to returning the referencing table,
the list of referenced table columns associated with each constraint was
needed. The column information returned was transformed into a new
ColumnReference structure attached to the existing ObjectUsage and
ObjectReference classes. Changes were also required in getConstraintName to get
the RI constraint related to the column which no longer has the privilege.
In addition, the code to remove column level privileges when object level
privileges was removed. In SQL, each grant needs a separate revoke to remove.
So this code did not follow ANSI standard.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/392031a3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/392031a3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/392031a3
Branch: refs/heads/master
Commit: 392031a304b52348aa4bbb8fe3a4e6399c70838f
Parents: 0918828
Author: Roberta Marton <ro...@apache.org>
Authored: Mon Feb 29 20:14:15 2016 +0000
Committer: Roberta Marton <ro...@apache.org>
Committed: Mon Feb 29 20:14:15 2016 +0000
----------------------------------------------------------------------
core/sql/regress/privs2/EXPECTED135 | 329 -----------
core/sql/regress/privs2/EXPECTED142 | 760 +++++++++++++++++++++++++
core/sql/regress/privs2/TEST135 | 43 --
core/sql/regress/privs2/TEST142 | 280 ++++++++++
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 30 +-
core/sql/sqlcomp/PrivMgrDefs.h | 4 +-
core/sql/sqlcomp/PrivMgrMD.cpp | 171 ++++--
core/sql/sqlcomp/PrivMgrMD.h | 129 ++++-
core/sql/sqlcomp/PrivMgrPrivileges.cpp | 793 ++++++++++++++++-----------
core/sql/sqlcomp/PrivMgrPrivileges.h | 48 +-
10 files changed, 1811 insertions(+), 776 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/regress/privs2/EXPECTED135
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs2/EXPECTED135 b/core/sql/regress/privs2/EXPECTED135
index 0d8b0f6..9fbc688 100644
--- a/core/sql/regress/privs2/EXPECTED135
+++ b/core/sql/regress/privs2/EXPECTED135
@@ -648,335 +648,6 @@ End of MXCI Session
--- SQL operation complete.
>>
->>obey TEST135(constraint_tests);
->>-- ============================================================================
->>set schema t135sch;
-
---- SQL operation complete.
->>create table t135_t1 (c1 int not null primary key, c2 int);
-
---- SQL operation complete.
->>
->>-- have user3 create some objects
->>sh sqlci -i "TEST135(user3_objects)" -u sql_user3;
->>create table t135_t3 (c1 int not null primary key, c2 int);
-
---- SQL operation complete.
->>create table t135_t4 (c1 int not null, c2 largeint not null primary key, c3 int);
-
---- SQL operation complete.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>showddl t135_t4;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T4
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
- , C3 INT DEFAULT NULL
- , PRIMARY KEY (C2 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T4 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>exit;
-
-End of MXCI Session
-
->>
->>-- now have user3 create an RI constraint
->>-- fails because user3 has no privs
->>sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
->>alter table t135_t3 add constraint t1_t3 foreign key (c1) references t135sch.t135_t1;
-
-*** ERROR[1017] You are not authorized to perform this operation.
-
---- SQL operation failed with errors.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>-- ============================================================================
->>exit;
-
-End of MXCI Session
-
->>grant references on t135_t1 to sql_user3;
-
---- SQL operation complete.
->>showddl t135_t1;
-
-CREATE TABLE TRAFODION.T135SCH.T135_T1
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH.T135_T1 TO DB__ROOT WITH GRANT OPTION;
- GRANT REFERENCES ON TRAFODION.T135SCH.T135_T1 TO SQL_USER3;
-
---- SQL operation complete.
->>-- operation should succeed
->>sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
->>alter table t135_t3 add constraint t1_t3 foreign key (c1) references t135sch.t135_t1;
-
---- SQL operation complete.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
-ALTER TABLE TRAFODION.T135SCH_USER3.T135_T3 ADD CONSTRAINT
- TRAFODION.T135SCH_USER3.T1_T3 FOREIGN KEY
- (
- C1
- )
- REFERENCES TRAFODION.T135SCH.T135_T1
- (
- C1
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>-- ============================================================================
->>exit;
-
-End of MXCI Session
-
->>
->>-- now try to revoke references privileges
->>revoke references on t135_t1 from sql_user3;
-
-*** ERROR[1025] Request failed. Dependent object TRAFODION."T135SCH_USER3"."T1_T3" exists.
-
---- SQL operation failed with errors.
->>sh sqlci -i "TEST135(user3_drops)" -u sql_user3;
->>drop table t135_t3 cascade;
-
---- SQL operation complete.
->>drop table t135_t4 cascade;
-
---- SQL operation complete.
->>
->>exit;
-
-End of MXCI Session
-
->>revoke references on t135_t1 from sql_user3;
-
---- SQL operation complete.
->>showddl t135_t1;
-
-CREATE TABLE TRAFODION.T135SCH.T135_T1
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH.T135_T1 TO DB__ROOT WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>-- repeat, but grant all privileges instead.
->>-- have user3 create some objects
->>sh sqlci -i "TEST135(user3_objects)" -u sql_user3;
->>create table t135_t3 (c1 int not null primary key, c2 int);
-
---- SQL operation complete.
->>create table t135_t4 (c1 int not null, c2 largeint not null primary key, c3 int);
-
---- SQL operation complete.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>showddl t135_t4;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T4
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
- , C3 INT DEFAULT NULL
- , PRIMARY KEY (C2 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T4 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>exit;
-
-End of MXCI Session
-
->>
->>-- now have user3 create an RI constraint
->>-- fails because user3 has no privs
->>sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
->>alter table t135_t3 add constraint t1_t3 foreign key (c1) references t135sch.t135_t1;
-
-*** ERROR[1017] You are not authorized to perform this operation.
-
---- SQL operation failed with errors.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>-- ============================================================================
->>exit;
-
-End of MXCI Session
-
->>grant all on t135_t1 to sql_user3;
-
---- SQL operation complete.
->>showddl t135_t1;
-
-CREATE TABLE TRAFODION.T135SCH.T135_T1
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH.T135_T1 TO DB__ROOT WITH GRANT OPTION;
- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH.T135_T1
- TO SQL_USER3;
-
---- SQL operation complete.
->>-- operation should succeed
->>sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
->>alter table t135_t3 add constraint t1_t3 foreign key (c1) references t135sch.t135_t1;
-
---- SQL operation complete.
->>showddl t135_t3;
-
-CREATE TABLE TRAFODION.T135SCH_USER3.T135_T3
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
-ALTER TABLE TRAFODION.T135SCH_USER3.T135_T3 ADD CONSTRAINT
- TRAFODION.T135SCH_USER3.T1_T3 FOREIGN KEY
- (
- C1
- )
- REFERENCES TRAFODION.T135SCH.T135_T1
- (
- C1
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH_USER3.T135_T3 TO SQL_USER3 WITH GRANT OPTION;
-
---- SQL operation complete.
->>
->>-- ============================================================================
->>exit;
-
-End of MXCI Session
-
->>
->>-- now try to revoke references privileges
->>revoke references on t135_t1 from sql_user3;
-
-*** ERROR[1025] Request failed. Dependent object TRAFODION."T135SCH_USER3"."T1_T3" exists.
-
---- SQL operation failed with errors.
->>sh sqlci -i "TEST135(user3_drops)" -u sql_user3;
->>drop table t135_t3 cascade;
-
---- SQL operation complete.
->>drop table t135_t4 cascade;
-
---- SQL operation complete.
->>
->>exit;
-
-End of MXCI Session
-
->>revoke references on t135_t1 from sql_user3;
-
---- SQL operation complete.
->>showddl t135_t1;
-
-CREATE TABLE TRAFODION.T135SCH.T135_T1
- (
- C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
- , C2 INT DEFAULT NULL
- , PRIMARY KEY (C1 ASC)
- )
-;
-
--- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T135SCH.T135_T1 TO DB__ROOT WITH GRANT OPTION;
- GRANT SELECT, INSERT, DELETE, UPDATE ON TRAFODION.T135SCH.T135_T1 TO
- SQL_USER3;
-
---- SQL operation complete.
->>
->>drop table t135_t1 cascade;
-
---- SQL operation complete.
->>
>>obey TEST135(udr_tests);
>>-- ============================================================================
>>-- To create a function/table_mapping function, or SPJ, you need
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/regress/privs2/EXPECTED142
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs2/EXPECTED142 b/core/sql/regress/privs2/EXPECTED142
new file mode 100644
index 0000000..2e9fc77
--- /dev/null
+++ b/core/sql/regress/privs2/EXPECTED142
@@ -0,0 +1,760 @@
+>>obey TEST142(create_db);
+>>create schema t142user1 authorization sql_user1;
+
+--- SQL operation complete.
+>>create schema t142user2 authorization sql_user2;
+
+--- SQL operation complete.
+>>create schema t142user3 authorization sql_user3;
+
+--- SQL operation complete.
+>>create schema t142user4 authorization sql_user4;
+
+--- SQL operation complete.
+>>create schema t142user5 authorization sql_user5;
+
+--- SQL operation complete.
+>>create schema t142user6 authorization sql_user6;
+
+--- SQL operation complete.
+>>
+>>set schema t142user4;
+
+--- SQL operation complete.
+>>create table referencedTable
++>( c1 int not null primary key,
++> c2 int not null,
++> c3 char(10) not null,
++> c4 char(10) not null,
++> c5 largeint not null );
+
+--- SQL operation complete.
+>>alter table referencedTable add constraint u1 unique (c3, c2);
+
+--- SQL operation complete.
+>>alter table referencedTable add constraint u2 unique (c4);
+
+--- SQL operation complete.
+>>alter table referencedTable add constraint u3 unique(c5);
+
+--- SQL operation complete.
+>>showddl referencedTable;
+
+CREATE TABLE TRAFODION.T142USER4.REFERENCEDTABLE
+ (
+ C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , C4 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , C5 LARGEINT NO DEFAULT NOT NULL NOT DROPPABLE
+ , PRIMARY KEY (C1 ASC)
+ )
+;
+
+-- The following index is a system created index --
+CREATE UNIQUE INDEX U1 ON TRAFODION.T142USER4.REFERENCEDTABLE
+ (
+ C3 ASC
+ , C2 ASC
+ )
+;
+
+-- The following index is a system created index --
+CREATE UNIQUE INDEX U2 ON TRAFODION.T142USER4.REFERENCEDTABLE
+ (
+ C4 ASC
+ )
+;
+
+-- The following index is a system created index --
+CREATE UNIQUE INDEX U3 ON TRAFODION.T142USER4.REFERENCEDTABLE
+ (
+ C5 ASC
+ )
+;
+
+ALTER TABLE TRAFODION.T142USER4.REFERENCEDTABLE ADD CONSTRAINT
+ TRAFODION.T142USER4.U1 UNIQUE
+ (
+ C3
+ , C2
+ )
+;
+
+ALTER TABLE TRAFODION.T142USER4.REFERENCEDTABLE ADD CONSTRAINT
+ TRAFODION.T142USER4.U2 UNIQUE
+ (
+ C4
+ )
+;
+
+ALTER TABLE TRAFODION.T142USER4.REFERENCEDTABLE ADD CONSTRAINT
+ TRAFODION.T142USER4.U3 UNIQUE
+ (
+ C5
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER4.REFERENCEDTABLE TO SQL_USER4 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>-- compile cpp program for function
+>>sh rm -f ./etest140.dll;
+>>sh sh $$scriptsdir$$/tools/dll-compile.ksh etest140.cpp
++> 2>&1 | tee LOG140-SECONDARY;
+>>set pattern $$DLL$$ etest140.dll;
+>>set pattern $$QUOTE$$ '''';
+>>
+>>-- create the library and udf
+>>create library t142_l1 file $$QUOTE$$ $$REGRRUNDIR$$/$$DLL$$ $$QUOTE$$ ;
+
+--- SQL operation complete.
+>>create function t142_translatePrivsBitmap(bitmap largeint) returns (bitmap_string char (20))
++>language c parameter style sql external name 'translateBitmap'
++>library t142_l1
++>deterministic no sql final call allow any parallelism state area size 1024 ;
+
+--- SQL operation complete.
+>>grant execute on function t142_translatePrivsBitmap to "PUBLIC";
+
+--- SQL operation complete.
+>>
+>>set schema t142user1;
+
+--- SQL operation complete.
+>>create table user1
++>(u1_c1 int not null,
++> u1_c2 int not null primary key,
++> u1_c3 char(10) not null,
++> u1_c4 char(10));
+
+--- SQL operation complete.
+>>showddl user1;
+
+CREATE TABLE TRAFODION.T142USER1.USER1
+ (
+ U1_C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U1_C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U1_C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U1_C4 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT DEFAULT NULL
+ , PRIMARY KEY (U1_C2 ASC)
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER1.USER1 TO SQL_USER1 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>set schema t142user2;
+
+--- SQL operation complete.
+>>create table user2
++>(u2_c1 int not null,
++> u2_c2 int not null primary key,
++> u2_c3 char(10) not null,
++> u2_c4 largeint);
+
+--- SQL operation complete.
+>>showddl user2;
+
+CREATE TABLE TRAFODION.T142USER2.USER2
+ (
+ U2_C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U2_C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U2_C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U2_C4 LARGEINT DEFAULT NULL
+ , PRIMARY KEY (U2_C2 ASC)
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER2.USER2 TO SQL_USER2 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>set schema t142user3;
+
+--- SQL operation complete.
+>>create table user3
++>(u3_c1 int not null,
++> u3_c2 int not null primary key,
++> u3_c3 char(10) not null,
++> u3_c4 char(10));
+
+--- SQL operation complete.
+>>showddl user3;
+
+CREATE TABLE TRAFODION.T142USER3.USER3
+ (
+ U3_C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U3_C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U3_C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U3_C4 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT DEFAULT NULL
+ , PRIMARY KEY (U3_C2 ASC)
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER3.USER3 TO SQL_USER3 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>set schema t142user5;
+
+--- SQL operation complete.
+>>create table user5
++>(u5_c1 int not null,
++> u5_c2 int not null primary key,
++> u5_c3 char(10) not null,
++> u5_c4 char(10));
+
+--- SQL operation complete.
+>>showddl user5;
+
+CREATE TABLE TRAFODION.T142USER5.USER5
+ (
+ U5_C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U5_C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U5_C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U5_C4 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT DEFAULT NULL
+ , PRIMARY KEY (U5_C2 ASC)
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER5.USER5 TO SQL_USER5 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>set schema t142user6;
+
+--- SQL operation complete.
+>>create table user6
++>(u6_c1 int not null,
++> u6_c2 int not null primary key,
++> u6_c3 char(10) not null,
++> u6_c4 char(10));
+
+--- SQL operation complete.
+>>showddl user6;
+
+CREATE TABLE TRAFODION.T142USER6.USER6
+ (
+ U6_C1 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U6_C2 INT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U6_C3 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT NO DEFAULT NOT NULL NOT DROPPABLE
+ , U6_C4 CHAR(10) CHARACTER SET ISO88591 COLLATE
+ DEFAULT DEFAULT NULL
+ , PRIMARY KEY (U6_C2 ASC)
+ )
+;
+
+-- GRANT SELECT, INSERT, DELETE, UPDATE, REFERENCES ON TRAFODION.T142USER6.USER6 TO SQL_USER6 WITH GRANT OPTION;
+
+--- SQL operation complete.
+>>
+>>obey TEST142(set_up);
+>>set schema "_PRIVMGR_MD_";
+
+--- SQL operation complete.
+>>prepare get_privs from
++>select distinct
++> trim(substring (o.object_name,1,20)) as object_name,
++> grantor_id, grantee_id, 'all',
++> t142user4.t142_translatePrivsBitmap(privileges_bitmap) as granted_privs,
++> t142user4.t142_translatePrivsBitmap(grantable_bitmap) as grantable_privs
++>from object_privileges p, "_MD_".objects o
++>where p.object_uid in
++> (select object_uid
++> from "_MD_".objects
++> where schema_name like 'T142USER%'
++> and object_name not like 'SB_%')
++> and p.object_uid = o.object_uid
++>union
++> (select distinct
++> trim(substring (o.object_name,1,20)) as object_name,
++> grantor_id, grantee_id, cast (column_number as char(3)),
++> t142user4.t142_translatePrivsBitmap(privileges_bitmap) as granted_privs,
++> t142user4.t142_translatePrivsBitmap(grantable_bitmap) as grantable_privs
++> from column_privileges p, "_MD_".objects o
++> where p.object_uid in
++> (select object_uid
++> from "_MD_".objects
++> where schema_name like 'T142USER%'
++> and object_name not like 'SB_%')
++> and p.object_uid = o.object_uid)
++>order by 1, 2, 3, 4
++>;
+
+--- SQL command prepared.
+>>
+>>obey TEST142(test_grants);
+>>-- =================================================================
+>>-- this set of tests run basic grant tests for constraints
+>>-- schema t142user4 contains the referenced table
+>>-- =================================================================
+>>set schema t142user4;
+
+--- SQL operation complete.
+>>
+>>-- all should fail, no one has permissions
+>>execute get_privs;
+
+OBJECT_NAME GRANTOR_ID GRANTEE_ID (EXPR) GRANTED_PRIVS GRANTABLE_PRIVS
+-------------------------------------------------------------------------------- -------------------- -------------------- ------ -------------------- --------------------
+
+REFERENCEDTABLE -2 33337 all SIDU-R- SIDU-R-
+T142_L1 -2 33337 all ---UG-- ---UG--
+T142_TRANSLATEPRIVSB -2 33337 all ------E ------E
+T142_TRANSLATEPRIVSB 33337 -1 all ------E NONE
+USER1 -2 33334 all SIDU-R- SIDU-R-
+USER2 -2 33335 all SIDU-R- SIDU-R-
+USER3 -2 33336 all SIDU-R- SIDU-R-
+USER5 -2 33338 all SIDU-R- SIDU-R-
+USER6 -2 33339 all SIDU-R- SIDU-R-
+
+--- 9 row(s) selected.
+>>sh sqlci -i "TEST142(user1_cmds)" -u sql_user1;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER1
+
+--- 1 row(s) selected.
+>>set schema t142user1;
+
+--- SQL operation complete.
+>>alter table user1 add constraint u1_fk1 foreign key (u1_c4, u1_c1)
++> references t142user4.referencedTable (c3, c2);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>alter table user1 add constraint u1_fk2 foreign key (u1_c2)
++> references t142user4.referencedTable(c1);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER2
+
+--- 1 row(s) selected.
+>>set schema t142user2;
+
+--- SQL operation complete.
+>>alter table user2 add constraint u2_fk1 foreign key (u2_c3)
++> references t142user4.referencedTable (c4);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>alter table user2 add constraint u2_fk2 foreign key (u2_c4)
++> references t142user4.referencedTable(c5);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user3_cmds)" -u sql_user3;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER3
+
+--- 1 row(s) selected.
+>>set schema t142user3;
+
+--- SQL operation complete.
+>>alter table user3 add constraint u3_fk1 foreign key (u3_c1)
++> references t142user4.referencedTable;
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user5_cmds)" -u sql_user5;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER5
+
+--- 1 row(s) selected.
+>>set schema t142user5;
+
+--- SQL operation complete.
+>>alter table user5 add constraint u5_fk1 foreign key (u5_c1)
++> references t142user4.referencedTable;
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user6_cmds)" -u sql_user6;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER6
+
+--- 1 row(s) selected.
+>>set schema t142user6;
+
+--- SQL operation complete.
+>>alter table user6 add constraint u6_fk1 foreign key (u6_c3)
++> references t142user4.referencedTable(c4);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>-- this case always fails
+>>alter table user6 add constraint u6_fk2 foreign key (u6_c1)
++> references t142user4.referencedTable(c2);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>
+>>-- user1, user3, & user5 can create constraints
+>>grant references on referencedTable to sql_user1;
+
+--- SQL operation complete.
+>>grant references(c2, c3) on referencedTable to sql_user1;
+
+--- SQL operation complete.
+>>grant all_dml on referencedTable to sql_user3 with grant option;
+
+--- SQL operation complete.
+>>grant references on referencedTable to sql_user5 by sql_user3;
+
+--- SQL operation complete.
+>>execute get_privs;
+
+OBJECT_NAME GRANTOR_ID GRANTEE_ID (EXPR) GRANTED_PRIVS GRANTABLE_PRIVS
+-------------------------------------------------------------------------------- -------------------- -------------------- ------ -------------------- --------------------
+
+REFERENCEDTABLE -2 33337 all SIDU-R- SIDU-R-
+REFERENCEDTABLE 33336 33338 all -----R- NONE
+REFERENCEDTABLE 33337 33334 1 -----R- NONE
+REFERENCEDTABLE 33337 33334 2 -----R- NONE
+REFERENCEDTABLE 33337 33334 all -----R- NONE
+REFERENCEDTABLE 33337 33336 all SIDU-R- SIDU-R-
+T142_L1 -2 33337 all ---UG-- ---UG--
+T142_TRANSLATEPRIVSB -2 33337 all ------E ------E
+T142_TRANSLATEPRIVSB 33337 -1 all ------E NONE
+USER1 -2 33334 all SIDU-R- SIDU-R-
+USER2 -2 33335 all SIDU-R- SIDU-R-
+USER3 -2 33336 all SIDU-R- SIDU-R-
+USER5 -2 33338 all SIDU-R- SIDU-R-
+USER6 -2 33339 all SIDU-R- SIDU-R-
+
+--- 14 row(s) selected.
+>>
+>>sh sqlci -i "TEST142(user1_cmds)" -u sql_user1;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER1
+
+--- 1 row(s) selected.
+>>set schema t142user1;
+
+--- SQL operation complete.
+>>alter table user1 add constraint u1_fk1 foreign key (u1_c4, u1_c1)
++> references t142user4.referencedTable (c3, c2);
+
+--- SQL operation complete.
+>>alter table user1 add constraint u1_fk2 foreign key (u1_c2)
++> references t142user4.referencedTable(c1);
+
+--- SQL operation complete.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user3_cmds)" -u sql_user3;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER3
+
+--- 1 row(s) selected.
+>>set schema t142user3;
+
+--- SQL operation complete.
+>>alter table user3 add constraint u3_fk1 foreign key (u3_c1)
++> references t142user4.referencedTable;
+
+--- SQL operation complete.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>sh sqlci -i "TEST142(user5_cmds)" -u sql_user5;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER5
+
+--- 1 row(s) selected.
+>>set schema t142user5;
+
+--- SQL operation complete.
+>>alter table user5 add constraint u5_fk1 foreign key (u5_c1)
++> references t142user4.referencedTable;
+
+--- SQL operation complete.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>
+>>-- first time, user2 can only create one, second time it works
+>>grant references (c5) on referencedTable to sql_user2;
+
+--- SQL operation complete.
+>>sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER2
+
+--- 1 row(s) selected.
+>>set schema t142user2;
+
+--- SQL operation complete.
+>>alter table user2 add constraint u2_fk1 foreign key (u2_c3)
++> references t142user4.referencedTable (c4);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>alter table user2 add constraint u2_fk2 foreign key (u2_c4)
++> references t142user4.referencedTable(c5);
+
+--- SQL operation complete.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>grant references (c4) on referencedTable to sql_user2 with grant option;
+
+--- SQL operation complete.
+>>sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER2
+
+--- 1 row(s) selected.
+>>set schema t142user2;
+
+--- SQL operation complete.
+>>alter table user2 add constraint u2_fk1 foreign key (u2_c3)
++> references t142user4.referencedTable (c4);
+
+--- SQL operation complete.
+>>alter table user2 add constraint u2_fk2 foreign key (u2_c4)
++> references t142user4.referencedTable(c5);
+
+*** ERROR[1043] Constraint TRAFODION.T142USER2.U2_FK2 already exists.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>
+>>-- user6 can create first but not second constraint
+>>grant references (c4) on referencedTable to sql_user6 by sql_user2;
+
+--- SQL operation complete.
+>>sh sqlci -i "TEST142(user6_cmds)" -u sql_user6;
+>>values (user);
+
+(EXPR)
+---------------------------------------------------------------------------------------------------------------------------------
+
+SQL_USER6
+
+--- 1 row(s) selected.
+>>set schema t142user6;
+
+--- SQL operation complete.
+>>alter table user6 add constraint u6_fk1 foreign key (u6_c3)
++> references t142user4.referencedTable(c4);
+
+--- SQL operation complete.
+>>-- this case always fails
+>>alter table user6 add constraint u6_fk2 foreign key (u6_c1)
++> references t142user4.referencedTable(c2);
+
+*** ERROR[4481] The user does not have REFERENCES privilege on table or view REFERENCEDTABLE.
+
+--- SQL operation failed with errors.
+>>
+>>exit;
+
+End of MXCI Session
+
+>>
+>>obey TEST142(test_revokes);
+>>-- ============================================================================
+>>-- verify that revoking privileges handle REFERENCES privilege correctly
+>>-- ============================================================================
+>>set schema t142user4;
+
+--- SQL operation complete.
+>>execute get_privs;
+
+OBJECT_NAME GRANTOR_ID GRANTEE_ID (EXPR) GRANTED_PRIVS GRANTABLE_PRIVS
+-------------------------------------------------------------------------------- -------------------- -------------------- ------ -------------------- --------------------
+
+REFERENCEDTABLE -2 33337 all SIDU-R- SIDU-R-
+REFERENCEDTABLE 33335 33339 3 -----R- NONE
+REFERENCEDTABLE 33336 33338 all -----R- NONE
+REFERENCEDTABLE 33337 33334 1 -----R- NONE
+REFERENCEDTABLE 33337 33334 2 -----R- NONE
+REFERENCEDTABLE 33337 33334 all -----R- NONE
+REFERENCEDTABLE 33337 33335 3 -----R- -----R-
+REFERENCEDTABLE 33337 33335 4 -----R- NONE
+REFERENCEDTABLE 33337 33336 all SIDU-R- SIDU-R-
+T142_L1 -2 33337 all ---UG-- ---UG--
+T142_TRANSLATEPRIVSB -2 33337 all ------E ------E
+T142_TRANSLATEPRIVSB 33337 -1 all ------E NONE
+USER1 -2 33334 all SIDU-R- SIDU-R-
+USER2 -2 33335 all SIDU-R- SIDU-R-
+USER3 -2 33336 all SIDU-R- SIDU-R-
+USER5 -2 33338 all SIDU-R- SIDU-R-
+USER6 -2 33339 all SIDU-R- SIDU-R-
+
+--- 17 row(s) selected.
+>>
+>>-- unable to revoke because of u1_fk2
+>>revoke references on referencedTable from sql_user1;
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK2" exists.
+
+--- SQL operation failed with errors.
+>>-- revoke succeeds because user2 has references at the object level
+>>revoke references (c2, c3) on referencedTable from sql_user1;
+
+--- SQL operation complete.
+>>
+>>-- remove u1_fk2 and retry
+>>alter table t142user1.user1 drop constraint u1_fk2;
+
+--- SQL operation complete.
+>>grant references (c2, c3) on referencedTable to sql_user1;
+
+--- SQL operation complete.
+>>
+>>-- now able to revoke references privilege
+>>revoke references on referencedTable from sql_user1;
+
+--- SQL operation complete.
+>>-- but not able to remove column privileges
+>>revoke references (c2) on referencedTable from sql_user1;
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+--- SQL operation failed with errors.
+>>revoke references (c3) on referencedTable from sql_user1;
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+--- SQL operation failed with errors.
+>>revoke references (c2, c3) on referencedTable from sql_user1;
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+--- SQL operation failed with errors.
+>>
+>>-- and vice versa
+>>grant references on referencedTable to sql_user1;
+
+--- SQL operation complete.
+>>-- can revoke
+>>revoke references (c2) on referencedTable from sql_user1;
+
+--- SQL operation complete.
+>>revoke references (c3) on referencedTable from sql_user1;
+
+--- SQL operation complete.
+>>-- cannot revoke
+>>revoke references on referencedTable from sql_user1;
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+*** ERROR[1025] Request failed. Dependent object TRAFODION."T142USER1"."U1_FK1" exists.
+
+--- SQL operation failed with errors.
+>>
+>>-- drop constraint and revoke succeeds
+>>alter table t142user1.user1 drop constraint u1_fk1;
+
+--- SQL operation complete.
+>>revoke references on referencedTable from sql_user1;
+
+--- SQL operation complete.
+>>
+>>log;
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/regress/privs2/TEST135
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs2/TEST135 b/core/sql/regress/privs2/TEST135
index fb71235..1c15345 100755
--- a/core/sql/regress/privs2/TEST135
+++ b/core/sql/regress/privs2/TEST135
@@ -40,7 +40,6 @@ sh rm -f LOG135-SECONDARY;
obey TEST135(set_up);
obey TEST135(tbl_tests);
obey TEST135(view_tests);
-obey TEST135(constraint_tests);
obey TEST135(udr_tests);
obey TEST135(negative_tests);
log;
@@ -238,48 +237,6 @@ drop table t135_t2 cascade;
drop role t135_role1;
drop role t135_role2;
-?section constraint_tests
--- ============================================================================
-set schema t135sch;
-create table t135_t1 (c1 int not null primary key, c2 int);
-
--- have user3 create some objects
-sh sqlci -i "TEST135(user3_objects)" -u sql_user3;
-
--- now have user3 create an RI constraint
--- fails because user3 has no privs
-sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
-grant references on t135_t1 to sql_user3;
-showddl t135_t1;
--- operation should succeed
-sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
-
--- now try to revoke references privileges
-revoke references on t135_t1 from sql_user3;
-sh sqlci -i "TEST135(user3_drops)" -u sql_user3;
-revoke references on t135_t1 from sql_user3;
-showddl t135_t1;
-
--- repeat, but grant all privileges instead.
--- have user3 create some objects
-sh sqlci -i "TEST135(user3_objects)" -u sql_user3;
-
--- now have user3 create an RI constraint
--- fails because user3 has no privs
-sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
-grant all on t135_t1 to sql_user3;
-showddl t135_t1;
--- operation should succeed
-sh sqlci -i "TEST135(user3_constraint)" -u sql_user3;
-
--- now try to revoke references privileges
-revoke references on t135_t1 from sql_user3;
-sh sqlci -i "TEST135(user3_drops)" -u sql_user3;
-revoke references on t135_t1 from sql_user3;
-showddl t135_t1;
-
-drop table t135_t1 cascade;
-
?section udr_tests
-- ============================================================================
-- To create a function/table_mapping function, or SPJ, you need
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/regress/privs2/TEST142
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs2/TEST142 b/core/sql/regress/privs2/TEST142
new file mode 100755
index 0000000..8cf7f3c
--- /dev/null
+++ b/core/sql/regress/privs2/TEST142
@@ -0,0 +1,280 @@
+-- ============================================================================
+-- TEST142 - tests grant and revoke privileges for RI constraints
+--
+-- @@@ START COPYRIGHT @@@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied. See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+--
+-- @@@ END COPYRIGHT @@@
+--
+-- ============================================================================
+
+cqd SHOWDDL_DISPLAY_PRIVILEGE_GRANTS 'ON';
+obey TEST142(clean_up);
+log LOG142 clear;
+obey TEST142(create_db);
+obey TEST142(set_up);
+obey TEST142(test_grants);
+obey TEST142(test_revokes);
+log;
+obey TEST142(clean_up);
+exit;
+
+?section clean_up
+-- drop database
+drop schema if exists t142user1 cascade;
+drop schema if exists t142user2 cascade;
+drop schema if exists t142user3 cascade;
+drop schema if exists t142user4 cascade;
+drop schema if exists t142user5 cascade;
+drop schema if exists t142user6 cascade;
+
+?section create_db
+create schema t142user1 authorization sql_user1;
+create schema t142user2 authorization sql_user2;
+create schema t142user3 authorization sql_user3;
+create schema t142user4 authorization sql_user4;
+create schema t142user5 authorization sql_user5;
+create schema t142user6 authorization sql_user6;
+
+set schema t142user4;
+create table referencedTable
+( c1 int not null primary key,
+ c2 int not null,
+ c3 char(10) not null,
+ c4 char(10) not null,
+ c5 largeint not null );
+alter table referencedTable add constraint u1 unique (c3, c2);
+alter table referencedTable add constraint u2 unique (c4);
+alter table referencedTable add constraint u3 unique(c5);
+showddl referencedTable;
+
+-- compile cpp program for function
+sh rm -f ./etest140.dll;
+sh sh $$scriptsdir$$/tools/dll-compile.ksh etest140.cpp
+ 2>&1 | tee LOG140-SECONDARY;
+set pattern $$DLL$$ etest140.dll;
+set pattern $$QUOTE$$ '''';
+
+-- create the library and udf
+create library t142_l1 file $$QUOTE$$ $$REGRRUNDIR$$/$$DLL$$ $$QUOTE$$ ;
+create function t142_translatePrivsBitmap(bitmap largeint) returns (bitmap_string char (20))
+language c parameter style sql external name 'translateBitmap'
+library t142_l1
+deterministic no sql final call allow any parallelism state area size 1024 ;
+grant execute on function t142_translatePrivsBitmap to "PUBLIC";
+
+set schema t142user1;
+create table user1
+(u1_c1 int not null,
+ u1_c2 int not null primary key,
+ u1_c3 char(10) not null,
+ u1_c4 char(10));
+showddl user1;
+
+set schema t142user2;
+create table user2
+(u2_c1 int not null,
+ u2_c2 int not null primary key,
+ u2_c3 char(10) not null,
+ u2_c4 largeint);
+showddl user2;
+
+set schema t142user3;
+create table user3
+(u3_c1 int not null,
+ u3_c2 int not null primary key,
+ u3_c3 char(10) not null,
+ u3_c4 char(10));
+showddl user3;
+
+set schema t142user5;
+create table user5
+(u5_c1 int not null,
+ u5_c2 int not null primary key,
+ u5_c3 char(10) not null,
+ u5_c4 char(10));
+showddl user5;
+
+set schema t142user6;
+create table user6
+(u6_c1 int not null,
+ u6_c2 int not null primary key,
+ u6_c3 char(10) not null,
+ u6_c4 char(10));
+showddl user6;
+
+?section set_up
+set schema "_PRIVMGR_MD_";
+prepare get_privs from
+select distinct
+ trim(substring (o.object_name,1,20)) as object_name,
+ grantor_id, grantee_id, 'all',
+ t142user4.t142_translatePrivsBitmap(privileges_bitmap) as granted_privs,
+ t142user4.t142_translatePrivsBitmap(grantable_bitmap) as grantable_privs
+from object_privileges p, "_MD_".objects o
+where p.object_uid in
+ (select object_uid
+ from "_MD_".objects
+ where schema_name like 'T142USER%'
+ and object_name not like 'SB_%')
+ and p.object_uid = o.object_uid
+union
+ (select distinct
+ trim(substring (o.object_name,1,20)) as object_name,
+ grantor_id, grantee_id, cast (column_number as char(3)),
+ t142user4.t142_translatePrivsBitmap(privileges_bitmap) as granted_privs,
+ t142user4.t142_translatePrivsBitmap(grantable_bitmap) as grantable_privs
+ from column_privileges p, "_MD_".objects o
+ where p.object_uid in
+ (select object_uid
+ from "_MD_".objects
+ where schema_name like 'T142USER%'
+ and object_name not like 'SB_%')
+ and p.object_uid = o.object_uid)
+order by 1, 2, 3, 4
+;
+
+?section test_grants
+-- =================================================================
+-- this set of tests run basic grant tests for constraints
+-- schema t142user4 contains the referenced table
+-- =================================================================
+set schema t142user4;
+
+-- all should fail, no one has permissions
+execute get_privs;
+sh sqlci -i "TEST142(user1_cmds)" -u sql_user1;
+sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+sh sqlci -i "TEST142(user3_cmds)" -u sql_user3;
+sh sqlci -i "TEST142(user5_cmds)" -u sql_user5;
+sh sqlci -i "TEST142(user6_cmds)" -u sql_user6;
+
+-- user1, user3, & user5 can create constraints
+grant references on referencedTable to sql_user1;
+grant references(c2, c3) on referencedTable to sql_user1;
+grant all_dml on referencedTable to sql_user3 with grant option;
+grant references on referencedTable to sql_user5 by sql_user3;
+execute get_privs;
+
+sh sqlci -i "TEST142(user1_cmds)" -u sql_user1;
+sh sqlci -i "TEST142(user3_cmds)" -u sql_user3;
+sh sqlci -i "TEST142(user5_cmds)" -u sql_user5;
+
+-- first time, user2 can only create one, second time it works
+grant references (c5) on referencedTable to sql_user2;
+sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+grant references (c4) on referencedTable to sql_user2 with grant option;
+sh sqlci -i "TEST142(user2_cmds)" -u sql_user2;
+
+-- user6 can create first but not second constraint
+grant references (c4) on referencedTable to sql_user6 by sql_user2;
+sh sqlci -i "TEST142(user6_cmds)" -u sql_user6;
+
+?section test_revokes
+-- ============================================================================
+-- verify that revoking privileges handle REFERENCES privilege correctly
+-- ============================================================================
+set schema t142user4;
+execute get_privs;
+
+-- unable to revoke because of u1_fk2
+revoke references on referencedTable from sql_user1;
+-- revoke succeeds because user2 has references at the object level
+revoke references (c2, c3) on referencedTable from sql_user1;
+
+-- remove u1_fk2 and retry
+alter table t142user1.user1 drop constraint u1_fk2;
+grant references (c2, c3) on referencedTable to sql_user1;
+
+-- now able to revoke references privilege
+revoke references on referencedTable from sql_user1;
+-- but not able to remove column privileges
+revoke references (c2) on referencedTable from sql_user1;
+revoke references (c3) on referencedTable from sql_user1;
+revoke references (c2, c3) on referencedTable from sql_user1;
+
+-- and vice versa
+grant references on referencedTable to sql_user1;
+-- can revoke
+revoke references (c2) on referencedTable from sql_user1;
+revoke references (c3) on referencedTable from sql_user1;
+-- cannot revoke
+revoke references on referencedTable from sql_user1;
+
+-- drop constraint and revoke succeeds
+alter table t142user1.user1 drop constraint u1_fk1;
+revoke references on referencedTable from sql_user1;
+
+?section user1_cmds
+-- ============================================================================
+-- creates RI constraints on referenced tables
+-- ============================================================================
+log LOG142;
+values (user);
+set schema t142user1;
+alter table user1 add constraint u1_fk1 foreign key (u1_c4, u1_c1)
+ references t142user4.referencedTable (c3, c2);
+alter table user1 add constraint u1_fk2 foreign key (u1_c2)
+ references t142user4.referencedTable(c1);
+
+?section user2_cmds
+-- ============================================================================
+-- creates RI constraints on referenced tables
+-- ============================================================================
+log LOG142;
+values (user);
+set schema t142user2;
+alter table user2 add constraint u2_fk1 foreign key (u2_c3)
+ references t142user4.referencedTable (c4);
+alter table user2 add constraint u2_fk2 foreign key (u2_c4)
+ references t142user4.referencedTable(c5);
+
+?section user3_cmds
+-- ============================================================================
+-- creates RI constraints on referenced tables
+-- ============================================================================
+log LOG142;
+values (user);
+set schema t142user3;
+alter table user3 add constraint u3_fk1 foreign key (u3_c1)
+ references t142user4.referencedTable;
+
+?section user5_cmds
+-- ============================================================================
+-- creates RI constraints on referenced tables
+-- ============================================================================
+log LOG142;
+values (user);
+set schema t142user5;
+alter table user5 add constraint u5_fk1 foreign key (u5_c1)
+ references t142user4.referencedTable;
+
+?section user6_cmds
+-- ============================================================================
+-- creates RI constraints on referenced tables
+-- ============================================================================
+log LOG142;
+values (user);
+set schema t142user6;
+alter table user6 add constraint u6_fk1 foreign key (u6_c3)
+ references t142user4.referencedTable(c4);
+-- this case always fails
+alter table user6 add constraint u6_fk2 foreign key (u6_c1)
+ references t142user4.referencedTable(c2);
+
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index 4f8d7a7..6def978 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -6160,6 +6160,9 @@ void CmpSeabaseDDL::alterSeabaseTableAddRIConstraint(
}
// User must have REFERENCES privilege on the referenced table
+ // First check for REFERENCES at the object level (column checks happen
+ // later)
+ NABoolean noObjPriv = FALSE;
if (isAuthorizationEnabled())
{
PrivMgrUserPrivs* privs = refdNaTable->getPrivInfo();
@@ -6175,15 +6178,7 @@ void CmpSeabaseDDL::alterSeabaseTableAddRIConstraint(
}
if (!ComUser::isRootUserID() && !privs->hasReferencePriv())
- {
- *CmpCommon::diags() << DgSqlCode(-CAT_NOT_AUTHORIZED);
-
- deallocEHI(ehi);
-
- processReturn();
-
- return;
- }
+ noObjPriv = TRUE;
}
ElemDDLColNameArray &ringCols = alterAddConstraint->getConstraint()->castToElemDDLConstraintRI()->getReferencingColumns();
@@ -6309,6 +6304,23 @@ void CmpSeabaseDDL::alterSeabaseTableAddRIConstraint(
return;
}
+
+ // If the user/role does not have REFERENCES privilege at the object
+ // level, check to see if the user/role has been granted the privilege
+ // on all affected columns
+ if (noObjPriv)
+ {
+ PrivMgrUserPrivs* privs = refdNaTable->getPrivInfo();
+ if (!privs->hasColReferencePriv(refdNAC->getPosition()))
+ {
+ *CmpCommon::diags() << DgSqlCode(-4481)
+ << DgString0("REFERENCES")
+ << DgString1(referencedTableName.getObjectNamePart().getExternalName().data());
+
+ processReturn();
+ return;
+ }
+ }
}
// method getCorrespondingConstraint expects an empty input list if there are no
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/PrivMgrDefs.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrDefs.h b/core/sql/sqlcomp/PrivMgrDefs.h
index 486c1f1..552f7f3 100644
--- a/core/sql/sqlcomp/PrivMgrDefs.h
+++ b/core/sql/sqlcomp/PrivMgrDefs.h
@@ -266,10 +266,10 @@ const static int32_t NBR_OF_PRIVS = NBR_DML_PRIVS+NBR_DDL_PRIVS;
//using PrivMgrBitmap = std::bitset<NBR_OF_PRIVS>;
#define PrivMgrBitmap std::bitset<NBR_OF_PRIVS>
typedef std::bitset<NBR_OF_PRIVS> PrivObjectBitmap;
-typedef std::bitset<NBR_DML_COL_PRIVS> PrivColumnBitmap;
+typedef std::bitset<NBR_OF_PRIVS> PrivColumnBitmap;
typedef std::bitset<NBR_OF_PRIVS> PrivSchemaBitmap;
typedef std::map<size_t,PrivColumnBitmap> PrivColList;
-typedef std::map<size_t,std::bitset<NBR_DML_COL_PRIVS> >::const_iterator PrivColIterator;
+typedef std::map<size_t,std::bitset<NBR_OF_PRIVS> >::const_iterator PrivColIterator;
inline bool isDMLPrivType(PrivType privType)
{
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/PrivMgrMD.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.cpp b/core/sql/sqlcomp/PrivMgrMD.cpp
index 250b5ff..811a71b 100644
--- a/core/sql/sqlcomp/PrivMgrMD.cpp
+++ b/core/sql/sqlcomp/PrivMgrMD.cpp
@@ -911,12 +911,13 @@ PrivStatus PrivMgrMDAdmin::getUdrsThatReferenceLibrary(
//
// method: getReferencingTablesForConstraints
//
-// This method returns the list of underlying tables that are associated with
-// RI constraints referencing an ObjectUsage.
+// This method returns the list of underlying tables and their columns that are
+// associated with RI constraints referencing an ObjectUsage.
//
// An RI constraint is a relationship between a set of columns on one table
-// with a set of columns on another table. Each set of columns must be
-// defined as an unique constraint (which include primary key constraints.
+// (the referencing table) with a set of columns on another table (the
+// referenced table). The set of columns must be defined as an unique
+// constraint (which include primary key constraints) on the referenced table.
// Relationships are stored through the constraints not their underlying tables.
//
// for example:
@@ -926,25 +927,41 @@ PrivStatus PrivMgrMDAdmin::getUdrsThatReferenceLibrary(
//
// user2:
// create table empl (empl_no int not null primary key, dept_no int, ... );
-// alter table empl add constraint empl_dept foreign key references dept;
+// alter table empl
+// add constraint empl_dept foreign key(dept_no) references dept;
//
// empl_dept is the name of the RI constraint
// The empl table references dept
// The dept table is being referenced by empl
//
-// The following query is called to get the list of tables:
-// <Gets underlying table for the foreign key's constraint>
-// select distinct o.object_uid, o.object_owner, o.create_time
-// from table_constraints t, objects o
-// where o.object_uid = t.table_uid;
-// and t.constraint_uid in
-//
-// <Gets foreign key's constraints referencing table>
-// (select foreign_constraint_uid
-// from table_constraints t, unique_ref_constr_usage u
-// where t.table_uid = objectUsage.objectUID
-// and t.constraint_uid = u.unique_constraint_uid)
-// order by o.create_time
+// The following query is called to get the list of tables and their columns:
+// <Gets underlying table and columns for the foreign key's constraint>
+// select (for referenced table)
+// objects (o): object_uid, object_owner, object_type, create_time, name,
+// list of columns (c): column_number
+// from table_constraints t, objects o, unique_ref_constr_usage u
+// (list of foreign key/unique constraint uids on referenced table) r,
+// (list of column numbers on referenced table's unique constraints) c
+// where o.object_uid = t.table_uid
+// and t.constraint_uid = r.foreign_constraint_uid
+// and r.unique_constraint_uid = c.object_uid
+// order by object_owner & create time
+//
+// <Get list of foreign key/unique constraint uids on reference table>
+// (select foreign_constraint_uid, unique_constraint_uid
+// from table_constraints t, unique_ref_constr_usage u
+// where t.table_uid = objectUsage.objectUID
+// and t.constraint_uid = u.unique_constraint_uid)
+// order by o.create_time
+//
+// <Get list of column numbers on referenced table's unique constraints>
+// (select object_uid, column_number, column_name
+// from TRAFODION."_MD_".KEYS
+// where object_uid in
+// (select unique_constraint_uid
+// from TABLE_CONSTRAINTS t,UNIQUE_REF_CONSTR_USAGE u
+// where t.table_uid = objectUsage.objectUID
+// and t.constraint_uid = u.unique_constraint_uid))
//
// input: ObjectUsage - object desiring list of referencing tables
// In the example above, this would be the DEPT table
@@ -962,29 +979,41 @@ PrivStatus PrivMgrMDAdmin::getReferencingTablesForConstraints (
trafMetadataLocation_ + ".OBJECTS o";
std::string tblConstraintsMDTable =
trafMetadataLocation_ + ".TABLE_CONSTRAINTS t";
+ std::string keysMDTable =
+ trafMetadataLocation_ + ".KEYS k";
std::string uniqueRefConstraintsMDTable =
trafMetadataLocation_ + ".UNIQUE_REF_CONSTR_USAGE u";
// Select all the constraints that are referenced by the table
- // create_time is included to order by the oldest to newest
std::string selectStmt = "select distinct o.object_uid, o.object_owner, o.object_type, o.create_time, ";
selectStmt += "trim(o.catalog_name) || '.\"' || ";
- selectStmt += "trim (o.schema_name) || '\".\"' ||";
- selectStmt += "trim (o.object_name)|| '\"' from ";
+ selectStmt += "trim (o.schema_name) || '\".\"' ||";
+ selectStmt += "trim (o.object_name)|| '\"' ";
+ selectStmt += ", c.column_number ";
+ selectStmt += "from " + uniqueRefConstraintsMDTable + std::string(", ");
selectStmt += tblConstraintsMDTable + std::string(", ") + objectsMDTable;
- selectStmt += " where o.object_uid = t.table_uid and t.constraint_uid in ";
- selectStmt += "(select foreign_constraint_uid from ";
+ selectStmt += " , (select foreign_constraint_uid, unique_constraint_uid from ";
selectStmt += tblConstraintsMDTable + std::string(", ") + uniqueRefConstraintsMDTable;
selectStmt += " where t.table_uid = " + UIDToString(objectUsage.objectUID);
- selectStmt += " and t.constraint_uid = u.unique_constraint_uid)";
- selectStmt += " order by o.create_time ";
+ selectStmt += " and t.constraint_uid = u.unique_constraint_uid) r ";
+ selectStmt += " , (select object_uid, column_number, column_name from ";
+ selectStmt += keysMDTable;
+ selectStmt += " where object_uid in (select unique_constraint_uid from ";
+ selectStmt += tblConstraintsMDTable + std::string(", ") ;
+ selectStmt += uniqueRefConstraintsMDTable + std::string(" where t.table_uid = ");
+ selectStmt += UIDToString(objectUsage.objectUID);
+ selectStmt += " and t.constraint_uid = u.unique_constraint_uid)) c ";
+ selectStmt += "where o.object_uid = t.table_uid ";
+ selectStmt += " and t.constraint_uid = r.foreign_constraint_uid ";
+ selectStmt += " and r.unique_constraint_uid = c.object_uid ";
+ selectStmt += " order by o.object_owner, o.create_time ";
ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
CmpCommon::context()->sqlSession()->getParentQid());
Queue * objectsQueue = NULL;
-// set pointer in diags area
-int32_t diagsMark = pDiags_->mark();
+ // set pointer in diags area
+ int32_t diagsMark = pDiags_->mark();
int32_t cliRC = cliInterface.fetchAllRows(objectsQueue, (char *)selectStmt.c_str(), 0, FALSE, FALSE, TRUE);
if (cliRC < 0)
@@ -1004,35 +1033,74 @@ int32_t diagsMark = pDiags_->mark();
char value[MAX_SQL_IDENTIFIER_NAME_LEN + 1];
objectsQueue->position();
+ std::vector<ColumnReference *> *columnReferences = new std::vector<ColumnReference *>;
+ ObjectReference *pObjectReference(NULL);
+ ColumnReference *pColumnReference(NULL);
+ int64_t currentObjectUID = 0;
+
// Set up an objectReference for any objects found, the caller manages
// space for this list
for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
{
OutputInfo * pCliRow = (OutputInfo*)objectsQueue->getNext();
- ObjectReference *pObjectReference = new ObjectReference;
// column 0: object uid
pCliRow->get(0,ptr,len);
- pObjectReference->objectUID = *(reinterpret_cast<int64_t*>(ptr));
+ int64_t nextObjectUID = *(reinterpret_cast<int64_t*>(ptr));
- // column 1: object owner
- pCliRow->get(1,ptr,len);
- pObjectReference->objectOwner = *(reinterpret_cast<int32_t*>(ptr));
+ // If a new object uid then save previous object reference
+ // and prepare for new object reference
+ if (nextObjectUID != currentObjectUID)
+ {
+ // Save off previous reference, if previous reference exists
+ if (currentObjectUID > 0)
+ {
+ pObjectReference->columnReferences = columnReferences;
+ objectReferences.push_back(pObjectReference);
+ }
+ currentObjectUID = nextObjectUID;
- // column 2: object type
- pCliRow->get(2,ptr,len);
- strncpy(value, ptr, len);
- value[len] = 0;
- pObjectReference->objectType = ObjectLitToEnum(value);
+ // prepare for new object reference
+ pObjectReference = new ObjectReference;
+ columnReferences = new std::vector<ColumnReference *>;
- // column 3: object name
- pCliRow->get(3,ptr,len);
- strncpy(value, ptr, len);
- value[len] = 0;
- pObjectReference->objectName = value;
+ // object UID
+ pObjectReference->objectUID = nextObjectUID;
- objectReferences.push_back(pObjectReference);
+ // column 1: object owner
+ pCliRow->get(1,ptr,len);
+ pObjectReference->objectOwner = *(reinterpret_cast<int32_t*>(ptr));
+
+ // column 2: object type
+ pCliRow->get(2,ptr,len);
+ strncpy(value, ptr, len);
+ value[len] = 0;
+ pObjectReference->objectType = ObjectLitToEnum(value);
+
+ // skip create_time (column 3)
+
+ // column 4: object name
+ pCliRow->get(4,ptr,len);
+ strncpy(value, ptr, len);
+ value[len] = 0;
+ pObjectReference->objectName = value;
+
+ }
+
+ // set up the column reference
+ // column 5: column number
+ ColumnReference *pColumnReference = new ColumnReference;
+ pCliRow->get(5,ptr,len);
+ pColumnReference->columnOrdinal = *(reinterpret_cast<int32_t*>(ptr));
+
+ // add to column list
+ columnReferences->push_back(pColumnReference);
}
+
+ // Add the final object reference to list
+ pObjectReference->columnReferences = columnReferences;
+ objectReferences.push_back(pObjectReference);
+
return STATUS_GOOD;
}
@@ -1053,21 +1121,23 @@ int32_t diagsMark = pDiags_->mark();
//
// user2:
// create table empl (empl_no int not null primary key, dept_no int, ... );
-// alter table empl add constraint empl_dept foreign key references dept;
+// alter table empl add constraint empl_dept foreign key(dept_no) references dept;
//
// This method returns the constraint named empl_dept
//
// The following query is called to get the constraint name:
//
// select [first 1] object_name as referenced_constraint_name
-// from objects o, table_constraints t
+// from objects o, table_constraints t, keys k
// where o.object_uid = t.constraint_uid
// and t.table_uid = <referencing table UID>
// and t.constraint_uid in
// (select ref_constraint_uid from ref_constraints
// where unique_constraint_uid in
// (select constraint_uid from table_constraints
-// where t.table_uid = <referenced table uid>))
+// where t.table_uid = <referenced table uid>
+// and constraint_uid = k.object_uid
+// and k.column_number = <column number>))
//
// input: referencedTableUID - the referenced table
// in the example above, the is the DEPT table UID
@@ -1085,6 +1155,7 @@ int32_t diagsMark = pDiags_->mark();
bool PrivMgrMDAdmin::getConstraintName(
const int64_t referencedTableUID,
const int64_t referencingTableUID,
+ const int32_t columnNumber,
std::string &constraintName)
{
std::string objectsMDTable = trafMetadataLocation_ + ".OBJECTS o";
@@ -1092,6 +1163,8 @@ bool PrivMgrMDAdmin::getConstraintName(
trafMetadataLocation_ + ".TABLE_CONSTRAINTS t";
std::string refConstraintsMDTable =
trafMetadataLocation_ + ".REF_CONSTRAINTS u";
+ std::string keysMDTable =
+ trafMetadataLocation_ + ".KEYS k";
// select object_name based on passed in object UID
std::string quote("\"");
@@ -1103,11 +1176,12 @@ bool PrivMgrMDAdmin::getConstraintName(
selectStmt += " where o.object_uid = t.constraint_uid";
selectStmt += " and t.table_uid = " + UIDToString(referencingTableUID);
selectStmt += " and t.constraint_uid in (select ref_constraint_uid from ";
- selectStmt += refConstraintsMDTable;
+ selectStmt += refConstraintsMDTable + ", " + keysMDTable;
selectStmt += " where unique_constraint_uid in ";
selectStmt += " (select constraint_uid from " + tblConstraintsMDTable;
selectStmt += " where t.table_uid = " + UIDToString(referencedTableUID);
- selectStmt += "))";
+ selectStmt += ") and k.column_number = " + UIDToString(columnNumber);
+ selectStmt += " and unique_constraint_uid = k.object_uid) ";
ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
CmpCommon::context()->sqlSession()->getParentQid());
@@ -1146,6 +1220,7 @@ int32_t diagsMark = pDiags_->mark();
return true;
}
+
// ----------------------------------------------------------------------------
// method: compareTableDefs
//
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/392031a3/core/sql/sqlcomp/PrivMgrMD.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.h b/core/sql/sqlcomp/PrivMgrMD.h
index 97bf5a7..c61d49a 100644
--- a/core/sql/sqlcomp/PrivMgrMD.h
+++ b/core/sql/sqlcomp/PrivMgrMD.h
@@ -29,6 +29,7 @@
#include "PrivMgrDefs.h"
#include "PrivMgr.h"
#include "PrivMgrDesc.h"
+#include "PrivMgrMDTable.h"
#include "ComSmallDefs.h"
#include "CmpSeabaseDDLauth.h"
@@ -36,6 +37,7 @@
class Queue;
class ExeCliInterface;
class OutputInfo;
+
#ifndef Lng32
typedef int Lng32;
#endif
@@ -56,35 +58,29 @@ typedef int Lng32;
// -----------------------------------------------------------------------
class ObjectPrivsRow;
class PrivMgrMDAdmin;
+class ObjectReference;
+class ObjectUsage;
// -----------------------------------------------------------------------
// Struct definitions
// -----------------------------------------------------------------------
-typedef struct {
- int64_t objectUID;
- int32_t granteeID;
- bool grantorIsSystem;
- std::string objectName;
- ComObjectType objectType;
- PrivMgrDesc originalPrivs;
- PrivMgrDesc updatedPrivs;
+struct ColumnReference {
+ int32_t columnOrdinal;
+ PrivMgrCoreDesc originalPrivs;
+ PrivMgrCoreDesc updatedPrivs;
+ ColumnReference()
+ : columnOrdinal(-1),
+ originalPrivs(),
+ updatedPrivs(){};
void describe (std::string &details) const
{
- details = "object usage - type is ";
- char objectTypeLit[3] = {0};
- strncpy(objectTypeLit,PrivMgr::ObjectEnumToLit(objectType),2);
- details += objectTypeLit;
- details += ", UID is ";
- details += to_string((long long int) objectUID);
- details += ", name is ";
- details += objectName;
- details += ", grantee is ";
- details += to_string((long long int) granteeID);
- details += ", is owner ";
- details += (grantorIsSystem) ? "true " : "false ";
+ details = "column usage ";
+ details += " column number is ";
+ details += to_string((long long int) columnOrdinal);
}
-} ObjectUsage;
+
+};
typedef struct {
int64_t viewUID;
@@ -110,12 +106,35 @@ typedef struct {
} ViewUsage;
-typedef struct {
+// -----------------------------------------------------------------------
+// Class definitions
+// -----------------------------------------------------------------------
+class ObjectReference
+{
+ public:
+
+ ObjectReference()
+ : objectUID(0),
+ objectOwner(NA_UserIdDefault),
+ objectType(COM_UNKNOWN_OBJECT),
+ columnReferences(NULL),
+ updatedPrivs()
+ {}
+
+ virtual ~ObjectReference ( void )
+ {
+ while(!columnReferences->empty())
+ delete columnReferences->back(), columnReferences->pop_back();
+ delete columnReferences;
+ }
+
int64_t objectUID;
int32_t objectOwner;
ComObjectType objectType;
std::string objectName;
+ std::vector<ColumnReference *> *columnReferences;
PrivMgrDesc updatedPrivs;
+
void describe (std::string &details) const
{
details = "object reference - type is ";
@@ -130,7 +149,70 @@ typedef struct {
details += to_string((long long int) objectOwner);
}
-} ObjectReference;
+};
+
+class ObjectUsage
+{
+ public:
+
+ ObjectUsage()
+ : objectUID (0),
+ granteeID (NA_UserIdDefault),
+ grantorIsSystem(false),
+ objectType (COM_UNKNOWN_OBJECT),
+ columnReferences(NULL),
+ originalPrivs(),
+ updatedPrivs()
+ {}
+
+ virtual ~ObjectUsage ( void )
+ {
+ if (columnReferences)
+ {
+ while(!columnReferences->empty())
+ delete columnReferences->back(), columnReferences->pop_back();
+ delete columnReferences;
+ }
+ }
+
+ int64_t objectUID;
+ int32_t granteeID;
+ bool grantorIsSystem;
+ std::string objectName;
+ ComObjectType objectType;
+ std::vector<ColumnReference *> *columnReferences;
+ PrivMgrDesc originalPrivs;
+ PrivMgrDesc updatedPrivs;
+
+ ColumnReference * findColumn (int32_t columnOrdinal)
+ {
+ if (columnReferences == NULL)
+ return NULL;
+ for (int i = 0; i < columnReferences->size(); i++)
+ {
+ ColumnReference *pRef = (*columnReferences)[i];
+ if (pRef->columnOrdinal == columnOrdinal)
+ return pRef;
+ }
+ return NULL;
+ }
+
+ void describe (std::string &details) const
+ {
+ details = "object usage - type is ";
+ char objectTypeLit[3] = {0};
+ strncpy(objectTypeLit,PrivMgr::ObjectEnumToLit(objectType),2);
+ details += objectTypeLit;
+ details += ", UID is ";
+ details += to_string((long long int) objectUID);
+ details += ", name is ";
+ details += objectName;
+ details += ", grantee is ";
+ details += to_string((long long int) granteeID);
+ details += ", is owner ";
+ details += (grantorIsSystem) ? "true " : "false ";
+ }
+};
// ****************************************************************************
@@ -178,6 +260,7 @@ class PrivMgrMDAdmin : public PrivMgr
bool getConstraintName(
const int64_t referencedTableUID,
const int64_t referencingTableUID,
+ const int32_t columnNumber,
std::string &referencingTable);
PrivStatus getObjectsThatViewReferences (
[3/5] incubator-trafodion git commit: Merge branch 'master' into
col-privs
Posted by sa...@apache.org.
Merge branch 'master' into col-privs
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/b9161bfe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/b9161bfe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/b9161bfe
Branch: refs/heads/master
Commit: b9161bfe28e6931ee7d7763a14603c841b04f4a9
Parents: 392031a b2fe5fd
Author: Roberta Marton <ro...@apache.org>
Authored: Tue Mar 1 16:02:50 2016 +0000
Committer: Roberta Marton <ro...@apache.org>
Committed: Tue Mar 1 16:02:50 2016 +0000
----------------------------------------------------------------------
.gitattributes | 3 -
.gitignore | 3 +
.rat-excludes | 6 +-
LICENSE | 305 -
Makefile | 13 +-
NOTICE | 2 +-
README | 8 +-
core/conn/Makefile | 12 +-
core/conn/trafci/manualtests/README | 50 +
core/conn/trafci/manualtests/statcheck.sql | 47 +
.../src/org/trafodion/ci/DatabaseQuery.java | 3 +-
.../odbc/odbcclient/unixcli/makefile.lnx | 2 +-
.../odbc/odbcclient/unixcli/package/LICENSE | 1 -
.../odbc/odbcclient/unixcli/package/license.txt | 18 -
.../odbc/odbcclient/unixcli/package/mklnxpkg.sh | 6 +-
.../unixcli/package/trafodbclnx_install.sh | 22 +-
core/rest/.gitignore | 2 +
core/rest/Makefile | 13 +-
core/rest/src/assembly/all.xml | 8 +
core/sqf/.gitignore | 3 +
core/sqf/LocalSettingsTemplate.sh | 4 +-
core/sqf/Makefile | 12 +-
core/sqf/sqenvcom.sh | 5 +-
core/sqf/sql/scripts/sqgen | 12 +-
core/sql/SqlCompilerDebugger/mk.sh | 3 +
core/sql/cli/CliExpExchange.cpp | 2 +
core/sql/common/ComSmallDefs.h | 2 +
core/sql/executor/HBaseClient_JNI.cpp | 25 +-
core/sql/executor/HBaseClient_JNI.h | 3 +-
core/sql/exp/ExpHbaseInterface.cpp | 8 +-
core/sql/exp/ExpHbaseInterface.h | 12 +-
core/sql/exp/exp_datetime.cpp | 30 +-
core/sql/generator/Generator.cpp | 5 +
core/sql/nskgmake/SqlCompilerDebugger/Makefile | 15 +-
core/sql/optimizer/NAColumn.h | 43 +-
core/sql/optimizer/NATable.cpp | 7 +-
core/sql/optimizer/NodeMap.cpp | 15 +-
.../sql/parser/StmtDDLAlterTableAlterColumn.cpp | 20 +-
core/sql/parser/StmtDDLAlterTableAlterColumn.h | 17 +-
core/sql/parser/sqlparser.y | 6 +-
core/sql/parser/ulexer.h | 21 +
core/sql/regress/compGeneral/EXPECTED071 | 8 +-
core/sql/regress/core/EXPECTED056.SB | 52 +-
core/sql/regress/executor/EXPECTED013.SB | 38 +-
core/sql/regress/executor/EXPECTED022.LINUX | 9365 -----------------
core/sql/regress/executor/EXPECTED022.SB | 9467 ++++++++++++++++++
core/sql/regress/executor/TEST022 | 12 +
core/sql/regress/privs2/EXPECTED138 | 2 +-
core/sql/regress/seabase/EXPECTED011 | 101 +-
core/sql/regress/seabase/EXPECTED027 | 433 +-
core/sql/regress/seabase/TEST011 | 16 -
core/sql/regress/seabase/TEST027 | 58 +
core/sql/sqlci/Param.cpp | 8 +-
core/sql/sqlci/SqlCmd.cpp | 37 +-
core/sql/sqlcomp/CmpDescribe.cpp | 180 +-
core/sql/sqlcomp/CmpSeabaseDDL.h | 68 +-
core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 217 +-
core/sql/sqlcomp/CmpSeabaseDDLschema.cpp | 4 +-
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 1507 ++-
core/sql/sqlcomp/DefaultConstants.h | 4 +
core/sql/sqlcomp/nadefaults.cpp | 10 +-
.../java/org/trafodion/sql/HBaseClient.java | 33 +-
core/sql/ustat/hs_update.cpp | 3 +-
dcs/.gitignore | 2 +
dcs/Makefile | 14 +-
dcs/bin/stop-dcs.sh | 2 +-
dcs/src/assembly/all.xml | 4 +-
.../dcs/master/listener/ConnectReply.java | 60 +-
.../src/asciidoc/_chapters/about.adoc | 3 +-
docs/client_install/src/asciidoc/index.adoc | 3 +-
docs/command_interface/pom.xml | 2 +
.../src/asciidoc/_chapters/about.adoc | 2 +
docs/command_interface/src/asciidoc/index.adoc | 5 +-
docs/messages_guide/pom.xml | 2 +
.../src/asciidoc/_chapters/about.adoc | 3 +-
docs/messages_guide/src/asciidoc/index.adoc | 5 +-
docs/odb_user/pom.xml | 2 +
docs/odb_user/src/asciidoc/_chapters/about.adoc | 3 +-
docs/odb_user/src/asciidoc/index.adoc | 5 +-
docs/provisioning_guide/pom.xml | 2 +
.../src/asciidoc/_chapters/about.adoc | 20 +-
.../src/asciidoc/_chapters/activate.adoc | 147 +
.../src/asciidoc/_chapters/enable_security.adoc | 491 +
.../src/asciidoc/_chapters/install_prepare.adoc | 39 -
.../src/asciidoc/_chapters/introduction.adoc | 466 +
.../src/asciidoc/_chapters/prepare.adoc | 356 +
.../src/asciidoc/_chapters/recipe_install.adoc | 29 +
.../src/asciidoc/_chapters/recipe_upgrade.adoc | 30 +
.../src/asciidoc/_chapters/requirements.adoc | 256 +-
.../src/asciidoc/_chapters/script_install.adoc | 511 +
.../src/asciidoc/_chapters/script_remove.adoc | 118 +
.../src/asciidoc/_chapters/script_upgrade.adoc | 442 +
docs/provisioning_guide/src/asciidoc/index.adoc | 15 +-
docs/shared/trafodion-logo.jpg | Bin 0 -> 28850 bytes
docs/shared/trafodion-manuals.css | 2 +-
docs/sql_reference/pom.xml | 2 +
.../src/asciidoc/_chapters/about.adoc | 3 +-
docs/sql_reference/src/asciidoc/index.adoc | 5 +-
docs/src/site/markdown/documentation.md | 3 +
docs/src/site/markdown/download.md | 156 +-
.../site/markdown/enable-secure-trafodion.md | 210 +-
docs/src/site/markdown/index.md | 2 +-
docs/src/site/markdown/install-preparation.md | 138 -
docs/src/site/markdown/install-troubleshoot.md | 21 -
docs/src/site/markdown/install.md | 202 -
docs/src/site/markdown/ldapcheck.md | 28 +-
docs/src/site/markdown/ldapconfigcheck.md | 36 +-
docs/src/site/markdown/port-assignment.md | 134 -
docs/src/site/markdown/quickstart.md | 95 +-
docs/src/site/markdown/uninstall.md | 176 -
.../site/resources/images/logos/egg-logo.png | Bin 0 -> 7241 bytes
.../resources/images/logos/trafodion-logo.jpg | Bin 0 -> 18953 bytes
docs/src/site/site.xml | 117 +-
install/.gitignore | 2 +
install/Makefile | 11 +-
install/installer/traf_add_sudoAccess | 42 +-
install/installer/traf_cloudera_mods98 | 15 +
install/installer/traf_config_check | 16 +-
install/installer/traf_config_setup | 12 +
install/installer/traf_hortonworks_mods98 | 13 +
install/installer/traf_sqgen | 2 +-
install/installer/trafodion_install | 4 +-
install/traf_tools_setup.sh | 6 +-
licenses/Apache | 203 +
licenses/LICENSE-bsd3 | 14 -
licenses/LICENSE-bsd4 | 34 -
licenses/LICENSE-facebook | 14 -
licenses/LICENSE-jquery | 8 -
licenses/LICENSE-js | 21 -
licenses/LICENSE-salesforce | 23 -
licenses/Makefile | 46 +
licenses/lic-clients-bin | 177 +
licenses/lic-components-src | 9 +
licenses/lic-dcs-bin | 9 +
licenses/lic-dcs-src | 69 +
licenses/lic-rest-bin | 9 +
licenses/lic-server-bin | 120 +
licenses/lic-server-src | 76 +
licenses/lic-test-src | 43 +
.../phoenix/end2end/AlterTableTest.java | 22 +
.../phoenix/end2end/ArithmeticQueryTest.java | 22 +
.../phoenix/end2end/AutoCommitTest.java | 22 +
.../org/trafodion/phoenix/end2end/BaseTest.java | 22 +
.../phoenix/end2end/BinaryRowKeyTest.java | 22 +
.../phoenix/end2end/CoalesceFunctionTest.java | 22 +
.../end2end/CompareDecimalToLongTest.java | 22 +
.../phoenix/end2end/CreateTableTest.java | 22 +
.../phoenix/end2end/CustomEntityDataTest.java | 22 +
.../phoenix/end2end/DeleteRangeTest.java | 22 +
.../end2end/DescColumnSortOrderTest.java | 24 +-
.../phoenix/end2end/DistinctCountTest.java | 22 +
.../phoenix/end2end/ExecuteStatementsTest.java | 22 +
.../phoenix/end2end/ExtendedQueryExecTest.java | 22 +
.../phoenix/end2end/FunkyNamesTest.java | 22 +
.../phoenix/end2end/GroupByCaseTest.java | 22 +
.../trafodion/phoenix/end2end/IndexTest.java | 22 +
.../trafodion/phoenix/end2end/IsNullTest.java | 22 +
.../trafodion/phoenix/end2end/KeyOnlyTest.java | 22 +
.../phoenix/end2end/MultiCfQueryExecTest.java | 22 +
.../trafodion/phoenix/end2end/OrderByTest.java | 22 +
.../phoenix/end2end/ProductMetricsTest.java | 24 +-
.../phoenix/end2end/QueryExecTest.java | 22 +
.../end2end/QueryExecWithoutSCNTest.java | 22 +
.../phoenix/end2end/QueryPlanTest.java | 22 +
.../phoenix/end2end/ReadIsolationLevelTest.java | 22 +
.../phoenix/end2end/SaltedTableTest.java | 22 +
.../end2end/SaltedTableUpsertSelectTest.java | 22 +
.../end2end/SaltedTableVarLengthRowKeyTest.java | 22 +
.../phoenix/end2end/ServerExceptionTest.java | 22 +
.../phoenix/end2end/SkipScanQueryTest.java | 22 +
.../phoenix/end2end/StatementHintsTest.java | 22 +
.../trafodion/phoenix/end2end/StddevTest.java | 22 +
.../phoenix/end2end/ToCharFunctionTest.java | 22 +
.../phoenix/end2end/ToNumberFunctionTest.java | 22 +
.../org/trafodion/phoenix/end2end/TopNTest.java | 22 +
.../phoenix/end2end/UpsertBigValuesTest.java | 22 +
.../end2end/UpsertSelectAutoCommitTest.java | 22 +
.../phoenix/end2end/UpsertSelectTest.java | 22 +
.../phoenix/end2end/UpsertValuesTest.java | 22 +
.../phoenix/end2end/VariableLengthPKTest.java | 22 +
180 files changed, 16677 insertions(+), 12013 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9161bfe/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
[5/5] incubator-trafodion git commit: Merge remote branch
'origin/pr/349/head' into merge_trafodion349
Posted by sa...@apache.org.
Merge remote branch 'origin/pr/349/head' into merge_trafodion349
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/39d3a0c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/39d3a0c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/39d3a0c4
Branch: refs/heads/master
Commit: 39d3a0c44c8ee064fdd43caee311e2a01b7b00bf
Parents: cad7ab6 66e03ea
Author: Sandhya Sundaresan <sa...@apache.org>
Authored: Wed Mar 2 06:36:19 2016 +0000
Committer: Sandhya Sundaresan <sa...@apache.org>
Committed: Wed Mar 2 06:36:19 2016 +0000
----------------------------------------------------------------------
core/sql/regress/privs2/EXPECTED135 | 329 -----------
core/sql/regress/privs2/EXPECTED142 | 760 +++++++++++++++++++++++++
core/sql/regress/privs2/TEST135 | 43 --
core/sql/regress/privs2/TEST142 | 280 ++++++++++
core/sql/sqlcomp/CmpSeabaseDDLtable.cpp | 30 +-
core/sql/sqlcomp/PrivMgrDefs.h | 4 +-
core/sql/sqlcomp/PrivMgrMD.cpp | 171 ++++--
core/sql/sqlcomp/PrivMgrMD.h | 132 ++++-
core/sql/sqlcomp/PrivMgrPrivileges.cpp | 793 ++++++++++++++++-----------
core/sql/sqlcomp/PrivMgrPrivileges.h | 48 +-
10 files changed, 1814 insertions(+), 776 deletions(-)
----------------------------------------------------------------------
[4/5] incubator-trafodion git commit: TRAFODION-1856: Revoke - object
and column privilege checks not integrated for constraints
Posted by sa...@apache.org.
TRAFODION-1856: Revoke - object and column privilege checks not integrated for constraints
Fixed a problem with null pointer referencing from prior push
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/66e03ea3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/66e03ea3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/66e03ea3
Branch: refs/heads/master
Commit: 66e03ea3ff0d0fd0e190f60abb256c810926d871
Parents: b9161bf
Author: Roberta Marton <ro...@apache.org>
Authored: Tue Mar 1 16:37:27 2016 +0000
Committer: Roberta Marton <ro...@apache.org>
Committed: Tue Mar 1 16:37:27 2016 +0000
----------------------------------------------------------------------
core/sql/sqlcomp/PrivMgrMD.h | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/66e03ea3/core/sql/sqlcomp/PrivMgrMD.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/PrivMgrMD.h b/core/sql/sqlcomp/PrivMgrMD.h
index c61d49a..a4c3f5e 100644
--- a/core/sql/sqlcomp/PrivMgrMD.h
+++ b/core/sql/sqlcomp/PrivMgrMD.h
@@ -75,8 +75,7 @@ struct ColumnReference {
void describe (std::string &details) const
{
- details = "column usage ";
- details += " column number is ";
+ details = "column usage - column number is ";
details += to_string((long long int) columnOrdinal);
}
@@ -123,15 +122,19 @@ class ObjectReference
virtual ~ObjectReference ( void )
{
- while(!columnReferences->empty())
- delete columnReferences->back(), columnReferences->pop_back();
- delete columnReferences;
+ if (columnReferences)
+ {
+ while(!columnReferences->empty())
+ delete columnReferences->back(), columnReferences->pop_back();
+ delete columnReferences;
+ }
}
int64_t objectUID;
int32_t objectOwner;
ComObjectType objectType;
std::string objectName;
+ //TBD - make columnReferences a map instead of a vector
std::vector<ColumnReference *> *columnReferences;
PrivMgrDesc updatedPrivs;