Author: rmeggins
Update of /cvs/dirsec/adminutil/lib/libadminutil
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv19482/adminutil/lib/libadminutil
Modified Files:
admutil.c form_post.c psetc.c resource.c srvutil.c uginfo.c
Log Message:
Resolves: bug 239475
Bug Description: adminutil: Several admin server related bugs
Reviewed by: nhosoi (Thanks!)
Fix Description:
1) I needed a function to return the SIE DN given a server ID (e.g. return
cn=slapd-localhost, cn=..... given slapd-localhost). This is to avoid lots of
duplicate code in the admin server CGIs. There is an SSL version as well. Create non-ssl
and ssl function to find the SIE DN given the SIE ID. Change pset code to use these new
functions
2) Need to be able to force NSS initialization via ADMSSL_Init*. There were a couple of
places where admin server would perform a SHA hash using homegrown code. This has been
removed in favor of using NSS. ADMSSL_Init* would fail if
not configured for SSL, so we need to force it to initialize NSS even if SSL is
not configured. Change the ADMSSL_Init* routines to accept a force parameter. If this
parameter is true, force NSS_Initialize even if the adminutil is not configured for SSL.
Changed code that uses ADMSSL_Init* to use this new parameter.3) PSET attribute removal is
just broken. It corrupts the internal tree structure used to hold the attr/values. The
pset node removal code needed to set the node->left or ->right to NULL only after
freeing it. Fortunately this function is hardly used at all. 4) small memory leak in
form_post.c - not a big deal as this is only used by
CGIs which usually don't free() anyway but just exit() to release their memory. free
memory after use
Resolves: bug 239475
Bug Description: adminutil: Several admin server related bugs
Reviewed by: nhosoi (Thanks!)
Fix Description:
1) I needed a function to return the SIE DN given a server ID (e.g. return
cn=slapd-localhost, cn=..... given slapd-localhost). This is to avoid lots of
duplicate code in the admin server CGIs. There is an SSL version as well. Create non-ssl
and ssl function to find the SIE DN given the SIE ID. Change pset code to use these new
functions
2) Need to be able to force NSS initialization via ADMSSL_Init*. There were a couple of
places where admin server would perform a SHA hash using homegrown code. This has been
removed in favor of using NSS. ADMSSL_Init* would fail if
not configured for SSL, so we need to force it to initialize NSS even if SSL is
not configured. Change the ADMSSL_Init* routines to accept a force parameter. If this
parameter is true, force NSS_Initialize even if the adminutil is not configured for SSL.
Changed code that uses ADMSSL_Init* to use this new parameter.3) PSET attribute removal is
just broken. It corrupts the internal tree structure used to hold the attr/values. The
pset node removal code needed to set the node->left or ->right to NULL only after
freeing it. Fortunately this function is hardly used at all. 4) small memory leak in
form_post.c - not a big deal as this is only used by
CGIs which usually don't free() anyway but just exit() to release their memory. free
memory after use
Resolves: bug 239475
Bug Description: adminutil: Several admin server related bugs
Reviewed by: nhosoi (Thanks!)
Fix Description:
1) I needed a function to return the SIE DN given a server ID (e.g. return
cn=slapd-localhost, cn=..... given slapd-localhost). This is to avoid lots of
duplicate code in the admin server CGIs. There is an SSL version as well. Create non-ssl
and ssl function to find the SIE DN given the SIE ID. Change pset code to use these new
functions
2) Need to be able to force NSS initialization via ADMSSL_Init*. There were a couple of
places where admin server would perform a SHA hash using homegrown code. This has been
removed in favor of using NSS. ADMSSL_Init* would fail if
not configured for SSL, so we need to force it to initialize NSS even if SSL is
not configured. Change the ADMSSL_Init* routines to accept a force parameter. If this
parameter is true, force NSS_Initialize even if the adminutil is not configured for SSL.
Changed code that uses ADMSSL_Init* to use this new parameter.3) PSET attribute removal is
just broken. It corrupts the internal tree structure used to hold the attr/values. The
pset node removal code needed to set the node->left or ->right to NULL only after
freeing it. Fortunately this function is hardly used at all. 4) small memory leak in
form_post.c - not a big deal as this is only used by
CGIs which usually don't free() anyway but just exit() to release their memory. free
memory after use
5) small memory error in the new code in resource.c - does not affect any
released code. Make sure the buffer is correctly null terminated. Also, clean up a small
memory leak.
6) small memory leaks in various places in uginfo.c - also changed some code to
use PR_smprintf instead of fixed size buffers. Fixed memory leaks.
Platforms tested: RHEL4
Flag Day: no
Doc impact: no
Index: admutil.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/admutil.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- admutil.c 4 Apr 2007 19:37:36 -0000 1.7
+++ admutil.c 8 May 2007 19:13:25 -0000 1.8
@@ -77,11 +77,13 @@
const char *path /* path given by caller */
)
{
- char *retval = NULL;
+ char *retval = NULL;
char *adminutilConfDir = getenv(ADMINUTIL_CONFDIR_ENV_VAR);
- /* try given path */
- retval = PR_smprintf("%s/%s", path, filename);
+ /* try given path */
+ if (path) {
+ retval = PR_smprintf("%s/%s", path, filename);
+ }
if (!is_file_ok(retval) && adminutilConfDir) {
PR_smprintf_free(retval);
retval = PR_smprintf("%s/%s", adminutilConfDir, filename);
@@ -91,7 +93,7 @@
}
}
- return retval;
+ return retval;
}
/* Copy from libadmin..... */
@@ -848,16 +850,20 @@
else if (result > 0) {
if (node->left) {
flag = treeRemoveNode(node->left, name, &remove);
- if (remove) PR_Free(node->left);
- node->left = NULL;
+ if (remove) {
+ PR_Free(node->left);
+ node->left = NULL;
+ }
}
else flag = ADMUTIL_OP_FAIL; /* Can't find the node */
}
else {
if (node->right) {
flag = treeRemoveNode(node->right, name, &remove);
- if (remove) PR_Free(node->right);
- node->right = NULL;
+ if (remove) {
+ PR_Free(node->right);
+ node->right = NULL;
+ }
}
else flag = ADMUTIL_OP_FAIL; /* Can't find the node */
}
Index: form_post.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/form_post.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- form_post.c 4 Apr 2007 19:37:36 -0000 1.4
+++ form_post.c 8 May 2007 19:13:25 -0000 1.5
@@ -152,6 +152,7 @@
vars[cl] = '\0';
input = string_to_vec(vars);
+ PL_strfree(vars); /* string_to_vec dups it */
}
PR_IMPLEMENT(void)
Index: psetc.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/psetc.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- psetc.c 4 Apr 2007 19:37:36 -0000 1.4
+++ psetc.c 8 May 2007 19:13:25 -0000 1.5
@@ -31,6 +31,7 @@
#include "psetc_pvt.h"
#include "libadminutil/admutil.h"
#include "libadminutil/distadm.h"
+#include "libadminutil/srvutil.h"
#include "dbtadmutil.h"
#include <ldap_ssl.h>
@@ -1316,12 +1317,13 @@
psetCreate(char* serverID, char* configRoot, char* user, char* passwd,
int* errorcode)
{
- PsetHndl pset;
+ PsetHndl pset = NULL;
AdmldapInfo ldapInfo= NULL;
- char *path, *ldapHost=NULL, *sieDN = NULL;
+ char *path = NULL, *ldapHost=NULL, *sieDN = NULL;
char *userDN = NULL;
char *bindPasswd = NULL;
int ldapPort = -1;
+ int useLocalConf = 1;
ldapInfo = admldapBuildInfo(configRoot, errorcode);
@@ -1336,8 +1338,20 @@
if (!ldapHost) ldapHost = PL_strdup("localhost");
if (ldapPort < 0) ldapPort = 389;
- /* Get SIE and password */
- sieDN = admldapGetSIEDN(ldapInfo);
+ /* if server is admin-serv, then the ldapInfo sieDN is the correct sieDN */
+ if (!serverID || !PL_strncasecmp(serverID, "admin-serv",
strlen("admin-serv"))) {
+ sieDN = admldapGetSIEDN(ldapInfo);
+ } else { /* given other serverID */
+ sieDN = findSIEDNByID(ldapInfo, serverID);
+ if (!sieDN) {
+ *errorcode = PSET_ENTRY_NOT_EXIST;
+ goto done;
+ }
+ useLocalConf = 0; /* disallow local.conf creation - will overwrite admin server one
*/
+ /* use psetRealCreate to pass in a conf file */
+ }
+
+ /* Get user dn and password */
if (!user) {
ADM_GetUserDNString(errorcode, &user);
}
@@ -1357,13 +1371,15 @@
}
/* find local.conf file */
- if (!(path = find_file_in_paths("local.conf", configRoot))) {
+ if (useLocalConf &&
+ !(path = find_file_in_paths("local.conf", configRoot))) {
/* error - no valid file or dir could be found */
*errorcode = PSET_ENV_ERR;
}
pset = psetRealCreate(ldapHost, ldapPort, sieDN, userDN, bindPasswd, path,
errorcode);
+done:
PR_Free(ldapHost);
PR_Free(sieDN);
PR_smprintf_free(path);
Index: resource.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/resource.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- resource.c 4 Apr 2007 19:37:36 -0000 1.2
+++ resource.c 8 May 2007 19:13:25 -0000 1.3
@@ -192,7 +192,7 @@
there may be truncation/overflow - see below */
msglen = (int32_t)bufsize;
u_strToUTF8(buffer, msglen, &msglen, umsg, umsglen, &status);
- buffer[bufsize] = '\0'; /* ensure null termination */
+ buffer[bufsize-1] = '\0'; /* ensure null termination */
} else {
/* Get first the required buffer size */
u_strToUTF8(NULL, 0, &msglen, umsg, umsglen, &status);
@@ -204,7 +204,10 @@
/* now the real conversion with allocated buffer */
u_strToUTF8((char*)result, msglen+1, &msglen, umsg, umsglen,
&status);
if (!U_SUCCESS(status)) {
+ PR_Free(result);
result = NULL;
+ } else {
+ result[msglen] = '\0';
}
}
}
Index: srvutil.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/srvutil.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- srvutil.c 4 Apr 2007 19:37:36 -0000 1.3
+++ srvutil.c 8 May 2007 19:13:25 -0000 1.4
@@ -237,3 +237,36 @@
return resultList;
}
+
+#define IS_A_DELIMITER(x) ((x == ',') || (x == ' ') || (x == '+')
|| (x == '\0'))
+
+PR_IMPLEMENT(char *)
+findSIEDNByID(AdmldapInfo info, const char *serverID)
+{
+ char *retval = NULL;
+ AttrNameList nl = getServerDNList(info);
+
+ if (nl) {
+ size_t len = strlen(serverID);
+ AttrNameList nlptr = nl;
+ while (retval = *nlptr++) {
+ /* nl is a list of DNs like this:
+ cn=slapd-foo, ...
+ cn=slapd-bar,...
+ cn=admin-serv-localhost,
+ ...
+ serverID is the value of the cn - we have to look for the trailing
+ delimiter to distinguish between slapd-foo slapd-foo2
+ */
+ if ((len <= strlen(retval+3)) &&
+ !PL_strncasecmp(retval+3, serverID, len) &&
+ (IS_A_DELIMITER(retval[3+len]))) {
+ retval = PL_strdup(retval);
+ break;
+ }
+ }
+ deleteAttrNameList(nl);
+ }
+
+ return retval;
+}
Index: uginfo.c
===================================================================
RCS file: /cvs/dirsec/adminutil/lib/libadminutil/uginfo.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- uginfo.c 4 Apr 2007 19:37:36 -0000 1.4
+++ uginfo.c 8 May 2007 19:13:25 -0000 1.5
@@ -85,6 +85,7 @@
0,
&result))
!= LDAP_SUCCESS ) {
+ ldap_msgfree(result);
#ifdef LDAP_DEBUG
ldap_perror(ld, "ldap_search_s");
#endif
@@ -104,6 +105,7 @@
if (ldap_count_entries(ld, result) == 0) {
/* error return : entry does not exist */
*error_code = UG_ENTRY_NOT_EXIST;
+ ldap_msgfree(result);
return 0;
}
@@ -128,10 +130,10 @@
} else {
PR_snprintf(buffer, sizeof(buffer), "%s %s", directoryURLVals[0],
s[0]);
}
- ldap_value_free(s);
} else {
PR_snprintf(buffer, sizeof(buffer), "%s", directoryURLVals[0]);
}
+ ldap_value_free(s);
*directoryURL = PL_strdup(buffer);
ldap_value_free(directoryURLVals);
@@ -149,6 +151,7 @@
ldap_value_free(directoryInfoRefVals);
}
+ ldap_msgfree(result);
return 1;
}
@@ -158,20 +161,20 @@
{
char** dnList;
int dnLen = 0;
- char dnbuf[1024];
+ char *dnbuf = NULL;
dnList = ldap_explode_dn(sieDN, 0);
- while (dnList[dnLen]) dnLen++;
+ while (dnList && dnList[dnLen]) dnLen++;
- if (dnLen <5) return NULL;
- PR_snprintf(dnbuf, sizeof(dnbuf),
- "%s,%s,%s,%s",
+ if (dnLen >= 5) {
+ dnbuf = PR_smprintf("%s,%s,%s,%s",
dnList[dnLen-4],
dnList[dnLen-3],
dnList[dnLen-2],
dnList[dnLen-1]);
-
- return PL_strdup(dnbuf);
+ }
+ ldap_value_free(dnList);
+ return dnbuf;
}
static char*
@@ -179,18 +182,19 @@
{
char** dnList;
int dnLen = 0;
- char dnbuf[1024];
+ char *dnbuf = NULL;
dnList = ldap_explode_dn(sieDN, 0);
- while (dnList[dnLen]) dnLen++;
+ while (dnList && dnList[dnLen]) dnLen++;
- if (dnLen < 3) return NULL;
- PR_snprintf(dnbuf, sizeof(dnbuf),
- "cn=UserDirectory, ou=Global Preferences,%s,%s",
+ if (dnLen >= 3) {
+ dnbuf = PR_smprintf("cn=UserDirectory, ou=Global Preferences,%s,%s",
dnList[dnLen-2],
dnList[dnLen-1]);
+ }
+ ldap_value_free(dnList);
- return PL_strdup(dnbuf);
+ return dnbuf;
}