Thread View: news.software.nntp
2 messages
2 total messages
Started by hj
Tue, 12 Nov 1996 00:00
New INN feature: patch for IN.NNRPD (INN1.5beta2)
Author: hj
Date: Tue, 12 Nov 1996 00:00
Date: Tue, 12 Nov 1996 00:00
428 lines
12679 bytes
12679 bytes
Hi!
I have always wanted the ability to be able to limit the max simultaneous
connections one or a group of IP/nets could do to nnrpd, so today I and a
co-worker started working on this new feature. For the record, I am no
news guru. I have been administrating news for a couple of years, but
don't really know much about it anyway (at least compared to all you guys
:). We have only tested this patch, with no flaws, on Digital UNIX 3.2c
but I do believe it should compile on all other platforms INN compiles
on.. And remember, apply it on your own risk. Anyway... this is what the
patch do:
The normal nnrp.access file has the following look:
193.45.254.*:RP:username:password:groups
We add an optional 6th field:
193.45.254.*:RP:username:password:groups:access-group/limit
The 6th field is EITHER an access-group, or an integer limiting the MAX
connections from field 1 (193.45.254.*). Here follows 3 exemples:
1.) $NEWSPATH/nnrp.access
globecom.net:10
193.45.253.*:RP:::*:globecom.net
193.45.254.*:RP:::*:globecom.net
The above means that the two net's, 193.45.253. and 193.45.254. can have a
max of 10 simultaneous connections.
2.) $NEWSPATH/nnrp.access
193.45.253.*:RP:::*:10
193.45.254.*:RP:::*:10
The above means that the two net's, 193.45.253. and 193.45.254. can have a
max of 10 simultaneous connections each.
3.) $NEWSPATH/nnrp.access
*:RP:johndoe:password:*:1
The above means that user johndoe can have a maximum of 1 connection,
which obstructs the possibilty of two people sharing the same account at
the same time or connecting several times with e.g. Netscape.
If you leave the 6th field out (like it is normally), the IP/IP-net has
unlimited access (limited by the normal conditions, such as compile
options NNRP_LOADLIMIT and DEFAULT_CONNECTIONS).
The patch updates the following files: nnrpd/nnrpd.c, config/config.dist
and include/paths.h.
What else does it do? :)
Well, it add a few new log entries. Check the patch to see them. If all
works well, all that you will see is: "%s too_many_clients", which is sort
of self-explanatory.
It adds a new define to config.dist, which updates include/paths.h. The
define is: _PATH_NNRPTEMP, which is the path to the file holding the
different access-groups accessing your server.
There are a few rules which are mandatory:
1.) The access-group name can be max 100 chars long.
2.) The access-groups _MUST_ be declared _BEFORE_ any IP specifying access
control.
Example:
$ cat nnrp.access
group1:10
193.1.1.*:RP:::*:group1
193.1.2.*:RP:::*:group1
193.1.3.*:RP:::*:group1
193.1.4.*:RP:::*:group1
group2:5
123.45.67.*:RP:::*:group2
group3:1
*:RP:user:pass:*:group3
190.4.5.*:RP:::*:2
190.76.5.*:RP:::*:6
205.23.45.*:RP:::*
205.23.46.*:RP:::*
TODO:
-----
A lot! :)
1.) Innlog has to be updated to understand the new "%s too_many_clients",
and produce a useful (maybe) statistic.
2.) Inncheck has to be updated to understand this new syntax for
nnrp.access.
3.) Probably something else, but I can't remember it now.
Perhaps there is another way of doing this thing, but I haven't figured it
out. Hope you all like it.
--- begion included patch ---
Patch written by Henrik P. Johnson <hpj@globecom.net>. For more info about it,
or new versions (maybe), check out the following URL:
http://globecom.net/nnrpd-patch
*** nnrpd/nnrpd.c Mon Nov 11 15:51:26 1996
--- nnrpd/nnrpd.c Tue Nov 12 21:52:23 1996
***************
*** 47,52 ****
--- 47,53 ----
char ACTIVETIMES[] = _PATH_ACTIVETIMES;
char HISTORY[] = _PATH_HISTORY;
char NEWSGROUPS[] = _PATH_NEWSGROUPS;
+ char GROUPS[] = _PATH_TEMPNNRP;
/* Default permission -- change with adb. */
BOOL PERMdefault = FALSE;
***************
*** 58,63 ****
--- 59,65 ----
STATIC char *TITLEend;
#endif /* !defined(HPUX) */
STATIC SIGVAR ChangeTrace;
+ STATIC int GroupIndex=-1;
extern FUNCTYPE CMDauthinfo();
extern FUNCTYPE CMDdate();
***************
*** 131,136 ****
--- 133,157 ----
/*
+ ** Unreserv group if any
+ */
+
+ UnreservGroup(int fd)
+ {
+ int val;
+ if (lseek(fd,GroupIndex,SEEK_SET)!=GroupIndex)
+ syslog(L_NOTICE, "%s couldnt set fileposition", ClientHost);
+ read(fd,&val,sizeof(int));
+ val--;
+ if (val>=0) {
+ if (lseek(fd,GroupIndex,SEEK_SET)!=GroupIndex)
+ syslog(L_NOTICE, "%s couldnt set fileposition", ClientHost);
+ write(fd,&val,sizeof(int));
+ }
+ GroupIndex=-1;
+ }
+
+ /*
** Log a summary status message and exit.
*/
NORETURN
***************
*** 148,153 ****
--- 169,185 ----
usertime = 0;
systime = 0;
}
+ if (GroupIndex>=0) {
+ int GF;
+ GF=open(GROUPS,O_RDWR|O_CREAT|O_CREAT,0600);
+ if (GF<0)
+ syslog(L_ERROR, "%s cant open %s %m", ClientHost, GROUPS);
+ else {
+ LockFile(GF,TRUE);
+ UnreservGroup(GF);
+ close(GF);
+ }
+ }
GRPreport();
syslog(L_NOTICE, "%s exit articles %ld groups %ld",
***************
*** 301,307 ****
}
#endif /* defined(DO_NNRP_GETHOSTBYADDR) */
-
BOOL
PERMinfile(hp, ip, user, pass, accesslist)
char *hp;
--- 333,338 ----
***************
*** 315,323 ****
register char *p;
register BOOL found;
register int i;
struct passwd *pwd;
char buff[BIG_BUFFER];
! char *fields[5];
if ((F = fopen(ACCESS, "r")) == NULL) {
syslog(L_ERROR, "%s cant fopen %s %m", ClientHost, ACCESS);
--- 346,368 ----
register char *p;
register BOOL found;
register int i;
+
+ int GF=-1;
+ int mgl;
+ int ngi=0;
+ int its;
+ struct AccessGroup_str {
+ char Name[100];
+ int Number;
+ int Index;
+ } *AccessGroups=NULL;
+ int Number;
+ int NumGroups;
+ BOOL toomany=FALSE;
+
struct passwd *pwd;
char buff[BIG_BUFFER];
! char *fields[6];
if ((F = fopen(ACCESS, "r")) == NULL) {
syslog(L_ERROR, "%s cant fopen %s %m", ClientHost, ACCESS);
***************
*** 342,350 ****
*p = '\0';
fields[++i] = p + 1;
}
! if (i != 4)
! /* Malformed line. */
! continue;
if (hp)
/* Got an address; try to match either the IP address or as
--- 387,424 ----
*p = '\0';
fields[++i] = p + 1;
}
! if (i == 1) {
! NumGroups++;
! if (AccessGroups)
! AccessGroups=realloc(AccessGroups,sizeof(struct AccessGroup_str)*NumGroups);
! else
! AccessGroups=malloc(sizeof(struct AccessGroup_str)*NumGroups);
! strcpy(AccessGroups[NumGroups-1].Name,fields[0]);
! AccessGroups[NumGroups-1].Number=atoi(fields[1]);
! AccessGroups[NumGroups-1].Index=ngi;
! ngi+=sizeof(int);
! continue;
! } else if (i==5) {
! if (CTYPE(isalpha, fields[5][0])) {
! int i;
! its=-1;
! Number=0;
! for (i=0;i<NumGroups;i++) {
! if (EQ(fields[5],AccessGroups[i].Name)) {
! Number=AccessGroups[i].Number;
! its=AccessGroups[i].Index;
! break;
! }
! }
! } else {
! its=ngi;
! ngi+=sizeof(int);
! Number=atoi(fields[5]);
! }
! } else if (i != 4) {
! its=-1;
! continue;
! }
if (hp)
/* Got an address; try to match either the IP address or as
***************
*** 363,368 ****
--- 437,498 ----
else if (user && (!EQ(user, fields[2]) || !EQ(pass, fields[3])))
continue;
+ if (GroupIndex>=0) {
+ UnreservGroup(GF);
+ GroupIndex=its;
+ } else
+ GroupIndex=its;
+ if (i == 5) {
+ if (GF<0) {
+ struct stat buf;
+ if (stat(GROUPS,&buf))
+ mgl=0;
+ else
+ mgl=buf.st_size;
+
+ GF=open(GROUPS,O_RDWR|O_CREAT|O_CREAT,0600);
+ if (GF<0) {
+ syslog(L_ERROR, "%s cant open %s %m", ClientHost, GROUPS);
+ continue;
+ }
+ LockFile(GF,TRUE);
+ }
+ if (GroupIndex>=0&&GF>=0) {
+ int t;
+ if (GroupIndex>=mgl) {
+ if (Number>0) {
+ int tmgl=mgl;
+ lseek(GF,mgl,SEEK_SET);
+ for (t=0;mgl<GroupIndex;mgl+=sizeof(int)) {
+ if (write(GF,&t,sizeof(int))!=sizeof(int))
+ syslog(L_NOTICE, "%s could not write to %s %m", ClientHost, GROUPS);
+ }
+ t++;
+ syslog(L_NOTICE, "%s connected with new group entry", ClientHost, t);
+ if (write(GF,&t,sizeof(int))!=sizeof(int))
+ syslog(L_NOTICE, "%s could not write to %s %m", ClientHost, GROUPS);
+ mgl+=sizeof(int);
+ } else {
+ toomany=TRUE;
+ GroupIndex=-1;
+ }
+ } else {
+ lseek(GF,GroupIndex,SEEK_SET);
+ read(GF,&t,sizeof(int));
+ t++;
+ if (t>Number) {
+ GroupIndex=-1;
+ toomany=TRUE;
+ continue;
+ }
+ lseek(GF,GroupIndex,SEEK_SET);
+ if (write(GF,&t,sizeof(int))!=sizeof(int))
+ syslog(L_NOTICE, "%s could not write to %s %m", ClientHost, GROUPS);
+ }
+ }
+ } else
+ GroupIndex=-1;
+
PERMcanread = strchr(fields[1], 'R') != NULL;
PERMcanpost = strchr(fields[1], 'P') != NULL;
(void)strcpy(PERMuser, user ? user : fields[2]);
***************
*** 371,376 ****
--- 501,521 ----
found = TRUE;
}
(void)fclose(F);
+ if (AccessGroups)
+ free(AccessGroups);
+ if (GF>=0)
+ close(GF);
+ if (!found) {
+ if (toomany) {
+ Printf("%d Too many clients in your group, please contact your administrator. Goodbye.\r\n",
+ NNTP_ACCESS_VAL);
+ syslog(L_NOTICE, "%s too_many_clients", ClientHost);
+ } else {
+ Printf("%d You are not in my access file. Goodbye.\r\n",
+ NNTP_ACCESS_VAL);
+ syslog(L_NOTICE, "%s no_access", ClientHost);
+ }
+ }
return found;
}
***************
*** 443,451 ****
syslog(L_NOTICE, "%s connect", ClientHost);
if (!PERMinfile(ClientHost, ClientAddr, (char *)NULL, (char *)NULL,
accesslist)) {
- syslog(L_NOTICE, "%s no_access", ClientHost);
- Printf("%d You are not in my access file. Goodbye.\r\n",
- NNTP_ACCESS_VAL);
ExitWithStats(1);
}
}
--- 588,593 ----
*** include/paths.h Tue Nov 12 22:50:14 1996
--- include/paths.h Tue Nov 12 22:50:37 1996
***************
*** 114,119 ****
--- 114,121 ----
#define _PATH_DISTPATS "/var/news/etc/distrib.pats"
/* =()<#define _PATH_NNRPDIST "@<_PATH_NNRPDIST>@">()= */
#define _PATH_NNRPDIST "/var/news/etc/distributions"
+ /* =()<#define _PATH_TEMPNNRP "@<_PATH_TEMPNNRP>@">()= */
+ #define _PATH_TEMPNNRP "/var/tmp/nnrp.groups"
/* =()<#define _PATH_NNRPSUBS "@<_PATH_NNRPSUBS>@">()= */
#define _PATH_NNRPSUBS "/var/news/etc/subscriptions"
/* =()<#define _PATH_NEWSGROUPS "@<_PATH_NEWSGROUPS>@">()= */
*** config/config.dist Tue Nov 12 22:45:45 1996
--- config/config.dist Tue Nov 12 22:47:52 1996
***************
*** 720,725 ****
--- 720,727 ----
## Where NNRP distributions file is
#### =()<_PATH_NNRPDIST @<_PATH_NNRPDIST>@>()=
_PATH_NNRPDIST /var/news/etc/distributions
+ #### =()<_PATH_TEMPNNRP @<_PATH_TEMPNNRP>@>()=
+ _PATH_TEMPNNRP /var/tmp/nnrp.groups
## Where the NNRP automatic subscriptions file is
#### =()<_PATH_NNRPSUBS @<_PATH_NNRPSUBS>@>()=
_PATH_NNRPSUBS /var/news/etc/subscriptions
--- end included patch---
Please direct comments, questions etc. to me.
Regards
Henrik Johansson
GlobeCom Network
-----=<->=-----=</>=-----=<->=-----=<|>=-----=<->=-----=<\>=-----=<->=-----
Henrik Johansson email: hj@globecom.net tel: +46 (0)31-775 00 90
Systems Manager mobile: +46 (0)706-25 15 45 fax: +46 (0)31-775 00 85
GlobeCom Network "When communicating is your need" http://globecom.net/
-----=<->=-----=<\>=-----=<->=-----=<|>=-----=<->=-----=</>=-----=<->=-----
Re: New INN feature: patch for IN.NNRPD (INN1.5beta2)
Author: Heiko W.Rupp
Date: Thu, 14 Nov 1996 00:00
Date: Thu, 14 Nov 1996 00:00
36 lines
1917 bytes
1917 bytes
In <Pine.OSF.3.95.961112223434.13782A-100000@via.one.se>, hj@globecom.net wrote:
Hi!
:|I have always wanted the ability to be able to limit the max simultaneous
:|connections one or a group of IP/nets could do to nnrpd, so today I and a
Yery c00l thing ;-)
:|globecom.net:10
:|193.45.253.*:RP:::*:globecom.net
:|193.45.254.*:RP:::*:globecom.net
:|The above means that the two net's, 193.45.253. and 193.45.254. can have a
:|max of 10 simultaneous connections.
10 connections each or thogheter?
:|3.) $NEWSPATH/nnrp.access
:|
:|*:RP:johndoe:password:*:1
:|
:|The above means that user johndoe can have a maximum of 1 connection,
:|which obstructs the possibilty of two people sharing the same account at
:|the same time or connecting several times with e.g. Netscape.
This might be dangerous as some newsreaders have one authenticated
connection open for reading and open a second one for posting. I think
this also happens if one uses inews to post (but I think then you can't
have authentication).
--
Heiko W.Rupp hwr@pilhuhn.de
INN FAQ can be found in ftp://ftp.xlink.net/pub/news/docs/
Stoppt den Kinderwahnsinn !! -- Esst nur deutsche Kinder !!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads