Exemplo n.º 1
0
static int check_filesystem(TDB_CONTEXT *tdb, io_channel channel)
{
	__u32   s_mtime;
	__u8    s_uuid[16];
	errcode_t retval;
	TDB_DATA tdb_key, tdb_data;
	struct ext2_super_block super;

	io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
	retval = io_channel_read_blk64(channel, 1, -SUPERBLOCK_SIZE, &super);
	if (retval) {
		com_err(prg_name,
			retval, _("Failed to read the file system data \n"));
		return retval;
	}

	tdb_key.dptr = mtime_key;
	tdb_key.dsize = sizeof(mtime_key);
	tdb_data = tdb_fetch(tdb, tdb_key);
	if (!tdb_data.dptr) {
		retval = EXT2_ET_TDB_SUCCESS + tdb_error(tdb);
		com_err(prg_name, retval,
			_("Failed tdb_fetch %s\n"), tdb_errorstr(tdb));
		return retval;
	}

	s_mtime = *(__u32 *)tdb_data.dptr;
	if (super.s_mtime != s_mtime) {

		com_err(prg_name, 0,
			_("The file system Mount time didn't match %u\n"),
			s_mtime);

		return  -1;
	}


	tdb_key.dptr = uuid_key;
	tdb_key.dsize = sizeof(uuid_key);
	tdb_data = tdb_fetch(tdb, tdb_key);
	if (!tdb_data.dptr) {
		retval = EXT2_ET_TDB_SUCCESS + tdb_error(tdb);
		com_err(prg_name, retval,
			_("Failed tdb_fetch %s\n"), tdb_errorstr(tdb));
		return retval;
	}
	memcpy(s_uuid, tdb_data.dptr, sizeof(s_uuid));
	if (memcmp(s_uuid, super.s_uuid, sizeof(s_uuid))) {
		com_err(prg_name, 0,
			_("The file system UUID didn't match \n"));
		return -1;
	}

	return 0;
}
Exemplo n.º 2
0
static NTSTATUS tdbsam_delete_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_pass)
{
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
	TDB_CONTEXT 	*pwd_tdb;
	TDB_DATA 	key;
	fstring 	keystr;
	uint32		rid;
	fstring		name;
	
	fstrcpy(name, pdb_get_username(sam_pass));
	strlower_m(name);
	
	/* open the TDB */
	if (!(pwd_tdb = tdb_open_log(tdb_state->tdbsam_location, 0, TDB_DEFAULT, O_RDWR, 0600))) {
		DEBUG(0, ("Unable to open TDB passwd!"));
		return nt_status;
	}
  
  	/* set the search key */
	slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
	key.dptr = keystr;
	key.dsize = strlen (keystr) + 1;
	
	rid = pdb_get_user_rid(sam_pass);

	/* it's outaa here!  8^) */
	if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
		DEBUG(5, ("Error deleting entry from tdb passwd database!\n"));
		DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
		tdb_close(pwd_tdb); 
		return nt_status;
	}	

	/* delete also the RID key */

  	/* set the search key */
	slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
	key.dptr = keystr;
	key.dsize = strlen (keystr) + 1;

	/* it's outaa here!  8^) */
	if (tdb_delete(pwd_tdb, key) != TDB_SUCCESS) {
		DEBUG(5, ("Error deleting entry from tdb rid database!\n"));
		DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
		tdb_close(pwd_tdb); 
		return nt_status;
	}
	
	tdb_close(pwd_tdb);
	
	return NT_STATUS_OK;
}
Exemplo n.º 3
0
static void terror(enum TDB_ERROR err, const char *why)
{
	if (err != TDB_SUCCESS)
		printf("%s:%s\n", tdb_errorstr(err), why);
	else
		printf("%s\n", why);
}
Exemplo n.º 4
0
static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir)
{
    struct dir_info_db	*db = ctx->dir_info;
    struct dir_info_ent	buf;
    TDB_DATA		key, data;

#ifdef DIRINFO_DEBUG
    printf("e2fsck_put_dir_info (%d, %d, %d)...", dir->ino, dir->dotdot,
           dir->parent);
#endif

    if (!db->tdb)
        return;

    buf.parent = dir->parent;
    buf.dotdot = dir->dotdot;

    key.dptr = (unsigned char *) &dir->ino;
    key.dsize = sizeof(ext2_ino_t);
    data.dptr = (unsigned char *) &buf;
    data.dsize = sizeof(buf);

    if (tdb_store(db->tdb, key, data, TDB_REPLACE) == -1) {
        printf("store failed: %s\n", tdb_errorstr(db->tdb));
    }
    return;
}
Exemplo n.º 5
0
static BOOL allowable_number_of_smbd_processes(void)
{
	int max_processes = lp_max_smbd_processes();

	if (!max_processes)
		return True;

	{
		TDB_CONTEXT *tdb = conn_tdb_ctx();
		int32 val;
		if (!tdb) {
			DEBUG(0,("allowable_number_of_smbd_processes: can't open connection tdb.\n" ));
			return False;
		}

		val = tdb_fetch_int32(tdb, "INFO/total_smbds");
		if (val == -1 && (tdb_error(tdb) != TDB_ERR_NOEXIST)) {
			DEBUG(0,("allowable_number_of_smbd_processes: can't fetch INFO/total_smbds. Error %s\n",
				tdb_errorstr(tdb) ));
			return False;
		}
		if (val > max_processes) {
			DEBUG(0,("allowable_number_of_smbd_processes: number of processes (%d) is over allowed limit (%d)\n",
				val, max_processes ));
			return False;
		}
	}
	return True;
}
Exemplo n.º 6
0
static int lock_record(const char *dbpath, const char *dbflags, const char *dbkey)
{
	TDB_DATA key;
	struct tdb_context *tdb;
	int tdb_flags;

	/* No error checking since CTDB always passes sane values */
	tdb_flags = strtol(dbflags, NULL, 0);

	/* Convert hex key to key */
	if (strcmp(dbkey, "NULL") == 0) {
		key.dptr = NULL;
		key.dsize = 0;
	} else {
		key.dptr = hex_decode_talloc(NULL, dbkey, &key.dsize);
	}

	tdb = tdb_open(dbpath, 0, tdb_flags, O_RDWR, 0600);
	if (tdb == NULL) {
		fprintf(stderr, "%s: Error opening database %s\n", progname, dbpath);
		return 1;
	}

	if (tdb_chainlock(tdb, key) < 0) {
		fprintf(stderr, "%s: Error getting record lock (%s)\n",
			progname, tdb_errorstr(tdb));
		return 1;
	}

	return 0;

}
Exemplo n.º 7
0
/*
 * Transaction end
 */
