1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/* ### Modified by P.Saratxaga on 4 Jan 1996 ###
* - added pktpwlist from T.Tanaka
* - added pkt 2.2 support
* - added fsc-0048 support
*/
#include <stdio.h>
#include <string.h>
#include "lutil.h"
#include "xutil.h"
#include "ftn.h"
#include "bread.h"
#include "config.h"
#define min(a,b) ((a) <= (b) ? (a) : (b))
faddr pktfrom;
char pktpwd[9];
int getheader(f,t,pkt)
faddr *f,*t;
FILE *pkt;
{
int i,pwdok;
int capword,capvalid;
int tome,pointcheck;
int pkt_sub;
fa_list *al;
char *p,*pktpassword;
f->domain=NULL;
f->name=NULL;
t->domain=NULL;
t->name=NULL;
debug(5,"from node: %u",f->node=iread(pkt));
debug(5,"to node: %u",t->node=iread(pkt));
debug(5,"year : %u",capword=iread(pkt));
debug(5,"month : %u",capvalid=iread(pkt));
debug(5,"day : %u",iread(pkt));
debug(5,"hour : %u",iread(pkt));
debug(5,"min : %u",iread(pkt));
debug(5,"sec : %u",iread(pkt));
debug(5,"rate : %u",pkt_sub=iread(pkt));
if (pkt_sub==2) {
debug(5,"In fact it is a pkt 2.2 packet; so we have");
debug(5,"from pnt : %u",f->point=capword);
debug(5,"to pnt : %u",t->point=capvalid);
debug(5,"subver : %u",pkt_sub);
debug(5,"instead of year, month and rate respectively");
debug(5,"(hour, min, sec are meaningless)");
} else { pkt_sub=0; /* keep pkt sub version at 0 */ }
debug(5,"ver : %u",iread(pkt));
f->net=iread(pkt);
if ((f->net==-1) && (pkt_sub==0)) {
debug(5,"This is an fsc-0048 packet from a point");
} else {
debug(5,"from net : %u",f->net);
}
debug(5,"to net : %u",t->net=iread(pkt));
debug(5,"prodx : 0x%04x",iread(pkt));
for (i=0;i<8;i++) pktpwd[i]=getc(pkt);
pktpwd[8]='\0';
for (p=pktpwd+7;(p >= pktpwd) && (*p == ' ');p--) *p='\0';
debug(5,"password : %s",pktpwd);
if (pktpwd[0]) f->name=pktpwd;
debug(5,"from zone: %u",f->zone=iread(pkt));
debug(5,"to zone: %u",t->zone=iread(pkt));
if (pkt_sub==2) {
for (i=0;i<8;i++) *(p+i)=getc(pkt);
*(p+8)='\0';
debug(5,"from dom : %s",p);
if (*p) f->domain=xstrcpy(p);
for (i=0;i<8;i++) *(p+i)=getc(pkt);
*(p+8)='\0';
debug(5,"to dom : %s",p);
if (*p) t->domain=xstrcpy(p);
} else {
if ((f->net==-1) && (pkt_sub==0)) {
debug(5,"from net : %u",f->net=iread(pkt));
} else {
debug(5,"filler : 0x%04x",iread(pkt));
}
debug(5,"capvalid : 0x%04x",capvalid=iread(pkt));
debug(5,"prodcode : 0x%04x",iread(pkt));
debug(5,"capword : 0x%04x",capword=iread(pkt));
debug(5,"from zone: %u",iread(pkt));
debug(5,"to zone: %u",iread(pkt));
debug(5,"from pnt : %u",f->point=iread(pkt));
debug(5,"to pnt : %u",t->point=iread(pkt));
}
debug(5,"proddata : 0x%08lx",lread(pkt));
if (feof(pkt) || ferror(pkt))
{
logerr("$Could not read packet header");
return 2;
}
pointcheck=0;
if (pkt_sub==2) {
pointcheck=1;
} else {
if (((capword >> 8) == (capvalid & 0xff)) &&
((capvalid >> 8) == (capword & 0xff)))
pointcheck=(capword & 0x0001);
else capword=0;
}
debug(5,"capword=%04x, pointcheck=%s",capword,pointcheck?"yes":"no");
pktfrom.name=NULL;
pktfrom.domain=f->domain;
pktfrom.zone=f->zone;
pktfrom.net=f->net;
pktfrom.node=f->node;
if (pointcheck) pktfrom.point=f->point;
else pktfrom.point=0;
tome=0;
for (al=whoami;al;al=al->next)
{
if (((t->domain == NULL) ||
(strncasecmp(al->addr->domain,t->domain,
min(strlen(al->addr->domain),strlen(t->domain))))) &&
((t->zone == 0) || (t->zone == al->addr->zone)) &&
(t->net == al->addr->net) &&
(t->node == al->addr->node) &&
((!pointcheck) || (t->point == al->addr->point)))
tome=1;
}
pwdok=0;
pktpassword=NULL;
/* look between packetpasswd lines */
for (al=pktpwlist;al;al=al->next)
{
if (((f->domain == NULL) ||
(strncasecmp(al->addr->domain,f->domain,
min(strlen(al->addr->domain),strlen(f->domain))))) &&
((f->zone == 0) || (f->zone == al->addr->zone)) &&
(f->net == al->addr->net) &&
(f->node == al->addr->node) &&
((!pointcheck) || (f->point == al->addr->point)))
{
pktpassword=al->addr->name;
pwdok=1;
}
}
/* if not matching packetpasswd lines, search in password ones */
if (!pwdok) for (al=pwlist;al;al=al->next)
{
if (((f->domain == NULL) ||
(strncasecmp(al->addr->domain,f->domain,
min(strlen(al->addr->domain),strlen(f->domain))))) &&
((f->zone == 0) || (f->zone == al->addr->zone)) &&
(f->net == al->addr->net) &&
(f->node == al->addr->node) &&
((!pointcheck) || (f->point == al->addr->point)))
{
pktpassword=al->addr->name;
pwdok=1;
}
}
/* if we have a password (general or for packets) for that address */
if ((pwdok) && (strcasecmp(pktpassword,pktpwd) != 0))
{
loginf("password got \"%s\", expected \"%s\"",
pktpwd,pktpassword);
pwdok=0;
}
loginf("packet from node %s",ascfnode(f,0x1f));
loginf(" to node %s",ascfnode(t,0x1f));
if (!tome) return 3;
else if (!pwdok) return 4;
else return 0;
}
|