Example #1
0
int main(int argc, char **argv)
{
  struct rekey_session *sess;
  krb5_principal subject;
  struct ACL *acl;
  FILE *F;
  char *string_acl[3], **x;
  int rc, exact = 0;

  if (argc < 2) usage();

  switch ((*++argv)[0]) {
    case 'b':
      if (argc < 3) usage();
      exact = ((*argv)[1] == 'e');
      sess = setup_session();
      acl = acl_load_builtin(sess, "<builtin>", builtin_acl);
      break;

    case 'f':
      if (argc < 4) usage();
      exact = ((*argv)[1] == 'e');
      sess = setup_session();
      acl = acl_load(sess, *++argv);
      break;

    case 's':
      if (argc < 4) usage();
      exact = ((*argv)[1] == 'e');
      sess = setup_session();
      string_acl[0] = *++argv;
      if (**argv == '!') {
        string_acl[1] = "**@REKEY.EXAMPLE";
        string_acl[2] = 0;
      } else {
        string_acl[1] = 0;
      }
      acl = acl_load_builtin(sess, "<string>", string_acl);
      break;

    case 'o':
      if (argc < 3) usage();
      if (!(F = fopen(*++argv, "w")))
        fatal("%s: %s\n", *argv, strerror(errno));
      for (x = builtin_acl; *x; x++)
        fprintf(F, "%s\n", *x);
      fclose(F);
      exit(0);

    default: usage();
  }

  if ((rc = krb5_parse_name(sess->kctx, *++argv, &subject)))
    fatal("%s: %s\n", *argv, krb5_get_err_text(sess->kctx, rc));

  rc = acl_check(sess, acl, subject, exact);
  exit(rc ? 0 : 99);
}
int
main (int argc, char *const *argv)
{
  int errorCount = 0;;
  struct MHD_Daemon *d;
  gnutls_session_t session;
  gnutls_datum_t key;
  gnutls_datum_t cert;
  gnutls_certificate_credentials_t xcred;


  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
#ifdef GCRYCTL_INITIALIZATION_FINISHED
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
  gnutls_global_init ();
  gnutls_global_set_log_level (11);

  d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
                        MHD_USE_DEBUG, DEAMON_TEST_PORT,
                        NULL, NULL, &http_dummy_ahc, NULL,
                        MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
                        MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                        MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);

  if (d == NULL)
    {
      fprintf (stderr, MHD_E_SERVER_INIT);
      return -1;
    }

  if (0 != setup_session (&session, &key, &cert, &xcred))
    {
      fprintf (stderr, "failed to setup session\n");
      return 1;
    }
  errorCount += test_tls_session_time_out (session);
  teardown_session (session, &key, &cert, xcred);

  print_test_result (errorCount, argv[0]);

  MHD_stop_daemon (d);
  gnutls_global_deinit ();

  return errorCount != 0;
}
Example #3
0
static void
launch_compositor(struct weston_launch *wl, int argc, char *argv[])
{
	char *child_argv[MAX_ARGV_SIZE];
	sigset_t mask;
	int i;

	if (wl->verbose)
		printf("weston-launch: spawned weston with pid: %d\n", getpid());
	if (wl->new_user)
		setup_session(wl);

	if (getuid() != geteuid() || getgid() != getegid())
		drop_privileges(wl);

	if (wl->tty != STDIN_FILENO)
		setenv_fd("WESTON_TTY_FD", wl->tty);

	setenv_fd("WESTON_LAUNCHER_SOCK", wl->sock[1]);

	unsetenv("DISPLAY");

	/* Do not give our signal mask to the new process. */
	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGCHLD);
	sigaddset(&mask, SIGINT);
	sigprocmask(SIG_UNBLOCK, &mask, NULL);

	child_argv[0] = wl->pw->pw_shell;
	child_argv[1] = "-l";
	child_argv[2] = "-c";
	child_argv[3] = BINDIR "/weston \"$@\"";
	child_argv[4] = "weston";
	for (i = 0; i < argc; ++i)
		child_argv[5 + i] = argv[i];
	child_argv[5 + i] = NULL;

	execv(child_argv[0], child_argv);
	error(1, errno, "exec failed");
}
Example #4
0
int
main (int argc, char *const *argv)
{
  int errorCount = 0;;
  struct MHD_Daemon *d;
  MHD_gtls_session_t session;
  MHD_gnutls_datum_t key;
  MHD_gnutls_datum_t cert;
  MHD_gtls_cert_credentials_t xcred;

  MHD__gnutls_global_init ();
  MHD_gtls_global_set_log_level (11);

  d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
                        MHD_USE_DEBUG, DEAMON_TEST_PORT,
                        NULL, NULL, &rehandshake_ahc, NULL,
                        MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                        MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);

  if (d == NULL)
    {
      fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
      return -1;
    }

  setup_session (&session, &key, &cert, &xcred);
  errorCount += test_out_of_context_cipher_change (session);
  teardown_session (session, &key, &cert, xcred);

  print_test_result (errorCount, argv[0]);

  MHD_stop_daemon (d);
  MHD__gnutls_global_deinit ();

  return errorCount != 0;
}
int
main (int argc, char *const *argv)
{
  int i, errorCount = 0;
  FILE *test_fd;
  struct MHD_Daemon *d;
  gnutls_session_t session;
  gnutls_datum_t key;
  gnutls_datum_t cert;
  gnutls_certificate_credentials_t xcred;

  const int ext_arr[] = {
    GNUTLS_EXTENSION_SERVER_NAME,
    -1
  };

  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
#ifdef GCRYCTL_INITIALIZATION_FINISHED
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
  MHD_gtls_global_set_log_level (11);

  if ((test_fd = setup_test_file ()) == NULL)
    {
      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
      return -1;
    }

  if (0 != curl_global_init (CURL_GLOBAL_ALL))
    {
      fprintf (stderr, "Error: %s\n", strerror (errno));
      return -1;
    }

  d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
                        MHD_USE_DEBUG, DEAMON_TEST_PORT,
                        NULL, NULL, &http_ahc, NULL,
                        MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                        MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);

  if (d == NULL)
    {
      fprintf (stderr, "%s\n", MHD_E_SERVER_INIT);
      return -1;
    }

  i = 0;
  setup_session (&session, &key, &cert, &xcred);
  errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
  teardown_session (session, &key, &cert, xcred);
