Пример #1
0
static char *
get_username_from_passwd_file (void *ctx)
{
    long pw_buf_size;
    char *pw_buf;
    struct passwd passwd, *ignored;
    char *name;
    int e;

    pw_buf_size = sysconf(_SC_GETPW_R_SIZE_MAX);
    if (pw_buf_size == -1) pw_buf_size = 64;
    pw_buf = talloc_zero_size (ctx, pw_buf_size);

    while ((e = getpwuid_r (getuid (), &passwd, pw_buf,
                            pw_buf_size, &ignored)) == ERANGE) {
        pw_buf_size = pw_buf_size * 2;
        pw_buf = talloc_zero_size(ctx, pw_buf_size);
    }

    if (e == 0)
	name = talloc_strdup (ctx, passwd.pw_name);
    else
	name = talloc_strdup (ctx, "");

    talloc_free (pw_buf);

    return name;
}
Пример #2
0
/* Expand a packet using V.42bis data compression */
static int v42bis_expand_unitdata(uint8_t *data, unsigned int len,
				  uint8_t pcomp_index, v42bis_state_t *comp)
{
	/* Note: This implementation may only be used to compress SN_UNITDATA
	 * packets, since it resets the compression state for each NPDU. */

	int rc;
	struct v42bis_output_buffer uncompressed_data;
	uint8_t *data_i;

	/* Skip when the packet is marked as uncompressed */
	if (pcomp_index == 0) {
		return len;
	}

	/* Reset V.42bis compression state */
	v42bis_reset(comp);

	/* Decompress packet */
	data_i = talloc_zero_size(comp, len);
	memcpy(data_i, data, len);
	uncompressed_data.buf = data;
	uncompressed_data.buf_pointer = data;
	uncompressed_data.len = 0;
	comp->decompress.user_data = (&uncompressed_data);
	rc = v42bis_decompress(comp, data_i, len);
	talloc_free(data_i);
	if (rc < 0)
		return -EINVAL;
	rc = v42bis_decompress_flush(comp);
	if (rc < 0)
		return -EINVAL;

	return uncompressed_data.len;
}
Пример #3
0
static bool wrap_ndr_inout_pull_test(struct torture_context *tctx,
				     struct torture_tcase *tcase,
				     struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	void *ds = talloc_zero_size(tctx, data->struct_size);
	struct ndr_pull *ndr;
	uint32_t highest_ofs;

	/* handle NDR_IN context */

	ndr = ndr_pull_init_blob(&(data->data_context), tctx);
	torture_assert(tctx, ndr, "ndr init failed");

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx,
		data->pull_fn(ndr, NDR_IN, ds),
		"ndr pull of context failed");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
		talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - highest_ofs));

	talloc_free(ndr);

	/* handle NDR_OUT */

	ndr = ndr_pull_init_blob(&(data->data), tctx);
	torture_assert(tctx, ndr, "ndr init failed");

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx,
		data->pull_fn(ndr, NDR_OUT, ds),
		"ndr pull failed");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
		talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - highest_ofs));

	talloc_free(ndr);

	if (check_fn) {
		return check_fn(tctx, ds);
	} else {
		return true;
	}
}
Пример #4
0
// return 1 on success, 0 if disabled, -1 on error
int stream_file_cache_init(stream_t *cache, stream_t *stream,
                           struct mp_cache_opts *opts)
{
    if (!opts->file || !opts->file[0] || opts->file_max < 1)
        return 0;

    FILE *file = fopen(opts->file, "wb+");
    if (!file) {
        MP_ERR(cache, "can't open cache file '%s'\n", opts->file);
        return -1;
    }

    struct priv *p = talloc_zero(NULL, struct priv);

    cache->priv = p;
    p->original = stream;
    p->cache_file = file;
    p->max_size = opts->file_max * 1024LL;

