source: trunk/oscam-chk.c@ 21

Last change on this file since 21 was 21, checked in by smurzch2, 12 years ago

Rename from MpCS to OSCam

File size: 7.6 KB
Line 
1#include "globals.h"
2
3static int chk_srvid_match(ECM_REQUEST *er, SIDTAB *sidtab)
4{
5 int i, rc=0;
6
7 if (!sidtab->num_caid)
8 rc|=1;
9 else
10 for (i=0; (i<sidtab->num_caid) && (!(rc&1)); i++)
11 if (er->caid==sidtab->caid[i]) rc|=1;
12
13 if (!sidtab->num_provid)
14 rc|=2;
15 else
16 for (i=0; (i<sidtab->num_provid) && (!(rc&2)); i++)
17 if (er->prid==sidtab->provid[i]) rc|=2;
18
19 if (!sidtab->num_srvid)
20 rc|=4;
21 else
22 for (i=0; (i<sidtab->num_srvid) && (!(rc&4)); i++)
23 if (er->srvid==sidtab->srvid[i]) rc|=4;
24
25 return(rc==7);
26}
27
28int chk_srvid(ECM_REQUEST *er, int idx)
29{
30 int nr, rc=0;
31 char *ptr;
32 SIDTAB *sidtab;
33
34 if (!client[idx].sidtabok)
35 {
36 if (!client[idx].sidtabno) return(1);
37 rc=1;
38 }
39 for (nr=0, sidtab=cfg->sidtab; sidtab; sidtab=sidtab->next, nr++)
40 if (sidtab->num_caid | sidtab->num_provid | sidtab->num_srvid)
41 {
42 if ((client[idx].sidtabno&(1<<nr)) &&
43 (chk_srvid_match(er, sidtab)))
44 return(0);
45 if ((client[idx].sidtabok&(1<<nr)) &&
46 (chk_srvid_match(er, sidtab)))
47 rc=1;
48 }
49 return(rc);
50}
51
52// server filter for newcamd
53int chk_sfilter(ECM_REQUEST *er, PTAB *ptab)
54{
55 int i, j, pi, rc=1;
56 ushort caid, scaid;
57 ulong prid, sprid;
58
59 if (!ptab) return(1);
60
61 caid = er->caid;
62 prid = er->prid;
63 pi = client[cs_idx].port_idx;
64
65 if (ptab->nports && ptab->ports[pi].ftab.nfilts)
66 {
67 for( rc=j=0; (!rc) && (j<ptab->ports[pi].ftab.nfilts); j++ )
68 {
69 scaid = ptab->ports[pi].ftab.filts[j].caid;
70 if (caid==0||(caid!=0 && caid==scaid))
71 {
72 for( i=0; (!rc) && i<ptab->ports[pi].ftab.filts[j].nprids; i++ )
73 {
74 sprid=ptab->ports[pi].ftab.filts[j].prids[i];
75 cs_debug("trying server filter %04X:%06X", scaid, sprid);
76 if (prid==sprid)
77 {
78 rc=1;
79 cs_debug("%04X:%06X allowed by server filter %04X:%06X",
80 caid, prid, scaid, sprid);
81 }
82 }
83 }
84 }
85 if(!rc)
86 {
87 cs_debug("no match, %04X:%06X rejected by server filters", caid, prid);
88 if (!er->rcEx) er->rcEx=(E1_LSERVER<<4)|E2_IDENT;
89 return(rc);
90 }
91 }
92 return (rc);
93}
94
95static int chk_chid(ECM_REQUEST *er, FTAB *fchid, char *type, char *name)
96{
97 int rc=1, i, j;
98
99 if( (er->caid & 0xFF00)!=0x600 ) return 1;
100 if( !er->chid ) return 1;
101 if( !fchid->nfilts ) return 1;
102
103 for( i=rc=0; (!rc) && i<fchid->nfilts; i++ )
104 if( er->caid == fchid->filts[i].caid )
105 for( j=0; (!rc) && j<fchid->filts[i].nprids; j++ )
106 {
107 cs_debug("trying %s '%s' CHID filter %04X:%04X",
108 type, name, fchid->filts[i].caid, fchid->filts[i].prids[j]);
109 if( er->chid == fchid->filts[i].prids[j] )
110 {
111 cs_debug("%04X:%04X allowed by %s '%s' CHID filter %04X:%04X",
112 er->caid, er->chid, type, name, fchid->filts[i].caid,
113 fchid->filts[i].prids[j]);
114 rc=1;
115 }
116 }
117
118 if( !rc ) cs_debug("no match, %04X:%04X rejected by %s '%s' CHID filter(s)",
119 er->caid, er->chid, type, name);
120
121 return (rc);
122}
123
124int chk_ufilters(ECM_REQUEST *er)
125{
126 int i, j, rc;
127 ushort ucaid;
128 ulong uprid;
129
130 rc=1;
131 if( client[cs_idx].ftab.nfilts )
132 {
133 FTAB *f = &client[cs_idx].ftab;
134 for( i=rc=0; (!rc) && (i<f->nfilts); i++ )
135 {
136 ucaid = f->filts[i].caid;
137 if( er->caid==0 || ucaid==0 || (er->caid!=0 && er->caid==ucaid) )
138 {
139 for( j=rc=0; (!rc) && (j<f->filts[i].nprids); j++ )
140 {
141 uprid = f->filts[i].prids[j];
142 cs_debug("trying user '%s' filter %04X:%06X",
143 client[cs_idx].usr, ucaid, uprid);
144 if( er->prid == uprid )
145 {
146 rc=1;
147 cs_debug("%04X:%06X allowed by user '%s' filter %04X:%06X",
148 er->caid, er->prid, client[cs_idx].usr, ucaid, uprid);
149 }
150 }
151 }
152 }
153 if( !rc ) {
154 cs_debug("no match, %04X:%06X rejected by user '%s' filters",
155 er->caid, er->prid, client[cs_idx].usr);
156 if( !er->rcEx ) er->rcEx=(E1_USER<<4)|E2_IDENT;
157 return (rc);
158 }
159 }
160
161 if( !(rc=chk_class(er, &client[cs_idx].cltab, "user", client[cs_idx].usr)) )
162 if( !er->rcEx ) er->rcEx=(E1_USER<<4)|E2_CLASS;
163 else if( !(rc=chk_chid(er, &client[cs_idx].fchid, "user", client[cs_idx].usr)) )
164 if( !er->rcEx ) er->rcEx=(E1_USER<<4)|E2_CHID;
165
166 if( rc ) er->rcEx=0;
167
168 return (rc);
169}
170
171int chk_rsfilter(ECM_REQUEST *er, int disable_server_filt)
172{
173 int i, rc=1;
174 ushort caid;
175 ulong prid;
176
177 if( disable_server_filt )
178 {
179 cs_debug("%04X:%06X allowed - server filters disabled",
180 er->caid, er->prid);
181 return 1;
182 }
183
184 rc=prid=0;
185 caid = reader[ridx].caid[0];
186 if( caid==er->caid )
187 {
188 for( i=0; (!rc) && (i<reader[ridx].nprov); i++ )
189 {
190 prid = (ulong)((reader[ridx].prid[i][0]<<16) |
191 (reader[ridx].prid[i][1]<<8) |
192 (reader[ridx].prid[i][2]));
193 cs_debug("trying server '%s' filter %04X:%06X",
194 reader[ridx].device, caid, prid);
195 if( prid==er->prid )
196 {
197 rc=1;
198 cs_debug("%04X:%06X allowed by server '%s' filter %04X:%06X",
199 er->caid, er->prid, reader[ridx].device, caid, prid);
200 }
201 }
202 }
203 if(!rc) {
204 cs_debug("no match, %04X:%06X rejected by server '%s' filters",
205 er->caid, er->prid, reader[ridx].device);
206 if( !er->rcEx ) er->rcEx=(E1_SERVER<<4)|E2_IDENT;
207 return 0;
208 }
209
210 return(rc);
211}
212
213int chk_rfilter(ECM_REQUEST *er, struct s_reader *rdr)
214{
215 int i, j, rc=1;
216 ushort caid=0;
217 ulong prid=0;
218
219 if( rdr->ftab.nfilts )
220 {
221 for( rc=i=0; (!rc) && (i<rdr->ftab.nfilts); i++ )
222 {
223 caid = rdr->ftab.filts[i].caid;
224 if( (caid!=0 && caid==er->caid) || caid==0 )
225 {
226 for( j=0; (!rc) && (j<rdr->ftab.filts[i].nprids); j++)
227 {
228 prid = rdr->ftab.filts[i].prids[j];
229 cs_debug("trying reader '%s' filter %04X:%06X",
230 rdr->label, caid, prid);
231 if( prid==er->prid )
232 {
233 rc=1;
234 cs_debug("%04X:%06X allowed by reader '%s' filter %04X:%06X",
235 er->caid, er->prid, rdr->label, caid, prid);
236 }
237 }
238 }
239 }
240 if(!rc) {
241 cs_debug("no match, %04X:%06X rejected by reader '%s' filters",
242 er->caid, er->prid, rdr->label);
243 return 0;
244 }
245 }
246
247 return(rc);
248}
249
250int chk_avail_reader(ECM_REQUEST *er, struct s_reader *rdr)
251{
252 if( !chk_rfilter(er, rdr) ) {
253 if( !er->rcEx ) er->rcEx=(E1_READER<<4)|E2_IDENT;
254 return 0;
255 }
256 if( !chk_class(er, &rdr->cltab, "reader", rdr->label) ) {
257 if( !er->rcEx ) er->rcEx=(E1_READER<<4)|E2_CLASS;
258 return 0;
259 }
260 if( !chk_chid(er, &rdr->fchid, "reader", rdr->label) ) {
261 if( !er->rcEx ) er->rcEx=(E1_READER<<4)|E2_CHID;
262 return 0;
263 }
264/*
265 if( rdr->typ=='r' )
266 {
267 if( rdr->qlen>=rdr->maxqlen )
268 {
269 cs_log("reader '%s' max. queue length(%d) reached, rejected", rdr->label,
270 rdr->qlen);
271 if( !er->rcEx ) er->rcEx=(E1_READER<<4)|E2_QUEUE;
272 return 0;
273 }
274 else {
275 cs_log("reader '%s' qlen=%d", rdr->label, rdr->qlen);
276 rdr->qlen++;
277 }
278 }
279*/
280 return 1;
281}
282
283int matching_reader(ECM_REQUEST *er, struct s_reader *rdr)
284{
285 if (!((rdr->fd) && (rdr->grp&client[cs_idx].grp))) return(0);
286 if (!chk_srvid(er, rdr->cs_idx))
287 return(0);
288 if (!chk_rfilter(er, rdr))
289 {
290// if (!er->rcEx) er->rcEx=(E1_READER<<4)|E2_IDENT;
291 return(0);
292 }
293 if (!chk_class(er, &rdr->cltab, "reader", rdr->label))
294 {
295// if (!er->rcEx) er->rcEx=(E1_READER<<4)|E2_CLASS;
296 return(0);
297 }
298 if (!chk_chid(er, &rdr->fchid, "reader", rdr->label))
299 {
300// if (!er->rcEx) er->rcEx=(E1_READER<<4)|E2_CHID;
301 return(0);
302 }
303 return(1);
304}
Note: See TracBrowser for help on using the repository browser.