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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 extern struct current_user current_user;
25 /****************************************************************************
26 Open a file with a share mode.
27 ****************************************************************************/
28 files_struct *open_fake_file_shared1(enum FAKE_FILE_TYPE fake_file_type, connection_struct *conn,char *fname,
29 SMB_STRUCT_STAT *psbuf,
30 uint32 desired_access,
31 int share_mode,int ofun, uint32 new_dos_attr, int oplock_request,
32 int *Access,int *action)
35 files_struct *fsp = NULL;
37 if (fake_file_type == 0) {
38 return open_file_shared1(conn,fname,psbuf,desired_access,
39 share_mode,ofun,new_dos_attr,
40 oplock_request,Access,action);
44 if (current_user.uid != 0) {
45 DEBUG(1,("access_denied to service[%s] file[%s] user[%s]\n",
46 lp_servicename(SNUM(conn)),fname,conn->user));
55 DEBUG(5,("open_fake_file_shared1: fname = %s, FID = %d, share_mode = %x, ofun = %x, oplock request = %d\n",
56 fname, fsp->fnum, share_mode, ofun, oplock_request ));
58 if (!check_name(fname,conn)) {
64 fsp->mode = psbuf->st_mode;
65 fsp->inode = psbuf->st_ino;
66 fsp->dev = psbuf->st_dev;
67 fsp->vuid = current_user.vuid;
68 fsp->size = psbuf->st_size;
71 fsp->can_read = ((flags & O_WRONLY)==0);
72 fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
74 fsp->desired_access = desired_access;
75 fsp->print_file = False;
76 fsp->modified = False;
77 fsp->oplock_type = NO_OPLOCK;
78 fsp->sent_oplock_break = NO_BREAK_SENT;
79 fsp->is_directory = False;
81 fsp->directory_delete_on_close = False;
83 string_set(&fsp->fsp_name,fname);
84 fsp->wcp = NULL; /* Write cache pointer. */
86 fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
88 if (fsp->fake_file_handle==NULL) {
93 conn->num_files_open++;
97 static FAKE_FILE fake_files[] = {
99 {FAKE_FILE_NAME_QUOTA_UNIX, FAKE_FILE_TYPE_QUOTA, init_quota_handle, destroy_quota_handle},
100 #endif /* WITH_QUOTAS */
101 {NULL, FAKE_FILE_TYPE_NONE, NULL, NULL }
104 int is_fake_file(char *fname)
111 for (i=0;fake_files[i].name!=NULL;i++) {
112 if (strncmp(fname,fake_files[i].name,strlen(fake_files[i].name))==0) {
113 DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname));
114 return fake_files[i].type;
118 return FAKE_FILE_TYPE_NONE;
121 struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
123 TALLOC_CTX *mem_ctx = NULL;
124 FAKE_FILE_HANDLE *fh = NULL;
127 for (i=0;fake_files[i].name!=NULL;i++) {
128 if (fake_files[i].type==type) {
129 DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
131 if ((mem_ctx=talloc_init("fake_file_handle"))==NULL) {
132 DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
136 if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
137 DEBUG(0,("talloc_zero() failed.\n"));
138 talloc_destroy(mem_ctx);
143 fh->mem_ctx = mem_ctx;
145 if (fake_files[i].init_pd)
146 fh->pd = fake_files[i].init_pd(fh->mem_ctx);
148 fh->free_pd = fake_files[i].free_pd;
157 void destroy_fake_file_handle(FAKE_FILE_HANDLE **fh)
163 (*fh)->free_pd(&(*fh)->pd);
165 talloc_destroy((*fh)->mem_ctx);