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 extern struct current_user current_user;
24 struct fake_file_type {
26 enum FAKE_FILE_TYPE type;
27 void *(*init_pd)(TALLOC_CTX *mem_ctx);
30 static struct fake_file_type fake_files[] = {
32 {FAKE_FILE_NAME_QUOTA_UNIX, FAKE_FILE_TYPE_QUOTA, init_quota_handle},
33 #endif /* WITH_QUOTAS */
34 {NULL, FAKE_FILE_TYPE_NONE, NULL}
37 /****************************************************************************
38 Create a fake file handle
39 ****************************************************************************/
41 static struct fake_file_handle *init_fake_file_handle(enum FAKE_FILE_TYPE type)
43 struct fake_file_handle *fh = NULL;
46 for (i=0; fake_files[i].name!=NULL; i++) {
47 if (fake_files[i].type==type) {
52 if (fake_files[i].name == NULL) {
56 DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
58 fh = talloc(NULL, struct fake_file_handle);
60 DEBUG(0,("TALLOC_ZERO() failed.\n"));
66 if (fake_files[i].init_pd) {
67 fh->private_data = fake_files[i].init_pd(fh);
72 /****************************************************************************
73 Does this name match a fake filename ?
74 ****************************************************************************/
76 enum FAKE_FILE_TYPE is_fake_file(const char *fname)
78 #ifdef HAVE_SYS_QUOTAS
83 return FAKE_FILE_TYPE_NONE;
86 #ifdef HAVE_SYS_QUOTAS
87 for (i=0;fake_files[i].name!=NULL;i++) {
88 if (strncmp(fname,fake_files[i].name,strlen(fake_files[i].name))==0) {
89 DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname));
90 return fake_files[i].type;
95 return FAKE_FILE_TYPE_NONE;
99 /****************************************************************************
100 Open a fake quota file with a share mode.
101 ****************************************************************************/
103 NTSTATUS open_fake_file(connection_struct *conn,
104 enum FAKE_FILE_TYPE fake_file_type,
107 files_struct **result)
109 files_struct *fsp = NULL;
113 if (current_user.ut.uid != 0) {
114 DEBUG(3, ("open_fake_file_shared: access_denied to "
115 "service[%s] file[%s] user[%s]\n",
116 lp_servicename(SNUM(conn)), fname,
117 conn->server_info->unix_name));
118 return NT_STATUS_ACCESS_DENIED;
122 status = file_new(conn, &fsp);
123 if(!NT_STATUS_IS_OK(status)) {
127 DEBUG(5,("open_fake_file_shared: fname = %s, FID = %d, access_mask = 0x%x\n",
128 fname, fsp->fnum, (unsigned int)access_mask));
132 fsp->vuid = current_user.vuid;
134 fsp->can_lock = False; /* Should this be true ? - No, JRA */
135 fsp->access_mask = access_mask;
136 string_set(&fsp->fsp_name,fname);
138 fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
140 if (fsp->fake_file_handle==NULL) {
142 return NT_STATUS_NO_MEMORY;
145 conn->num_files_open++;
150 void destroy_fake_file_handle(struct fake_file_handle **fh)
158 NTSTATUS close_fake_file(files_struct *fsp)