diff options
Diffstat (limited to 'src/sh_xfer_server.c')
-rw-r--r-- | src/sh_xfer_server.c | 190 |
1 files changed, 150 insertions, 40 deletions
diff --git a/src/sh_xfer_server.c b/src/sh_xfer_server.c index 0f7f1ab..fcc80fc 100644 --- a/src/sh_xfer_server.c +++ b/src/sh_xfer_server.c @@ -104,7 +104,7 @@ #define FD_SETSIZE 32 #endif #ifndef FD_ZERO -#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) +#define FD_ZERO(p) memset((char *)(p), 0, sizeof(*(p))) #endif #if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK) @@ -418,6 +418,11 @@ char * clt_stat[] = { * } client_t; */ +typedef struct client_alias { + char * alias; + char * hostname; +} alias_t; + #include "zAVLTree.h" static char * sh_tolower (char * s) @@ -434,7 +439,7 @@ static char * sh_tolower (char * s) } /* Function to return the key for indexing - * the argument + * the argument (for the client list) */ zAVLKey sh_avl_key (void const * arg) { @@ -444,6 +449,17 @@ zAVLKey sh_avl_key (void const * arg) zAVLTree * all_clients = NULL; +/* Function to return the key for indexing + * the argument (for the aliases list) + */ +zAVLKey sh_avl_alias (void const * arg) +{ + const alias_t * sa = (const alias_t *) arg; + return (zAVLKey) sa->alias; +} + +zAVLTree * all_aliases = NULL; + void sh_xfer_html_write() { SL_ENTER(_("sh_xfer_html_write")); @@ -469,7 +485,7 @@ int sh_xfer_use_clt_sev (const char * c) } -/* the destructor +/* the destructor (client list item) */ void free_client(void * inptr) { @@ -491,6 +507,100 @@ void free_client(void * inptr) SL_RET0(_("free_client")); } +/* the destructor (alias list item) + */ +void free_alias(void * inptr) +{ + alias_t * here; + + SL_ENTER(_("free_alias")); + if (inptr == NULL) + SL_RET0(_("free_alias")); + else + here = (alias_t *) inptr; + + if (here->alias != NULL) + SH_FREE(here->alias); + if (here->hostname != NULL) + SH_FREE(here->hostname); + SH_FREE(here); + SL_RET0(_("free_alias")); +} + +int sh_xfer_register_alias (const char * str) +{ + alias_t * newalias; + alias_t * testalias; + + const char * ptr; + int sepnum = 0; + int sep = 0; + register int i = 0; + int siz_str = 0; + + SL_ENTER(_("sh_xfer_register_alias")); + + ptr = str; + while (*ptr) { + if (*ptr == '@' && sepnum < 1) + { + sep = i; + ++sepnum; + } + ++ptr; ++i; + } + + if (all_aliases == NULL) + { + all_aliases = zAVLAllocTree (sh_avl_alias, zAVL_KEY_STRING); + if (all_aliases == NULL) + { + (void) safe_logger (0, 0, NULL); + aud__exit(FIL__, __LINE__, EXIT_FAILURE); + } + } + + if ((sepnum == 1) && (sep > 0) && (i > (sep + 1))) + { + newalias = SH_ALLOC (sizeof(alias_t)); + newalias->alias = SH_ALLOC (sep+1); + newalias->hostname = SH_ALLOC (sl_strlen(str)-sep); + + /* truncate */ + sl_strlcpy(newalias->alias, &str[0], sep+1); + sh_tolower(newalias->alias); + + /* truncate */ + sl_strlcpy(newalias->hostname, &str[sep+1], sl_strlen(str)-sep); + sh_tolower(newalias->hostname); + + testalias = (alias_t *) zAVLSearch (all_aliases, newalias->alias); + + if (testalias != NULL) + { + /* keep the alias but replace the hostname with the new one */ + SH_FREE(testalias->hostname); + siz_str = strlen (newalias->hostname) + 1; + testalias->hostname = SH_ALLOC (siz_str); + sl_strlcpy(testalias->hostname, newalias->hostname, siz_str); + + free_alias(newalias); + SL_RETURN( 0, _("sh_xfer_register_alias")); + } + else + { + if (0 == zAVLInsert (all_aliases, newalias)) + { + sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_AREG, + newalias->alias, + newalias->hostname); + SL_RETURN( 0, _("sh_xfer_register_alias")); + } + } + } + SL_RETURN (-1, _("sh_xfer_register_alias")); +} + int sh_xfer_register_client (const char * str) { @@ -1052,6 +1162,7 @@ int set_socket_peer (const char * c) */ client_t * search_register(sh_conn_t * conn, int pos) { + alias_t * this_alias; client_t * this_client; char peer_ip[SH_IP_BUF]; char numerical[SH_IP_BUF]; @@ -1067,6 +1178,7 @@ client_t * search_register(sh_conn_t * conn, int pos) { memcpy(&peer_addr, &(conn->addr_peer), sizeof(struct sh_sockaddr)); sh_ipvx_ntoa (peer_ip, sizeof(peer_ip), &peer_addr); + peer_name[0] = '\0'; /* get canonical name of socket peer */ @@ -1085,6 +1197,14 @@ client_t * search_register(sh_conn_t * conn, int pos) { sl_strlcpy(peer_name, peer_ip, MAXHOSTNAMELEN + 1); } + else + { + this_alias = zAVLSearch(all_aliases, peer_name); + if (this_alias) + { + sl_strlcpy(peer_name, this_alias->hostname, MAXHOSTNAMELEN + 1); + } + } search_string = peer_name; } @@ -1196,7 +1316,7 @@ client_t * do_check_client(sh_conn_t * conn, int * retval) sigbuf, sizeof(sigbuf)), KEY_LEN+1); - if (0 != sl_strncmp(conn->K, conn->buf, KEY_LEN)) + if (0 != sl_ts_strncmp(conn->K, conn->buf, KEY_LEN)) { TPT((0, FIL__, __LINE__, _("msg=<clt %s>\n"), conn->buf)); TPT((0, FIL__, __LINE__, _("msg=<srv %s>\n"), conn->K)); @@ -1228,11 +1348,6 @@ static void do_file_send_data(sh_conn_t * conn) char * send_buf; int bytes; SL_TICKET sfd = -1; -#ifdef SH_ENCRYPT - int blkfac; - int rem; - int send_bytes; -#endif if (conn == NULL || conn->FileName == NULL) { @@ -1279,26 +1394,11 @@ static void do_file_send_data(sh_conn_t * conn) if (bytes >= 0) { + send_buf = hash_me(conn->K, read_buf, bytes); #ifdef SH_ENCRYPT - /* need to send N * B_SIZ bytes - */ - blkfac = bytes / B_SIZ; - rem = bytes - (blkfac * B_SIZ); - if (rem != 0) - { - memset(&read_buf[bytes], '\n', (B_SIZ-rem)); - ++blkfac; - send_bytes = blkfac * B_SIZ; - } - else - send_bytes = bytes; - - send_buf = hash_me(conn->K, read_buf, send_bytes); - - sh_xfer_send_crypt (conn, send_buf, send_bytes+KEY_LEN, _("FILE"), + sh_xfer_send_crypt (conn, send_buf, bytes+KEY_LEN, _("FILE"), SH_PROTO_BIG|conn->client_entry->encf_flag); #else - send_buf = hash_me(conn->K, read_buf, bytes); sh_xfer_send_crypt (conn, send_buf, bytes+KEY_LEN, _("FILE"), SH_PROTO_BIG); #endif @@ -1662,12 +1762,12 @@ static int do_message_transfer(sh_conn_t * conn, int state) /* verify hash */ buffer = sh_util_strconcat(conn->buf, conn->challenge, NULL); - i = sl_strncmp(hash, - sh_util_siggen(conn->client_entry->session_key, - buffer, - sl_strlen(buffer), - sigbuf, sizeof(sigbuf)), - KEY_LEN); + i = sl_ts_strncmp(hash, + sh_util_siggen(conn->client_entry->session_key, + buffer, + sl_strlen(buffer), + sigbuf, sizeof(sigbuf)), + KEY_LEN); TPT((0, FIL__, __LINE__, _("msg=<sign %s.>\n"), sh_util_siggen(conn->client_entry->session_key, buffer, @@ -1787,7 +1887,7 @@ static int do_message_transfer(sh_conn_t * conn, int state) SH_FREE(ptok); clt_class = (-1); } - memset(buffer, '\0', sl_strlen(buffer)); + memset(buffer, 0, sl_strlen(buffer)); SH_FREE(buffer); /* SERVER CONF SEND @@ -1845,7 +1945,7 @@ static int do_message_transfer(sh_conn_t * conn, int state) SH_PROTO_MSG|SH_PROTO_END); #endif - memset(buffer, '\0', sl_strlen(buffer)); + memset(buffer, 0, sl_strlen(buffer)); SH_FREE(buffer); /* sh_xfer_do_free (conn); */ @@ -2086,7 +2186,7 @@ int do_auth(sh_conn_t * conn) TPT((0, FIL__, __LINE__, _("msg=<c/r: H = %s>\n"), hash)); TPT((0, FIL__, __LINE__, _("msg=<c/r: P = %s>\n"), conn->M1)); - if ( 0 != sl_strncmp(conn->M1, conn->buf, KEY_LEN)) + if ( 0 != sl_ts_strncmp(conn->M1, conn->buf, KEY_LEN)) { sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_BADCONN, _("Session key mismatch"), conn->peer); @@ -2412,7 +2512,7 @@ int do_auth(sh_conn_t * conn) * ----- send M2 = H(A, M1, K) ------- */ if (conn->buf != NULL && - sl_strncmp(conn->buf, conn->M1, KEY_LEN) == 0) + sl_ts_strncmp(conn->buf, conn->M1, KEY_LEN) == 0) { /* * send M2 @@ -2425,8 +2525,12 @@ int do_auth(sh_conn_t * conn) _("PARP"), (conn->head[0]|SH_PROTO_SRP)); - if (conn->A != NULL) SH_FREE(conn->A); conn->A = NULL; - if (conn->M1 != NULL) SH_FREE(conn->M1); conn->M1 = NULL; + if (conn->A != NULL) + SH_FREE(conn->A); + conn->A = NULL; + if (conn->M1 != NULL) + SH_FREE(conn->M1); + conn->M1 = NULL; sl_strlcpy(conn->client_entry->session_key, conn->K, KEY_LEN+1); TPT((0, FIL__, __LINE__, _("msg=<key %s>\n"), @@ -2449,7 +2553,9 @@ int do_auth(sh_conn_t * conn) _("sh_xfer_prep_send_int: makeKey")); #endif - if (conn->K != NULL) SH_FREE(conn->K); conn->K = NULL; + if (conn->K != NULL) + SH_FREE(conn->K); + conn->K = NULL; conn->client_entry->last_connect = time (NULL); @@ -3102,7 +3208,7 @@ int sh_create_tcp_socket (void) #if defined(USE_IPVX) if (use_server_interface == 0) /* INADDR_ANY, listen on all interfaces */ { - memset (&hints, '\0', sizeof (hints)); + memset (&hints, 0, sizeof (hints)); hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_UNSPEC; @@ -3387,6 +3493,10 @@ void sh_xfer_start_server() */ sh_xfer_mark_dead (); + /* free the aliases list */ + zAVLFreeTree (all_aliases, free_alias); + all_aliases = NULL; + reset_count_dev_console(); reset_count_dev_time(); sl_trust_purge_user(); |