Exemplo n.º 1
0
void SigHandler (int sig)
{
	int ThreadGroupId;

	switch (sig)
	{
		case SIGTERM:
			
			// tell the NLM its exiting, and save the console threadid, recovering the main threadid
			NlmExiting = TRUE;
			ThreadGroupId = SetThreadGroupID (MainThreadGroupId);

			// if the NLM is waiting on the user, stuff an enter keypress into the keyboard buffer
			if (AwaitingInput)
				ungetch (KEY_ENTER);

			// allow the NLM to finish cleanly			
			while (ThreadCount != 0)
				ThreadSwitchWithDelay ();

			// restore the console threadid
			SetThreadGroupID (ThreadGroupId);
		break;
	}

	return;
}
Exemplo n.º 2
0
   /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed
   */
int RAND_poll(void)
{
   unsigned long l;
   unsigned long tsc;
   int i; 

      /* There are several options to gather miscellaneous data
       * but for now we will loop checking the time stamp counter (rdtsc) and
       * the SuperHighResolutionTimer.  Each iteration will collect 8 bytes
       * of data but it is treated as only 1 byte of entropy.  The call to
       * ThreadSwitchWithDelay() will introduce additional variability into
       * the data returned by rdtsc.
       *
       * Applications can agument the seed material by adding additional
       * stuff with RAND_add() and should probably do so.
      */
   l = GetProcessSwitchCount();
   RAND_add(&l,sizeof(l),1);
   
   /* need to cast the void* to unsigned long here */
   l = (unsigned long)RunningProcess;
   RAND_add(&l,sizeof(l),1);

   for( i=2; i<ENTROPY_NEEDED; i++)
   {
#ifdef __MWERKS__
      asm 
      {
         rdtsc
         mov tsc, eax        
      }
#else
      asm volatile("rdtsc":"=A" (tsc));
#endif

      RAND_add(&tsc, sizeof(tsc), 1);

      l = GetSuperHighResolutionTimer();
      RAND_add(&l, sizeof(l), 0);

# if defined(NETWARE_LIBC)
      NXThreadYield();
# else /* NETWARE_CLIB */
      ThreadSwitchWithDelay();
# endif
   }

   return 1;
}
Exemplo n.º 3
0
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
{
    SSL_CTX *ssl_ctx[2];
    int i;
    ssl_ctx[0] = s_ctx;
    ssl_ctx[1] = c_ctx;

    for (i = 0; i < thread_number; i++) {
        BeginThread((void (*)(void *))ndoit, NULL, THREAD_STACK_SIZE,
                    (void *)ssl_ctx);
        ThreadSwitchWithDelay();
    }

    printf("reaping\n");

    /* loop until all threads have signaled the semaphore */
    for (i = 0; i < thread_number; i++) {
        MPKSemaphoreWait(ThreadSem);
    }
    printf("netware threads done (%d,%d)\n",
           s_ctx->references, c_ctx->references);
}
Exemplo n.º 4
0
void NLM_SignalHandler(int sig)
#pragma on(unreferenced);
{
	int handlerThreadGroupID;

	switch(sig)
	{
	case SIGTERM:
		NLM_exiting = TRUE;
		handlerThreadGroupID = GetThreadGroupID();
		SetThreadGroupID(NLM_mainThreadGroupID);

		/* NLM SDK functions may be called here */

		while (NLM_threadCnt != 0) 
			ThreadSwitchWithDelay();
		SetThreadGroupID(handlerThreadGroupID);
		break;
	case SIGINT:
		signal(SIGINT, NLM_SignalHandler);
		break;
	}
	return;
}
Exemplo n.º 5
0
int doit(char *ctx[4])
{
    SSL_CTX *s_ctx, *c_ctx;
    static char cbuf[200], sbuf[200];
    SSL *c_ssl = NULL;
    SSL *s_ssl = NULL;
    BIO *c_to_s = NULL;
    BIO *s_to_c = NULL;
    BIO *c_bio = NULL;
    BIO *s_bio = NULL;
    int c_r, c_w, s_r, s_w;
    int c_want, s_want;
    int i;
    int done = 0;
    int c_write, s_write;
    int do_server = 0, do_client = 0;

    s_ctx = (SSL_CTX *)ctx[0];
    c_ctx = (SSL_CTX *)ctx[1];

    if (ctx[2] != NULL)
        s_ssl = (SSL *)ctx[2];
    else
        s_ssl = SSL_new(s_ctx);

    if (ctx[3] != NULL)
        c_ssl = (SSL *)ctx[3];
    else
        c_ssl = SSL_new(c_ctx);

    if ((s_ssl == NULL) || (c_ssl == NULL))
        goto err;

    c_to_s = BIO_new(BIO_s_mem());
    s_to_c = BIO_new(BIO_s_mem());
    if ((s_to_c == NULL) || (c_to_s == NULL))
        goto err;

    c_bio = BIO_new(BIO_f_ssl());
    s_bio = BIO_new(BIO_f_ssl());
    if ((c_bio == NULL) || (s_bio == NULL))
        goto err;

    SSL_set_connect_state(c_ssl);
    SSL_set_bio(c_ssl, s_to_c, c_to_s);
    BIO_set_ssl(c_bio, c_ssl, (ctx[2] == NULL) ? BIO_CLOSE : BIO_NOCLOSE);

    SSL_set_accept_state(s_ssl);
    SSL_set_bio(s_ssl, c_to_s, s_to_c);
    BIO_set_ssl(s_bio, s_ssl, (ctx[3] == NULL) ? BIO_CLOSE : BIO_NOCLOSE);

    c_r = 0;
    s_r = 1;
    c_w = 1;
    s_w = 0;
    c_want = W_WRITE;
    s_want = 0;
    c_write = 1, s_write = 0;

    /* We can always do writes */
    for (;;) {
        do_server = 0;
        do_client = 0;

        i = (int)BIO_pending(s_bio);
        if ((i && s_r) || s_w)
            do_server = 1;

        i = (int)BIO_pending(c_bio);
        if ((i && c_r) || c_w)
            do_client = 1;

        if (do_server && verbose) {
            if (SSL_in_init(s_ssl))
                printf("server waiting in SSL_accept - %s\n",
                       SSL_state_string_long(s_ssl));
            else if (s_write)
                printf("server:SSL_write()\n");
            else
                printf("server:SSL_read()\n");
        }

        if (do_client && verbose) {
            if (SSL_in_init(c_ssl))
                printf("client waiting in SSL_connect - %s\n",
                       SSL_state_string_long(c_ssl));
            else if (c_write)
                printf("client:SSL_write()\n");
            else
                printf("client:SSL_read()\n");
        }

        if (!do_client && !do_server) {
            fprintf(stdout, "ERROR IN STARTUP\n");
            break;
        }
        if (do_client && !(done & C_DONE)) {
            if (c_write) {
                i = BIO_write(c_bio, "hello from client\n", 18);
                if (i < 0) {
                    c_r = 0;
                    c_w = 0;
                    if (BIO_should_retry(c_bio)) {
                        if (BIO_should_read(c_bio))
                            c_r = 1;
                        if (BIO_should_write(c_bio))
                            c_w = 1;
                    } else {
                        fprintf(stderr, "ERROR in CLIENT\n");
                        ERR_print_errors_fp(stderr);
                        return (1);
                    }
                } else if (i == 0) {
                    fprintf(stderr, "SSL CLIENT STARTUP FAILED\n");
                    return (1);
                } else {
                    /* ok */
                    c_write = 0;
                }
            } else {
                i = BIO_read(c_bio, cbuf, 100);
                if (i < 0) {
                    c_r = 0;
                    c_w = 0;
                    if (BIO_should_retry(c_bio)) {
                        if (BIO_should_read(c_bio))
                            c_r = 1;
                        if (BIO_should_write(c_bio))
                            c_w = 1;
                    } else {
                        fprintf(stderr, "ERROR in CLIENT\n");
                        ERR_print_errors_fp(stderr);
                        return (1);
                    }
                } else if (i == 0) {
                    fprintf(stderr, "SSL CLIENT STARTUP FAILED\n");
                    return (1);
                } else {
                    done |= C_DONE;
#ifdef undef
                    fprintf(stdout, "CLIENT:from server:");
                    fwrite(cbuf, 1, i, stdout);
                    fflush(stdout);
#endif
                }
            }
        }

        if (do_server && !(done & S_DONE)) {
            if (!s_write) {
                i = BIO_read(s_bio, sbuf, 100);
                if (i < 0) {
                    s_r = 0;
                    s_w = 0;
                    if (BIO_should_retry(s_bio)) {
                        if (BIO_should_read(s_bio))
                            s_r = 1;
                        if (BIO_should_write(s_bio))
                            s_w = 1;
                    } else {
                        fprintf(stderr, "ERROR in SERVER\n");
                        ERR_print_errors_fp(stderr);
                        return (1);
                    }
                } else if (i == 0) {
                    fprintf(stderr, "SSL SERVER STARTUP FAILED\n");
                    return (1);
                } else {
                    s_write = 1;
                    s_w = 1;
#ifdef undef
                    fprintf(stdout, "SERVER:from client:");
                    fwrite(sbuf, 1, i, stdout);
                    fflush(stdout);
#endif
                }
            } else {
                i = BIO_write(s_bio, "hello from server\n", 18);
                if (i < 0) {
                    s_r = 0;
                    s_w = 0;
                    if (BIO_should_retry(s_bio)) {
                        if (BIO_should_read(s_bio))
                            s_r = 1;
                        if (BIO_should_write(s_bio))
                            s_w = 1;
                    } else {
                        fprintf(stderr, "ERROR in SERVER\n");
                        ERR_print_errors_fp(stderr);
                        return (1);
                    }
                } else if (i == 0) {
                    fprintf(stderr, "SSL SERVER STARTUP FAILED\n");
                    return (1);
                } else {
                    s_write = 0;
                    s_r = 1;
                    done |= S_DONE;
                }
            }
        }

        if ((done & S_DONE) && (done & C_DONE))
            break;
#if defined(OPENSSL_SYS_NETWARE)
        ThreadSwitchWithDelay();
#endif
    }

    SSL_set_shutdown(c_ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
    SSL_set_shutdown(s_ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);

#ifdef undef
    fprintf(stdout, "DONE\n");
#endif
 err:
    /*
     * We have to set the BIO's to NULL otherwise they will be free()ed
     * twice.  Once when th s_ssl is SSL_free()ed and again when c_ssl is
     * SSL_free()ed. This is a hack required because s_ssl and c_ssl are
     * sharing the same BIO structure and SSL_set_bio() and SSL_free()
     * automatically BIO_free non NULL entries. You should not normally do
     * this or be required to do this
     */

    if (s_ssl != NULL) {
        s_ssl->rbio = NULL;
        s_ssl->wbio = NULL;
    }
    if (c_ssl != NULL) {
        c_ssl->rbio = NULL;
        c_ssl->wbio = NULL;
    }

    /* The SSL's are optionally freed in the following calls */
    if (c_to_s != NULL)
        BIO_free(c_to_s);
    if (s_to_c != NULL)
        BIO_free(s_to_c);

    if (c_bio != NULL)
        BIO_free(c_bio);
    if (s_bio != NULL)
        BIO_free(s_bio);
    return (0);
}