445?
bs at niggard.org
bs at niggard.org
Wed Sep 8 16:29:00 GMT 1999
On Sat, 28 Aug 1999, Luke Kenneth Casson Leighton wrote:
> i've done client-side (clientgen.c) in cvs main, it was incredibly simple:
>
> if (port != 445)
> {
> cli_session_request(...)
> }
>
> server-side i haven't done, i don't know enough about sockets: you need to
> listen on both 445 and 139. if 445, then skip the session request and
> fake up the netbios names (called / calling) from reverse dns lookups
> (gethostbyaddr()).
I've written a little patch to smbd. Now you can use 'smbpasswd' over port
445. Everything else is probably broken, so handle with care ;)
cu,
bertl.
-------------- next part --------------
diff -urN samba/source/lib/util_sock.c samba-patch/source/lib/util_sock.c
--- samba/source/lib/util_sock.c Wed Sep 8 16:59:53 1999
+++ samba-patch/source/lib/util_sock.c Wed Sep 8 14:58:32 1999
@@ -35,6 +35,9 @@
/* the client file descriptor */
int Client = -1;
+/* the port, where client connected */
+int ClientPort = 0;
+
/* the last IP received from */
struct in_addr lastip;
diff -urN samba/source/smbd/process.c samba-patch/source/smbd/process.c
--- samba/source/smbd/process.c Wed Sep 8 16:58:26 1999
+++ samba-patch/source/smbd/process.c Wed Sep 8 17:11:19 1999
@@ -746,6 +746,7 @@
void smbd_process(void)
{
extern int Client;
+ extern int ClientPort;
InBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
OutBuffer = (char *)malloc(BUFFER_SIZE + SAFETY_MARGIN);
@@ -771,6 +772,33 @@
/* re-initialise the timezone */
TimeInit();
+
+ /* if connection on port 445, fake session setup... */
+ if(ClientPort == 445)
+ {
+ extern fstring remote_machine;
+ extern fstring local_machine;
+ char *s;
+
+ fstrcpy(remote_machine, dns_to_netbios_name(client_name(Client)));
+ fstrcpy(local_machine, global_myname);
+ remote_machine[15] = 0;
+ local_machine[15] = 0;
+ strlower(remote_machine);
+ strlower(local_machine);
+
+ DEBUG(2, ("smbd_process(): faking session setup\n"
+ "client_name: %s my_name: %s\n", remote_machine, local_machine));
+
+ add_session_user(remote_machine);
+
+ reload_services(True);
+ reopen_logs();
+
+ if(lp_status(-1)) {
+ claim_connection(NULL,"STATUS.",MAXSTATUS,True);
+ }
+ }
while (True)
{
diff -urN samba/source/smbd/server.c samba-patch/source/smbd/server.c
--- samba/source/smbd/server.c Wed Sep 8 16:58:33 1999
+++ samba-patch/source/smbd/server.c Wed Sep 8 17:33:18 1999
@@ -76,11 +76,13 @@
static BOOL open_sockets_inetd(void)
{
extern int Client;
+ extern int ClientPort;
/* Started from inetd. fd 0 is the socket. */
/* We will abort gracefully when the client or remote system
goes away */
Client = dup(0);
+ ClientPort = 138;
/* close our standard file descriptors */
close_low_fds();
@@ -91,13 +93,32 @@
return True;
}
+/****************************************************************************
+ open and listen to a socket
+****************************************************************************/
+static int open_server_socket(int port, ulong ipaddr)
+{
+ int s;
+
+ s = open_socket_in(SOCK_STREAM, port, 0, ipaddr);
+ if(s == -1)
+ return -1;
+ /* ready to listen */
+ if (listen(s, 5) == -1) {
+ DEBUG(0,("listen: %s\n", strerror(errno)));
+ close(s);
+ return -1;
+ }
+ return s;
+}
/****************************************************************************
open the socket communication
****************************************************************************/
-static BOOL open_sockets(BOOL is_daemon,int port)
+static BOOL open_sockets(BOOL is_daemon,int port,int port445)
{
extern int Client;
+ extern int ClientPort;
int num_interfaces = iface_count();
int fd_listenset[FD_SETSIZE];
fd_set listen_set;
@@ -131,7 +152,7 @@
socket per interface and bind to only these.
*/
- if(num_interfaces > FD_SETSIZE) {
+ if(num_interfaces * 2 > FD_SETSIZE) {
DEBUG(0,("open_sockets: Too many interfaces specified to bind to. Number was %d \
max can be %d\n",
num_interfaces, FD_SETSIZE));
@@ -147,15 +168,11 @@
DEBUG(0,("open_sockets: interface %d has NULL IP address !\n", i));
continue;
}
- s = fd_listenset[i] = open_socket_in(SOCK_STREAM, port, 0, ifip->s_addr);
- if(s == -1)
- return False;
- /* ready to listen */
- if (listen(s, 5) == -1) {
- DEBUG(0,("listen: %s\n",strerror(errno)));
- close(s);
- return False;
- }
+ s = fd_listenset[i * 2] = open_server_socket(port, ifip->s_addr);
+ if(s == -1) return False;
+ FD_SET(s,&listen_set);
+ s = fd_listenset[i * 2 + 1] = open_server_socket(port445, ifip->s_addr);
+ if(s == -1) return False;
FD_SET(s,&listen_set);
}
} else {
@@ -164,21 +181,16 @@
num_interfaces = 1;
/* open an incoming socket */
- s = open_socket_in(SOCK_STREAM, port, 0,
- interpret_addr(lp_socket_address()));
+ s = open_server_socket(port, interpret_addr(lp_socket_address()));
if (s == -1)
return(False);
-
- /* ready to listen */
- if (listen(s, 5) == -1) {
- DEBUG(0,("open_sockets: listen: %s\n",
- strerror(errno)));
- close(s);
- return False;
- }
-
fd_listenset[0] = s;
FD_SET(s,&listen_set);
+ s = open_server_socket(port445, interpret_addr(lp_socket_address()));
+ if (s == -1)
+ return(False);
+ fd_listenset[1] = s;
+ FD_SET(s,&listen_set);
}
/* now accept incoming connections - forking a new process
@@ -204,15 +216,22 @@
s = -1;
for(i = 0; i < num_interfaces; i++) {
- if(FD_ISSET(fd_listenset[i],&lfds)) {
- s = fd_listenset[i];
- /* Clear this so we don't look
- at it again. */
- FD_CLR(fd_listenset[i],&lfds);
+ if(FD_ISSET(fd_listenset[i * 2],&lfds)) {
+ s = fd_listenset[i * 2];
+ ClientPort = 138;
+ break;
+ }
+ if(FD_ISSET(fd_listenset[i * 2 + 1],&lfds)) {
+ s = fd_listenset[i * 2 + 1];
+ ClientPort = 445;
break;
}
}
+ /* Clear this so we don't look
+ at it again. */
+ FD_CLR(s,&lfds);
+
Client = accept(s,&addr,&in_addrlen);
if (Client == -1 && errno == EINTR)
@@ -489,6 +508,7 @@
/* shall I run as a daemon */
BOOL is_daemon = False;
int port = SMB_PORT;
+ int port445 = 455;
int opt;
extern char *optarg;
@@ -728,7 +748,7 @@
pidfile_create("smbd");
}
- if (!open_sockets(is_daemon,port))
+ if (!open_sockets(is_daemon,port,port445))
exit(1);
if (!locking_init(0))
More information about the samba-ntdom
mailing list