~ubuntu-branches/ubuntu/utopic/vsftpd/utopic-proposed

« back to all changes in this revision

Viewing changes to twoprocess.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-03 17:49:00 UTC
  • mto: (2.4.1 sid) (1.5.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20090503174900-0osuifgr8jknvu5e
Tags: upstream-2.1.1~pre1
ImportĀ upstreamĀ versionĀ 2.1.1~pre1

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
  }
91
91
  vsf_sysutil_install_sighandler(kVSFSysUtilSigCHLD, handle_sigchld, 0, 1);
92
92
  {
93
 
    int newpid;
94
 
    if (tunable_isolate_network)
95
 
    {
96
 
      newpid = vsf_sysutil_fork_newnet();
97
 
    }
98
 
    else
99
 
    {
100
 
      newpid = vsf_sysutil_fork();
101
 
    }
 
93
    int newpid = vsf_sysutil_fork();
102
94
    if (newpid != 0)
103
95
    {
104
96
      priv_sock_set_parent_context(p_sess);
128
120
                              VSFTP_CONF_FILE_MAX);
129
121
    if (vsf_sysutil_retval_is_error(retval))
130
122
    {
131
 
      die2("cannot read user list file:", tunable_userlist_file);
 
123
      die2("cannot open user list file:", tunable_userlist_file);
132
124
    }
133
125
  }
134
126
  drop_all_privs();
141
133
{
142
134
  struct mystr user_str = INIT_MYSTR;
143
135
  struct mystr dir_str = INIT_MYSTR;
144
 
  int option = VSF_SECUTIL_OPTION_CHROOT | VSF_SECUTIL_OPTION_NO_PROCS;
 
136
  int option = VSF_SECUTIL_OPTION_CHROOT;
145
137
  if (!tunable_ssl_enable)
146
138
  {
147
139
    /* Unfortunately, can only enable this if we can be sure of not using SSL.
208
200
vsf_two_process_get_priv_data_sock(struct vsf_session* p_sess)
209
201
{
210
202
  char res;
211
 
  unsigned short port = vsf_sysutil_sockaddr_get_port(p_sess->p_port_sockaddr);
212
203
  priv_sock_send_cmd(p_sess->child_fd, PRIV_SOCK_GET_DATA_SOCK);
213
 
  priv_sock_send_int(p_sess->child_fd, port);
214
204
  res = priv_sock_get_result(p_sess->child_fd);
215
 
  if (res == PRIV_SOCK_RESULT_BAD)
216
 
  {
217
 
    return -1;
218
 
  }
219
 
  else if (res != PRIV_SOCK_RESULT_OK)
 
205
  if (res != PRIV_SOCK_RESULT_OK)
220
206
  {
221
207
    die("could not get privileged socket");
222
208
  }
224
210
}
225
211
 
226
212
void
227
 
vsf_two_process_pasv_cleanup(struct vsf_session* p_sess)
228
 
{
229
 
  char res;
230
 
  priv_sock_send_cmd(p_sess->child_fd, PRIV_SOCK_PASV_CLEANUP);
231
 
  res = priv_sock_get_result(p_sess->child_fd);
232
 
  if (res != PRIV_SOCK_RESULT_OK)
233
 
  {
234
 
    die("could not clean up socket");
235
 
  }
236
 
}
237
 
 
238
 
int
239
 
vsf_two_process_pasv_active(struct vsf_session* p_sess)
240
 
{
241
 
  priv_sock_send_cmd(p_sess->child_fd, PRIV_SOCK_PASV_ACTIVE);
242
 
  return priv_sock_get_int(p_sess->child_fd);
243
 
}
244
 
 
245
 
unsigned short
246
 
vsf_two_process_listen(struct vsf_session* p_sess)
247
 
{
248
 
  priv_sock_send_cmd(p_sess->child_fd, PRIV_SOCK_PASV_LISTEN);
249
 
  return (unsigned short) priv_sock_get_int(p_sess->child_fd);
250
 
}
251
 
 
252
 
int
253
 
vsf_two_process_get_pasv_fd(struct vsf_session* p_sess)
254
 
{
255
 
  char res;
256
 
  priv_sock_send_cmd(p_sess->child_fd, PRIV_SOCK_PASV_ACCEPT);
257
 
  res = priv_sock_get_result(p_sess->child_fd);
258
 
  if (res == PRIV_SOCK_RESULT_BAD)
259
 
  {
260
 
    return priv_sock_get_int(p_sess->child_fd);
261
 
  }
262
 
  else if (res != PRIV_SOCK_RESULT_OK)
263
 
  {
264
 
    die("could not accept on listening socket");
265
 
  }
266
 
  return priv_sock_recv_fd(p_sess->child_fd);
267
 
}
268
 
 
269
 
void
270
213
vsf_two_process_chown_upload(struct vsf_session* p_sess, int fd)
271
214
{
272
215
  char res;
330
273
                                    VSFTP_CONF_FILE_MAX);
331
274
          if (vsf_sysutil_retval_is_error(retval))
332
275
          {
333
 
            die2("could not read chroot() list file:",
 
276
            die2("could not open chroot() list file:",
334
277
                 tunable_chroot_list_file);
335
278
          }
336
279
          if (str_contains_line(&chroot_list_file, &p_sess->user_str))
381
324
  priv_sock_close(p_sess);
382
325
  priv_sock_init(p_sess);
383
326
  vsf_sysutil_install_sighandler(kVSFSysUtilSigCHLD, handle_sigchld, 0, 1);
384
 
  if (tunable_isolate_network && !tunable_port_promiscuous)
385
 
  {
386
 
    newpid = vsf_sysutil_fork_newnet();
387
 
  }
388
 
  else
389
 
  {
390
 
    newpid = vsf_sysutil_fork();
391
 
  }
 
327
  newpid = vsf_sysutil_fork(); 
392
328
  if (newpid == 0)
393
329
  {
394
330
    struct mystr guest_user_str = INIT_MYSTR;
395
331
    struct mystr chroot_str = INIT_MYSTR;
396
332
    struct mystr chdir_str = INIT_MYSTR;
397
333
    struct mystr userdir_str = INIT_MYSTR;
398
 
    unsigned int secutil_option = VSF_SECUTIL_OPTION_USE_GROUPS |
399
 
                                  VSF_SECUTIL_OPTION_NO_PROCS;
 
334
    unsigned int secutil_option = VSF_SECUTIL_OPTION_USE_GROUPS;
400
335
    /* Child - drop privs and start proper FTP! */
401
336
    /* This PR_SET_PDEATHSIG doesn't work for all possible process tree setups.
402
337
     * The other cases are taken care of by a shutdown() of the command
478
413
  str_append_char(&filename_str, '/');
479
414
  str_append_str(&filename_str, p_user_str);
480
415
  retval = str_stat(&filename_str, &p_statbuf);
481
 
  if (!vsf_sysutil_retval_is_error(retval))
482
 
  {
483
 
    /* Security - file ownership check now in vsf_parseconf_load_file() */
484
 
    vsf_parseconf_load_file(str_getbuf(&filename_str), 1);
485
 
  }
486
 
  else if (vsf_sysutil_get_error() != kVSFSysUtilErrNOENT)
487
 
  {
488
 
    die("error opening per-user config file");
489
 
  }
 
416
  /* Security - file ownership check now in vsf_parseconf_load_file() */
 
417
  vsf_parseconf_load_file(str_getbuf(&filename_str), 1);
490
418
  str_free(&filename_str);
491
419
  vsf_sysutil_free(p_statbuf);
492
420
}