my Patch for nntpcache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I am a very casual C hacker, I have made a small change to nntpcache to suit
my needs in limiting IP connections per user.
This is a very small code change (and probably very clumsy).  But I am
posting it here so maybe someone can improve and integrate the patch into
nntpcache's main distribution.
The patch would allow nntpcache to refuse connections from people who
already have 2 streams open to nntpcached.  This is useful if you have a
limited connections number to your upstream news server.

The patch is simple: in file ./src/acc.c , change the existing function
fillAuth to look like this:

========== cut here ======================
EXPORT bool fillAuth (int fd, char *what)
{
   /* Start of code addition (1) */
    int tn;
    int clientstreams;  /*  This contains the number of streams initiated by
the client */
    struct task_info *task;
    clientstreams = 0;
   /* End of code addition (1) */

   if (con->useLibWrap && !authWrap(fd))
        return FALSE;
    if (!getAuth (fd, ClientHost, ClientHostNormal, ClientHostLocal,
ClientHostRFC931, ClientHostLocalRFC931, ClientHostAddr,
ClientHostAddrRFC931, sizeof (ClientHost), Host, &ClientRemoteAddr))
 return FALSE;
    strncpy (Task->ti_client_host, ClientHost, sizeof Task->ti_client_host);


   /* Start of code addition (2) */

    for (tn=0; tn<=Stats->task_high; tn++)
        {
            task = &TaskList[tn];
            if (task->ti_state == nc_none)
                continue;

            if (strCaseEq(task->ti_client_host,ClientHost))
                clientstreams++;

            if (clientstreams > 2) /* XXX it is better not to hardcode this
*/
                return FALSE;
        }
   /* End of code addition (2) */

    if (!(ConnectAuth = authorise (RemoteHosts, what)) || ConnectAuth->deny)
        return FALSE;
    return TRUE;
}
======= cut here ====================================



[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux