--- wb_common.c@@/main/LATEST	Wed Jun 19 04:13:44 2002
+++ wb_common.c	Tue Jun 25 11:33:48 2002
@@ -25,6 +25,15 @@
 #include "winbind_nss_config.h"
 #include "winbindd_nss.h"
 
+#ifdef WITH_WINBIND_CFG
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+
+#define WINBIND_CFG "/etc/winbind.cfg"
+#endif /* WITH_WINBIND_CFG */
+
 /* Global variables.  These are effectively the client state information */
 
 int winbindd_fd = -1;           /* fd for winbindd socket */
@@ -96,6 +105,60 @@
 
 /* Connect to winbindd socket */
 
+#ifdef WITH_WINBIND_CFG
+int winbind_open_tcp_sock(int tcpport, char *ip)
+{
+    struct sockaddr_in servaddr;
+
+    if (winbindd_fd != -1) {
+            return winbindd_fd;
+    }    
+
+    bzero(&servaddr, sizeof(servaddr));  	
+    servaddr.sin_port = htons(tcpport);	
+    servaddr.sin_family = AF_INET;
+	       
+    if ((winbindd_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+		perror("socket");
+        return -1;
+	}
+ 
+    inet_pton(AF_INET, ip, &servaddr.sin_addr);        
+    free(ip);
+
+    if (connect (winbindd_fd, (struct sockaddr *) &servaddr, sizeof(servaddr)) !=0 ) {
+        close_sock();        
+        return -1;
+    }   
+
+	/* Return socket */
+	return winbindd_fd;
+}
+
+int read_wb_config(int *portnum, char **ip)
+{
+    int fd;
+    int port;
+    char s[300];
+    char p[50];
+    
+
+    if ((fd = open(WINBIND_CFG, O_RDONLY)) < 0) 
+    	return 0;
+
+    read(fd, s, 300);
+   
+    sscanf(s, "%s %d", p, &port);
+
+    *portnum = port;
+
+    *ip = malloc(strlen(p) + 1);
+    strcpy(*ip, p);
+ 
+    return 1;
+}
+#endif /* (ifdef WITH_WINBIND_CFG) */ 
+
 int winbind_open_pipe_sock(void)
 {
 	struct sockaddr_un sunaddr;
@@ -173,15 +236,23 @@
 int write_sock(void *buffer, int count)
 {
 	int result, nwritten;
-	
+	int portnum;
+    char *ip;
+
 	/* Open connection to winbind daemon */
 	
  restart:
 	
+#ifdef WITH_WINBIND_CFG
+    if (read_wb_config(&portnum, &ip)) {
+       if (winbind_open_tcp_sock(portnum, ip) == -1 ) {
+            return -1;
+       }
+    } else
+#endif  /* WITH_WINBIND_CFG */
 	if (winbind_open_pipe_sock() == -1) {
 		return -1;
 	}
-	
 	/* Write data to socket */
 	
 	nwritten = 0;
