Пример #1
0
int main(int argc, char *argv[])
{
  OCIError *errhp = NULL;

  printf("stage4: Demonstrating OCI statement caching \n");

  /* parse command line options */
  parse_options(argc, argv);
  
  checkenv(envhp, OCIEnvCreate(&envhp,                /* returned env handle */
                               OCI_THREADED,         /* initialization modes */
                               NULL, NULL, NULL, NULL, /* callbacks, context */
                               (size_t) 0,    /* extra memory size: optional */
                               (void **) NULL));    /* returned extra memory */

  /* allocate error handle
   * note: for OCIHandleAlloc(), we always check error on environment handle
   */
  checkenv(envhp, OCIHandleAlloc(envhp,                /* environment handle */
                                 (void **) &errhp,    /* returned err handle */
                                 OCI_HTYPE_ERROR,/*type of handle to allocate*/
                                 (size_t) 0,  /* extra memory size: optional */
                                 (void **) NULL));  /* returned extra memory */

  create_session_pool(envhp, errhp, &poolName, &poolNameLen);

  /* allocate auth handle
   * note: for OCIHandleAlloc(), we check error on environment handle
   */
  checkenv(envhp, OCIHandleAlloc(envhp,
                          (void **) &authp, OCI_HTYPE_AUTHINFO,
                          (size_t) 0, (void **) NULL));

  /* setup username and password */
  checkerr(errhp, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO,
                             (void *) username, strlen((char *)username),
                             OCI_ATTR_USERNAME, errhp));

  checkerr(errhp, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO,
                            apppassword, strlen((char *) apppassword),
                            OCI_ATTR_PASSWORD, errhp));

  spawn_threads(envhp, errhp, &thread_function);
  
  /* Destroy the session pool */
  OCISessionPoolDestroy(spoolhp, errhp, OCI_DEFAULT);

  /* clean up */
  if (authp)
    OCIHandleFree(authp, OCI_HTYPE_AUTHINFO);
  if (spoolhp)
    OCIHandleFree(spoolhp, OCI_HTYPE_SPOOL); 
  if (errhp)
    OCIHandleFree(errhp, OCI_HTYPE_ERROR);
  if (envhp)
    OCIHandleFree(envhp, OCI_HTYPE_ENV);
  
  return 0;
}
Пример #2
0
ocisession::ocisession(const char * connect_str, const int connect_str_len,
					   const char * user_name, const int user_name_len,
					   const char * password, const int password_len)
{
	intf_ret r;
	OCIAuthInfo *authp = NULL;

	init();

	r.handle = envhp;

	// allocate error handle
	checkenv(&r, OCIHandleAlloc((OCIEnv*)envhp,	/* environment handle */
                            (void **) &_errhp,	/* returned err handle */
                            OCI_HTYPE_ERROR,	/* typ of handle to allocate */
                            (size_t) 0,			/* optional extra memory size */
                            (void **) NULL));	/* returned extra memeory */

	if(r.fn_ret != SUCCESS) {
   		REMOTE_LOG("failed OCISessionGet %s\n", r.gerrbuf);
        throw r;
	}

	// allocate auth handle
	checkenv(&r, OCIHandleAlloc((OCIEnv*)envhp,
							(void**)&authp, OCI_HTYPE_AUTHINFO,
							(size_t)0, (void **) NULL));

	r.handle = _errhp;

	// usrname and password
	checkerr(&r, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO,
								(void*) user_name, user_name_len,
								OCI_ATTR_USERNAME, (OCIError *)_errhp));
	checkerr(&r, OCIAttrSet(authp, OCI_HTYPE_AUTHINFO,
								(void*) password, password_len,
								OCI_ATTR_PASSWORD, (OCIError *)_errhp));


    /* get the database connection */
    checkerr(&r, OCISessionGet((OCIEnv*)envhp, (OCIError *)_errhp,
                               (OCISvcCtx**)&_svchp,					/* returned database connection */
                               authp,									/* initialized authentication handle */                               
                               (OraText *) connect_str, connect_str_len,/* connect string */
                               NULL, 0, NULL, NULL, NULL,				/* session tagging parameters: optional */
                               OCI_SESSGET_STMTCACHE));					/* modes */
	if(r.fn_ret != SUCCESS) {
		REMOTE_LOG("failed OCISessionGet %s\n", r.gerrbuf);
        throw r;
	}

	(void) OCIHandleFree(authp, OCI_HTYPE_AUTHINFO);

	REMOTE_LOG("got session %p\n", _svchp);

	_sessions.push_back(this);
}
Пример #3
0
void oci_init(void)
{
	function_success = SUCCESS;
    checkenv(envhp, OCIEnvCreate(&envhp,				/* returned env handle */
                                 OCI_DEFAULT,			/* initilization modes */
                                 NULL, NULL, NULL, NULL,/* callbacks, context */
                                 (size_t) 0,			/* optional extra memory size: optional */
                                 (void**) NULL));		/* returned extra memeory */

    checkenv(envhp, OCIHandleAlloc(envhp,				/* environment handle */
                                   (void **) &errhp,	/* returned err handle */
                                   OCI_HTYPE_ERROR,		/* typ of handle to allocate */
                                   (size_t) 0,			/* optional extra memory size */
                                   (void **) NULL));	/* returned extra memeory */

    if(function_success != SUCCESS)
        exit(1);
}
Пример #4
0
uint_t
la_version(uint_t version)
{
  
	int	fd;
	sigset_t mask;

	if (version < LAV_CURRENT) {
		(void) fprintf(stderr,
		    "audit.so.1: unexpected version: %d\n",
		    version);
		return (0);
	}

	build_env_list(&bindto_list, (const char *)"AUDIT_BINDTO");
	build_env_list(&bindfrom_list, (const char *)"AUDIT_BINDFROM");
        
        if (checkenv((const char *)"AUDIT_PID")) {
		pidout = 1;
		pid = getpid();
	} else {
		char	*str = "LD_AUDIT=";
		/*
		 * This disables truss output in subsequent fork()/exec
		 * processes.
		 */
		(void) putenv(str);
	}
        if (checkenv((const char *)"AUDIT_NOEXIT")) {
		noexit++;
		indent = 0;
	}
        
        
        
        (void) sigfillset(&iset);
        return (LAV_CURRENT);
}
Пример #5
0
void ocisession::init(void)
{
	intf_ret r;
 	r.fn_ret = SUCCESS;

	if(envhp == NULL) {
		sword ret = 0;
		ret = OCIEnvCreate((OCIEnv**)&envhp,		/* returned env handle */
						   OCI_THREADED,			/* initilization modes */
						   NULL, NULL, NULL, NULL,	/* callbacks, context */
						   (size_t) 0,				/* optional extra memory size: optional */
						   (void**) NULL);			/* returned extra memeory */

		r.handle = envhp;
		checkenv(&r, ret);
		if(r.fn_ret != SUCCESS)
        throw r;
	}
}
Пример #6
0
bool oci_create_tns_seesion_pool(const unsigned char * connect_str, const int connect_str_len,
                                 const unsigned char * user_name, const int user_name_len,
                                 const unsigned char * password, const int password_len,
                                 const unsigned char * options, const int options_len)
{
    function_success = SUCCESS;
    poolName = NULL;
    poolNameLen = 0;

    oci_free_session_pool();

    /* allocate session pool handle
     * note: for OCIHandleAlloc() we check error on environment handle
     */
    checkenv(envhp, OCIHandleAlloc(envhp, (void **)&spoolhp,
                                   OCI_HTYPE_SPOOL, (size_t) 0, (void **) NULL));

    /* set the statement cache size for all sessions in the pool
     * note: this can also be set per session after obtaining the session from the pool
     */
    checkerr(errhp, OCIAttrSet(spoolhp, OCI_HTYPE_SPOOL,
                               &stmt_cachesize, 0, OCI_ATTR_SPOOL_STMTCACHESIZE, errhp));

    checkerr(errhp, OCISessionPoolCreate(envhp, errhp,
                                         spoolhp,
                                         (OraText **) &poolName, &poolNameLen,
                                         (OraText *) connect_str, connect_str_len,
                                         POOL_MIN, POOL_MAX, POOL_INCR,
                                         (OraText*)user_name, user_name_len,			/* h**o pool user specified */
                                         (OraText*)password, password_len,			/* h**o pool password specified */
                                         OCI_SPC_STMTCACHE));	/* modes */
    if(function_success != SUCCESS)return false;

    sprintf_s(session_pool_name, sizeof(session_pool_name), "%.*s", poolNameLen, (char *)poolName);

    ub1 spoolMode = OCI_SPOOL_ATTRVAL_NOWAIT;
    checkerr(errhp, OCIAttrSet(spoolhp, OCI_HTYPE_SPOOL,
                               (void*)&spoolMode, sizeof(ub1),
                               OCI_ATTR_SPOOL_GETMODE, errhp));
    if(function_success != SUCCESS)return false;

    return true;
}
Пример #7
0
/* thread_function can be run in multi-threads, each thread will have its own 
   error handle */
