Пример #1
0
/*
 * Take values from the parents certificateand write them to the
 * current certificate.
 * val is filename of the parent certificate
 * fields of interest:
 *    signature algorithm ID - overwrite (from template)
 *    issuer     - if filled in then don't overwrite
 *    aki        - use ski from issuer's cert
 *    algorithm ID  overwrite (from template)
 */
int use_parent_cert(
    void *cert,
    void *val)
{
    struct Certificate issuer;
    struct Certificate *certp = (struct Certificate *)cert;
    struct CertificateToBeSigned *ctftbsp = &certp->toBeSigned;
    Certificate(&issuer, (ushort) 0);
    struct Extension *iextp,
       *cextp;

    // if not parent cert or we are self signed (and shouldn't have a parent
    // cert)
    if ((val == NULL) || (selfSigned))
        return SUCCESS;

    // fprintf(stdout,"getting issuers cert %s\n", (char *)val);
    if (get_casn_file(&issuer.self, val, 0) < 0)
    {
        fprintf(stdout, "can't use issuers cert %s", (char *)val);
        return -1;
    }
    // copy algorithm identifiers (overwrite template value)
    // fprintf(stdout,"trying to copy algorithm identifiers\n");
    copy_casn(&certp->algorithm.self, &issuer.toBeSigned.signature.self);
    copy_casn(&ctftbsp->signature.self, &issuer.toBeSigned.signature.self);
    // fprintf(stdout,"copied algorithm identifiers\n");

    // copy subject name from issuer cert into issuer name in cert if issuer
    // name
    // not filled in.
    copy_casn(&ctftbsp->issuer.self, &issuer.toBeSigned.subject.self);
    // fprintf(stdout,"copied issuer name\n");

    // replace aki extension of certificate with ski from issuer's cert
    cextp = find_extension(&ctftbsp->extensions, id_authKeyId, false);
    if (!cextp)
        cextp = make_extension(&ctftbsp->extensions, id_authKeyId);
    // fprintf(stdout,"copying ski as aki\n");
    if ((iextp = find_extension(&issuer.toBeSigned.extensions,
                                id_subjectKeyIdentifier, false)))
    {
        copy_casn(&cextp->extnValue.authKeyId.keyIdentifier,
                  &iextp->extnValue.subjectKeyIdentifier);
    }
    else
    {
        fprintf(stdout, "Error: issuer cert has no SKI. AKI not set.");
        delete_casn(&issuer.self);
        return -1;
    }

    delete_casn(&issuer.self);
    return (SUCCESS);
}
Пример #2
0
int write_default_fields(
    struct Certificate *certp)
{

    struct CertificateToBeSigned *ctftbsp = &certp->toBeSigned;
    struct Extension *cextp;


    // key usage
    // If ca set keyCertSign and CRLsign bits
    // if ee set digitalSignature bit
    if (!(cextp = find_extension(&ctftbsp->extensions, id_keyUsage, false)))
        cextp = make_extension(&ctftbsp->extensions, id_keyUsage);
    if (eecert)
    {                           // clear everything first
        write_casn_num(&cextp->critical, 1);
        write_casn(&cextp->extnValue.keyUsage.self, (uchar *) "", 0);
        write_casn_bit(&cextp->extnValue.keyUsage.digitalSignature, 1);
    }
    else
    {
        write_casn_num(&cextp->critical, 1);
        write_casn(&cextp->extnValue.keyUsage.self, (uchar *) "", 0);
        write_casn_bit(&cextp->extnValue.keyUsage.keyCertSign, 1);
        write_casn_bit(&cextp->extnValue.keyUsage.cRLSign, 1);
    }

    // basic constraints
    // if ee no extension, if ca set ca to one
    cextp = find_extension(&ctftbsp->extensions, id_basicConstraints, false);
    if (eecert)
    {
        // no basic constraints extension for an ee cert
        if (cextp)
            removeExtension(&ctftbsp->extensions, id_basicConstraints);
    }
    else
    {
        int caConstraint = 1;
        if (!cextp)
            cextp = make_extension(&ctftbsp->extensions, id_basicConstraints);
        write_casn_num(&cextp->critical, 1);
        // write_casn(&cextp->extnValue.basicConstraints.self, (uchar *)"",
        // 0);
        write_casn_num(&cextp->extnValue.basicConstraints.cA, caConstraint);
    }

