瀏覽代碼

Ticket 48754 - ldclt should support -H

Bug Description:  Most ldap tools are using the ldap url format of
ldap://hostname:port rather than -h hostname -p port. We should support this.

Fix Description:  Add support for -H to ldclt.

https://fedorahosted.org/389/ticket/48754

Author: wibrown

Review by: nhosoi (Thanks!)
William Brown 9 年之前
父節點
當前提交
d13057ebf1

+ 7 - 3
ldap/servers/slapd/tools/ldclt/ldapfct.c

@@ -489,9 +489,13 @@ connectToLDAP(thread_context *tttctx, const char *bufBindDN, const char *bufPass
   }
 
 #if defined(USE_OPENLDAP)
-  ldapurl = PR_smprintf("ldap%s://%s:%d/",
-			(mode & SSL) ? "s" : "",
-			mctx.hostname, mctx.port);
+  if (mctx.ldapurl != NULL) {
+    ldapurl = PL_strdup(mctx.ldapurl);
+  } else {
+    ldapurl = PR_smprintf("ldap%s://%s:%d/",
+              (mode & SSL) ? "s" : "",
+              mctx.hostname, mctx.port);
+  }
   if (PR_SUCCESS != PR_CallOnce(&ol_init_callOnce, internal_ol_init_init)) {
       printf("Could not perform internal ol_init init\n");
       goto done;

+ 14 - 4
ldap/servers/slapd/tools/ldclt/ldclt.c

@@ -2363,6 +2363,7 @@ main (
   mctx.filter	     = NULL;
   mctx.globStatsCnt  = DEF_GLOBAL_NB;				/*JLS 08-08-00*/
   mctx.hostname	     = "localhost";
+  mctx.ldapurl       = NULL;                /* Default url to none. */
   mctx.ignErrNb      = 0;
   mctx.images	     = NULL;					/*JLS 17-11-00*/
   mctx.imagesDir     = DEF_IMAGES_PATH;				/*JLS 16-11-00*/
@@ -2412,7 +2413,7 @@ main (
    * Get options
    */
   while ((opt_ret = getopt (argc, argv, 
-		"a:b:D:e:E:f:h:i:I:n:N:o:p:qQr:R:s:S:t:T:vVw:W:Z:H")) != EOF)
+		"a:b:D:e:E:f:h:H:i:I:n:N:o:p:qQr:R:s:S:t:T:vVw:W:Z:H")) != EOF)
     switch (opt_ret)
     {
       case 'a':
@@ -2439,6 +2440,9 @@ main (
       case 'h':
 	mctx.hostname = optarg;
 	break;
+      case 'H':
+	mctx.ldapurl = optarg;
+	break;
       case 'i':
 	mctx.inactivMax = atoi (optarg);
 	break;
@@ -2517,10 +2521,12 @@ main (
 	mctx.mode |= SSL;
 	mctx.certfile = optarg;
 	break;
+    /*
       case 'H':
 	usage ();
-	ldcltExit (EXIT_OK);					/*JLS 18-12-00*/
+	ldcltExit (EXIT_OK);
 	break;
+    */
       case '?':
 	usage ();
 	ldcltExit (EXIT_PARAMS);				/*JLS 13-11-00*/
@@ -2818,8 +2824,12 @@ main (
   {
     printf ("%s\n", argvList);					/*JLS 07-12-00*/
     printf ("Process ID         = %d\n", mctx.pid);
-    printf ("Host to connect    = %s\n", mctx.hostname);
-    printf ("Port number        = %d\n", mctx.port);
+    if (mctx.ldapurl != NULL) {
+      printf ("Ldap url           = %s\n", mctx.ldapurl);
+    } else {
+      printf ("Host to connect    = %s\n", mctx.hostname);
+      printf ("Port number        = %d\n", mctx.port);
+    }
     if (mctx.bindDN == NULL)
       printf ("Bind DN            = NULL\n");
     else

+ 1 - 0
ldap/servers/slapd/tools/ldclt/ldclt.h

@@ -521,6 +521,7 @@ typedef struct main_context {
 	char		*genldifName;	/* Where to put ldif */	/*JLS 19-03-01*/
 	int		 genldifFile;	/* Where to put ldif */	/*JLS 19-03-01*/
 	char		*hostname;	/* Host to connect */
+	char		*ldapurl; /* Url to connect to */
 	int		 globStatsCnt;	/* Global stats loop */ /*JLS 08-08-00*/
 	int		 ignErr[MAX_IGN_ERRORS]; /* Err ignor */
 	int		 ignErrNb;	/* Nb err ignored */

+ 2 - 0
ldap/servers/slapd/tools/ldclt/ldcltU.c

@@ -94,6 +94,7 @@
  * 		withnewparent : rename with newparent specified as argument.
  * 	 -f  Filter for searches.
  * 	 -h  Host to connect.                      Default "localhost".
+ * 	 -H  Ldap URL to connect to. Overrides -h -p. Default "None".
  * 	 -i  Number of times inactivity allowed.   Default 3 (30 seconds)
  * 	 -I  Ignore errors (cf. -E).               Default none.
  * 	 -n  Number of threads.                    Default 10.
@@ -200,6 +201,7 @@ void usage ()
   (void) printf ("		randomauthidhigh=value : high value for random SASL Authid.\n");
   (void) printf ("	 -f  Filter for searches.\n");
   (void) printf ("	 -h  Host to connect.                      Default \"localhost\".\n");
+  (void) printf ("	 -H  Ldap URL to connect to. Overrides -h -p. Default \"None\".\n");
   (void) printf ("	 -i  Number of times inactivity allowed.   Default 3 (30 seconds)\n");
   (void) printf ("	 -I  Ignore errors (cf. -E).               Default none.\n");
   (void) printf ("	 -n  Number of threads.                    Default 10.\n");

+ 3 - 0
man/man1/ldclt.1

@@ -55,6 +55,9 @@ Filter for searches.
 .B \fB\-h\fR
 Host to connect. Default "localhost".
 .TP
+.B \fB\-H\fR
+Ldap URL to connect to. Example, ldap://localhost:389. This takes precedence over -h and -p.
+.TP
 .B \fB\-i\fR
 Number of times inactivity allowed. Default 3 (30 seconds)
 .TP