Exemplo n.º 1
0
/*
 * Allocate or resize memory previously allocated.
 *
 * sr	If not NULL, request the memory is associated with.
 *
 * ptr	Memory address
 *
 * size	New size
 *
 * zero	If true zero out the extra space or the truncated space.
 */
static void *
smb_realloc(smb_request_t *sr, void *ptr, size_t size, boolean_t zero)
{
	smb_mem_header_t	*smh;
	void			*new_ptr;

	if (ptr == NULL)
		return (smb_alloc(sr, size, zero));

	smh = SMB_MEM2SMH(ptr);
	SMB_SMH_VALID(smh);
	ASSERT(sr == smh->smh_sr);

	if (size == 0) {
		smb_free(sr, ptr, zero);
		return (NULL);
	}
	if (smh->smh_size >= size) {
		if ((zero) & (smh->smh_size > size))
			bzero((caddr_t)ptr + size, smh->smh_size - size);
		return (ptr);
	}
	new_ptr = smb_alloc(sr, size, B_FALSE);
	bcopy(ptr, new_ptr, smh->smh_size);
	if (zero)
		bzero((caddr_t)new_ptr + smh->smh_size, size - smh->smh_size);

	smb_free(sr, ptr, zero);
	return (new_ptr);
}
Exemplo n.º 2
0
/**
   @brief Expand the hash table, adding increment to the capacity of the table.

   @param table The table to expand.
 */
void ht_resize(smb_ht *table)
{
  smb_ht_bckt *old_table;
  unsigned int index, old_allocated;

  // Step one: allocate new space for the table
  old_table = table->table;
  old_allocated = table->allocated;
  table->length = 0;
  table->allocated = ht_next_size(old_allocated);
  table->table = smb_new(smb_ht_bckt, table->allocated);

  // Zero out the new block too.
  memset((void*)table->table, 0, table->allocated * sizeof(smb_ht_bckt));

  // Step two, add the old items to the new table.
  for (index = 0; index < old_allocated; index++) {
    if (old_table[index].mark == HT_FULL) {
      ht_insert(table, old_table[index].key, old_table[index].value);
    }
  }

  // Step three: free old data.
  smb_free(old_table);
}
Exemplo n.º 3
0
void su_delete_group(smb_ut_group *group)
{
  for (int i = 0; i < group->num_tests; i++) {
    if (group->tests[i]) // don't delete if already deleted
      su_delete_test(group->tests[i]);
  }
  smb_free(group);
}
Exemplo n.º 4
0
/*
 * Free everything on the request-specific temporary storage list and destroy
 * the list.
 */
