diff options
author | Volker Lendecke <vl@samba.org> | 2010-08-28 16:33:00 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-08-29 21:55:23 +0200 |
commit | 4a58c640cce3b37d5eef62caddd15f64ef8befbe (patch) | |
tree | f39760fd4203157f2151d5d27364334752d5cd38 | |
parent | 8d256b8f30e726bec6755712121840d3a4c9b620 (diff) | |
download | samba-4a58c640cce3b37d5eef62caddd15f64ef8befbe.tar.gz samba-4a58c640cce3b37d5eef62caddd15f64ef8befbe.tar.bz2 samba-4a58c640cce3b37d5eef62caddd15f64ef8befbe.zip |
s3: Set the client_id in substitute.c once
This never changes during a client connection's life, so we can set it
once.
-rw-r--r-- | source3/include/proto.h | 2 | ||||
-rw-r--r-- | source3/lib/substitute.c | 45 | ||||
-rw-r--r-- | source3/smbd/server.c | 5 |
3 files changed, 40 insertions, 12 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index e2d1c94e7b..37f4d19232 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -816,6 +816,8 @@ const char *get_remote_machine_name(void); void sub_set_smb_name(const char *name); void set_current_user_info(const char *smb_name, const char *unix_name, const char *domain); +void sub_set_socket_ids(const char *peeraddr, const char *peername, + const char *sockaddr); const char *get_current_username(void); void standard_sub_basic(const char *smb_name, const char *domain_name, char *str, size_t len); 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); diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 7d257692e9..cbd6a9c405 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -61,6 +61,7 @@ int smbd_server_fd(void) static void smbd_set_server_fd(int fd) { struct smbd_server_connection *sconn = smbd_server_conn; + char addr[INET6_ADDRSTRLEN]; const char *name; server_fd = fd; @@ -82,6 +83,10 @@ static void smbd_set_server_fd(int fd) } sconn->client_id.name = (name != NULL) ? name : sconn->client_id.addr; + + sub_set_socket_ids(sconn->client_id.addr, sconn->client_id.name, + client_socket_addr(sconn->sock, addr, + sizeof(addr))); } struct event_context *smbd_event_context(void) |