* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-/* NOTE: This is an experimental module, not yet finished. JRA. */
-
#include "includes.h"
#include "smbd/smbd.h"
#include "system/filesys.h"
#include "librpc/gen_ndr/xattr.h"
#include "librpc/gen_ndr/ndr_xattr.h"
-#include "../lib/crypto/crypto.h"
+#include "../lib/crypto/sha256.h"
#include "dbwrap/dbwrap.h"
#include "dbwrap/dbwrap_open.h"
#include "auth.h"
}
become_root();
- acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
unbecome_root();
if (acl_db == NULL) {
struct db_context *db,
const struct file_id *id)
{
- uint8 id_buf[16];
+ uint8_t id_buf[16];
/* For backwards compatibility only store the dev/inode. */
push_file_id_16((char *)id_buf, id);
- return db->fetch_locked(db,
- mem_ctx,
- make_tdb_data(id_buf,
- sizeof(id_buf)));
+ return dbwrap_fetch_locked(db,
+ mem_ctx,
+ make_tdb_data(id_buf,
+ sizeof(id_buf)));
}
/*******************************************************************
return NT_STATUS_OK;
}
- status = rec->delete_rec(rec);
+ status = dbwrap_record_delete(rec);
TALLOC_FREE(rec);
return status;
}
static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
vfs_handle_struct *handle,
files_struct *fsp,
- const char *name,
+ const struct smb_filename *smb_fname,
DATA_BLOB *pblob)
{
- uint8 id_buf[16];
+ uint8_t id_buf[16];
TDB_DATA data;
struct file_id id;
struct db_context *db = acl_db;
status = vfs_stat_fsp(fsp);
sbuf = fsp->fsp_name->st;
} else {
- int ret = vfs_stat_smb_fname(handle->conn, name, &sbuf);
+ int ret = vfs_stat_smb_basename(handle->conn,
+ smb_fname->base_name,
+ &sbuf);
if (ret == -1) {
status = map_nt_error_from_unix(errno);
}
/* For backwards compatibility only store the dev/inode. */
push_file_id_16((char *)id_buf, &id);
- if (db->fetch(db,
- ctx,
- make_tdb_data(id_buf, sizeof(id_buf)),
- &data) != 0) {
+ status = dbwrap_fetch(db,
+ ctx,
+ make_tdb_data(id_buf, sizeof(id_buf)),
+ &data);
+ if (!NT_STATUS_IS_OK(status)) {
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
pblob->length = data.dsize;
DEBUG(10,("get_acl_blob: returned %u bytes from file %s\n",
- (unsigned int)data.dsize, name ));
+ (unsigned int)data.dsize, smb_fname->base_name ));
if (pblob->length == 0 || pblob->data == NULL) {
return NT_STATUS_NOT_FOUND;
files_struct *fsp,
DATA_BLOB *pblob)
{
- uint8 id_buf[16];
+ uint8_t id_buf[16];
struct file_id id;
TDB_DATA data;
struct db_context *db = acl_db;
/* For backwards compatibility only store the dev/inode. */
push_file_id_16((char *)id_buf, &id);
- rec = db->fetch_locked(db, talloc_tos(),
- make_tdb_data(id_buf,
- sizeof(id_buf)));
+ rec = dbwrap_fetch_locked(db, talloc_tos(),
+ make_tdb_data(id_buf,
+ sizeof(id_buf)));
if (rec == NULL) {
DEBUG(0, ("store_acl_blob_fsp_tdb: fetch_lock failed\n"));
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
data.dptr = pblob->data;
data.dsize = pblob->length;
- return rec->store(rec, data, 0);
+ return dbwrap_record_store(rec, data, 0);
}
/*********************************************************************
{
struct smb_filename *smb_fname_tmp = NULL;
struct db_context *db = acl_db;
- NTSTATUS status;
int ret = -1;
- status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
- if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
+ smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
+ if (smb_fname_tmp == NULL) {
+ errno = ENOMEM;
goto out;
}
- if (lp_posix_pathnames()) {
+ if (smb_fname_tmp->flags & SMB_FILENAME_POSIX_PATH) {
ret = SMB_VFS_LSTAT(handle->conn, smb_fname_tmp);
} else {
ret = SMB_VFS_STAT(handle->conn, smb_fname_tmp);
On rmdir we need to delete the tdb record (if using tdb).
*********************************************************************/
-static int rmdir_acl_tdb(vfs_handle_struct *handle, const char *path)
+static int rmdir_acl_tdb(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
{
SMB_STRUCT_STAT sbuf;
struct db_context *db = acl_db;
int ret = -1;
- if (lp_posix_pathnames()) {
- ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
- } else {
- ret = vfs_stat_smb_fname(handle->conn, path, &sbuf);
- }
-
+ ret = vfs_stat_smb_basename(handle->conn, smb_fname->base_name, &sbuf);
if (ret == -1) {
return -1;
}
- ret = rmdir_acl_common(handle, path);
+ ret = rmdir_acl_common(handle, smb_fname);
if (ret == -1) {
return -1;
}
SMB_ACL_TYPE_T type,
SMB_ACL_T theacl)
{
- SMB_STRUCT_STAT sbuf;
struct db_context *db = acl_db;
int ret = -1;
+ struct smb_filename smb_fname = {
+ .base_name = discard_const_p(char, path)
+ };
- if (lp_posix_pathnames()) {
- ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
- } else {
- ret = vfs_stat_smb_fname(handle->conn, path, &sbuf);
- }
-
+ ret = SMB_VFS_STAT(handle->conn, &smb_fname);
if (ret == -1) {
return -1;
}
return -1;
}
- acl_tdb_delete(handle, db, &sbuf);
+ acl_tdb_delete(handle, db, &smb_fname.st);
return 0;
}
static struct vfs_fn_pointers vfs_acl_tdb_fns = {
.connect_fn = connect_acl_tdb,
- .disconnect = disconnect_acl_tdb,
- .opendir = opendir_acl_common,
- .mkdir = mkdir_acl_common,
- .rmdir = rmdir_acl_tdb,
- .open_fn = open_acl_common,
- .create_file = create_file_acl_common,
- .unlink = unlink_acl_tdb,
- .chmod = chmod_acl_module_common,
- .fchmod = fchmod_acl_module_common,
- .fget_nt_acl = fget_nt_acl_common,
- .get_nt_acl = get_nt_acl_common,
- .fset_nt_acl = fset_nt_acl_common,
- .chmod_acl = chmod_acl_acl_module_common,
- .fchmod_acl = fchmod_acl_acl_module_common,
- .sys_acl_set_file = sys_acl_set_file_tdb,
- .sys_acl_set_fd = sys_acl_set_fd_tdb
+ .disconnect_fn = disconnect_acl_tdb,
+ .rmdir_fn = rmdir_acl_tdb,
+ .unlink_fn = unlink_acl_tdb,
+ .chmod_fn = chmod_acl_module_common,
+ .fchmod_fn = fchmod_acl_module_common,
+ .fget_nt_acl_fn = fget_nt_acl_common,
+ .get_nt_acl_fn = get_nt_acl_common,
+ .fset_nt_acl_fn = fset_nt_acl_common,
+ .chmod_acl_fn = chmod_acl_acl_module_common,
+ .fchmod_acl_fn = fchmod_acl_acl_module_common,
+ .sys_acl_set_file_fn = sys_acl_set_file_tdb,
+ .sys_acl_set_fd_fn = sys_acl_set_fd_tdb
};
+static_decl_vfs;
NTSTATUS vfs_acl_tdb_init(void)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "acl_tdb",