mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
s3-util: Add a get_remote_hostname() function.
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
6b86590342
commit
c663dfff88
@ -436,7 +436,7 @@ CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
|
|||||||
../lib/crypto/sha256.o ../lib/crypto/hmacsha256.o \
|
../lib/crypto/sha256.o ../lib/crypto/hmacsha256.o \
|
||||||
../lib/crypto/aes.o ../lib/crypto/rijndael-alg-fst.o
|
../lib/crypto/aes.o ../lib/crypto/rijndael-alg-fst.o
|
||||||
|
|
||||||
LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
|
LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
|
||||||
lib/messages.o librpc/gen_ndr/ndr_messaging.o lib/messages_local.o \
|
lib/messages.o librpc/gen_ndr/ndr_messaging.o lib/messages_local.o \
|
||||||
lib/messages_ctdbd.o lib/ctdb_packet.o lib/ctdbd_conn.o \
|
lib/messages_ctdbd.o lib/ctdb_packet.o lib/ctdbd_conn.o \
|
||||||
../lib/socket/interfaces.o lib/memcache.o \
|
../lib/socket/interfaces.o lib/memcache.o \
|
||||||
@ -576,7 +576,7 @@ LIBTSOCKET_OBJ = ../lib/tsocket/tsocket.o \
|
|||||||
CLDAP_OBJ = libads/cldap.o \
|
CLDAP_OBJ = libads/cldap.o \
|
||||||
../libcli/cldap/cldap.o \
|
../libcli/cldap/cldap.o \
|
||||||
../lib/util/idtree.o \
|
../lib/util/idtree.o \
|
||||||
$(LIBCLI_LDAP_MESSAGE_OBJ) $(LIBCLI_LDAP_NDR_OBJ) $(LIBTSOCKET_OBJ)
|
$(LIBCLI_LDAP_MESSAGE_OBJ) $(LIBCLI_LDAP_NDR_OBJ)
|
||||||
|
|
||||||
TLDAP_OBJ = lib/tldap.o lib/tldap_util.o lib/util_tsock.o
|
TLDAP_OBJ = lib/tldap.o lib/tldap_util.o lib/util_tsock.o
|
||||||
|
|
||||||
@ -1038,7 +1038,7 @@ SMBPASSWD_OBJ = utils/smbpasswd.o $(PASSWD_UTIL_OBJ) $(PASSCHANGE_OBJ) \
|
|||||||
rpc_client/init_lsa.o
|
rpc_client/init_lsa.o
|
||||||
|
|
||||||
PDBEDIT_OBJ = utils/pdbedit.o $(PASSWD_UTIL_OBJ) $(PARAM_OBJ) $(PASSDB_OBJ) \
|
PDBEDIT_OBJ = utils/pdbedit.o $(PASSWD_UTIL_OBJ) $(PARAM_OBJ) $(PASSDB_OBJ) \
|
||||||
$(LIBSAMBA_OBJ) $(LIBTSOCKET_OBJ) \
|
$(LIBSAMBA_OBJ) \
|
||||||
$(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) \
|
$(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) \
|
||||||
$(LIBCLI_LDAP_NDR_OBJ) \
|
$(LIBCLI_LDAP_NDR_OBJ) \
|
||||||
$(DRSUAPI_OBJ) $(LIBNDR_GEN_OBJ0) \
|
$(DRSUAPI_OBJ) $(LIBNDR_GEN_OBJ0) \
|
||||||
@ -1327,7 +1327,7 @@ PAM_SMBPASS_OBJ_0 = pam_smbpass/pam_smb_auth.o pam_smbpass/pam_smb_passwd.o \
|
|||||||
PAM_SMBPASS_OBJ = $(PAM_SMBPASS_OBJ_0) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \
|
PAM_SMBPASS_OBJ = $(PAM_SMBPASS_OBJ_0) $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \
|
||||||
$(SMBLDAP_OBJ) $(LIBSAMBA_OBJ) \
|
$(SMBLDAP_OBJ) $(LIBSAMBA_OBJ) \
|
||||||
$(DRSUAPI_OBJ) $(LIBNDR_GEN_OBJ0) \
|
$(DRSUAPI_OBJ) $(LIBNDR_GEN_OBJ0) \
|
||||||
$(LIBTSOCKET_OBJ) $(PAM_ERRORS_OBJ)
|
$(PAM_ERRORS_OBJ)
|
||||||
|
|
||||||
IDMAP_RW_OBJ = winbindd/idmap_rw.o
|
IDMAP_RW_OBJ = winbindd/idmap_rw.o
|
||||||
|
|
||||||
@ -1505,7 +1505,7 @@ NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
|
|||||||
../lib/util/asn1.o ../libcli/auth/spnego_parse.o libsmb/clikrb5.o ../libcli/auth/krb5_wrap.o libads/kerberos.o \
|
../lib/util/asn1.o ../libcli/auth/spnego_parse.o libsmb/clikrb5.o ../libcli/auth/krb5_wrap.o libads/kerberos.o \
|
||||||
libsmb/samlogon_cache.o \
|
libsmb/samlogon_cache.o \
|
||||||
$(LIBADS_SERVER_OBJ) \
|
$(LIBADS_SERVER_OBJ) \
|
||||||
$(PASSDB_OBJ) $(LIBTSOCKET_OBJ) $(GROUPDB_OBJ) \
|
$(PASSDB_OBJ) $(GROUPDB_OBJ) \
|
||||||
$(SMBLDAP_OBJ) $(LIBNMB_OBJ) \
|
$(SMBLDAP_OBJ) $(LIBNMB_OBJ) \
|
||||||
$(WBCOMMON_OBJ) \
|
$(WBCOMMON_OBJ) \
|
||||||
$(LIBCLI_LDAP_NDR_OBJ) \
|
$(LIBCLI_LDAP_NDR_OBJ) \
|
||||||
|
@ -788,6 +788,13 @@ NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd);
|
|||||||
int open_udp_socket(const char *host, int port);
|
int open_udp_socket(const char *host, int port);
|
||||||
const char *get_peer_name(int fd, bool force_lookup);
|
const char *get_peer_name(int fd, bool force_lookup);
|
||||||
const char *get_peer_addr(int fd, char *addr, size_t addr_len);
|
const char *get_peer_addr(int fd, char *addr, size_t addr_len);
|
||||||
|
|
||||||
|
struct tsocket_address;
|
||||||
|
|
||||||
|
int get_remote_hostname(const struct tsocket_address *remote_address,
|
||||||
|
char **name,
|
||||||
|
TALLOC_CTX *mem_ctx);
|
||||||
|
|
||||||
int create_pipe_sock(const char *socket_dir,
|
int create_pipe_sock(const char *socket_dir,
|
||||||
const char *socket_name,
|
const char *socket_name,
|
||||||
mode_t dir_perms);
|
mode_t dir_perms);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "lib/socket/interfaces.h"
|
#include "lib/socket/interfaces.h"
|
||||||
#include "../lib/util/tevent_unix.h"
|
#include "../lib/util/tevent_unix.h"
|
||||||
#include "../lib/util/tevent_ntstatus.h"
|
#include "../lib/util/tevent_ntstatus.h"
|
||||||
|
#include "../lib/tsocket/tsocket.h"
|
||||||
|
|
||||||
const char *client_name(int fd)
|
const char *client_name(int fd)
|
||||||
{
|
{
|
||||||
@ -1126,6 +1127,113 @@ const char *get_peer_addr(int fd, char *addr, size_t addr_len)
|
|||||||
return get_peer_addr_internal(fd, addr, addr_len, NULL, NULL);
|
return get_peer_addr_internal(fd, addr, addr_len, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_remote_hostname(const struct tsocket_address *remote_address,
|
||||||
|
char **name,
|
||||||
|
TALLOC_CTX *mem_ctx)
|
||||||
|
{
|
||||||
|
char name_buf[MAX_DNS_NAME_LENGTH];
|
||||||
|
char tmp_name[MAX_DNS_NAME_LENGTH];
|
||||||
|
struct name_addr_pair nc;
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
socklen_t len;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!lp_hostname_lookups()) {
|
||||||
|
nc.name = tsocket_address_inet_addr_string(remote_address,
|
||||||
|
mem_ctx);
|
||||||
|
if (nc.name == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = tsocket_address_bsd_sockaddr(remote_address,
|
||||||
|
(struct sockaddr *) &nc.ss,
|
||||||
|
sizeof(struct sockaddr_storage));
|
||||||
|
if (len < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
store_nc(&nc);
|
||||||
|
lookup_nc(&nc);
|
||||||
|
|
||||||
|
if (nc.name == NULL) {
|
||||||
|
*name = talloc_strdup(mem_ctx, "UNKNOWN");
|
||||||
|
} else {
|
||||||
|
*name = talloc_strdup(mem_ctx, nc.name);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lookup_nc(&nc);
|
||||||
|
|
||||||
|
ZERO_STRUCT(ss);
|
||||||
|
|
||||||
|
len = tsocket_address_bsd_sockaddr(remote_address,
|
||||||
|
(struct sockaddr *) &ss,
|
||||||
|
sizeof(struct sockaddr_storage));
|
||||||
|
if (len < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* it might be the same as the last one - save some DNS work */
|
||||||
|
if (sockaddr_equal((struct sockaddr *)&ss, (struct sockaddr *)&nc.ss)) {
|
||||||
|
if (nc.name == NULL) {
|
||||||
|
*name = talloc_strdup(mem_ctx, "UNKNOWN");
|
||||||
|
} else {
|
||||||
|
*name = talloc_strdup(mem_ctx, nc.name);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Look up the remote host name. */
|
||||||
|
rc = sys_getnameinfo((struct sockaddr *) &ss,
|
||||||
|
len,
|
||||||
|
name_buf,
|
||||||
|
sizeof(name_buf),
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if (rc < 0) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
p = tsocket_address_inet_addr_string(remote_address, mem_ctx);
|
||||||
|
if (p == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG(1,("getnameinfo failed for %s with error %s\n",
|
||||||
|
p,
|
||||||
|
gai_strerror(rc)));
|
||||||
|
strlcpy(name_buf, p, sizeof(name_buf));
|
||||||
|
|
||||||
|
talloc_free(p);
|
||||||
|
} else {
|
||||||
|
if (!matchname(name_buf, (struct sockaddr *)&ss, len)) {
|
||||||
|
DEBUG(0,("matchname failed on %s\n", name_buf));
|
||||||
|
strlcpy(name_buf, "UNKNOWN", sizeof(name_buf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(tmp_name, name_buf, sizeof(tmp_name));
|
||||||
|
alpha_strcpy(name_buf, tmp_name, "_-.", sizeof(name_buf));
|
||||||
|
if (strstr(name_buf,"..")) {
|
||||||
|
strlcpy(name_buf, "UNKNOWN", sizeof(name_buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
nc.name = name_buf;
|
||||||
|
nc.ss = ss;
|
||||||
|
|
||||||
|
store_nc(&nc);
|
||||||
|
lookup_nc(&nc);
|
||||||
|
|
||||||
|
if (nc.name == NULL) {
|
||||||
|
*name = talloc_strdup(mem_ctx, "UNKOWN");
|
||||||
|
} else {
|
||||||
|
*name = talloc_strdup(mem_ctx, nc.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
Create protected unix domain socket.
|
Create protected unix domain socket.
|
||||||
|
|
||||||
|
@ -800,7 +800,7 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
|
|||||||
|
|
||||||
bld.SAMBA3_SUBSYSTEM('samba3core',
|
bld.SAMBA3_SUBSYSTEM('samba3core',
|
||||||
source=LIB_SRC,
|
source=LIB_SRC,
|
||||||
deps='LIBCRYPTO ndr security NDR_SECURITY samba-util NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 UTIL_TDB UTIL_PW SAMBA_VERSION KRB5_WRAP flag_mapping util_reg PTHREADPOOL interfaces cap string_init param util_str CHARSET3 namearray dbwrap_util util_sec util_malloc memcache ccan errors3',
|
deps='LIBTSOCKET LIBCRYPTO ndr security NDR_SECURITY samba-util NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 UTIL_TDB UTIL_PW SAMBA_VERSION KRB5_WRAP flag_mapping util_reg PTHREADPOOL interfaces cap string_init param util_str CHARSET3 namearray dbwrap_util util_sec util_malloc memcache ccan errors3',
|
||||||
vars=locals())
|
vars=locals())
|
||||||
|
|
||||||
bld.SAMBA3_LIBRARY('smbd_shim',
|
bld.SAMBA3_LIBRARY('smbd_shim',
|
||||||
|
Loading…
Reference in New Issue
Block a user