コード例 #1
0
ファイル: smb_spnego.c プロジェクト: SourceBackups/libdsm
static void     asn1_display_error(const char *where, int errcode)
{
    // Avoids warning when not in debug mode
    (void)where;
    (void)errcode;

    BDSM_dbg("%s error: %s\n", where, asn1_strerror(errcode));
}
コード例 #2
0
ファイル: Test_errors.c プロジェクト: Chronic-Dev/libtasn1
int
main (int argc, char *argv[])
{
  asn1_retCode ec = 0;
  const char *errstr;

  do
    {
      errstr = asn1_strerror (ec);
      asn1_perror (ec);
#ifndef ASN1_DISABLE_DEPRECATED
      errstr = libtasn1_strerror (ec);
      libtasn1_perror (ec);
#endif
      ec++;
    }
  while (errstr);

  return 0;
}
コード例 #3
0
ファイル: Test_errors.c プロジェクト: FANTOM007/libtasn1
int
main (int argc, char *argv[])
{
  int ec = 0;
  const char *errstr;
  int verbose = 0;

  if (argc > 1)
    verbose = 1;

  do
    {
      errstr = asn1_strerror (ec);
      if (verbose != 0)
	asn1_perror (ec);
      ec++;
    }
  while (errstr);

  return 0;
}
コード例 #4
0
ファイル: worker-kkdcp.c プロジェクト: fqtools/ocserv
int post_kkdcp_handler(worker_st *ws, unsigned http_ver)
{
	int ret, e, fd = -1;
	struct http_req_st *req = &ws->req;
	unsigned i, length;
	kkdcp_st *kkdcp = NULL;
	uint8_t *buf;
	uint32_t mlength;
	char realm[128] = "";
	const char *reason = "Unknown";
	kkdcp_realm_st *kr;

	oclog(ws, LOG_INFO, "Processing KKDCP request");

	for (i=0;i<ws->config->kkdcp_size;i++) {
		if (ws->config->kkdcp[i].url && strcmp(ws->config->kkdcp[i].url, req->url) == 0) {
			kkdcp = &ws->config->kkdcp[i];
			break;
		}
	}

	if (kkdcp == NULL) {
		oclog(ws, LOG_HTTP_DEBUG, "could not figure kkdcp handler for %s", req->url);
		return -1;
	}

	if (req->body_length == 0) {
		oclog(ws, LOG_HTTP_DEBUG, "empty body length for kkdcp handler %s", req->url);
		return -1;
	}

	ws_add_score_to_ip(ws, ws->config->ban_points_kkdcp, 0);
	oclog(ws, LOG_HTTP_DEBUG, "HTTP processing kkdcp framed request: %u bytes", (unsigned)req->body_length);

	length = BUF_SIZE;
	buf = talloc_size(ws, length);
	if (buf == NULL) {
		oclog(ws, LOG_ERR, "kkdcp: memory error");
		reason = "memory error";
		return -1;
	}

	ret = der_decode((uint8_t*)req->body, req->body_length, buf, &length, realm, sizeof(realm), &e);
	if (ret < 0) {
		oclog(ws, LOG_ERR, "kkdcp: DER decoding error: %s", asn1_strerror(e));
		reason = "DER decoding error";
		goto fail;
	}

	kr = &kkdcp->realms[0];
	if (realm[0] != 0 && kkdcp->realms_size > 1) {
		oclog(ws, LOG_DEBUG, "kkdcp: client asked for '%s'", realm);

		for (i=0;i<kkdcp->realms_size;i++) {
			if (strcmp(kkdcp->realms[i].realm, realm) == 0) {
				kr = &kkdcp->realms[i];
				break;
			}
		}
	}

	fd = socket(kr->ai_family, kr->ai_socktype, kr->ai_protocol);
	if (fd == -1) {
		e = errno;
		oclog(ws, LOG_ERR, "kkdcp: socket error: %s", strerror(e));
		reason = "socket error";
		goto fail;
	}

	ret = connect(fd, (struct sockaddr*)&kr->addr, kr->addr_len);
	if (ret == -1) {
		e = errno;
		oclog(ws, LOG_ERR, "kkdcp: connect error: %s", strerror(e));
		reason = "connect error";
		goto fail;
	}

	oclog(ws, LOG_HTTP_DEBUG, "HTTP sending kkdcp request: %u bytes", (unsigned)length);
	ret = send(fd, buf, length, 0);
	if (ret != length) {
		if (ret == -1) {
			e = errno;
			oclog(ws, LOG_ERR, "kkdcp: send error: %s", strerror(e));
		} else {
			oclog(ws, LOG_ERR, "kkdcp: send error: only %d were sent", ret);
		}
		reason = "send error";
		goto fail;
	}

	if (kr->ai_socktype == SOCK_DGRAM) {
		ret = recv(fd, buf, BUF_SIZE, 0);
		if (ret == -1) {
			e = errno;
			oclog(ws, LOG_ERR, "kkdcp: recv error: %s", strerror(e));
			reason = "recv error";
			goto fail;
		}

		length = ret;
	} else {
		ret = recv(fd, buf, 4, 0);
		if (ret < 4) {
			e = errno;
			oclog(ws, LOG_ERR, "kkdcp: recv error: %s", strerror(e));
			reason = "Recv error";
			ret = -1;
			goto fail;
		}

		memcpy(&mlength, buf, 4);
		mlength = ntohl(mlength);
		if (mlength >= BUF_SIZE-4) {
			oclog(ws, LOG_ERR, "kkdcp: too long message (%d bytes)", (int)mlength);
			reason = "recv error";
			ret = -1;
			goto fail;
		}

		ret = force_read_timeout(fd, buf+4, mlength, 5);
		if (ret == -1) {
			e = errno;
			oclog(ws, LOG_ERR, "kkdcp: recv error: %s", strerror(e));
			reason = "recv error";
			goto fail;
		}
		length = ret + 4;
	}

	oclog(ws, LOG_HTTP_DEBUG, "HTTP processing kkdcp reply: %u bytes", (unsigned)length);

	cstp_cork(ws);
	ret = cstp_printf(ws, "HTTP/1.%u 200 OK\r\n", http_ver);
	if (ret < 0) {
		goto fail;
	}

	ret =
	    cstp_puts(ws, "Content-Type: application/kerberos\r\n");
	if (ret < 0) {
		goto fail;
	}

	ret = der_encode_inplace(buf, &length, BUF_SIZE, &e);
	if (ret < 0) {
		oclog(ws, LOG_ERR, "kkdcp: DER encoding error: %s", asn1_strerror(e));
		reason = "DER encoding error";
		goto fail;
	}

	oclog(ws, LOG_HTTP_DEBUG, "HTTP sending kkdcp framed reply: %u bytes", (unsigned)length);
	ret =
	    cstp_printf(ws, "Content-Length: %u\r\n",
		       (unsigned int)length);
	if (ret < 0) {
		goto fail;
	}

	ret = cstp_puts(ws, "Connection: Keep-Alive\r\n");
	if (ret < 0) {
		goto fail;
	}

	ret = cstp_puts(ws, "\r\n");
	if (ret < 0) {
		goto fail;
	}

	ret = cstp_send(ws, buf, length);
	if (ret < 0) {
		goto fail;
	}

	ret = cstp_uncork(ws);
	if (ret < 0) {
		goto fail;
	}

	ret = 0;
	goto cleanup;
 fail:
	cstp_printf(ws,
		   "HTTP/1.%u 502 Bad Gateway\r\nX-Reason: %s\r\n\r\n",
		   http_ver, reason);
	ret = -1;

 cleanup:
 	talloc_free(buf);
 	if (fd != -1)
	 	close(fd);
 	return ret;
}
コード例 #5
0
ファイル: asn1Coding.c プロジェクト: Distrotech/libtasn1
int
main (int argc, char *argv[])
{
  static const struct option long_options[] = {
    {"help", no_argument, 0, 'h'},
    {"version", no_argument, 0, 'v'},
    {"check", no_argument, 0, 'c'},
    {"output", required_argument, 0, 'o'},
    {0, 0, 0, 0}
  };
  int option_index = 0;
  int option_result;
  char *outputFileName = NULL;
  char *inputFileAsnName = NULL;
  char *inputFileAssignmentName = NULL;
  int checkSyntaxOnly = 0;
  asn1_node definitions = NULL;
  asn1_node structure = NULL;
  char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
  int asn1_result = ASN1_SUCCESS;
  FILE *outputFile;
  FILE *inputFile;
  char varName[1024];
  char value[1024];
  unsigned char *der = NULL;
  int der_len;
  int k;
  int last_ra;

  set_program_name (argv[0]);

  opterr = 0;			/* disable error messages from getopt */

  while (1)
    {

      option_result =
	getopt_long (argc, argv, "hvco:", long_options, &option_index);

      if (option_result == -1)
	break;

      switch (option_result)
	{
	case 'h':		/* HELP */
	  free (outputFileName);
	  usage (EXIT_SUCCESS);
	  break;
	case 'v':		/* VERSION */
	  version_etc (stdout, program_name, PACKAGE, VERSION,
		       "Fabio Fiorina", NULL);
	  free (outputFileName);
	  exit (0);
	  break;
	case 'c':		/* CHECK SYNTAX */
	  checkSyntaxOnly = 1;
	  break;
	case 'o':		/* OUTPUT */
	  outputFileName = (char *) malloc (strlen (optarg) + 1);
	  strcpy (outputFileName, optarg);
	  break;
	case '?':		/* UNKNOW OPTION */
	  free (outputFileName);
	  fprintf (stderr,
		   "asn1Coding: option '%s' not recognized or without argument.\n\n",
		   argv[optind - 1]);
	  usage (EXIT_FAILURE);
	  break;
	default:
	  fprintf (stderr,
		   "asn1Coding: ?? getopt returned character code Ox%x ??\n",
		   option_result);
	}
    }

  if (optind == argc || optind == argc - 1)
    {
      free (outputFileName);
      fputs ("asn1Coding: input files missing\n", stderr);
      usage (EXIT_FAILURE);
    }

  inputFileAsnName = (char *) malloc (strlen (argv[optind]) + 1);
  strcpy (inputFileAsnName, argv[optind]);

  inputFileAssignmentName = (char *) malloc (strlen (argv[optind + 1]) + 1);
  strcpy (inputFileAssignmentName, argv[optind + 1]);

  asn1_result =
    asn1_parser2tree (inputFileAsnName, &definitions, errorDescription);

  switch (asn1_result)
    {
    case ASN1_SUCCESS:
      fputs ("Parse: done.\n", stderr);
      break;
    case ASN1_FILE_NOT_FOUND:
      fprintf (stderr, "asn1Coding: FILE %s NOT FOUND\n", inputFileAsnName);
      break;
    case ASN1_SYNTAX_ERROR:
    case ASN1_IDENTIFIER_NOT_FOUND:
    case ASN1_NAME_TOO_LONG:
      fprintf (stderr, "asn1Coding: %s\n", errorDescription);
      break;
    default:
      fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (asn1_result));
    }

  if (asn1_result != ASN1_SUCCESS)
    {
      free (inputFileAsnName);
      free (inputFileAssignmentName);
      exit (1);
    }


  inputFile = fopen (inputFileAssignmentName, "r");

  if (inputFile == NULL)
    {
      fprintf (stderr, "asn1Coding: file '%s' not found\n",
	       inputFileAssignmentName);
      free (inputFileAsnName);
      free (inputFileAssignmentName);
      exit (1);
    }


  putc ('\n', stderr);

  while ((last_ra = readAssignment (inputFile, varName, value))
	 == ASSIGNMENT_SUCCESS)
    {
      fprintf (stderr, "var=%s, value=%s\n", varName, value);
      if (structure == NULL)
	{
	  asn1_result = asn1_create_element (definitions, value, &structure);
	}
      else
        {
	  if (strcmp(value, "(NULL)") == 0)
	    asn1_result = asn1_write_value (structure, varName, NULL, 0);
	  else
	    asn1_result = asn1_write_value (structure, varName, value, 0);
	}

      if (asn1_result != ASN1_SUCCESS)
	{
	  fprintf (stderr, "libtasn1 ERROR: %s\n",
		   asn1_strerror (asn1_result));

	  asn1_delete_structure (&definitions);
	  asn1_delete_structure (&structure);

	  free (inputFileAsnName);
	  free (inputFileAssignmentName);

	  fclose (inputFile);
	  exit (1);
	}
    }
  if (last_ra != ASSIGNMENT_EOF)
    {
      fprintf (stderr, "asn1Coding: error reading assignment file\n");
      exit (1);
    }
  fclose (inputFile);

  putc ('\n', stderr);
  asn1_print_structure (stderr, structure, "", ASN1_PRINT_NAME_TYPE_VALUE);

  der_len = 0;
  asn1_result = asn1_der_coding (structure, "", der, &der_len,
				 errorDescription);
  if (asn1_result == ASN1_MEM_ERROR)
    {
      der = malloc (der_len);
      asn1_result = asn1_der_coding (structure, "", der, &der_len,
				     errorDescription);
    }
  fprintf (stderr, "\nCoding: %s\n\n", asn1_strerror (asn1_result));
  if (asn1_result != ASN1_SUCCESS)
    {
      fprintf (stderr, "asn1Coding: %s\n", errorDescription);

      free (der);

      asn1_delete_structure (&definitions);
      asn1_delete_structure (&structure);

      free (inputFileAsnName);
      free (inputFileAssignmentName);

      exit (1);
    }

  /* Print the 'Certificate1' DER encoding */
  fprintf (stderr, "-----------------\nNumber of bytes=%i\n", der_len);
  for (k = 0; k < der_len; k++)
    fprintf (stderr, "%02x ", der[k]);
  fputs ("\n-----------------\n", stderr);

  asn1_delete_structure (&definitions);
  asn1_delete_structure (&structure);

  if (!checkSyntaxOnly)
    {
      if (outputFileName == NULL)
	createFileName (inputFileAssignmentName, &outputFileName);

      fprintf (stderr, "\nOutputFile=%s\n", outputFileName);

      outputFile = fopen (outputFileName, "w");

      if (outputFile == NULL)
	{
	  fprintf (stderr,
		   "asn1Coding: output file '%s' not available\n",
		   outputFileName);
	  free (der);
	  free (inputFileAsnName);
	  free (inputFileAssignmentName);
	  free (outputFileName);
	  exit (1);
	}

      for (k = 0; k < der_len; k++)
	fprintf (outputFile, "%c", der[k]);
      fclose (outputFile);
      fputs ("\nWriting: done.\n", stderr);
    }

  free (der);

  free (inputFileAsnName);
  free (inputFileAssignmentName);
  free (outputFileName);

  exit (0);
}
コード例 #6
0
ファイル: errors.c プロジェクト: ystk/debian-gnutls26
/**
 * asn1_perror - prints a string to stderr with a description of an error
 * @error: is an error returned by a libtasn1 function.
 *
 * This function is like perror().  The only difference is that it
 * accepts an error returned by a libtasn1 function.
 *
 * This function replaces libtasn1_perror() in older libtasn1.
 *
 * Since: 1.6
 **/
