Author Topic: set a limit for the number of files per user  (Read 412 times)

Offline lsplouis

  • New user
  • *
  • Posts: 6
    • View Profile
set a limit for the number of files per user
« on: November 04, 2016, 11:23:37 am »
Hey guys,

I hope I'm right here, I am looking for a setting for my proftpd server. It's running on Ubuntu 16.04.
I need to limit the maximium number of files for a user.

Note: every user works in his own directory and can't leave it.

It would be also nice that the user can recognize an error message from the system (like the 530 if you cannot login)

Thank you, Louis

Offline castaglia

  • Administrator
  • Support Hero
  • *****
  • Posts: 5221
    • View Profile
    • http://www.castaglia.org/
Re: set a limit for the number of files per user
« Reply #1 on: November 08, 2016, 02:41:15 pm »
For this, you would want to use the file upload limit of mod_quotatab; it controls how many files a user may upload (and thus have) to the server.  If your users have files already there, you might also look into using the ScanOnLogin QuotaOption, to take those existing files into account.

Offline lsplouis

  • New user
  • *
  • Posts: 6
    • View Profile
Re: set a limit for the number of files per user
« Reply #2 on: November 08, 2016, 02:55:23 pm »
Sounds good - I already saw that in your documentation.

I try to get it run and tell you about it then.

Thank you!

Offline lsplouis

  • New user
  • *
  • Posts: 6
    • View Profile
Re: set a limit for the number of files per user
« Reply #3 on: November 09, 2016, 03:29:24 pm »
Hey,

it seems like Im really to dumb to do this. Here is step by step list how I tryed to do it:

1. Create the two databases (' ftpquota --create-table --type=limit ' and ' ftpquota --create-table --type=tally ')
2. Update the tables with the first entry (' ftpquota --add-record --type=limit --quota-type=all --Fu=1 ')
3. Restart the proftpd service with (' systemctl restart proftpd ')
4. Now I tried to upload several files and it still works.

I also tried to limit the transferred files to 1 - there is no change. By the way I need to say that my users a stored in a MySQL Database.
Maybe that is the point, where the quota doesnt work with ?

Sorry for my bad english.

Thank you for helping me, Louis

Offline castaglia

  • Administrator
  • Support Hero
  • *****
  • Posts: 5221
    • View Profile
    • http://www.castaglia.org/
Re: set a limit for the number of files per user
« Reply #4 on: November 09, 2016, 11:55:08 pm »
What does your full mod_quotatab configuration look like?

Offline lsplouis

  • New user
  • *
  • Posts: 6
    • View Profile
Re: set a limit for the number of files per user
« Reply #5 on: November 10, 2016, 07:41:52 am »
Here is Screenshot of 'ftpquota --show-records --type=limit'

Here is a better Descripton of what i want:

A user is allowed to store at least one file on the FTP server - if he tries to upload another file this should be cancled by the server. If there is already a file in his directory, he should also not be allowed to put another into it. When there ist no file, he can store only one there but not a second one.

Thank you for help, Louis

Offline castaglia

  • Administrator
  • Support Hero
  • *****
  • Posts: 5221
    • View Profile
    • http://www.castaglia.org/
Re: set a limit for the number of files per user
« Reply #6 on: November 10, 2016, 04:18:06 pm »
No, I asked for the relevant mod_quotatab directives from your proftpd.conf, not the output from ftpquota.  It would also help if you defined a QuotaLog in your proftpd.conf, and examined that file to see why it might not be behaving as you expect.

Offline lsplouis

  • New user
  • *
  • Posts: 6
    • View Profile
Re: set a limit for the number of files per user
« Reply #7 on: November 11, 2016, 08:19:30 am »
Hey,

I maybe found another mistake in the proftpd.conf, you can see it on the screenshot.
This value was "off", I changed it to "on", but there ist still no change.

Here is the full proftpd.conf:

#
# /etc/proftpd/proftpd.conf -- This is a basic ProFTPD configuration file.
# To really apply changes, reload proftpd after modifications, if
# it runs in daemon mode. It is not required in inetd/xinetd mode.
#

# Includes DSO modules
Include /etc/proftpd/modules.conf

# Set off to disable IPv6 support which is annoying on IPv4 only boxes.
UseIPv6                         on
# If set on you can experience a longer connection delay in many cases.
IdentLookups                    off

ServerName                      "server.server.server.com"
ServerType                      standalone
DeferWelcome                    off
DefaultRoot ~

MultilineRFC2228                on
DefaultServer                   on
ShowSymlinks                    on

TimeoutNoTransfer               600
TimeoutStalled                  600
TimeoutIdle                     1200

DisplayLogin                    welcome.msg
DisplayChdir                    .message true
ListOptions                     "-l"

DenyFilter                      \*.*/