void thread_function(void *ptr)
{
  OCIError    *errhp = NULL;
  int          i=0;

  /* allocate error handle
   * note: for OCIHandleAlloc(), we always check error on environment handle
   */
  checkenv(envhp, OCIHandleAlloc(envhp,                /* environment handle */
                                 (void **) &errhp,    /* returned err handle */
                                 OCI_HTYPE_ERROR,/*type of handle to allocate*/
                                 (size_t) 0,  /* extra memory size: optional */
                                 (void **) NULL));  /* returned extra memory */
  
  for(i=0; i<iteration; i++)
  {
    OCISvcCtx *svchp = NULL; /* OCI Service Context is a database connection */

    /* get the database connection */
    checkerr(errhp, OCISessionGet(envhp, errhp,
                                &svchp,      /* returned database connection */
                                authp,  /* initialized authentication handle */
                                                        /* connect pool name */
                                (OraText *) poolName, poolNameLen,
                                     /* session tagging parameters: optional */
                                NULL, 0, NULL, NULL, NULL,
                                OCI_SESSGET_SPOOL));

    do_workload(svchp, errhp, ptr,i);
    
    /* destroy the connection */
    checkerr(errhp, OCISessionRelease(svchp, errhp, NULL, 0, OCI_DEFAULT));

    print_progress(ptr, i);                                /* print progress */
    
    if (waittime > 0)
      sleep(waittime);            /* Thinking time between database sessions */
  }

  if (errhp)
    OCIHandleFree(errhp, OCI_HTYPE_ERROR);
}
Пример #8
0
static void create_session_pool(OCIEnv *envhp, OCIError * errhp,
                         char **poolName, ub4 *poolNameLenp)
{
  ub4       stmt_cachesize = 20;
  ub4  min;                            /* minimum number of sessions in pool */
  ub4  max;                            /* maximum number of sessions in pool */
  ub4  increment;                     /* the number to increment the pool by */

  /* allocate session pool handle
   * note: for OCIHandleAlloc(), we check error on environment handle
   */
  checkenv(envhp, OCIHandleAlloc(envhp, (void **) &spoolhp,
           OCI_HTYPE_SPOOL, (size_t) 0, (void **) NULL));

  /* set the statement cache size for all sessions in the pool */
  checkerr(errhp, OCIAttrSet(spoolhp, OCI_HTYPE_SPOOL,
                  &stmt_cachesize, 0, OCI_ATTR_SPOOL_STMTCACHESIZE, errhp));

  min = thread_num;                    /* minimum number of sessions in pool */
  max = thread_num + 1;                /* maximum number of sessions in pool */
  increment = 1;                      /* the number to increment the pool by */

  /* create a homogeneous session pool */
  checkerr(errhp,
           OCISessionPoolCreate(envhp, errhp,
                                spoolhp,              /* session pool handle */
                                                /* returned poolname, length */
                                (OraText **) poolName, poolNameLenp,
                                                           /* connect string */
                                (const OraText *) connstr, strlen(connstr),
                                min, max, increment,/* pool size constraints */
                                                                 /* username */
                                (OraText *) username,strlen((char *) username),
                                                                 /* password */
                                (OraText *) apppassword,
                                strlen((char *) apppassword),
                                                                    /* modes */
                                OCI_SPC_HOMOGENEOUS|OCI_SPC_STMTCACHE));
}
Пример #9
0
void execute(int argc, const char **argv) {

    /*** Shell internal commands ***/

    if (runInternalCommand(argc, argv))
        return;

    /*** Aliases ***/

    else if (strcmp("pager", argv[0]) == 0) {
        page(argc, argv);
    }
    else if (strcmp("checkEnv", argv[0]) == 0) {
        checkenv(argc, argv);
    }

    /*** External command ***/

    else {
        execvp(argv[0], (char * const*) argv);
        fprintf(stderr, "Could not run program %s : %s\n", argv[0], strerror(errno));
        exit(0);
    }
}
Пример #10
0
int main()
{
    FILE *makefile;
    FILE *config;
    FILE *sslrnd;
    FILE *uran;
#ifndef SSLPATH
    char *sslblist[]={
	"/bin/openssl",
	"/usr/bin/openssl",
	"/usr/sbin/openssl",
	"/usr/local/bin/openssl",
	"/usr/local/ssl/bin/openssl",
	NULL
    };
#endif
    int sslin=0;
    int provi=0;
    unsigned char rchar,orchar;
    int ic;
#ifdef SSLPATH
    char mbuf[strlen(SSLPATH)+30];
    char ibuf[strlen(SSLPATH)+20];
#else
    char mbuf[200];
    char ibuf[200];
#endif
    bigopt[0]=0;
    sunosopt[0]=0;
    timeopt[0]=0;
    ipv6opt[0]=0;
    ssllib[0]=0;
    socklib[0]=0;
    snbuf[0]=0;
    snopt[0]=0;
    env[0]=0;
    sslbin[0]=0;
    sslopt[0]=0;
    dnsopt[0]=0;
    dnslib[0]=0;
    printf("System:");
    getos();    
    printf(" %s\n",os);
    if(strstr(os,"SunOS")==os) strcpy(sunosopt,"-DSUNOS ");
    printf("Socket Libs: ");
    fflush(stdout);
    needsock=checksocklib();
    if(needsock!=0)
    {
	/* in the case of external socket-libs, sol8 needs to check for lbind */
	strcpy(socklib,"-lnsl -ldl -lsocket ");
	needbind=checkbind();
	if(needbind!=0)
	{
	    strcat(socklib,"-lbind ");
	    printf("External, -lbind required.\n");
	} else
	    printf("External.\n");
    }
    else
	printf("Internal.\n");
    fflush(stdout);
    printf("Environment: ");
    fflush(stdout);
    extenv=checkenv();
    if(extenv!=0)
    {
	printf("No internal Routines.\n");
	strcpy(env," src/bsd-setenv.o ");
    }
    else
    {
	printf("Internal.\n");
    }
    fflush(stdout);
    printf("Time-Headers: ");
    fflush(stdout);
    off_time=checktime();
    if(off_time!=0)
    {
	printf("in time.h and sys/time.h\n");
	strcpy(timeopt," -DNOSYSTIME ");
    }
    else
    {
	printf("in sys/time.h.\n");
    }
    fflush(stdout);
    bigendian=checkendian();
    if(bigendian)
    {
	printf("Byte order: Big Endian.\n");
	strcpy(bigopt,"-DBIGENDIAN ");
    }
    else
	printf("Byte order: Low Endian.\n");
    printf("IPv6-Support: ");
    fflush(stdout);
    ipv6=checkipv6();
    if(ipv6==0)
    {
#ifdef AF_INET6
	ic=checkipv6usable();
	if(ic==0)
	{
	    printf("Yes.\n");
	    strcpy(ipv6opt,"-DIPV6 ");
	} else {
	    printf("Yes, general support. But no interface configured.\n");
	    ipv6=1;
	}
#else
	printf("No.\n");
	ipv6=1;
#endif
    }
    else
	printf("No.\n");
    printf("async-DNS-Support: ");
    fflush(stdout);
    dns=checkresolve();
    if(dns==0)
    {
    	printf("Yes.\n");
	strcpy(dnslib,"-lresolv ");
    }
    else
    {
	strcpy(dnsopt,"-DBLOCKDNS ");
	printf("No, using blocking DNS.\n");
    }
    printf("SSL-Support: ");
    fflush(stdout);
    ssl=checkssl();
    if(ssl==0)
    {
#ifndef SSLPATH
	while(sslblist[sslin]!=NULL)
	{
	    if(fexists(sslblist[sslin]))
		break;
	    sslin++;
	}
	if(sslblist[sslin]==NULL)
	{
	    printf("Yes, but no openssl binary found.");
	    ssl=-1;
	} else {
	    strcpy(sslbin,sslblist[sslin]);
	    printf("Yes.\n");
	    strcpy(sslopt,"-DHAVE_SSL ");
	    strcpy(ssllib,"-L/usr/local/ssl/lib -lssl -lcrypto ");
	}
#else
	if(strlen(SSLPATH)+13<sizeof(mbuf))
	{
	    strcpy(mbuf,SSLPATH);
	    if(mbuf[strlen(mbuf)-1]!='/')
		strcat(mbuf,"/");
	    strcpy(ibuf,mbuf);
	    strcat(mbuf,"bin/openssl");
	    if(fexists(mbuf)==0)
	    {
		printf("Yes, but no openssl binary found in \"%s\".",SSLPATH);
		ssl=-1;
	    } else {
		strcpy(sslbin,mbuf);
		printf("Yes.\n");
		strcpy(sslopt,"-DHAVE_SSL ");
		strcpy(ssllib,"-L");
		strcat(ssllib,ibuf);
		strcat(ssllib,"lib -lssl -lcrypto ");
	    }
	} else {
	    printf("Possibly. But the configured path \"%s\" is too long.\n",SSLPATH);
	}	
#endif
    }
    else
	printf("No openssl found. Get openssl at www.openssl.org\n");
    config=fopen("/psybnc/config.h","r");
    if(config!=NULL)
    {
	fclose(config);
	printf("Found Provider-Config - Using this for compilation\n");
	provi=1;
    }
    printf("Creating Makefile\n");
    makefile=fopen("makefile.out","w");
    if(makefile==NULL)
    {
	printf("Can't create makefile.out .. aborting\n");
	exit(0x1);
    }
    fprintf(makefile,"CC	= gcc\n");
    fprintf(makefile,"SRC	= src/\n");
#ifdef BOUNDCHECK
    fprintf(makefile,"CFLAGS  = -O -fbounds-checking -fno-builtin\n");
#else
    fprintf(makefile,"CFLAGS  = -O\n");
#endif
    fprintf(makefile,"LIBS	= -lm %s %s %s\n",socklib,ssllib,dnslib); /* math lib needed for snprintf of ap */
    if(ssl==0)
#ifdef SSLPATH
	fprintf(makefile,"INCLUDE = -I./src/ -I. -I%sinclude\n",SSLPATH);
#else
	fprintf(makefile,"INCLUDE = -I./src/ -I. -I/usr/local/ssl/include\n");
#endif
    else
Пример #11
0
uint_t
la_version(uint_t version)
{
	char		*str;
	FILE		*fp;

	if (version > LAV_CURRENT)
		(void) fprintf(stderr,
				dgettext(TEXT_DOMAIN,
					"apptrace: unexpected version: %u\n"),
				version);

	build_env_list(&bindto_list, "APPTRACE_BINDTO");
	build_env_list(&bindto_excl, "APPTRACE_BINDTO_EXCLUDE");

	build_env_list(&bindfrom_list, "APPTRACE_BINDFROM");
	build_env_list(&bindfrom_excl, "APPTRACE_BINDFROM_EXCLUDE");

	if (checkenv("APPTRACE_PID") != NULL) {
		pidout = 1;
	} else {
		char *str = "LD_AUDIT=";
		char *str2 = "LD_AUDIT64=";
		/*
		 * This disables apptrace output in subsequent exec'ed
		 * processes.
		 */
		(void) putenv(str);
		(void) putenv(str2);
	}

	if ((str = checkenv("APPTRACE_OUTPUT")) != NULL) {
		int fd, newfd, targetfd, lowerlimit;
		struct rlimit rl;

		if (getrlimit(RLIMIT_NOFILE, &rl) == -1) {
			(void) fprintf(stderr,
					dgettext(TEXT_DOMAIN,
						"apptrace: getrlimit: %s\n"),
					strerror(errno));
			exit(EXIT_FAILURE);
		}

		fd = open(str, O_WRONLY|O_CREAT|O_TRUNC, 0666);
		if (fd == -1) {
			(void) fprintf(stderr,
					dgettext(TEXT_DOMAIN,
						"apptrace: %s: %s\n"),
					str,
					strerror(errno));
			exit(EXIT_FAILURE);
		}

		/*
		 * Those fans of dup2 should note that dup2 cannot
		 * be used below because dup2 closes the target file
		 * descriptor.  Thus, if we're apptracing say, ksh
		 * we'd have closed the fd it uses for the history
		 * file (63 on my box).
		 *
		 * fcntl with F_DUPFD returns first available >= arg3
		 * so we iterate from the top until we find a available
		 * fd.
		 *
		 * Not finding an fd after 10 tries is a failure.
		 *
		 * Since the _file member of the FILE structure is an
		 * unsigned char, we must clamp our fd request to
		 * UCHAR_MAX
		 */
		lowerlimit = ((rl.rlim_cur >
		    UCHAR_MAX) ? UCHAR_MAX : rl.rlim_cur) - 10;

		for (targetfd = lowerlimit + 10;
		    targetfd > lowerlimit; targetfd--) {
			if ((newfd = fcntl(fd, F_DUPFD, targetfd)) != -1)
				break;
		}

		if (newfd == -1) {
			(void) fprintf(stderr,
					dgettext(TEXT_DOMAIN,
						"apptrace: F_DUPFD: %s\n"),
					strerror(errno));
			exit(EXIT_FAILURE);
		}
		(void) close(fd);

		if (fcntl(newfd, F_SETFD, FD_CLOEXEC) == -1) {
			(void) fprintf(stderr,
					dgettext(TEXT_DOMAIN,
					"apptrace: fcntl FD_CLOEXEC: %s\n"),
					strerror(errno));
			exit(EXIT_FAILURE);
		}

		if ((fp = fdopen(newfd, "wF")) != NULL) {
			ABISTREAM = fp;
		} else {
			(void) fprintf(stderr,
					dgettext(TEXT_DOMAIN,
						"apptrace: fdopen: %s\n"),
					strerror(errno));
			exit(EXIT_FAILURE);
		}
	}

#if defined(_LP64)
	build_env_list1(&intlib_list, &intlib_listend,
	    "APPTRACE_INTERCEPTORS64");
#else
	build_env_list1(&intlib_list, &intlib_listend,
	    "APPTRACE_INTERCEPTORS");
#endif

	/* Set up lists interfaces to trace or ignore */
	env_to_intlist(&trace_list, "APPTRACE_INTERFACES");
	env_to_intlist(&trace_excl, "APPTRACE_INTERFACES_EXCLUDE");
	env_to_intlist(&verbose_list, "APPTRACE_VERBOSE");
	env_to_intlist(&verbose_excl, "APPTRACE_VERBOSE_EXCLUDE");

	return (LAV_CURRENT);
}