~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/smbd/server_exit.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
10
 
 
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.
 
15
 
 
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.
 
20
 
 
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/>.
 
23
*/
 
24
 
 
25
#include "includes.h"
 
26
#include "smbd/smbd.h"
 
27
#include "smbd/globals.h"
 
28
#include "ntdomain.h"
 
29
#include "../librpc/gen_ndr/srv_dfs.h"
 
30
#include "../librpc/gen_ndr/srv_dssetup.h"
 
31
#include "../librpc/gen_ndr/srv_echo.h"
 
32
#include "../librpc/gen_ndr/srv_eventlog.h"
 
33
#include "../librpc/gen_ndr/srv_initshutdown.h"
 
34
#include "../librpc/gen_ndr/srv_lsa.h"
 
35
#include "../librpc/gen_ndr/srv_netlogon.h"
 
36
#include "../librpc/gen_ndr/srv_ntsvcs.h"
 
37
#include "../librpc/gen_ndr/srv_samr.h"
 
38
#include "../librpc/gen_ndr/srv_spoolss.h"
 
39
#include "../librpc/gen_ndr/srv_srvsvc.h"
 
40
#include "../librpc/gen_ndr/srv_svcctl.h"
 
41
#include "../librpc/gen_ndr/srv_winreg.h"
 
42
#include "../librpc/gen_ndr/srv_wkssvc.h"
 
43
#include "printing/notify.h"
 
44
#include "printing.h"
 
45
#include "serverid.h"
 
46
 
 
47
static struct files_struct *log_writeable_file_fn(
 
48
        struct files_struct *fsp, void *private_data)
 
49
{
 
50
        bool *found = (bool *)private_data;
 
51
        char *path;
 
52
 
 
53
        if (!fsp->can_write) {
 
54
                return NULL;
 
55
        }
 
56
        if (!(*found)) {
 
57
                DEBUG(0, ("Writable files open at exit:\n"));
 
58
                *found = true;
 
59
        }
 
60
 
 
61
        path = talloc_asprintf(talloc_tos(), "%s/%s", fsp->conn->connectpath,
 
62
                               smb_fname_str_dbg(fsp->fsp_name));
 
63
        if (path == NULL) {
 
64
                DEBUGADD(0, ("<NOMEM>\n"));
 
65
        }
 
66
 
 
67
        DEBUGADD(0, ("%s\n", path));
 
68
 
 
69
        TALLOC_FREE(path);
 
70
        return NULL;
 
71
}
 
72
 
 
73
/****************************************************************************
 
74
 Exit the server.
 
75
****************************************************************************/
 
76
 
 
77
/* Reasons for shutting down a server process. */
 
78
enum server_exit_reason { SERVER_EXIT_NORMAL, SERVER_EXIT_ABNORMAL };
 
79
 
 
80
static void exit_server_common(enum server_exit_reason how,
 
81
        const char *const reason) _NORETURN_;
 
82
 
 
83
static void exit_server_common(enum server_exit_reason how,
 
84
        const char *const reason)
 
