summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/substitute.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index d7ca1841ef..399ef1daa3 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -192,6 +192,33 @@ void sub_set_smb_name(const char *name)
}
}
+static char sub_peeraddr[INET6_ADDRSTRLEN];
+static const char *sub_peername = "";
+static char sub_sockaddr[INET6_ADDRSTRLEN];
+
+void sub_set_socket_ids(const char *peeraddr, const char *peername,
+ const char *sockaddr)
+{
+ const char *addr = peeraddr;
+
+ if (strnequal(addr, "::ffff:", 7)) {
+ addr += 7;
+ }
+ strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr));
+
+ sub_peername = SMB_STRDUP(peername);
+ if (sub_peername == NULL) {
+ sub_peername = sub_peeraddr;
+ }
+
+ /*
+ * Shouldn't we do the ::ffff: cancellation here as well? The
+ * original code in alloc_sub_basic() did not do it, so I'm
+ * leaving it out here as well for compatibility.
+ */
+ strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr));
+}
+
static const char *get_smb_user_name(void)
{
return smb_user_name ? smb_user_name : "";
@@ -538,7 +565,6 @@ static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
{
char *b, *p, *s, *r, *a_string;
fstring pidstr, vnnstr;
- char addr[INET6_ADDRSTRLEN];
const char *local_machine_name = get_local_machine_name();
TALLOC_CTX *tmp_ctx = NULL;
@@ -593,20 +619,15 @@ static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
a_string = realloc_string_sub(a_string, "%D", r);
break;
case 'I' : {
- int offset = 0;
- client_addr(smbd_server_fd(), addr, sizeof(addr));
- if (strnequal(addr,"::ffff:",7)) {
- offset = 7;
- }
- a_string = realloc_string_sub(a_string, "%I",
- addr + offset);
+ a_string = realloc_string_sub(
+ a_string, "%I",
+ sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0");
break;
}
case 'i':
a_string = realloc_string_sub(
a_string, "%i",
- client_socket_addr(smbd_server_fd(),
- addr, sizeof(addr)));
+ sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0");
break;
case 'L' :
if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
@@ -622,8 +643,8 @@ static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
a_string = realloc_string_sub(a_string, "%N", automount_server(smb_name));
break;
case 'M' :
- a_string = realloc_string_sub(
- a_string, "%M", client_name(smbd_server_fd()));
+ a_string = realloc_string_sub(a_string, "%M",
+ sub_peername);
break;
case 'R' :
a_string = realloc_string_sub(a_string, "%R", remote_proto);