QualifiedName::QualifiedName(const ComObjectName &comObjNam, CollHeap * h) : SchemaName (comObjNam.getSchemaNamePart ().getInternalName(), comObjNam.getCatalogNamePart().getInternalName(), h), objectName_(comObjNam.getObjectNamePart ().getInternalName(), h), objectNameSpace_(comObjNam.getNameSpace()), flagbits_(0) {}
HSTableDef::HSTableDef(const ComObjectName &tableName, const hs_table_type tableType, const ComAnsiNameSpace nameSpace) :tableName_(new(STMTHEAP) NAString(STMTHEAP)), ansiName_(new(STMTHEAP) NAString(STMTHEAP)), naTbl_(NULL), catalog_(new(STMTHEAP) NAString(tableName.getCatalogNamePart().getInternalName(), STMTHEAP)), schema_(new(STMTHEAP) NAString(tableName.getSchemaNamePart().getInternalName(), STMTHEAP)), object_(new(STMTHEAP) NAString(tableName.getObjectNamePart().getInternalName(), STMTHEAP)), objectUID_(0), objActualFormat_(UNKNOWN), objFormat_(tableType), numCols_(0), colInfo_(NULL), retcode_(0), isVolatile_(FALSE), guardianName_(new(STMTHEAP) NAString(STMTHEAP)), nameSpace_(nameSpace), labelAccessed_(FALSE), objectType_(COM_UNKNOWN_OBJECT), isMetadataObject_(FALSE), hasSyskey_(FALSE) { // Set volatile schema flag based on schema name. if (!strncmp(schema_->data(), COM_VOLATILE_SCHEMA_PREFIX, strlen(COM_VOLATILE_SCHEMA_PREFIX))) isVolatile_ = TRUE; }
NABoolean isHBaseUmdHistograms(const ComObjectName& objectName) { return ( HSGlobalsClass::isHBaseUMDHistogram( objectName.getObjectNamePart().getInternalName() ) && HSGlobalsClass::isTrafodionCatalog( objectName.getCatalogNamePart().getInternalName() ) ); }
void CmpCommon::applyDefaults(ComObjectName &nam) { CMPASSERT(nam.isValid()); if (nam.getCatalogNamePart().isEmpty()) { NAString dcat, dsch; ActiveSchemaDB()->getDefaults().getCatalogAndSchema(dcat, dsch); if (nam.getSchemaNamePart().isEmpty()) nam.setSchemaNamePart(ComAnsiNamePart(dsch,CmpCommon::statementHeap())); nam.setCatalogNamePart(ComAnsiNamePart(dcat,CmpCommon::statementHeap())); } }
NABoolean isSpecialObject(const ComObjectName& objectName) { if ( isSpecialObject(objectName.getObjectNamePartAsAnsiString()) ) return TRUE; return isHBaseMeta(objectName); }
NABoolean isHBaseMeta(const ComObjectName& objectName) { return ( HSGlobalsClass::isHBaseMeta( objectName.getSchemaNamePart().getInternalName() ) || isHBaseUmdHistograms(objectName) ); }
// ***************************************************************************** // * * // * Function: checkAccessPrivileges * // * * // * This function determines if a user has the requesite privileges to * // * access the referenced objects that comprise the view. * // * * // ***************************************************************************** // * * // * Parameters: * // * * // * <vtul> const ParTableUsageList & In * // * is a reference to a list of objects used by the view. * // * * // * <vctcul> const ParViewColTableColsUsageList & In * // * is a reference to the list of columns used by the view. * // * * // * <privilegesBitmap> PrivMgrBitmap & Out * // * passes back the union of privileges the user has on the referenced * // * objects. * // * * // * <grantableBitmap> PrivMgrBitmap & Out * // * passes back the union of the with grant option authority the user has * // * on the referenced objects. * // * * // ***************************************************************************** // * * // * Returns: bool * // * * // * true: User has requisite privileges; bitmap unions returned. * // * false: Could not retrieve privileges or user does not have requesite * // * privileges; see diags area for error details. * // * * // ***************************************************************************** static bool checkAccessPrivileges( const ParTableUsageList & vtul, const ParViewColTableColsUsageList & vctcul, PrivMgrBitmap & privilegesBitmap, PrivMgrBitmap & grantableBitmap) { BindWA bindWA(ActiveSchemaDB(),CmpCommon::context(),FALSE/*inDDL*/); bool missingPrivilege = false; NAString extUsedObjName; // generate the lists of privileges and grantable privileges // a side effect is to return an error if basic privileges are not granted for (CollIndex i = 0; i < vtul.entries(); i++) { if (vtul[i].getSpecialType() == ExtendedQualName::SG_TABLE) continue; ComObjectName usedObjName(vtul[i].getQualifiedNameObj().getQualifiedNameAsAnsiString(), vtul[i].getAnsiNameSpace()); const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString(); const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE); const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE); const NAString extUsedObjName = usedObjName.getExternalName(TRUE); CorrName cn(objectNamePart,STMTHEAP, schemaNamePart,catalogNamePart); NATable *naTable = bindWA.getNATable(cn); if (naTable == NULL) { SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges"); return false; } // Grab privileges from the NATable structure PrivMgrUserPrivs *privs = naTable->getPrivInfo(); if (privs == NULL) { *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); return false; } // Requester must have at least select privilege if ( !privs->hasSelectPriv() ) missingPrivilege = true; // Summarize privileges privilegesBitmap &= privs->getObjectBitmap(); grantableBitmap &= privs->getGrantableBitmap(); } if (!missingPrivilege) return true; missingPrivilege = false; PrivColumnBitmap colPrivBitmap; PrivColumnBitmap colGrantableBitmap; PrivMgrPrivileges::setColumnPrivs(colPrivBitmap); PrivMgrPrivileges::setColumnPrivs(colGrantableBitmap); for (size_t i = 0; i < vctcul.entries(); i++) { const ParViewColTableColsUsage &vctcu = vctcul[i]; int32_t usingColNum = vctcu.getUsingViewColumnNumber(); const ColRefName &usedColRef = vctcu.getUsedObjectColumnName(); ComObjectName usedObjName; usedObjName = usedColRef.getCorrNameObj().getQualifiedNameObj(). getQualifiedNameAsAnsiString(); const NAString catalogNamePart = usedObjName.getCatalogNamePartAsAnsiString(); const NAString schemaNamePart = usedObjName.getSchemaNamePartAsAnsiString(TRUE); const NAString objectNamePart = usedObjName.getObjectNamePartAsAnsiString(TRUE); extUsedObjName = usedObjName.getExternalName(TRUE); CorrName cn(objectNamePart,STMTHEAP,schemaNamePart,catalogNamePart); NATable *naTable = bindWA.getNATable(cn); if (naTable == NULL) { SEABASEDDL_INTERNAL_ERROR("Bad NATable pointer in checkAccessPrivileges"); return -1; } const NAColumnArray &nacolArr = naTable->getNAColumnArray(); ComString usedObjColName(usedColRef.getColName()); const NAColumn * naCol = nacolArr.getColumn(usedObjColName); if (naCol == NULL) { *CmpCommon::diags() << DgSqlCode(-CAT_COLUMN_DOES_NOT_EXIST_ERROR) << DgColumnName(usedObjColName); return false; } int32_t usedColNumber = naCol->getPosition(); // Grab privileges from the NATable structure PrivMgrUserPrivs *privs = naTable->getPrivInfo(); if (privs == NULL) { *CmpCommon::diags() << DgSqlCode(-CAT_UNABLE_TO_RETRIEVE_PRIVS); return false; } // If the user is missing SELECT on at least one column-level privilege, // view cannot be created. No need to proceed. if (!privs->hasColSelectPriv(usedColNumber)) { missingPrivilege = true; break; } colPrivBitmap &= privs->getColumnPrivBitmap(usedColNumber); colGrantableBitmap &= privs->getColumnGrantableBitmap(usedColNumber); } if (missingPrivilege || vctcul.entries() == 0) { *CmpCommon::diags() << DgSqlCode(-4481) << DgString0("SELECT") << DgString1(extUsedObjName.data()); return false; } for (size_t i = FIRST_DML_COL_PRIV; i <= LAST_DML_COL_PRIV; i++ ) { if (colPrivBitmap.test(PrivType(i))) privilegesBitmap.set(PrivType(i)); if (colGrantableBitmap.test(PrivType(i))) grantableBitmap.set(PrivType(i)); } return true; }