Date: Fri, 08 Feb 2002 08:36:36 +0000 From: "Francis little" <dj_oggy@hotmail.com> To: freebsd-hackers@freebsd.org Subject: suggestion/patch for ftpd Message-ID: <F125WHJVkl4AU1O6Yal0000bb0a@hotmail.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F125WHJVkl4AU1O6Yal0000bb0a>