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 /****************************************************************************
24 Open a file with a share mode.
25 ****************************************************************************/
26 files_struct
*open_fake_file_shared1(enum FAKE_FILE_TYPE fake_file_type
, connection_struct
*conn
,char *fname
,
27 SMB_STRUCT_STAT
*psbuf
,
28 uint32 desired_access
,
29 int share_mode
,int ofun
, mode_t mode
,int oplock_request
,
30 int *Access
,int *action
)
32 extern struct current_user current_user
;
34 files_struct
*fsp
= NULL
;
36 if (fake_file_type
== 0) {
37 return open_file_shared1(conn
,fname
,psbuf
,desired_access
,
39 oplock_request
,Access
,action
);
43 if (conn
->admin_user
!= True
) {
44 DEBUG(1,("access_denied to service[%s] file[%s] user[%s]\n",
45 lp_servicename(SNUM(conn
)),fname
,conn
->user
));
54 DEBUG(5,("open_fake_file_shared1: fname = %s, FID = %d, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
55 fname
, fsp
->fnum
, share_mode
, ofun
, (int)mode
, oplock_request
));
57 if (!check_name(fname
,conn
)) {
63 fsp
->mode
= psbuf
->st_mode
;
64 fsp
->inode
= psbuf
->st_ino
;
65 fsp
->dev
= psbuf
->st_dev
;
66 fsp
->vuid
= current_user
.vuid
;
67 fsp
->size
= psbuf
->st_size
;
70 fsp
->can_read
= ((flags
& O_WRONLY
)==0);
71 fsp
->can_write
= ((flags
& (O_WRONLY
|O_RDWR
))!=0);
73 fsp
->desired_access
= desired_access
;
74 fsp
->print_file
= False
;
75 fsp
->modified
= False
;
76 fsp
->oplock_type
= NO_OPLOCK
;
77 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
78 fsp
->is_directory
= False
;
80 fsp
->directory_delete_on_close
= False
;
82 string_set(&fsp
->fsp_name
,fname
);
83 fsp
->wcp
= NULL
; /* Write cache pointer. */
85 fsp
->fake_file_handle
= init_fake_file_handle(fake_file_type
);
87 if (fsp
->fake_file_handle
==NULL
) {
92 conn
->num_files_open
++;
96 static FAKE_FILE fake_files
[] = {
98 {FAKE_FILE_NAME_QUOTA
, FAKE_FILE_TYPE_QUOTA
, init_quota_handle
, destroy_quota_handle
},
99 #endif /* WITH_QUOTAS */
100 {NULL
, FAKE_FILE_TYPE_NONE
, NULL
, NULL
}
103 int is_fake_file(char *fname
)
110 for (i
=0;fake_files
[i
].name
!=NULL
;i
++) {
111 if (strncmp(fname
,fake_files
[i
].name
,strlen(fake_files
[i
].name
))==0) {
112 DEBUG(5,("is_fake_file: [%s] is a fake file\n",fname
));
113 return fake_files
[i
].type
;
117 return FAKE_FILE_TYPE_NONE
;
120 struct _FAKE_FILE_HANDLE
*init_fake_file_handle(enum FAKE_FILE_TYPE type
)
122 TALLOC_CTX
*mem_ctx
= NULL
;
123 FAKE_FILE_HANDLE
*fh
= NULL
;
126 for (i
=0;fake_files
[i
].name
!=NULL
;i
++) {
127 if (fake_files
[i
].type
==type
) {
128 DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files
[i
].name
));
130 if ((mem_ctx
=talloc_init("fake_file_handle"))==NULL
) {
131 DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
135 if ((fh
=(FAKE_FILE_HANDLE
*)talloc_zero(mem_ctx
, sizeof(FAKE_FILE_HANDLE
)))==NULL
) {
136 DEBUG(0,("talloc_zero() failed.\n"));
137 talloc_destroy(mem_ctx
);
142 fh
->mem_ctx
= mem_ctx
;
144 if (fake_files
[i
].init_pd
)
145 fh
->pd
= fake_files
[i
].init_pd(fh
->mem_ctx
);
147 fh
->free_pd
= fake_files
[i
].free_pd
;
156 void destroy_fake_file_handle(FAKE_FILE_HANDLE
**fh
)
162 (*fh
)->free_pd(&(*fh
)->pd
);
164 talloc_destroy((*fh
)->mem_ctx
);