Beispiel #1
0
//	-----------------------------------------------------------------------------
int SaveSituation(void)
{
    if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
        set_extension(sit_filename, "MIN");
        if (med_save_mine(sit_filename)) {
            return 0;
        }

        set_extension(sit_filename, "SIT");
        if (med_save_situation(sit_filename))
            return 0;
    }

    return 1;
}
Beispiel #2
0
//	-----------------------------------------------------------------------------
int med_save_situation(char * filename)
{
	PHYSFS_file * SaveFile;
	char	mine_name[MAX_NAME_LENGTH];

	SaveFile = PHYSFSX_openWriteBuffered( filename );
	if (!SaveFile)	{
		char  ErrorMessage[200];

		sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
		ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" );
		return 1;
	}

	//	Write mine name.
//	strcpy(mine_name, filename);
	d_splitpath(filename, NULL, NULL, mine_name, NULL);
	set_extension(mine_name, "min");
	PHYSFSX_printf(SaveFile, "%s\n", mine_name);

	//	Write player position.
        PHYSFSX_printf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z);

	//	Write player orientation.
        PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z);
        PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z);                       
        PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z);
	PHYSFSX_printf(SaveFile, "%i\n", ConsoleObject->segnum);

	PHYSFS_close( SaveFile);

	return 1;
}
Beispiel #3
0
//	-----------------------------------------------------------------------------
int SaveSituation(void)
{
	if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
		set_extension(sit_filename, "MIN");
		if (med_save_mine(sit_filename)) {
			mprintf((0, "Unable to save mine in SaveSituation.\n"));
			return 0;
		}

		set_extension(sit_filename, "SIT");
		if (med_save_situation(sit_filename))
			return 0;
	}
	
	return 1;
}
Beispiel #4
0
static void set_filenm(t_filenm *fnm, const char *name, gmx_bool bCanNotOverride,
                       gmx_bool bReadNode)
{
    /* Set the default filename, extension and option for those fields that
     * are not already set. An extension is added if not present, if fn = NULL
     * or empty, the default filename is given.
     */
    char buf[256];
    int  i, len, extlen;

    if ((fnm->flag & ffREAD) && !bReadNode)
    {
        return;
    }

    if ((fnm->ftp < 0) || (fnm->ftp >= efNR))
    {
        gmx_fatal(FARGS, "file type out of range (%d)", fnm->ftp);
    }

    if (name)
    {
        strcpy(buf, name);
    }
    if ((fnm->flag & ffREAD) && name && gmx_fexist(name))
    {
        /* check if filename ends in .gz or .Z, if so remove that: */
        len = strlen(name);
        for (i = 0; i < NZEXT; i++)
        {
            extlen = strlen(z_ext[i]);
            if (len > extlen)
            {
                if (gmx_strcasecmp(name+len-extlen, z_ext[i]) == 0)
                {
                    buf[len-extlen] = '\0';
                    break;
                }
            }
        }
    }

    if (deffile[fnm->ftp].ntps)
    {
        set_grpfnm(fnm, name ? buf : NULL, bCanNotOverride);
    }
    else
    {
        if ((name == NULL) || !(bCanNotOverride || (default_file_name == NULL)))
        {
            const char *defnm = ftp2defnm(fnm->ftp);
            strcpy(buf, defnm);
        }
        set_extension(buf, fnm->ftp);

        add_filenm(fnm, buf);
    }
}
Beispiel #5
0
int
_gnutls_x509_crl_set_extension (gnutls_x509_crl_t crl,
                                const char *ext_id,
                                const gnutls_datum_t * ext_data,
                                unsigned int critical)
{
  return set_extension (crl->crl, "tbsCertList.crlExtensions", ext_id,
                        ext_data, critical);
}
Beispiel #6
0
/* This function will attempt to overwrite the requested extension with
 * the given one. 
 *
 * Critical will be either 0 or 1.
 */
int
_gnutls_x509_crt_set_extension (gnutls_x509_crt_t cert,
                                const char *ext_id,
                                const gnutls_datum_t * ext_data,
                                unsigned int critical)
{
  return set_extension (cert->cert, "tbsCertificate.extensions", ext_id,
                        ext_data, critical);
}
/* -----------------------------------------------
	creates filename, callocs memory for it
	----------------------------------------------- */	
