示例#1
0
文件: ntlmssp.c 项目: javierag/samba
/**
 * Converts a password to the hashes on an NTLMSSP context.
 *
 */
NTSTATUS ntlmssp_set_password(struct ntlmssp_state *ntlmssp_state, const char *password)
{
	uint8_t lm_hash[16];
	uint8_t nt_hash[16];

	TALLOC_FREE(ntlmssp_state->lm_hash);
	TALLOC_FREE(ntlmssp_state->nt_hash);

	if (password == NULL) {
		return NT_STATUS_OK;
	}

	if (E_deshash(password, lm_hash)) {
		ntlmssp_state->lm_hash = (uint8_t *)
			talloc_memdup(ntlmssp_state, lm_hash, 16);
		if (!ntlmssp_state->lm_hash) {
			return NT_STATUS_NO_MEMORY;
		}
	}

	E_md4hash(password, nt_hash);

	ntlmssp_state->nt_hash = (uint8_t *)
		talloc_memdup(ntlmssp_state, nt_hash, 16);
	if (!ntlmssp_state->nt_hash) {
		TALLOC_FREE(ntlmssp_state->lm_hash);
		return NT_STATUS_NO_MEMORY;
	}

	return NT_STATUS_OK;
}
示例#2
0
/**
   \details Set sort order to specified openchangedb table object

   \param table_object pointer to the table object
   \param lpSortCriteria pointer to the sort order to save

   \return MAPI_E_SUCCESS on success, otherwise MAPI error
 */
_PUBLIC_ enum MAPISTATUS openchangedb_table_set_sort_order(void *table_object, 
							   struct SSortOrderSet *lpSortCriteria)
{
	struct openchangedb_table	*table;

	/* Sanity checks */
	MAPI_RETVAL_IF(!table_object, MAPI_E_NOT_INITIALIZED, NULL);
	MAPI_RETVAL_IF(!lpSortCriteria, MAPI_E_INVALID_PARAMETER, NULL);

	table = (struct openchangedb_table *) table_object;

	if (table->res) {
		talloc_free(table->res);
		table->res = NULL;
	}

	if (table->lpSortCriteria) {
		talloc_free(table->lpSortCriteria);
	}
	if (lpSortCriteria) {
		table->lpSortCriteria = talloc_memdup((TALLOC_CTX *)table, lpSortCriteria, sizeof(struct SSortOrderSet));
		if (!table->lpSortCriteria) {
			return MAPI_E_NOT_ENOUGH_MEMORY;
		}
		table->lpSortCriteria->aSort = talloc_memdup((TALLOC_CTX *)table->lpSortCriteria, lpSortCriteria->aSort, lpSortCriteria->cSorts * sizeof(struct SSortOrder));
		if (!table->lpSortCriteria->aSort) {
			return MAPI_E_NOT_ENOUGH_MEMORY;
		}
	}
	else {
		table->lpSortCriteria = NULL;
	}

	return MAPI_E_SUCCESS;
}
示例#3
0
文件: request.c 项目: AIdrifter/samba
/*
  setup a copy of a request, used when the server needs to send
  more than one reply for a single request packet
*/
struct smbsrv_request *smbsrv_setup_secondary_request(struct smbsrv_request *old_req)
{
	struct smbsrv_request *req;
	ptrdiff_t diff;

	req = talloc_memdup(old_req, old_req, sizeof(struct smbsrv_request));
	if (req == NULL) {
		return NULL;
	}

	req->out.buffer = talloc_memdup(req, req->out.buffer, req->out.allocated);
	if (req->out.buffer == NULL) {
		talloc_free(req);
		return NULL;
	}

	diff = req->out.buffer - old_req->out.buffer;

	req->out.hdr  += diff;
	req->out.vwv  += diff;
	req->out.data += diff;
	req->out.ptr  += diff;

	return req;
}
示例#4
0
static WERROR dns_copy_tsig(TALLOC_CTX *mem_ctx,
			    struct dns_res_rec *old,
			    struct dns_res_rec *new_rec)
{
	new_rec->name = talloc_strdup(mem_ctx, old->name);
	W_ERROR_HAVE_NO_MEMORY(new_rec->name);

	new_rec->rr_type = old->rr_type;
	new_rec->rr_class = old->rr_class;
	new_rec->ttl = old->ttl;
	new_rec->length = old->length;
	new_rec->rdata.tsig_record.algorithm_name = talloc_strdup(mem_ctx,
				old->rdata.tsig_record.algorithm_name);
	W_ERROR_HAVE_NO_MEMORY(new_rec->rdata.tsig_record.algorithm_name);