void
asn1_perror (asn1_retCode error)
{
  const char *str = asn1_strerror (error);
  fprintf (stderr, "LIBTASN1 ERROR: %s\n", str ? str : "(null)");
}
コード例 #7
0
ファイル: errors.c プロジェクト: ystk/debian-gnutls26
/**
 * libtasn1_strerror - Returns a string with a description of an error
 * @error: is an error returned by a libtasn1 function.
 *
 * This function is similar to strerror.  The only difference is that
 * it accepts an error (number) returned by a libtasn1 function.
 *
 * Returns: Pointer to static zero-terminated string describing error
 *   code.
 *
 * Deprecated: Use asn1_strerror() instead.
 **/
const char *
libtasn1_strerror (asn1_retCode error)
{
  return asn1_strerror (error);
}
コード例 #8
0
ファイル: Test_parser.c プロジェクト: Chronic-Dev/libtasn1
int
main (int argc, char *argv[])
{
  asn1_retCode result;
  ASN1_TYPE definitions = ASN1_TYPE_EMPTY;
  char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
  test_type *test;
  int errorCounter = 0, testCounter = 0;

  fileCorrectName = getenv ("ASN1PARSER");
  if (!fileCorrectName)
    fileCorrectName = "Test_parser.asn";

  printf ("\n\n/****************************************/\n");
  printf ("/*     Test sequence : Test_parser      */\n");
  printf ("/****************************************/\n\n");
  printf ("ASN1PARSER: %s\n", fileCorrectName);

  result = asn1_parser2tree (fileCorrectName, &definitions, errorDescription);

  if (result != ASN1_SUCCESS)
    {
      printf ("File '%s' not correct\n", fileCorrectName);
      asn1_perror (result);
      printf ("ErrorDescription = %s\n\n", errorDescription);
      exit (1);
    }

  /* Only for Test */
  /* asn1_visit_tree(stdout,definitions,"TEST_PARSER",ASN1_PRINT_ALL); */

  /* Clear the definitions structures */
  asn1_delete_structure (&definitions);


  test = test_array;

  while (test->lineNumber != 0)
    {
      testCounter++;

      createFile (test->lineNumber, test->line);

      result =
	asn1_parser2tree (fileErroredName, &definitions, errorDescription);
      asn1_delete_structure (&definitions);

      if ((result != test->errorNumber) ||
	  (strcmp (errorDescription, test->errorDescription)))
	{
	  errorCounter++;
	  printf ("ERROR N. %d:\n", errorCounter);
	  printf ("  Line %d - %s\n", test->lineNumber, test->line);
	  printf ("  Error expected: %s - %s\n",
		  asn1_strerror (test->errorNumber), test->errorDescription);
	  printf ("  Error detected: %s - %s\n\n", asn1_strerror (result),
		  errorDescription);
	}

      test++;
    }


  printf ("Total tests : %d\n", testCounter);
  printf ("Total errors: %d\n", errorCounter);

  if (errorCounter > 0)
    return 1;

  exit (0);
}