    // file_max can be INT_MAX, so this is at most about 256MB
    p->block_bits = talloc_zero_size(p, (p->max_size / BLOCK_SIZE + 1) / 8 + 1);

    cache->seek = seek;
    cache->fill_buffer = fill_buffer;
    cache->control = control;
    cache->close = s_close;

    return 1;
}
Пример #5
0
static AudioChannelLayout* ca_query_stereo_layout(struct ao *ao,
                                                  AudioDeviceID device,
                                                  void *talloc_ctx)
{
    OSStatus err;
    const int nch = 2;
    uint32_t channels[nch];
    AudioChannelLayout *r = NULL;

    AudioObjectPropertyAddress p_addr = (AudioObjectPropertyAddress) {
        .mSelector = kAudioDevicePropertyPreferredChannelsForStereo,
        .mScope    = kAudioDevicePropertyScopeOutput,
        .mElement  = kAudioObjectPropertyElementWildcard,
    };

    uint32_t psize = sizeof(channels);
    err = AudioObjectGetPropertyData(device, &p_addr, 0, NULL, &psize, channels);
    CHECK_CA_ERROR("could not get device preferred stereo layout");

    psize = sizeof(AudioChannelLayout) + nch * sizeof(AudioChannelDescription);
    r = talloc_zero_size(talloc_ctx, psize);
    r->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
    r->mNumberChannelDescriptions = nch;

    AudioChannelDescription desc = {0};
    desc.mChannelFlags = kAudioChannelFlags_AllOff;

    for(int i = 0; i < nch; i++) {
        desc.mChannelLabel = channels[i];
        r->mChannelDescriptions[i] = desc;
    }

coreaudio_error:
    return r;
}
Пример #6
0
int tr_dh_pub_hash(TID_REQ *request,
		   unsigned char **out_digest,
		   size_t *out_len)
{
  const BIGNUM *pub = request->tidc_dh->pub_key;
  unsigned char *bn_bytes = talloc_zero_size(request, BN_num_bytes(pub));
  unsigned char *digest = talloc_zero_size(request, SHA_DIGEST_LENGTH+1);
  assert(bn_bytes && digest);
  BN_bn2bin(pub, bn_bytes);
  SHA1(bn_bytes, BN_num_bytes(pub), digest);
  *out_digest = digest;
  *out_len = SHA_DIGEST_LENGTH;

  talloc_free(bn_bytes);
  return 0;
}
Пример #7
0
int drm_object_create_properties(struct mp_log *log, int fd,
                                 struct drm_object *object)
{
    object->props = drmModeObjectGetProperties(fd, object->id, object->type);
    if (object->props) {
        object->props_info = talloc_zero_size(NULL, object->props->count_props
                                              * sizeof(object->props_info));
        if (object->props_info) {
            for (int i = 0; i < object->props->count_props; i++)
                object->props_info[i] = drmModeGetProperty(fd, object->props->props[i]);
        } else {
            mp_err(log, "Out of memory\n");
            goto fail;
        }
    } else {
        mp_err(log, "Failed to retrieve properties for object id %d\n", object->id);
        goto fail;
    }

    return 0;