void
smb_srm_fini(smb_request_t *sr)
{
	smb_mem_header_t	*smh;

	while ((smh = list_head(&sr->sr_storage)) != NULL)
		smb_free(sr, ++smh, B_FALSE);
	list_destroy(&sr->sr_storage);
}
Exemplo n.º 5
0
void ht_delete_act(smb_ht *table, DATA_ACTION deleter)
{
  if (!table) {
    return;
  }

  ht_destroy_act(table, deleter);
  smb_free(table);
}
Exemplo n.º 6
0
static smbios_hdl_t *
smb_biosopen(int fd, int version, int flags, int *errp)
{
	smbios_entry_t *ep = alloca(SMB_ENTRY_MAXLEN);
	smbios_hdl_t *shp = NULL;
	size_t pgsize, pgmask, pgoff;
	void *stbuf, *bios, *p, *q;

	bios = mmap(NULL, SMB_RANGE_LIMIT - SMB_RANGE_START + 1,
	    PROT_READ, MAP_SHARED, fd, (uint32_t)SMB_RANGE_START);

	if (bios == MAP_FAILED)
		return (smb_open_error(shp, errp, ESMB_MAPDEV));

	q = (void *)((uintptr_t)bios + SMB_RANGE_LIMIT - SMB_RANGE_START + 1);

	for (p = bios; p < q; p = (void *)((uintptr_t)p + 16)) {
		if (strncmp(p, SMB_ENTRY_EANCHOR, SMB_ENTRY_EANCHORLEN) == 0)
			break;
	}

	if (p >= q) {
		(void) munmap(bios, SMB_RANGE_LIMIT - SMB_RANGE_START + 1);
		return (smb_open_error(NULL, errp, ESMB_NOTFOUND));
	}

	bcopy(p, ep, sizeof (smbios_entry_t));
	ep->smbe_elen = MIN(ep->smbe_elen, SMB_ENTRY_MAXLEN);
	bcopy(p, ep, ep->smbe_elen);
	(void) munmap(bios, SMB_RANGE_LIMIT - SMB_RANGE_START + 1);

	pgsize = getpagesize();
	pgmask = ~(pgsize - 1);
	pgoff = ep->smbe_staddr & ~pgmask;

	bios = mmap(NULL, ep->smbe_stlen + pgoff,
	    PROT_READ, MAP_SHARED, fd, ep->smbe_staddr & pgmask);

	if (bios == MAP_FAILED)
		return (smb_open_error(shp, errp, ESMB_MAPDEV));

	if ((stbuf = smb_alloc(ep->smbe_stlen)) == NULL) {
		(void) munmap(bios, ep->smbe_stlen + pgoff);
		return (smb_open_error(shp, errp, ESMB_NOMEM));
	}

	bcopy((char *)bios + pgoff, stbuf, ep->smbe_stlen);
	(void) munmap(bios, ep->smbe_stlen + pgoff);
	shp = smbios_bufopen(ep, stbuf, ep->smbe_stlen, version, flags, errp);

	if (shp != NULL)
		shp->sh_flags |= SMB_FL_BUFALLOC;
	else
		smb_free(stbuf, ep->smbe_stlen);

	return (shp);
}
Exemplo n.º 7
0
void
smbios_close(smbios_hdl_t *shp)
{
	const smbios_entry_t *ep = &shp->sh_ent;
	uint_t i;

	for (i = 0; i < shp->sh_nstructs; i++) {
		smb_free(shp->sh_structs[i].smbst_strtab,
		    sizeof (uint16_t) * shp->sh_structs[i].smbst_strtablen);
	}

	smb_free(shp->sh_structs, sizeof (smb_struct_t) * ep->smbe_stnum);
	smb_free(shp->sh_hash, sizeof (smb_struct_t *) * shp->sh_hashlen);

	if (shp->sh_flags & SMB_FL_BUFALLOC)
		smb_free((void *)shp->sh_buf, shp->sh_buflen);

	smb_free(shp, sizeof (smbios_hdl_t));
}
Exemplo n.º 8
0
void run_cbot_cli(int argc, char **argv)
{
  char *line, *plugin_dir="bin/release/plugin";
  char *hash = NULL;
  cbot_t *bot;
  smb_ad args;
  arg_data_init(&args);

  process_args(&args, argc, argv);
  if (check_long_flag(&args, "name")) {
    name = get_long_flag_parameter(&args, "name");
  }
  if (check_long_flag(&args, "plugin-dir")) {
    plugin_dir = get_long_flag_parameter(&args, "plugin-dir");
  }
  if (check_long_flag(&args, "hash")) {
    hash = get_long_flag_parameter(&args, "hash");
  }
  if (check_long_flag(&args, "help")) {
    help();
  }
  if (!(name && plugin_dir)) {
    help();
  }
  if (!hash) {
    help();
  }

  bot = cbot_create("cbot");
  bot->actions.send = cbot_cli_send;
  bot->actions.me = cbot_cli_me;
  bot->actions.op = cbot_cli_op;
  bot->actions.join = cbot_cli_join;

  // Set the hash in the bot.
  void *decoded = base64_decode(hash, 20);
  memcpy(bot->hash, decoded, 20);
  free(decoded);

  cbot_load_plugins(bot, plugin_dir, ll_get_iter(args.bare_strings));
  while (!feof(stdin)) {
    printf("> ");
    line = read_line(stdin);
    cbot_handle_channel_message(bot, "stdin", "shell", line);
    smb_free(line);
  }

  arg_data_destroy(&args);
  cbot_delete(bot);
}
Exemplo n.º 9
0
static smbios_hdl_t *
smb_fileopen(int fd, int version, int flags, int *errp)
{
	smbios_entry_t *ep = alloca(SMB_ENTRY_MAXLEN);
	smbios_hdl_t *shp = NULL;
	ssize_t n, elen;
	void *stbuf;

	if ((n = pread64(fd, ep, sizeof (*ep), 0)) != sizeof (*ep))
		return (smb_open_error(shp, errp, n < 0 ? errno : ESMB_NOHDR));

	if (strncmp(ep->smbe_eanchor, SMB_ENTRY_EANCHOR, SMB_ENTRY_EANCHORLEN))
		return (smb_open_error(shp, errp, ESMB_HEADER));

	elen = MIN(ep->smbe_elen, SMB_ENTRY_MAXLEN);

	if ((n = pread64(fd, ep, elen, 0)) != elen)
		return (smb_open_error(shp, errp, n < 0 ? errno : ESMB_NOHDR));

	if ((stbuf = smb_alloc(ep->smbe_stlen)) == NULL)
		return (smb_open_error(shp, errp, ESMB_NOMEM));

	if ((n = pread64(fd, stbuf, ep->smbe_stlen,
	    (off64_t)ep->smbe_staddr)) != ep->smbe_stlen) {
		smb_free(stbuf, ep->smbe_stlen);
		return (smb_open_error(shp, errp, n < 0 ? errno : ESMB_NOSTAB));
	}

	shp = smbios_bufopen(ep, stbuf, ep->smbe_stlen, version, flags, errp);

	if (shp != NULL)
		shp->sh_flags |= SMB_FL_BUFALLOC;
	else
		smb_free(stbuf, ep->smbe_stlen);

	return (shp);
}
Exemplo n.º 10
0
/**
   @brief Removes the given node, reassigning the links to and from it.

   Frees the node, in addition no reassigning links.  Once this function is
   called, the_node is invlidated.  Please note that this function *does not*
   decrement the list's length!

   This function is a *private* function, not declared in libstephen.h for a
   reason.  It is only necessary for the implementation functions within this
   file.

   @param list The list that contains this node.
   @param the_node The node to delete.
 */