int partition_metadata_end_trans(struct ldb_module *module)
{
	struct partition_private_data *data;
	struct tdb_context *tdb;

	data = talloc_get_type_abort(ldb_module_get_private(module),
				     struct partition_private_data);
	if (!data || !data->metadata || !data->metadata->db) {
		return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
					"partition_metadata: metadata not initialized");
	}
	tdb = data->metadata->db->tdb;

	if (data->metadata->in_transaction == 0) {
		return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
					"partition_metadata: not in transaction");
	}

	data->metadata->in_transaction--;

	if (tdb_transaction_commit(tdb) != 0) {
		return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
					tdb_errorstr(tdb));
	}

	return LDB_SUCCESS;
}
Exemplo n.º 8
0
static int lock_db(const char *dbpath, const char *dbflags)
{
	struct tdb_context *tdb;
	int tdb_flags;

	/* No error checking since CTDB always passes sane values */
	tdb_flags = strtol(dbflags, NULL, 0);

	tdb = tdb_open(dbpath, 0, tdb_flags, O_RDWR, 0600);
	if (tdb == NULL) {
		fprintf(stderr, "%s: Error opening database %s\n", progname, dbpath);
		return 1;
	}

	set_priority();

	if (tdb_lockall(tdb) < 0) {
		fprintf(stderr, "%s: Error getting db lock (%s)\n",
			progname, tdb_errorstr(tdb));
		return 1;
	}

	reset_priority();

	return 0;
}
Exemplo n.º 9
0
static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *udp)
{
	struct connections_data crec;
	struct count_stat *cs = (struct count_stat *)udp;
 
	if (dbuf.dsize != sizeof(crec))
		return 0;

	memcpy(&crec, dbuf.dptr, sizeof(crec));
 
	if (crec.cnum == -1)
		return 0;

	/* If the pid was not found delete the entry from connections.tdb */

	if (cs->Clear && !process_exists(crec.pid) && (errno == ESRCH)) {
		DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n",
			(unsigned int)crec.pid, crec.cnum, crec.name));
		if (tdb_delete(the_tdb, kbuf) != 0)
			DEBUG(0,("count_fn: tdb_delete failed with error %s\n", tdb_errorstr(tdb) ));
		return 0;
	}

	if (strequal(crec.name, cs->name))
		cs->curr_connections++;

	return 0;
}
Exemplo n.º 10
0
/*
  unlock a record in the ltdb, given a key
 */
