예제 #1
0
static int collect_sessions_fn(struct smbXsrv_session_global0 *global,
			       void *connections_forall_state)
{
	NTSTATUS status;
	struct connections_forall_state *state =
		(struct connections_forall_state*)connections_forall_state;

	uint32_t id = global->session_global_id;
	struct connections_forall_session sess;

	if (global->auth_session_info == NULL) {
		sess.uid = -1;
		sess.gid = -1;
	} else {
		sess.uid = global->auth_session_info->unix_token->uid;
		sess.gid = global->auth_session_info->unix_token->gid;
	}
	fstrcpy(sess.machine, global->channels[0].remote_name);
	fstrcpy(sess.addr, global->channels[0].remote_address);
	sess.cipher = global->channels[0].encryption_cipher;
	sess.dialect = global->connection_dialect;
	sess.signing_flags = global->signing_flags;

	status = dbwrap_store(state->session_by_pid,
			      make_tdb_data((void*)&id, sizeof(id)),
			      make_tdb_data((void*)&sess, sizeof(sess)),
			      TDB_INSERT);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0, ("Failed to store record: %s\n", nt_errstr(status)));
	}
	return 0;
}
예제 #2
0
static NTSTATUS dbwrap_cache_parse_record(
	struct db_context *db, TDB_DATA key,
	void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data),
	void *private_data)
{
	struct db_cache_ctx *ctx = talloc_get_type_abort(
		db->private_data, struct db_cache_ctx);
	TDB_DATA value;
	NTSTATUS status;

	if (!dbwrap_cache_validate(ctx)) {
		return NT_STATUS_NO_MEMORY;
	}

	if (dbwrap_exists(ctx->negative, key)) {
		return NT_STATUS_NOT_FOUND;
	}
	status = dbwrap_parse_record(ctx->positive, key, parser, private_data);
	if (NT_STATUS_IS_OK(status)) {
		return status;
	}

	status = dbwrap_fetch(ctx->backing, talloc_tos(), key, &value);

	if (NT_STATUS_IS_OK(status)) {
		dbwrap_store(ctx->positive, key, value, 0);
		parser(key, value, private_data);
		TALLOC_FREE(value.dptr);
		return NT_STATUS_OK;
	}

	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
		char c = '\0';
		value.dptr = (uint8_t *)&c;
		value.dsize = sizeof(c);
		dbwrap_store(ctx->negative, key, value, 0);
		return NT_STATUS_NOT_FOUND;
	}
	return status;
}
예제 #3
0
static NTSTATUS fss_state_sc_store(TALLOC_CTX *mem_ctx,
				   struct db_context *db,
				   const char *sc_set_key_str,
				   struct fss_sc *sc)
{
	NTSTATUS status;
	TDB_DATA val;
	const char *sc_key_str;
	struct fsrvp_state_sc sc_state;
	struct fss_sc_smap *smap;
	enum ndr_err_code ndr_ret;
	DATA_BLOB sc_state_blob;

	/* becomes sc_set/@sc_set.id/sc/@sc_id */
	sc_key_str = talloc_asprintf(mem_ctx, "%s/%s%s", sc_set_key_str,
				     FSS_DB_KEY_PFX_SC, sc->id_str);
	if (sc_key_str == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	sc_state.id_str = sc->id_str;
	sc_state.volume_name = sc->volume_name;
	/* @sc->sc_path may be null if not committed, store empty str */
	sc_state.sc_path = (sc->sc_path ? sc->sc_path : "");
	sc_state.create_ts = sc->create_ts;
	sc_state.smaps_count = sc->smaps_count;

	ndr_ret = ndr_push_struct_blob(&sc_state_blob, mem_ctx,
				       &sc_state,
				(ndr_push_flags_fn_t)ndr_push_fsrvp_state_sc);
	if (ndr_ret != NDR_ERR_SUCCESS) {
		return NT_STATUS_INTERNAL_ERROR;
	}

	val.dsize = sc_state_blob.length;
	val.dptr = sc_state_blob.data;

	status = dbwrap_store(db, string_term_tdb_data(sc_key_str), val, 0);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	for (smap = sc->smaps; smap; smap = smap->next) {
		status = fss_state_smap_store(mem_ctx, db, sc_key_str, smap);
		if (!NT_STATUS_IS_OK(status)) {
			return status;
		}
	}

	return NT_STATUS_OK;
}
예제 #4
0
static NTSTATUS fss_state_sc_set_store(TALLOC_CTX *mem_ctx,
				       struct db_context *db,
				       struct fss_sc_set *sc_set)
{
	NTSTATUS status;
	TDB_DATA val;
	const char *sc_set_key_str;
	struct fss_sc *sc;
	struct fsrvp_state_sc_set sc_set_state;
	DATA_BLOB sc_set_state_blob;
	enum ndr_err_code ndr_ret;