85
{
 
86
        bool had_open_conn = false;
 
87
        struct smbd_server_connection *sconn = smbd_server_conn;
 
88
 
 
89
        if (!exit_firsttime)
 
90
                exit(0);
 
91
        exit_firsttime = false;
 
92
 
 
93
        change_to_root_user();
 
94
 
 
95
        if (sconn && sconn->smb1.negprot.auth_context) {
 
96
                TALLOC_FREE(sconn->smb1.negprot.auth_context);
 
97
        }
 
98
 
 
99
        if (sconn) {
 
100
                if (lp_log_writeable_files_on_exit()) {
 
101
                        bool found = false;
 
102
                        files_forall(sconn, log_writeable_file_fn, &found);
 
103
                }
 
104
                had_open_conn = conn_close_all(sconn);
 
105
                invalidate_all_vuids(sconn);
 
106
        }
 
107
 
 
108
        /* 3 second timeout. */
 
109
        print_notify_send_messages(sconn->msg_ctx, 3);
 
110
 
 
111
        /* delete our entry in the serverid database. */
 
112
        if (am_parent) {
 
113
                /*
 
114
                 * For children the parent takes care of cleaning up
 
115
                 */
 
116
                serverid_deregister(sconn_server_id(sconn));
 
117
        }
 
118
 
 
119
#ifdef WITH_DFS
 
120
        if (dcelogin_atmost_once) {
 
121
                dfs_unlogin();
 
122
        }
 
123
#endif
 
124
 
 
125
#ifdef USE_DMAPI
 
126
        /* Destroy Samba DMAPI session only if we are master smbd process */
 
127
        if (am_parent) {
 
128
                if (!dmapi_destroy_session()) {
 
129
                        DEBUG(0,("Unable to close Samba DMAPI session\n"));
 
130
                }
 
131
        }
 
132
#endif
 
133
 
 
134
        if (am_parent) {
 
135
                rpc_wkssvc_shutdown();
 
136
                rpc_dssetup_shutdown();
 
137
#ifdef DEVELOPER
 
138
                rpc_rpcecho_shutdown();
 
139
#endif
 
140
                rpc_netdfs_shutdown();
 
141
                rpc_initshutdown_shutdown();
 
142
                rpc_eventlog_shutdown();
 
143
                rpc_ntsvcs_shutdown();
 
144
                rpc_svcctl_shutdown();
 
145
                rpc_spoolss_shutdown();
 
146
 
 
147
                rpc_srvsvc_shutdown();
 
148
                rpc_winreg_shutdown();
 
149
 
 
150
                rpc_netlogon_shutdown();
 
151
                rpc_samr_shutdown();
 
152
                rpc_lsarpc_shutdown();
 
153
        }
 
154
 
 
155
        /*
 
156
         * we need to force the order of freeing the following,
 
157
         * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
 
158
         */
 
159
        sconn = NULL;
 
160
        TALLOC_FREE(smbd_server_conn);
 
161
        server_messaging_context_free();
 
162
        server_event_context_free();
 
163
        TALLOC_FREE(smbd_memcache_ctx);
 
164
 
 
165
        locking_end();
 
166
        printing_end();
 
167
 
 
168
        if (how != SERVER_EXIT_NORMAL) {
 
169
                DEBUGSEP(0);
 
170
                DEBUG(0,("Abnormal server exit: %s\n",
 
171
                        reason ? reason : "no explanation provided"));
 
172
                DEBUGSEP(0);
 
173
 
 
174
                log_stack_trace();
 
175
 
 
176
                dump_core();
 
177
 
 
178
        } else {
 
179
                DEBUG(3,("Server exit (%s)\n",
 
180
                        (reason ? reason : "normal exit")));
 
181
                if (am_parent) {
 
182
                        pidfile_unlink();
 
183
                }
 
184
                gencache_stabilize();
 
185
        }
 
186
 
 
187
        /* if we had any open SMB connections when we exited then we
 
188
           need to tell the parent smbd so that it can trigger a retry
 
189
           of any locks we may have been holding or open files we were
 
190
           blocking */
 
191
        if (had_open_conn) {
 
192
                exit(1);
 
193
        } else {
 
194
                exit(0);
 
195
        }
 
196
}
 
197
 
 
198
void exit_server(const char *const explanation)
 
199
{
 
200
        exit_server_common(SERVER_EXIT_ABNORMAL, explanation);
 
201
}
 
202
 
 
203
void exit_server_cleanly(const char *const explanation)
 
204
{
 
205
        exit_server_common(SERVER_EXIT_NORMAL, explanation);
 
206
}
 
207
 
 
208
void exit_server_fault(void)
 
209
{
 
210
        exit_server("critical server fault");
 
211
}