コード例 #1
0
static void
handle_size(struct vsf_session* p_sess)
{
  /* Note - in ASCII mode, are supposed to return the size after taking into
   * account ASCII linefeed conversions. At least this is what wu-ftpd does in
   * version 2.6.1. Proftpd-1.2.0pre fails to do this.
   * I will not do it because it is a potential I/O DoS.
   */
  static struct vsf_sysutil_statbuf* s_p_statbuf;
  int retval;
  if (!vsf_access_check_file(&p_sess->ftp_arg_str))
  {
    vsf_cmdio_write(p_sess, FTP_NOPERM, "Permission denied.");
    return;
  }
  retval = str_stat(&p_sess->ftp_arg_str, &s_p_statbuf);
  if (retval != 0 || !vsf_sysutil_statbuf_is_regfile(s_p_statbuf))
  {
    vsf_cmdio_write(p_sess, FTP_FILEFAIL, "Could not get file size.");
  }
  else
  {
    static struct mystr s_size_res_str;
    str_alloc_filesize_t(&s_size_res_str,
                         vsf_sysutil_statbuf_get_size(s_p_statbuf));
    vsf_cmdio_write_str(p_sess, FTP_SIZEOK, &s_size_res_str);
  }
}
コード例 #2
0
ファイル: ls.c プロジェクト: nikatshun/asuswrt-merlin
static void
build_dir_line(struct mystr* p_str, const struct mystr* p_filename_str,
               const struct vsf_sysutil_statbuf* p_stat, long curr_time)
{
    static struct mystr s_tmp_str;
    char *tmp_filename=NULL;
    filesize_t size = vsf_sysutil_statbuf_get_size(p_stat);
    /* Permissions */
    str_alloc_text(p_str, vsf_sysutil_statbuf_get_perms(p_stat));
    str_append_char(p_str, ' ');
    /* Hard link count */
    str_alloc_ulong(&s_tmp_str, vsf_sysutil_statbuf_get_links(p_stat));
    str_lpad(&s_tmp_str, 4);
    str_append_str(p_str, &s_tmp_str);
    str_append_char(p_str, ' ');
    /* User */
    if (tunable_hide_ids)
    {
        str_alloc_text(&s_tmp_str, "ftp");
    }
    else
    {
        int uid = vsf_sysutil_statbuf_get_uid(p_stat);
        struct vsf_sysutil_user* p_user = 0;
        if (tunable_text_userdb_names)
        {
            p_user = vsf_sysutil_getpwuid(uid);
        }
        if (p_user == 0)
        {
            str_alloc_ulong(&s_tmp_str, (unsigned long) uid);
        }
        else
        {
            str_alloc_text(&s_tmp_str, vsf_sysutil_user_getname(p_user));
        }
    }
    str_rpad(&s_tmp_str, 8);
    str_append_str(p_str, &s_tmp_str);
    str_append_char(p_str, ' ');
    /* Group */
    if (tunable_hide_ids)
    {
        str_alloc_text(&s_tmp_str, "ftp");
    }
    else
    {
        int gid = vsf_sysutil_statbuf_get_gid(p_stat);
        struct vsf_sysutil_group* p_group = 0;
        if (tunable_text_userdb_names)
        {
            p_group = vsf_sysutil_getgrgid(gid);
        }
        if (p_group == 0)
        {
            str_alloc_ulong(&s_tmp_str, (unsigned long) gid);
        }
        else
        {
            str_alloc_text(&s_tmp_str, vsf_sysutil_group_getname(p_group));
        }
    }
    str_rpad(&s_tmp_str, 8);
    str_append_str(p_str, &s_tmp_str);
    str_append_char(p_str, ' ');
    /* Size in bytes */
    str_alloc_filesize_t(&s_tmp_str, size);
    str_lpad(&s_tmp_str, 8);
    str_append_str(p_str, &s_tmp_str);
    str_append_char(p_str, ' ');
    /* Date stamp */
    str_append_text(p_str, vsf_sysutil_statbuf_get_date(p_stat,
                    tunable_use_localtime,
                    curr_time));
    str_append_char(p_str, ' ');
    /* Filename */
    tmp_filename = local2remote(str_getbuf(p_filename_str));
    if (tmp_filename == NULL)
        str_append_str(p_str, p_filename_str);
    else {
        str_append_text(p_str, tmp_filename);
        vsf_sysutil_free(tmp_filename);
    }
    str_append_text(p_str, "\r\n");
}