From owner-freebsd-hackers Fri Feb 8 0:36:44 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from hotmail.com (f125.law4.hotmail.com [216.33.149.125]) by hub.freebsd.org (Postfix) with ESMTP id 8152F37B41A for ; Fri, 8 Feb 2002 00:36:36 -0800 (PST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Fri, 8 Feb 2002 00:36:36 -0800 Received: from 195.147.239.234 by lw4fd.law4.hotmail.msn.com with HTTP; Fri, 08 Feb 2002 08:36:36 GMT X-Originating-IP: [195.147.239.234] From: "Francis little" To: freebsd-hackers@freebsd.org Subject: suggestion/patch for ftpd Date: Fri, 08 Feb 2002 08:36:36 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 08 Feb 2002 08:36:36.0450 (UTC) FILETIME=[B869EC20:01C1B07B] Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hello all, i have writen a patch for ftpd that alows it to limit the number of users that log in. it currently works in daemon mode only. the user limit can be set with the option "-C". (it will through up an error if you use this option from "inetd"). If the "/etc/ftpwelcome" message is used then it will display the current/maximum number of connections after this message. If the user limit is not set then ftpd behaves as normal. below is a patch against 4.5-RELEASE.... Hope this is of use to some one... -OGGY *** /usr/src/libexec/KEEP_ME/ftpd/ftpd.c Tue Dec 18 18:35:55 2001 --- /usr/src/libexec/ftpd/ftpd.c Thu Feb 7 22:16:12 2002 *************** *** 153,158 **** --- 153,162 ---- int noretr=0; /* RETR command is disabled. */ int noguestretr=0; /* RETR command is disabled for anon users. */ + /* Two variables used for connection limiting */ + int maxusers = 0; /* maximum number of connections */ + int users = 0; /*current number of connections */ + sig_atomic_t transflag; off_t file_size; off_t byte_count; *************** *** 302,308 **** #endif /* OLD_SETPROCTITLE */ ! while ((ch = getopt(argc, argv, "AdlDESURrt:T:u:vOoa:p:46")) != -1) { switch (ch) { case 'D': daemon_mode++; --- 306,312 ---- #endif /* OLD_SETPROCTITLE */ ! while ((ch = getopt(argc, argv, "AdlDESC:URrt:T:u:vOoa:p:46")) != -1) { switch (ch) { case 'D': daemon_mode++; *************** *** 332,337 **** --- 336,349 ---- stats++; break; + /* Set the user limit */ + case 'C': + if (daemon_mode == 0) { + warnx("User limiting doesn't work from a super-server"); + } + maxusers = atoi(optarg); + break; + case 'T': maxtimeout = atoi(optarg); if (timeout > maxtimeout) *************** *** 507,512 **** --- 519,530 ---- while (1) { addrlen = server_addr.su_len; fd = accept(ctl_sock, (struct sockaddr *)&his_addr, &addrlen); + + /* We have a connection...*/ + if (maxusers != 0) { + users++; + } + if (fork() == 0) { /* child */ (void) dup2(fd, 0); *************** *** 591,596 **** --- 609,621 ---- reply(530, "System not available."); exit(0); } + + /* Are there are toomany users....*/ + if (maxusers != 0 && daemon_mode != 0 && users > maxusers) { + reply(421, "There are toomany users logged in. The maximum is: %lu", maxusers); + dologout(0); + } + #ifdef VIRTUAL_HOSTING if ((fd = fopen(thishost->welcome, "r")) != NULL) { #else *************** *** 601,606 **** --- 626,636 ---- *cp = '\0'; lreply(220, "%s", line); } + /* Lets tell them how many people are on...*/ + if (maxusers != 0 && daemon_mode != 0){ + lreply(230, "There are %lu users out of %lu logged in.", users, maxusers); + } + (void) fflush(stdout); (void) fclose(fd); /* reply(220,) must follow */ *************** *** 2778,2783 **** --- 2808,2819 ---- int signo; { while (wait3(NULL, WNOHANG, NULL) > 0); + + /* We'd better update when someone has gone...*/ + if (users !=0) { + users--; + } + } #ifdef OLD_SETPROCTITLE _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message