#if 1
  i = 0;
  while (ext_arr[i] != -1)
    {
      setup_session (&session, &key, &cert, &xcred);
      errorCount += test_hello_extension (session, ext_arr[i], 1, 16);
      teardown_session (session, &key, &cert, xcred);

      setup_session (&session, &key, &cert, &xcred);
      errorCount += test_hello_extension (session, ext_arr[i], 3, 8);
      teardown_session (session, &key, &cert, xcred);

      /* this test specifically tests the issue raised in CVE-2008-1948 */
      setup_session (&session, &key, &cert, &xcred);
      errorCount += test_hello_extension (session, ext_arr[i], 6, 0);
      teardown_session (session, &key, &cert, xcred);
      i++;
    }
#endif

  print_test_result (errorCount, argv[0]);

  MHD_stop_daemon (d);

  curl_global_cleanup ();
  fclose (test_fd);

  return errorCount;
}
Example #6
0
isc_result_t
pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype,
		 isc_boolean_t need_services, isc_boolean_t rw,
		 isc_boolean_t logon, const char *pin, CK_SLOT_ID slot)
{
	pk11_token_t *token = NULL;
	pk11_sessionlist_t *freelist;
	pk11_session_t *sp;
	isc_result_t ret;
#ifdef PKCS11CRYPTO
	isc_result_t service_ret = ISC_R_SUCCESS;
#else
	UNUSED(need_services);
#endif

	memset(ctx, 0, sizeof(pk11_context_t));
	ctx->handle = NULL;
	ctx->session = CK_INVALID_HANDLE;

	ret = pk11_initialize(NULL, NULL);
#ifdef PKCS11CRYPTO
	if (ret == PK11_R_NORANDOMSERVICE ||
	    ret == PK11_R_NODIGESTSERVICE ||
	    ret == PK11_R_NOAESSERVICE) {
		if (need_services)
			return (ret);
		service_ret = ret;
	}
	else
#endif /* PKCS11CRYPTO */
	if (ret != ISC_R_SUCCESS)
		return (ret);

	LOCK(&sessionlock);
	/* wait for initialization to finish */
	UNLOCK(&sessionlock);

	switch(optype) {
#ifdef PKCS11CRYPTO
	case OP_RAND:
		token = rand_token;
		break;
	case OP_DIGEST:
		token = digest_token;
		break;
	case OP_AES:
		token = aes_token;
		break;
	case OP_ANY:
		for (token = ISC_LIST_HEAD(tokens);
		     token != NULL;
		     token = ISC_LIST_NEXT(token, link))
			if (token->slotid == slot)
				break;
		break;
#endif
	default:
		for (token = ISC_LIST_HEAD(tokens);
		     token != NULL;
		     token = ISC_LIST_NEXT(token, link))
			if (token->slotid == slot)
				break;
#ifdef PKCS11CRYPTO
		if ((token == NULL) ||
		    ((token->operations & (1 << optype)) == 0))
			return (ISC_R_NOTFOUND);
#endif
		break;
	}
	if (token == NULL)
		return (ISC_R_NOTFOUND);

	/* Override the token's PIN */
	if (logon && pin != NULL && *pin != '\0') {
		if (strlen(pin) > PINLEN)
			return ISC_R_RANGE;
		memset(token->pin, 0, PINLEN + 1);
		strncpy(token->pin, pin, PINLEN);
	}

	freelist = &token->sessions;

	LOCK(&sessionlock);
	sp = ISC_LIST_HEAD(*freelist);
	if (sp != NULL) {
		ISC_LIST_UNLINK(*freelist, sp, link);
		ISC_LIST_APPEND(actives, sp, link);
		UNLOCK(&sessionlock);
		if (logon)
			ret = token_login(sp);
		ctx->handle = sp;
		ctx->session = sp->session;
		return (ret);
	}
	UNLOCK(&sessionlock);

	sp = pk11_mem_get(sizeof(*sp));
	if (sp == NULL)
		return (ISC_R_NOMEMORY);
	sp->magic = SES_MAGIC;
	sp->token = token;
	sp->session = CK_INVALID_HANDLE;
	ISC_LINK_INIT(sp, link);
	ret = setup_session(sp, token, rw);
	if ((ret == ISC_R_SUCCESS) && logon)
		ret = token_login(sp);
	LOCK(&sessionlock);
	ISC_LIST_APPEND(actives, sp, link);
	UNLOCK(&sessionlock);
	ctx->handle = sp;
	ctx->session = sp->session;
#ifdef PKCS11CRYPTO
	if (ret == ISC_R_SUCCESS)
		ret = service_ret;
#endif
	return (ret);
}
int
main (int argc, char *const *argv)
{
  int errorCount = 0;;
  struct MHD_Daemon *d;
  gnutls_session_t session;
  gnutls_datum_t key;
  gnutls_datum_t cert;
  gnutls_certificate_credentials_t xcred;
  int port;
  (void)argc;   /* Unused. Silent compiler warning. */

  if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    port = 0;
  else
    port = 3070;

#ifdef MHD_HTTPS_REQUIRE_GRYPT
  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
#ifdef GCRYCTL_INITIALIZATION_FINISHED
  gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
#endif /* MHD_HTTPS_REQUIRE_GRYPT */
  gnutls_global_init ();
  gnutls_global_set_log_level (11);

  d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS |
                        MHD_USE_ERROR_LOG, port,
                        NULL, NULL, &http_dummy_ahc, NULL,
                        MHD_OPTION_CONNECTION_TIMEOUT, TIME_OUT,
                        MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                        MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                        MHD_OPTION_END);

  if (NULL == d)
    {
      fprintf (stderr, MHD_E_SERVER_INIT);
      return -1;
    }
  if (0 == port)
    {
      const union MHD_DaemonInfo *dinfo;
      dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
      if (NULL == dinfo || 0 == dinfo->port)
        { MHD_stop_daemon (d); return -1; }
      port = (int)dinfo->port;
    }

  if (0 != setup_session (&session, &key, &cert, &xcred))
    {
      fprintf (stderr, "failed to setup session\n");
      return 1;
    }
  errorCount += test_tls_session_time_out (session, port);
  teardown_session (session, &key, &cert, xcred);

  print_test_result (errorCount, argv[0]);

  MHD_stop_daemon (d);
  gnutls_global_deinit ();

  return errorCount != 0 ? 1 : 0;
}
int main(int argc, char **argv)
{
	int ret;
	char tmppath[] = "/tmp/lttng-rotate-XXXXXX";
	char *session_name, *path, *ext_program;
	int delay, nr;

	if (argc != 5) {
		usage(argv[0]);
		ret = -1;
		goto end;
	}

	session_name = argv[1];
	delay = atoi(argv[2]);
	nr = atoi(argv[3]);
	ext_program = argv[4];

	if (delay < 0) {
		fprintf(stderr, "delay-sec must be a positive values\n");
		ret = -1;
		goto end;
	}

	if  (signal(SIGINT, sighandler) == SIG_ERR) {
		perror("signal handler");
		goto end;
	}

	path = mkdtemp(tmppath);
	if (!path) {
		fprintf(stderr, "Failed to create temporary path\n");
	}

	printf("Output directory: %s\n", path);

	ret = setup_session(session_name, path);
	if (ret) {
		goto end_cleanup_dir;
	}

	if (nr > 0) {
		unsigned int sleep_time;
		int i;

		for (i = 0; i < nr; i++) {
			ret = rotate_session(session_name, ext_program);
			if (ret) {
				goto end_cleanup;
			}
			sleep_time = delay;
			while (sleep_time > 0) {
				sleep_time = sleep(sleep_time);
			}
		}
	} else {
		for(;;) {
			if (quit) {
				break;
			}
			ret = rotate_session(session_name, ext_program);
			if (ret) {
				goto end_cleanup;
			}
			sleep(delay);
		}
	}

end_cleanup:
	ret = cleanup_session(session_name);
	if (ret) {
		goto end;
	}
end_cleanup_dir:
	ret = cleanup_dir(path);
end:
	return ret;
}
Example #9
0
int main(int argc, char* argv[]){

     struct qz_config* conf = init_config();

     tagger_pid = tagger_init(conf, argv);
     printf( "tagger_pid = %d\n", tagger_pid);
     signal( SIGTERM, cleanup );

     int j;
     xmlHashTablePtr ht = xmlHashCreate(NBRTESTS);
     struct handler_args hargs[NBRTESTS];
     struct session* s;

     const char* kw[] = { "host", "dbname", "user", "password", 
         "application_name", NULL };
     const char* vals[] = { "localhost", "info", "qz", "42", "qztest", NULL };

     const char* parts[] = { "qz", "one", "two", "three",  NULL };

     for(j=0; j<NBRTESTS; j++){
         fprintf(stderr, "setup_session %d\n", j);
         hargs[j].log = fopen("testsession.log", "w");
         hargs[j].conf = conf;
         hargs[j].uri_parts = parts;

         setup_session(&(hargs[j]), ht, conf);     
         hargs[j].uri_parts = NULL;
     }
     
     s = session_from_hargs(&hargs[NBRTESTS-1], ht, conf);
     s->is_logged_in = true;
     s->logged_in_time = time(NULL);

     s = session_from_hargs(&hargs[NBRTESTS-2], ht, conf);
     s->is_logged_in = true;
     s->logged_in_time = time(NULL);
     s->conn = PQconnectdbParams(kw, vals, 0);

     s = session_from_hargs(&hargs[NBRTESTS-3], ht, conf);
     s->is_logged_in = false;
     s->logged_in_time = time(NULL);
     s->conn = PQconnectdbParams(kw, vals, 0);

     for(j=0; j<NBRTESTS; j++){
         s = session_from_hargs(&hargs[j], ht, conf);
         printf("session_state[%d]:     %s\n", j,
             state_text( get_session_state(&(hargs[j])) ));
         //fclose( hargs[j].log );
     }
     printf("sleeping\n");
     sleep(5);
     printf("fin\n");

     for(j=0; j<100; j++){
         if (s->conn != NULL){
             PQfinish(s->conn);
             s->conn = NULL;
         }
     }
     kill( tagger_pid, 15);
     int status;
     waitpid(tagger_pid, &status, 0);
     fprintf(stderr, "killed tagger pid %d waitpid status = %d\n", 
         tagger_pid, status);

     return 0;
}