int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key)
{
	int ret = tdb_chainunlock(ctdb_db->ltdb->tdb, key);
	if (ret != 0) {
 		DEBUG(DEBUG_ERR,("tdb_chainunlock failed on db %s [%s]\n", ctdb_db->db_name, tdb_errorstr(ctdb_db->ltdb->tdb)));
	}
	return ret;
}
Exemplo n.º 11
0
/*
 * Write a key with uin64 value
 */
static int partition_metadata_set_uint64(struct ldb_module *module,
					 const char *key, uint64_t value,
					 bool insert)
{
	struct partition_private_data *data;
	struct tdb_context *tdb;
	TDB_DATA tdb_key, tdb_data;
	int tdb_flag;
	char *value_str;
	TALLOC_CTX *tmp_ctx;

	data = talloc_get_type_abort(ldb_module_get_private(module),
				     struct partition_private_data);

	if (!data || !data->metadata || !data->metadata->db) {
		return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
					"partition_metadata: metadata tdb not initialized");
	}

	tmp_ctx = talloc_new(NULL);
	if (tmp_ctx == NULL) {
		return ldb_module_oom(module);
	}

	tdb = data->metadata->db->tdb;

	value_str = talloc_asprintf(tmp_ctx, "%llu", (unsigned long long)value);
	if (value_str == NULL) {
		talloc_free(tmp_ctx);
		return ldb_module_oom(module);
	}

	tdb_key.dptr = (uint8_t *)discard_const_p(char, key);
	tdb_key.dsize = strlen(key);

	tdb_data.dptr = (uint8_t *)value_str;
	tdb_data.dsize = strlen(value_str);

	if (insert) {
		tdb_flag = TDB_INSERT;
	} else {
		tdb_flag = TDB_MODIFY;
	}

	if (tdb_store(tdb, tdb_key, tdb_data, tdb_flag) != 0) {
		int ret;
		char *error_string = talloc_asprintf(tmp_ctx, "%s: tdb_store of key %s failed: %s",
						     tdb_name(tdb), key, tdb_errorstr(tdb));
		ret = ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
				       error_string);
		talloc_free(tmp_ctx);
		return ret;
	}

	talloc_free(tmp_ctx);

	return LDB_SUCCESS;
}
Exemplo n.º 12
0
static void info_tdb(void)
{
  int count;
  total_bytes = 0;
  if ((count = tdb_traverse(tdb, traverse_fn, NULL) == -1))
    printf("Error = %s\n", tdb_errorstr(tdb));
  else
    printf("%d records totalling %d bytes\n", count, total_bytes);
}
Exemplo n.º 13
0
static void tdb_log(struct tdb_context *tdb,
		    enum tdb_log_level level,
		    enum TDB_ERROR ecode,
		    const char *message,
		    void *data)
{
	fprintf(stderr, "tdb:%s:%s:%s\n",
		tdb_name(tdb), tdb_errorstr(ecode), message);
}
Exemplo n.º 14
0
static void info_tdb(void)
{
	char *summary = tdb_summary(tdb);

	if (!summary) {
		printf("Error = %s\n", tdb_errorstr(tdb));
	} else {
		printf("%s", summary);
		free(summary);
	}
}
Exemplo n.º 15
0
BOOL register_message_flags(BOOL doreg, uint32 msg_flags)
{
	struct connections_key key;
	struct connections_data *pcrec;
	TDB_DATA kbuf, dbuf;

	if (!tdb)
		return False;

	DEBUG(10,("register_message_flags: %s flags 0x%x\n",
		doreg ? "adding" : "removing",
		(unsigned int)msg_flags ));

	make_conn_key(NULL, "", &kbuf, &key);

        dbuf = tdb_fetch(tdb, kbuf);
        if (!dbuf.dptr) {
		DEBUG(0,("register_message_flags: tdb_fetch failed: %s\n",
			tdb_errorstr(tdb)));
		return False;
	}

	pcrec = (struct connections_data *)dbuf.dptr;
	if (doreg)
		pcrec->bcast_msg_flags |= msg_flags;
	else
		pcrec->bcast_msg_flags &= ~msg_flags;

	if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) {
		DEBUG(0,("register_message_flags: tdb_store failed: %s.\n",
			tdb_errorstr(tdb) ));
		SAFE_FREE(dbuf.dptr);
		return False;
	}

	DEBUG(10,("register_message_flags: new flags 0x%x\n",
		(unsigned int)pcrec->bcast_msg_flags ));

	SAFE_FREE(dbuf.dptr);
	return True;
}
Exemplo n.º 16
0
/*
 * Read a key with uint64 value
 */
