source: trunk/server/source3/modules/vfs_fake_perms.c

Last change on this file was 862, checked in by Silvan Scherrer, 11 years ago

Samba Server: update trunk to 3.6.23

File size: 2.7 KB
Line 
1/*
2 * Fake Perms VFS module. Implements passthrough operation of all VFS
3 * calls to disk functions, except for file permissions, which are now
4 * mode 0700 for the current uid/gid.
5 *
6 * Copyright (C) Tim Potter, 1999-2000
7 * Copyright (C) Alexander Bokovoy, 2002
8 * Copyright (C) Andrew Bartlett, 2002
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include "includes.h"
25#include "smbd/smbd.h"
26#include "system/filesys.h"
27#include "auth.h"
28
29#undef DBGC_CLASS
30#define DBGC_CLASS DBGC_VFS
31
32extern struct current_user current_user;
33
34static int fake_perms_stat(vfs_handle_struct *handle,
35 struct smb_filename *smb_fname)
36{
37 int ret = -1;
38
39 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
40 if (ret == 0) {
41 if (S_ISDIR(smb_fname->st.st_ex_mode)) {
42 smb_fname->st.st_ex_mode = S_IFDIR | S_IRWXU;
43 } else {
44 smb_fname->st.st_ex_mode = S_IRWXU;
45 }
46 if (handle->conn->session_info != NULL) {
47 smb_fname->st.st_ex_uid =
48 handle->conn->session_info->utok.uid;
49 smb_fname->st.st_ex_gid =
50 handle->conn->session_info->utok.gid;
51 } else {
52 /*
53 * Sucks, but current_user is the best we can do here.
54 */
55 smb_fname->st.st_ex_uid = current_user.ut.uid;
56 smb_fname->st.st_ex_gid = current_user.ut.gid;
57 }
58 }
59
60 return ret;
61}
62
63static int fake_perms_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
64{
65 int ret = -1;
66
67 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
68 if (ret == 0) {
69 if (S_ISDIR(sbuf->st_ex_mode)) {
70 sbuf->st_ex_mode = S_IFDIR | S_IRWXU;
71 } else {
72 sbuf->st_ex_mode = S_IRWXU;
73 }
74 if (handle->conn->session_info != NULL) {
75 sbuf->st_ex_uid =
76 handle->conn->session_info->utok.uid;
77 sbuf->st_ex_gid =
78 handle->conn->session_info->utok.gid;
79 } else {
80 /*
81 * Sucks, but current_user is the best we can do here.
82 */
83 sbuf->st_ex_uid = current_user.ut.uid;
84 sbuf->st_ex_gid = current_user.ut.gid;
85 }
86 }
87 return ret;
88}
89
90static struct vfs_fn_pointers vfs_fake_perms_fns = {
91 .stat = fake_perms_stat,
92 .fstat = fake_perms_fstat
93};
94
95NTSTATUS vfs_fake_perms_init(void);
96NTSTATUS vfs_fake_perms_init(void)
97{
98 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fake_perms",
99 &vfs_fake_perms_fns);
100}
Note: See TracBrowser for help on using the repository browser.