	new_rec->rdata.tsig_record.time_prefix = old->rdata.tsig_record.time_prefix;
	new_rec->rdata.tsig_record.time = old->rdata.tsig_record.time;
	new_rec->rdata.tsig_record.fudge = old->rdata.tsig_record.fudge;
	new_rec->rdata.tsig_record.mac_size = old->rdata.tsig_record.mac_size;
	new_rec->rdata.tsig_record.mac = talloc_memdup(mem_ctx,
					old->rdata.tsig_record.mac,
					old->rdata.tsig_record.mac_size);
	W_ERROR_HAVE_NO_MEMORY(new_rec->rdata.tsig_record.mac);

	new_rec->rdata.tsig_record.original_id = old->rdata.tsig_record.original_id;
	new_rec->rdata.tsig_record.error = old->rdata.tsig_record.error;
	new_rec->rdata.tsig_record.other_size = old->rdata.tsig_record.other_size;
	new_rec->rdata.tsig_record.other_data = talloc_memdup(mem_ctx,
					old->rdata.tsig_record.other_data,
					old->rdata.tsig_record.other_size);
	W_ERROR_HAVE_NO_MEMORY(new_rec->rdata.tsig_record.other_data);

	return WERR_OK;
}
示例#5
0
/*
	Just try locking/unlocking a single record once
*/
static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev, uint32_t generation)
{
	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
	TDB_DATA key, data;
	struct ctdb_record_handle *h;
	struct ctdb_ltdb_header *header;
	int ret;

	key.dptr = discard_const(TESTKEY);
	key.dsize = strlen(TESTKEY);

	printf("Trying to fetch lock the record ...\n");

	h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, false);
	if (h == NULL) {
		printf("Failed to fetch record '%s' on node %d\n", 
	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
		talloc_free(tmp_ctx);
		exit(10);
	}

	printf("Record fetchlocked.\n");
	header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header));
       	printf("RSN:%d\n", (int)header->rsn);
	talloc_free(h);
	printf("Record released.\n");

	printf("Write new record with RSN+10\n");
	header->rsn += 10;
	data.dptr = (void *)talloc_asprintf(tmp_ctx, "%d", (int)header->rsn);
	data.dsize = strlen((char *)data.dptr);

	ret = ctdb_ctrl_updaterecord(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb_db, key, header, data);
	if (ret != 0) {
		printf("Failed to writerecord,  ret==%d\n", ret);	
		exit(1);
	}

	printf("re-fetch the record\n");
	h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
	if (h == NULL) {
		printf("Failed to fetch record '%s' on node %d\n", 
	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
		talloc_free(tmp_ctx);
		exit(10);
	}

	printf("Record fetchlocked.\n");
	header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header));
       	printf("RSN:%d\n", (int)header->rsn);
	talloc_free(h);
	printf("Record released.\n");

	talloc_free(tmp_ctx);
}
示例#6
0
/** Copy a single valuepair
 *
 * Allocate a new valuepair and copy the da from the old vp.
 *
 * @param[in] ctx for talloc
 * @param[in] vp to copy.
 * @return a copy of the input VP or NULL on error.
 */
VALUE_PAIR *paircopyvp(TALLOC_CTX *ctx, VALUE_PAIR const *vp)
{
	VALUE_PAIR *n;

	if (!vp) return NULL;

	VERIFY(vp);

	n = pairalloc(ctx, vp->da);
	if (!n) {
		fr_strerror_printf("out of memory");
		return NULL;
	}
	
	memcpy(n, vp, sizeof(*n));
	
	/*
	 *	Now copy the value
	 */
	if (vp->type == VT_XLAT) {
		n->value.xlat = talloc_strdup(n, n->value.xlat);
	}
	
	n->da = dict_attr_copy(vp->da, true);
	if (!n->da) {
		pairbasicfree(n);
		return NULL;
	}
	
	n->next = NULL;

	if ((n->da->type == PW_TYPE_TLV) ||
	    (n->da->type == PW_TYPE_OCTETS)) {
		if (n->vp_octets != NULL) {
			n->vp_octets = talloc_memdup(n, vp->vp_octets, n->length);
		}

	} else if (n->da->type == PW_TYPE_STRING) {
		if (n->vp_strvalue != NULL) {
			/*
			 *	Equivalent to, and faster than strdup.
			 */
			n->vp_strvalue = talloc_memdup(n, vp->vp_octets, n->length + 1);
		}
	}

	return n;
}
示例#7
0
WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
		      struct NetRemoteTOD *r)
{
	NTSTATUS status;
	WERROR werr;
	struct srvsvc_NetRemoteTODInfo *info = NULL;
	struct dcerpc_binding_handle *b;

	werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
					    &ndr_table_srvsvc.syntax_id,
					    &b);
	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	status = dcerpc_srvsvc_NetRemoteTOD(b, talloc_tos(),
					    r->in.server_name,
					    &info,
					    &werr);
	if (!NT_STATUS_IS_OK(status)) {
		werr = ntstatus_to_werror(status);
		goto done;
	}

	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	*r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
			  sizeof(struct srvsvc_NetRemoteTODInfo));
	W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);

 done:
	return werr;
}
示例#8
0
文件: socket.c 项目: AIdrifter/samba
/* Copy a socket_address structure */
struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
					   const struct socket_address *oaddr)
{
	struct socket_address *addr = talloc_zero(mem_ctx, struct socket_address);
	if (!addr) {
		return NULL;
	}
	addr->family	= oaddr->family;
	if (oaddr->addr) {
		addr->addr	= talloc_strdup(addr, oaddr->addr);
		if (!addr->addr) {
			goto nomem;
		}
	}
	addr->port	= oaddr->port;
	if (oaddr->sockaddr) {
		addr->sockaddr = (struct sockaddr *)talloc_memdup(addr,
								  oaddr->sockaddr,
								  oaddr->sockaddrlen);
		if (!addr->sockaddr) {
			goto nomem;
		}
		addr->sockaddrlen = oaddr->sockaddrlen;
	}

	return addr;

nomem:
	talloc_free(addr);
	return NULL;
}
示例#9
0
static bool tldap_add_blob_vals(TALLOC_CTX *mem_ctx, struct tldap_mod *mod,
				DATA_BLOB *newvals, int num_newvals)
{
	int num_values = talloc_array_length(mod->values);
	int i;
	DATA_BLOB *tmp;

	tmp = talloc_realloc(mem_ctx, mod->values, DATA_BLOB,
			     num_values + num_newvals);
	if (tmp == NULL) {
		return false;
	}
	mod->values = tmp;

	for (i=0; i<num_newvals; i++) {
		mod->values[i+num_values].data = (uint8_t *)talloc_memdup(
			mod->values, newvals[i].data, newvals[i].length);
		if (mod->values[i+num_values].data == NULL) {
			return false;
		}
		mod->values[i+num_values].length = newvals[i].length;
	}
	mod->num_values = num_values + num_newvals;
	return true;
}
示例#10
0
WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
		      struct NetRemoteTOD *r)
{
	struct rpc_pipe_client *pipe_cli = NULL;
	NTSTATUS status;
	WERROR werr;
	struct srvsvc_NetRemoteTODInfo *info = NULL;

	werr = libnetapi_open_pipe(ctx, r->in.server_name,
				   &ndr_table_srvsvc.syntax_id,
				   &pipe_cli);
	if (!W_ERROR_IS_OK(werr)) {
		goto done;
	}

	status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, talloc_tos(),
					    r->in.server_name,
					    &info,
					    &werr);
	if (!NT_STATUS_IS_OK(status)) {
		werr = ntstatus_to_werror(status);
		goto done;
	}

	*r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
			  sizeof(struct srvsvc_NetRemoteTODInfo));
	W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);

 done:
	return werr;
}
示例#11
0
NTSTATUS copy_netr_SamBaseInfo(TALLOC_CTX *mem_ctx,
			       const struct netr_SamBaseInfo *in,
			       struct netr_SamBaseInfo *out)
{
	/* first copy all, then realloc pointers */
	*out = *in;

	COPY_LSA_STRING(mem_ctx, in, out, account_name);
	COPY_LSA_STRING(mem_ctx, in, out, full_name);
	COPY_LSA_STRING(mem_ctx, in, out, logon_script);
	COPY_LSA_STRING(mem_ctx, in, out, profile_path);
	COPY_LSA_STRING(mem_ctx, in, out, home_directory);
	COPY_LSA_STRING(mem_ctx, in, out, home_drive);

	if (in->groups.count) {
		out->groups.rids = (struct samr_RidWithAttribute *)
			talloc_memdup(mem_ctx, in->groups.rids,
				(sizeof(struct samr_RidWithAttribute) *
					in->groups.count));
		NT_STATUS_HAVE_NO_MEMORY(out->groups.rids);
	}

	COPY_LSA_STRING(mem_ctx, in, out, logon_server);
	COPY_LSA_STRING(mem_ctx, in, out, logon_domain);

	if (in->domain_sid) {
		out->domain_sid = dom_sid_dup(mem_ctx, in->domain_sid);
		NT_STATUS_HAVE_NO_MEMORY(out->domain_sid);
	}