static int partition_metadata_get_uint64(struct ldb_module *module,
					 const char *key, uint64_t *value,
					 uint64_t default_value)
{
	struct partition_private_data *data;
	struct tdb_context *tdb;
	TDB_DATA tdb_key, tdb_data;
	char *value_str;
	TALLOC_CTX *tmp_ctx;

	data = talloc_get_type_abort(ldb_module_get_private(module),
				     struct partition_private_data);

	if (!data || !data->metadata || !data->metadata->db) {
		return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
					"partition_metadata: metadata tdb not initialized");
	}

	tmp_ctx = talloc_new(NULL);
	if (tmp_ctx == NULL) {
		return ldb_module_oom(module);
	}

	tdb = data->metadata->db->tdb;

	tdb_key.dptr = (uint8_t *)discard_const_p(char, key);
	tdb_key.dsize = strlen(key);

	tdb_data = tdb_fetch(tdb, tdb_key);
	if (!tdb_data.dptr) {
		if (tdb_error(tdb) == TDB_ERR_NOEXIST) {
			*value = default_value;
			return LDB_SUCCESS;
		} else {
			return ldb_module_error(module, LDB_ERR_OPERATIONS_ERROR,
						tdb_errorstr(tdb));
		}
	}

	value_str = talloc_strndup(tmp_ctx, (char *)tdb_data.dptr, tdb_data.dsize);
	if (value_str == NULL) {
		SAFE_FREE(tdb_data.dptr);
		talloc_free(tmp_ctx);
		return ldb_module_oom(module);
	}

	*value = strtoull(value_str, NULL, 10);

	SAFE_FREE(tdb_data.dptr);
	talloc_free(tmp_ctx);

	return LDB_SUCCESS;
}
Exemplo n.º 17
0
static
NTSTATUS schannel_store_session_key_tdb(struct tdb_wrap *tdb_sc,
					TALLOC_CTX *mem_ctx,
					struct netlogon_creds_CredentialState *creds)
{
	enum ndr_err_code ndr_err;
	DATA_BLOB blob;
	TDB_DATA value;
	int ret;
	char *keystr;
	char *name_upper;

	name_upper = strupper_talloc(mem_ctx, creds->computer_name);
	if (!name_upper) {
		return NT_STATUS_NO_MEMORY;
	}

	keystr = talloc_asprintf(mem_ctx, "%s/%s",
				 SECRETS_SCHANNEL_STATE, name_upper);
	TALLOC_FREE(name_upper);
	if (!keystr) {
		return NT_STATUS_NO_MEMORY;
	}

