2 Unix SMB/CIFS implementation.
3 FAKE FILE suppport, for faking up special files windows want access to
4 Copyright (C) Stefan (metze) Metzmacher 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 struct fake_file_type {
24 enum FAKE_FILE_TYPE type;
25 void *(*init_pd)(TALLOC_CTX *mem_ctx);
28 static const struct fake_file_type fake_files[] = {
30 {FAKE_FILE_NAME_QUOTA_UNIX, FAKE_FILE_TYPE_QUOTA, init_quota_handle},
31 #endif /* WITH_QUOTAS */
32 {NULL, FAKE_FILE_TYPE_NONE, NULL}
35 /****************************************************************************
36 Create a fake file handle
37 ****************************************************************************/
39 static struct fake_file_handle *init_fake_file_handle(enum FAKE_FILE_TYPE type)
41 struct fake_file_handle *fh = NULL;
44 for (i=0; fake_files[i].name!=NULL; i++) {
45 if (fake_files[i].type==type) {
50 if (fake_files[i].name == NULL) {
54 DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
56 fh = talloc(NULL, struct fake_file_handle);
58 DEBUG(0,("TALLOC_ZERO() failed.\n"));
64 if (fake_files[i].init_pd) {
65 fh->private_data = fake_files[i].init_pd(fh);
70 /****************************************************************************
71 Does this name match a fake filename ?
72 ****************************************************************************/
74 enum FAKE_FILE_TYPE is_fake_file(const struct smb_filename *smb_fname)
76 #ifdef HAVE_SYS_QUOTAS
83 return FAKE_FILE_TYPE_NONE;
86 #ifdef HAVE_SYS_QUOTAS
87 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
88 if (!NT_STATUS_IS_OK(status)) {
89 return FAKE_FILE_TYPE_NONE;
92 for (i=0;fake_files[i].name!=NULL;i++) {
93 if (strncmp(fname,fake_files[i].name,strlen(fake_files[i].name))==0) {
94 DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname));
96 return fake_files[i].type;
102 return FAKE_FILE_TYPE_NONE;
106 /****************************************************************************
107 Open a fake quota file with a share mode.
108 ****************************************************************************/
110 NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
111 uint16_t current_vuid,
112 enum FAKE_FILE_TYPE fake_file_type,
113 const struct smb_filename *smb_fname,
115 files_struct **result)
117 files_struct *fsp = NULL;
121 if (conn->server_info->utok.uid != 0) {
122 DEBUG(3, ("open_fake_file_shared: access_denied to "
123 "service[%s] file[%s] user[%s]\n",
124 lp_servicename(SNUM(conn)),
125 smb_fname_str_dbg(smb_fname),
126 conn->server_info->unix_name));
127 return NT_STATUS_ACCESS_DENIED;
131 status = file_new(req, conn, &fsp);
132 if(!NT_STATUS_IS_OK(status)) {
136 DEBUG(5,("open_fake_file_shared: fname = %s, FID = %d, access_mask = 0x%x\n",
137 smb_fname_str_dbg(smb_fname), fsp->fnum,
138 (unsigned int)access_mask));
142 fsp->vuid = current_vuid;
144 fsp->can_lock = False; /* Should this be true ? - No, JRA */
145 fsp->access_mask = access_mask;
146 status = fsp_set_smb_fname(fsp, smb_fname);
147 if (!NT_STATUS_IS_OK(status)) {
149 return NT_STATUS_NO_MEMORY;
152 fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
154 if (fsp->fake_file_handle==NULL) {
156 return NT_STATUS_NO_MEMORY;
163 NTSTATUS close_fake_file(struct smb_request *req, files_struct *fsp)