	return NT_STATUS_OK;
}
示例#12
0
struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken)
{
	struct security_token *token;

	if (!ptoken)
		return NULL;

	token = talloc_zero(mem_ctx, struct security_token);
	if (token == NULL) {
		DEBUG(0, ("talloc failed\n"));
		return NULL;
	}

	if (ptoken->sids && ptoken->num_sids) {
		token->sids = (struct dom_sid *)talloc_memdup(
			token, ptoken->sids, sizeof(struct dom_sid) * ptoken->num_sids );

		if (token->sids == NULL) {
			DEBUG(0, ("talloc_memdup failed\n"));
			TALLOC_FREE(token);
			return NULL;
		}
		token->num_sids = ptoken->num_sids;
	}
	
	token->privilege_mask = ptoken->privilege_mask;
	token->rights_mask = ptoken->rights_mask;

	return token;
}
_PUBLIC_ void mapistore_push_notification(struct mapistore_context *mstore_ctx, uint8_t object_type, enum mapistore_notification_type event, void *parameters)
{
        struct mapistore_notification *new_notification;
        struct mapistore_notification_list *new_list;
        struct mapistore_table_notification_parameters *table_parameters;
        struct mapistore_object_notification_parameters *object_parameters;

        if (!mstore_ctx) return;

	new_list = talloc_zero(mstore_ctx, struct mapistore_notification_list);
	new_notification = talloc_zero(new_list, struct mapistore_notification);
	new_list->notification = new_notification;
	new_notification->object_type = object_type;
	new_notification->event = event;
	if (object_type == MAPISTORE_TABLE) {
		table_parameters = parameters;
		new_notification->parameters.table_parameters = *table_parameters;
	}
	else {
		object_parameters = parameters;
		new_notification->parameters.object_parameters = *object_parameters;
		if (new_notification->parameters.object_parameters.tag_count > 0
		    && new_notification->parameters.object_parameters.tag_count != 0xffff) {
			new_notification->parameters.object_parameters.tags
				= talloc_memdup(new_notification, new_notification->parameters.object_parameters.tags,
						sizeof(enum MAPITAGS) * new_notification->parameters.object_parameters.tag_count);
		}
	}
	DLIST_ADD_END(mstore_ctx->notifications, new_list, void);
}
示例#14
0
文件: lavc_conv.c 项目: ThreeGe/mpv
struct lavc_conv *lavc_conv_create(struct mp_log *log, const char *codec_name,
                                   char *extradata, int extradata_len)
{
    struct lavc_conv *priv = talloc_zero(NULL, struct lavc_conv);
    priv->log = log;
    priv->cur_list = talloc_array(priv, char*, 0);
    priv->codec = talloc_strdup(priv, codec_name);
    AVCodecContext *avctx = NULL;
    const char *fmt = get_lavc_format(priv->codec);
    AVCodec *codec = avcodec_find_decoder(mp_codec_to_av_codec_id(fmt));
    if (!codec)
        goto error;
    avctx = avcodec_alloc_context3(codec);
    if (!avctx)
        goto error;
    avctx->extradata_size = extradata_len;
    avctx->extradata = talloc_memdup(priv, extradata, extradata_len);
    if (avcodec_open2(avctx, codec, NULL) < 0)
        goto error;
    // Documented as "set by libavcodec", but there is no other way
    avctx->time_base = (AVRational) {1, 1000};
    priv->avctx = avctx;
    priv->extradata = talloc_strndup(priv, avctx->subtitle_header,
                                     avctx->subtitle_header_size);
    disable_styles(bstr0(priv->extradata));
    return priv;

 error:
    MP_FATAL(priv, "Could not open libavcodec subtitle converter\n");
    av_free(avctx);
    talloc_free(priv);
    return NULL;
}
示例#15
0
unsigned char *sss_base64_decode(TALLOC_CTX *mem_ctx,
                                 const char *inbuf,
                                 size_t *outbufsize)
{
    int ret;
    unsigned char *b64decoded = NULL;
    unsigned int size;
    unsigned char *outbuf;

    /* initialize NSS if needed */
    ret = nspr_nss_init();
    if (ret != EOK) {
        return NULL;
    }

    b64decoded = ATOB_AsciiToData(inbuf, &size);
    if (!b64decoded) return NULL;

    outbuf = talloc_memdup(mem_ctx, b64decoded, size);
    PORT_Free(b64decoded);
    if (!outbuf) return NULL;

    *outbufsize = size;
    return outbuf;
}
示例#16
0
文件: talloc.c 项目: jophxy/samba
/** strdup with a talloc */
char *talloc_strdup(TALLOC_CTX *t, const char *p)
{
	if (p)
		return talloc_memdup(t, p, strlen(p) + 1);
	else
		return NULL;
}
示例#17
0
static int ctdb_ibw_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
{
	struct ctdb_ibw_node *cn = talloc_get_type(node->private_data, struct ctdb_ibw_node);
	int	rc;

	assert(length>=sizeof(uint32_t));
	assert(cn!=NULL);

	if (cn->conn==NULL) {
		DEBUG(DEBUG_ERR, ("ctdb_ibw_queue_pkt: conn is NULL\n"));
		return -1;
	}

	if (cn->conn->state==IBWC_CONNECTED) {
		rc = ctdb_ibw_send_pkt(cn->conn, data, length);
	} else {
		struct ctdb_ibw_msg *p = talloc_zero(cn, struct ctdb_ibw_msg);
		CTDB_NO_MEMORY(node->ctdb, p);

		p->data = talloc_memdup(p, data, length);
		CTDB_NO_MEMORY(node->ctdb, p->data);

		p->length = length;

		DLIST_ADD_AFTER(cn->queue, p, cn->queue_last);
		cn->queue_last = p;
		cn->qcnt++;

		rc = 0;
	}

	return rc;
}
示例#18
0
/** Copy data from one VP to another
 *
 * Allocate a new pair using da, and copy over the value from the specified
 * vp.
 *
 * @todo Should be able to do type conversions.
 *
 * @param[in] ctx for talloc
 * @param[in] da of new attribute to alloc.
 * @param[in] vp to copy data from.
 * @return the new valuepair.
 */