char* create_filename( char* base, char* extension )
{
	int len = strlen(base);
	int tol = 8;
	char* filename = (char*) calloc( len + tol, sizeof( char ) );
	
	set_extension( filename, base, extension );
	
	return filename;
}
Beispiel #8
0
/**
 * \brief Apply the \c MESA_EXTENSION_OVERRIDE environment variable.
 *
 * \c MESA_EXTENSION_OVERRIDE is a space-separated list of extensions to
 * enable or disable. The list is processed thus:
 *    - Enable recognized extension names that are prefixed with '+'.
 *    - Disable recognized extension names that are prefixed with '-'.
 *    - Enable recognized extension names that are not prefixed.
 *    - Collect unrecognized extension names in a new string.
 *
 * \return Space-separated list of unrecognized extension names (which must
 *    be freed). Does not return \c NULL.
 */
static char *
get_extension_override( struct gl_context *ctx )
{
   const char *env_const = _mesa_getenv("MESA_EXTENSION_OVERRIDE");
   char *env;
   char *ext;
   char *extra_exts;
   int len;

   if (env_const == NULL) {
      /* Return the empty string rather than NULL. This simplifies the logic
       * of client functions. */
      return calloc(4, sizeof(char));
   }

   /* extra_exts: List of unrecognized extensions. */
   extra_exts = calloc(ALIGN(strlen(env_const) + 2, 4), sizeof(char));

   /* Copy env_const because strtok() is destructive. */
   env = strdup(env_const);
   for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
      int enable;
      int recognized;
      switch (ext[0]) {
      case '+':
         enable = 1;
         ++ext;
         break;
      case '-':
         enable = 0;
         ++ext;
         break;
      default:
         enable = 1;
         break;
      }
      recognized = set_extension(ctx, ext, enable);
      if (!recognized) {
         strcat(extra_exts, ext);
         strcat(extra_exts, " ");
      }
   }

   free(env);

   /* Remove trailing space. */
   len = strlen(extra_exts);
   if (len > 0 && extra_exts[len - 1] == ' ')
      extra_exts[len - 1] = '\0';

   return extra_exts;
}
Beispiel #9
0
//	-----------------------------------------------------------------------------
int med_save_situation(char * filename)
{
	CFILE * SaveFile;
	char	mine_name[MAX_NAME_LENGTH];

	SaveFile = cfopen( filename, "wt" );
	if (!SaveFile)	{
		char  ErrorMessage[200];

		sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
		MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
		return 1;
	}

	//	Write mine name.
//	strcpy(mine_name, filename);
#ifndef __LINUX__
_splitpath(filename,NULL,NULL,mine_name,NULL);
#endif
	set_extension(mine_name, "min");
	fprintf(SaveFile, "%s\n", mine_name);

	//	Write player position.
        fprintf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z);

	//	Write player orientation.
        fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z);
        fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z);                       
        fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z);
	fprintf(SaveFile, "%i\n", ConsoleObject->segnum);

	mprintf((0, "Save Position = %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
	mprintf((0, "\n"));

	mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z));
	mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z));
	mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z));
	mprintf((0, "\n"));

	cfclose( SaveFile);

	return 1;
}
/**
 * Enable the named extension.
 * Typically called by drivers.
 */