	sc_set_key_str = talloc_asprintf(mem_ctx, "%s%s",
					 FSS_DB_KEY_PFX_SC_SET,
					 sc_set->id_str);
	if (sc_set_key_str == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	sc_set_state.id_str = sc_set->id_str;
	sc_set_state.state = sc_set->state;
	sc_set_state.context = sc_set->context;
	sc_set_state.scs_count = sc_set->scs_count;

	ndr_ret = ndr_push_struct_blob(&sc_set_state_blob, mem_ctx,
				       &sc_set_state,
			(ndr_push_flags_fn_t)ndr_push_fsrvp_state_sc_set);
	if (ndr_ret != NDR_ERR_SUCCESS) {
		return NT_STATUS_INTERNAL_ERROR;
	}

	val.dsize = sc_set_state_blob.length;
	val.dptr = sc_set_state_blob.data;

	status = dbwrap_store(db, string_term_tdb_data(sc_set_key_str), val, 0);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	for (sc = sc_set->scs; sc; sc = sc->next) {
		status = fss_state_sc_store(mem_ctx, db, sc_set_key_str, sc);
		if (!NT_STATUS_IS_OK(status)) {
			return status;
		}
	}

	return NT_STATUS_OK;
}
예제 #5
0
static NTSTATUS fss_state_smap_store(TALLOC_CTX *mem_ctx,
				     struct db_context *db,
				     const char *sc_key_str,
				     struct fss_sc_smap *smap)
{
	NTSTATUS status;
	TDB_DATA val;
	const char *smap_key_str;
	struct fsrvp_state_smap smap_state;
	enum ndr_err_code ndr_ret;
	DATA_BLOB smap_state_blob;

	/* becomes sc_set/@sc_set_id/sc/@sc_id/smap/@sc_share_name */
	smap_key_str = talloc_asprintf(mem_ctx, "%s/%s%s", sc_key_str,
				       FSS_DB_KEY_PFX_SMAP,
				       smap->sc_share_name);
	if (smap_key_str == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	smap_state.share_name = smap->share_name;
	smap_state.sc_share_name = smap->sc_share_name;
	/* @smap->sc_share_comment may be null if not exposed. */
	if (smap->sc_share_comment != NULL) {
		smap_state.sc_share_comment = smap->sc_share_comment;
	} else {
		smap_state.sc_share_comment = "";
	}
	smap_state.is_exposed = smap->is_exposed;

	ndr_ret = ndr_push_struct_blob(&smap_state_blob, mem_ctx,
				       &smap_state,
				(ndr_push_flags_fn_t)ndr_push_fsrvp_state_smap);
	if (ndr_ret != NDR_ERR_SUCCESS) {
		return NT_STATUS_INTERNAL_ERROR;
	}

	val.dsize = smap_state_blob.length;
	val.dptr = smap_state_blob.data;

	status = dbwrap_store(db, string_term_tdb_data(smap_key_str), val, 0);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	return NT_STATUS_OK;
}
예제 #6
0
/*****************************************************************************
 For idmap conversion: convert one record to new format
 Ancient versions (eg 2.2.3a) of winbindd_idmap.tdb mapped DOMAINNAME/rid
 instead of the SID.
*****************************************************************************/
static int convert_fn(struct db_record *rec, void *private_data)
{
	struct winbindd_domain *domain;
	char *p;
	NTSTATUS status;
	struct dom_sid sid;
	uint32 rid;
	fstring keystr;
	fstring dom_name;
	TDB_DATA key;
	TDB_DATA key2;
	TDB_DATA value;
	struct convert_fn_state *s = (struct convert_fn_state *)private_data;

	key = dbwrap_record_get_key(rec);

	DEBUG(10,("Converting %s\n", (const char *)key.dptr));

	p = strchr((const char *)key.dptr, '/');
	if (!p)
		return 0;

	*p = 0;
	fstrcpy(dom_name, (const char *)key.dptr);
	*p++ = '/';

	domain = find_domain_from_name(dom_name);
	if (domain == NULL) {
		/* We must delete the old record. */
		DEBUG(0,("Unable to find domain %s\n", dom_name ));
		DEBUG(0,("deleting record %s\n", (const char *)key.dptr ));

		status = dbwrap_record_delete(rec);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0, ("Unable to delete record %s:%s\n",
				(const char *)key.dptr,
				nt_errstr(status)));
			s->failed = true;
			return -1;
		}