  fail:
    drm_object_free_properties(object);
    return -1;
}
Пример #8
0
bool prs_init(prs_struct *ps, uint32_t size, TALLOC_CTX *ctx, bool io)
{
	ZERO_STRUCTP(ps);
	ps->io = io;
	ps->bigendian_data = RPC_LITTLE_ENDIAN;
	ps->align = RPC_PARSE_ALIGN;
	ps->is_dynamic = False;
	ps->data_offset = 0;
	ps->buffer_size = 0;
	ps->data_p = NULL;
	ps->mem_ctx = ctx;

	if (size != 0) {
		ps->buffer_size = size;
		ps->data_p = (char *)talloc_zero_size(ps->mem_ctx, size);
		if(ps->data_p == NULL) {
			DEBUG(0,("prs_init: talloc fail for %u bytes.\n", (unsigned int)size));
			return False;
		}
		ps->is_dynamic = True; /* We own this memory. */
	} else if (MARSHALLING(ps)) {
		/* If size is zero and we're marshalling we should allocate memory on demand. */
		ps->is_dynamic = True;
	}

	return True;
}
Пример #9
0
struct gsm341_ms_message *
gsm0341_build_msg(void *ctx, uint8_t geo_scope, uint8_t msg_code,
		  uint8_t update, uint16_t msg_id, uint8_t dcs,
		  uint8_t page_total, uint8_t page_cur,
		  uint8_t *data, uint8_t len)
{
	struct gsm341_ms_message *cbmsg;

	msg_id = htons(msg_id);

	if (len > 88)
		return NULL;

	cbmsg = talloc_zero_size(ctx, sizeof(*cbmsg)+len);
	if (!cbmsg)
		return NULL;

	cbmsg->serial.code_hi = (msg_code >> 4) & 0xF;
	cbmsg->serial.gs = geo_scope;
	cbmsg->serial.update = update;
	cbmsg->serial.code_lo = msg_code & 0xF;
	cbmsg->msg_id = msg_id;
	cbmsg->dcs.group = dcs >> 4;
	cbmsg->dcs.language = dcs & 0xF;
	cbmsg->page.total = page_total;
	cbmsg->page.current = page_cur;
	memcpy(cbmsg->data, data, len);

	return cbmsg;
}
Пример #10
0
/*
  Constructs a PR_ENTRYID value for recipients.
 */
_PUBLIC_ struct Binary_r *generate_recipient_entryid(TALLOC_CTX *mem_ctx, const char *recipient_id)
{
	struct Binary_r	*entryid;
	uint32_t	off;
	char		*guid = (char *) NULL;

	entryid = talloc(mem_ctx, struct Binary_r);
	entryid->cb = sizeof (uint32_t) + sizeof (MAPI_LOCAL_UID) + sizeof (MAPI_LOCAL_UID_END) + 1;

	if (recipient_id) {
		guid = guid_delete_dash(mem_ctx, recipient_id);
		entryid->cb += strlen(guid);
	}

	entryid->lpb = (uint8_t *)talloc_zero_size(mem_ctx, entryid->cb);
	off = 4;
	memcpy(entryid->lpb + off, MAPI_LOCAL_UID, sizeof (MAPI_LOCAL_UID));
	off += sizeof (MAPI_LOCAL_UID);
	
	memcpy(entryid->lpb + off, MAPI_LOCAL_UID_END, sizeof (MAPI_LOCAL_UID_END));
	off += sizeof (MAPI_LOCAL_UID_END);

	if (recipient_id) {
		strcpy((char *)entryid->lpb + off, guid);
		off += strlen(recipient_id);
	}
	
	return entryid;
}
Пример #11
0
struct tlv_parsed *tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx)
{
	struct tlv_parsed *tp_out;
	unsigned int i;

	tp_out = talloc_zero(ctx, struct tlv_parsed);
	if (!tp_out)
		return NULL;

	/* if the original is NULL, return empty tlvp */
	if (!tp_orig)
		return tp_out;

	for (i = 0; i < ARRAY_SIZE(tp_orig->lv); i++) {
		unsigned int len = tp_orig->lv[i].len;
		tp_out->lv[i].len = len;
		if (len && tp_out->lv[i].val) {
			tp_out->lv[i].val = talloc_zero_size(tp_out, len);
			if (!tp_out->lv[i].val) {
				talloc_free(tp_out);
				return NULL;
			}
			memcpy((uint8_t *)tp_out->lv[i].val, tp_orig->lv[i].val, len);
		}
	}

