Пример #1
0
/*
** Close a Connection object.
*/
static int conn_close (lua_State *L) {
	env_data *env;
	conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUASQL_CONNECTION_OCI8);
	luaL_argcheck (L, conn != NULL, 1, LUASQL_PREFIX"connection expected");
	if (conn->closed) {
		lua_pushboolean (L, 0);
		return 1;
	}
	if (conn->cur_counter > 0)
		return luaL_error (L, LUASQL_PREFIX"there are open cursors");

	/* Nullify structure fields. */
	conn->closed = 1;
	if (conn->svchp) {
		if (conn->loggedon)
			OCILogoff (conn->svchp, conn->errhp);
		else
			OCIHandleFree ((dvoid *)conn->svchp, OCI_HTYPE_SVCCTX);
	}
	if (conn->errhp)
		OCIHandleFree ((dvoid *)conn->errhp, OCI_HTYPE_ERROR);
	/* Decrement connection counter on environment object */
	lua_rawgeti (L, LUA_REGISTRYINDEX, conn->env);
	env = lua_touserdata (L, -1);
	env->conn_counter--;
	luaL_unref (L, LUA_REGISTRYINDEX, conn->env);

	lua_pushboolean (L, 1);
	return 1;
}
Пример #2
0
JP_INTERNAL(int) JP_Logoff(TJConnector &conn)
{
  if (conn.user) free(conn.user);
  if (conn.server) free(conn.server);
  conn.result = OCILogoff(conn.ociSvcCtx, conn.ociError);
  conn.ociSvcCtx = 0;
  conn.user = 0;
  conn.server = 0;
  return _Result(conn);
}
Пример #3
0
void	zbx_db_close()
{
#if defined(HAVE_IBM_DB2)
	if (ibm_db2.hdbc)
	{
		SQLDisconnect(ibm_db2.hdbc);
		SQLFreeHandle(SQL_HANDLE_DBC, ibm_db2.hdbc);
	}

	if (ibm_db2.henv)
		SQLFreeHandle(SQL_HANDLE_ENV, ibm_db2.henv);

	memset(&ibm_db2, 0, sizeof(ibm_db2));
#elif defined(HAVE_MYSQL)
	mysql_close(conn);
	conn = NULL;
#elif defined(HAVE_ORACLE)
	/* deallocate statement handle */
	if (NULL != oracle.stmthp)
	{
		OCIHandleFree((dvoid *)oracle.stmthp, OCI_HTYPE_STMT);
		oracle.stmthp = NULL;
	}

	if (NULL != oracle.svchp)
	{
		OCILogoff(oracle.svchp, oracle.errhp);
		oracle.svchp = NULL;
	}

	if (NULL != oracle.errhp)
	{
		OCIHandleFree(oracle.errhp, OCI_HTYPE_ERROR);
		oracle.errhp = NULL;
	}

	if (NULL != oracle.envhp)
	{
		OCIHandleFree((dvoid *)oracle.envhp, OCI_HTYPE_ENV);
		oracle.envhp = NULL;
	}

	if (NULL != oracle.srvhp)
	{
		OCIHandleFree(oracle.srvhp, OCI_HTYPE_SERVER);
		oracle.srvhp = NULL;
	}
#elif defined(HAVE_POSTGRESQL)
	PQfinish(conn);
	conn = NULL;
#elif defined(HAVE_SQLITE3)
	sqlite3_close(conn);
	conn = NULL;
#endif
}
Пример #4
0
static VALUE simple_logoff_execute(void *arg)
{
    simple_logoff_arg_t *sla = (simple_logoff_arg_t *)arg;
    OCIError *errhp = oci8_errhp;
    sword rv;

    OCITransRollback(sla->svchp, errhp, OCI_DEFAULT);
    rv = OCILogoff(sla->svchp, errhp);
    free(sla);
    return (VALUE)rv;
}
Пример #5
0
void FC_FUNC_(oraclesim_delete, ORACLESIM_DELETE) (OracleDbConnection **fdbconnid) {
  OracleDbConnection *dbconnid = *fdbconnid;
  if (dbconnid != NULL) {
    if (dbconnid->svchp != NULL) OCILogoff(dbconnid->svchp, dbconnid->errhp);
    if (dbconnid->stmthp != NULL) OCIHandleFree(dbconnid->stmthp, OCI_HTYPE_STMT);
    if (dbconnid->errhp != NULL) OCIHandleFree(dbconnid->errhp, OCI_HTYPE_ERROR);
    if (dbconnid->envhp != NULL) OCIHandleFree(dbconnid->envhp, OCI_HTYPE_ENV);
    free(dbconnid);
  }
  *fdbconnid = 0;
}
Пример #6
0
/*
=begin
--- OCISvcCtx#logoff()
     disconnect from Oracle.

     If you use ((<OCIServer#attach>)) and ((<OCISession#begin>)) to logon,
     use ((<OCIServer#detach>)) and ((<OCISession#end>)) instead.
     See also ((<Simplified Logon>)) and ((<Explicit Attach and Begin Session>)).

     correspond native OCI function: ((|OCILogoff|))
=end
*/
static VALUE oci8_svcctx_logoff(VALUE self)
{
  oci8_handle_t *h;
  sword rv;

  Get_Handle(self, h); /* 0 */

  rv = OCILogoff(h->hp, h->errhp);
  if (rv != OCI_SUCCESS)
    oci8_raise(h->errhp, rv, NULL);
  return self;
}
Пример #7
0
static void oracle_close_conn(void *theconn)
{
    struct ora_conn *conn = (struct ora_conn*) theconn;

    gw_assert(conn != NULL);

    if (conn->svchp != NULL)
        oracle_checkerr(conn->errhp, OCILogoff(conn->svchp, conn->errhp));

    OCIHandleFree(conn->errhp, OCI_HTYPE_ERROR);
    OCIHandleFree(conn->envp, OCI_HTYPE_ENV);
    /* OCITerminate(OCI_DEFAULT); */

    gw_free(conn);
}
Пример #8
0
/*
  Disconnect from the DBMS.
*/
int
cllDisconnect( icatSessionStruct *icss ) {
    sword stat;
    OCISvcCtx *p_svc;

    p_svc = ( OCISvcCtx * )icss->connectPtr;

    stat = OCILogoff( p_svc, p_err );                         /* Disconnect */
    if ( stat != OCI_SUCCESS ) {
        rodsLog( LOG_ERROR, "cllDisconnect: OCILogoff failed: %d", stat );
        return CAT_DISCONNECT_ERR;
    }

    return 0;
}
Пример #9
0
/*---------------------------------------------------------------------
 * disconnect_db  - Logoff from the database
 *---------------------------------------------------------------------*/