void
_mesa_enable_extension( GLcontext *ctx, const char *name )
{
   set_extension(ctx, name, GL_TRUE);
}
static void set_grpfnm(t_filenm *fnm, const char *name, const char *deffnm)
{
    char       buf[256], buf2[256];
    int        i, type;
    gmx_bool   bValidExt;
    int        nopts;
    const int *ftps;

    nopts = deffile[fnm->ftp].ntps;
    ftps  = deffile[fnm->ftp].tps;
    if ((nopts == 0) || (ftps == NULL))
    {
        gmx_fatal(FARGS, "nopts == 0 || ftps == NULL");
    }

    bValidExt = FALSE;
    if (name && deffnm == NULL)
    {
        strcpy(buf, name);
        /* First check whether we have a valid filename already */
        type = fn2ftp(name);
        if ((fnm->flag & ffREAD) && (fnm->ftp == efTRX))
        {
            /*if file exist don't add an extension for trajectory reading*/
            bValidExt = gmx_fexist(name);
        }
        for (i = 0; (i < nopts) && !bValidExt; i++)
        {
            if (type == ftps[i])
            {
                bValidExt = TRUE;
            }
        }
    }
    else if (deffnm != NULL)
    {
        strcpy(buf, deffnm);
    }
    else
    {
        /* No name given, set the default name */
        strcpy(buf, ftp2defnm(fnm->ftp));
    }

    if (!bValidExt && (fnm->flag & ffREAD))
    {
        /* for input-files only: search for filenames in the directory */
        for (i = 0; (i < nopts) && !bValidExt; i++)
        {
            type = ftps[i];
            strcpy(buf2, buf);
            set_extension(buf2, type);
            if (gmx_fexist(buf2))
            {
                bValidExt = TRUE;
                strcpy(buf, buf2);
            }
        }
    }

    if (!bValidExt)
    {
        /* Use the first extension type */
        set_extension(buf, ftps[0]);
    }

    add_filenm(fnm, buf);
}
/**
 * Disable the named extension.
 * XXX is this really needed???
 */
void
_mesa_disable_extension( struct gl_context *ctx, const char *name )
{
   if (!set_extension(ctx, name, GL_FALSE))
      _mesa_problem(ctx, "Trying to disable unknown extension: %s", name);
}
Beispiel #13
0
/* 
 * codegen: Generate code for all the classes in the symbol table.
 */
void codegen(char *kod_fname, char *bof_fname)
{
   list_type c = NULL;
   long endpos, stringpos, debugpos, namepos;

   codegen_ok = True;
   debug_lines = NULL;

   outfile = open(bof_fname, O_TRUNC | O_CREAT | O_RDWR | O_BINARY, S_IWRITE | S_IREAD);

   if (outfile == -1)
   {
      simple_error("Unable to open bof file %s!", bof_fname);
      return;
   }

   /* Write out header info */
   codegen_header();

   /* Remember position for backpatching location of kod filename, and leave room */
   namepos = FileCurPos(outfile);
   OutputInt(outfile, 0);

   /* Remember position for backpatching location of string table, and leave room */
   stringpos = FileCurPos(outfile);
   OutputInt(outfile, 0);

   /* Remember position for backpatching location of debugging info, and leave room */
   debugpos = FileCurPos(outfile);
   OutputInt(outfile, 0);
   
   codegen_classes();
   
   if (codegen_ok)
   {
      /* Backpatch location of string table */
      endpos = FileCurPos(outfile);
      FileGoto(outfile, stringpos); 
      OutputInt(outfile, endpos);

      FileGotoEnd(outfile);
      codegen_string_table();

      /* Backpatch location of debug info */
      endpos = FileCurPos(outfile);
      FileGoto(outfile, debugpos); 
      if (debug_bof)
         OutputInt(outfile, endpos);
      else OutputInt(outfile, 0);

      FileGotoEnd(outfile);
      if (debug_bof)
         codegen_debug_info();

      /* Backpatch location of kod filename */
      endpos = FileCurPos(outfile);
      FileGoto(outfile, namepos); 
      OutputInt(outfile, endpos);

      FileGotoEnd(outfile);
      codegen_filename(kod_fname);
   }

   close(outfile);

   /* If code generation failed, delete partial bof file */
   if (!codegen_ok)
   {
      if (unlink(bof_fname))
	 codegen_error("Couldn't delete file %s", bof_fname);
      else simple_warning("Deleted file %s", bof_fname);
   }

   /* Write out resources & new database if we compiled ok */
   if (codegen_ok)
   {
      char temp[256];
      set_extension(temp, bof_fname, ".rsc");
      write_resources(temp);
      save_kodbase();
   }

   /* Mark all classes as done */
   for (c = st.classes; c != NULL; c = c->next)
      ((class_type) (c->data))->is_new = False;
}
/**
 * Disable the named extension.
 * XXX is this really needed???
 */
void
_mesa_disable_extension( GLcontext *ctx, const char *name )
{
   set_extension(ctx, name, GL_FALSE);
}
Beispiel #15
0
/*
 * Create identity
 */