	return tp_out;
}
Пример #12
0
char *cfstr_get_cstr(CFStringRef cfstr)
{
    CFIndex size =
        CFStringGetMaximumSizeForEncoding(
            CFStringGetLength(cfstr), CA_CFSTR_ENCODING) + 1;
    char *buffer = talloc_zero_size(NULL, size);
    CFStringGetCString(cfstr, buffer, size, CA_CFSTR_ENCODING);
    return buffer;
}
Пример #13
0
const char *
notmuch_time_relative_date (const void *ctx, time_t then)
{
    struct tm tm_now, tm_then;
    time_t now = time(NULL);
    time_t delta;
    char *result;

    localtime_r (&now, &tm_now);
    localtime_r (&then, &tm_then);

    result = talloc_zero_size (ctx, RELATIVE_DATE_MAX);
    if (result == NULL)
	return "when?";

    if (then > now)
	return "the future";

    delta = now - then;

    if (delta > 180 * DAY) {
	strftime (result, RELATIVE_DATE_MAX,
		  "%F", &tm_then); /* 2008-06-30 */
	return result;
    }

    if (delta < 3600) {
	snprintf (result, RELATIVE_DATE_MAX,
		  "%d mins. ago", (int) (delta / 60));
	return result;
    }

    if (delta <= 7 * DAY) {
	if (tm_then.tm_wday == tm_now.tm_wday &&
	    delta < DAY)
	{
	    strftime (result, RELATIVE_DATE_MAX,
		      "Today %R", &tm_then); /* Today 12:30 */
	    return result;
	} else if ((tm_now.tm_wday + 7 - tm_then.tm_wday) % 7 == 1) {
	    strftime (result, RELATIVE_DATE_MAX,
		      "Yest. %R", &tm_then); /* Yest. 12:30 */
	    return result;
	} else {
	    if (tm_then.tm_wday != tm_now.tm_wday) {
		strftime (result, RELATIVE_DATE_MAX,
			  "%a. %R", &tm_then); /* Mon. 12:30 */
		return result;
	    }
	}
    }

    strftime (result, RELATIVE_DATE_MAX,
	      "%B %d", &tm_then); /* October 12 */
    return result;
}
Пример #14
0
/*! \brief Generate a VTY command string from value_string */
char *vty_cmd_string_from_valstr(void *ctx, const struct value_string *vals,
				 const char *prefix, const char *sep,
				 const char *end, int do_lower)
{
	int len = 0, offset = 0, ret, rem;
	int size = strlen(prefix) + strlen(end);
	int sep_len = strlen(sep);
	const struct value_string *vs;
	char *str;

	for (vs = vals; vs->value || vs->str; vs++)
		size += strlen(vs->str) + sep_len;

	rem = size;
	str = talloc_zero_size(ctx, size);
	if (!str)
		return NULL;

	ret = snprintf(str + offset, rem, "%s", prefix);
	if (ret < 0)
		goto err;
	OSMO_SNPRINTF_RET(ret, rem, offset, len);

	for (vs = vals; vs->value || vs->str; vs++) {
		if (vs->str) {
			int j, name_len = strlen(vs->str)+1;
			char name[name_len];

			for (j = 0; j < name_len; j++)
				name[j] = do_lower ?
					tolower(vs->str[j]) : vs->str[j];

			name[name_len-1] = '\0';
			ret = snprintf(str + offset, rem, "%s%s", name, sep);
			if (ret < 0)
				goto err;
			OSMO_SNPRINTF_RET(ret, rem, offset, len);
		}
	}
	offset -= sep_len;	/* to remove the trailing sep */
	rem += sep_len;

	ret = snprintf(str + offset, rem, "%s", end);
	if (ret < 0)
		goto err;
	OSMO_SNPRINTF_RET(ret, rem, offset, len);
err:
	str[size-1] = '\0';
	return str;
}
Пример #15
0
static PyObject *py_generate_random_bytes(PyObject *self, PyObject *args)
{
	int len;
	PyObject *ret;
	uint8_t *bytes = NULL;

	if (!PyArg_ParseTuple(args, "i", &len))
		return NULL;

	bytes = talloc_zero_size(NULL, len);
	generate_random_buffer(bytes, len);
	ret = PyBytes_FromStringAndSize((const char *)bytes, len);
	talloc_free(bytes);
	return ret;
}
Пример #16
0
static int vo_preinit(struct vo *vo, char *arg)
{
    if (vo->driver->privsize)
        vo->priv = talloc_zero_size(vo, vo->driver->privsize);
    if (vo->driver->options) {
        struct m_config *cfg = m_config_simple(vo->driver->options);
        m_config_initialize(cfg, vo->priv);
        char n[50];
        int l = snprintf(n, sizeof(n), "vo/%s", vo->driver->info->short_name);
        assert(l < sizeof(n));
        int r = m_config_parse_suboptions(cfg, vo->priv, n, arg);
        talloc_free(cfg);
        if (r < 0)
            return r;
    }
    return vo->driver->preinit(vo, arg);
}
Пример #17
0
/** Create a fifo queue
 *
 * The first element enqueued will be the first to be dequeued.
 *
 * @note The created fifo does not provide any thread synchronisation functionality
 *	such as mutexes.  If multiple threads are enqueueing and dequeueing data
 *	the callers must synchronise their access.
 *
 * @param[in] ctx	to allocate fifo array in.
 * @param[in] type	Talloc type of elements (may be NULL).
 * @param[in] max	The maximum number of elements allowed.
 * @param[in] free_node	Function to use to free node data if the fifo is freed.
 * @return
 *	- A new fifo queue.
 *	- NULL on error.
 */
