}
if (rhost == NULL) {
- our_rhost = client_name();
+ our_rhost = client_name(get_client_fd());
if (strequal(our_rhost,"UNKNOWN"))
- our_rhost = client_addr(addr,sizeof(addr));
+ our_rhost = client_addr(get_client_fd(),addr,sizeof(addr));
} else {
our_rhost = rhost;
}
#include "includes.h"
+int get_client_fd(void)
+{
+ return -1;
+}
+
int find_service(fstring service)
{
return -1;
*/
if ( strequal(tmp_local_machine, "*SMBSERVER") || strequal(tmp_local_machine, "*SMBSERV") ) {
- fstrcpy( local_machine, client_socket_addr(addr, sizeof(addr)) );
+ fstrcpy( local_machine,
+ client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
return;
}
break;
case 'I' :
a_string = realloc_string_sub(a_string, "%I",
- client_addr(addr, sizeof(addr)));
+ client_addr(get_client_fd(),addr, sizeof(addr)));
break;
case 'i':
a_string = realloc_string_sub( a_string, "%i",
- client_socket_addr(addr, sizeof(addr)) );
+ client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
break;
case 'L' :
if ( StrnCaseCmp(p, "%LOGONSERVER%", strlen("%LOGONSERVER%")) == 0 ) {
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());
+ a_string = realloc_string_sub(a_string, "%M", client_name(get_client_fd()));
break;
case 'R' :
a_string = realloc_string_sub(a_string, "%R", remote_proto);
#include "includes.h"
-/* the following 3 client_*() functions are nasty ways of allowing
- some generic functions to get info that really should be hidden in
- particular modules */
-static int client_fd = -1;
-/* What to print out on a client disconnect error. */
-static char client_ip_string[INET6_ADDRSTRLEN];
-
/****************************************************************************
Return true if a string could be an IPv4 address.
****************************************************************************/
return dest;
}
-/****************************************************************************
- Set the global client_fd variable.
-****************************************************************************/
-
-void client_setfd(int fd)
-{
- char addr[INET6_ADDRSTRLEN];
- client_fd = fd;
- safe_strcpy(client_ip_string,
- get_peer_addr(client_fd,addr,sizeof(addr)),
- sizeof(client_ip_string)-1);
-}
-
/****************************************************************************
Return the string of an IP address (IPv4 or IPv6).
****************************************************************************/
return print_sockaddr_len(addr_buf, addr_len, &sa, length);
}
+#if 0
+/* Not currently used. JRA. */
/****************************************************************************
Return the port number we've bound to on a socket.
****************************************************************************/
}
return -1;
}
+#endif
-const char *client_name(void)
+const char *client_name(int fd)
{
- return get_peer_name(client_fd,false);
+ return get_peer_name(fd,false);
}
-const char *client_addr(char *addr, size_t addrlen)
+const char *client_addr(int fd, char *addr, size_t addrlen)
{
- return get_peer_addr(client_fd,addr,addrlen);
+ return get_peer_addr(fd,addr,addrlen);
}
-const char *client_socket_addr(char *addr, size_t addr_len)
+const char *client_socket_addr(int fd, char *addr, size_t addr_len)
{
- return get_socket_addr(client_fd, addr, addr_len);
+ return get_socket_addr(fd, addr, addr_len);
}
-int client_socket_port(void)
+#if 0
+/* Not currently used. JRA. */
+int client_socket_port(int fd)
{
- return get_socket_port(client_fd);
+ return get_socket_port(fd);
}
+#endif
/****************************************************************************
Accessor functions to make thread-safe code easier later...
ssize_t readret;
size_t nread = 0;
struct timeval timeout;
+ char addr[INET6_ADDRSTRLEN];
/* just checking .... */
if (maxcnt <= 0)
}
if (readret == -1) {
- if (fd == client_fd) {
+ if (fd == get_client_fd()) {
/* Try and give an error message
* saying what client failed. */
DEBUG(0,("read_socket_with_timeout: "
"client %s read error = %s.\n",
- client_ip_string,
+ get_peer_addr(fd,addr,sizeof(addr)),
strerror(errno) ));
} else {
DEBUG(0,("read_socket_with_timeout: "
/* Check if error */
if (selrtn == -1) {
/* something is wrong. Maybe the socket is dead? */
- if (fd == client_fd) {
+ if (fd == get_client_fd()) {
/* Try and give an error message saying
* what client failed. */
DEBUG(0,("read_socket_with_timeout: timeout "
"read for client %s. select error = %s.\n",
- client_ip_string, strerror(errno) ));
+ get_peer_addr(fd,addr,sizeof(addr)),
+ strerror(errno) ));
} else {
DEBUG(0,("read_socket_with_timeout: timeout "
"read. select error = %s.\n",
if (readret == -1) {
/* the descriptor is probably dead */
- if (fd == client_fd) {
+ if (fd == get_client_fd()) {
/* Try and give an error message
* saying what client failed. */
DEBUG(0,("read_socket_with_timeout: timeout "
"read to client %s. read error = %s.\n",
- client_ip_string, strerror(errno) ));
+ get_peer_addr(fd,addr,sizeof(addr)),
+ strerror(errno) ));
} else {
DEBUG(0,("read_socket_with_timeout: timeout "
"read. read error = %s.\n",
{
ssize_t ret;
size_t total=0;
+ char addr[INET6_ADDRSTRLEN];
set_smb_read_error(SMB_READ_OK);
}
if (ret == -1) {
- if (fd == client_fd) {
+ if (fd == get_client_fd()) {
/* Try and give an error message saying
* what client failed. */
DEBUG(0,("read_data: read failure for %d "
"bytes to client %s. Error = %s\n",
(int)(N - total),
- client_ip_string,
+ get_peer_addr(fd,addr,sizeof(addr)),
strerror(errno) ));
} else {
DEBUG(0,("read_data: read failure for %d. "
{
size_t total=0;
ssize_t ret;
+ char addr[INET6_ADDRSTRLEN];
while (total < N) {
ret = sys_write(fd,buffer + total,N - total);
if (ret == -1) {
- if (fd == client_fd) {
+ if (fd == get_client_fd()) {
/* Try and give an error message saying
* what client failed. */
DEBUG(0,("write_data: write failure in "
"writing to client %s. Error %s\n",
- client_ip_string, strerror(errno) ));
+ get_peer_addr(fd,addr,sizeof(addr)),
+ strerror(errno) ));
} else {
DEBUG(0,("write_data: write failure. "
"Error = %s\n", strerror(errno) ));
*space = '\0';
- if (strncmp(client_addr(addr,sizeof(addr)),
+ if (strncmp(client_addr(get_client_fd(),addr,sizeof(addr)),
buf, strlen(buf)) == 0) {
found = True;
break;
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, pjob->user);
- clientname = client_name();
+ clientname = client_name(get_client_fd());
if (strcmp(clientname, "UNKNOWN") == 0) {
- clientname = client_addr(addr,sizeof(addr));
+ clientname = client_addr(get_client_fd(),addr,sizeof(addr));
}
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, pjob->user);
- clientname = client_name();
+ clientname = client_name(get_client_fd());
if (strcmp(clientname, "UNKNOWN") == 0) {
- clientname = client_addr(addr,sizeof(addr));
+ clientname = client_addr(get_client_fd(),addr,sizeof(addr));
}
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
*/
if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
- client_name(), client_addr(addr,sizeof(addr))))
- {
+ client_name(get_client_fd()),
+ client_addr(get_client_fd(),addr,sizeof(addr)))) {
DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
return False;
}
crec.bcast_msg_flags = msg_flags;
strlcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine));
- strlcpy(crec.addr,conn?conn->client_address:client_addr(addr,sizeof(addr)),
+ strlcpy(crec.addr,conn?conn->client_address:
+ client_addr(get_client_fd(),addr,sizeof(addr)),
sizeof(crec.addr));
dbuf.dptr = (uint8 *)&crec;
/* send a negative session response "not listening on calling name" */
static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81};
DEBUG( 1, ( "Connection denied from %s\n",
- client_addr(addr,sizeof(addr)) ) );
+ client_addr(get_client_fd(),addr,sizeof(addr)) ) );
(void)send_smb(smbd_server_fd(),(char *)buf);
exit_server_cleanly("connection denied");
}
static void smbd_set_server_fd(int fd)
{
server_fd = fd;
- client_setfd(fd);
}
+int get_client_fd(void)
+{
+ return server_fd;
+}
struct event_context *smbd_event_context(void)
{
add_session_user(user);
- safe_strcpy(conn->client_address, client_addr(addr,sizeof(addr)),
- sizeof(conn->client_address)-1);
+ safe_strcpy(conn->client_address,
+ client_addr(get_client_fd(),addr,sizeof(addr)),
+ sizeof(conn->client_address)-1);
conn->num_files_open = 0;
conn->lastused = conn->lastused_count = time(NULL);
conn->used = True;
DEBUG(0,("%s (%s) couldn't find service %s\n",
get_remote_machine_name(),
- client_addr(addr,sizeof(addr)),
+ client_addr(get_client_fd(),addr,sizeof(addr)),
service));
*status = NT_STATUS_BAD_NETWORK_NAME;
return NULL;
client_name() handles this case internally.
*/
- hostname = client_name();
+ hostname = client_name(get_client_fd());
if (strcmp(hostname, "UNKNOWN") == 0) {
- hostname = client_addr(addr,sizeof(addr));
+ hostname = client_addr(get_client_fd(),addr,sizeof(addr));
}
fstrcpy(sessionid.username, vuser->user.unix_name);
sessionid.uid = vuser->uid;
sessionid.gid = vuser->gid;
fstrcpy(sessionid.remote_machine, get_remote_machine_name());
- fstrcpy(sessionid.ip_addr_str, client_addr(addr,sizeof(addr)));
+ fstrcpy(sessionid.ip_addr_str,
+ client_addr(get_client_fd(),addr,sizeof(addr)));
sessionid.connect_start = time(NULL);
if (!smb_pam_claim_session(sessionid.username, sessionid.id_str,
#endif
if (lp_reset_on_zero_vc()) {
connections_forall(shutdown_other_smbds,
- CONST_DISCARD(void *,
- client_addr(addr,sizeof(addr))));
+ CONST_DISCARD(void *,
+ client_addr(get_client_fd(),addr,sizeof(addr))));
}
}
extern pstring user_socket_options;
+int get_client_fd(void)
+{
+ return -1;
+}
+
/****************************************************************************
handle completion of commands for readline
****************************************************************************/