	ndr_err = ndr_push_struct_blob(&blob, mem_ctx, creds,
			(ndr_push_flags_fn_t)ndr_push_netlogon_creds_CredentialState);
	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
		talloc_free(keystr);
		return ndr_map_error2ntstatus(ndr_err);
	}

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

	ret = tdb_store_bystring(tdb_sc->tdb, keystr, value, TDB_REPLACE);
	if (ret != TDB_SUCCESS) {
		DEBUG(0,("Unable to add %s to session key db - %s\n",
			 keystr, tdb_errorstr(tdb_sc->tdb)));
		talloc_free(keystr);
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	DEBUG(3,("schannel_store_session_key_tdb: stored schannel info with key %s\n",
		keystr));

	if (DEBUGLEVEL >= 10) {
		NDR_PRINT_DEBUG(netlogon_creds_CredentialState, creds);
	}

	talloc_free(keystr);

	return NT_STATUS_OK;
}
Exemplo n.º 18
0
static int tdb_ass_subscript(tdb_hnd_object *obj, PyObject *key, PyObject *value)
{
	TDB_DATA krec, drec;

        if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize)) {
		PyErr_SetString(PyExc_TypeError,
				"tdb mappings have string indices only");
		return -1;
	}

        if (!obj->tdb) {
		PyErr_SetString(
			py_tdb_error, "tdb object has been closed"); 
		return -1; 
        }

	if (!value) {

		/* Delete value */

		if (tdb_delete(obj->tdb, krec) == -1) {
			PyErr_SetString(PyExc_KeyError,
					PyString_AsString(value));
			return -1;
		}

	} else {

		/* Set value */

		if (!PyArg_Parse(value, "s#", &drec.dptr, &drec.dsize)) {
			PyErr_SetString(PyExc_TypeError,
				    "tdb mappings have string elements only");
			return -1;
		}

		errno = 0;

		if (tdb_store(obj->tdb, krec, drec, 0) < 0 ) {
			if (errno != 0)
				PyErr_SetFromErrno(py_tdb_error);
			else
				PyErr_SetString(
					py_tdb_error, 
					(char *)tdb_errorstr(obj->tdb));

			return -1;
		}
	}

	return 0;
} 
Exemplo n.º 19
0
void tap_log_fn(struct tdb_context *tdb,
		enum tdb_log_level level,
		enum TDB_ERROR ecode,
		const char *message, void *priv)
{
	if (suppress_logging)
		return;

	diag("tdb log level %u: %s: %s%s",
	     level, tdb_errorstr(ecode), log_prefix, message);
	if (log_last)
		free(log_last);
	log_last = strdup(message);
	tap_log_messages++;
}
Exemplo n.º 20
0
static void tdb_log(struct tdb_context *tdb,
		    enum tdb_log_level level,
		    enum TDB_ERROR ecode,
		    const char *message,
		    void *data)
{
	printf("tdb:%s:%s:%s\n",
	       tdb_name(tdb), tdb_errorstr(ecode), message);
	fflush(stdout);
#if 0
	{
		char str[200];
		signal(SIGUSR1, SIG_IGN);
		sprintf(str,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid());
		system(str);
	}
#endif	
}
Exemplo n.º 21
0
static int read_rec(FILE *f, TDB_CONTEXT *tdb, int *eof)
{
	int length;
	TDB_DATA key, data;
	int ret = -1;

	key.dptr = NULL;
	data.dptr = NULL;

	if (swallow(f, "{\n", eof) == -1) {
		goto fail;
	}
	length = read_linehead(f);
	if (length == -1) {
		goto fail;
	}
	if (read_data(f, &key, length) == -1) {
		goto fail;
	}
	if (swallow(f, "\"\n", NULL) == -1) {
		goto fail;
	}
	length = read_linehead(f);
	if (length == -1) {
		goto fail;
	}
	if (read_data(f, &data, length) == -1) {
		goto fail;
	}
	if ((swallow(f, "\"\n", NULL) == -1)
	    || (swallow(f, "}\n", NULL) == -1)) {
		goto fail;
	}
	if (tdb_store(tdb, key, data, TDB_INSERT) != 0) {
		fprintf(stderr, "TDB error: %s\n", tdb_errorstr(tdb));
		goto fail;
	}

	ret = 0;
fail:
	free(key.dptr);
	free(data.dptr);
	return ret;
}
Exemplo n.º 22
0
static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods, SAM_ACCOUNT *user, uint32 rid)
{
	NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
	struct tdbsam_privates *tdb_state = (struct tdbsam_privates *)my_methods->private_data;
	TDB_CONTEXT 		*pwd_tdb;
	TDB_DATA 		data, key;
	fstring 		keystr;
	fstring			name;
	
	if (user==NULL) {
		DEBUG(0,("pdb_getsampwrid: SAM_ACCOUNT is NULL.\n"));
		return nt_status;
	}

	/* set search key */
	slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
	key.dptr = keystr;
	key.dsize = strlen (keystr) + 1;

	/* open the accounts TDB */
	if (!(pwd_tdb = tdbsam_tdbopen(tdb_state->tdbsam_location, O_RDONLY))) {
		DEBUG(0, ("pdb_getsampwrid: Unable to open TDB rid database!\n"));
		return nt_status;
	}

	/* get the record */
	data = tdb_fetch (pwd_tdb, key);
	if (!data.dptr) {
		DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr));
		DEBUGADD(5, (" Error: %s\n", tdb_errorstr(pwd_tdb)));
		tdb_close (pwd_tdb);
		return nt_status;
	}


	fstrcpy(name, data.dptr);
	SAFE_FREE(data.dptr);
	
	tdb_close (pwd_tdb);
	
	return tdbsam_getsampwnam (my_methods, user, name);
}
Exemplo n.º 23
0
/*
 * A simple interator function
 */
struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, struct dir_info_iter *iter)
{
    TDB_DATA data, key;
    struct dir_info_db *db = ctx->dir_info;
    struct dir_info_ent *buf;
    static struct dir_info ret_dir_info;

    if (!ctx->dir_info || !iter)
        return 0;

    if (db->tdb) {
        if (iter->tdb_iter.dptr == 0)
            return 0;
        key = iter->tdb_iter;
        data = tdb_fetch(db->tdb, key);
        if (!data.dptr) {
            printf("iter fetch failed: %s\n",
                   tdb_errorstr(db->tdb));
            return 0;
        }
        buf = (struct dir_info_ent *) data.dptr;
        ret_dir_info.ino = *((ext2_ino_t *) iter->tdb_iter.dptr);
        ret_dir_info.dotdot = buf->dotdot;
        ret_dir_info.parent = buf->parent;
        iter->tdb_iter = tdb_nextkey(db->tdb, key);
        free(key.dptr);
        free(data.dptr);
        return &ret_dir_info;
    }

    if (iter->i >= ctx->dir_info->count)
        return 0;

#ifdef DIRINFO_DEBUG
    printf("iter(%d, %d, %d)...", ctx->dir_info->array[iter->i].ino,
           ctx->dir_info->array[iter->i].dotdot,
           ctx->dir_info->array[iter->i].parent);
#endif
    ctx->dir_info->last_lookup = ctx->dir_info->array + iter->i++;
    return(ctx->dir_info->last_lookup);
}
Exemplo n.º 24
0
BOOL yield_connection(connection_struct *conn, const char *name)
{
	struct connections_key key;
	TDB_DATA kbuf;

	if (!tdb)
		return False;

	DEBUG(3,("Yielding connection to %s\n",name));

	make_conn_key(conn, name, &kbuf, &key);

	if (tdb_delete(tdb, kbuf) != 0) {
		int dbg_lvl = (!conn && (tdb_error(tdb) == TDB_ERR_NOEXIST)) ? 3 : 0;
		DEBUG(dbg_lvl,("yield_connection: tdb_delete for name %s failed with error %s.\n",
			name, tdb_errorstr(tdb) ));
		return (False);
	}

	return(True);
}
Exemplo n.º 25
0
/**
   \details Update a TDB record

   
 */