fr_fifo_t *_fr_fifo_create(TALLOC_CTX *ctx, char const *type, int max, fr_fifo_free_t free_node)
{
	fr_fifo_t *fi;

	if ((max < 2) || (max > (1024 * 1024))) return NULL;

	fi = talloc_zero_size(ctx, (sizeof(*fi) + (sizeof(fi->data[0])*max)));
	if (!fi) return NULL;
	talloc_set_type(fi, fr_fifo_t);
	talloc_set_destructor(fi, _fifo_free);

	fi->max = max;
	fi->type = type;
	fi->free_node = free_node;

	return fi;
}
Пример #18
0
/*
 * @brief Create an new EncryptedSecret owned by the supplied talloc context.
 *
 * Create a new encrypted secret and initialise the header.
 *
 * @param ldb ldb context, to allow logging.
 * @param ctx The talloc memory context that will own the new EncryptedSecret
 *
 * @return pointer to the new encrypted secret, or NULL if there was an error
 */
static struct EncryptedSecret *makeEncryptedSecret(struct ldb_context *ldb,
						   TALLOC_CTX *ctx)
{
	struct EncryptedSecret *es = NULL;

	es = talloc_zero_size(ctx, sizeof(struct EncryptedSecret));
	if (es == NULL) {
		ldb_set_errstring(ldb,
				  "Out of memory, allocating "
				   "struct EncryptedSecret\n");
		return NULL;
	}
	es->header.magic     = ENCRYPTED_SECRET_MAGIC_VALUE;
	es->header.version   = SECRET_ATTRIBUTE_VERSION;
	es->header.algorithm = SECRET_ENCRYPTION_ALGORITHM;
	es->header.flags     = 0;
	return es;
}
Пример #19
0
/* helper function for marshalling multiple records */
struct ctdb_marshall_buffer *ctdb_marshall_add(TALLOC_CTX *mem_ctx,
					       struct ctdb_marshall_buffer *m,
					       uint64_t db_id,
					       uint32_t reqid,
					       TDB_DATA key,
					       struct ctdb_ltdb_header *header,
					       TDB_DATA data)
{
	struct ctdb_rec_data *r;
	struct ctdb_marshall_buffer *m2;
	uint32_t length, offset;

	length = ctdb_marshall_record_size(key, header, data);

	if (m == NULL) {
		offset = offsetof(struct ctdb_marshall_buffer, data);
		m2 = talloc_zero_size(mem_ctx, offset + length);
	} else {
Пример #20
0
/*
 * Convert an Imap string to a filesystem string
 * ex INBOX/Test/Test2 -> .Test.Test2
 */
char *ImapToMaildir(TALLOC_CTX *MemCtx, char *sImap)
{
char *returnString;
int i;

returnString = (char *)talloc_zero_size(MemCtx, strlen(sImap));
i=0;
while(sImap[i] != 0)
  {
  if( sImap[i+5] == '/' )
    returnString[i] = '.';
  else
    returnString[i] = sImap[i+5];
  i++;
  }
returnString[i] = 0;
return( returnString ); 
}
Пример #21
0
static bool wrap_ndr_pullpush_test(struct torture_context *tctx,
				   struct torture_tcase *tcase,
				   struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx);
	void *ds = talloc_zero_size(ndr, data->struct_size);
	bool ret;
	uint32_t highest_ofs;

	ndr->flags |= data->flags;

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
				   "pulling");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
				   talloc_asprintf(tctx,
					   "%d unread bytes", ndr->data_size - highest_ofs));

	if (check_fn != NULL) {
		ret = check_fn(tctx, ds);
	} else {
		ret = true;
	}

	if (data->push_fn != NULL) {
		DATA_BLOB outblob;
		torture_assert_ndr_success(tctx, ndr_push_struct_blob(&outblob, ndr, ds, data->push_fn), "pushing");
		torture_assert_data_blob_equal(tctx, outblob, data->data, "ndr push compare");
	}

	talloc_free(ndr);
	return ret;
}
Пример #22
0
static int vo_preinit(struct vo *vo, char *arg)
{
    if (vo->driver->priv_size) {
        vo->priv = talloc_zero_size(vo, vo->driver->priv_size);
        if (vo->driver->priv_defaults)
            memcpy(vo->priv, vo->driver->priv_defaults, vo->driver->priv_size);
    }
    if (vo->driver->options) {
        struct m_config *cfg = m_config_simple(vo->priv);
        talloc_steal(vo->priv, cfg);
        m_config_register_options(cfg, vo->driver->options);
        char n[50];
        int l = snprintf(n, sizeof(n), "vo/%s", vo->driver->info->short_name);
        assert(l < sizeof(n));
        int r = m_config_parse_suboptions(cfg, n, arg);
        if (r < 0)
            return r;
    }
    return vo->driver->preinit(vo, arg);
}
Пример #23
0
/* enqueue some data into the tx_queue of a given subchannel */
int subchan_mux_enqueue(struct subch_mux *mx, int s_nr, const u_int8_t *data,
			int len)
{
	struct mux_subch *sch = &mx->subch[s_nr];
	int list_len = llist_len(&sch->tx_queue);
	struct subch_txq_entry *tqe = talloc_zero_size(tall_tqe_ctx,
							sizeof(*tqe) + len);
	if (!tqe)
		return -ENOMEM;

	tqe->bit_len = len;
	memcpy(tqe->bits, data, len);

	if (list_len > 2)
		tx_queue_evict(sch, list_len-2);

	llist_add_tail(&tqe->list, &sch->tx_queue);

	return 0;
}
Пример #24
0
_PUBLIC_ char *guid_delete_dash(TALLOC_CTX *mem_ctx, const char *recipient_id)
{
	char		*guid;
	uint32_t	count,i;

	if (!recipient_id) {
		return NULL;
	}

	for (count=0,i=0;i!=strlen(recipient_id);i++) {
		if (recipient_id[i] != '-') count++;
	}

	guid = (char *)talloc_zero_size(mem_ctx, count+1);
	for (count=0,i = 0;i!=strlen(recipient_id);i++) {
		if (recipient_id[i] != '-') {
			guid[count] = recipient_id[i];
			count++;
		}
	}

	return guid;
}
Пример #25
0
Файл: ndr.c Проект: endisd/samba
static bool wrap_ndr_pull_test(struct torture_context *tctx,
							   struct torture_tcase *tcase,
							   struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	void *ds = talloc_zero_size(tctx, data->struct_size);
	struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx, lp_iconv_convenience(tctx->lp_ctx));

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
				   "pulling");

	torture_assert(tctx, ndr->offset == ndr->data_size, 
				   talloc_asprintf(tctx, 
					   "%d unread bytes", ndr->data_size - ndr->offset));

	if (check_fn != NULL) 
		return check_fn(tctx, ds);
	else
		return true;
}
Пример #26
0
struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx,
				    void *pdata,
				    size_t data_size,
				    const char *type,
				    const char *location)
{
	struct tevent_req *req;
	void **ppdata = (void **)pdata;
	void *data;

	req = talloc_zero(mem_ctx, struct tevent_req);
	if (req == NULL) {
		return NULL;
	}
	req->internal.private_type	= type;
	req->internal.create_location	= location;
	req->internal.finish_location	= NULL;
	req->internal.state		= TEVENT_REQ_IN_PROGRESS;
	req->internal.trigger		= tevent_create_immediate(req);
	if (!req->internal.trigger) {
		talloc_free(req);
		return NULL;
	}
	req->internal.defer_callback_ev	= NULL;

	data = talloc_zero_size(req, data_size);
	if (data == NULL) {
		talloc_free(req);
		return NULL;
	}
	talloc_set_name_const(data, type);

	req->data = data;

	*ppdata = data;
	return req;
}
Пример #27
0
struct rate_ctr_group *rate_ctr_group_alloc(void *ctx,
					    const struct rate_ctr_group_desc *desc,
					    unsigned int idx)
{
	unsigned int size;
	struct rate_ctr_group *group;

	size = sizeof(struct rate_ctr_group) +
			desc->num_ctr * sizeof(struct rate_ctr);

	if (!ctx)
		ctx = tall_rate_ctr_ctx;

	group = talloc_zero_size(ctx, size);
	if (!group)
		return NULL;

	group->desc = desc;
	group->idx = idx;

	llist_add(&group->list, &rate_ctr_groups);

	return group;
}
Пример #28
0
/**
 * Initializes a new primitive by allocating memory
 * and filling some meta-information (e.g. lchan type).
 *
 * @param  trx     TRX instance to be used as initial talloc context
 * @param  prim    external prim pointer (will point to the allocated prim)
 * @param  pl_len  prim payload length
 * @param  chan_nr RSL channel description (used to set a proper chan)
 * @param  link_id RSL link description (used to set a proper chan)
 * @return         zero in case of success, otherwise a error number
 */
