Exemplo n.º 1
0
// Retrieve the database user ID from CLI
Int32 SqlciEnv::getDatabaseUserID(Int32 &uid)
{
  HandleCLIErrorInit();

  Int32 localUID = 0;
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,
                                     &localUID,
                                     NULL, 0, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    uid = localUID;

  return rc;
}
Exemplo n.º 2
0
// ----------------------------------------------------------------------------
// method:  getSessionUser
//
// Returns sessionUser from the Cli context
// ----------------------------------------------------------------------------
Int32 ComUser::getSessionUser(void)
{
  Int32 dbUserID = 0;
  Int32 rc = 0;

  SQL_EXEC_ClearDiagnostics(NULL);

  rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,
                               &dbUserID,
                               NULL, 0, NULL);

  assert(rc >= 0);
  assert(dbUserID >= SUPER_USER);

  return dbUserID;
}
Exemplo n.º 3
0
// Retrieve the external database user ID from CLI
Int32 SqlciEnv::getExternalUserName(NAString &username)
{
  HandleCLIErrorInit();

  char buf[1024] = "";
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_EXTERNAL_USER_NAME,
                                     NULL,
                                     buf, 1024, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    username = buf;

  if (username.length() == 0)
   username = "******";
  return rc;
}
Exemplo n.º 4
0
// Retrieve the database user name from CLI. This will be the
// USER_NAME column from a USERS row not the EXTERNAL_USER_NAME
// column.
Int32 SqlciEnv::getDatabaseUserName(NAString &username)
{
  HandleCLIErrorInit();

  char buf[1024] = "";
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_NAME,
                                     NULL,
                                     buf, 1024, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    username = buf;

  if (rc != 0)
    SQL_EXEC_ClearDiagnostics(NULL);

  return rc;
}
Exemplo n.º 5
0
// ----------------------------------------------------------------------------
// method:  getCurrentUsername
//
// Returns size of username
// ----------------------------------------------------------------------------
bool ComUser::getCurrentUsername(
   char * username,
   Int32 maxUsernameLength)
   
{

   SQL_EXEC_ClearDiagnostics(NULL);

Int32 usernameLength = 0;

Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,NULL,
                                   username,maxUsernameLength,&usernameLength);

   assert(rc >= 0);

   if (usernameLength > maxUsernameLength)
      return false;
     
   return true;

}
Exemplo n.º 6
0
// Private method to retrieve user information from CLI and store a
// copy in the databaseUserID_ and databaseUserName_ members. The
// return value is a SQLCODE. When a value other than zero is
// returned, error information is written into CmpCommon::diags().
Lng32 CmpSqlSession::getUserInfoFromCLI()
{

  NABoolean doDebug = FALSE;
#if defined (NA_DEBUG_C_RUNTIME)
  doDebug = (getenv("DBUSER_DEBUG") ? TRUE : FALSE);
  if (doDebug)
    printf("[DBUSER:%d] BEGIN CmpSqlSession::getUserInfoFromCLI\n",
           (int) getpid());
#endif

  Lng32 sqlcode = 0;
  Int32 localUserID = 0;
  char localUserName[MAX_DBUSERNAME_LEN+1] = "";

  sqlcode = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,
                                    &localUserID, NULL, 0, NULL);
  if (sqlcode != 0)
  {
    SQL_EXEC_MergeDiagnostics_Internal(*CmpCommon::diags());
    SQL_EXEC_ClearDiagnostics(NULL);
  }

  if (doDebug)
    printf("[DBUSER:%d]   SQL_EXEC_GetSessionAttr returned %d\n",
           (int) getpid(), (int) sqlcode);

  if (sqlcode >= 0)
  {
    sqlcode = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_NAME,
                                      NULL,
                                      localUserName,
                                      sizeof(localUserName),
                                      NULL);
    if (sqlcode != 0)
    {
      SQL_EXEC_MergeDiagnostics_Internal(*CmpCommon::diags());
      SQL_EXEC_ClearDiagnostics(NULL);
    }

    if (doDebug)
      printf("[DBUSER:%d]   SQL_EXEC_GetSessionAttr returned %d\n",
             (int) getpid(), (int) sqlcode);
  }

  if (sqlcode >= 0)
  {
    databaseUserID_ = localUserID;
    databaseUserName_ = localUserName;

    // On Linux the value of externalUserName_ is always the same as
    // databaseUserName_
    externalUserName_ = localUserName;

    if (doDebug)
      printf("[DBUSER:%d]   Retrieved user ID %d, name [%s]\n",
             (int) getpid(), (int) localUserID, localUserName);
  }

  if (doDebug)
    printf("[DBUSER:%d] END CmpSqlSession::getUserInfoFromCLI\n",
           (int) getpid());

  return sqlcode;

}