DBA Tips Archive for Oracle

  


The BECOME USER System Privilege

by Jeff Hunter, Sr. Database Administrator

The "BECOME USER" System Privilege is one that has stirred up a lot of confusion amoung DBAs and developers. Oracle unfortunately does not support or comment on the use of this system privilege. I believe that import uses it to import objects in the schemas of other users.

Oracle has an undocumented OCI function called upicui that will allow a given oracle user to become another user. This user has to have the "BECOME USER" system privilege.

Provided below is a simple example using the "upicui" function:

upicui.c
/*
** Test program to test the function "upicui".
**
*/
#include <stdio.h>

#include <oratypes.h>
#include <ocidfn.h>
#include <ociapr.h>

Lda_Def  Lda;
ub1      Hda[256];

main() {
  int     ret;
  char    *user="TESTUSER";   /* The user name has to be in capital letters
                               ** or the same way it appears in sys.user$
                               */

  printf("Connecting to system/manager\n");
  ret = orlon( &Lda, Hda, (text *)"system/manager", -1, (text *)0, -1, 0 );
  if (ret) {
    fprintf(stderr, "Cannot connect ret=%d \n", ret );
    return(ret);
  }

  printf("Become user TESTUSER\n");
  ret = upicui( Hda, 0, user, strlen(user) );
  if (ret) {
    fprintf(stderr, "Cannot connect as %s. ret=%d \n", user, ret );
    return(ret);
  }
}
Compile / Link
# gcc -c -I$ORACLE_HOME/rdbms/public upicui.c
# gcc -L$ORACLE_HOME/lib/ -L$ORACLE_HOME/rdbms/lib/ -o upicui upicui.o -lclntsh
Run
# ./upicui
Connecting to system/manager
Become user TESTUSER


Copyright (c) 1998-2014 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Tuesday, 03-Jan-2006 15:14:36 EST
Page Count: 22990