static enum MAPISTATUS mapi_handles_tdb_update(struct mapi_handles_context *handles_ctx,
					       uint32_t handle, uint32_t container_handle)
{
	TALLOC_CTX	*mem_ctx;
	TDB_DATA	key;
	TDB_DATA	dbuf;
	int		ret;

	/* Sanity checks */
	OPENCHANGE_RETVAL_IF(!handles_ctx, MAPI_E_NOT_INITIALIZED, NULL);
	OPENCHANGE_RETVAL_IF(!handles_ctx->tdb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
	OPENCHANGE_RETVAL_IF(!handle, MAPI_E_INVALID_PARAMETER, NULL);

	mem_ctx = talloc_named(NULL, 0, "mapi_handles_tdb_update");

	key.dptr = (unsigned char *) talloc_asprintf(mem_ctx, "0x%x", handle);
	key.dsize = strlen((const char *)key.dptr);

	/* Step 1. Makes sure the record exists */
	ret = tdb_exists(handles_ctx->tdb_ctx, key);
	OPENCHANGE_RETVAL_IF(!ret, MAPI_E_NOT_FOUND, mem_ctx);

	/* Step 2. Update record */
	dbuf.dptr = (unsigned char *) talloc_asprintf(mem_ctx, "0x%x", container_handle);
	dbuf.dsize = strlen((const char *)dbuf.dptr);

	ret = tdb_store(handles_ctx->tdb_ctx, key, dbuf, TDB_MODIFY);
	talloc_free(mem_ctx);
	if (ret == -1) {
		OC_DEBUG(3, "Unable to update 0x%x record: %s\n",
			  handle, tdb_errorstr(handles_ctx->tdb_ctx));

		return MAPI_E_CORRUPT_STORE;
	}

	return MAPI_E_SUCCESS;
}
Exemplo n.º 26
0
static int set_blk_size(TDB_CONTEXT *tdb, io_channel channel)
{
	int block_size;
	errcode_t retval;
	TDB_DATA tdb_key, tdb_data;

	tdb_key.dptr = blksize_key;
	tdb_key.dsize = sizeof(blksize_key);
	tdb_data = tdb_fetch(tdb, tdb_key);
	if (!tdb_data.dptr) {
		retval = EXT2_ET_TDB_SUCCESS + tdb_error(tdb);
		com_err(prg_name, retval,
			_("Failed tdb_fetch %s\n"), tdb_errorstr(tdb));
		return retval;
	}

	block_size = *(int *)tdb_data.dptr;
#ifdef DEBUG
	printf("Block size %d\n", block_size);
#endif
	io_channel_set_blksize(channel, block_size);

	return 0;
}
Exemplo n.º 27
0
static int sss_ncache_set_str(struct sss_nc_ctx *ctx,
                              char *str, bool permanent)
{
    TDB_DATA key;
    TDB_DATA data;
    char *timest;
    int ret;

    ret = string_to_tdb_data(str, &key);
    if (ret != EOK) return ret;

    if (permanent) {
        timest = talloc_strdup(ctx, "0");
    } else {
        timest = talloc_asprintf(ctx, "%llu",
                                 (unsigned long long int)time(NULL));
    }
    if (!timest) return ENOMEM;

    ret = string_to_tdb_data(timest, &data);
    if (ret != EOK) goto done;

    DEBUG(6, ("Adding [%s] to negative cache%s\n",
              str, permanent?" permanently":""));

    ret = tdb_store(ctx->tdb, key, data, TDB_REPLACE);
    if (ret != 0) {
        DEBUG(1, ("Negative cache failed to set entry: [%s]\n",
                  tdb_errorstr(ctx->tdb)));
        ret = EFAULT;
    }

done:
    talloc_free(timest);
    return ret;
}
Exemplo n.º 28
0
static void tdb_wrap_log(struct tdb_context *tdb,
                         enum tdb_log_level level,
                         enum TDB_ERROR ecode,
                         const char *message,
                         void *unused)
{
    int dl;
    const char *name = tdb_name(tdb);

    switch (level) {
    case TDB_LOG_USE_ERROR:
    case TDB_LOG_ERROR:
        dl = 0;
        break;
    case TDB_LOG_WARNING:
        dl = 2;
        break;
    default:
        dl = 0;
    }

    DEBUG(dl, ("tdb(%s):%s: %s", name ? name : "unnamed",
               tdb_errorstr(ecode), message));
}
Exemplo n.º 29
0
int main(int argc, char *argv[])
{
	int c,force = 0;
	TDB_CONTEXT *tdb;
	TDB_DATA key, data;
	io_channel channel;
	errcode_t retval;
	int  mount_flags;
	blk64_t  blk_num;
	char *device_name, *tdb_file;
	io_manager manager = unix_io_manager;

#ifdef ENABLE_NLS
	setlocale(LC_MESSAGES, "");
	setlocale(LC_CTYPE, "");
	bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
	textdomain(NLS_CAT_NAME);
#endif
	add_error_table(&et_ext2_error_table);

	prg_name = argv[0];
	while((c = getopt(argc, argv, "f")) != EOF) {
		switch (c) {
			case 'f':
				force = 1;
				break;
			default:
				usage(prg_name);
		}
	}

	if (argc != optind+2)
		usage(prg_name);

	tdb_file = argv[optind];
	device_name = argv[optind+1];

	tdb = tdb_open(tdb_file, 0, 0, O_RDONLY, 0600);

	if (!tdb) {
		com_err(prg_name, errno,
				_("Failed tdb_open %s\n"), tdb_file);
		exit(1);
	}

	retval = ext2fs_check_if_mounted(device_name, &mount_flags);
	if (retval) {
		com_err(prg_name, retval, _("Error while determining whether "
				"%s is mounted.\n"), device_name);
		exit(1);
	}

	if (mount_flags & EXT2_MF_MOUNTED) {
		com_err(prg_name, retval, _("e2undo should only be run on "
				"unmounted file system\n"));
		exit(1);
	}

	retval = manager->open(device_name,
				IO_FLAG_EXCLUSIVE | IO_FLAG_RW,  &channel);
	if (retval) {
		com_err(prg_name, retval,
				_("Failed to open %s\n"), device_name);
		exit(1);
	}

	if (!force && check_filesystem(tdb, channel)) {
		exit(1);
	}

	if (set_blk_size(tdb, channel)) {
		exit(1);
	}

	for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key)) {
		if (!strcmp((char *) key.dptr, (char *) mtime_key) ||
		    !strcmp((char *) key.dptr, (char *) uuid_key) ||
		    !strcmp((char *) key.dptr, (char *) blksize_key)) {
			continue;
		}

		data = tdb_fetch(tdb, key);
		if (!data.dptr) {
			com_err(prg_name, 0,
				_("Failed tdb_fetch %s\n"), tdb_errorstr(tdb));
			exit(1);
		}
		blk_num = *(unsigned long *)key.dptr;
		printf(_("Replayed transaction of size %zd at location %llu\n"),
							data.dsize, blk_num);
		retval = io_channel_write_blk64(channel, blk_num,
						-data.dsize, data.dptr);
		if (retval == -1) {
			com_err(prg_name, retval,
					_("Failed write %s\n"),
					strerror(errno));
			exit(1);
		}
	}
	io_channel_close(channel);
	tdb_close(tdb);

	return 0;
}
Exemplo n.º 30
0
/*
 * get_dir_info() --- given an inode number, try to find the directory
 * information entry for it.
 */
