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

« back to all changes in this revision

Viewing changes to source4/smbd/process_standard.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:
23
23
 
24
24
#include "includes.h"
25
25
#include "lib/events/events.h"
26
 
#include "../tdb/include/tdb.h"
27
26
#include "smbd/process_model.h"
28
27
#include "system/filesys.h"
29
28
#include "cluster/cluster.h"
30
29
#include "param/param.h"
 
30
#include "ldb_wrap.h"
31
31
 
32
32
#ifdef HAVE_SETPROCTITLE
33
33
#ifdef HAVE_SETPROCTITLE_H
50
50
/*
51
51
  called when the process model is selected
52
52
*/
53
 
static void standard_model_init(struct tevent_context *ev)
 
53
static void standard_model_init(void)
54
54
{
55
55
        pipe(child_pipe);
56
56
        signal(SIGCHLD, SIG_IGN);
80
80
        NTSTATUS status;
81
81
        struct socket_context *sock2;
82
82
        pid_t pid;
83
 
        struct tevent_context *ev2;
84
83
        struct socket_address *c, *s;
85
84
 
86
85
        /* accept an incoming connection. */
106
105
        pid = getpid();
107
106
 
108
107
        /* This is now the child code. We need a completely new event_context to work with */
109
 
        ev2 = s4_event_context_init(NULL);
110
108
 
111
 
        /* the service has given us a private pointer that
112
 
           encapsulates the context it needs for this new connection -
113
 
           everything else will be freed */
114
 
        talloc_steal(ev2, private_data);
115
 
        talloc_steal(private_data, sock2);
 
109
        if (tevent_re_initialise(ev) != 0) {
 
110
                smb_panic("Failed to re-initialise tevent after fork");
 
111
        }
116
112
 
117
113
        /* this will free all the listening sockets and all state that
118
114
           is not associated with this new connection */
119
115
        talloc_free(sock);
120
 
        talloc_free(ev);
121
116
 
122
117
        /* we don't care if the dup fails, as its only a select()
123
118
           speed optimisation */
124
119
        socket_dup(sock2);
125
120
                        
126
121
        /* tdb needs special fork handling */
127
 
        if (tdb_reopen_all(1) == -1) {
128
 
                DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
129
 
        }
 
122
        ldb_wrap_fork_hook();
130
123
 
131
 
        tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
 
124
        tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
132
125
                      standard_pipe_handler, NULL);
133
126
        close(child_pipe[1]);
134
127
 
136
129
        set_need_random_reseed();
137
130
 
138
131
        /* setup the process title */
139
 
        c = socket_get_peer_addr(sock2, ev2);
140
 
        s = socket_get_my_addr(sock2, ev2);
 
132
        c = socket_get_peer_addr(sock2, ev);
 
133
        s = socket_get_my_addr(sock2, ev);
141
134
        if (s && c) {
142
135
                setproctitle("conn c[%s:%u] s[%s:%u] server_id[%d]",
143
 
                             c->addr, c->port, s->addr, s->port, pid);
 
136
                             c->addr, c->port, s->addr, s->port, (int)pid);
144
137
        }
145
138
        talloc_free(c);
146
139
        talloc_free(s);
147
140
 
148
141
        /* setup this new connection.  Cluster ID is PID based for this process modal */
149
 
        new_conn(ev2, lp_ctx, sock2, cluster_id(pid, 0), private_data);
 
142
        new_conn(ev, lp_ctx, sock2, cluster_id(pid, 0), private_data);
150
143
 
151
144
        /* we can't return to the top level here, as that event context is gone,
152
145
           so we now process events in the new event context until there are no
153
146
           more to process */      
154
 
        event_loop_wait(ev2);
 
147
        event_loop_wait(ev);
155
148
 
156
 
        talloc_free(ev2);
 
149
        talloc_free(ev);
157
150
        exit(0);
158
151
}
159
152
 
163
156
static void standard_new_task(struct tevent_context *ev, 
164
157
                              struct loadparm_context *lp_ctx,
165
158
                              const char *service_name,
166
 
                              void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *), 
 
159
                              void (*new_task)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *),
167
160
                              void *private_data)
168
161
{
169
162
        pid_t pid;
170
 
        struct tevent_context *ev2;
171
163
 
172
164
        pid = fork();
173
165
 
178
170
 
179
171
        pid = getpid();
180
172
 
181
 
        /* This is now the child code. We need a completely new event_context to work with */
182
 
        ev2 = s4_event_context_init(NULL);
183
 
 
184
 
        /* the service has given us a private pointer that
185
 
           encapsulates the context it needs for this new connection -
186
 
           everything else will be freed */
187
 
        talloc_steal(ev2, private_data);
188
 
 
189
173
        /* this will free all the listening sockets and all state that
190
174
           is not associated with this new connection */
191
 
        talloc_free(ev);
192
 
 
193
 
        /* tdb needs special fork handling */
194
 
        if (tdb_reopen_all(1) == -1) {
195
 
                DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n"));
 
175
        if (tevent_re_initialise(ev) != 0) {
 
176
                smb_panic("Failed to re-initialise tevent after fork");
196
177
        }
197
178
 
198
 
        tevent_add_fd(ev2, ev2, child_pipe[0], TEVENT_FD_READ,
 
179
        /* ldb/tdb need special fork handling */
 
180
        ldb_wrap_fork_hook();
 
181
 
 
182
        tevent_add_fd(ev, ev, child_pipe[0], TEVENT_FD_READ,
199
183
                      standard_pipe_handler, NULL);
200
184
        close(child_pipe[1]);
201
185
 
202
186
        /* Ensure that the forked children do not expose identical random streams */
203
187
        set_need_random_reseed();
204
188
 
205
 
        setproctitle("task %s server_id[%d]", service_name, pid);
 
189
        setproctitle("task %s server_id[%d]", service_name, (int)pid);
206
190
 
207
191
        /* setup this new task.  Cluster ID is PID based for this process modal */
208
 
        new_task(ev2, lp_ctx, cluster_id(pid, 0), private_data);
 
192
        new_task(ev, lp_ctx, cluster_id(pid, 0), private_data);
209
193
 
210
194
        /* we can't return to the top level here, as that event context is gone,
211
195
           so we now process events in the new event context until there are no
212
196
           more to process */      
213
 
        event_loop_wait(ev2);
 
197
        event_loop_wait(ev);
214
198
 
215
 
        talloc_free(ev2);
 
199
        talloc_free(ev);
216
200
        exit(0);
217
201
}
218
202
 
219
203
 
220
204
/* called when a task goes down */
221
 
_NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, 
 
205
_NORETURN_ static void standard_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx,
222
206
                                          const char *reason) 
223
207
{
224
208
        DEBUG(2,("standard_terminate: reason[%s]\n",reason));
225
209
 
 
210
        talloc_free(ev);
 
211
 
226
212
        /* this reload_charcnv() has the effect of freeing the iconv context memory,
227
213
           which makes leak checking easier */
228
214
        reload_charcnv(lp_ctx);
229
215
 
230
 
        talloc_free(ev);
231
 
 
232
216
        /* terminate this process */
233
217
        exit(0);
234
218
}