Changeset 8 for trunk/src/rules_mgmt.c
- Timestamp:
- 10/20/05 15:05:40 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/rules_mgmt.c
r2 r8 72 72 if (rPtr!=NULL){ 73 73 fprintf(stderr, "\nid: %hu\n", rPtr->id); 74 if (rPtr->prev) { fprintf(stderr, "\nid prev: %hu\n", rPtr->prev->id);} 75 if (rPtr->next) { fprintf(stderr, "\nid next: %hu\n", rPtr->next->id);} 74 76 fprintf(stderr, "Name: %s\n", rPtr->ruleName); 75 77 /* puts (asctime (& rPtr->begin)); */ … … 137 139 { 138 140 RulesPtr tmp = NULL; 139 if (rPtr->prev!=NULL) { 140 rPtr->prev->next = rPtr->next; 141 if (rPtr==firstrPtr) { 142 if (rPtr->next) { 143 tmp = rPtr->next; 144 tmp->prev = NULL; 145 freeRule(rPtr); 146 return tmp; 147 }else{ 148 freeRule(rPtr); 149 return NULL; 150 } 151 } else { 152 if (rPtr->prev->next) { rPtr->prev->next = rPtr->next;} 141 153 if (rPtr->next) {rPtr->next->prev = rPtr->prev;} 142 154 freeRule(rPtr); 143 155 return firstrPtr; 144 } else { 145 if (rPtr->next) { 146 rPtr->next->prev = NULL; 147 tmp = rPtr->next; 148 } 149 freeRule(rPtr); 150 return tmp; 151 } 152 } 153 154 RulesPtr 156 } 157 } 158 159 RulesPtr 155 160 getRules(RulesPtr rPtr, char *filename) 156 161 { 157 162 FILE *ruleFile; 158 163 RulesPtr tmp = NULL; 164 RulesPtr tmp2 = NULL; 159 165 time_t hour; 160 166 char line[512]; … … 168 174 169 175 if (!(ruleFile = fopen(filename, "r"))) { 170 fprintf (stderr, "error during %s opening\n", filename);176 syslog(LOG_ERR, "error during %s opening\n", filename); 171 177 exit(1); 172 178 } … … 184 190 strTok, 185 191 strName) == 0) { 186 fprintf(stderr, "Error in file %s, line %d\n",192 syslog(LOG_ERR, "Error in file %s, line %d\n", 187 193 filename, cptLine); 188 194 exit(1); … … 192 198 tmp = (RulesPtr) malloc(sizeof(struct Rules)); 193 199 if (tmp==NULL) { 194 fprintf(stderr, "ERROR in malloc in getRule function\n");200 syslog(LOG_ERR, "ERROR in malloc in getRule function\n"); 195 201 exit(1); 196 202 } else { … … 202 208 tmp->db = NULL; 203 209 tmp->next = rPtr; 210 /* rPtr->prev = tmp; */ 204 211 tmp->prev = NULL; 205 212 } … … 214 221 str1, 215 222 str2) == 0) { 216 fprintf(stderr, "Error in file %s, line %d\n",223 syslog(LOG_ERR, "Error in file %s, line %d\n", 217 224 filename, cptLine); 218 225 exit(1); … … 244 251 cptLine++; 245 252 } 246 /* if (rPtr!=NULL) { rPtr->prev = tmp;} */247 253 /* tmp->prev = NULL; */ 248 254 } 249 return tmp; 255 tmp2 = tmp; 256 for ( ; tmp2; tmp2=tmp2->next) { 257 if (tmp2->next) { 258 tmp2->next->prev = tmp2; 259 } 260 } 261 fclose(ruleFile); 262 return tmp; 250 263 } 251 264 … … 255 268 FILE *ruleFile; 256 269 RulesPtr tmp = NULL; 270 RulesPtr tmp2 = NULL; 257 271 time_t hour; 258 272 char line[512]; … … 266 280 267 281 if (!(ruleFile = fopen(filename, "r"))) { 268 fprintf (stderr, "error during %s opening\n", filename);282 syslog(LOG_ERR, "error during %s opening\n", filename); 269 283 exit(1); 270 284 } … … 282 296 strTok, 283 297 strName) == 0) { 284 fprintf(stderr, "Error in file %s, line %d\n",298 syslog(LOG_ERR, "Error in file %s, line %d\n", 285 299 filename, cptLine); 286 300 exit(1); … … 290 304 tmp = (RulesPtr) malloc(sizeof(struct Rules)); 291 305 if (tmp==NULL) { 292 fprintf(stderr, "ERROR in malloc in getRule function\n");306 syslog(LOG_ERR, "ERROR in malloc in getRule function\n"); 293 307 exit(1); 294 308 } else { … … 312 326 str1, 313 327 str2) == 0) { 314 fprintf(stderr, "Error in file %s, line %d\n",328 syslog(LOG_ERR, "Error in file %s, line %d\n", 315 329 filename, cptLine); 316 330 exit(1); … … 332 346 } 333 347 if (strncmp("A", lineCopy, 1) == 0){ 334 syslog(LOG_INFO,"Aggregation mode isn't yet implemented \n");348 syslog(LOG_INFO,"Aggregation mode isn't yet implemented"); 335 349 } 336 350 if (strncmp("R", lineCopy, 1) == 0){ … … 339 353 cptLine++; 340 354 } 341 /* if (rPtr!=NULL) { rPtr->prev = tmp;} */ 342 /* tmp->prev = NULL; */ 343 } 355 } 356 tmp2 = tmp; 357 for ( ; tmp2; tmp2=tmp2->next) { 358 if (tmp2->next) { 359 tmp2->next->prev = tmp2; 360 } 361 } 362 fclose(ruleFile); 344 363 return tmp; 345 364 } … … 348 367 addFileDef(FilePtr fPtr, char *str1, char *str2) 349 368 { 350 fprintf(stderr,"add file def: %s %s \n", str1, str2); 369 /* fprintf(stderr,"add file def: %s %s \n", str1, str2); */ 351 370 return NULL; 352 371 } … … 358 377 tmp = (RemoteHostPtr) malloc(sizeof(struct RemoteHost)); 359 378 if (tmp==NULL) { 360 fprintf(stderr, "ERROR in malloc in addRemoteHostDef function\n");379 syslog(LOG_ERR, "ERROR in malloc in addRemoteHostDef function"); 361 380 exit(1); 362 381 } else { 363 tmp->hostAddressPtr = (struct sockaddr_ in*)364 malloc(sizeof(struct sockaddr_ in));382 tmp->hostAddressPtr = (struct sockaddr_storage*) 383 malloc(sizeof(struct sockaddr_storage)); 365 384 if (tmp->hostAddressPtr==NULL) { 366 fprintf(stderr, "ERROR in malloc in addRemoteHostDef function\n");385 syslog(LOG_ERR, "ERROR in malloc in addRemoteHostDef function"); 367 386 exit(1); 368 387 } else { 369 tmp->sockId = create_socket( str1, atoi(str2), tmp->hostAddressPtr); 388 if ((tmp->sockId=create_socket( str1, str2, tmp->hostAddressPtr))==0) 389 return NULL; 370 390 tmp->next = rPtr; 371 391 } … … 376 396 DbPtr 377 397 addDataBase(DbPtr dPtr, char *str1, char *str2){ 378 fprintf(stderr,"add DB def: %s %s \n", str1, str2);398 syslog(LOG_INFO,"DB output not in this release"); 379 399 return NULL; 380 400 } … … 392 412 unsigned short length; 393 413 if (sscanf(fields, " %hu %hu ", &type, &length) == 0) { 394 fprintf(stderr,395 "Errors in definition of fields to record: wrong syntax \n");414 syslog(LOG_ERR, 415 "Errors in definition of fields to record: wrong syntax"); 396 416 exit(1); 397 417 } else { … … 424 444 tmp = (RuleDefPtr) malloc(sizeof(struct RuleDef)); 425 445 if (tmp==NULL) { 426 fprintf(stderr, "ERROR in malloc in addRuleDef function\n");446 syslog(LOG_ERR, "ERROR in malloc in addRuleDef function"); 427 447 exit(1); 428 448 } else { 429 449 if (sscanf(fields, " %hu %1s %s ", &ft, operator, value) == 0) { 430 fprintf(stderr, "Errors in Tests definition : wrong syntax\n");450 syslog(LOG_ERR, "Errors in Tests definition : wrong syntax"); 431 451 exit(1); 432 452 } … … 456 476 } else { 457 477 syslog(LOG_INFO, 458 "You can't compare the field <%hu> currently, sorry\n",478 "You can't compare the field <%hu> in this release, sorry", 459 479 ft); 460 480 } … … 479 499 tmp = (ValuesPtr) malloc(sizeof(struct Values)); 480 500 if (tmp==NULL) { 481 fprintf(stderr, "ERROR in malloc in addAddress function\n");501 syslog(LOG_ERR, "ERROR in malloc in addAddress function"); 482 502 exit(1); 483 503 } else { 484 504 if (sscanf(val, "%hu.%hu.%hu.%hu", &v0, &v1, &v2, &v3) == 0) { 485 fprintf(stderr, "Errors in Tests definition : wrong IPv4 value\n");505 syslog(LOG_ERR, "Errors in Tests definition : wrong IPv4 value"); 486 506 exit(1); 487 507 } … … 507 527 tmp = (ValuesPtr) malloc(sizeof(struct Values)); 508 528 if (tmp==NULL) { 509 fprintf(stderr, "ERROR in malloc in addV6Address function\n");529 syslog(LOG_ERR, "ERROR in malloc in addV6Address function"); 510 530 exit(1); 511 531 } else { … … 513 533 switch(result) { 514 534 case 0 : 515 printf(" inet_pton : Invalid IPv6 Address\n");535 syslog(LOG_ERR," inet_pton : Invalid IPv6 Address"); 516 536 exit(1); 517 537 break; 518 538 case -1: 519 printf(" inet_pton : AF unknown \n");539 syslog(LOG_ERR," inet_pton : AF unknown"); 520 540 exit(1); 521 541 break; … … 540 560 tmp = (ValuesPtr) malloc(sizeof(struct Values)); 541 561 if (tmp==NULL) { 542 fprintf(stderr, "ERROR in malloc in addValue function\n");562 syslog(LOG_ERR, "ERROR in malloc in addValue function"); 543 563 exit(1); 544 564 } else { 545 565 if (sscanf(val, "%s", value) == 0) { 546 fprintf(stderr, "Errors in Tests definition : wrong short value\n");566 syslog(LOG_ERR, "Errors in Tests definition : wrong short value"); 547 567 exit(1); 548 568 } … … 562 582 tmp = (ValuesPtr) malloc(sizeof(struct Values)); 563 583 if (tmp==NULL) { 564 fprintf(stderr, "ERROR in malloc in addValue function\n");584 syslog(LOG_ERR, "ERROR in malloc in addValue function"); 565 585 exit(1); 566 586 } else { 567 587 if (sscanf(val, "%s", value) == 0) { 568 fprintf(stderr, "Errors in Tests definition : wrong char value\n");588 syslog(LOG_ERR, "Errors in Tests definition : wrong char value"); 569 589 exit(1); 570 590 }