VALUE_PAIR *paircopyvpdata(TALLOC_CTX *ctx, DICT_ATTR const *da, VALUE_PAIR const *vp)
{
	VALUE_PAIR *n;

	if (!vp) return NULL;

	VERIFY(vp);

	if (da->type != vp->da->type) return NULL;
	
	n = pairalloc(ctx, da);
	if (!n) {
		return NULL;	
	}

	memcpy(n, vp, sizeof(*n));
	n->da = da;

	if (n->type == VT_XLAT) {
		n->value.xlat = talloc_strdup(n, n->value.xlat);
	}
	
	if ((n->da->type == PW_TYPE_TLV) ||
	    (n->da->type == PW_TYPE_OCTETS) ||
	    (n->da->type == PW_TYPE_STRING)) {
		if (n->vp_octets != NULL) {
			n->vp_octets = talloc_memdup(n, vp->vp_octets, n->length);
		}
	}

	n->next = NULL;

	return n;
}
示例#19
0
/*
 * Handle the curl response data. We could probably simplify our chunks by
 * having the header on each chunk be the list as well. Oh well.
 */
static size_t recv_data(void *data, size_t size, size_t nmemb, void *info)
{
	struct chunk_list_struct *chunk = NULL;
	struct s3_request_struct *req = (struct s3_request_struct *)info;

	DEBUG(10, ("Received size = %zu nmemb = %zu\n", size, nmemb));
	dump_data(10, data, size * nmemb);

	chunk = talloc_zero(req->response, struct chunk_list_struct);
	if (!chunk) {
		DEBUG(1, ("Unable to allocate space for chunk: %s, size: %zu, "
			" nmemb = %zu\n", strerror(errno), size, nmemb));
		goto out;
	}

	chunk->chunk_size = size * nmemb;
	chunk->chunk = talloc_memdup(chunk, data, size * nmemb);

	DLIST_ADD_END(req->response->chunks, 
		      chunk,
		      struct chunk_list_struct *);

out:
	return nmemb * size;
}
示例#20
0
文件: socket.c 项目: AIdrifter/samba
_PUBLIC_ struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx, 
							     struct sockaddr *sockaddr, 
							     size_t sockaddrlen)
{
	struct socket_address *addr = talloc(mem_ctx, struct socket_address);
	if (!addr) {
		return NULL;
	}
	switch (sockaddr->sa_family) {
	case AF_INET:
		addr->family = "ipv4";
		break;
#ifdef HAVE_IPV6
	case AF_INET6:
		addr->family = "ipv6";
		break;
#endif
	case AF_UNIX:
		addr->family = "unix";
		break;
	}
	addr->addr = NULL;
	addr->port = 0;
	addr->sockaddr = (struct sockaddr *)talloc_memdup(addr, sockaddr, sockaddrlen);
	if (!addr->sockaddr) {
		talloc_free(addr);
		return NULL;
	}
	addr->sockaddrlen = sockaddrlen;
	return addr;
}
示例#21
0
/*
  fetch a record from the ltdb, separating out the header information
  and returning the body of the record.
  if the record does not exist, *header will be NULL
  and data = {0, NULL}
*/
int ctdb_ltdb_fetch_with_header(struct ctdb_db_context *ctdb_db, 
		    TDB_DATA key, struct ctdb_ltdb_header *header, 
		    TALLOC_CTX *mem_ctx, TDB_DATA *data)
{
	TDB_DATA rec;

	rec = tdb_fetch(ctdb_db->ltdb->tdb, key);
	if (rec.dsize < sizeof(*header)) {
		free(rec.dptr);

		data->dsize = 0;
		data->dptr = NULL;
		return -1;
	}

	*header = *(struct ctdb_ltdb_header *)rec.dptr;
	if (data) {
		data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header);
		data->dptr = talloc_memdup(mem_ctx, 
					   sizeof(struct ctdb_ltdb_header)+rec.dptr,
					   data->dsize);
	}

	free(rec.dptr);

	return 0;
}
示例#22
0
static int init(struct sd *sd)
{
    struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv);
    AVCodecContext *avctx = NULL;
    AVCodec *codec = avcodec_find_decoder(mp_codec_to_av_codec_id(sd->codec));
    if (!codec)
        goto error;
    avctx = avcodec_alloc_context3(codec);
    if (!avctx)
        goto error;
    avctx->extradata_size = sd->extradata_len;
    avctx->extradata = sd->extradata;
    if (avcodec_open2(avctx, codec, NULL) < 0)
        goto error;
    // Documented as "set by libavcodec", but there is no other way
    avctx->time_base = (AVRational) {1, 1000};
    priv->avctx = avctx;
    sd->priv = priv;
    sd->output_codec = "ass";
    sd->output_extradata = avctx->subtitle_header;
    sd->output_extradata_len = avctx->subtitle_header_size;
    if (sd->output_extradata) {
        sd->output_extradata = talloc_memdup(sd, sd->output_extradata,
                                             sd->output_extradata_len);
        disable_styles((bstr){sd->output_extradata, sd->output_extradata_len});
    }
    return 0;

 error:
    mp_msg(MSGT_SUBREADER, MSGL_ERR,
           "Could not open libavcodec subtitle converter\n");
    av_free(avctx);
    talloc_free(priv);
    return -1;
}
示例#23
0
NT_USER_TOKEN *dup_nt_token(TALLOC_CTX *mem_ctx, const NT_USER_TOKEN *ptoken)
{
	NT_USER_TOKEN *token;

	if (!ptoken)
		return NULL;

	token = TALLOC_ZERO_P(mem_ctx, NT_USER_TOKEN);
	if (token == NULL) {
		DEBUG(0, ("talloc failed\n"));
		return NULL;
	}

	if (ptoken->user_sids && ptoken->num_sids) {
		token->user_sids = (DOM_SID *)talloc_memdup(
			token, ptoken->user_sids, sizeof(DOM_SID) * ptoken->num_sids );

		if (token->user_sids == NULL) {
			DEBUG(0, ("talloc_memdup failed\n"));
			TALLOC_FREE(token);
			return NULL;
		}
		token->num_sids = ptoken->num_sids;
	}
	
	/* copy the privileges; don't consider failure to be critical here */
	
	if ( !se_priv_copy( &token->privileges, &ptoken->privileges ) ) {
		DEBUG(0,("dup_nt_token: Failure to copy SE_PRIV!.  "
			 "Continuing with 0 privileges assigned.\n"));
	}

	return token;
}
示例#24
0
/*
  convert a dom_sid to a string
*/
char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
{
	char buf[DOM_SID_STR_BUFLEN];
	char *result;
	int len;

	len = dom_sid_string_buf(sid, buf, sizeof(buf));

	if (len+1 > sizeof(buf)) {
		return talloc_strdup(mem_ctx, "(SID ERR)");
	}

	/*
	 * Avoid calling strlen (via talloc_strdup), we already have
	 * the length
	 */
	result = (char *)talloc_memdup(mem_ctx, buf, len+1);
	if (result == NULL) {
		return NULL;
	}

	/*
	 * beautify the talloc_report output
	 */
	talloc_set_name_const(result, result);
	return result;
}
示例#25
0
文件: eventlog.c 项目: gojdic/samba
NTSTATUS evlog_tdb_entry_to_evt_entry(TALLOC_CTX *mem_ctx,
				      const struct eventlog_Record_tdb *t,
				      struct EVENTLOGRECORD *e)
{
	uint32_t i;