    return SUCCESS;
}
Пример #3
0
/*
 * Take values from the subject keyfile and write them to the
 * current certificate.
 * val is filename of the subject keyfile
 * values of interest are the subject public key and the ski.
 */
int use_subject_keyfile(
    void *cert,
    void *val)
{
    struct Certificate *certp = (struct Certificate *)cert;
    struct CertificateToBeSigned *ctftbsp = &certp->toBeSigned;
    struct SubjectPublicKeyInfo *spkinfop = &ctftbsp->subjectPublicKeyInfo;
    struct Extensions *extsp = &ctftbsp->extensions;
    struct Extension *extp;
    struct casn *spkp = &spkinfop->subjectPublicKey;


    if (val == NULL)
        return -1;

    // if no subjectPublicKey in the cert then get if from keyfile
    if (vsize_casn(&spkinfop->subjectPublicKey) <= 0)
    {
        write_objid(&spkinfop->algorithm.algorithm, id_rsadsi_rsaEncryption);
        write_casn(&spkinfop->algorithm.parameters.rsadsi_rsaEncryption,
                   (uchar *) "", 0);
        if (!fillPublicKey(spkp, val))
            return -1;
    }

    // always update SKI to match subjectPublicKey
    if (!(extp = find_extension(extsp, id_subjectKeyIdentifier, false)))
        extp = make_extension(extsp, id_subjectKeyIdentifier);
    writeHashedPublicKey(&extp->extnValue.subjectKeyIdentifier, spkp, false);

    return (SUCCESS);
}
Пример #4
0
int find_program(char *name, char *ext)
{
   /* look for a file, checking the possible extensions */

   char *p;
   int pos;

   if ((ext) && (*ext) && (*(find_extension(name))==0)) {
      p = ext;
      while(*p) {
	 while ((*p==' ') || (*p==',') || (*p==';'))
	    p++;
	 if(*p) {
	    pos=strlen(name);
	    name[pos++]='.';
	    name[pos]=0;
	    while ((*p) && (*p!=' ') && (*p!=',') && (*p!=';')) {
	       name[pos++]=*(p++);
	       name[pos]=0;
	    }
	    if (file_exists(name))
	       return TRUE;
	    remove_extension(name);
	 }
      }
   }
   else
      return file_exists(name);

   return FALSE;
}
Пример #5
0
compilation_unit_type_t autodetect_input(char const *const path)
{
	char const *name;
	char const *suffix = find_extension(path, &name);
	/* Ensure there is at least one char before the suffix */
	if (suffix == name)
		return COMPILATION_UNIT_OBJECT;
	++suffix;
	return
		streq(suffix, "S")   ? COMPILATION_UNIT_ASSEMBLER              :
		streq(suffix, "a")   ? COMPILATION_UNIT_OBJECT                 :
		streq(suffix, "c")   ? COMPILATION_UNIT_C                      :
		streq(suffix, "i")   ? COMPILATION_UNIT_PREPROCESSED_C         :
		streq(suffix, "C")   ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "cc")  ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "cp")  ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "cpp") ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "CPP") ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "cxx") ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "c++") ? COMPILATION_UNIT_CXX                    :
		streq(suffix, "ii")  ? COMPILATION_UNIT_PREPROCESSED_CXX       :
		streq(suffix, "h")   ? COMPILATION_UNIT_C                      :
		streq(suffix, "ir")  ? COMPILATION_UNIT_IR                     :
		streq(suffix, "o")   ? COMPILATION_UNIT_OBJECT                 :
		streq(suffix, "so")  ? COMPILATION_UNIT_OBJECT                 :
		streq(suffix, "s")   ? COMPILATION_UNIT_PREPROCESSED_ASSEMBLER :
		COMPILATION_UNIT_OBJECT; /* gcc behavior: unknown file extension means
		                            object file */
}
Пример #6
0
	String8 String8::getPathExtension(void) const
	{
		char* ext;

		ext = find_extension();
		if (ext != NULL)
			return String8(ext);
		else
			return String8("");
	}
Пример #7
0
	String8 String8::getBasePath(void) const
	{
		char* ext;
		const char* const str = mString;

		ext = find_extension();
		if (ext == NULL)
			return String8(*this);
		else
			return String8(str, ext - str);
	}
Пример #8
0
// clear out the fields that must be filled in
void clear_cert(
    struct Certificate *certp)
{
    struct CertificateToBeSigned *tbsp = &certp->toBeSigned;
    struct Extensions *extsp = &tbsp->extensions;

