File pure-ftpd-1.0.22-oes-bugfix-534424.patch of Package pure-ftpd.import4353

--- src/ftpd.c	2010-09-24 12:29:10.000000000 +0530
+++ src/ftpd.c	2010-09-27 11:13:54.000000000 +0530
@@ -55,7 +55,8 @@ const char* SERV_LIST_FILE = "/var/opt/n
 #define MAX_PATH_SIZE 1000
 #define MAX_IP_SIZE 20
 #define MAX_NO_OF_SERVERS 300
-
+#define SITE_MSG "NCP Servers in the NDS Tree"
+#define CHK_MOD_TIME 3600
 
 char serverInfo[MAX_NO_OF_SERVERS][120]; 
 const char MOUNT_PATH[] = "/var/opt/novell/nclmnt";
@@ -63,6 +64,7 @@ const int MOUNT_PATH_SIZE = 22;
 	
 char userFDN[512];
 static const char *getlocalhostname();
+void extractEdir_IP_Port(char *);
 	  
 
 #ifndef HAVE_SYS_FSUID_H
@@ -5358,9 +5360,8 @@ int main(int argc, char *argv[])
 		}	
 				  
 		case '3': {
-	   		edir_ldap_port = atoi(optarg);
-			if(edir_ldap_port <= 0 )
-				edir_ldap_port = 389;
+			/* Extract E-directory IP address & Port number */
+			extractEdir_IP_Port(optarg);
 	   		break;
 		}			
 		case '2': {
@@ -6162,6 +6163,9 @@ int edir_login(const char* user,const ch
 		
 		char* data[9];
 		char* context;
+		char tree[256] ={0};
+		char server[256] ={0};
+
 		context = index(userFDN,'.');
 		if(context != NULL)
 			context++;
@@ -6173,8 +6177,11 @@ int edir_login(const char* user,const ch
 			exit(0);
 		}	
 		
-		data[0] ="-t 127.0.0.1";
-		data[1] ="-s 127.0.0.1";
+		snprintf(tree,sizeof(tree),"-t %s",edir_ip_address);
+		snprintf(server,sizeof(server),"-s %s",edir_ip_address);
+
+		data[0] =tree;
+		data[1] =server;
 		data[2] ="-u" ; data[3] = (char*)user;
 		data[4] ="-c" ; data[5] = (char*)context;
 		data[6] ="-p" ; data[7] = (char*)passwd;
@@ -6252,18 +6259,18 @@ int edir_login(const char* user,const ch
 
 int mount_remote_server(const char* where,char* nss_loc,char* remote_server)
 {
-	char tmp[MAX_PATH_SIZE+1000],path[MAX_PATH_SIZE];
+	char tmp[2*MAX_PATH_SIZE] = {0},path[MAX_PATH_SIZE] = {0};
 	char* str1,*server;
 	int err,i;
 	struct hostent *he;
 	struct in_addr ipv4addr;
 	//mnt_loc         - mounted path name by novell client (server name)
 	//ncl_req_name    - Request used in novell client (IP - preferably) 
-	char mnt_loc[MAX_SERVER_SIZE],ncl_req_name[MAX_SERVER_SIZE],ip[MAX_IP_SIZE];
+	char mnt_loc[MAX_SERVER_SIZE] ={0},ncl_req_name[MAX_SERVER_SIZE] = {0},ip[MAX_IP_SIZE] = {0};
 	struct in_addr addr;	
 	char*  context = NULL;
 	
-	if((where != NULL ) &&(strncmp(where,"//",2 ) ==0))
+	if((where != NULL ) && (strncmp(where,"//",2 ) ==0) && (strlen(where) > 2) )
 	{
 
 		if( no_of_server <= 0) 
@@ -6276,6 +6283,11 @@ int mount_remote_server(const char* wher
 		str1 = (char*) where+2;
 		server = strtok(str1,"/");
 
+		if ( NULL == server)
+		{
+			return -1;
+		}
+
 		/*
 		   Get the server name/ip address of remote server
 		   Remote server name in ftp request can be either server name / DNS name / IP
@@ -6413,19 +6425,89 @@ int get_remote_server_path(char* path)
 	return 0;
 }	
 
-// response for site slist command
+/**
+ * Description: This function is used to extract E-directory IP address
+ * and Port number.
+ *
+ * Input: Charcter string which have IP address & port number.
+ *
+ * Output: None.
+ */
+void extractEdir_IP_Port(char *optarg)
+{
+	char *ip_address;
+        char *port;
+
+	/* extract ip address */
+        ip_address=strtok(optarg,":");
+
+	/* extract port and validate the port */
+        if ( (NULL != ip_address) && (NULL != (port= strtok(NULL,":"))))
+        {
+        	edir_ip_address = strdup(ip_address);
+                edir_ldap_port = atoi(port);
+                
+		if((edir_ldap_port <= 0) || (edir_ldap_port > 65535))
+                	edir_ldap_port = 389;
+        }
+        else
+        {
+		/* Assign default IP address & port number */
+                edir_ip_address = "127.0.0.1";
+                edir_ldap_port = 389;
+        }
+
+	return;
+}
+
+/**
+ * Description: This function is used to get file modified
+ * time in seconds.
+ *
+ * Input: fileName - file from which modified time to be calculated.
+ *
+ * Output: integer which holds the modified time in seconds
+ */
+static int getModTime(char *fileName)
+{
+        struct stat fileStat = {0};
+        struct timeval curTime = {0};
+
+        // get the file status from the file.
+        if (stat(fileName,&fileStat) < 0)
+        {
+                return -1;
+        }
+
+	// get the current time.
+        gettimeofday(&curTime,NULL);
+
+        return (curTime.tv_sec - fileStat.st_mtime);
+}
+
+/** 
+ * Description: This function is used to response for site slist command.
+ *
+ * Input: None
+ *
+ * Output: integer which return the status
+ *
+ */
 int do_list_servers()
 {
 	FILE* file;
 	char buffer[2*MAX_SERVER_FDN_SIZE];
 	int serverLen;
-	char server[200],*ip;
+	char server[200],countMsg[128]={0},*ip;
+	int nodeCount= 0;
 	
-	if( ( no_of_server <= 0) && (get_server_list_from_file() < 0))
+	if( (( no_of_server <= 0) && (get_server_list_from_file() < 0)) || (getModTime(SERV_LIST_FILE) >= CHK_MOD_TIME))
 		 get_server_list_from_edir();
 	
-	file = fopen (SERV_LIST_FILE,"r"); 
+	// Code added for Bug Fix: "534424 - FTP-RSN: Site slist doesn't list server count as in netware"
+	addreply_noformat(200, SITE_MSG);
 	
+	file = fopen (SERV_LIST_FILE,"r"); 
     if(file != NULL)
 	{	
 		while (!feof (file))
@@ -6442,12 +6524,19 @@ int do_list_servers()
 				serverLen = MAX_SERVER_FDN_SIZE;	
 			
 			snprintf(server,serverLen+1,"%s",buffer);
-			addreply_noformat(0, server);
+			
+			// Code added for Bug Fix: "534424 - FTP-RSN: Site slist doesn't list server count as in netware"
+			addreply_noformat(200, server);
+			nodeCount++;
 		}	
 		
 		fclose(file);
 	}  
 
+        // Code added for Bug Fix: "534424 - FTP-RSN: Site slist doesn't list server count as in netware"
+	sprintf(countMsg," %d \"NCP Server\"(s)",nodeCount);
+	addreply_noformat(200, countMsg);
+
 	return 0;
 	
 }
@@ -6455,7 +6544,7 @@ int do_list_servers()
 				  
 int ldap_connect(const char* username,const char*passwd)
 {	
-    	ldapHandle = ldap_init("127.0.0.1",edir_ldap_port);
+    	ldapHandle = ldap_init(edir_ip_address,edir_ldap_port);
     	if (ldapHandle == NULL)
     	{
 			return -1;
--- src/globals.h	2010-09-24 12:29:10.000000000 +0530
+++ src/globals.h	2010-09-24 12:20:33.000000000 +0530
@@ -30,6 +30,7 @@ GLOBAL0(signed char no_ipv4);           
 GLOBAL0(signed char remote_server);                    /* OES remote server supported or not*/
 GLOBAL0(signed char disallow_list_oes_server);         /* list remote OES server supported or not*/
 GLOBAL(unsigned int edir_ldap_port,389);                 /* edirectory ldap port*/
+GLOBAL0(char *edir_ip_address);                 /* edirectory ip address */
 GLOBAL0(char *default_home_dir);                /* default home dir */
 GLOBAL(const size_t cmdsize, MAXPATHLEN + 16U);
 GLOBAL0(char cmd[MAXPATHLEN + 32U]);        /* command line - about 30 chars for command */
openSUSE Build Service is sponsored by