	ZERO_STRUCTP(e);

	e->Length		= t->size;
	e->Reserved		= t->reserved;
	e->RecordNumber		= t->record_number;
	e->TimeGenerated	= t->time_generated;
	e->TimeWritten		= t->time_written;
	e->EventID		= t->event_id;
	e->EventType		= t->event_type;
	e->NumStrings		= t->num_of_strings;
	e->EventCategory	= t->event_category;
	e->ReservedFlags	= t->reserved_flags;
	e->ClosingRecordNumber	= t->closing_record_number;

	e->StringOffset		= t->stringoffset;
	e->UserSidLength	= t->sid_length;
	e->UserSidOffset	= t->sid_offset;
	e->DataLength		= t->data_length;
	e->DataOffset		= t->data_offset;

	e->SourceName		= talloc_strdup(mem_ctx, t->source_name);
	NT_STATUS_HAVE_NO_MEMORY(e->SourceName);

	e->Computername		= talloc_strdup(mem_ctx, t->computer_name);
	NT_STATUS_HAVE_NO_MEMORY(e->Computername);

	if (t->sid_length > 0) {
		const char *sid_str = NULL;
		size_t len;
		if (!convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
					   t->sid.data, t->sid.length,
					   (void **)&sid_str, &len, false)) {
			return NT_STATUS_INVALID_SID;
		}
		if (len > 0) {
			e->UserSid = *string_sid_talloc(mem_ctx, sid_str);
		}
	}

	e->Strings		= talloc_array(mem_ctx, const char *, t->num_of_strings);
	for (i=0; i < t->num_of_strings; i++) {
		e->Strings[i] = talloc_strdup(e->Strings, t->strings[i]);
		NT_STATUS_HAVE_NO_MEMORY(e->Strings[i]);
	}

	e->Data			= (uint8_t *)talloc_memdup(mem_ctx, t->data.data, t->data_length);
	e->Pad			= talloc_strdup(mem_ctx, "");
	NT_STATUS_HAVE_NO_MEMORY(e->Pad);

	e->Length2		= t->size;

	return NT_STATUS_OK;
}
示例#26
0
/*
 * Lock record / db depending on type
 */