static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
{
    struct dir_info_db	*db = ctx->dir_info;
    int			low, high, mid;
    struct dir_info_ent	*buf;
    static struct dir_info	ret_dir_info;

    if (!db)
        return 0;

#ifdef DIRINFO_DEBUG
    printf("e2fsck_get_dir_info %d...", ino);
#endif

    if (db->tdb) {
        TDB_DATA key, data;

        key.dptr = (unsigned char *) &ino;
        key.dsize = sizeof(ext2_ino_t);

        data = tdb_fetch(db->tdb, key);
        if (!data.dptr) {
            if (tdb_error(db->tdb) != TDB_ERR_NOEXIST)
                printf("fetch failed: %s\n",
                       tdb_errorstr(db->tdb));
            return 0;
        }

        buf = (struct dir_info_ent *) data.dptr;
        ret_dir_info.ino = ino;
        ret_dir_info.dotdot = buf->dotdot;
        ret_dir_info.parent = buf->parent;
#ifdef DIRINFO_DEBUG
        printf("(%d,%d,%d)\n", ino, buf->dotdot, buf->parent);
#endif
        free(data.dptr);
        return &ret_dir_info;
    }

    if (db->last_lookup && db->last_lookup->ino == ino)
        return db->last_lookup;

    low = 0;
    high = ctx->dir_info->count-1;
    if (ino == ctx->dir_info->array[low].ino) {
#ifdef DIRINFO_DEBUG
        printf("(%d,%d,%d)\n", ino,
               ctx->dir_info->array[low].dotdot,
               ctx->dir_info->array[low].parent);
#endif
        return &ctx->dir_info->array[low];
    }
    if (ino == ctx->dir_info->array[high].ino) {
#ifdef DIRINFO_DEBUG
        printf("(%d,%d,%d)\n", ino,
               ctx->dir_info->array[high].dotdot,
               ctx->dir_info->array[high].parent);
#endif
        return &ctx->dir_info->array[high];
    }

    while (low < high) {
        mid = (low+high)/2;
        if (mid == low || mid == high)
            break;
        if (ino == ctx->dir_info->array[mid].ino) {
#ifdef DIRINFO_DEBUG
            printf("(%d,%d,%d)\n", ino,
                   ctx->dir_info->array[mid].dotdot,
                   ctx->dir_info->array[mid].parent);
#endif
            return &ctx->dir_info->array[mid];
        }
        if (ino < ctx->dir_info->array[mid].ino)
            high = mid;
        else
            low = mid;
    }
    return 0;
}