1 /* knocker version 0.8.0
2  * Release date: 28 December 2020
3  *
4  * Project homepage: https://knocker.sourceforge.io
5  *
6  * Copyright 2001,2020 Gabriele Giorgetti <g.giorgetti@gmail.com>
7  *
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 */
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 
28 #include "knocker_services.h"
29 #include "knocker_core.h"
30 
31 
32 int knocker_core_services_db_init;
33 char *knocker_core_services_db[SERVICES_DB_TOTAL_SERVICES];
34 
35 
36 /* this following list of services has been automatically
37    generated from /etc/services */
38 
init_knocker_core_services_db(void)39 int init_knocker_core_services_db (void)
40 {
41 #ifdef DEBUG
42   int n_of_services = 0;
43   int i = 0;
44 #endif
45 
46 /* if it has been already initialized we do anything */
47   if (knocker_core_services_db_init)
48     return 0;
49 
50   knocker_core_services_db_init = 0;
51 
52 #ifdef DEBUG
53   fprintf (stderr, "debug: function init_knocker_core_services_db (...) called.\n");
54 #endif
55 
56 #ifdef DEBUG
57   fprintf (stderr, "debug: allocating memory to store service strings... ");
58 #endif
59 
60   knocker_core_services_db[1] = malloc (6 + 1);
61   strcpy (knocker_core_services_db[1], "tcpmux");
62 
63   if (knocker_core_services_db[1] == NULL)
64     return -1;
65 
66   knocker_core_services_db[7] = malloc (4 + 1);
67   strcpy (knocker_core_services_db[7], "echo");
68 
69   if (knocker_core_services_db[7] == NULL)
70     return -1;
71 
72   knocker_core_services_db[9] = malloc (7 + 1);
73   strcpy (knocker_core_services_db[9], "discard");
74 
75   if (knocker_core_services_db[9] == NULL)
76     return -1;
77 
78   knocker_core_services_db[11] = malloc (6 + 1);
79   strcpy (knocker_core_services_db[11], "systat");
80 
81   if (knocker_core_services_db[11] == NULL)
82     return -1;
83 
84   knocker_core_services_db[13] = malloc (7 + 1);
85   strcpy (knocker_core_services_db[13], "daytime");
86 
87   if (knocker_core_services_db[13] == NULL)
88     return -1;
89 
90   knocker_core_services_db[15] = malloc (7 + 1);
91   strcpy (knocker_core_services_db[15], "netstat");
92 
93   if (knocker_core_services_db[15] == NULL)
94     return -1;
95 
96   knocker_core_services_db[17] = malloc (4 + 1);
97   strcpy (knocker_core_services_db[17], "qotd");
98 
99   if (knocker_core_services_db[17] == NULL)
100     return -1;
101 
102   knocker_core_services_db[18] = malloc (3 + 1);
103   strcpy (knocker_core_services_db[18], "msp");
104 
105   if (knocker_core_services_db[18] == NULL)
106     return -1;
107 
108   knocker_core_services_db[19] = malloc (7 + 1);
109   strcpy (knocker_core_services_db[19], "chargen");
110 
111   if (knocker_core_services_db[19] == NULL)
112     return -1;
113 
114   knocker_core_services_db[20] = malloc (8 + 1);
115   strcpy (knocker_core_services_db[20], "ftp-data");
116 
117   if (knocker_core_services_db[20] == NULL)
118     return -1;
119 
120   knocker_core_services_db[21] = malloc (3 + 1);
121   strcpy (knocker_core_services_db[21], "ftp");
122 
123   if (knocker_core_services_db[21] == NULL)
124     return -1;
125 
126   knocker_core_services_db[22] = malloc (3 + 1);
127   strcpy (knocker_core_services_db[22], "ssh");
128 
129   if (knocker_core_services_db[22] == NULL)
130     return -1;
131 
132   knocker_core_services_db[23] = malloc (6 + 1);
133   strcpy (knocker_core_services_db[23], "telnet");
134 
135   if (knocker_core_services_db[23] == NULL)
136     return -1;
137 
138   knocker_core_services_db[25] = malloc (4 + 1);
139   strcpy (knocker_core_services_db[25], "smtp");
140 
141   if (knocker_core_services_db[25] == NULL)
142     return -1;
143 
144   knocker_core_services_db[37] = malloc (4 + 1);
145   strcpy (knocker_core_services_db[37], "time");
146 
147   if (knocker_core_services_db[37] == NULL)
148     return -1;
149 
150   knocker_core_services_db[39] = malloc (3 + 1);
151   strcpy (knocker_core_services_db[39], "rlp");
152 
153   if (knocker_core_services_db[39] == NULL)
154     return -1;
155 
156   knocker_core_services_db[42] = malloc (10 + 1);
157   strcpy (knocker_core_services_db[42], "nameserver");
158 
159   if (knocker_core_services_db[42] == NULL)
160     return -1;
161 
162   knocker_core_services_db[43] = malloc (5 + 1);
163   strcpy (knocker_core_services_db[43], "whois");
164 
165   if (knocker_core_services_db[43] == NULL)
166     return -1;
167 
168   knocker_core_services_db[50] = malloc (10 + 1);
169   strcpy (knocker_core_services_db[50], "re-mail-ck");
170 
171   if (knocker_core_services_db[50] == NULL)
172     return -1;
173 
174   knocker_core_services_db[53] = malloc (6 + 1);
175   strcpy (knocker_core_services_db[53], "domain");
176 
177   if (knocker_core_services_db[53] == NULL)
178     return -1;
179 
180   knocker_core_services_db[57] = malloc (3 + 1);
181   strcpy (knocker_core_services_db[57], "mtp");
182 
183   if (knocker_core_services_db[57] == NULL)
184     return -1;
185 
186   knocker_core_services_db[67] = malloc (6 + 1);
187   strcpy (knocker_core_services_db[67], "bootps");
188 
189   if (knocker_core_services_db[67] == NULL)
190     return -1;
191 
192   knocker_core_services_db[68] = malloc (6 + 1);
193   strcpy (knocker_core_services_db[68], "bootpc");
194 
195   if (knocker_core_services_db[68] == NULL)
196     return -1;
197 
198   knocker_core_services_db[69] = malloc (4 + 1);
199   strcpy (knocker_core_services_db[69], "tftp");
200 
201   if (knocker_core_services_db[69] == NULL)
202     return -1;
203 
204   knocker_core_services_db[70] = malloc (6 + 1);
205   strcpy (knocker_core_services_db[70], "gopher");
206 
207   if (knocker_core_services_db[70] == NULL)
208     return -1;
209 
210   knocker_core_services_db[77] = malloc (3 + 1);
211   strcpy (knocker_core_services_db[77], "rje");
212 
213   if (knocker_core_services_db[77] == NULL)
214     return -1;
215 
216   knocker_core_services_db[79] = malloc (6 + 1);
217   strcpy (knocker_core_services_db[79], "finger");
218 
219   if (knocker_core_services_db[79] == NULL)
220     return -1;
221 
222   knocker_core_services_db[80] = malloc (3 + 1);
223   strcpy (knocker_core_services_db[80], "www");
224 
225   if (knocker_core_services_db[80] == NULL)
226     return -1;
227 
228   knocker_core_services_db[87] = malloc (4 + 1);
229   strcpy (knocker_core_services_db[87], "link");
230 
231   if (knocker_core_services_db[87] == NULL)
232     return -1;
233 
234   knocker_core_services_db[88] = malloc (8 + 1);
235   strcpy (knocker_core_services_db[88], "kerberos");
236 
237   if (knocker_core_services_db[88] == NULL)
238     return -1;
239 
240   knocker_core_services_db[95] = malloc (6 + 1);
241   strcpy (knocker_core_services_db[95], "supdup");
242 
243   if (knocker_core_services_db[95] == NULL)
244     return -1;
245 
246   knocker_core_services_db[98] = malloc (9 + 1);
247   strcpy (knocker_core_services_db[98], "linuxconf");
248 
249   if (knocker_core_services_db[98] == NULL)
250     return -1;
251 
252   knocker_core_services_db[101] = malloc (9 + 1);
253   strcpy (knocker_core_services_db[101], "hostnames");
254 
255   if (knocker_core_services_db[101] == NULL)
256     return -1;
257 
258   knocker_core_services_db[102] = malloc (8 + 1);
259   strcpy (knocker_core_services_db[102], "iso-tsap");
260 
261   if (knocker_core_services_db[102] == NULL)
262     return -1;
263 
264   knocker_core_services_db[105] = malloc (8 + 1);
265   strcpy (knocker_core_services_db[105], "csnet-ns");
266 
267   if (knocker_core_services_db[105] == NULL)
268     return -1;
269 
270   knocker_core_services_db[107] = malloc (7 + 1);
271   strcpy (knocker_core_services_db[107], "rtelnet");
272 
273   if (knocker_core_services_db[107] == NULL)
274     return -1;
275 
276   knocker_core_services_db[109] = malloc (4 + 1);
277   strcpy (knocker_core_services_db[109], "pop2");
278 
279   if (knocker_core_services_db[109] == NULL)
280     return -1;
281 
282   knocker_core_services_db[110] = malloc (4 + 1);
283   strcpy (knocker_core_services_db[110], "pop3");
284 
285   if (knocker_core_services_db[110] == NULL)
286     return -1;
287 
288   knocker_core_services_db[111] = malloc (6 + 1);
289   strcpy (knocker_core_services_db[111], "sunrpc");
290 
291   if (knocker_core_services_db[111] == NULL)
292     return -1;
293 
294   knocker_core_services_db[113] = malloc (4 + 1);
295   strcpy (knocker_core_services_db[113], "auth");
296 
297   if (knocker_core_services_db[113] == NULL)
298     return -1;
299 
300   knocker_core_services_db[115] = malloc (4 + 1);
301   strcpy (knocker_core_services_db[115], "sftp");
302 
303   if (knocker_core_services_db[115] == NULL)
304     return -1;
305 
306   knocker_core_services_db[117] = malloc (9 + 1);
307   strcpy (knocker_core_services_db[117], "uucp-path");
308 
309   if (knocker_core_services_db[117] == NULL)
310     return -1;
311 
312   knocker_core_services_db[119] = malloc (4 + 1);
313   strcpy (knocker_core_services_db[119], "nntp");
314 
315   if (knocker_core_services_db[119] == NULL)
316     return -1;
317 
318   knocker_core_services_db[123] = malloc (3 + 1);
319   strcpy (knocker_core_services_db[123], "ntp");
320 
321   if (knocker_core_services_db[123] == NULL)
322     return -1;
323 
324   knocker_core_services_db[129] = malloc (6 + 1);
325   strcpy (knocker_core_services_db[129], "pwdgen");
326 
327   if (knocker_core_services_db[129] == NULL)
328     return -1;
329 
330   knocker_core_services_db[137] = malloc (10 + 1);
331   strcpy (knocker_core_services_db[137], "netbios-ns");
332 
333   if (knocker_core_services_db[137] == NULL)
334     return -1;
335 
336   knocker_core_services_db[138] = malloc (11 + 1);
337   strcpy (knocker_core_services_db[138], "netbios-dgm");
338 
339   if (knocker_core_services_db[138] == NULL)
340     return -1;
341 
342   knocker_core_services_db[139] = malloc (11 + 1);
343   strcpy (knocker_core_services_db[139], "netbios-ssn");
344 
345   if (knocker_core_services_db[139] == NULL)
346     return -1;
347 
348   knocker_core_services_db[143] = malloc (5 + 1);
349   strcpy (knocker_core_services_db[143], "imap2");
350 
351   if (knocker_core_services_db[143] == NULL)
352     return -1;
353 
354   knocker_core_services_db[161] = malloc (4 + 1);
355   strcpy (knocker_core_services_db[161], "snmp");
356 
357   if (knocker_core_services_db[161] == NULL)
358     return -1;
359 
360   knocker_core_services_db[162] = malloc (9 + 1);
361   strcpy (knocker_core_services_db[162], "snmp-trap");
362 
363   if (knocker_core_services_db[162] == NULL)
364     return -1;
365 
366   knocker_core_services_db[163] = malloc (8 + 1);
367   strcpy (knocker_core_services_db[163], "cmip-man");
368 
369   if (knocker_core_services_db[163] == NULL)
370     return -1;
371 
372   knocker_core_services_db[164] = malloc (10 + 1);
373   strcpy (knocker_core_services_db[164], "cmip-agent");
374 
375   if (knocker_core_services_db[164] == NULL)
376     return -1;
377 
378   knocker_core_services_db[174] = malloc (5 + 1);
379   strcpy (knocker_core_services_db[174], "mailq");
380 
381   if (knocker_core_services_db[174] == NULL)
382     return -1;
383 
384   knocker_core_services_db[177] = malloc (5 + 1);
385   strcpy (knocker_core_services_db[177], "xdmcp");
386 
387   if (knocker_core_services_db[177] == NULL)
388     return -1;
389 
390   knocker_core_services_db[178] = malloc (8 + 1);
391   strcpy (knocker_core_services_db[178], "nextstep");
392 
393   if (knocker_core_services_db[178] == NULL)
394     return -1;
395 
396   knocker_core_services_db[179] = malloc (3 + 1);
397   strcpy (knocker_core_services_db[179], "bgp");
398 
399   if (knocker_core_services_db[179] == NULL)
400     return -1;
401 
402   knocker_core_services_db[191] = malloc (8 + 1);
403   strcpy (knocker_core_services_db[191], "prospero");
404 
405   if (knocker_core_services_db[191] == NULL)
406     return -1;
407 
408   knocker_core_services_db[194] = malloc (3 + 1);
409   strcpy (knocker_core_services_db[194], "irc");
410 
411   if (knocker_core_services_db[194] == NULL)
412     return -1;
413 
414   knocker_core_services_db[199] = malloc (4 + 1);
415   strcpy (knocker_core_services_db[199], "smux");
416 
417   if (knocker_core_services_db[199] == NULL)
418     return -1;
419 
420   knocker_core_services_db[201] = malloc (7 + 1);
421   strcpy (knocker_core_services_db[201], "at-rtmp");
422 
423   if (knocker_core_services_db[201] == NULL)
424     return -1;
425 
426   knocker_core_services_db[202] = malloc (6 + 1);
427   strcpy (knocker_core_services_db[202], "at-nbp");
428 
429   if (knocker_core_services_db[202] == NULL)
430     return -1;
431 
432   knocker_core_services_db[204] = malloc (7 + 1);
433   strcpy (knocker_core_services_db[204], "at-echo");
434 
435   if (knocker_core_services_db[204] == NULL)
436     return -1;
437 
438   knocker_core_services_db[206] = malloc (6 + 1);
439   strcpy (knocker_core_services_db[206], "at-zis");
440 
441   if (knocker_core_services_db[206] == NULL)
442     return -1;
443 
444   knocker_core_services_db[209] = malloc (4 + 1);
445   strcpy (knocker_core_services_db[209], "qmtp");
446 
447   if (knocker_core_services_db[209] == NULL)
448     return -1;
449 
450   knocker_core_services_db[210] = malloc (5 + 1);
451   strcpy (knocker_core_services_db[210], "z3950");
452 
453   if (knocker_core_services_db[210] == NULL)
454     return -1;
455 
456   knocker_core_services_db[213] = malloc (3 + 1);
457   strcpy (knocker_core_services_db[213], "ipx");
458 
459   if (knocker_core_services_db[213] == NULL)
460     return -1;
461 
462   knocker_core_services_db[220] = malloc (5 + 1);
463   strcpy (knocker_core_services_db[220], "imap3");
464 
465   if (knocker_core_services_db[220] == NULL)
466     return -1;
467 
468   knocker_core_services_db[369] = malloc (11 + 1);
469   strcpy (knocker_core_services_db[369], "rpc2portmap");
470 
471   if (knocker_core_services_db[369] == NULL)
472     return -1;
473 
474   knocker_core_services_db[370] = malloc (9 + 1);
475   strcpy (knocker_core_services_db[370], "codaauth2");
476 
477   if (knocker_core_services_db[370] == NULL)
478     return -1;
479 
480   knocker_core_services_db[372] = malloc (9 + 1);
481   strcpy (knocker_core_services_db[372], "ulistserv");
482 
483   if (knocker_core_services_db[372] == NULL)
484     return -1;
485 
486   knocker_core_services_db[389] = malloc (4 + 1);
487   strcpy (knocker_core_services_db[389], "ldap");
488 
489   if (knocker_core_services_db[389] == NULL)
490     return -1;
491 
492   knocker_core_services_db[443] = malloc (5 + 1);
493   strcpy (knocker_core_services_db[443], "https");
494 
495   if (knocker_core_services_db[443] == NULL)
496     return -1;
497 
498   knocker_core_services_db[444] = malloc (4 + 1);
499   strcpy (knocker_core_services_db[444], "snpp");
500 
501   if (knocker_core_services_db[444] == NULL)
502     return -1;
503 
504   knocker_core_services_db[487] = malloc (4 + 1);
505   strcpy (knocker_core_services_db[487], "saft");
506 
507   if (knocker_core_services_db[487] == NULL)
508     return -1;
509 
510   knocker_core_services_db[610] = malloc (10 + 1);
511   strcpy (knocker_core_services_db[610], "npmp-local");
512 
513   if (knocker_core_services_db[610] == NULL)
514     return -1;
515 
516   knocker_core_services_db[611] = malloc (8 + 1);
517   strcpy (knocker_core_services_db[611], "npmp-gui");
518 
519   if (knocker_core_services_db[611] == NULL)
520     return -1;
521 
522   knocker_core_services_db[612] = malloc (8 + 1);
523   strcpy (knocker_core_services_db[612], "hmmp-ind");
524 
525   if (knocker_core_services_db[612] == NULL)
526     return -1;
527 
528   knocker_core_services_db[631] = malloc (3 + 1);
529   strcpy (knocker_core_services_db[631], "ipp");
530 
531   if (knocker_core_services_db[631] == NULL)
532     return -1;
533 
534   knocker_core_services_db[512] = malloc (4 + 1);
535   strcpy (knocker_core_services_db[512], "exec");
536 
537   if (knocker_core_services_db[512] == NULL)
538     return -1;
539 
540   knocker_core_services_db[513] = malloc (5 + 1);
541   strcpy (knocker_core_services_db[513], "login");
542 
543   if (knocker_core_services_db[513] == NULL)
544     return -1;
545 
546   knocker_core_services_db[514] = malloc (5 + 1);
547   strcpy (knocker_core_services_db[514], "shell");
548 
549   if (knocker_core_services_db[514] == NULL)
550     return -1;
551 
552   knocker_core_services_db[515] = malloc (7 + 1);
553   strcpy (knocker_core_services_db[515], "printer");
554 
555   if (knocker_core_services_db[515] == NULL)
556     return -1;
557 
558   knocker_core_services_db[517] = malloc (4 + 1);
559   strcpy (knocker_core_services_db[517], "talk");
560 
561   if (knocker_core_services_db[517] == NULL)
562     return -1;
563 
564   knocker_core_services_db[518] = malloc (5 + 1);
565   strcpy (knocker_core_services_db[518], "ntalk");
566 
567   if (knocker_core_services_db[518] == NULL)
568     return -1;
569 
570   knocker_core_services_db[520] = malloc (5 + 1);
571   strcpy (knocker_core_services_db[520], "route");
572 
573   if (knocker_core_services_db[520] == NULL)
574     return -1;
575 
576   knocker_core_services_db[525] = malloc (5 + 1);
577   strcpy (knocker_core_services_db[525], "timed");
578 
579   if (knocker_core_services_db[525] == NULL)
580     return -1;
581 
582   knocker_core_services_db[526] = malloc (5 + 1);
583   strcpy (knocker_core_services_db[526], "tempo");
584 
585   if (knocker_core_services_db[526] == NULL)
586     return -1;
587 
588   knocker_core_services_db[530] = malloc (7 + 1);
589   strcpy (knocker_core_services_db[530], "courier");
590 
591   if (knocker_core_services_db[530] == NULL)
592     return -1;
593 
594   knocker_core_services_db[531] = malloc (10 + 1);
595   strcpy (knocker_core_services_db[531], "conference");
596 
597   if (knocker_core_services_db[531] == NULL)
598     return -1;
599 
600   knocker_core_services_db[532] = malloc (7 + 1);
601   strcpy (knocker_core_services_db[532], "netnews");
602 
603   if (knocker_core_services_db[532] == NULL)
604     return -1;
605 
606   knocker_core_services_db[533] = malloc (7 + 1);
607   strcpy (knocker_core_services_db[533], "netwall");
608 
609   if (knocker_core_services_db[533] == NULL)
610     return -1;
611 
612   knocker_core_services_db[538] = malloc (6 + 1);
613   strcpy (knocker_core_services_db[538], "gdomap");
614 
615   if (knocker_core_services_db[538] == NULL)
616     return -1;
617 
618   knocker_core_services_db[540] = malloc (4 + 1);
619   strcpy (knocker_core_services_db[540], "uucp");
620 
621   if (knocker_core_services_db[540] == NULL)
622     return -1;
623 
624   knocker_core_services_db[548] = malloc (10 + 1);
625   strcpy (knocker_core_services_db[548], "afpovertcp");
626 
627   if (knocker_core_services_db[548] == NULL)
628     return -1;
629 
630   knocker_core_services_db[556] = malloc (8 + 1);
631   strcpy (knocker_core_services_db[556], "remotefs");
632 
633   if (knocker_core_services_db[556] == NULL)
634     return -1;
635 
636   knocker_core_services_db[543] = malloc (6 + 1);
637   strcpy (knocker_core_services_db[543], "klogin");
638 
639   if (knocker_core_services_db[543] == NULL)
640     return -1;
641 
642   knocker_core_services_db[544] = malloc (6 + 1);
643   strcpy (knocker_core_services_db[544], "kshell");
644 
645   if (knocker_core_services_db[544] == NULL)
646     return -1;
647 
648   knocker_core_services_db[563] = malloc (5 + 1);
649   strcpy (knocker_core_services_db[563], "nntps");
650 
651   if (knocker_core_services_db[563] == NULL)
652     return -1;
653 
654   knocker_core_services_db[636] = malloc (5 + 1);
655   strcpy (knocker_core_services_db[636], "ldaps");
656 
657   if (knocker_core_services_db[636] == NULL)
658     return -1;
659 
660   knocker_core_services_db[655] = malloc (4 + 1);
661   strcpy (knocker_core_services_db[655], "tinc");
662 
663   if (knocker_core_services_db[655] == NULL)
664     return -1;
665 
666   knocker_core_services_db[749] = malloc (12 + 1);
667   strcpy (knocker_core_services_db[749], "kerberos-adm");
668 
669   if (knocker_core_services_db[749] == NULL)
670     return -1;
671 
672   knocker_core_services_db[765] = malloc (7 + 1);
673   strcpy (knocker_core_services_db[765], "webster");
674 
675   if (knocker_core_services_db[765] == NULL)
676     return -1;
677 
678   knocker_core_services_db[873] = malloc (5 + 1);
679   strcpy (knocker_core_services_db[873], "rsync");
680 
681   if (knocker_core_services_db[873] == NULL)
682     return -1;
683 
684   knocker_core_services_db[989] = malloc (9 + 1);
685   strcpy (knocker_core_services_db[989], "ftps-data");
686 
687   if (knocker_core_services_db[989] == NULL)
688     return -1;
689 
690   knocker_core_services_db[990] = malloc (4 + 1);
691   strcpy (knocker_core_services_db[990], "ftps");
692 
693   if (knocker_core_services_db[990] == NULL)
694     return -1;
695 
696   knocker_core_services_db[992] = malloc (7 + 1);
697   strcpy (knocker_core_services_db[992], "telnets");
698 
699   if (knocker_core_services_db[992] == NULL)
700     return -1;
701 
702   knocker_core_services_db[993] = malloc (5 + 1);
703   strcpy (knocker_core_services_db[993], "imaps");
704 
705   if (knocker_core_services_db[993] == NULL)
706     return -1;
707 
708   knocker_core_services_db[994] = malloc (4 + 1);
709   strcpy (knocker_core_services_db[994], "ircs");
710 
711   if (knocker_core_services_db[994] == NULL)
712     return -1;
713 
714   knocker_core_services_db[995] = malloc (5 + 1);
715   strcpy (knocker_core_services_db[995], "pop3s");
716 
717   if (knocker_core_services_db[995] == NULL)
718     return -1;
719 
720   knocker_core_services_db[1080] = malloc (5 + 1);
721   strcpy (knocker_core_services_db[1080], "socks");
722 
723   if (knocker_core_services_db[1080] == NULL)
724     return -1;
725 
726   knocker_core_services_db[1352] = malloc (9 + 1);
727   strcpy (knocker_core_services_db[1352], "lotusnote");
728 
729   if (knocker_core_services_db[1352] == NULL)
730     return -1;
731 
732   knocker_core_services_db[1524] = malloc (10 + 1);
733   strcpy (knocker_core_services_db[1524], "ingreslock");
734 
735   if (knocker_core_services_db[1524] == NULL)
736     return -1;
737 
738   knocker_core_services_db[1525] = malloc (11 + 1);
739   strcpy (knocker_core_services_db[1525], "prospero-np");
740 
741   if (knocker_core_services_db[1525] == NULL)
742     return -1;
743 
744   knocker_core_services_db[1645] = malloc (11 + 1);
745   strcpy (knocker_core_services_db[1645], "datametrics");
746 
747   if (knocker_core_services_db[1645] == NULL)
748     return -1;
749 
750   knocker_core_services_db[1646] = malloc (11 + 1);
751   strcpy (knocker_core_services_db[1646], "sa-msg-port");
752 
753   if (knocker_core_services_db[1646] == NULL)
754     return -1;
755 
756   knocker_core_services_db[1812] = malloc (6 + 1);
757   strcpy (knocker_core_services_db[1812], "radius");
758 
759   if (knocker_core_services_db[1812] == NULL)
760     return -1;
761 
762   knocker_core_services_db[1813] = malloc (11 + 1);
763   strcpy (knocker_core_services_db[1813], "radius-acct");
764 
765   if (knocker_core_services_db[1813] == NULL)
766     return -1;
767 
768   knocker_core_services_db[2101] = malloc (10 + 1);
769   strcpy (knocker_core_services_db[2101], "rtcm-sc104");
770 
771   if (knocker_core_services_db[2101] == NULL)
772     return -1;
773 
774   knocker_core_services_db[2401] = malloc (10 + 1);
775   strcpy (knocker_core_services_db[2401], "cvspserver");
776 
777   if (knocker_core_services_db[2401] == NULL)
778     return -1;
779 
780   knocker_core_services_db[2430] = malloc (5 + 1);
781   strcpy (knocker_core_services_db[2430], "venus");
782 
783   if (knocker_core_services_db[2430] == NULL)
784     return -1;
785 
786   knocker_core_services_db[2431] = malloc (8 + 1);
787   strcpy (knocker_core_services_db[2431], "venus-se");
788 
789   if (knocker_core_services_db[2431] == NULL)
790     return -1;
791 
792   knocker_core_services_db[2432] = malloc (7 + 1);
793   strcpy (knocker_core_services_db[2432], "codasrv");
794 
795   if (knocker_core_services_db[2432] == NULL)
796     return -1;
797 
798   knocker_core_services_db[2433] = malloc (10 + 1);
799   strcpy (knocker_core_services_db[2433], "codasrv-se");
800 
801   if (knocker_core_services_db[2433] == NULL)
802     return -1;
803 
804   knocker_core_services_db[2583] = malloc (3 + 1);
805   strcpy (knocker_core_services_db[2583], "mon");
806 
807   if (knocker_core_services_db[2583] == NULL)
808     return -1;
809 
810   knocker_core_services_db[2628] = malloc (4 + 1);
811   strcpy (knocker_core_services_db[2628], "dict");
812 
813   if (knocker_core_services_db[2628] == NULL)
814     return -1;
815 
816   knocker_core_services_db[3050] = malloc (6 + 1);
817   strcpy (knocker_core_services_db[3050], "gds_db");
818 
819   if (knocker_core_services_db[3050] == NULL)
820     return -1;
821 
822   knocker_core_services_db[3130] = malloc (5 + 1);
823   strcpy (knocker_core_services_db[3130], "icpv2");
824 
825   if (knocker_core_services_db[3130] == NULL)
826     return -1;
827 
828   knocker_core_services_db[3306] = malloc (5 + 1);
829   strcpy (knocker_core_services_db[3306], "mysql");
830 
831   if (knocker_core_services_db[3306] == NULL)
832     return -1;
833 
834   knocker_core_services_db[5002] = malloc (3 + 1);
835   strcpy (knocker_core_services_db[5002], "rfe");
836 
837   if (knocker_core_services_db[5002] == NULL)
838     return -1;
839 
840   knocker_core_services_db[5308] = malloc (8 + 1);
841   strcpy (knocker_core_services_db[5308], "cfengine");
842 
843   if (knocker_core_services_db[5308] == NULL)
844     return -1;
845 
846   knocker_core_services_db[6000] = malloc (3 + 1);
847   strcpy (knocker_core_services_db[6000], "x11");
848 
849   if (knocker_core_services_db[6000] == NULL)
850     return -1;
851 
852   knocker_core_services_db[6001] = malloc (5 + 1);
853   strcpy (knocker_core_services_db[6001], "x11-1");
854 
855   if (knocker_core_services_db[6001] == NULL)
856     return -1;
857 
858   knocker_core_services_db[6002] = malloc (5 + 1);
859   strcpy (knocker_core_services_db[6002], "x11-2");
860 
861   if (knocker_core_services_db[6002] == NULL)
862     return -1;
863 
864   knocker_core_services_db[6003] = malloc (5 + 1);
865   strcpy (knocker_core_services_db[6003], "x11-3");
866 
867   if (knocker_core_services_db[6003] == NULL)
868     return -1;
869 
870   knocker_core_services_db[6004] = malloc (5 + 1);
871   strcpy (knocker_core_services_db[6004], "x11-4");
872 
873   if (knocker_core_services_db[6004] == NULL)
874     return -1;
875 
876   knocker_core_services_db[6005] = malloc (5 + 1);
877   strcpy (knocker_core_services_db[6005], "x11-5");
878 
879   if (knocker_core_services_db[6005] == NULL)
880     return -1;
881 
882   knocker_core_services_db[6006] = malloc (5 + 1);
883   strcpy (knocker_core_services_db[6006], "x11-6");
884 
885   if (knocker_core_services_db[6006] == NULL)
886     return -1;
887 
888   knocker_core_services_db[6007] = malloc (5 + 1);
889   strcpy (knocker_core_services_db[6007], "x11-7");
890 
891   if (knocker_core_services_db[6007] == NULL)
892     return -1;
893 
894   knocker_core_services_db[7000] = malloc (15 + 1);
895   strcpy (knocker_core_services_db[7000], "afs3-fileserver");
896 
897   if (knocker_core_services_db[7000] == NULL)
898     return -1;
899 
900   knocker_core_services_db[7001] = malloc (13 + 1);
901   strcpy (knocker_core_services_db[7001], "afs3-callback");
902 
903   if (knocker_core_services_db[7001] == NULL)
904     return -1;
905 
906   knocker_core_services_db[7002] = malloc (13 + 1);
907   strcpy (knocker_core_services_db[7002], "afs3-prserver");
908 
909   if (knocker_core_services_db[7002] == NULL)
910     return -1;
911 
912   knocker_core_services_db[7003] = malloc (13 + 1);
913   strcpy (knocker_core_services_db[7003], "afs3-vlserver");
914 
915   if (knocker_core_services_db[7003] == NULL)
916     return -1;
917 
918   knocker_core_services_db[7004] = malloc (13 + 1);
919   strcpy (knocker_core_services_db[7004], "afs3-kaserver");
920 
921   if (knocker_core_services_db[7004] == NULL)
922     return -1;
923 
924   knocker_core_services_db[7005] = malloc (11 + 1);
925   strcpy (knocker_core_services_db[7005], "afs3-volser");
926 
927   if (knocker_core_services_db[7005] == NULL)
928     return -1;
929 
930   knocker_core_services_db[7006] = malloc (11 + 1);
931   strcpy (knocker_core_services_db[7006], "afs3-errors");
932 
933   if (knocker_core_services_db[7006] == NULL)
934     return -1;
935 
936   knocker_core_services_db[7007] = malloc (8 + 1);
937   strcpy (knocker_core_services_db[7007], "afs3-bos");
938 
939   if (knocker_core_services_db[7007] == NULL)
940     return -1;
941 
942   knocker_core_services_db[7008] = malloc (11 + 1);
943   strcpy (knocker_core_services_db[7008], "afs3-update");
944 
945   if (knocker_core_services_db[7008] == NULL)
946     return -1;
947 
948   knocker_core_services_db[7009] = malloc (11 + 1);
949   strcpy (knocker_core_services_db[7009], "afs3-rmtsys");
950 
951   if (knocker_core_services_db[7009] == NULL)
952     return -1;
953 
954   knocker_core_services_db[7100] = malloc (12 + 1);
955   strcpy (knocker_core_services_db[7100], "font-service");
956 
957   if (knocker_core_services_db[7100] == NULL)
958     return -1;
959 
960   knocker_core_services_db[22273] = malloc (4 + 1);
961   strcpy (knocker_core_services_db[22273], "wnn6");
962 
963   if (knocker_core_services_db[22273] == NULL)
964     return -1;
965 
966   knocker_core_services_db_init = 1;    /* Initialization complete */
967 
968 #ifdef DEBUG
969   fprintf (stderr, "done.\n");
970 #endif
971 
972 
973 #ifdef DEBUG
974   for (i = 0; i < SERVICES_DB_TOTAL_SERVICES; i++)
975     {
976       if (knocker_core_services_db[i] != NULL)
977         n_of_services++;
978     }
979   fprintf (stderr, "debug: succesfully stored %d service strings.\n", n_of_services);
980 #endif
981 
982   return 0;
983 }
984 
985 
free_knocker_core_services_db(void)986 void free_knocker_core_services_db (void)
987 {
988   int i;
989 
990   /* if it hasn't been initialized yet we don't free anything */
991   if (!knocker_core_services_db_init)
992     return;
993 
994   for (i = 0; i < SERVICES_DB_TOTAL_SERVICES; i++)
995     {
996 	/* FIXME DELIBERATELLY NOT FREEING HERE TO AVOID CRASHDUMPS
997       if (knocker_core_services_db[i] != NULL)
998         free (knocker_core_services_db[i]); */
999     }
1000 
1001   knocker_core_services_db_init = 0;    /* deinitialized state */
1002 }
1003 
1004 
knocker_core_services_db_get_service(unsigned int port,int protocol)1005 char *knocker_core_services_db_get_service (unsigned int port, int protocol)
1006 {
1007   int slenght;                  /* string lenght */
1008 
1009   if (!knocker_core_services_db_init)
1010     {
1011       /* if the services string list is not initialized */
1012       return NULL;
1013     }
1014 
1015   if (protocol != PROTO_TCP)
1016     {
1017 
1018       if (protocol != PROTO_UDP)
1019         {
1020           return NULL;
1021         }
1022     }
1023 
1024   /* this functions returns the number of copied chars in tmpstr, if it is
1025      successfull, else -1 */
1026   if (knocker_core_services_db[port] != NULL)
1027     slenght = strlen (knocker_core_services_db[port]);
1028   else
1029     slenght = -1;
1030 
1031   if (slenght == -1)
1032     {
1033       if (knocker_core_last_service == NULL)
1034         {
1035           knocker_core_last_service = malloc (strlen ("unknown") + 1);
1036           strcpy (knocker_core_last_service, "unknown");
1037         }
1038       else
1039         {
1040           knocker_core_last_service = realloc (knocker_core_last_service, strlen ("unknown") + 1);
1041           strcpy (knocker_core_last_service, "unknown");
1042         }
1043       return NULL;
1044     }
1045 
1046 
1047   if (knocker_core_last_service == NULL)
1048     {
1049       knocker_core_last_service = malloc (slenght + 1);
1050     }
1051   else
1052     {
1053       knocker_core_last_service = realloc (knocker_core_last_service, slenght + 1);
1054 
1055     }
1056 
1057   return (strcpy (knocker_core_last_service, knocker_core_services_db[port]));
1058 }
1059