static struct lock_request *ctdb_lock_internal(struct ctdb_context *ctdb,
					       struct ctdb_db_context *ctdb_db,
					       TDB_DATA key,
					       uint32_t priority,
					       void (*callback)(void *, bool),
					       void *private_data,
					       enum lock_type type,
					       bool auto_mark)
{
	struct lock_context *lock_ctx = NULL;
	struct lock_request *request;

	if (callback == NULL) {
		DEBUG(DEBUG_WARNING, ("No callback function specified, not locking\n"));
		return NULL;
	}

#if 0
	/* Disable this optimization to ensure first-in-first-out fair
	 * scheduling of lock requests */

	/* get a context for this key - search only the pending contexts,
	 * current contexts might in the middle of processing callbacks */
	lock_ctx = find_lock_context(ctdb->lock_pending, ctdb_db, key, priority, type);
#endif

	/* No existing context, create one */
	if (lock_ctx == NULL) {
		lock_ctx = talloc_zero(ctdb, struct lock_context);
		if (lock_ctx == NULL) {
			DEBUG(DEBUG_ERR, ("Failed to create a new lock context\n"));
			return NULL;
		}

		lock_ctx->type = type;
		lock_ctx->ctdb = ctdb;
		lock_ctx->ctdb_db = ctdb_db;
		lock_ctx->key.dsize = key.dsize;
		if (key.dsize > 0) {
			lock_ctx->key.dptr = talloc_memdup(lock_ctx, key.dptr, key.dsize);
		} else {
			lock_ctx->key.dptr = NULL;
		}
		lock_ctx->priority = priority;
		lock_ctx->auto_mark = auto_mark;

		lock_ctx->child = -1;
		lock_ctx->block_child = -1;

		DLIST_ADD_END(ctdb->lock_pending, lock_ctx, NULL);
		ctdb->lock_num_pending++;
		CTDB_INCREMENT_STAT(ctdb, locks.num_pending);
		if (ctdb_db) {
			CTDB_INCREMENT_DB_STAT(ctdb_db, locks.num_pending);
		}

		/* Start the timer when we activate the context */
		lock_ctx->start_time = timeval_current();
	}
示例#27
0
文件: nss_util.c 项目: jhrozek/sssd
static int generate_random_key(TALLOC_CTX *mem_ctx,
                               PK11SlotInfo *slot,
                               struct crypto_mech_data *mech_props,
                               SECItem **_key)
{
    SECStatus sret;
    SECItem      *randkeydata;
    SECItem      *key = NULL;
    PK11SymKey   *randkey;
    int ret;

    randkey = PK11_KeyGen(slot, mech_props->cipher,
                          NULL, mech_props->keylen, NULL);
    if (randkey == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Failure to generate key (err %d)\n",
              PR_GetError());
        ret = EIO;
        goto done;
    }

    sret = PK11_ExtractKeyValue(randkey);
    if (sret != SECSuccess) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Failure to extract key value (err %d)\n",
              PR_GetError());
        ret = EIO;
        goto done;
    }

    randkeydata = PK11_GetKeyData(randkey);
    if (randkeydata == NULL) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Failure to get key data (err %d)\n",
              PR_GetError());
        ret = EIO;
        goto done;
    }

    /* randkeydata is valid until randkey is. Copy with talloc to
     * get a nice memory hierarchy symmetrical in encrypt
     * and decrypt case */
    key = talloc_zero(mem_ctx, SECItem);
    if (!key) {
        ret = ENOMEM;
        goto done;
    }

    key->data = talloc_memdup(key, randkeydata->data, randkeydata->len);
    if (!key->data) {
        ret = ENOMEM;
        goto done;
    }
    key->len = randkeydata->len;

    *_key = key;
    ret = EOK;
