Author: rmeggins
Update of /cvs/dirsec/setuputil/installer/lib
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv592/setuputil/installer/lib
Modified Files:
global.cpp ldapu.cpp setupapi.cpp
Log Message:
Resolves: bug 239494
Description: setuputil: use adm.conf instead of dbswitch.conf, ldap.conf, etc.
Fix Description: We only really need one config file - adm.conf - so just add extra fields
as necessary.
Reviewed by: nhosoi (Thanks!)
Index: global.cpp
===================================================================
RCS file: /cvs/dirsec/setuputil/installer/lib/global.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- global.cpp 29 Jul 2005 22:16:28 -0000 1.1.1.1
+++ global.cpp 9 May 2007 00:27:48 -0000 1.2
@@ -28,6 +28,12 @@
**
** HISTORY:
** $Log$
+** Revision 1.2 2007/05/09 00:27:48 rmeggins
+** Resolves: bug 239494
+** Description: setuputil: use adm.conf instead of dbswitch.conf, ldap.conf, etc.
+** Fix Description: We only really need one config file - adm.conf - so just add extra
fields as necessary.
+** Reviewed by: nhosoi (Thanks!)
+**
** Revision 1.1.1.1 2005/07/29 22:16:28 foxworth
** Importing new setup sdk for open source project
**
@@ -202,11 +208,9 @@
#endif
#ifndef XP_WIN32
-const char *DEFAULT_LDAPSWITCH = SETUP_DEFAULT_LDAPSWITCH;
const char *DEFAULT_ADMINUSER = "admin";
const char *DEFAULT_ADMINPWD = "admin";
-const char *DEFAULT_SSUSERCONF = "shared/config/ssusers.conf";
-const char *DEFAULT_ADMINCONF = "admin-serv/config/ns-admin.conf";
+const char *DEFAULT_ADMINCONF = SETUP_ADM_CONF;
const char *DEFAULT_SSUSER = "nobody";
const char *DEFAULT_SSGROUP = "nobody";
const char *DEFAULT_SROOT = "/opt/fedora";
Index: ldapu.cpp
===================================================================
RCS file: /cvs/dirsec/setuputil/installer/lib/ldapu.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ldapu.cpp 27 Mar 2006 21:18:35 -0000 1.2
+++ ldapu.cpp 9 May 2007 00:27:48 -0000 1.3
@@ -29,6 +29,12 @@
**
** HISTORY:
** $Log$
+** Revision 1.3 2007/05/09 00:27:48 rmeggins
+** Resolves: bug 239494
+** Description: setuputil: use adm.conf instead of dbswitch.conf, ldap.conf, etc.
+** Fix Description: We only really need one config file - adm.conf - so just add extra
fields as necessary.
+** Reviewed by: nhosoi (Thanks!)
+**
** Revision 1.2 2006/03/27 21:18:35 nhosoi
** [186642] Directory Server Makefile updates for Internal build
** Changed the createSIE so that caller (Admin Server and Directory Server) passes
@@ -1683,7 +1689,7 @@
}
else
{
- *p++ = NULL;
+ *p++ = '\0';
gotEntry = True;
stripBlank(buf, True);
stripBlank(p, False);
Index: setupapi.cpp
===================================================================
RCS file: /cvs/dirsec/setuputil/installer/lib/setupapi.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- setupapi.cpp 23 Mar 2006 15:59:10 -0000 1.2
+++ setupapi.cpp 9 May 2007 00:27:48 -0000 1.3
@@ -572,11 +572,12 @@
** there.
**
** INPUTS:
-** sroot - server root
+** configdir - directory containing the config file DEFAULT_ADMINCONF
** ldapURL - ldap url to be returned
** ldapUser - optional bind user id to be returned
+** adminDomain - admin domain
**
-** OUTPUTS: ldapURL, ldapUser, bindDN, bindPwd
+** OUTPUTS: ldapURL, ldapUser, adminDomain
** RETURN: none
** SIDE EFFECTS:
** none
@@ -593,19 +594,17 @@
char **adminDomain)
{
char tstr[BIG_BUF];
- snprintf(tstr, sizeof(tstr), "%s/%s", sroot, SETUP_LDAP_CONF);
+ snprintf(tstr, sizeof(tstr), "%s/%s", sroot, DEFAULT_ADMINCONF);
if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
+
+ NVPair admConf;
+
+ admConf.setFormat(2);
+ admConf.read(tstr);
+
if (ldapURL)
{
- *ldapURL = setupGetFileString("ConfigURL", " ", tstr);
- if (*ldapURL == NULL)
- {
- char dbswith[BIG_BUF];
- snprintf(dbswith, sizeof(dbswith), "%s/%s", sroot,
SETUP_DEFAULT_LDAPSWITCH);
- if (!memchr(dbswith, 0, sizeof(dbswith))) return; /*overflow*/
- *ldapURL = setupGetFileString("directory default", " ",
dbswith);
- }
-
+ *ldapURL = setupStrdup(admConf.get("ldapurl"));
if (*ldapURL && ldap_is_ldap_url(*ldapURL))
{
unescape_ldap_basedn(*ldapURL);
@@ -614,24 +613,12 @@
if (ldapUser)
{
- *ldapUser = setupGetFileString("admnm", " ", tstr);
+ *ldapUser = setupStrdup(admConf.get("userdn"));
}
if (adminDomain)
{
- *adminDomain = setupGetFileString(DS_ADMIN_DOMAIN, ":", tstr);
- if (*adminDomain == NULL)
- {
- char *s = NULL;
- snprintf(tstr, sizeof(tstr), "%s/%s", sroot, SETUP_DS_CONF);
- if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
- s = setupGetFileString(DS_ADMIN_DOMAIN, ":", tstr);
- if (s)
- {
- *adminDomain = setupStripAdminDomainDN(s);
- setupFree(s);
- }
- }
+ *adminDomain = setupStrdup(admConf.get(DS_ADMIN_DOMAIN));
}
return;
@@ -642,7 +629,7 @@
** FUNCTION: setupSetDefaultLdapInfo
** replaced: getDefaultLdapInfo
** DESCRIPTION:
-** Set Config Ldap information to ldap.conf. Caller needs to fill the
+** Set Config Ldap information to adm.conf. Caller needs to fill the
** value to each argument. NULL means not to change the existing value.
**
** INPUTS:
@@ -658,7 +645,7 @@
** RESTRICTIONS:
** None
** MEMORY:
-** Returned memory is allocated for char ** parameters
+** none
**********************************************************************
*/
@@ -668,55 +655,18 @@
char *adminDomain)
{
char tstr[BIG_BUF];
- char *oldLines[2];
- char *newLines[2];
- char buffer[100];
-
- if (ldapURL)
- {
-
- snprintf(tstr, sizeof(tstr), "%s/%s", sroot, SETUP_DEFAULT_LDAPSWITCH);
- if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
- oldLines[1] = NULL;
- newLines[1] = NULL;
- snprintf(buffer, sizeof(buffer), "directory default %s", ldapURL);
- if (!memchr(buffer, 0, sizeof(buffer))) return; /*overflow*/
-
- oldLines[0] = (char *)"directory default ";
- newLines[0] = buffer;
- setupFileUpdateLines(oldLines, newLines, tstr);
- }
-
- if (ldapUser)
- {
- snprintf(tstr, sizeof(tstr), "%s/%s", sroot, SETUP_LDAP_CONF);
- if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
-
- oldLines[1] = NULL;
- newLines[1] = NULL;
- snprintf(buffer, sizeof(buffer), "admnm %s", ldapUser);
- if (!memchr(buffer, 0, sizeof(buffer))) return; /*overflow*/
-
- oldLines[0] = (char *)"admnm";
- newLines[0] = buffer;
- setupFileUpdateLines(oldLines, newLines, tstr);
- }
+ snprintf(tstr, sizeof(tstr), "%s/%s", sroot, DEFAULT_ADMINCONF);
+ if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
- if (adminDomain)
- {
- snprintf(tstr, sizeof(tstr), "%s/%s", sroot, SETUP_DS_CONF);
- if (!memchr(tstr, 0, sizeof(tstr))) return; /*overflow*/
+ NVPair admConf;
- oldLines[1] = NULL;
- newLines[1] = NULL;
- snprintf(buffer, sizeof(buffer), "%s:%s", DS_ADMIN_DOMAIN, adminDomain);
- if (!memchr(buffer, 0, sizeof(buffer))) return; /*overflow*/
-
- oldLines[0] = (char *) DS_ADMIN_DOMAIN;
- newLines[0] = buffer;
- setupFileUpdateLines(oldLines, newLines, tstr);
- }
+ admConf.setFormat(2);
+ admConf.read(tstr);
+ admConf.set("ldapurl", ldapURL);
+ admConf.set("userdn", ldapUser);
+ admConf.set(DS_ADMIN_DOMAIN, adminDomain);
+ admConf.write();
return;
}
@@ -1138,7 +1088,7 @@
return malloc(size);
}
NSAPI_EXTERN char *
- setupStrdup(char *src)
+ setupStrdup(const char *src)
{
if (!(src))
{
@@ -2912,147 +2862,3 @@
return (unsigned long)(((unsigned long long)buf.f_bavail / 1024.0) * buf.f_frsize);
#endif
}
-
-/*********************************************************************
-**
-** FUNCTION: setupFileUpdateLines
-** DESCRIPTION: replace multiple lines to new lines in existing text file.
-**
-** INPUTS:
-** oldLines -- existing lines to match.
-** newLines -- replacement lines for each oldLines
-** OUTPUTS:
-** if successful, the file will be replaced with new one.
-** RETURN:
-** 0 -- success
-** 1 -- file can't open for read
-** 2 -- can't write the file.
-** 3 -- out of memory
-** Note:
-** setupReplaceLines does case insensitive match between each line from file
-** and oldLines. When matching, string length is based on oldLines.
-** Thus caller can pass "partial" line as oldLines and replaced it with
-** newLines. oldLines and newLines should be in sync. Last item in oldLines
-** should be set to NULL.
-**********************************************************************
-*/
-
-
-int setupFileUpdateLines(char *oldLines[], char *newLines[], char *fileName)
-{
- char line[1024];
- struct stat statbuf;
- long size;
- FILE *fp;
- char *buffer;
- int origbuflen;
- int buflen;
- int *updateList;
- int n;
- int extraSize;
- int i;
-
- n = 0;
- extraSize = 0;
- while (newLines[n] != NULL)
- {
- extraSize += strlen(newLines[n]);
- n ++;
- }
-
- updateList = (int *) malloc(n);
- if (updateList == NULL)
- return 3;
- for (i = 0; i < n; i++)
- {
- updateList[i] = 0;
- }
-
- if (stat(fileName, &statbuf) != 0)
- {
- buflen = extraSize + 1;
- buffer = (char *) malloc(buflen);
- if (buffer == NULL)
- return 3;
- buffer[0] = '\0';
- }
- else
- {
- size = statbuf.st_size;
-
- if ((fp = fopen(fileName, "r")) == NULL)
- return 1;
-
- /*
- * get replacement count
- */
-
- origbuflen = buflen = size + extraSize + 1;
- buffer = (char *) malloc(buflen);
- if (buffer == NULL)
- return 3;
-
- buffer[0] = '\0';
-
- /*
- * replace necessary lines and save them to memory
- */
- while(fgets(line, sizeof(line), fp))
- {
- for (i = 0; i < n; i ++)
- {
- if (strncasecmp(line, oldLines[i], strlen(oldLines[i])) == 0)
- {
- strncat(buffer, newLines[i], buflen);
- buflen -= strlen(newLines[i]);
- strncat(buffer, "\n", buflen);
- buflen -= 1;
- if (buflen <= 0) {
- buffer[origbuflen - 1] = '\0';
- goto error_out; /* overflow: write at least what we have */
- }
- updateList[i] = 1;
- }
- else
- {
- strncat(buffer, line, buflen);
- buflen -= strlen(line);
- strncat(buffer, "\n", buflen);
- buflen -= 1;
- if (buflen <= 0) {
- buffer[origbuflen - 1] = '\0';
- goto error_out; /* overflow: write at least what we have */
- }
- }
- }
- }
- fclose(fp);
- }
-
- for (i = 0; (i < n) && (updateList[i] == 0); i++)
- {
- strncat(buffer, newLines[i], buflen);
- buflen -= strlen(newLines[i]);
- strncat(buffer, "\n", buflen);
- buflen -= 1;
- if (buflen <= 0) {
- buffer[origbuflen - 1] = '\0';
- goto error_out; /* overflow: write at least what we have */
- }
- updateList[i] = 1;
- }
-error_out:
- /*
- * write from memory to file
- */
- if ((fp = fopen(fileName, "w")) == NULL)
- return 2;
-
- fwrite(buffer, sizeof(char), strlen(buffer), fp);
-
- free(buffer);
-
- fclose(fp);
-
- return 0;
-}