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