From ca7129fd08e7e7736b7bd49ed9b12f47429acbab Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 9 Apr 2013 21:07:23 +0200 Subject: [PATCH 1/3] vfs_fake_perms: Slightly streamline code Do an early error return Signed-off-by: Volker Lendecke --- source3/modules/vfs_fake_perms.c | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-) diff --git a/source3/modules/vfs_fake_perms.c b/source3/modules/vfs_fake_perms.c index 4cda7ea..a447f31 100644 --- a/source3/modules/vfs_fake_perms.c +++ b/source3/modules/vfs_fake_perms.c @@ -35,16 +35,18 @@ static int fake_perms_stat(vfs_handle_struct *handle, int ret = -1; ret = SMB_VFS_NEXT_STAT(handle, smb_fname); - if (ret == 0) { - if (S_ISDIR(smb_fname->st.st_ex_mode)) { - smb_fname->st.st_ex_mode = S_IFDIR | S_IRWXU; - } else { - smb_fname->st.st_ex_mode = S_IRWXU; - } - smb_fname->st.st_ex_uid = handle->conn->session_info->unix_token->uid; - smb_fname->st.st_ex_gid = handle->conn->session_info->unix_token->gid; + if (ret != 0) { + return ret; } + if (S_ISDIR(smb_fname->st.st_ex_mode)) { + smb_fname->st.st_ex_mode = S_IFDIR | S_IRWXU; + } else { + smb_fname->st.st_ex_mode = S_IRWXU; + } + smb_fname->st.st_ex_uid = handle->conn->session_info->unix_token->uid; + smb_fname->st.st_ex_gid = handle->conn->session_info->unix_token->gid; + return ret; } @@ -53,15 +55,18 @@ static int fake_perms_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_ST int ret = -1; ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf); - if (ret == 0) { - if (S_ISDIR(sbuf->st_ex_mode)) { - sbuf->st_ex_mode = S_IFDIR | S_IRWXU; - } else { - sbuf->st_ex_mode = S_IRWXU; - } - sbuf->st_ex_uid = handle->conn->session_info->unix_token->uid; - sbuf->st_ex_gid = handle->conn->session_info->unix_token->gid; + if (ret != 0) { + return ret; } + + if (S_ISDIR(sbuf->st_ex_mode)) { + sbuf->st_ex_mode = S_IFDIR | S_IRWXU; + } else { + sbuf->st_ex_mode = S_IRWXU; + } + sbuf->st_ex_uid = handle->conn->session_info->unix_token->uid; + sbuf->st_ex_gid = handle->conn->session_info->unix_token->gid; + return ret; } -- 1.7.3.4 From 2201a94d32bf85e1988e8378f0c9f41faf98459b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 9 Apr 2013 21:07:23 +0200 Subject: [PATCH 2/3] vfs_fake_perms: Slightly streamline code Don't initialize a variable directly set Signed-off-by: Volker Lendecke --- source3/modules/vfs_fake_perms.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/modules/vfs_fake_perms.c b/source3/modules/vfs_fake_perms.c index a447f31..f8d8901 100644 --- a/source3/modules/vfs_fake_perms.c +++ b/source3/modules/vfs_fake_perms.c @@ -32,7 +32,7 @@ static int fake_perms_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname) { - int ret = -1; + int ret; ret = SMB_VFS_NEXT_STAT(handle, smb_fname); if (ret != 0) { @@ -52,7 +52,7 @@ static int fake_perms_stat(vfs_handle_struct *handle, static int fake_perms_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf) { - int ret = -1; + int ret; ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf); if (ret != 0) { -- 1.7.3.4 From 3afea563a845aa798fe9cb5170d32b2e9d9d1805 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 9 Apr 2013 21:18:34 +0200 Subject: [PATCH 3/3] vfs_fake_perms: Fix bug 9775, segfault for "artificial" conn_structs Signed-off-by: Volker Lendecke --- source3/modules/vfs_fake_perms.c | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-) diff --git a/source3/modules/vfs_fake_perms.c b/source3/modules/vfs_fake_perms.c index f8d8901..8eb6e3c 100644 --- a/source3/modules/vfs_fake_perms.c +++ b/source3/modules/vfs_fake_perms.c @@ -44,8 +44,21 @@ static int fake_perms_stat(vfs_handle_struct *handle, } else { smb_fname->st.st_ex_mode = S_IRWXU; } - smb_fname->st.st_ex_uid = handle->conn->session_info->unix_token->uid; - smb_fname->st.st_ex_gid = handle->conn->session_info->unix_token->gid; + + if (handle->conn->session_info != NULL) { + struct security_unix_token *utok; + + utok = handle->conn->session_info->unix_token; + smb_fname->st.st_ex_uid = utok->uid; + smb_fname->st.st_ex_gid = utok->gid; + } else { + /* + * We have an artificial connection for dfs for example. It + * sucks, but the current uid/gid is the best we have. + */ + smb_fname->st.st_ex_uid = geteuid(); + smb_fname->st.st_ex_gid = getegid(); + } return ret; } @@ -64,8 +77,20 @@ static int fake_perms_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_ST } else { sbuf->st_ex_mode = S_IRWXU; } - sbuf->st_ex_uid = handle->conn->session_info->unix_token->uid; - sbuf->st_ex_gid = handle->conn->session_info->unix_token->gid; + if (handle->conn->session_info != NULL) { + struct security_unix_token *utok; + + utok = handle->conn->session_info->unix_token; + sbuf->st_ex_uid = utok->uid; + sbuf->st_ex_gid = utok->gid; + } else { + /* + * We have an artificial connection for dfs for example. It + * sucks, but the current uid/gid is the best we have. + */ + sbuf->st_ex_uid = geteuid(); + sbuf->st_ex_gid = getegid(); + } return ret; } -- 1.7.3.4