~ubuntu-branches/ubuntu/lucid/vsftpd/lucid-201001052349

« back to all changes in this revision

Viewing changes to dirchange.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-03-23 15:52:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050323155234-00xobn5vcl0nwozg
Tags: 2.0.1-1ubuntu1
pretty init scriptage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Part of Very Secure FTPd
3
 
 * Licence: GPL
4
 
 * Author: Chris Evans
5
 
 * dirchange.c
6
 
 *
7
 
 * Calls exposed to handle the junk a typical FTP server has to do upon
8
 
 * entering a new directory (messages, etc).
9
 
 */
10
 
 
11
 
#include "dirchange.h"
12
 
#include "strlist.h"
13
 
#include "str.h"
14
 
#include "sysstr.h"
15
 
#include "tunables.h"
16
 
#include "ftpcmdio.h"
17
 
#include "filestr.h"
18
 
#include "session.h"
19
 
#include "sysutil.h"
20
 
 
21
 
/* Definitions */
22
 
#define VSFTP_MAX_VISIT_REMEMBER 100
23
 
#define VSFTP_MAX_MSGFILE_SIZE 1000
24
 
 
25
 
void
26
 
dir_changed(struct vsf_session* p_sess, int ftpcode)
27
 
{
28
 
  struct mystr dir_str = INIT_MYSTR;
29
 
  /* Do nothing if .message support is off */
30
 
  if (!tunable_dirmessage_enable)
31
 
  {
32
 
    return;
33
 
  }
34
 
  if (p_sess->p_visited_dir_list == 0)
35
 
  {
36
 
    struct mystr_list the_list = INIT_STRLIST;
37
 
    p_sess->p_visited_dir_list = vsf_sysutil_malloc(sizeof(struct mystr_list));
38
 
    *p_sess->p_visited_dir_list = the_list;
39
 
  }
40
 
  str_getcwd(&dir_str);
41
 
  /* Do nothing if we already visited this directory */
42
 
  if (!str_list_contains_str(p_sess->p_visited_dir_list, &dir_str))
43
 
  {
44
 
    /* Just in case, cap the max. no of visited directories we'll remember */
45
 
    if (str_list_get_length(p_sess->p_visited_dir_list) <
46
 
        VSFTP_MAX_VISIT_REMEMBER)
47
 
    {
48
 
      str_list_add(p_sess->p_visited_dir_list, &dir_str, 0);
49
 
    }
50
 
    /* If we have a .message file, squirt it out prepended by the ftpcode and
51
 
     * the continuation mark '-'
52
 
     */
53
 
    {
54
 
      struct mystr msg_file_str = INIT_MYSTR;
55
 
      struct mystr msg_line_str = INIT_MYSTR;
56
 
      unsigned int str_pos = 0;
57
 
      (void) str_fileread(&msg_file_str, tunable_message_file,
58
 
                          VSFTP_MAX_MSGFILE_SIZE);
59
 
      while (str_getline(&msg_file_str, &msg_line_str, &str_pos))
60
 
      {
61
 
        vsf_cmdio_write_str_hyphen(p_sess, ftpcode, &msg_line_str);
62
 
      }
63
 
      str_free(&msg_file_str);
64
 
      str_free(&msg_line_str);
65
 
    }
66
 
  }
67
 
  str_free(&dir_str);
68
 
}
69