Browse Source

Resolves: bug 230498
Bug Description: allow ds_newinst with ldapi and no serverport
Reviewed by: nkinder, nhosoi (Thanks!)
Fix Description: Two new fields have been added to the ds_newinst .inf files:
ldapifilepath - the full path and file name of the server ldapi file
start_server - if present and has a value of 0, this tells ds_newinst not to start the server - default is 1
The ds_newinst code has been changed to allow an empty or "0" value servport if an ldapifilepath is given (and ENABLE_LDAPI is defined). Either a valid server port or an ldapifilepath must be provided, or both.
In addition, I changed ds_newinst.pl to accept a .inf file given on stdin.
Platforms tested: RHEL4, FC6
Flag Day: no
Doc impact: We will have to document ldapi support on the wiki.

Rich Megginson 19 years ago
parent
commit
b4940b547e
3 changed files with 88 additions and 15 deletions
  1. 48 8
      ldap/admin/src/create_instance.c
  2. 3 0
      ldap/admin/src/create_instance.h
  3. 37 7
      ldap/admin/src/ds_newinst.pl.in

+ 48 - 8
ldap/admin/src/create_instance.c

@@ -253,7 +253,6 @@ void set_defaults(char *sroot, char *hn, server_config_s *conf)
 
     conf->servname = hn;
     conf->bindaddr = "";
-    conf->servport = "80";
     conf->cfg_sspt = NULL;
     conf->suitespot3x_uid = NULL;
     conf->cfg_sspt_uid = NULL;
@@ -331,6 +330,7 @@ void set_defaults(char *sroot, char *hn, server_config_s *conf)
 /* ----------------- Sanity check a server configuration ------------------ */
 
 char *create_instance_checkport(char *, char *);
+char *create_instance_checkports(server_config_s *cf);
 char *create_instance_checkuser(char *);
 int create_instance_numbers(char *);
 int create_instance_exists(char *fn, int type);
