Пример #1
0
bool CFileHashSet::SetHashSet(const QList<QByteArray>& HashSet)
{
	ASSERT(!CanHashParts());
	if(HashSet.size() != GetPartCount() || HashSet.isEmpty() || HashSet.at(0).size() != m_uSize)
	{
		ASSERT(0);
		return false;
	}

	m_HashSet.reserve(HashSet.size());
	foreach(const QByteArray& Hash, HashSet)
	{
		byte* pHash = (byte*)hash_malloc(m_uSize);
		memcpy(pHash,Hash.data(),m_uSize);

		QWriteLocker Locker(&m_SetMutex);
		m_HashSet.append(pHash);
	}
Пример #2
0
WIN32DLL_DEFINE
void *mhash_hmac_end_m(MHASH td, void *(*hash_malloc) (mutils_word32))
{
    void *digest;

    digest =
        hash_malloc(mhash_get_block_size
                    (td->algorithm_given));

    if (digest == NULL)
    {
        return(NULL);
    }

    mhash_hmac_deinit(td, digest);

    return(digest);
}
Пример #3
0
int
main (int argc, char **argv)
{
#define BUFSIZE 8192
  char *host, *user, *domain, *key;
  char buffer[BUFSIZE + 1];
  int hosts;
  hash_t *work
   ;
#ifdef DEBUG_NETGROUP
  FILE *debug_file = NULL;
#endif

  /* Only -u or -h are allowed, --version will exit the program */
  /* --users = -u, --hosts = -h */
  hosts = -1;

  if (argc < 2)
    usage (1);

  while (1)
    {
      int c;
      int option_index = 0;
      static struct option long_options[] =
      {
	{"version", no_argument, NULL, '\255'},
	{"hosts", no_argument, NULL, 'h'},
	{"users", no_argument, NULL, 'u'},
	{"help", no_argument, NULL, '\254'},
	{"usage", no_argument, NULL, '\254'},
	{NULL, 0, NULL, '\0'}
      };

      c = getopt_long (argc, argv, "uh", long_options, &option_index);
      if (c == EOF)
	break;
      switch (c)
	{
	case 'u':
	  hosts = PARSE_FOR_USERS;
	  break;
	case 'h':
	  hosts = PARSE_FOR_HOSTS;
	  break;
	case '\255':
          printf ("revnetgroup (%s) %s", PACKAGE, VERSION);
	  exit (0);
	case '\254':
	  usage (0);
	  break;
	default:
	  usage (1);
	  break;
	}
    }

#ifdef DEBUG_NETGROUP
  debug_file = fopen ("/etc/netgroup", "rt");
  if (debug_file == NULL)
    {
      perror ("Error: could not open /etc/netgroup:");
      exit (0);
    }
#endif

  /* Put the netgroup names in a list: */

#ifdef DEBUG_NETGROUP
  while (fgets (buffer, BUFSIZE, debug_file))
#else
  while (fgets (buffer, BUFSIZE, stdin))
#endif
    {
      char *val;
      char *cptr;

      if (buffer[0] == '#')
	continue;

      if (strlen (buffer) == 0)
	continue;

      /* Replace first '\n' with '\0' */
      if ((cptr = strchr (buffer, '\n')) != NULL)
	*cptr = '\0';

      while (buffer[strlen (buffer) - 1] == '\\')
	{
	  char *s;
#ifdef DEBUG_NETGROUP
	  s = fgets (&buffer[strlen (buffer) - 1],
		     BUFSIZE - strlen (buffer), debug_file);
#else
	  s = fgets (&buffer[strlen (buffer) - 1],
		     BUFSIZE - strlen (buffer), stdin);
#endif
	  if (s == NULL)
	    continue;
	  if ((cptr = strchr (buffer, '\n')) != NULL)
	    *cptr = '\0';
	}

      val = (char *) (strpbrk (buffer, " \t"));
      if (val == NULL)
	continue;
      key = (char *) &buffer;
      *val = '\0';
      val++;
      insert_netgroup (&input, key, val);
#ifdef DEBUG_NETGROUP
      fprintf (stderr, "KEY: [%s]\n", key);
#endif
    }

#ifdef DEBUG_NETGROUP
  fclose (debug_file);
#endif


#ifdef DEBUG_NETGROUP
  fprintf (stderr, "About to enter while loop...\n");
#endif

  /*
   * Find all members of each netgroup and keep track of which
   * group they belong to.
   */
  empty = hash_malloc ();
  output = hash_malloc ();
  work = input;
  while (work != NULL)
    {
      rev_setnetgrent (work->key);

#ifdef DEBUG_NETGROUP
      fprintf (stderr, "Processing: [%s]\n", work->key);
#endif

      while (rev_getnetgrent (&host, &user, &domain) != 0)
	{
	  static char star[] = "*";
	  char *key = NULL;
	  char *dat = NULL;

	  /* what are we processing for? */
	  if (hosts == PARSE_FOR_HOSTS)
	    dat = host;
	  else
	    dat = user;

	  /* empty fields are wildcard fields = use '-'
	   * to prevent entries
	   */
	  if (dat == NULL)
	    dat = star;

	  /* if we have an entry with data... */
	  if (dat[0] != '-')
	    {
	      /* create the dat/domain key */
	      if (domain == NULL)
		{
		  key = malloc (strlen (dat) + 3);
		  sprintf (key, "%s.*", dat);
		}
	      else
		{
		  key = malloc (strlen (dat) + strlen (domain) + 2);
		  sprintf (key, "%s.%s", dat, domain);
		}

	      /* if we have a wildcard search */
	      if (*dat == '*')
		{
		  char *val = hash_search (empty, key);

		  if (val != NULL)
		    {
		      char *buf = NULL;
		      char *buf2 = NULL;
		      int found = 0;

		      buf2 = malloc (strlen (val) + 2);
		      sprintf (buf2, "%s,", val);
		      buf = strtok (buf2, ",");

		      while ((buf != NULL) && (found == 0))
			{
			  found = (strcmp (buf, work->key) == 0);
			  buf = strtok (NULL, ",");
			}

		      free (buf2);

		      if (!found)
			{
			  buf = malloc (strlen (work->key) + strlen (val) + 2);
			  sprintf (buf, "%s,%s", val, work->key);
			  hash_delkey (empty, key);
			  hash_insert (empty, key, buf);
			  free (buf);
			}
		    }
		  else
		    {
		      hash_insert (empty, key, work->key);
		    }
		}
	      else
		{
		  /* non-wild card search */
		  char *val = hash_search (output, key);

		  if (val != NULL)
		    {
		      char *buf = NULL;
		      char *buf2 = NULL;
		      int found = 0;

		      buf2 = malloc (strlen (val) + 2);
		      sprintf (buf2, "%s,", val);
		      buf = strtok (buf2, ",");

		      while ((buf != NULL) && (found == 0))
			{
			  found = (strcmp (buf, work->key) == 0);
			  buf = strtok (NULL, ",");
			}

		      free (buf2);

		      if (!found)
			{
			  buf = malloc (strlen (work->key) + strlen (val) + 2);
			  sprintf (buf, "%s,%s", val, work->key);
			  hash_delkey (output, key);

			  hash_insert (output, key, buf);
			  free (buf);
			}
		    }
		  else
		    {
		      hash_insert (output, key, work->key);
		    }
		}

	      free (key);
	    }
	}
      work = work->next;
      /* Release resources used by the getnetgrent code. */
      rev_endnetgrent ();
    }

#ifdef DEBUG_NETGROUP
  fprintf (stderr, "About to print results...\n");
#endif

  /* Print the results. */
  work = hash_first (output);
  while (work != NULL)
    {
      printf ("%s\t%s\n", work->key, work->val);
      work = hash_next (output, work->key);
    }

  work = hash_first (empty);
  while (work != NULL)
    {
      printf ("%s\t%s\n", work->key, work->val);
      work = hash_next (empty, work->key);
    }

#if 0
  remove_netgroup (&input);
  remove_netgroup (&output);
  remove_netgroup (&empty);
#endif

  return 0;
}
Пример #4
0
rt_public EIF_REFERENCE edclone(EIF_CONTEXT EIF_REFERENCE source)
{
    /* Recursive Eiffel clone. This function recursively clones the source
     * object and returns a pointer to the top of the new tree.
     */
    RT_GET_CONTEXT
    EIF_GET_CONTEXT
    EIF_REFERENCE root = (EIF_REFERENCE)  0;		/* Root of the deep cloned object */
    jmp_buf exenv;					/* Environment saving */
    struct {
        union overhead discard;		/* Pseudo object header */
        EIF_REFERENCE boot;					/* Anchor point for cloning process */
    } anchor;
    struct rt_traversal_context traversal_context;
    int volatile is_locked;

#ifdef DEBUG
    int xobjs;
#endif

    if (source == NULL) {
        return NULL;			/* Void source */
    }

    /* The deep clone of the source will be attached in the 'boot' entry from
     * the anchor structure. It all happens as if we were in fact deep cloning
     * the anchor pseudo-object.
     */

    memset (&anchor, 0, sizeof(anchor));	/* Reset header */
    anchor.boot = (EIF_REFERENCE)  &root;	/* To boostrap cloning process */

    RT_GC_PROTECT(source);	/* Protect source: allocation will occur */

#ifdef DEBUG
    xobjs = nomark(source);
    printf("Source has %x %d objects\n", source, xobjs);
#endif

    /* Set up an exception trap. If any exception occurs, control will be
     * transferred back here by the run-time to give us a chance to clean-up
     * our structures.
     */

    {
        RTXDRH;							/* Save stack contexts */
        EIF_EO_STORE_LOCK;				/* Because we perform a traversal that marks
										   objects, we need to be sure we are the
										   only one doing it. */
        is_locked = 1;

        excatch(&exenv);		/* Record pseudo-execution vector */
        if (setjmp(exenv)) {
            RTXSCH;						/* Restore stack contexts */
            map_reset(1);				/* Reset in emergency situation */
            /* If we locked the EO_STORE_MUTEX, then we need to unmark objects
             * and unlock it. */
            if (is_locked) {
                /* We are only concerned abount unmarking objects, so we do not perform any
                 * accounting. */
                CHECK ("Not accounting", traversal_context.accounting == 0);
                CHECK ("Not unmarking", traversal_context.is_unmarking == 0);
                /* First we mark again all objects. */
                traversal_context.is_unmarking = 0;
                traversal(&traversal_context, source);
                /* Then we unmark them. */
                traversal_context.is_unmarking = 1;
                traversal(&traversal_context, source);
                /* Now we can unlock our mutex. */
                EIF_EO_STORE_UNLOCK;
            }
            ereturn(MTC_NOARG);					/* And propagate the exception */
        }

        /* Now start the traversal of the source, allocating all the objects as
         * needed and stuffing them into a FIFO stack for later perusal by the
         * cloning process.
         */

        memset (&traversal_context, 0, sizeof(struct rt_traversal_context));
        traversal_context.accounting = TR_MAP;
        traversal(&traversal_context, source);		/* Object traversal, mark with EO_STORE */
        hash_malloc(&hclone, traversal_context.obj_nb);	/* Hash table allocation */
        map_start();					/* Restart at bottom of FIFO stack */

#ifdef DEBUG
        printf("Computed %x %d objects\n\n", source, traversal_context.obj_nb);
#endif

        /* Throughout the deep cloning process, we need to maintain the notion of
         * enclosing object for GC aging tests. The enclosing object is defined as
         * being the object to which the currently cloned tree will be attached.
         *
         * We need to initialize the cloning process by computing a valid reference
         * into the root variable. That will be the enclosing object, and of course
         * it cannot be void, ever, or something really really weird is happening.
         *
         * To get rid of code duplication, I am initially calling rdeepclone with
         * an enclosing object address set to anchor.boot. The anchor structure
         * represents a pseudo anchor object for the object hierarchy being cloned.
         */

        rdeepclone(source, (EIF_REFERENCE) &anchor.boot, 0);	/* Recursive clone */
        hash_free(&hclone);						/* Free hash table */
        map_reset(0);							/* And eif_free maping table */
        /* Release all the hector pointers asked for during the map table
         * construction (obj_nb exactly) */
        CHECK("Has objects", traversal_context.obj_nb > 0);
        eif_ostack_npop(&hec_stack, traversal_context.obj_nb);

#ifdef DEBUG
        xobjs= nomark(source);
        printf("Source now has %d objects\n", xobjs);
        xobjs = nomark(anchor.boot);
        printf("Result has %d objects\n", xobjs);
#endif

        RT_GC_WEAN(source);			/* Release GC protection */
        expop(&eif_stack);			/* Remove pseudo execution vector */
    }

    EIF_EO_STORE_UNLOCK;		/* Free marking mutex */
    is_locked = 0;

    return anchor.boot;			/* The cloned object tree */
}