Repository: trafodion Updated Branches: refs/heads/master 82710576e -> 3dd0eca44
[TRAFODION-2205] invalid char at create schema when authorization name is long There is code that converts the user ID to its username. The buffer size requested was not big enough to hold the return value. In addition, the buffer size check was returning an error but did not add an error to the ComDiags area; therefore the returned error was ignored. - Changed max len in calls to getAuthNameFromAuthID to the correct size. - Set up the Diags area when buffer size is too small so the error is reported correctly, returns error 20235: "Error returned while converting auth ID to auth name, status: xx ID: xx." Also removed redundant methods: - getDBUserNameFromID - calls getAuthNameFromID instead - getDBUserIDFromName - calls GetAuthIDFromName instead Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/affe1f60 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/affe1f60 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/affe1f60 Branch: refs/heads/master Commit: affe1f60ff02610d40a9d58702b12d9c9473de34 Parents: ee2cff9 Author: Roberta Marton <[email protected]> Authored: Thu Apr 12 16:07:02 2018 +0000 Committer: Roberta Marton <[email protected]> Committed: Thu Apr 12 16:07:02 2018 +0000 ---------------------------------------------------------------------- core/sql/cli/Cli.cpp | 12 +-- core/sql/cli/Context.cpp | 125 +------------------------- core/sql/cli/Context.h | 6 -- core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 6 +- core/sql/sqlcomp/CmpSeabaseDDLschema.cpp | 2 +- core/sql/sqlcomp/PrivMgrPrivileges.cpp | 2 +- 6 files changed, 14 insertions(+), 139 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/cli/Cli.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp index 4a83a14..a06aadb 100644 --- a/core/sql/cli/Cli.cpp +++ b/core/sql/cli/Cli.cpp @@ -6182,10 +6182,10 @@ Lng32 SQLCLI_GetDatabaseUserName ( ContextCli &currContext = *(cliGlobals->currContext()); ComDiagsArea &diags = currContext.diags(); - retcode = currContext.getDBUserNameFromID(user_id, - string_value, - max_string_len, - len_of_item); + retcode = currContext.getAuthNameFromID(user_id, + string_value, + max_string_len, + *len_of_item); return CliEpilogue(cliGlobals, NULL, retcode); } @@ -6206,8 +6206,8 @@ Lng32 SQLCLI_GetDatabaseUserID ( ContextCli &currContext = *(cliGlobals->currContext()); ComDiagsArea &diags = currContext.diags(); - retcode = currContext.getDBUserIDFromName(string_value, - numeric_value); + retcode = currContext.getAuthIDFromName(string_value, + *numeric_value); return CliEpilogue(cliGlobals, NULL, retcode); } http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/cli/Context.cpp ---------------------------------------------------------------------- diff --git a/core/sql/cli/Context.cpp b/core/sql/cli/Context.cpp index 09f1783..c4dd6c7 100644 --- a/core/sql/cli/Context.cpp +++ b/core/sql/cli/Context.cpp @@ -4359,128 +4359,6 @@ RETCODE ContextCli::getAuthNameFromID( //******************* End of ContextCli::getAuthNameFromID ********************* - - - - -// Public method to map an integer user ID to a user name -RETCODE ContextCli::getDBUserNameFromID(Int32 userID, // IN - char *userNameBuffer, // OUT - Int32 maxBufLen, // IN - Int32 *requiredLen) // OUT optional -{ - RETCODE result = SUCCESS; - char usersNameFromUsersTable[MAX_USERNAME_LEN + 1]; - Int32 userIDFromUsersTable; - std::vector<int32_t> roleIDs; - if (requiredLen) - *requiredLen = 0; - - // Cases to consider - // * userID is the current user ID - // * SYSTEM_USER and PUBLIC_USER have special integer user IDs and - // are not registered in the USERS table - // * other users - - NABoolean isCurrentUser = - (userID == (Int32) databaseUserID_ ? TRUE : FALSE); - - const char *currentUserName = NULL; - if (isCurrentUser) - { - currentUserName = databaseUserName_; - } - else - { - // See if the USERS row exists - result = authQuery(USERS_QUERY_BY_USER_ID, - NULL, // IN user name (ignored) - userID, // IN user ID - usersNameFromUsersTable, //OUT - sizeof(usersNameFromUsersTable), - userIDFromUsersTable, - roleIDs); // OUT - if (result != ERROR) - currentUserName = usersNameFromUsersTable; - } - - // Return the user name if the lookup was successful - if (result != ERROR) - { - ex_assert(currentUserName, "currentUserName should not be NULL"); - - Int32 bytesNeeded = strlen(currentUserName) + 1; - - if (bytesNeeded > maxBufLen) - { - diagsArea_ << DgSqlCode(-CLI_USERNAME_BUFFER_TOO_SMALL); - if (requiredLen) - *requiredLen = bytesNeeded; - result = ERROR; - } - else - { - strcpy(userNameBuffer, currentUserName); - } - } - - return result; -} - -// Public method to map a user name to an integer user ID -RETCODE ContextCli::getDBUserIDFromName(const char *userName, // IN - Int32 *userID) // OUT -{ - - if (userName == NULL || userID == NULL) - return ERROR; - -// Cases to consider -// * userName is the current user name -// * SYSTEM_USER and PUBLIC_USER have special integer user IDs and -// are not registered in the USERS table -// * other users - - if (databaseUserName_ && strcasecmp(userName,databaseUserName_) == 0) - { - *userID = databaseUserID_; - return SUCCESS; - } - - if (strcasecmp(userName,ComUser::getPublicUserName()) == 0) - { - *userID = ComUser::getPublicUserID(); - return SUCCESS; - } - - if (strcasecmp(userName,ComUser::getSystemUserName()) == 0) - { - *userID = ComUser::getSystemUserID(); - return SUCCESS; - } - - // See if the AUTHS row exists - - RETCODE result = SUCCESS; - char usersNameFromUsersTable[MAX_USERNAME_LEN + 1]; - Int32 userIDFromUsersTable; - std::vector<int32_t> roleIDs; - - result = authQuery(USERS_QUERY_BY_USER_NAME, - userName, // IN user name - 0, // IN user ID (ignored) - usersNameFromUsersTable, //OUT - sizeof(usersNameFromUsersTable), - userIDFromUsersTable, - roleIDs); // OUT - if (result == SUCCESS && userID) - *userID = userIDFromUsersTable; - - return result; - -} - -// Public method only meant to be called in ESPs. All we do is call // the private method to update user ID data members. On platforms // other than Linux the method is a no-op. void ContextCli::setDatabaseUserInESP(const Int32 &uid, const char *uname, @@ -4790,7 +4668,10 @@ RETCODE ContextCli::storeName( actualLength = strlen(src); if (actualLength >= maxLength) + { + diagsArea_ << DgSqlCode(-CLI_USERNAME_BUFFER_TOO_SMALL); return ERROR; + } memcpy(dest,src,actualLength); dest[actualLength] = 0; http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/cli/Context.h ---------------------------------------------------------------------- diff --git a/core/sql/cli/Context.h b/core/sql/cli/Context.h index a432ec9..d64ac09 100644 --- a/core/sql/cli/Context.h +++ b/core/sql/cli/Context.h @@ -125,12 +125,6 @@ public: char *authNameBuffer, // OUT Int32 maxBufLen, // IN Int32 &requiredLen); // OUT optional - RETCODE getDBUserNameFromID(Int32 userID, // IN - char *userNameBuffer, // OUT - Int32 maxBufLen, // IN - Int32 *requiredLen); // OUT - RETCODE getDBUserIDFromName(const char *userName, // IN - Int32 *userID); // OUT // Function to be used only in ESPs to establish user identity. This // call will update data members and will NOT verify the input http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp index b5db51b..e5fb166 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp @@ -8426,7 +8426,7 @@ NABoolean CmpSeabaseDDL::insertPrivMgrInfo(const Int64 objUID, Int32 lActualLen = 0; Int16 status = ComUser::getAuthNameFromAuthID( (Int32) schemaOwnerID , (char *)&username - , MAX_USERNAME_LEN + , MAX_USERNAME_LEN+1 , lActualLen ); if (status != FEOK) { @@ -8448,7 +8448,7 @@ std::string creatorGrantee; Int32 lActualLen = 0; Int16 status = ComUser::getAuthNameFromAuthID( (Int32) objOwnerID , (char *)&username - , MAX_USERNAME_LEN + , MAX_USERNAME_LEN+1 , lActualLen ); if (status != FEOK) { @@ -8468,7 +8468,7 @@ std::string creatorGrantee; Int32 lActualLen = 0; Int16 status = ComUser::getAuthNameFromAuthID( (Int32) creatorID , (char *)&username - , MAX_USERNAME_LEN + , MAX_USERNAME_LEN+1 , lActualLen ); if (status != FEOK) { http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp index 1bfe3cd..e346c9e 100644 --- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp +++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp @@ -419,7 +419,7 @@ Int64 schemaUID = getObjectTypeandOwner(&cliInterface, char username[MAX_USERNAME_LEN+1]; Int32 lActualLen = 0; Int16 status = ComUser::getAuthNameFromAuthID(objectOwner,username, - MAX_USERNAME_LEN,lActualLen); + MAX_USERNAME_LEN+1,lActualLen); if (status != FEOK) { *CmpCommon::diags() << DgSqlCode(-20235) // Error converting user ID. http://git-wip-us.apache.org/repos/asf/trafodion/blob/affe1f60/core/sql/sqlcomp/PrivMgrPrivileges.cpp ---------------------------------------------------------------------- diff --git a/core/sql/sqlcomp/PrivMgrPrivileges.cpp b/core/sql/sqlcomp/PrivMgrPrivileges.cpp index 40108d4..ba7d00f 100644 --- a/core/sql/sqlcomp/PrivMgrPrivileges.cpp +++ b/core/sql/sqlcomp/PrivMgrPrivileges.cpp @@ -2851,7 +2851,7 @@ short retcode = 0; char authName[MAX_USERNAME_LEN+1]; Int32 actualLen = 0; retcode = ComUser::getAuthNameFromAuthID(objectOwner,authName, - MAX_USERNAME_LEN,actualLen); + MAX_USERNAME_LEN+1,actualLen); if (retcode != FEOK) { *pDiags_ << DgSqlCode(-20235)