@@ -441,7 +441,7 @@ static char *sanity_check(server_config_s *cf, char *param_name)
     */
     if (!needToStartServer(cf))
     {
-        if( (t = create_instance_checkport(cf->bindaddr, cf->servport)) )
+        if( (t = create_instance_checkports(cf)))
         {
             PL_strncpyz(param_name, "servport", BIG_LINE);
             return t;
@@ -1418,6 +1418,20 @@ int tryuser(char *user)
 
 /* --------------------------- create_instance_check* ---------------------------- */
 
+char *create_instance_checkports(server_config_s *cf)
+{
+    /* allow port 0 if ldapifilepath is specified */
+#if defined(ENABLE_LDAPI)
+    if (!cf->ldapifilepath || strcmp(cf->servport, "0")) {
+#endif
+        return create_instance_checkport(cf->bindaddr, cf->servport);
+#if defined(ENABLE_LDAPI)
+    }
+#endif
+
+    return NULL;
+}
+
 
 char *create_instance_checkport(char *addr, char *sport)
 {
@@ -2687,7 +2701,11 @@ char *ds_gen_confs(char *sroot, server_config_s *cf, char *cs_path)
     fprintf(f, "nsslapd-ssl-check-hostname: on\n");
     fprintf(f, "nsslapd-port: %s\n", cf->servport);
 #if defined(ENABLE_LDAPI)
-    fprintf(f, "nsslapd-ldapifilepath: %s/%s-%s.socket\n", cf->run_dir, PRODUCT_NAME, cf->servid);
+    if (cf->ldapifilepath) {
+        fprintf(f, "nsslapd-ldapifilepath: %s\n", cf->ldapifilepath);
+    } else {
+        fprintf(f, "nsslapd-ldapifilepath: %s/%s-%s.socket\n", cf->run_dir, PRODUCT_NAME, cf->servid);
+    }
     fprintf(f, "nsslapd-ldapilisten: on\n");
 #if defined(ENABLE_AUTOBIND)
     fprintf(f, "nsslapd-ldapiautobind: on\n");
@@ -4003,9 +4021,10 @@ static char *install_ds(char *sroot, server_config_s *cf, char *param_name)
       it or if we are configuring the server to serve as the repository
       for SuiteSpot (Mission Control) information
       Only attempt to start the server if the port is not in use
+      In order to start the server, there must either be an ldapifilepath
+      specified or a valid port.  If the port is not "0" it must be valid.
       */
-    if(needToStartServer(cf) &&
-       !(t = create_instance_checkport(cf->bindaddr, cf->servport)))
+    if(needToStartServer(cf) && !(t = create_instance_checkports(cf)))
     {
     PR_snprintf(big_line, sizeof(big_line),"SERVER_NAMES=slapd-%s",cf->servid);
     putenv(big_line);
@@ -4366,12 +4385,33 @@ int parse_form(server_config_s *cf)
     }
 
     cf->bindaddr = ds_a_get_cgi_var("bindaddr", NULL, NULL);
-    if (!(cf->servport = ds_a_get_cgi_var("servport", "Server Port",
-                                          "Please specify the TCP port number for this server.")))
-    {
+#if defined(ENABLE_LDAPI)
+    temp = ds_a_get_cgi_var("ldapifilepath", NULL, NULL);
+    if (NULL != temp) {
+        cf->ldapifilepath = PL_strdup(temp);
+    }
+#endif
+
+    temp = ds_a_get_cgi_var("servport", NULL, NULL);
+    if (!temp
+#if defined(ENABLE_LDAPI)
+        && !cf->ldapifilepath
+#endif
+        ) {
+#if defined(ENABLE_LDAPI)
+        ds_show_message("error: either servport or ldapifilepath must be specified.");
+#else
+        ds_show_message("error: servport must be specified.");
+#endif
         return 1;
     }
 
+    if (NULL != temp) {
+        cf->servport = PL_strdup(temp);
+    } else {
+        cf->servport = PL_strdup("0");
+    }
+
     cf->cfg_sspt = ds_a_get_cgi_var("cfg_sspt", NULL, NULL);
     cf->cfg_sspt_uid = ds_a_get_cgi_var("cfg_sspt_uid", NULL, NULL);
     if (cf->cfg_sspt_uid && *(cf->cfg_sspt_uid) &&

+ 3 - 0
ldap/admin/src/create_instance.h

@@ -182,6 +182,9 @@ typedef struct {
     char *cert_dir;
     char *sasl_path;
     char *prefix;
+#if defined(ENABLE_LDAPI)
+    char *ldapifilepath;
+#endif
 } server_config_s;
 
 

+ 37 - 7
ldap/admin/src/ds_newinst.pl.in

@@ -44,7 +44,8 @@ use File::Basename;
 sub usage {
 	my $msg = shift;
 	print "Error: $msg\n";
-	print "Usage: $0 filename.inf\n";
+	print "Usage: $0 [-|filename.inf]\n";
+	print "Use - to read from stdin\n";
 	exit 1
 }
 
@@ -136,7 +137,7 @@ sub addAndCheck {
 }
 
 my $filename = $ARGV[0];
-usage("$filename not found") if (! -f $filename);
+usage("$filename not found") if ($filename ne "-" && ! -f $filename);
 
 my $curSection;
 # each key in the table is a section name
@@ -145,8 +146,14 @@ my $curSection;
 #   and the value is the config param value
 my %table = ();
 
-open(IN, $filename);
-while (<IN>) {
+my $fh;
+if ($filename eq "-") {
+    $fh = \*STDIN;
+} else {
+    open(IN, $filename);
+    $fh = \*IN;
+}
+while (<$fh>) {
 	# e.g. [General]
 	if (/^\[(.*?)\]/) {
 		$curSection = $1;
@@ -158,7 +165,9 @@ while (<IN>) {
 		$table{$curSection}->{$1} = $2;
 	}
 }
-close IN;
+if ($filename ne "-") {
+    close IN;
+}
 
 #printhash (\%table);
 
@@ -171,12 +180,29 @@ my $package_name = "@package_name@";
 addAndCheck(\%cgiargs, "sroot", \%table, "General", "ServerRoot");
 addAndCheck(\%cgiargs, "servname", \%table, "General", "FullMachineName");
 addAndCheck(\%cgiargs, "servuser", \%table, "General", "SuiteSpotUserID");
-addAndCheck(\%cgiargs, "servport", \%table, "slapd", "ServerPort");
 addAndCheck(\%cgiargs, "rootdn", \%table, "slapd", "RootDN");
 addAndCheck(\%cgiargs, "rootpw", \%table, "slapd", "RootDNPwd");
 addAndCheck(\%cgiargs, "servid", \%table, "slapd", "ServerIdentifier");
 addAndCheck(\%cgiargs, "suffix", \%table, "slapd", "Suffix");
 
+# either servport or ldapifilepath must be specified - the server must
+# listen to something . . .
+my $canlisten = 0;
+if (defined($table{"slapd"}->{"ServerPort"}) &&
+    $table{"slapd"}->{"ServerPort"} > 0) {
+    $canlisten = 1;
+    $cgiargs{"servport"} = $table{"slapd"}->{"ServerPort"};
+} else {
+    $cgiargs{"servport"} = "0"; # 0 means do not listen
+}
+if (defined($table{"slapd"}->{"ldapifilepath"})) {
+    $canlisten = 1;
+    $cgiargs{"ldapifilepath"} = $table{"slapd"}->{"ldapifilepath"};
+}
+if (! $canlisten) {
+    usage("Either ServerPort or ldapifilepath must be specified in the slapd section of $filename");
+}
+
 # the following items are optional
 
 $cgiargs{"lock_dir"} = $table{"slapd"}->{"lock_dir"};
@@ -253,7 +279,11 @@ $cgiargs{install_ldif_file} = $table{slapd}->{InstallLdifFile};
 # if for some reason you do not want the server started after instance creation
 # the following line can be commented out - NOTE that if you are creating the
 # Configuration DS, it will be started anyway
-$cgiargs{start_server} = 1;
+if (defined($table{"slapd"}->{"start_server"})) {
+    $cgiargs{start_server} = $table{"slapd"}->{"start_server"};
+} else { # default is on
+    $cgiargs{start_server} = 1;
+}
 
 my $sroot = $cgiargs{sroot};