2 Unix SMB/CIFS implementation.
3 Main SMB server routines
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Martin Pool 2002
6 Copyright (C) Jelmer Vernooij 2002-2003
7 Copyright (C) Volker Lendecke 1993-2007
8 Copyright (C) Jeremy Allison 1993-2007
9 Copyright (C) Andrew Bartlett 2010
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "smbd/globals.h"
27 #include "librpc/gen_ndr/messaging.h"
29 static struct files_struct
*log_writeable_file_fn(
30 struct files_struct
*fsp
, void *private_data
)
32 bool *found
= (bool *)private_data
;
35 if (!fsp
->can_write
) {
39 DEBUG(0, ("Writable files open at exit:\n"));
43 path
= talloc_asprintf(talloc_tos(), "%s/%s", fsp
->conn
->connectpath
,
44 smb_fname_str_dbg(fsp
->fsp_name
));
46 DEBUGADD(0, ("<NOMEM>\n"));
49 DEBUGADD(0, ("%s\n", path
));
55 /****************************************************************************
57 ****************************************************************************/
59 /* Reasons for shutting down a server process. */
60 enum server_exit_reason
{ SERVER_EXIT_NORMAL
, SERVER_EXIT_ABNORMAL
};
62 static void exit_server_common(enum server_exit_reason how
,
63 const char *const reason
) _NORETURN_
;
65 static void exit_server_common(enum server_exit_reason how
,
66 const char *const reason
)
68 bool had_open_conn
= false;
69 struct smbd_server_connection
*sconn
= smbd_server_conn
;
73 exit_firsttime
= false;
75 change_to_root_user();
77 if (sconn
&& sconn
->smb1
.negprot
.auth_context
) {
78 TALLOC_FREE(sconn
->smb1
.negprot
.auth_context
);
82 if (lp_log_writeable_files_on_exit()) {
84 files_forall(sconn
, log_writeable_file_fn
, &found
);
86 had_open_conn
= conn_close_all(sconn
);
87 invalidate_all_vuids(sconn
);
90 /* 3 second timeout. */
91 print_notify_send_messages(sconn
->msg_ctx
, 3);
93 /* delete our entry in the serverid database. */
96 * For children the parent takes care of cleaning up
98 serverid_deregister(sconn_server_id(sconn
));
102 if (dcelogin_atmost_once
) {
108 /* Destroy Samba DMAPI session only if we are master smbd process */
110 if (!dmapi_destroy_session()) {
111 DEBUG(0,("Unable to close Samba DMAPI session\n"));
120 * we need to force the order of freeing the following,
121 * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
124 TALLOC_FREE(smbd_server_conn
);
125 server_messaging_context_free();
126 server_event_context_free();
127 TALLOC_FREE(smbd_memcache_ctx
);
129 if (how
!= SERVER_EXIT_NORMAL
) {
131 DEBUG(0,("Abnormal server exit: %s\n",
132 reason
? reason
: "no explanation provided"));
140 DEBUG(3,("Server exit (%s)\n",
141 (reason
? reason
: "normal exit")));
145 gencache_stabilize();
148 /* if we had any open SMB connections when we exited then we
149 need to tell the parent smbd so that it can trigger a retry
150 of any locks we may have been holding or open files we were
159 void exit_server(const char *const explanation
)
161 exit_server_common(SERVER_EXIT_ABNORMAL
, explanation
);
164 void exit_server_cleanly(const char *const explanation
)
166 exit_server_common(SERVER_EXIT_NORMAL
, explanation
);
169 void exit_server_fault(void)
171 exit_server("critical server fault");