void ll_remove_node(smb_ll *list, smb_ll_node *the_node)
{
  smb_ll_node *previous = the_node->prev;
  smb_ll_node *next = the_node->next;
  if (previous) {
    previous->next = next;
  } else {
    list->head = next;
  }
  if (next) {
    next->prev = previous;
  } else {
    list->tail = previous;
  }
  smb_free(the_node);
}
Exemplo n.º 11
0
void ht_destroy_act(smb_ht *table, DATA_ACTION deleter)
{
  unsigned int i;

  // Do the action on all the items in the table, if provided.
  if (deleter) {
    for (i = 0; i < table->allocated; i++) {
      if (table->table[i].mark == HT_FULL) {
        deleter(table->table[i].value);
      }
    }
  }

  // Delete the table.
  smb_free(table->table);
}
Exemplo n.º 12
0
/**
   @brief Free the iterator and its resources.
   @param iter A pointer to the iterator
   @param free_src Whether to free the source list.
 */
void ll_iter_delete(smb_iter *iter)
{
  iter->destroy(iter);
  smb_free(iter);
}
Exemplo n.º 13
0
void ll_delete(smb_ll *list)
{
  ll_destroy(list);
  smb_free(list);
}
Exemplo n.º 14
0
/*
 * Free memory previously allocated with smb_malloc(), smb_zalloc(),
 * smb_remalloc() or smb_rezalloc().
 */
void
smb_mem_free(void *ptr)
{
	smb_free(NULL, ptr, B_FALSE);
}
Exemplo n.º 15
0
void al_destroy(smb_al *list)
{
  smb_free(list->data);
}
Exemplo n.º 16
0
/*
 * Free memory previously allocated with smb_mem_malloc(), smb_mem_zalloc(),
 * smb_mem_remalloc() or smb_mem_rezalloc() or smb_mem_strdup(). The memory will
 * be zeroed out before being actually freed.
 */
void
smb_mem_zfree(void *ptr)
{
	smb_free(NULL, ptr, B_TRUE);
}
Exemplo n.º 17
0
void al_delete(smb_al *list)
{
  al_destroy(list);
  smb_free(list);
}
Exemplo n.º 18
0
void su_delete_test(smb_ut_test *test)
{
  smb_free(test);
}