		return 0;
	}

	rid = atoi(p);

	sid_compose(&sid, &domain->sid, rid);

	sid_to_fstring(keystr, &sid);
	key2 = string_term_tdb_data(keystr);

	value = dbwrap_record_get_value(rec);

	status = dbwrap_store(s->db, key2, value, TDB_INSERT);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0,("Unable to add record %s:%s\n",
			(const char *)key2.dptr,
			nt_errstr(status)));
		s->failed = true;
		return -1;
	}

	status = dbwrap_store(s->db, value, key2, TDB_REPLACE);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0,("Unable to update record %s:%s\n",
			(const char *)value.dptr,
			nt_errstr(status)));
		s->failed = true;
		return -1;
	}

	status = dbwrap_record_delete(rec);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0,("Unable to delete record %s:%s\n",
			(const char *)key.dptr,
			nt_errstr(status)));
		s->failed = true;
		return -1;
	}

	return 0;
}
예제 #7
0
NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
			       TDB_DATA data, int flags)
{
	return dbwrap_store(db, string_term_tdb_data(key), data, flags);
}
예제 #8
0
static int upgrade_v2_to_v3(struct db_record *rec, void *priv)
{
	size_t prefix_len = strlen(SHARE_SECURITY_DB_KEY_PREFIX_STR);
	const char *servicename = NULL;
	char *c_servicename = NULL;
	char *newkey = NULL;
	bool *p_upgrade_ok = (bool *)priv;
	NTSTATUS status;
	TDB_DATA key;
	TDB_DATA value;

	key = dbwrap_record_get_key(rec);

	/* Is there space for a one character sharename ? */
	if (key.dsize <= prefix_len+2) {
		return 0;
	}

	/* Does it start with the share key prefix ? */
	if (memcmp(key.dptr, SHARE_SECURITY_DB_KEY_PREFIX_STR,
			prefix_len) != 0) {
		return 0;
	}

	/* Is it a null terminated string as a key ? */
	if (key.dptr[key.dsize-1] != '\0') {
		return 0;
	}

	/* Bytes after the prefix are the sharename string. */
	servicename = (char *)&key.dptr[prefix_len];
	c_servicename = canonicalize_servicename(talloc_tos(), servicename);
	if (!c_servicename) {
		smb_panic("out of memory upgrading share security db from v2 -> v3");
	}

	if (strcmp(servicename, c_servicename) == 0) {
		/* Old and new names match. No canonicalization needed. */
		TALLOC_FREE(c_servicename);
		return 0;
	}

	/* Oops. Need to canonicalize name, delete old then store new. */
	status = dbwrap_record_delete(rec);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("upgrade_v2_to_v3: Failed to delete secdesc for "
			  "%s: %s\n", (const char *)key.dptr,
			  nt_errstr(status)));
		TALLOC_FREE(c_servicename);
		*p_upgrade_ok = false;
		return -1;
	} else {
		DEBUG(10, ("upgrade_v2_to_v3: deleted secdesc for "
                          "%s\n", (const char *)key.dptr));
	}

	if (!(newkey = talloc_asprintf(talloc_tos(),
			SHARE_SECURITY_DB_KEY_PREFIX_STR "%s",
			c_servicename))) {
		smb_panic("out of memory upgrading share security db from v2 -> v3");
	}

	value = dbwrap_record_get_value(rec);
	status = dbwrap_store(share_db,
				string_term_tdb_data(newkey),
				value,
				TDB_REPLACE);

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("upgrade_v2_to_v3: Failed to store secdesc for "
			  "%s: %s\n", c_servicename, nt_errstr(status)));
		TALLOC_FREE(c_servicename);
		TALLOC_FREE(newkey);
		*p_upgrade_ok = false;
		return -1;
	} else {
		DEBUG(10, ("upgrade_v2_to_v3: stored secdesc for "
                          "%s\n", newkey ));
	}

	TALLOC_FREE(newkey);
	TALLOC_FREE(c_servicename);

	return 0;
}