Changeset 577 for trunk/src


Ignore:
Timestamp:
May 1, 2022, 12:24:37 AM (2 years ago)
Author:
katerina
Message:

Implement ticket #465 (server option to register alias for hostname).

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_cat.c

    r525 r577  
    225225
    226226  { 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\"")},
    227228  { MSG_TCP_FAUTH,   SH_ERR_INFO,    TCP,   N_("msg=\"Force authentication\" host=\"%s\"")},
    228229
     
    569570
    570571  { 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>")},
    571573  { MSG_TCP_FAUTH,   SH_ERR_INFO,    TCP,   N_("msg=<Force authentication>, client=<%s>")},
    572574
  • trunk/src/sh_readconf.c

    r550 r577  
    11481148  { N_("setserverinterface"),  SH_SECTION_SRV,  SH_SECTION_MISC,
    11491149    sh_xfer_set_interface },
     1150  { N_("alias"),               SH_SECTION_CLIENTS,           SH_SECTION_NONE,
     1151    sh_xfer_register_alias },
    11501152  { N_("client"),              SH_SECTION_CLIENTS,           SH_SECTION_NONE,
    11511153    sh_xfer_register_client },
  • trunk/src/sh_xfer_server.c

    r575 r577  
    419419 */
    420420
     421typedef struct client_alias {
     422  char                  * alias;
     423  char                  * hostname;
     424} alias_t;
     425
    421426#include "zAVLTree.h"
    422427
     
    435440
    436441/* Function to return the key for indexing
    437  * the argument
     442 * the argument (for the client list)
    438443 */
    439444zAVLKey sh_avl_key (void const * arg)
     
    444449
    445450zAVLTree * all_clients = NULL;
     451
     452/* Function to return the key for indexing
     453 * the argument (for the aliases list)
     454 */
     455zAVLKey sh_avl_alias (void const * arg)
     456{
     457  const alias_t * sa = (const alias_t *) arg;
     458  return (zAVLKey) sa->alias;
     459}
     460
     461zAVLTree * all_aliases = NULL;
    446462
    447463void sh_xfer_html_write()
     
    470486
    471487
    472 /* the destructor
     488/* the destructor (client list item)
    473489 */
    474490void free_client(void * inptr)
     
    490506  SH_FREE(here);
    491507  SL_RET0(_("free_client"));
     508}
     509
     510/* the destructor (alias list item)
     511 */
     512void 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
     530int 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"));
    492602}
    493603
     
    10531163client_t * search_register(sh_conn_t * conn, int pos)
    10541164{
     1165  alias_t  * this_alias;
    10551166  client_t * this_client;
    10561167  char       peer_ip[SH_IP_BUF];
     
    10861197        {
    10871198          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            }
    10881207        }
    10891208
     
    33753494            sh_xfer_mark_dead ();
    33763495
     3496            /* free the aliases list */
     3497            zAVLFreeTree (all_aliases, free_alias);
     3498            all_aliases = NULL;
     3499
    33773500            reset_count_dev_console();
    33783501            reset_count_dev_time();
Note: See TracChangeset for help on using the changeset viewer.