# Use this to jail all users in their homes
# DefaultRoot                   ~

# Users require a valid shell listed in /etc/shells to login.
# Use this directive to release that constrain.
# RequireValidShell             off

# Port 21 is the standard FTP port.
Port                            21

# In some cases you have to specify passive ports range to by-pass
# firewall limitations. Ephemeral ports can be used for that, but
# feel free to use a more narrow range.
# PassivePorts                  49152 65534




# If your host was NATted, this option is useful in order to
# allow passive tranfers to work. You have to use your public
# address and opening the passive ports used on your firewall as well.
# MasqueradeAddress             1.2.3.4

# This is useful for masquerading address with dynamic IPs:
# refresh any configured MasqueradeAddress directives every 8 hours
<IfModule mod_dynmasq.c>
# DynMasqRefresh 28800
</IfModule>

# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances                    30

# Set the user and group that the server normally runs at.
User                            proftpd
Group                           nogroup

# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.
Umask                           022  022
# Normally, we want files to be overwriteable.
AllowOverwrite                  on

# Uncomment this if you are using NIS or LDAP via NSS to retrieve passwords:
# PersistentPasswd              off

# This is required to use both PAM-based authentication and local passwords
# AuthOrder                     mod_auth_pam.c* mod_auth_unix.c

# Be warned: use of this directive impacts CPU average load!
# Uncomment this if you like to see progress and transfer rate with ftpwho
# in downloads. That is not needed for uploads rates.
#
# UseSendFile                   off

TransferLog /var/log/proftpd/xferlog
SystemLog   /var/log/proftpd/proftpd.log

# Logging onto /var/log/lastlog is enabled but set to off by default
#UseLastlog on

# In order to keep log file dates consistent after chroot, use timezone info
# from /etc/localtime.  If this is not set, and proftpd is configured to
# chroot (e.g. DefaultRoot or <Anonymous>), it will use the non-daylight
# savings timezone regardless of whether DST is in effect.
#SetEnv TZ :/etc/localtime

<IfModule mod_quotatab.c>
QuotaEngine on
</IfModule>

<IfModule mod_ratio.c>
Ratios off
</IfModule>


# Delay engine reduces impact of the so-called Timing Attack described in
# http://www.securityfocus.com/bid/11430/discuss
# It is on by default.
<IfModule mod_delay.c>
DelayEngine on
</IfModule>

<IfModule mod_ctrls.c>
ControlsEngine        off
ControlsMaxClients    2
ControlsLog           /var/log/proftpd/controls.log
ControlsInterval      5
ControlsSocket        /var/run/proftpd/proftpd.sock

</IfModule>

<IfModule mod_ctrls_admin.c>
AdminControlsEngine off
</IfModule>

#
# Alternative authentication frameworks
#
#Include /etc/proftpd/ldap.conf
#Include /etc/proftpd/sql.conf

#
# This is used for FTPS connections
#
Include /etc/proftpd/tls.conf

#
# Useful to keep VirtualHost/VirtualRoot directives separated
#
#Include /etc/proftpd/virtuals.conf

# A basic anonymous configuration, no upload directories.

# <Anonymous ~ftp>
#   User                                ftp
#   Group                               nogroup
#   # We want clients to be able to login with "anonymous" as well as "ftp"
#   UserAlias                   anonymous ftp
#   # Cosmetic changes, all files belongs to ftp user
#   DirFakeUser on ftp
#   DirFakeGroup on ftp
#
#   RequireValidShell           off
#
#   # Limit the maximum number of anonymous logins
#   MaxClients                  10
#
#   # We want 'welcome.msg' displayed at login, and '.message' displayed
#   # in each newly chdired directory.
#   DisplayLogin                        welcome.msg
#   DisplayChdir                .message
#
#   # Limit WRITE everywhere in the anonymous chroot
#   <Directory *>
#     <Limit WRITE>
#       DenyAll
#     </Limit>
#   </Directory>
#
# </Anonymous>

# Include other custom configuration files
Include /etc/proftpd/conf.d/
Include /etc/proftpd/sql.conf

RequireValidShell         off



Offline castaglia

  • Administrator
  • Support Hero
  • *****
  • Posts: 5221
    • View Profile
    • http://www.castaglia.org/
Re: set a limit for the number of files per user
« Reply #8 on: November 11, 2016, 02:39:54 pm »
I don't know what .conf files are in your /etc/proftpd/conf.d/ directory; maybe they have more mod_quotatab-related configuration.  That said, just having "QuotaEngine on" is not enough; you need to tell mod_quotatab where its limit/tally tables are, via the QuotaLimitTable and QuotaTallyTable directives; see:

  http://www.proftpd.org/docs/contrib/mod_quotatab_file.html

You can also see an example configuration here:

  http://www.proftpd.org/docs/howto/Quotas.html