- Timestamp:
- May 1, 2022, 12:24:37 AM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_cat.c
r525 r577 225 225 226 226 { MSG_TCP_CREG, SH_ERR_ALL, TCP, N_("msg=\"Registered %s, salt %s, verifier %s\"")}, 227 { MSG_TCP_AREG, SH_ERR_ALL, TCP, N_("msg=\"Registered %s, hostname %s\"")}, 227 228 { MSG_TCP_FAUTH, SH_ERR_INFO, TCP, N_("msg=\"Force authentication\" host=\"%s\"")}, 228 229 … … 569 570 570 571 { MSG_TCP_CREG, SH_ERR_ALL, TCP, N_("msg=<Registered %s, salt %s, verifier %s>")}, 572 { MSG_TCP_AREG, SH_ERR_ALL, TCP, N_("msg=<Registered %s, hostname %s>")}, 571 573 { MSG_TCP_FAUTH, SH_ERR_INFO, TCP, N_("msg=<Force authentication>, client=<%s>")}, 572 574 -
trunk/src/sh_readconf.c
r550 r577 1148 1148 { N_("setserverinterface"), SH_SECTION_SRV, SH_SECTION_MISC, 1149 1149 sh_xfer_set_interface }, 1150 { N_("alias"), SH_SECTION_CLIENTS, SH_SECTION_NONE, 1151 sh_xfer_register_alias }, 1150 1152 { N_("client"), SH_SECTION_CLIENTS, SH_SECTION_NONE, 1151 1153 sh_xfer_register_client }, -
trunk/src/sh_xfer_server.c
r575 r577 419 419 */ 420 420 421 typedef struct client_alias { 422 char * alias; 423 char * hostname; 424 } alias_t; 425 421 426 #include "zAVLTree.h" 422 427 … … 435 440 436 441 /* Function to return the key for indexing 437 * the argument 442 * the argument (for the client list) 438 443 */ 439 444 zAVLKey sh_avl_key (void const * arg) … … 444 449 445 450 zAVLTree * all_clients = NULL; 451 452 /* Function to return the key for indexing 453 * the argument (for the aliases list) 454 */ 455 zAVLKey sh_avl_alias (void const * arg) 456 { 457 const alias_t * sa = (const alias_t *) arg; 458 return (zAVLKey) sa->alias; 459 } 460 461 zAVLTree * all_aliases = NULL; 446 462 447 463 void sh_xfer_html_write() … … 470 486 471 487 472 /* the destructor 488 /* the destructor (client list item) 473 489 */ 474 490 void free_client(void * inptr) … … 490 506 SH_FREE(here); 491 507 SL_RET0(_("free_client")); 508 } 509 510 /* the destructor (alias list item) 511 */ 512 void free_alias(void * inptr) 513 { 514 alias_t * here; 515 516 SL_ENTER(_("free_alias")); 517 if (inptr == NULL) 518 SL_RET0(_("free_alias")); 519 else 520 here = (alias_t *) inptr; 521 522 if (here->alias != NULL) 523 SH_FREE(here->alias); 524 if (here->hostname != NULL) 525 SH_FREE(here->hostname); 526 SH_FREE(here); 527 SL_RET0(_("free_alias")); 528 } 529 530 int sh_xfer_register_alias (const char * str) 531 { 532 alias_t * newalias; 533 alias_t * testalias; 534 535 const char * ptr; 536 int sepnum = 0; 537 int sep = 0; 538 register int i = 0; 539 int siz_str = 0; 540 541 SL_ENTER(_("sh_xfer_register_alias")); 542 543 ptr = str; 544 while (*ptr) { 545 if (*ptr == '@' && sepnum < 1) 546 { 547 sep = i; 548 ++sepnum; 549 } 550 ++ptr; ++i; 551 } 552 553 if (all_aliases == NULL) 554 { 555 all_aliases = zAVLAllocTree (sh_avl_alias, zAVL_KEY_STRING); 556 if (all_aliases == NULL) 557 { 558 (void) safe_logger (0, 0, NULL); 559 aud__exit(FIL__, __LINE__, EXIT_FAILURE); 560 } 561 } 562 563 if ((sepnum == 1) && (sep > 0) && (i > (sep + 1))) 564 { 565 newalias = SH_ALLOC (sizeof(alias_t)); 566 newalias->alias = SH_ALLOC (sep+1); 567 newalias->hostname = SH_ALLOC (sl_strlen(str)-sep); 568 569 /* truncate */ 570 sl_strlcpy(newalias->alias, &str[0], sep+1); 571 sh_tolower(newalias->alias); 572 573 /* truncate */ 574 sl_strlcpy(newalias->hostname, &str[sep+1], sl_strlen(str)-sep); 575 sh_tolower(newalias->hostname); 576 577 testalias = (alias_t *) zAVLSearch (all_aliases, newalias->alias); 578 579 if (testalias != NULL) 580 { 581 /* keep the alias but replace the hostname with the new one */ 582 SH_FREE(testalias->hostname); 583 siz_str = strlen (newalias->hostname) + 1; 584 testalias->hostname = SH_ALLOC (siz_str); 585 sl_strlcpy(testalias->hostname, newalias->hostname, siz_str); 586 587 free_alias(newalias); 588 SL_RETURN( 0, _("sh_xfer_register_alias")); 589 } 590 else 591 { 592 if (0 == zAVLInsert (all_aliases, newalias)) 593 { 594 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_AREG, 595 newalias->alias, 596 newalias->hostname); 597 SL_RETURN( 0, _("sh_xfer_register_alias")); 598 } 599 } 600 } 601 SL_RETURN (-1, _("sh_xfer_register_alias")); 492 602 } 493 603 … … 1053 1163 client_t * search_register(sh_conn_t * conn, int pos) 1054 1164 { 1165 alias_t * this_alias; 1055 1166 client_t * this_client; 1056 1167 char peer_ip[SH_IP_BUF]; … … 1086 1197 { 1087 1198 sl_strlcpy(peer_name, peer_ip, MAXHOSTNAMELEN + 1); 1199 } 1200 else 1201 { 1202 this_alias = zAVLSearch(all_aliases, peer_name); 1203 if (this_alias) 1204 { 1205 sl_strlcpy(peer_name, this_alias->hostname, MAXHOSTNAMELEN + 1); 1206 } 1088 1207 } 1089 1208 … … 3375 3494 sh_xfer_mark_dead (); 3376 3495 3496 /* free the aliases list */ 3497 zAVLFreeTree (all_aliases, free_alias); 3498 all_aliases = NULL; 3499 3377 3500 reset_count_dev_console(); 3378 3501 reset_count_dev_time();
Note:
See TracChangeset
for help on using the changeset viewer.