int OBJ_NAME_add(const char *name, int type, const char *data)
	{
	OBJ_NAME *onp,*ret;
	int alias;

	if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);

	alias=type&OBJ_NAME_ALIAS;
	type&= ~OBJ_NAME_ALIAS;

	onp=(OBJ_NAME *)OPENSSL_malloc(sizeof(OBJ_NAME));
	if (onp == NULL)
		{
		/* ERROR */
		return(0);
		}

	onp->name=name;
	onp->alias=alias;
	onp->type=type;
	onp->data=data;

	ret=(OBJ_NAME *)lh_insert(names_lh,onp);
	if (ret != NULL)
		{
		/* free things */
		if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type))
			{
			/* XXX: I'm not sure I understand why the free
			 * function should get three arguments...
			 * -- Richard Levitte
			 */
			sk_NAME_FUNCS_value(name_funcs_stack,ret->type)
				->free_func(ret->name,ret->type,ret->data);
			}
		OPENSSL_free(ret);
		}
	else
		{
		if (lh_error(names_lh))
			{
			/* ERROR */
			return(0);
			}
		}
	return(1);
	}
Exemple #2
0
int lh_lf(char *args)
{
  int rc = err_out_of_memory;
  char *fullname, *fnam;

  assert(args);


    if (initialise() == OK)
    {
      if ((rc = parseArgs(args, &fnam, &args)) == OK)
      {
        /* command line was OK - try to find the file */

        fullname = find_which(fnam);
      free(fnam);

        if (fullname)
        {
          /* a file was found - allocate the memory */
          if (loadfix_flag)
            rc = loadfix_prepare();
          else
            rc = loadhigh_prepare();

          /* finally, execute the file */
          if (!rc)
            rc = exec(fullname, args, 0);

        }
        else
          rc = err_file_not_found;

      }
    }
    cleanup();

  /* if any error occurred, rc will hold the error code */
  if (rc)
    lh_error(rc);

  return rc;
}
Exemple #3
0
/*
 * Store a pathname in the pathname store.
 */
char*
Pathstore_path(Pathstore *store, char *pathname, int discardDuplicateFiles)
{
	char chksum1[CHKSUMFILE_SIZE];
	struct unixfilesystem *fs = (struct unixfilesystem *) (store->fshandle);

	numstores++;
	
	PathstoreElement *entry;
	
	/* For 1 file case
	 * No hash table or checksum 
	 */
	if(numfilesseen == 0){
		numfilesseen++;
		entry = malloc(sizeof(PathstoreElement));;
	    entry->pathname = strdup(pathname);
		if (entry->pathname == NULL) {
		  	free(entry);
			printf("memory problem 2\n");
		  	return NULL;
		}
		store->elementList = entry;
		return entry->pathname;
	}
	
	/* For >1 file
	 * Use hash table and checksums
	 */
	_LHASH *hashtable;
	
	// if we are going from 1 file case to 2 files
	if(numfilesseen == 1){
		numfilesseen++;
		//store first entry somewhere
		PathstoreElement *temp = store->elementList;
		//calc checksum for file 1 path
		int err = chksumfile_bypathname(fs, temp->pathname, chksum1);
		if (err < 0) {
	    	fprintf(stderr,"Can't checksum path %s\n", pathname);
		    return 0;
	 	}
		memcpy(temp->chksum, chksum1, CHKSUMFILE_SIZE);
		//initialize hash table
		store->elementList = lh_new(HashCallback, CompareCallback);
		hashtable = (_LHASH*) (store->elementList);
		//seed hash table with first entry
		lh_insert(hashtable,(char *) temp);
	    if (lh_error(hashtable)) {
	    	free(temp);
			printf("hash problem\n");
	    	return NULL;
	    }
	}else{
		hashtable = (_LHASH*) (store->elementList);
	}
	// calc checksum of pathname
	int err = chksumfile_bypathname(fs, pathname, chksum1);
	if (err < 0) {
    	fprintf(stderr,"Can't checksum path %s\n", pathname);
	    return 0;
 	}	

	PathstoreElement key;
	memcpy(key.chksum, chksum1, CHKSUMFILE_SIZE);	
	
	// if discardDups, see if its in table, if it is, return
	if (discardDuplicateFiles) {
		entry = lh_retrieve(hashtable, (char *) &key);
		if(entry != NULL){
			numdups++;
			return NULL;
		}
	}
	
	// otherwise add
	entry = malloc(sizeof(PathstoreElement));
    if (entry == NULL) {
		printf("memory problem\n");
      	return NULL;
    }
	memcpy(entry->chksum, chksum1, CHKSUMFILE_SIZE);
    entry->pathname = strdup(pathname);
	if (entry->pathname == NULL) {
	  	free(entry);
		printf("memory problem 2\n");
	  	return NULL;
	}

    lh_insert(hashtable,(char *) entry);

    if (lh_error(hashtable)) {
    	free(entry);
		printf("hash problem\n");
    	return NULL;
    }
  
	return entry->pathname;
}