int build_identity(void)
{
    EVP_PKEY * pkey ;
    RSA * rsa ;
    EC_KEY * ecc ;
    X509 * cert ;
    X509_NAME * name ;
    identity ca ;
    char filename[FIELD_SZ+5];
    FILE * pem ;

    /* Check before overwriting */
    sprintf(filename, "%s.crt", certinfo.cn);
    if (access(filename, F_OK)!=-1) {
        fprintf(stderr, "identity named %s already exists in this directory. Exiting now\n", filename);
        return -1 ;
    }
    sprintf(filename, "%s.key", certinfo.cn);
    if (access(filename, F_OK)!=-1) {
        fprintf(stderr, "identity named %s already exists in this directory. Exiting now\n", filename);
        return -1 ;
    }

    switch (certinfo.profile) {
        case PROFILE_ROOT_CA:
        strcpy(certinfo.ou, "Root");
        break;

        case PROFILE_SUB_CA:
        strcpy(certinfo.ou, "Sub");
        break;

        case PROFILE_SERVER:
        strcpy(certinfo.ou, "Server");
        break;
        
        case PROFILE_CLIENT:
        strcpy(certinfo.ou, "Client");
        break;

        case PROFILE_WWW:
        strcpy(certinfo.ou, "Server");
        break;

        default:
        fprintf(stderr, "Unknown profile: aborting\n");
        return -1 ;
    }

    if (certinfo.ec_name[0] && certinfo.profile!=PROFILE_CLIENT) {
        fprintf(stderr, "ECC keys are only supported for clients\n");
        return -1 ;
    }

    if (certinfo.profile != PROFILE_ROOT_CA) {
        /* Need to load signing CA */
        if (load_ca(certinfo.signing_ca, &ca)!=0) {
            fprintf(stderr, "Cannot find CA key or certificate\n");
            return -1 ;
        }
        /* Organization is the same as root */
        X509_NAME_get_text_by_NID(X509_get_subject_name(ca.cert),
                                  NID_organizationName,
                                  certinfo.o,
                                  FIELD_SZ);
    }

    /* Generate key pair */
    if (certinfo.ec_name[0]) {
        printf("Generating EC key [%s]\n", certinfo.ec_name);
        ecc = EC_KEY_new_by_curve_name(OBJ_txt2nid(certinfo.ec_name));
        if (!ecc) {
            fprintf(stderr, "Unknown curve: [%s]\n", certinfo.ec_name);
            return -1 ;
        }
        EC_KEY_set_asn1_flag(ecc, OPENSSL_EC_NAMED_CURVE);
        EC_KEY_generate_key(ecc);
        pkey = EVP_PKEY_new();
        EVP_PKEY_assign_EC_KEY(pkey, ecc);
    } else {
        printf("Generating RSA-%d key\n", certinfo.rsa_keysz);
        pkey = EVP_PKEY_new();
        rsa = RSA_generate_key(certinfo.rsa_keysz, RSA_F4, progress, 0);
        EVP_PKEY_assign_RSA(pkey, rsa);
    }

    /* Assign all certificate fields */
    cert = X509_new();
    X509_set_version(cert, 2);
    set_serial128(cert);
    X509_gmtime_adj(X509_get_notBefore(cert), 0);
    X509_gmtime_adj(X509_get_notAfter(cert), certinfo.days * 24*60*60);
    X509_set_pubkey(cert, pkey);

    name = X509_get_subject_name(cert);
    if (certinfo.c[0]) {
        X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, (unsigned char*)certinfo.c, -1, -1, 0);
    }
    X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, (unsigned char*)certinfo.o, -1, -1, 0);
    X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, (unsigned char*)certinfo.cn, -1, -1, 0);
    X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_ASC, (unsigned char*)certinfo.ou, -1, -1, 0);
    if (certinfo.l[0]) {
        X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, (unsigned char *)certinfo.l, -1, -1, 0);
    }
    if (certinfo.st[0]) {
        X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, (unsigned char *)certinfo.st, -1, -1, 0);
    }

    /* Set extensions according to profile */
    switch (certinfo.profile) {
        case PROFILE_ROOT_CA:
        /* CA profiles can issue certs and sign CRLS */
        set_extension(cert, cert, NID_basic_constraints, "critical,CA:TRUE");
        set_extension(cert, cert, NID_key_usage, "critical,keyCertSign,cRLSign");
        set_extension(cert, cert, NID_subject_key_identifier, "hash");
        set_extension(cert, cert, NID_authority_key_identifier, "keyid:always");
        break ;

        case PROFILE_SUB_CA:
        /* CA profiles can issue certs and sign CRLS */
        set_extension(ca.cert, cert, NID_basic_constraints, "critical,CA:TRUE");
        set_extension(ca.cert, cert, NID_key_usage, "critical,keyCertSign,cRLSign");
        set_extension(ca.cert, cert, NID_subject_key_identifier, "hash");
        set_extension(ca.cert, cert, NID_authority_key_identifier, "keyid:always");
        break;

        case PROFILE_CLIENT:
        if (certinfo.san[0]) {
            set_extension(ca.cert, cert, NID_subject_alt_name, certinfo.san);
        }
        set_extension(ca.cert, cert, NID_basic_constraints, "CA:FALSE");
        set_extension(ca.cert, cert, NID_anyExtendedKeyUsage, "clientAuth");
        set_extension(ca.cert, cert, NID_key_usage, "digitalSignature");
        set_extension(ca.cert, cert, NID_subject_key_identifier, "hash");
        set_extension(ca.cert, cert, NID_authority_key_identifier, "issuer:always,keyid:always");
        break ;

        case PROFILE_SERVER:
        if (certinfo.san[0]) {
            set_extension(ca.cert, cert, NID_subject_alt_name, certinfo.san);
        }
        set_extension(ca.cert, cert, NID_basic_constraints, "CA:FALSE");
        set_extension(ca.cert, cert, NID_netscape_cert_type, "server");
        set_extension(ca.cert, cert, NID_anyExtendedKeyUsage, "serverAuth");
        set_extension(ca.cert, cert, NID_key_usage, "digitalSignature,keyEncipherment");
        set_extension(ca.cert, cert, NID_subject_key_identifier, "hash");
        set_extension(ca.cert, cert, NID_authority_key_identifier, "issuer:always,keyid:always");
        break ;

        case PROFILE_WWW:
        if (certinfo.san[0]) {
            set_extension(ca.cert, cert, NID_subject_alt_name, certinfo.san);
        }
        set_extension(ca.cert, cert, NID_basic_constraints, "CA:FALSE");
        set_extension(ca.cert, cert, NID_netscape_cert_type, "server");
        set_extension(ca.cert, cert, NID_anyExtendedKeyUsage, "serverAuth,clientAuth");
        set_extension(ca.cert, cert, NID_key_usage, "digitalSignature,keyEncipherment");
        set_extension(ca.cert, cert, NID_subject_key_identifier, "hash");
        set_extension(ca.cert, cert, NID_authority_key_identifier, "issuer:always,keyid:always");
        break;

        case PROFILE_UNKNOWN:
        default:
        break ;
    }
    /* Set issuer */
    if (certinfo.profile==PROFILE_ROOT_CA) {
        /* Self-signed */
        X509_set_issuer_name(cert, name);
        X509_sign(cert, pkey, EVP_sha256());
    } else {
        /* Signed by parent CA */
        X509_set_issuer_name(cert, X509_get_subject_name(ca.cert));
        X509_sign(cert, ca.key, EVP_sha256());
    }

    printf("Saving results to %s.[crt|key]\n", certinfo.cn);
    pem = fopen(filename, "wb");
    PEM_write_PrivateKey(pem, pkey, NULL, NULL, 0, NULL, NULL);
    fclose(pem);
    sprintf(filename, "%s.crt", certinfo.cn);
    pem = fopen(filename, "wb");
    PEM_write_X509(pem, cert);
    fclose(pem);
    X509_free(cert);
    EVP_PKEY_free(pkey);

    if (certinfo.profile!=PROFILE_ROOT_CA) {
        X509_free(ca.cert);
        EVP_PKEY_free(ca.key);
    }
    printf("done\n");

    return 0;
}
Beispiel #16
0
int
_gnutls_x509_crq_set_extension (gnutls_x509_crq_t crq,
                                const char *ext_id,
                                const gnutls_datum_t * ext_data,
                                unsigned int critical)
{
  unsigned char *extensions = NULL;
  size_t extensions_size = 0;
  gnutls_datum_t der;
  ASN1_TYPE c2;
  int result;

  result = gnutls_x509_crq_get_attribute_by_oid (crq, "1.2.840.113549.1.9.14",
                                                 0, NULL, &extensions_size);
  if (result == GNUTLS_E_SHORT_MEMORY_BUFFER)
    {
      extensions = gnutls_malloc (extensions_size);
      if (extensions == NULL)
        {
          gnutls_assert ();
          return GNUTLS_E_MEMORY_ERROR;
        }

      result = gnutls_x509_crq_get_attribute_by_oid (crq,
                                                     "1.2.840.113549.1.9.14",
                                                     0, extensions,
                                                     &extensions_size);
    }
  if (result < 0)
    {
      if (result == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
        {
          extensions_size = 0;
        }
      else
        {
          gnutls_assert ();
          gnutls_free (extensions);
          return result;
        }
    }

  result = asn1_create_element (_gnutls_get_pkix (), "PKIX1.Extensions", &c2);
  if (result != ASN1_SUCCESS)
    {
      gnutls_assert ();
      gnutls_free (extensions);
      return _gnutls_asn2err (result);
    }

  if (extensions_size > 0)
    {
      result = asn1_der_decoding (&c2, extensions, extensions_size, NULL);
      gnutls_free (extensions);
      if (result != ASN1_SUCCESS)
        {
          gnutls_assert ();
          asn1_delete_structure (&c2);
          return _gnutls_asn2err (result);
        }
    }

  result = set_extension (c2, "", ext_id, ext_data, critical);
  if (result < 0)
    {
      gnutls_assert ();
      asn1_delete_structure (&c2);
      return result;
    }

  result = _gnutls_x509_der_encode (c2, "", &der, 0);

  asn1_delete_structure (&c2);

  if (result < 0)
    {
      gnutls_assert ();
      return result;
    }

  result = gnutls_x509_crq_set_attribute_by_oid (crq, "1.2.840.113549.1.9.14",
                                                 der.data, der.size);
  gnutls_free (der.data);
  if (result < 0)
    {
      gnutls_assert ();
      return result;
    }


  return 0;
}
/**
 * \brief Initialize extension override tables.
 *
 * This should be called one time early during first context initialization.
 */
void
_mesa_one_time_init_extension_overrides(void)
{
   const char *env_const = getenv("MESA_EXTENSION_OVERRIDE");
   char *env;
   char *ext;
   int len;
   size_t offset;

   atexit(free_unknown_extensions_strings);

   memset(&_mesa_extension_override_enables, 0, sizeof(struct gl_extensions));
   memset(&_mesa_extension_override_disables, 0, sizeof(struct gl_extensions));

   if (env_const == NULL) {
      return;
   }

   /* extra_exts: List of unrecognized extensions. */
   extra_extensions = calloc(ALIGN(strlen(env_const) + 2, 4), sizeof(char));

   /* Copy env_const because strtok() is destructive. */
   env = strdup(env_const);

   if (env == NULL ||
       extra_extensions == NULL) {
      free(env);
      free(extra_extensions);
      return;
   }

   for (ext = strtok(env, " "); ext != NULL; ext = strtok(NULL, " ")) {
      int enable;
      int i;
      bool recognized;
      switch (ext[0]) {
      case '+':
         enable = 1;
         ++ext;
         break;
      case '-':
         enable = 0;
         ++ext;
         break;
      default:
         enable = 1;
         break;
      }

      i = name_to_index(ext);
      offset = set_extension(&_mesa_extension_override_enables, i, enable);
      if (offset != 0 && (offset != o(dummy_true) || enable != GL_FALSE)) {
         ((GLboolean *) &_mesa_extension_override_disables)[offset] = !enable;
         recognized = true;
      } else {
         recognized = false;
      }

      if (i >= 0)
         disabled_extensions[i] = !enable;

      if (!recognized && enable) {
         strcat(extra_extensions, ext);
         strcat(extra_extensions, " ");
      }
   }

   free(env);

   /* Remove trailing space, and free if unused. */
   len = strlen(extra_extensions);
   if (len == 0) {
      free(extra_extensions);
      extra_extensions = NULL;
   } else if (extra_extensions[len - 1] == ' ') {
      extra_extensions[len - 1] = '\0';
   }
}