void disconnect_db(oci_t * ocip)
{
  if (OCILogoff(ocip->svcp, ocip->errp))
  {
    ocierror(ocip, (char *)"OCILogoff() failed", TRUE);
  }

  if (ocip->stmtp)
    OCIHandleFree((dvoid *) ocip->stmtp, (ub4) OCI_HTYPE_STMT);

  if (ocip->stmt2p)
    OCIHandleFree((dvoid *) ocip->stmt2p, (ub4) OCI_HTYPE_STMT);
  
  if (ocip->errp)
    OCIHandleFree((dvoid *) ocip->errp, (ub4) OCI_HTYPE_ERROR);

  if (ocip->envp)
    OCIHandleFree((dvoid *) ocip->envp, (ub4) OCI_HTYPE_ENV);
}
Пример #10
0
/*************************************************************************
 *
 *	Function: sql_close
 *
 *	Purpose: database specific close. Closes an open database
 *               connection and cleans up any open handles.
 *
 *************************************************************************/
static int sql_close(SQLSOCK *sqlsocket, SQL_CONFIG *config) {

	rlm_sql_oracle_sock *oracle_sock = sqlsocket->conn;

	if (oracle_sock->conn) {
		OCILogoff (oracle_sock->conn, oracle_sock->errHandle);
	}

	if (oracle_sock->queryHandle) {
		OCIHandleFree((dvoid *)oracle_sock->queryHandle, (ub4) OCI_HTYPE_STMT);
	}
	if (oracle_sock->errHandle) {
		OCIHandleFree((dvoid *)oracle_sock->errHandle, (ub4) OCI_HTYPE_ERROR);
	}
	if (oracle_sock->env) {
		OCIHandleFree((dvoid *)oracle_sock->env, (ub4) OCI_HTYPE_ENV);
	}

	oracle_sock->conn = NULL;
	free(oracle_sock);
	sqlsocket->conn = NULL;

	return 0;
}
Пример #11
0
static int sql_socket_destructor(void *c)
{
	rlm_sql_oracle_conn_t *conn = c;
	
	DEBUG2("rlm_sql_mysql: Socket destructor called, closing socket");
	
	if (conn->ctx) {
		OCILogoff (conn->ctx, conn->errHandle);
	}

	if (conn->queryHandle) {
		OCIHandleFree((dvoid *)conn->queryHandle, (ub4) OCI_HTYPE_STMT);
	}
	
	if (conn->errHandle) {
		OCIHandleFree((dvoid *)conn->errHandle, (ub4) OCI_HTYPE_ERROR);
	}
	
	if (conn->env) {
		OCIHandleFree((dvoid *)conn->env, (ub4) OCI_HTYPE_ENV);
	}
	
	return 0;
}
Пример #12
0
void *thread_process() {
     int thisret,size,i,fields,j,bufout=0,counter=0;
	 int fetch_resu;
     long int datalen,buflen=0;
     int ociposi=-1;
     char buf[_buflen],tmp[_buflen],*realdata ;
     mytext *sqldata;
     int realdatalen=0;
     ub1   *bufp;
     int bufpint=1024;
     dvoid *hdlptr = (dvoid *) 0,*tmphdlptr = (dvoid *) 0;
     ub1   in_out = 0;
     sb2   indptr = 0;
     ub1   piece = OCI_FIRST_PIECE;
     ub4 	hdltype = OCI_HTYPE_DEFINE, iter = 0, idx = 0;
     int poid;
     pthread_detach(pthread_self());
     sqldata=(mytext *)malloc(sizeof(mytext));
     sqldata->next=0;
     sqldata->last=0;
     sqldata->size=0;
     bufp=(ub1 *)malloc(sizeof(ub1)*_clobmax);//**bufp must set to _clobmax
     
     realdata=(char *)malloc(_buflen);  
     realdatalen=_buflen;
     
     if((ociposi=getsession())==-1){
          printf("pool is busy!!\n");
          buf[16]=0;
          exit(1);
     }          
	 
	 
     poci[ociposi].threadid=pthread_self();    
     poci[ociposi].id=ociposi;
     printf("thread id=%d , ociposi=%d \n",pthread_self(),ociposi);
     memset(buf,0,_buflen);
     
			 
     while(1){
          pthread_mutex_lock(&mylock);
          thisret=accept(sock,NULL,NULL);
          pthread_mutex_unlock(&mylock);
          
          poci[ociposi].busy=1;
          bufout=0;
          conn_times++;
          if(conn_times>=1000000){conn_times1++;conn_times=0;}
          if(conn_times1>=1000000)conn_times1=0;
          printf("connections %d millions %d socket=%d ociposi=%d\n",conn_times1,conn_times,thisret,ociposi);
          
          poci[ociposi].datetime=datetime->tm_min*60+datetime->tm_sec;
          poci[ociposi].transfer=0;
          //data_buffer(sqldata,"",2,0);
	        while(sqldata->next){
	            sqldata=sqldata->next;
	        }
	        sqldata->size=0;
	        while(sqldata->last){
	            sqldata=sqldata->last;
	            sqldata->size=0;
	        }								   

          
          
          poci[ociposi].sock=thisret;
          
          
          
          while(size=recv(thisret,buf,_buflen,0)){
               buflen=size;
               buf[buflen]=0;
               poci[ociposi].transfer=1;
               //printf("--buflen=%d \n",buflen);
               
               if(buflen>2){
               }
               else{
                   bufout++;
                   if(bufout>=5 || buflen<=0)break;
               }
               size=buflen;
               if(poci[ociposi].sock==0)continue;
               poci[ociposi].datetime=datetime->tm_min*60+datetime->tm_sec;
               
               
               data_buffer(sqldata,buf,1,buflen);               
               
               //end
               j=0;
               if(size>9)
               for(i=size-9;i<size;i++){
                   tmp[j]=buf[i];
                   j++;
               }
               tmp[j]=0;          
               if((strncmp(buf,_end,strlen(_end))==0)||(strncmp(tmp,_end,strlen(_end))==0)){
                   break;
               }
          
               //set commit off
               if(strncmp(buf,_commitoff,strlen(_commitoff))==0){
                   poci[ociposi].commitmode=1;
                   memset(buf,0,sizeof(buf));
                   send(thisret,_autocommitoff,strlen(_autocommitoff),0);
                   continue;
               }
          
               //_commit
               if(strncmp(buf,_commit,strlen(_commit))==0){
                   OCITransCommit(poci[ociposi].svchp,poci[ociposi].errhp,OCI_DEFAULT );
                   memset(buf,0,sizeof(buf));
                   continue;
               }
                          
               //set commit on
               if(strncmp(buf,_commiton,strlen(_commiton))==0){              
                   poci[ociposi].commitmode=0;
                   memset(buf,0,sizeof(buf));
                   send(thisret,_autocommiton,strlen(_autocommiton),0);
                   continue;
               }                                                                              
               
               //rollback
               if(strncmp(buf,_rollback,strlen(_rollback))==0){
                   OCITransRollback(poci[ociposi].svchp,poci[ociposi].errhp,OCI_DEFAULT) ;
                   poci[ociposi].commitmode=1;
                   memset(buf,0,sizeof(buf));
                   continue;   
               }
               //_serverdown
               if(strncmp(buf,_serverdown,strlen(_serverdown))==0){
               	   OCITerminate(OCI_DEFAULT);
                   exit(1);
               }                    
          
          
               if(sqldata->size+1>=_mytextlen)
               while(sqldata->next){
                  if(sqldata->size+1>=_mytextlen)
                     sqldata=sqldata->next;
                  else
                     break;
               }
               //end input
               size=sqldata->size;
               datalen=size-2; 
               j=0;
               if(size>15)
               for(i=size-15;i<size;i++){
                   tmp[j]=sqldata->mydata[i];
                   j++;
               }
               tmp[j]=0;
               if((strncmp(tmp,_inputend,strlen(_inputend))==0)){    
                   datalen=data_buffer(sqldata,buf,3,0);
                   if(datalen+1>realdatalen){
                       printf("free\n");
                       free(realdata);
                       printf("malloc\n");
                       realdata=(char *)malloc(datalen+1); 
                       realdatalen=datalen+1;
                   }
                   data_buffer(sqldata,realdata,4,0);
                   
                   size=realdatalen;
                   realdata[size-17]=0;          
                   
				   
                   OCIHandleAlloc(poci[ociposi].envhp,(dvoid*)&poci[ociposi].stmthp,OCI_HTYPE_STMT,0,0);
				   
				   printf("oracle_query \n");
                   fields=oracle_query(&poci[ociposi],realdata,datalen-17,tmp);
				   printf("oracle_query ok fields=%d \n",fields);
				   
				   if(fields<=0)break;
                   //printf("start fetch\n");
                   i=0;
				   counter=0;
                   if(fields>0){
                       piece = OCI_FIRST_PIECE ;
                       bufp[0]=0;
                       fetch_data(&poci[ociposi]);
					   counter++;printf("counter=%d \n",counter);
                       send_process(_output_begin,strlen(_output_begin),&poci[ociposi]);
                       
                       while (poci[ociposi].status != OCI_NO_DATA){
               	           //if(OCI_NEED_DATA==poci[ociposi].status){
	               	           //bufpint=4096;
	                           //poci[ociposi].status = OCIStmtGetPieceInfo(poci[ociposi].stmthp, poci[ociposi].errhp, &hdlptr, &hdltype,&in_out, &iter, &idx, &piece);
	                           //poci[ociposi].status = OCIStmtSetPieceInfo(hdlptr, hdltype, poci[ociposi].errhp,(dvoid *) bufp, &bufpint, piece,(CONST dvoid *) &indptr, (ub2 *) 0);
							   
						   //}
						   
						   //printf("data=%s\n",poci[ociposi].data[0]);
						   //printf("data=%s\n",poci[ociposi].data[1]);
						   //printf("data=%s\n",poci[ociposi].data[2]);
						   
						   fetch_data(&poci[ociposi]);
						   if(poci[ociposi].status<0)break;
						   
						   counter++;printf("OCI_NO_DATA=%d , poci[ociposi].status=%d , counter=%d fetch_resu=%d \n",OCI_NO_DATA,poci[ociposi].status,counter);
						   bufp[bufpint]=0;
						   
						   
							for (i=0;i<fields;i++){
								send_process(poci[ociposi].data[i],strlen(poci[ociposi].data[i]),&poci[ociposi]);
								if(i+1<fields){
									send_process(_output_column,strlen(_output_column),&poci[ociposi]);
								}
							}
						    send_process(_output_row,strlen(_output_row),&poci[ociposi]);
						   /*
						   if(poci[ociposi].status==OCI_NEED_DATA){
								if(tmphdlptr!=hdlptr){
								  i++;
							  if(i>1)
							  if((i-1)%fields==0){
								  send_process(_output_row,strlen(_output_row),&poci[ociposi]);
							   }else{
								  send_process(_output_column,strlen(_output_column),&poci[ociposi]);
							   }
							   tmphdlptr=hdlptr;
							   }
							   send_process(bufp,bufpint,&poci[ociposi]);
						   }*/
                       	}
                       	
                       	if(i>1){
                       		send_process(_output_column,strlen(_output_column),&poci[ociposi]);
                       		send_process(bufp,bufpint,&poci[ociposi]);
                       		send_process(_output_row,strlen(_output_row),&poci[ociposi]);
                       	}
                       	send_process(_output_end,strlen(_output_end),&poci[ociposi]);
                   }else{
                      if((fields<0) && (strlen(poci[ociposi].errbuf)>0)){
                      	   send_process(_output_beginerr,strlen(_output_beginerr),&poci[ociposi]);
                           send_process(poci[ociposi].errbuf,512,&poci[ociposi]);
                           send_process(_output_end,strlen(_output_end),&poci[ociposi]);
                      }else{
                           send_process(_ok,strlen(_ok),&poci[ociposi]);
                      }
                   }
                   
                   OCIHandleFree(poci[ociposi].stmthp,OCI_HTYPE_STMT);
                   //printf("fetch ok\n");                                                         
                   send_process("",-1,&poci[ociposi]);
								   //printf("data send ok\n");
						       datalen=0;
								   //data_buffer(sqldata,"",2,0);
						        while(sqldata->next){
						            sqldata=sqldata->next;
						        }
						        sqldata->size=0;
						        while(sqldata->last){
						            sqldata=sqldata->last;
						            sqldata->size=0;
						        }								   
								   //printf("query complete\n");
		               
               }
               poci[ociposi].transfer=0;
          }
          close(thisret);
          poci[ociposi].busy=0;
		  if(fields==-99){
			poci[ociposi].id=-1;
			OCILogoff(poci[ociposi].svchp,poci[ociposi].errhp);
			OCIHandleFree(poci[ociposi].envhp,OCI_HTYPE_ENV);
			
			pthread_create(&ph[ociposi], NULL, &thread_process,NULL);
			printf("exit program \n");
			break;
		  
		  }
    }   

}
Пример #13
0
/* main */
int main(int argc, char* argv[])
{
	double start, total;
	sword status;

	total = get_time();

	printf("START\n");

	get_command_line_arguments(argc, argv);

	start = get_time();
	OCIEnvCreate(&envhp, OCI_THREADED | OCI_OBJECT, (dvoid *)0,  NULL, NULL, NULL, 0, (dvoid *)0);
	elapsed_time("OCIEnvCreate", start);

	start = get_time();
	OCIHandleAlloc((dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0);
	OCIHandleAlloc((dvoid *) envhp, (dvoid **) &poolhp, OCI_HTYPE_CPOOL, (size_t) 0, (dvoid **) 0);
	elapsed_time("OCIHandleAlloc", start);
 
	if (!useConnectionPool)
	{
		/* CONNECT DIRECTLY TO THE SERVER */
		start = get_time();
		status = OCILogon2(
			envhp,					// envhp        (IN) A pointer to the environment where the connection pool is to be created.
			errhp,					// errhp    (IN/OUT) An error handle you can pass to OCIErrorGet() for diagnostic information in the event of an error.
			&svchp,					// svchp    (IN/OUT) Address of an OCI service context pointer. This is filled with a server and session handle.
			username,				// username     (IN) The user name used to authenticate the session. Must be in the encoding specified by the charset parameter of a previous call to OCIEnvNlsCreate().
			olen(username),			// uname_len    (IN) The length of username, in number of bytes, regardless of the encoding.
			password,				// password     (IN) The user's password. For connection pooling, if this parameter is NULL then OCILogon2() assumes that the logon is for a proxy user. It implicitly creates a proxy connection in such a case, using the pool user to authenticate the proxy user. Must be in the encoding specified by the charset parameter of a previous call to OCIEnvNlsCreate().
			olen(password),			// passwd_len   (IN) The length of password, in number of bytes, regardless of the encoding.
			database,				// dbname       (IN) For the default case, this indicates the connect string to use to connect to the Oracle Database.
			olen(database),			// dbname_len   (IN) The length of dbname. For session pooling and connection pooling, this value is returned by the OCISessionPoolCreate() or OCIConnectionPoolCreate() call respectively.
			OCI_DEFAULT				// mode         (IN) The values accepted are: OCI_DEFAULT, OCI_LOGON2_CPOOL, OCI_LOGON2_SPOOL, OCI_LOGON2_STMTCACHE, OCI_LOGON2_PROXY
			);
		elapsed_time("OCILogon2 to the server", start);
		if (status)
		{
			checkerr(errhp, status);
			exit(1);
		}

		/* DISCONNECT */
		start = get_time();
		checkerr(errhp, OCILogoff((dvoid *) svchp, errhp));
		elapsed_time("OCILogoff from the server", start);
	}

	if (useConnectionPool)
	{
		/* CREATE THE CONNECTION POOL */
		start = get_time();
		status = OCIConnectionPoolCreate(
			envhp,					// envhp        (IN) A pointer to the environment where the connection pool is to be created.
			errhp,					// errhp    (IN/OUT) An error handle you can pass to OCIErrorGet() for diagnostic information in the event of an error.
			poolhp,					// poolhp       (IN) An allocated pool handle.
			&poolName,				// poolName    (OUT) The name of the connection pool connected to.
			&poolNameLen,			// poolNameLen (OUT) The length of the string pointed to by poolName.
			database,				// dblink       (IN) Specifies the database (server) to connect to.
			olen(database),			// dblinkLen    (IN) The length of the string pointed to by dblink.
			conMin,					// connMin      (IN) Specifies the minimum number of connections in the connection pool. Valid values are 0 and above.
			conMax,					// connMax      (IN) Specifies the maximum number of connections that can be opened to the database. Once this value is reached, no more connections are opened. Valid values are 1 and above.
			conIncr,				// connIncr     (IN) Allows the application to set the next increment for connections to be opened to the database if the current number of connections are less than connMax. Valid values are 0 and above.
			appusername,			// poolUsername (IN) Connection pooling requires an implicit primary session and this attribute provides a username for that session.
			olen(appusername),		// poolUserLen  (IN) The length of poolUsername.
			apppassword,			// poolPassword (IN) The password for the username poolUsername.
			olen(apppassword),		// poolPassLen  (IN) The length of poolPassword.
			OCI_DEFAULT				// mode         (IN) The modes supported are
			);
		elapsed_time("OCIConnectionPoolCreate", start);
		if (status)
		{
			checkerr(errhp, status);
			exit(1);
		}

		/* CONNECT USING THE CONNECTION POOL */
		start = get_time();
		status = OCILogon2(
			envhp,					// envhp        (IN) A pointer to the environment where the connection pool is to be created.
			errhp,					// errhp    (IN/OUT) An error handle you can pass to OCIErrorGet() for diagnostic information in the event of an error.
			&svchp,					// svchp    (IN/OUT) Address of an OCI service context pointer. This is filled with a server and session handle.
			username,				// username     (IN) The user name used to authenticate the session. Must be in the encoding specified by the charset parameter of a previous call to OCIEnvNlsCreate().
			olen(username),			// uname_len    (IN) The length of username, in number of bytes, regardless of the encoding.
			password,				// password     (IN) The user's password. For connection pooling, if this parameter is NULL then OCILogon2() assumes that the logon is for a proxy user. It implicitly creates a proxy connection in such a case, using the pool user to authenticate the proxy user. Must be in the encoding specified by the charset parameter of a previous call to OCIEnvNlsCreate().
			olen(password),			// passwd_len   (IN) The length of password, in number of bytes, regardless of the encoding.
			poolName,				// dbname       (IN) For the default case, this indicates the connect string to use to connect to the Oracle Database.
			poolNameLen,			// dbname_len   (IN) The length of dbname. For session pooling and connection pooling, this value is returned by the OCISessionPoolCreate() or OCIConnectionPoolCreate() call respectively.
			OCI_LOGON2_CPOOL		// mode         (IN) The values accepted are: OCI_DEFAULT, OCI_LOGON2_CPOOL, OCI_LOGON2_SPOOL, OCI_LOGON2_STMTCACHE, OCI_LOGON2_PROXY
			);
		elapsed_time("OCILogon2 using the connection pool", start);
		if (status)
		{
			checkerr(errhp, status);
			exit(1);
		}

		/* DISCONNECT */
		start = get_time();
		checkerr(errhp, OCILogoff((dvoid *) svchp, errhp));
		elapsed_time("OCILogoff from the connection pool", start);

		/* DESTROY THE CONNECTION POOL */
		start = get_time();
		checkerr(errhp, OCIConnectionPoolDestroy(poolhp, errhp, OCI_DEFAULT));
		elapsed_time("OCIConnectionPoolDestroy", start);
	}

	/* FREE HANDLES */  
	start = get_time();
	checkerr(errhp, OCIHandleFree((dvoid *)poolhp, OCI_HTYPE_CPOOL));
	checkerr(errhp, OCIHandleFree((dvoid *)errhp, OCI_HTYPE_ERROR));
	elapsed_time("OCIHandleFree", start);

	printf("END\n");
	elapsed_time("Total execution time", total);

	return 0;
} 
Пример #14
0
void DisconnectServer() {
	OCILogoff(hsvc, herr);
}
Пример #15
0
int main(int argc,char** argv)  
{  
	int nRet;  
	OCIEnv*      phOCIEnv;    //OCI环境句柄  
	OCIError*    phOCIErr;    //OCI错误句柄  
	OCISvcCtx*   phOCIConn;   //OCI数据库服务连接句柄  
 
	char acDBName[20],acUserName[20],acPwd[20];  
 
	//初始化OCI应用环境  
	nRet = OCIInitialize((ub4)OCI_DEFAULT,(dvoid*)0,(dvoid* (*)(dvoid*,size_t))0,
			(dvoid* (*)(dvoid*,dvoid*,size_t))0,(void (*)(dvoid*,dvoid*))0);  
	if(nRet)  
	{  
		printf("OCIInitialize() Failed: %d\n",(int)OCI_ERROR);  
		return (int)OCI_ERROR;  
	}  
 
	//初始化OCI环境句柄(由系统来负责分配OCI环境句柄)  
	nRet = OCIEnvInit(&phOCIEnv,(ub4)OCI_DEFAULT,(size_t)0,(dvoid**)0);  
	if(nRet)  
	{  
		printf("OCIEnvInit() Failed: %d\n",(int)OCI_ERROR);  
		return (int)OCI_ERROR;  
	}  
 
	//在OCI应用环境中依据OCI环境句柄来分配OCI的错误报告句柄  
	nRet = OCIHandleAlloc((dvoid*)phOCIEnv,(dvoid**)&phOCIErr,
		    (ub4)OCI_HTYPE_ERROR,(size_t)0,(dvoid**)0);  
	if(nRet)  
	{  
		printf("OCIHandleAlloc() Failed: %d\n",(int)OCI_ERROR);  
		return (int)OCI_ERROR;  
	}  
 
	//建立与Oracle的连接  
	memset(acDBName,0,sizeof(acDBName));  
	memset(acUserName,0,sizeof(acUserName));  
	memset(acPwd,0,sizeof(acPwd));  
 
	strcpy(acDBName,"simplegw");  
	strcpy(acUserName,"simplegw");  
	strcpy(acPwd,"simplegw");  
 
	//连接数据库  
	nRet = OCILogon(phOCIEnv,phOCIErr,&phOCIConn,(text*)acUserName,
		    strlen(acUserName),(text*)acPwd,strlen(acPwd),
	    (OraText*)acDBName,strlen(acDBName));  
	if(nRet)  
	{  
		printf("Connection Failed: %d\n\n",nRet);  
		exit(1);  
	}  
	printf("Connection OK: %d\n",nRet);  
	printf("执行一些SQL语句和数据库操作命令 ......\n\n");  







 
	//断开与数据库的连接  
	nRet = OCILogoff(phOCIConn,phOCIErr);  
	if(nRet)  
	{  
		printf("OCILogoff() Failed.\n\n");  
	}
	else 
	{  
		printf("Connecttion closed.\n\n");  
	}  
	//连接已经断开,把连接句柄置为空  
	phOCIConn = NULL;  
 
	//销毁OCI应用环境与相关的句柄  
	if(phOCIErr)  
	{  
		OCIHandleFree((dvoid*)phOCIErr,OCI_HTYPE_ERROR);  
		printf("OCI错误报告句柄已经释放.\n\n");  
	}  
 
	if(phOCIEnv)  
	{  
		OCIHandleFree((dvoid*)phOCIEnv,(ub4)OCI_HTYPE_ENV);  
		printf("OCI环境句柄已经释放.\n\n");  
	}  
	printf("OCI环境释放结束.\n\n");  
	return 0;  
} 
Пример #16
0
int start_oracle(int s, char *ip, int port, unsigned char options, char *miscptr, FILE * fp) {
  char *empty = "";
  char *login, *pass, buffer[200], sid[100];

  if (strlen(login = hydra_get_next_login()) == 0)
    login = empty;
  if (strlen(pass = hydra_get_next_password()) == 0)
    pass = empty;

  strncpy(sid, miscptr, sizeof(sid));
  snprintf(buffer, sizeof(buffer), "//%s:%d/%s", hydra_address2string(ip), port, sid);

  /*

     To use the Easy Connect naming method, PHP must be linked with Oracle 10g or greater Client libraries.
     The Easy Connect string for Oracle 10g is of the form: [//]host_name[:port][/service_name].
     With Oracle 11g, the syntax is: [//]host_name[:port][/service_name][:server_type][/instance_name].
     Service names can be found by running the Oracle utility lsnrctl status on the database server machine.

     The tnsnames.ora file can be in the Oracle Net search path, which includes $ORACLE_HOME/network/admin
     and /etc. Alternatively set TNS_ADMIN so that $TNS_ADMIN/tnsnames.ora is read. Make sure the web
     daemon has read access to the file. 

   */

  if (OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL)) {
    print_oracle_error("OCIInitialize");
    return 4;
  }
  if (OCIEnvInit(&o_environment, OCI_DEFAULT, 0, NULL)) {
    print_oracle_error("OCIEnvInit");
    return 4;
  }
  if (OCIEnvInit(&o_environment, OCI_DEFAULT, 0, NULL)) {
    print_oracle_error("OCIEnvInit 2");
    return 4;
  }
  if (OCIHandleAlloc(o_environment, (dvoid **) & o_error, OCI_HTYPE_ERROR, (size_t) 0, NULL)) {
    print_oracle_error("OCIHandleAlloc");
    return 4;
  }

  if (OCILogon(o_environment, o_error, &o_servicecontext, (const OraText *) login, strlen(login), (const OraText *) pass, strlen(pass), (const OraText *) buffer, strlen(buffer))) {
    OCIErrorGet(o_error, 1, NULL, &o_errorcode, o_errormsg, sizeof(o_errormsg), OCI_HTYPE_ERROR);
    //database: oracle_error: ORA-01017: invalid username/password; logon denied
    //database: oracle_error: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
    //database: oracle_error: ORA-28000: the account is locked
    //Failed login attempts is set to 10 by default
    if (verbose) {
      hydra_report(stderr, "[VERBOSE] database: oracle_error: %s\n", o_errormsg);
    }
    if (strstr((const char *) o_errormsg, "ORA-12514") != NULL) {
      hydra_report(stderr, "[ERROR] ORACLE SID is not valid, you should try to enumerate them.\n");
    }
    if (strstr((const char *) o_errormsg, "ORA-28000") != NULL) {
      hydra_report(stderr, "[ERROR] ORACLE account %s is locked.\n", login);
    }

    if (o_error) {
      OCIHandleFree((dvoid *) o_error, OCI_HTYPE_ERROR);
    }

    hydra_completed_pair();
    //by default, set in sqlnet.ora, the trace file is generated in pwd to log any errors happening,
    //as we don't care, we are deleting the file
    //set these parameters to not generate the file
    //LOG_DIRECTORY_CLIENT = /dev/null
    //LOG_FILE_CLIENT = /dev/null
    unlink("sqlnet.log");

    return 2;
  } else {
    OCILogoff(o_servicecontext, o_error);
    if (o_error) {
      OCIHandleFree((dvoid *) o_error, OCI_HTYPE_ERROR);
    }
    hydra_report_found_host(port, ip, "oracle", fp);
    hydra_completed_pair_found();
  }
  if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
    return 3;
  return 1;
}