s3:spoolss: Exit if fork call fails
[Samba.git] / source3 / smbd / smb1_utils.c
blob8a7e66e2ae3aa001d03778353510cbc0b484f1b7
1 /*
2 * Unix SMB/CIFS implementation.
3 * Util functions valid in the SMB1 server
5 * Copyright (C) Volker Lendecke 2019
6 * Copyright by the authors of the functions moved here eventually
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "smb1_utils.h"
24 #include "libcli/security/security.h"
26 /****************************************************************************
27 Special FCB or DOS processing in the case of a sharing violation.
28 Try and find a duplicated file handle.
29 ****************************************************************************/
31 struct files_struct *fcb_or_dos_open(
32 struct smb_request *req,
33 const struct smb_filename *smb_fname,
34 uint32_t access_mask,
35 uint32_t share_access,
36 uint32_t create_options,
37 uint32_t private_flags)
39 struct connection_struct *conn = req->conn;
40 struct file_id id = vfs_file_id_from_sbuf(conn, &smb_fname->st);
41 struct files_struct *fsp = NULL, *new_fsp = NULL;
42 NTSTATUS status;
44 if ((private_flags &
45 (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
46 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB))
47 == 0) {
48 return NULL;
51 for(fsp = file_find_di_first(conn->sconn, id);
52 fsp != NULL;
53 fsp = file_find_di_next(fsp)) {
55 DBG_DEBUG("Checking file %s, fd = %d, vuid = %"PRIu64", "
56 "file_pid = %"PRIu16", "
57 "private_options = 0x%"PRIx32", "
58 "access_mask = 0x%"PRIx32"\n",
59 fsp_str_dbg(fsp),
60 fsp->fh->fd,
61 fsp->vuid,
62 fsp->file_pid,
63 fsp->fh->private_options,
64 fsp->access_mask);
66 if (fsp->fh->fd != -1 &&
67 fsp->vuid == req->vuid &&
68 fsp->file_pid == req->smbpid &&
69 (fsp->fh->private_options &
70 (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS |
71 NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) &&
72 (fsp->access_mask & FILE_WRITE_DATA) &&
73 strequal(fsp->fsp_name->base_name, smb_fname->base_name) &&
74 strequal(fsp->fsp_name->stream_name,
75 smb_fname->stream_name)) {
76 DBG_DEBUG("file match\n");
77 break;
81 if (fsp == NULL) {
82 return NULL;
85 /* quite an insane set of semantics ... */
86 if (is_executable(smb_fname->base_name) &&
87 (fsp->fh->private_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) {
88 DBG_DEBUG("file fail due to is_executable.\n");
89 return NULL;
92 status = file_new(req, conn, &new_fsp);
93 if (!NT_STATUS_IS_OK(status)) {
94 DBG_DEBUG("file_new failed: %s\n", nt_errstr(status));
95 return NULL;
98 status = dup_file_fsp(
99 req,
100 fsp,
101 access_mask,
102 share_access,
103 create_options,
104 new_fsp);
106 if (!NT_STATUS_IS_OK(status)) {
107 DBG_DEBUG("dup_file_fsp failed: %s\n", nt_errstr(status));
108 file_free(req, new_fsp);
109 return NULL;
112 return new_fsp;