1 | /*
|
---|
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
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 |
|
---|
22 | struct fake_file_type {
|
---|
23 | const char *name;
|
---|
24 | enum FAKE_FILE_TYPE type;
|
---|
25 | void *(*init_pd)(TALLOC_CTX *mem_ctx);
|
---|
26 | };
|
---|
27 |
|
---|
28 | static const struct fake_file_type fake_files[] = {
|
---|
29 | #ifdef WITH_QUOTAS
|
---|
30 | {FAKE_FILE_NAME_QUOTA_UNIX, FAKE_FILE_TYPE_QUOTA, init_quota_handle},
|
---|
31 | #endif /* WITH_QUOTAS */
|
---|
32 | {NULL, FAKE_FILE_TYPE_NONE, NULL}
|
---|
33 | };
|
---|
34 |
|
---|
35 | /****************************************************************************
|
---|
36 | Create a fake file handle
|
---|
37 | ****************************************************************************/
|
---|
38 |
|
---|
39 | static struct fake_file_handle *init_fake_file_handle(enum FAKE_FILE_TYPE type)
|
---|
40 | {
|
---|
41 | struct fake_file_handle *fh = NULL;
|
---|
42 | int i;
|
---|
43 |
|
---|
44 | for (i=0; fake_files[i].name!=NULL; i++) {
|
---|
45 | if (fake_files[i].type==type) {
|
---|
46 | break;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (fake_files[i].name == NULL) {
|
---|
51 | return NULL;
|
---|
52 | }
|
---|
53 |
|
---|
54 | DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
|
---|
55 |
|
---|
56 | fh = talloc(NULL, struct fake_file_handle);
|
---|
57 | if (fh == NULL) {
|
---|
58 | DEBUG(0,("TALLOC_ZERO() failed.\n"));
|
---|
59 | return NULL;
|
---|
60 | }
|
---|
61 |
|
---|
62 | fh->type = type;
|
---|
63 |
|
---|
64 | if (fake_files[i].init_pd) {
|
---|
65 | fh->private_data = fake_files[i].init_pd(fh);
|
---|
66 | }
|
---|
67 | return fh;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /****************************************************************************
|
---|
71 | Does this name match a fake filename ?
|
---|
72 | ****************************************************************************/
|
---|
73 |
|
---|
74 | enum FAKE_FILE_TYPE is_fake_file_path(const char *path)
|
---|
75 | {
|
---|
76 | int i;
|
---|
77 |
|
---|
78 | if (!path) {
|
---|
79 | return FAKE_FILE_TYPE_NONE;
|
---|
80 | }
|
---|
81 |
|
---|
82 | for (i=0;fake_files[i].name!=NULL;i++) {
|
---|
83 | if (strncmp(path,fake_files[i].name,strlen(fake_files[i].name))==0) {
|
---|
84 | DEBUG(5,("is_fake_file: [%s] is a fake file\n",path));
|
---|
85 | return fake_files[i].type;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | return FAKE_FILE_TYPE_NONE;
|
---|
90 | }
|
---|
91 |
|
---|
92 | enum FAKE_FILE_TYPE is_fake_file(const struct smb_filename *smb_fname)
|
---|
93 | {
|
---|
94 | char *fname = NULL;
|
---|
95 | NTSTATUS status;
|
---|
96 | enum FAKE_FILE_TYPE ret;
|
---|
97 |
|
---|
98 | if (!smb_fname) {
|
---|
99 | return FAKE_FILE_TYPE_NONE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
|
---|
103 | if (!NT_STATUS_IS_OK(status)) {
|
---|
104 | return FAKE_FILE_TYPE_NONE;
|
---|
105 | }
|
---|
106 |
|
---|
107 | ret = is_fake_file_path(fname);
|
---|
108 |
|
---|
109 | TALLOC_FREE(fname);
|
---|
110 |
|
---|
111 | return ret;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /****************************************************************************
|
---|
115 | Open a fake quota file with a share mode.
|
---|
116 | ****************************************************************************/
|
---|
117 |
|
---|
118 | NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
|
---|
119 | uint16_t current_vuid,
|
---|
120 | enum FAKE_FILE_TYPE fake_file_type,
|
---|
121 | const struct smb_filename *smb_fname,
|
---|
122 | uint32 access_mask,
|
---|
123 | files_struct **result)
|
---|
124 | {
|
---|
125 | files_struct *fsp = NULL;
|
---|
126 | NTSTATUS status;
|
---|
127 |
|
---|
128 | /* access check */
|
---|
129 | if (conn->server_info->utok.uid != 0 && !conn->admin_user) {
|
---|
130 | DEBUG(3, ("open_fake_file_shared: access_denied to "
|
---|
131 | "service[%s] file[%s] user[%s]\n",
|
---|
132 | lp_servicename(SNUM(conn)),
|
---|
133 | smb_fname_str_dbg(smb_fname),
|
---|
134 | conn->server_info->unix_name));
|
---|
135 | return NT_STATUS_ACCESS_DENIED;
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | status = file_new(req, conn, &fsp);
|
---|
140 | if(!NT_STATUS_IS_OK(status)) {
|
---|
141 | return status;
|
---|
142 | }
|
---|
143 |
|
---|
144 | DEBUG(5,("open_fake_file_shared: fname = %s, FID = %d, access_mask = 0x%x\n",
|
---|
145 | smb_fname_str_dbg(smb_fname), fsp->fnum,
|
---|
146 | (unsigned int)access_mask));
|
---|
147 |
|
---|
148 | fsp->conn = conn;
|
---|
149 | fsp->fh->fd = -1;
|
---|
150 | fsp->vuid = current_vuid;
|
---|
151 | fsp->fh->pos = -1;
|
---|
152 | fsp->can_lock = False; /* Should this be true ? - No, JRA */
|
---|
153 | fsp->access_mask = access_mask;
|
---|
154 | status = fsp_set_smb_fname(fsp, smb_fname);
|
---|
155 | if (!NT_STATUS_IS_OK(status)) {
|
---|
156 | file_free(req, fsp);
|
---|
157 | return NT_STATUS_NO_MEMORY;
|
---|
158 | }
|
---|
159 |
|
---|
160 | fsp->fake_file_handle = init_fake_file_handle(fake_file_type);
|
---|
161 |
|
---|
162 | if (fsp->fake_file_handle==NULL) {
|
---|
163 | file_free(req, fsp);
|
---|
164 | return NT_STATUS_NO_MEMORY;
|
---|
165 | }
|
---|
166 |
|
---|
167 | *result = fsp;
|
---|
168 | return NT_STATUS_OK;
|
---|
169 | }
|
---|
170 |
|
---|
171 | NTSTATUS close_fake_file(struct smb_request *req, files_struct *fsp)
|
---|
172 | {
|
---|
173 | file_free(req, fsp);
|
---|
174 | return NT_STATUS_OK;
|
---|
175 | }
|
---|