int sched_prim_init(struct trx_instance *trx,
	struct trx_ts_prim **prim, size_t pl_len,
	uint8_t chan_nr, uint8_t link_id)
{
	enum trx_lchan_type lchan_type;
	struct trx_ts_prim *new_prim;
	uint8_t len;

	/* Determine lchan type */
	lchan_type = sched_trx_chan_nr2lchan_type(chan_nr, link_id);
	if (!lchan_type) {
		LOGP(DSCH, LOGL_ERROR, "Couldn't determine lchan type "
			"for chan_nr=%02x and link_id=%02x\n", chan_nr, link_id);
		return -EINVAL;
	}

	/* How much memory do we need? */
	len  = sizeof(struct trx_ts_prim); /* Primitive header */
	len += pl_len; /* Requested payload size */

	/* Allocate a new primitive */
	new_prim = talloc_zero_size(trx, len);
	if (new_prim == NULL) {
		LOGP(DSCH, LOGL_ERROR, "Failed to allocate memory\n");
		return -ENOMEM;
	}

	/* Init primitive header */
	new_prim->payload_len = pl_len;
	new_prim->chan = lchan_type;

	/* Set external pointer */
	*prim = new_prim;

	return 0;
}
Пример #29
0
struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
					const struct dcerpc_binding_handle_ops *ops,
					const struct GUID *object,
					const struct ndr_interface_table *table,
					void *pstate,
					size_t psize,
					const char *type,
					const char *location)
{
	struct dcerpc_binding_handle *h;
	void **ppstate = (void **)pstate;
	void *state;

	h = talloc_zero(mem_ctx, struct dcerpc_binding_handle);
	if (h == NULL) {
		return NULL;
	}
	h->ops		= ops;
	h->location	= location;
	h->object	= object;
	h->table	= table;

	state = talloc_zero_size(h, psize);
	if (state == NULL) {
		talloc_free(h);
		return NULL;
	}
	talloc_set_name_const(state, type);

	h->private_data = state;

	talloc_set_destructor(h, dcerpc_binding_handle_destructor);

	*ppstate = state;
	return h;
}
Пример #30
0
static void test_store_records(struct db_context *db, struct tevent_context *ev)
{
	TDB_DATA key;
	uint32_t *counters;
	TALLOC_CTX *tmp_ctx = talloc_stackframe();
	struct timeval start;

	key = string_term_tdb_data("testkey");

	start = timeval_current();
	while ((timelimit == 0) || (timeval_elapsed(&start) < timelimit)) {
		struct db_record *rec;
		TDB_DATA data;
		TDB_DATA value;
		int ret;
		NTSTATUS status;

		if (!no_trans) {
			if (verbose) DEBUG(1, ("starting transaction\n"));
			ret = dbwrap_transaction_start(db);
			if (ret != 0) {
				DEBUG(0, ("Failed to start transaction on node "
					  "%d\n", pnn));
				goto fail;
			}
			if (verbose) DEBUG(1, ("transaction started\n"));
			do_sleep(torture_delay);
		}

		if (verbose) DEBUG(1, ("calling fetch_lock\n"));
		rec = dbwrap_fetch_locked(db, tmp_ctx, key);
		if (rec == NULL) {
			DEBUG(0, ("Failed to fetch record\n"));
			goto fail;
		}
		if (verbose) DEBUG(1, ("fetched record ok\n"));
		do_sleep(torture_delay);
		value = dbwrap_record_get_value(rec);

		data.dsize = MAX(value.dsize, sizeof(uint32_t) * (pnn+1));
		data.dptr = (unsigned char *)talloc_zero_size(tmp_ctx,
							      data.dsize);
		if (data.dptr == NULL) {
			DEBUG(0, ("Failed to allocate data\n"));
			goto fail;
		}
		memcpy(data.dptr, value.dptr, value.dsize);

		counters = (uint32_t *)data.dptr;

		/* bump our counter */
		counters[pnn]++;

		if (verbose) DEBUG(1, ("storing data\n"));
		status = dbwrap_record_store(rec, data, TDB_REPLACE);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0, ("Failed to store record\n"));
			if (!no_trans) {
				ret = dbwrap_transaction_cancel(db);
				if (ret != 0) {
					DEBUG(0, ("Error cancelling transaction.\n"));
				}
			}
			goto fail;
		}
		talloc_free(rec);
		if (verbose) DEBUG(1, ("stored data ok\n"));
		do_sleep(torture_delay);

		if (!no_trans) {
			if (verbose) DEBUG(1, ("calling transaction_commit\n"));
			ret = dbwrap_transaction_commit(db);
			if (ret != 0) {
				DEBUG(0, ("Failed to commit transaction\n"));
				goto fail;
			}
			if (verbose) DEBUG(1, ("transaction committed\n"));
		}

		/* store the counters and verify that they are sane */
		if (verbose || (pnn == 0)) {
			if (!check_counters(db, data)) {
				goto fail;
			}
		}
		talloc_free(data.dptr);

		do_sleep(torture_delay);
	}

	goto done;

fail:
	success = false;

done:
	talloc_free(tmp_ctx);
	return;
}