[Fedora-directory-commits] ldapserver/ldap/admin/src create_instance.c, 1.48, 1.49 create_instance.h, 1.15, 1.16 ds_newinst.pl.in, 1.4, 1.5
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/ldapserver/ldap/admin/src
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv14385/ldapserver/ldap/admin/src
Modified Files:
create_instance.c create_instance.h ds_newinst.pl.in
Log Message:
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.
Index: create_instance.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/create_instance.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- create_instance.c 27 Feb 2007 02:57:24 -0000 1.48
+++ create_instance.c 1 Mar 2007 03:34:23 -0000 1.49
@@ -253,7 +253,6 @@
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 @@
/* ----------------- 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 @@
*/
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 @@
/* --------------------------- 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 @@
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 @@
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 @@
}
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) &&
Index: create_instance.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/create_instance.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- create_instance.h 9 Feb 2007 22:33:59 -0000 1.15
+++ create_instance.h 1 Mar 2007 03:34:23 -0000 1.16
@@ -182,6 +182,9 @@
char *cert_dir;
char *sasl_path;
char *prefix;
+#if defined(ENABLE_LDAPI)
+ char *ldapifilepath;
+#endif
} server_config_s;
Index: ds_newinst.pl.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/ds_newinst.pl.in,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ds_newinst.pl.in 12 Feb 2007 19:39:04 -0000 1.4
+++ ds_newinst.pl.in 1 Mar 2007 03:34:23 -0000 1.5
@@ -44,7 +44,8 @@
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 @@
}
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 @@
# 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 @@
$table{$curSection}->{$1} = $2;
}
}
-close IN;
+if ($filename ne "-") {
+ close IN;
+}
#printhash (\%table);
@@ -171,12 +180,29 @@
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 @@
# 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};
17 years