--- winbindd.c@@/main/LATEST	Wed Jun 19 04:13:44 2002
+++ winbindd.c	Tue Jun 25 11:33:57 2002
@@ -199,10 +199,41 @@
 
 /* Create winbindd socket */
 
-static int create_sock(void)
+static int create_sock(int tcpport)
 {
-	return create_pipe_sock( WINBINDD_SOCKET_DIR,
+    int                 listenfd;
+    struct sockaddr_in  servaddr;
+    const int on=1;
+
+    if ( tcpport > -1 ) {
+        listenfd = socket(AF_INET, SOCK_STREAM, 0);
+        setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+
+        bzero(&servaddr, sizeof(servaddr));
+        
+        servaddr.sin_family      = AF_INET;
+        servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+        servaddr.sin_port = htons(tcpport);
+
+        if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))!=0) {
+            DEBUG(0, ("bind failed on winbind socket : %s\n",
+                  strerror(errno)));
+            close(listenfd);
+            return -1;
+        };
+    if (listen(listenfd, 5)!=0) {
+        DEBUG(0, ("listen failed on winbind socket : %s\n",
+                  strerror(errno)));
+        close(listenfd);
+        return -1;
+    }
+     /* Success! */
+    return listenfd;
+
+    } else {
+	    return create_pipe_sock( WINBINDD_SOCKET_DIR,
 				 WINBINDD_SOCKET_NAME, 0755);
+    }
 }
 
 struct dispatch_table {
@@ -515,8 +546,7 @@
 static void process_loop(int accept_sock)
 {
 	/* We'll be doing this a lot */
-
-	while (1) {
+  	while (1) {
 		struct winbindd_cli_state *state;
 		fd_set r_fds, w_fds;
 		int maxfd = accept_sock, selret;
@@ -679,6 +709,7 @@
 	printf("\t-n                disable cacheing\n");
 	printf("\t-d level          set debug level\n");
 	printf("\t-s configfile     choose smb.conf location\n");
+    printf("\t-l port           listen to tcp port [port]\n");
 	printf("\t-h                show this help message\n");
 }
 
@@ -692,6 +723,7 @@
 	int accept_sock;
 	BOOL interactive = False;
 	int opt;
+    int tcpport = -1;
 
 	/* glibc (?) likes to print "User defined signal 1" and exit if a
 	   SIGUSR[12] is received before a handler is installed */
@@ -716,7 +748,7 @@
 
 	/* Initialise samba/rpc client stuff */
 
-	while ((opt = getopt(argc, argv, "id:s:nh")) != EOF) {
+	while ((opt = getopt(argc, argv, "id:s:nl:h")) != EOF) {
 		switch (opt) {
 
 			/* Don't become a daemon */
@@ -744,6 +776,10 @@
 			usage();
 			exit(0);
 
+        case 'l':
+            tcpport=atoi(optarg);
+            break;
+
 		default:
 			printf("Unknown option %c\n", (char)opt);
 			exit(1);
@@ -855,9 +891,9 @@
 		exit(1);
 	}
 
-	/* Create UNIX domain socket */
+	/* Create socket */
 	
-	if ((accept_sock = create_sock()) == -1) {
+	if ((accept_sock = create_sock(tcpport)) == -1) {
 		DEBUG(0, ("failed to create socket\n"));
 		return 1;
 	}