done:
    if (ret != EOK) talloc_zfree(key);
    PK11_FreeSymKey(randkey);
    return ret;
}
示例#28
0
/*
  perform the send side of a async dcerpc request
*/
static struct rpc_request *dcerpc_request_send(struct dcerpc_pipe *p, 
					       const struct GUID *object,
					       uint16_t opnum,
					       bool async,
					       DATA_BLOB *stub_data)
{
	struct rpc_request *req;

	p->conn->transport.recv_data = dcerpc_recv_data;

	req = talloc(p, struct rpc_request);
	if (req == NULL) {
		return NULL;
	}

	req->p = p;
	req->call_id = next_call_id(p->conn);
	req->status = NT_STATUS_OK;
	req->state = RPC_REQUEST_QUEUED;
	req->payload = data_blob(NULL, 0);
	req->flags = 0;
	req->fault_code = 0;
	req->async_call = async;
	req->ignore_timeout = false;
	req->async.callback = NULL;
	req->async.private_data = NULL;
	req->recv_handler = NULL;

	if (object != NULL) {
		req->object = (struct GUID *)talloc_memdup(req, (const void *)object, sizeof(*object));
		if (req->object == NULL) {
			talloc_free(req);
			return NULL;
		}
	} else {
		req->object = NULL;
	}

	req->opnum = opnum;
	req->request_data.length = stub_data->length;
	req->request_data.data = talloc_reference(req, stub_data->data);
	if (req->request_data.length && req->request_data.data == NULL) {
		return NULL;
	}

	DLIST_ADD_END(p->conn->request_queue, req, struct rpc_request *);
	talloc_set_destructor(req, dcerpc_req_dequeue);

	dcerpc_ship_next_request(p->conn);

	if (p->request_timeout) {
		event_add_timed(dcerpc_event_context(p), req, 
				timeval_current_ofs(p->request_timeout, 0), 
				dcerpc_timeout_handler, req);
	}

	return req;
}
示例#29
0
/*
  test two schannel connections
 */
bool torture_rpc_schannel2(struct torture_context *torture)
{
	struct test_join *join_ctx;
	NTSTATUS status;
	const char *binding = torture_setting_string(torture, "binding", NULL);
	struct dcerpc_binding *b;
	struct dcerpc_pipe *p1 = NULL, *p2 = NULL;
	struct cli_credentials *credentials1, *credentials2;
	uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SIGN;

	join_ctx = torture_join_domain(torture, talloc_asprintf(torture, "%s2", TEST_MACHINE_NAME),
				       ACB_WSTRUST, &credentials1);
	torture_assert(torture, join_ctx != NULL,
		       "Failed to join domain with acct_flags=ACB_WSTRUST");

	credentials2 = (struct cli_credentials *)talloc_memdup(torture, credentials1, sizeof(*credentials1));
	credentials1->netlogon_creds = NULL;
	credentials2->netlogon_creds = NULL;

	status = dcerpc_parse_binding(torture, binding, &b);
	torture_assert_ntstatus_ok(torture, status, "Bad binding string");

	b->flags &= ~DCERPC_AUTH_OPTIONS;
	b->flags |= dcerpc_flags;

	torture_comment(torture, "Opening first connection\n");
	status = dcerpc_pipe_connect_b(torture, &p1, b, &ndr_table_netlogon,
				       credentials1, torture->ev, torture->lp_ctx);
	torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");

	torture_comment(torture, "Opening second connection\n");
	status = dcerpc_pipe_connect_b(torture, &p2, b, &ndr_table_netlogon,
				       credentials2, torture->ev, torture->lp_ctx);
	torture_assert_ntstatus_ok(torture, status, "Failed to connect with schannel");

	credentials1->netlogon_creds = NULL;
	credentials2->netlogon_creds = NULL;

	torture_comment(torture, "Testing logon on pipe1\n");
	if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
		return false;

	torture_comment(torture, "Testing logon on pipe2\n");
	if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
		return false;

	torture_comment(torture, "Again on pipe1\n");
	if (!test_netlogon_ex_ops(p1, torture, credentials1, NULL))
		return false;

	torture_comment(torture, "Again on pipe2\n");
	if (!test_netlogon_ex_ops(p2, torture, credentials2, NULL))
		return false;

	torture_leave_domain(torture, join_ctx);
	return true;
}
示例#30
0
文件: dbwrap.c 项目: srimalik/samba
static void dbwrap_fetch_parser(TDB_DATA key, TDB_DATA data,
				void *private_data)
{
	struct dbwrap_fetch_state *state =
		(struct dbwrap_fetch_state *)private_data;

	state->data.dsize = data.dsize;
	state->data.dptr = (uint8_t *)talloc_memdup(state->mem_ctx, data.dptr,
						    data.dsize);
}