Esempio n. 1
0
bool serverid_exists(const struct server_id *id)
{
	bool result = false;
	bool ok = false;

	ok = serverids_exist(id, 1, &result);
	if (!ok) {
		return false;
	}

	return result;
}
Esempio n. 2
0
static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
						 const TDB_DATA dbuf)
{
	struct share_mode_data *d;
	int i;
	struct server_id *pids;
	bool *pid_exists;
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;

	d = talloc_zero(mem_ctx, struct share_mode_data);
	if (d == NULL) {
		DEBUG(0, ("talloc failed\n"));
		goto fail;
	}

	blob.data = dbuf.dptr;
	blob.length = dbuf.dsize;

	ndr_err = ndr_pull_struct_blob(
		&blob, d, d, (ndr_pull_flags_fn_t)ndr_pull_share_mode_data);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		DEBUG(1, ("ndr_pull_share_mode_lock failed\n"));
		goto fail;
	}

	d->modified = false;
	d->fresh = false;

	if (DEBUGLEVEL >= 10) {
		DEBUG(10, ("parse_share_modes:\n"));
		NDR_PRINT_DEBUG(share_mode_data, d);
	}

	/*
	 * Ensure that each entry has a real process attached.
	 */

	pids = talloc_array(talloc_tos(), struct server_id,
			    d->num_share_modes);
	if (pids == NULL) {
		DEBUG(0, ("talloc failed\n"));
		goto fail;
	}
	pid_exists = talloc_array(talloc_tos(), bool, d->num_share_modes);
	if (pid_exists == NULL) {
		DEBUG(0, ("talloc failed\n"));
		goto fail;
	}

	for (i=0; i<d->num_share_modes; i++) {
		pids[i] = d->share_modes[i].pid;
	}
	if (!serverids_exist(pids, d->num_share_modes, pid_exists)) {
		DEBUG(0, ("serverid_exists failed\n"));
		goto fail;
	}

	i = 0;
	while (i < d->num_share_modes) {
		struct share_mode_entry *e = &d->share_modes[i];
		if (!pid_exists[i]) {
			*e = d->share_modes[d->num_share_modes-1];
			d->num_share_modes -= 1;
			d->modified = True;
			continue;
		}
		i += 1;
	}
	TALLOC_FREE(pid_exists);
	TALLOC_FREE(pids);
	return d;
fail:
	TALLOC_FREE(d);
	return NULL;
}