MCPcopy Create free account
hub / github.com/MariaDB/server / thd_set_peer_addr

Function thd_set_peer_addr

sql/sql_connect.cc:942–1029  ·  view source on GitHub ↗

Set client address during authentication. Initializes THD::main_security_ctx and THD::peer_port. Optionally does ip to hostname translation. @param thd current THD handle @param addr peer address (can be NULL, if 'ip' is set) @param ip peer address as string (can be NULL if 'addr' is set) @param port peer port @param check_proxy_networks if true, and host is in

Source from the content-addressed store, hash-verified

940 @retval 0 ok, 1 error
941*/
942int thd_set_peer_addr(THD *thd,
943 sockaddr_storage *addr,
944 const char *ip,
945 uint port,
946 bool check_proxy_networks,
947 uint *host_errors)
948{
949 *host_errors= 0;
950
951 thd->peer_port= port;
952
953 char ip_string[128];
954 if (!ip)
955 {
956 void *addr_data;
957 if (addr->ss_family == AF_UNIX)
958 {
959 /* local connection */
960 my_free((void *)thd->main_security_ctx.ip);
961 thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host = my_localhost;
962 thd->main_security_ctx.ip= 0;
963 return 0;
964 }
965 else if (addr->ss_family == AF_INET)
966 addr_data= &((struct sockaddr_in *)addr)->sin_addr;
967 else
968 addr_data= &((struct sockaddr_in6 *)addr)->sin6_addr;
969 if (!inet_ntop(addr->ss_family,addr_data, ip_string, sizeof(ip_string)))
970 {
971 DBUG_ASSERT(0);
972 return 1;
973 }
974 ip= ip_string;
975 }
976
977 my_free((void *)thd->main_security_ctx.ip);
978 if (!(thd->main_security_ctx.ip = my_strdup(PSI_INSTRUMENT_ME, ip, MYF(MY_WME))))
979 {
980 /*
981 No error accounting per IP in host_cache,
982 this is treated as a global server OOM error.
983 TODO: remove the need for my_strdup.
984 */
985 statistic_increment(aborted_connects, &LOCK_status);
986 statistic_increment(connection_errors_internal, &LOCK_status);
987 return 1; /* The error is set by my_strdup(). */
988 }
989 thd->main_security_ctx.host_or_ip = thd->main_security_ctx.ip;
990 if (!opt_skip_name_resolve)
991 {
992 int rc;
993
994 rc = ip_to_hostname(addr,
995 thd->main_security_ctx.ip,
996 &thd->main_security_ctx.host,
997 host_errors);
998
999 /* Cut very long hostnames to avoid possible overflows */

Callers 2

handle_proxy_headerFunction · 0.85
check_connectionFunction · 0.85

Calls 6

my_freeFunction · 0.85
my_strdupFunction · 0.85
ip_to_hostnameFunction · 0.85
my_errorFunction · 0.85
acl_check_hostFunction · 0.85

Tested by

no test coverage detected