    clear_casn(&tbsp->serialNumber);
    clear_casn(&tbsp->issuer.self);
    clear_casn(&tbsp->subject.self);
    clear_casn(&tbsp->validity.self);
    clear_casn(&tbsp->subjectPublicKeyInfo.self);
    clear_casn(&certp->signature);

    // remove all RFC 3779 extensions
    // ASN.1 definition allows duplicates, even if RFC5280/6487 forbid them.
    while (find_extension(extsp, id_pe_ipAddrBlock, false))
        removeExtension(extsp, id_pe_ipAddrBlock);
    while (find_extension(extsp, id_pe_autonomousSysNum, false))
        removeExtension(extsp, id_pe_autonomousSysNum);
}
Пример #9
0
static char *make_output_name(char *source, char *new_extension)
{
    char *extension = find_extension(source);
    int base_len = extension ? extension - source - 1 : strlen(source);
    char *output = malloc(base_len + strlen(new_extension) + 1);

    memcpy(output, source, base_len);
    strcpy(output + base_len, new_extension);

    return output;
}
Пример #10
0
const char *get_output_name(const char *inputname, const char *newext)
{
	if (inputname == NULL)
		inputname = "a";

	char const       *filename;
	char const *const name_end = find_extension(inputname, &filename);

	assert(obstack_object_size(&file_obst) == 0);
	obstack_grow(&file_obst, filename, name_end-filename);
	size_t extlen = strlen(newext);
	obstack_grow(&file_obst, newext, extlen);
	return obstack_nul_finish(&file_obst);
}
Пример #11
0
int main(
    int argc,
    char **argv)
{
    struct Certificate cert;
    int lth;
    Certificate(&cert, (ushort) 0);
    if (argc == 0 || argc < 3)
        FATAL(MSG_USAGE);
    lth = get_casn_file(&cert.self, argv[1], 0);
    struct casn *casnp = &cert.toBeSigned.serialNumber;
    if ((lth = vsize_casn(casnp)) < 6)
        FATAL(MSG_SN);
    struct Extension *extp;
    if (!(extp = find_extension(&cert.toBeSigned.extensions, id_pe_ipAddrBlock, 0)))
        FATAL(MSG_EXT, "IPAddress");
    struct Extensions extensions;
    Extensions(&extensions, (ushort) 0);
    if ((lth = get_casn_file(&extensions.self, argv[2], 0)) < 0)
        FATAL(MSG_OPEN, argv[2]);
    struct Extension *sbextp = (struct Extension *)member_casn(&extensions.self, 0);    // ip
                                                                                        // Addresses
    uchar *sb = (uchar *) calloc(1, size_casn(&sbextp->self));
    read_casn(&sbextp->self, sb);
    uchar *b = (uchar *) calloc(1, size_casn(&extp->self));
    read_casn(&extp->self, b);
    if (diff_casn(&sbextp->self, &extp->self))
        FATAL(MSG_IN, "IP Addresses");
    sbextp = (struct Extension *)next_of(&sbextp->self);
    if (!(extp = find_extension(&cert.toBeSigned.extensions,
                                id_pe_autonomousSysNum, 0)))
        FATAL(MSG_EXT, "AS number");
    if (diff_casn(&sbextp->self, &extp->self))
        FATAL(MSG_IN, "AS numbers");
    DONE(MSG_OK, argv[1]);
    return 0;
}
Пример #12
0
void begin_statistics(void)
{
	if (produce_statev) {
		/* attempt to guess a good name for the file */
		const char *first_cup = units->name;
		if (first_cup != NULL) {
			char const *const pos = find_extension(first_cup, NULL);
			size_t      const len = pos - first_cup;
			char              buf[len + 1];
			memcpy(buf, first_cup, len);
			buf[len] = '\0';

			stat_ev_begin(buf, filtev);
		}
	}
}
Пример #13
0
static gchar *
find_content_type (const gchar *filename)
{
  /* This function returns a MIME Content-type: value based on the
     filename it is given.  */
  const gchar *type_mappings[20] =
  {
    "gif" , "image/gif",
    "jpg" , "image/jpeg",
    "jpeg", "image/jpeg",
    "tif" , "image/tiff",
    "tiff", "image/tiff",
    "png" , "image/png",
    "g3"  , "image/g3fax",
    "ps"  , "application/postscript",
    "eps" , "application/postscript",
    NULL, NULL
  };

  gchar *ext;
  gint   i;

  ext = find_extension (filename);

  if (!ext)
    {
      return g_strdup ("application/octet-stream");
    }

  i = 0;
  ext += 1;

  while (type_mappings[i])
    {
      if (g_ascii_strcasecmp (ext, type_mappings[i]) == 0)
        {
          return g_strdup (type_mappings[i + 1]);
        }

      i += 2;
    }

  return g_strdup_printf ("image/x-%s", ext);
}
Пример #14
0
//===========================================================================
bool cLoadMeshFromFile(cMesh* a_mesh, const string& a_fileName) 
{
    // verify mesh object
    if (a_mesh == NULL) { return (false); }

    // retrieve filename
    const char* filename = a_fileName.c_str();
    char* extension = find_extension(filename);

    // We need a file extension to figure out file type
    if (extension == 0) 
    {
        return false;
    }

    char lower_extension[1024];
    string_tolower(lower_extension,extension);

    // return value
    bool result = false;

    // Load an .obj file
    if (strcmp(lower_extension,"obj")==0) 
    {
        result = cLoadFileOBJ(a_mesh, a_fileName);
    }

    // Load a .3ds file
    else if (strcmp(lower_extension,"3ds")==0) 
    {
        result = cLoadFile3DS(a_mesh, a_fileName);
    }

    // if file has loaded, set the super parent to all child nodes.
    // the root (current object a_mesh) becomes the super parent of itself.
    if (result)
    {
        a_mesh->setSuperParent(a_mesh, true);
    }

    // return result
    return(result);
}
Пример #15
0
/* now actually a snapshot/tape loader*/
void spcf_read_command_line(const void* parameter)
{
  int ix;

  ix = find_extension( parameter - 3 + rb->strlen (parameter) );
      
  file_type = extensions[ix].type;
  file_subtype = extensions[ix].subtype;
  rb->strlcpy(filenamebuf, parameter, MAXFILENAME - 10 + 1);
  if(file_type < 0) file_subtype = -1;
  if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype))
    return;

  if(file_type == FT_SNAPSHOT) {
    spcf_init_snapshot = make_string(spcf_init_snapshot, filenamebuf);
    spcf_init_snapshot_type = file_subtype;
  }
  else if(file_type == FT_TAPEFILE) {
    spcf_init_tapefile = make_string(spcf_init_tapefile, filenamebuf);
    spcf_init_tapefile_type = file_subtype;
  }
}
Пример #16
0
int main(
    int argc,
    char *argv[])
{

    int delete_existing = 0;    /* delete existing SIA access descriptions */
    const char *file = NULL;    /* certificate file */
    struct Certificate cert;    /* ASN.1 certificate object */
    struct Extension *extp;     /* ASN.1 X.509 extension pointer */
    struct SubjectInfoAccess *siap;     /* ASN.1 SIA pointer */

    int c = 0;                  /* getopt option character */
    int i;                      /* loop counter */
    int ret;                    /* return value */

    /*
     * Parse command line arguments.
     */
    opterr = 0;
    while ((c = getopt(argc, argv, "dr:m:s:h")) != -1)
    {
        switch (c)
        {
        case 'd':
            delete_existing = 1;
            break;
        case 'r':              /* id-ad-caRepository */
            if (add_sia_request('r', optarg) != 0)
            {
                fprintf(stderr, "Error: failed to add URI request -r %s\n",
                        optarg);
                return -1;
            }
            break;
        case 'm':              /* id-ad-rpkiManifest */
            if (add_sia_request('m', optarg) != 0)
            {
                fprintf(stderr, "Error: failed to add URI request -m %s\n",
                        optarg);
                return -1;
            }
            break;
        case 's':              /* id-ad-signedObject */
            if (add_sia_request('s', optarg) != 0)
            {
                fprintf(stderr, "Error: failed to add URI request -s %s\n",
                        optarg);
                return -1;
            }
            break;
        case 'h':
            usage(argc, argv);
            return -1;
        case '?':
            if (isprint(optopt))
                fprintf(stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
            usage(argc, argv);
            return -1;
        default:
            usage(argc, argv);
            return -1;
        }
    }
    if (optind >= argc)
    {                           /* no arguments remain? */
        usage(argc, argv);
        return -1;
    }
    file = argv[optind];

    /*
     * Parse certificate.
     */
    Certificate(&cert, (unsigned short)0);      /* constructor */
    ret = get_casn_file(&cert.self, (char *)file, 0);
    if (ret < 0)
    {
        fprintf(stderr, "Could not open file: %s\n", file);
        return -2;
    }

    /*
     * Find or create SIA extension.
     */
    extp = find_extension(&cert.toBeSigned.extensions,
                          id_pe_subjectInfoAccess, false);
    if (!extp)
    {
        extp =
            make_extension(&cert.toBeSigned.extensions,
                          id_pe_subjectInfoAccess);
        if (!extp)
        {
            fprintf(stderr, "Could not create SIA extension.\n");
            return -3;
        }
    }
    siap = &extp->extnValue.subjectInfoAccess;

    /*
     * Optionally delete existing AccessDescriptions.
     */
    if (delete_existing)
    {
        clear_casn(&siap->self);        /* This messes up the "DEFINED BY"
                                         * flag, so we need to set it again in
                                         * the next line.  */
        if (write_objid(&extp->extnID, id_pe_subjectInfoAccess) < 0)
        {
            fprintf(stderr, "Error clearing existing URIs.\n");
            return -1;
        }
    }

    /*
     * For each AccessDescription request, insert it.
     */
    for (i = 0; i < num_sia_requests; i++)
    {
        int current_size;
        struct AccessDescription *adp;  /* ASN.1 AccessDescription pointer */

        /*
         * Append new entry.
         */
        current_size = num_items(&siap->self);
        adp =
            (struct AccessDescription *)inject_casn(&siap->self, current_size);
        if (!adp)
        {
            fprintf(stderr, "Error: failed to append access description.\n");
            return -1;
        }

        if (write_objid(&adp->accessMethod,
                        (char *)sia_requests[i].accessMethod) < 0)
        {
            fprintf(stderr, "Error: failed to set access method.\n");
            return -1;
        }

        if (write_casn(&adp->accessLocation.url,
                       (unsigned char *)sia_requests[i].accessLocation,
                       strlen(sia_requests[i].accessLocation)) < 0)
        {
            fprintf(stderr, "Error: failed to set access location.\n");
            return -1;
        }
    }

    /*
     * Check for non-empty SIA (RFC 5280)
     */
    if (num_items(&siap->self) == 0)
    {
        fprintf(stderr,
                "SIA must have at least one AccessDescription, per RFC5280.\n");
        return -1;
    }

    /*
     * Write to file.
     */
    if (put_casn_file(&cert.self, (char *)file, 0) < 0)
    {
        fprintf(stderr, "Error: failed to write %s\n", file);
        return -4;
    }

    /*
     * Clean up.
     */
    delete_casn(&cert.self);
    return 0;
}
Пример #17
0
static GimpPDBStatusType
save_image (const gchar *filename,
            gint32       image_ID,
            gint32       drawable_ID,
            gint32       run_mode)
{
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
  gchar             *ext;
  gchar             *tmpname;
  gchar             *mailcmd[3];
  GPid               mailpid;
  FILE              *mailpipe;
  GError            *error = NULL;

  ext = find_extension (filename);

  if (ext == NULL)
    return GIMP_PDB_CALLING_ERROR;

  /* get a temp name with the right extension and save into it. */
  tmpname = gimp_temp_name (ext + 1);

  /* construct the "sendmail user@location" line */
  mailcmd[0] = SENDMAIL;
  mailcmd[1] = mail_info.receipt;
  mailcmd[2] = NULL;

  /* create a pipe to sendmail */
  mailpipe = sendmail_pipe (mailcmd, &mailpid);

  if (mailpipe == NULL)
    return GIMP_PDB_EXECUTION_ERROR;

  create_headers (mailpipe);

  fflush (mailpipe);

  if (! (gimp_file_save (run_mode,
                         image_ID,
                         drawable_ID,
                         tmpname,
                         tmpname) && valid_file (tmpname)))
    {
      goto error;
    }

  if (! to64 (tmpname, mailpipe, &error))
    {
      g_message ("%s", error->message);
      g_error_free (error);
      goto error;
    }

  fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n");

  goto cleanup;

error:
  /* stop sendmail from doing anything */
  kill (mailpid, SIGINT);
  status = GIMP_PDB_EXECUTION_ERROR;

cleanup:
  /* close out the sendmail process */
  fclose (mailpipe);
  waitpid (mailpid, NULL, 0);
  g_spawn_close_pid (mailpid);

  /* delete the tmpfile that was generated */
  g_unlink (tmpname);
  g_free (tmpname);

  return status;
}
Пример #18
0
/*
 * ipv4 address are a comma separated list of either prefix or range
 * specifications for ipv4 addresses
 */
int write_cert_addrs(
    void *cert,
    void *val,
    int type)
{
    struct CertificateToBeSigned *tbsp =
        &((struct Certificate *)cert)->toBeSigned;
    struct Extension *extp;
    struct Extensions *extsp = &tbsp->extensions;
    struct IPAddressFamilyA *famp;
    char *ptr,
       *next,
       *buf;
    int ptr_len;
    char token = ',';
    char family[2];
    int num = 0;

    family[0] = 0;
    if (type == IPv4)
        family[1] = 1;
    else
        family[1] = 2;

    extp = find_extension(extsp, id_pe_ipAddrBlock, false);
    if (!extp)
    {
        extp = make_extension(extsp, id_pe_ipAddrBlock);
        write_casn_num(&extp->critical, 1);
    }

    if (type == IPv6)
        famp =
            (struct IPAddressFamilyA *)inject_casn(&extp->extnValue.
                                                   ipAddressBlock.self,
                                                   num_items(&extp->extnValue.
                                                             ipAddressBlock.
                                                             self));
    else
        famp =
            (struct IPAddressFamilyA *)inject_casn(&extp->extnValue.
                                                   ipAddressBlock.self, 0);

    write_casn(&famp->addressFamily, (unsigned char *)family, 2);

    // if it is inherit - set that and done
    if (strncmp(val, "inherit", strlen("inherit")) == 0)
    {
        struct IPAddressChoiceA *addrChoice = &famp->ipAddressChoice;
        write_casn(&addrChoice->inherit, (uchar *) "", 0);
        return SUCCESS;
    }

    // go through all addresses listed and add them to the block
    ptr = val;
    while (ptr != NULL)
    {
        next = strchr(ptr, token);
        while (isspace((int)(unsigned char)*ptr))
            ptr++;              // strip leading spaces
        if (next == NULL)
            ptr_len = strlen(ptr);
        else
        {
            ptr_len = (char *)next - (char *)ptr;
            next++;
        }
        if ((buf = strndup(ptr, ptr_len)) == NULL)
            return -1;

        if (write_family(famp, buf, num++) < 0)
            return -1;
        ptr = next;
    }

    return SUCCESS;
}
Пример #19
0
/**
 * cockpit_web_response_negotiation:
 * @path: likely filesystem path
 * @existing: a table of existing files
 * @chosen: out, a pointer to the suffix that was chosen
 * @error: a failure
 *
 * Find a file to serve based on the suffixes. We prune off extra
 * extensions while looking for a file that's present. We append
 * .min and .gz when looking for files. We also check for the language
 * before the extensions if set.
 *
 * The @existing may be NULL, if non-null it'll be used to check if
 * files exist.
 */
GBytes *
cockpit_web_response_negotiation (const gchar *path,
                                  GHashTable *existing,
                                  const gchar *language,
                                  gchar **actual,
                                  GError **error)
{
  gchar *base = NULL;
  const gchar *ext;
  gchar *dot;
  gchar *name = NULL;
  GBytes *bytes = NULL;
  GError *local_error = NULL;
  gint i;

  ext = find_extension (path);
  if (ext)
    {
      base = g_strndup (path, ext - path);
    }
  else
    {
      ext = "";
      base = g_strdup (path);
    }

  while (!bytes)
    {
      if (language)
        i = 0;
      else
        i = 2;
      for (; i < 6; i++)
        {
          g_free (name);
          switch (i)
            {
            case 0:
              name = g_strconcat (base, ".", language, ext, NULL);
              break;
            case 1:
              name = g_strconcat (base, ".", language, ext, ".gz", NULL);
              break;
            case 2:
              name = g_strconcat (base, ext, NULL);
              break;
            case 3:
              name = g_strconcat (base, ".min", ext, NULL);
              break;
            case 4:
              name = g_strconcat (base, ext, ".gz", NULL);
              break;
            case 5:
              name = g_strconcat (base, ".min", ext, ".gz", NULL);
              break;
            default:
              g_assert_not_reached ();
            }

          if (existing)
            {
              if (!g_hash_table_lookup (existing, name))
                continue;
            }

          bytes = load_file (name, &local_error);
          if (bytes)
            break;
          if (local_error)
            goto out;
        }

      /* Pop one level off the file name */
      dot = (gchar *)find_extension (base);
      if (!dot)
        break;

      dot[0] = '\0';
    }

out:
  if (local_error)
    g_propagate_error (error, local_error);
  if (bytes && name && actual)
    {
      *actual = name;
      name = NULL;
    }
  g_free (name);
  g_free (base);
  return bytes;
}
Пример #20
0
int main(
    int argc,
    char *argv[])
{
    int c = 0;                  /* command line option character */
    int option_dir = 0;         /* retrieve SIA directory URL */
    int option_mft = 0;         /* retrieve SIA manifest URL */
    const char *file = NULL;    /* certificate file */
    struct Certificate cert;    /* ASN.1 certificate object */
    struct Extension *extp;     /* ASN.1 X.509 extension pointer */
    struct SubjectInfoAccess *siap;     /* ASN.1 SIA pointer */
    struct AccessDescription *adp;      /* ASN.1 AccessDescription pointer */
    int ret;                    /* return value */

    /*
     * Parse command line arguments.
     */
    opterr = 0;
    while ((c = getopt(argc, argv, "dm")) != -1)
    {
        switch (c)
        {
        case 'd':
            option_dir = 1;
            break;
        case 'm':
            option_mft = 1;
            break;
        case '?':
            if (isprint(optopt))
                fprintf(stderr, "Unknown option `-%c'.\n", optopt);
            else
                fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
            usage(argc, argv);
            return -1;
        default:
            usage(argc, argv);
            return -1;
        }
    }
    /*
     * If no selection, default to directory.
     */
    if (option_dir == 0 && option_mft == 0)
        option_dir = 1;
    if (optind >= argc)
    {
        usage(argc, argv);
        return -1;
    }
    file = argv[optind];

    /*
     * Parse certificate.
     */
    Certificate(&cert, (unsigned short)0);      /* constructor */
    ret = get_casn_file(&cert.self, (char *)file, 0);
    if (ret < 0)
    {
        fprintf(stderr, "Could not open file: %s\n", file);
        return -2;
    }

    /*
     * Find SIA extension.
     */
    extp = find_extension(&cert.toBeSigned.extensions, id_pe_subjectInfoAccess, false);
    if (!extp)
    {
        fprintf(stderr, "Error: could not locate SIA extension.\n");
        return -3;
    }
    siap = &extp->extnValue.subjectInfoAccess;

    /*
     * For each AccessDescription, print the accessLocation URI if the
     * accessMethod matches the user requested SIA type: directory or
     * manifest.
     */
    for (adp = (struct AccessDescription *)member_casn(&siap->self, 0);
         adp != NULL; adp = (struct AccessDescription *)next_of(&adp->self))
    {
        char *rsync_uri = NULL;
        int len = 0;
        int print_this_one = 0;

        if (diff_objid(&adp->accessMethod, id_ad_rpkiManifest) == 0 &&
            option_mft)
        {
            /*
             * Manifest
             */
            print_this_one = 1;
        }
        else if (diff_objid(&adp->accessMethod, id_ad_caRepository) == 0 &&
                 option_dir)
        {
            /*
             * Directory
             */
            print_this_one = 1;
        }
        else if (diff_objid(&adp->accessMethod, id_ad_signedObject) == 0)
        {
            /*
             * Signed Object
             */
            print_this_one = 1;
        }

        if (!print_this_one)
            continue;

        /*
         * print manifest URI
         */
        len = vsize_casn(&adp->accessLocation.self);
        rsync_uri = (char *)calloc(len + 2, 1);
        if (!rsync_uri)
        {
            fprintf(stderr, "Memory allocation failure on %d bytes!\n",
                    len + 2);
            continue;
        }
        ret = read_casn(&adp->accessLocation.self, (unsigned char *)rsync_uri);
        if (ret < len)
        {
            fprintf(stderr, "Read failure: got %d, expected %d bytes\n", ret,
                    len);
        }
        else
        {
            printf("%s\n", rsync_uri);
        }
        free(rsync_uri);
    }

    /*
     * Clean up.
     */
    delete_casn(&cert.self);
    return 0;
}
Пример #21
0
//===========================================================================
bool cImageLoader::loadFromFile(const char* filename)
{
    // Sometimes we'll make a one-level recursive call into this
    // function; this is an extra safety check to avoid extra
    // recursion...
    static int recursive_call = 0;

    // cleanup previous image
    cleanup();

    strncpy(m_filename,filename,CHAI_SIZE_PATH);
    m_filename[CHAI_SIZE_PATH-1] = '\0';

    char* extension = find_extension(filename);

    // We need a file extension to figure out file type
    if (extension == 0)
    {
        cleanup();
        return (false);
    }

    char lower_extension[1024];
    string_tolower(lower_extension,extension);

    //--------------------------------------------------------------------
    // Load a .tga image
    //--------------------------------------------------------------------
    if (strcmp(lower_extension,"tga")==0)
    {
        cFileLoaderTGA targa_image;

        // Load the targa file from disk
        bool result = targa_image.LoadFromFile(m_filename);
        if (!result)
        {
            cleanup();

            // Try again using the windows native loader...
            result = loadFromFileOLE(filename);
            return (result);
        }

        m_width = targa_image.GetImageWidth();
        m_height = targa_image.GetImageHeight();

        // Find the correct openGL format for this .tga file
        GLenum format = (targa_image.GetImageType());

        if (format == itRGB)
        {
            m_bits_per_pixel = 24;
            m_format = GL_RGB;
        }

        else if (format == itRGBA)
        {
            m_bits_per_pixel = 32;
            m_format = GL_RGBA;
        }

        else
        {
            // Unrecognized format...
            cleanup();

            // Try again using the windows native loader...
            bool result = loadFromFileOLE(filename);
            return (result);
        }

        m_data = new unsigned char[m_width*m_height*(m_bits_per_pixel/8)];

        // Copy tga data into our internal data record
        memcpy(m_data,targa_image.GetPixels(),(m_bits_per_pixel/8)*m_width*m_height);
    }

    //--------------------------------------------------------------------
    // Load a .bmp image
    //--------------------------------------------------------------------
    else if (strcmp(lower_extension,"bmp")==0)
    {

        cFileLoaderBMP bmp_image;

        bool result = bmp_image.loadBMP(m_filename);
        if (!result)
        {
            cleanup();

            // Try again using the windows native loader...
            result = loadFromFileOLE(filename);
            return (result);
        }

        m_width = bmp_image.getWidth();
        m_height = bmp_image.getHeight();

        m_bits_per_pixel = 24;

        m_data = new unsigned char[m_width*m_height*(m_bits_per_pixel/8)];

        // Copy bmp data into our internal data record
        memcpy(m_data,bmp_image.pBitmap(),(m_bits_per_pixel/8)*m_width*m_height);
    }

#if defined(_WIN32)

    //--------------------------------------------------------------------
    // Unrecognized file format - use win32 loader
    //--------------------------------------------------------------------
    else
    {
        bool result = loadFromFileOLE(filename);
        return (result);
    }
      
#else

    //--------------------------------------------------------------------
    // Unrecognized file format an win32 not available - try again as a .bmp
    //--------------------------------------------------------------------
    else if (recursive_call == 0)
Пример #22
0
char *potion_find_file(char *str, PN_SIZE str_len)
{
	char *r = NULL;
	struct stat st;
	PN_TUPLE_EACH(pn_loader_path, i, prefix,
			{ PN_SIZE prefix_len = PN_STR_LEN(prefix); char dirname[prefix_len + 1 + str_len + 1]; char *str_pos = dirname + prefix_len + 1; char *dot; const char *ext; memcpy(str_pos, str, str_len); dot = memchr(str, '.', str_len); if (dot == NULL) dirname[sizeof(dirname) - 1] = '\0'; else *dot = '\0'; memcpy(dirname, PN_STR_PTR(prefix), prefix_len); dirname[prefix_len] = '/'; if (stat(dirname, &st) == 0 && S_ISREG(st.st_mode)) { if (asprintf(&r, "%s", dirname) == -1) potion_allocation_error(); break; } else if ((ext = find_extension(dirname)) != NULL) { if (asprintf(&r, "%s%s", dirname, ext) == -1) potion_allocation_error(); break; } else { char *file; if ((file = strrchr(str, '/')) == NULL) file = str; else file++; if (asprintf(&r, "%s/%s", dirname, file) == -1) potion_allocation_error(); if (stat(r, &st) != 0 || !S_ISREG(st.st_mode)) { int r_len = prefix_len + 1 + str_len * 2 + 1; if ((ext = find_extension(r)) == NULL) { free(r); r = NULL; continue; } r = realloc(r, r_len + strlen(ext)); if (r == NULL) potion_allocation_error(); strcpy(r + r_len, ext); } break; } });