summaryrefslogtreecommitdiffstats
path: root/ldap/admin/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ldap/admin/lib')
-rw-r--r--ldap/admin/lib/Makefile9
-rw-r--r--ldap/admin/lib/dsalib_conf.c4
-rw-r--r--ldap/admin/lib/dsalib_confs.c8
-rw-r--r--ldap/admin/lib/dsalib_db.c23
-rw-r--r--ldap/admin/lib/dsalib_debug.c3
-rw-r--r--ldap/admin/lib/dsalib_filename.c4
-rw-r--r--ldap/admin/lib/dsalib_html.c5
-rw-r--r--ldap/admin/lib/dsalib_ldif.c25
-rw-r--r--ldap/admin/lib/dsalib_location.c9
-rw-r--r--ldap/admin/lib/dsalib_pw.c107
-rw-r--r--ldap/admin/lib/dsalib_updown.c45
-rw-r--r--ldap/admin/lib/dsalib_util.c47
12 files changed, 197 insertions, 92 deletions
diff --git a/ldap/admin/lib/Makefile b/ldap/admin/lib/Makefile
index 7f5e7011..a7c35ced 100644
--- a/ldap/admin/lib/Makefile
+++ b/ldap/admin/lib/Makefile
@@ -29,10 +29,7 @@ SRCS = dsalib_location.c dsalib_debug.c dsalib_updown.c dsalib_tailf.c \
dsalib_ldif.c dsalib_db.c dsalib_conf.c dsalib_html.c \
dsalib_filename.c dsalib_util.c dsalib_dn.c dsalib_confs.c dsalib_pw.c
-PWDOBJ=$(OBJDIR)/lib/libpwdstorage/ssha_pwd.o
-
-OBJS1 = $(addprefix $(OBJDEST)/, $(subst .c,.o,$(SRCS)))
-OBJS = $(OBJS1) $(PWDOBJ)
+OBJS = $(addprefix $(OBJDEST)/, $(subst .c,.o,$(SRCS)))
INCLUDES += -I$(LDAP_SRC)/admin/include
ifdef FORTEZZA
@@ -95,13 +92,13 @@ endif
veryclean: clean
clean:
- -$(RM) $(OBJS1)
+ -$(RM) $(OBJS)
-$(RM) $(LIBS)
ifeq ($(ARCH), WINNT)
-$(RM) $(IMPLIB)
endif
-$(OBJS1): $(OBJDEST)/%.o: %.c
+$(OBJS): $(OBJDEST)/%.o: %.c
$(CC) -c $(NONSHARED) $(CFLAGS) $(MCC_INCLUDE) $(OFFLAG)$(OBJDEST)/$*.o $*.c
ifdef USE_LINT
$(LINT) $(LINTCCFLAGS) $(DEFS) $(MCC_SERVER) $(INCLUDES) $(MCC_INCLUDE) $*.c > $(OBJDEST)/$*.ln 2>&1
diff --git a/ldap/admin/lib/dsalib_conf.c b/ldap/admin/lib/dsalib_conf.c
index c9156020..0a03efdb 100644
--- a/ldap/admin/lib/dsalib_conf.c
+++ b/ldap/admin/lib/dsalib_conf.c
@@ -17,6 +17,8 @@
#include "portable.h"
#include <ctype.h>
+#include "nspr.h"
+
#define CONF_FILE_NAME "config/dse.ldif"
#define CONF_SUFFIX "cn=config"
@@ -49,7 +51,7 @@ ds_get_config(int type)
return(NULL);
}
- sprintf(conffile, "%s/%s", root, CONF_FILE_NAME);
+ PR_snprintf(conffile, PATH_MAX, "%s/%s", root, CONF_FILE_NAME);
if ( !(sf = fopen(conffile, "r")) ) {
ds_send_error("could not read config file.", 1);
diff --git a/ldap/admin/lib/dsalib_confs.c b/ldap/admin/lib/dsalib_confs.c
index 565315dd..0545e2be 100644
--- a/ldap/admin/lib/dsalib_confs.c
+++ b/ldap/admin/lib/dsalib_confs.c
@@ -17,6 +17,7 @@
#include <string.h>
#include <ldif.h>
#include <ctype.h>
+#include "nspr.h"
#include "plstr.h"
/*
@@ -32,11 +33,11 @@ ds_get_conf_from_file(FILE *conf)
char *entry = 0;
int lineno = 0;
- while (entry = ldif_get_entry(conf, &lineno)) {
+ while ((entry = ldif_get_entry(conf, &lineno))) {
char *begin = entry;
if (!PL_strncasecmp(entry, config_entry, cfg_ent_len)) {
char *line = entry;
- while (line = ldif_getline(&entry)) {
+ while ((line = ldif_getline(&entry))) {
listsize++;
conf_list = (char **) realloc(conf_list,
((listsize + 1) * sizeof(char *)));
@@ -120,6 +121,9 @@ ds_get_value(char **ds_config, char *parm, int phase, int occurance)
value = tmpvalue;
}
free(tmpline);
+ if (errmsg) {
+ PR_smprintf_free(errmsg);
+ }
return value;
}
}
diff --git a/ldap/admin/lib/dsalib_db.c b/ldap/admin/lib/dsalib_db.c
index dbef2a6f..dd483d33 100644
--- a/ldap/admin/lib/dsalib_db.c
+++ b/ldap/admin/lib/dsalib_db.c
@@ -22,6 +22,7 @@
#define pclose _pclose
#endif
#include "portable.h"
+#include "nspr.h"
/*
* Get a listing of backup directories
@@ -42,7 +43,7 @@ ds_get_bak_dirs()
return(bak_dirs);
}
- sprintf( format_str, "%s%cbak", root, FILE_SEP );
+ PR_snprintf( format_str, PATH_MAX, "%s%cbak", root, FILE_SEP );
bak_dirs = ds_get_file_list( format_str );
if( bak_dirs )
{
@@ -50,7 +51,7 @@ ds_get_bak_dirs()
{
/* Prepend the filename with the install root */
char filename[PATH_MAX];
- sprintf( filename, "%s%cbak%c%s", root, FILE_SEP,
+ PR_snprintf( filename, PATH_MAX, "%s%cbak%c%s", root, FILE_SEP,
FILE_SEP, bak_dirs[i] );
free( bak_dirs[i] );
bak_dirs[i] = strdup( filename );
@@ -103,8 +104,8 @@ ds_bak2db(char *file)
}
tmp_dir = ds_get_tmp_dir();
- sprintf(statfile, "%s%cbak2db.%d", tmp_dir, FILE_SEP, (int)getpid());
- sprintf(startup_line,
+ PR_snprintf(statfile, PATH_MAX, "%s%cbak2db.%d", tmp_dir, FILE_SEP, (int)getpid());
+ PR_snprintf(startup_line, BIG_LINE,
"%s%cbak2db "
"%s%s%s > "
"%s%s%s 2>&1",
@@ -169,7 +170,7 @@ ds_db2bak(char *file)
file = NULL;
tmp_dir = ds_get_tmp_dir();
- sprintf(statfile, "%s%cdb2bak.%d", tmp_dir, FILE_SEP, (int)getpid());
+ PR_snprintf(statfile, PATH_MAX, "%s%cdb2bak.%d", tmp_dir, FILE_SEP, (int)getpid());
#if defined( XP_WIN32 )
@@ -178,7 +179,7 @@ ds_db2bak(char *file)
file = malloc( BIG_LINE );
time( &ltime );
- sprintf( file, "%s", ctime( &ltime ) );
+ PR_snprintf( file, BIG_LINE, "%s", ctime( &ltime ) );
ds_timetofname( file );
}
@@ -204,7 +205,7 @@ ds_db2bak(char *file)
*/
- sprintf(startup_line,
+ PR_snprintf(startup_line, sizeof(startup_line),
"%s%cdb2bak "
"%s%s%s > "
"%s%s%s 2>&1",
@@ -321,7 +322,7 @@ ds_vlvindex(char **backendList, char **vlvList)
return DS_NO_SERVER_ROOT;
}
- sprintf(startup_line, "%s/bin/slapd/server/%s db2index "
+ PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
"-D %s%s/%s "
"-n %s ",
root, SLAPD_NAME,
@@ -332,7 +333,7 @@ ds_vlvindex(char **backendList, char **vlvList)
/* Create vlv TAG */
vlvc=vlvList;
while( *vlvc != NULL ) {
- sprintf( startup_line, "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
+ PR_snprintf( startup_line, sizeof(startup_line), "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
vlvc++;
}
@@ -358,7 +359,7 @@ ds_addindex(char **attrList, char *backendName)
return DS_NO_SERVER_ROOT;
}
- sprintf(startup_line, "%s/bin/slapd/server/%s db2index "
+ PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
"-D %s%s%s "
"-n %s",
root, SLAPD_NAME,
@@ -366,7 +367,7 @@ ds_addindex(char **attrList, char *backendName)
backendName);
while( *attrList != NULL ) {
- sprintf( startup_line, "%s -t %s", startup_line, *attrList );
+ PR_snprintf( startup_line, sizeof(startup_line), "%s -t %s", startup_line, *attrList );
attrList++;
}
diff --git a/ldap/admin/lib/dsalib_debug.c b/ldap/admin/lib/dsalib_debug.c
index fd0ae631..797b84dc 100644
--- a/ldap/admin/lib/dsalib_debug.c
+++ b/ldap/admin/lib/dsalib_debug.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include "nspr.h"
#if defined( XP_WIN32 )
int ldap_debug = 0;
@@ -39,7 +40,7 @@ ds_log_env(char **envp)
for ( i = 0; envp[i] != (char *) 0; i++ ) {
char envstr[200];
- sprintf(envstr, "%s\n", envp[i]);
+ PR_snprintf(envstr, sizeof(envstr), "%s\n", envp[i]);
fwrite(envstr, strlen(envstr), 1, file);
}
fclose(file);
diff --git a/ldap/admin/lib/dsalib_filename.c b/ldap/admin/lib/dsalib_filename.c
index bce6e3f4..6007176c 100644
--- a/ldap/admin/lib/dsalib_filename.c
+++ b/ldap/admin/lib/dsalib_filename.c
@@ -12,6 +12,8 @@
#include <stdlib.h>
#include <ctype.h>
+#include "nspr.h"
+
static char *
get_month_str(int month)
{
@@ -89,7 +91,7 @@ ds_get_file_meaning(char *file)
return(NULL);
if ( (sec < 0) || (sec > 60) )
return(NULL);
- sprintf(meaning, "%s % 2d %02d:%02d:%02d %4d", get_month_str(month),
+ PR_snprintf(meaning, sizeof(meaning), "%s % 2d %02d:%02d:%02d %4d", get_month_str(month),
day, hour, minute, sec, year);
return(meaning);
}
diff --git a/ldap/admin/lib/dsalib_html.c b/ldap/admin/lib/dsalib_html.c
index 5ed44f0c..2732e225 100644
--- a/ldap/admin/lib/dsalib_html.c
+++ b/ldap/admin/lib/dsalib_html.c
@@ -26,11 +26,6 @@ static char **input = 0;
*/
static int formattedOutput = 1;
-/* This is the separator string to use when outputting key/value pairs
- to be read by the non-HTML front end (Java console)
-*/
-static const char *SEPARATOR = ":"; /* from AdmTask.java */
-
DS_EXPORT_SYMBOL int
ds_get_formatted_output(void)
{
diff --git a/ldap/admin/lib/dsalib_ldif.c b/ldap/admin/lib/dsalib_ldif.c
index 262cbc9c..3a126ce8 100644
--- a/ldap/admin/lib/dsalib_ldif.c
+++ b/ldap/admin/lib/dsalib_ldif.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "nspr.h"
#ifndef XP_WIN32
#define SCRIPT_SUFFIX "" /* shell scripts have no suffix */
@@ -163,21 +164,21 @@ importldif(char *file, int preserve, char *backend, char *subtree)
}
if ( preserve ) {
- sprintf(startup_line, "%s%cldif2db%s -i %s%s%s",
+ PR_snprintf(startup_line, BIG_LINE, "%s%cldif2db%s -i %s%s%s",
root, FILE_SEP, SCRIPT_SUFFIX,
ENQUOTE, file, ENQUOTE);
} else if (backend) {
- sprintf(startup_line, "%s%cldif2db%s -n %s%s%s -i %s%s%s",
+ PR_snprintf(startup_line, BIG_LINE, "%s%cldif2db%s -n %s%s%s -i %s%s%s",
root, FILE_SEP, SCRIPT_SUFFIX,
ENQUOTE, backend, ENQUOTE,
ENQUOTE, file, ENQUOTE);
} else if (subtree) {
- sprintf(startup_line, "%s%cldif2db%s -s %s%s%s -i %s%s%s",
+ PR_snprintf(startup_line, BIG_LINE, "%s%cldif2db%s -s %s%s%s -i %s%s%s",
root, FILE_SEP, SCRIPT_SUFFIX,
ENQUOTE, subtree, ENQUOTE,
ENQUOTE, file, ENQUOTE);
} else {
- sprintf(startup_line, "%s%cldif2db%s -i %s%s%s -noconfig",
+ PR_snprintf(startup_line, BIG_LINE, "%s%cldif2db%s -i %s%s%s -noconfig",
root, FILE_SEP, SCRIPT_SUFFIX,
ENQUOTE, file, ENQUOTE);
}
@@ -206,13 +207,13 @@ importldif(char *file, int preserve, char *backend, char *subtree)
char sbuf[ BIG_LINE ];
char filename[ BIG_LINE ];
if ( strlen( db_files[ i ]) > 0 ) {
- sprintf( filename, "%s%c%s", changelogdir,
+ PR_snprintf( filename, BIG_LINE, "%s%c%s", changelogdir,
FILE_SEP, db_files[ i ]);
- sprintf(sbuf, "Removing %s", filename);
+ PR_snprintf(sbuf, BIG_LINE, "Removing %s", filename);
ds_send_status( sbuf );
rc = unlink( filename);
if ( rc != 0 ) {
- sprintf( errbuf, "Warning: some files in %s could not "
+ PR_snprintf( errbuf, BIG_LINE, "Warning: some files in %s could not "
"be removed\n", changelogdir );
haderror++;
}
@@ -285,7 +286,7 @@ ds_db2ldif_subtree(char *file, char *subtree)
file = NULL;
tmp_dir = ds_get_tmp_dir();
- sprintf(statfile, "%s%cdb2ldif.%d", tmp_dir, FILE_SEP, (int) getpid());
+ PR_snprintf(statfile, PATH_MAX, "%s%cdb2ldif.%d", tmp_dir, FILE_SEP, (int) getpid());
#if defined( XP_WIN32 )
if( file == NULL )
@@ -294,7 +295,7 @@ ds_db2ldif_subtree(char *file, char *subtree)
file = malloc( BIG_LINE );
time( &ltime );
- sprintf( file, "%s", ctime( &ltime ) );
+ PR_snprintf( file, BIG_LINE, "%s", ctime( &ltime ) );
ds_timetofname( file );
}
#endif
@@ -304,13 +305,13 @@ ds_db2ldif_subtree(char *file, char *subtree)
else
strcpy( outfile, file );
- sprintf(scriptfile, "%s%cdb2ldif", root, FILE_SEP);
+ PR_snprintf(scriptfile, PATH_MAX, "%s%cdb2ldif", root, FILE_SEP);
PATH_FOR_PLATFORM( outfile );
PATH_FOR_PLATFORM( scriptfile );
if ( subtree == NULL ) {
- sprintf(startup_line,
+ PR_snprintf(startup_line, sizeof(startup_line),
"%s "
"%s%s%s > "
"%s%s%s 2>&1",
@@ -318,7 +319,7 @@ ds_db2ldif_subtree(char *file, char *subtree)
ENQUOTE, outfile, ENQUOTE,
ENQUOTE, statfile, ENQUOTE);
} else {
- sprintf(startup_line,
+ PR_snprintf(startup_line, sizeof(startup_line),
"%s "
"%s%s%s "
"-s \"%s\" > "
diff --git a/ldap/admin/lib/dsalib_location.c b/ldap/admin/lib/dsalib_location.c
index 53dc5a2f..600cc19c 100644
--- a/ldap/admin/lib/dsalib_location.c
+++ b/ldap/admin/lib/dsalib_location.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include "nspr.h"
/*
* Returns the server root. Info is
@@ -48,7 +49,7 @@ ds_get_install_root()
if ( (ds_name = ds_get_server_name()) == NULL )
return(NULL);
- sprintf(install_root, "%s/%s", root, ds_name);
+ PR_snprintf(install_root, sizeof(install_root), "%s/%s", root, ds_name);
return(install_root);
}
@@ -67,7 +68,7 @@ ds_get_admserv_based_root()
return(NULL);
if ( (ds_name = ds_get_server_name()) == NULL )
return(NULL);
- sprintf(install_root, "%s/%s", root, ds_name);
+ PR_snprintf(install_root, sizeof(install_root), "%s/%s", root, ds_name);
return(install_root);
}
@@ -96,7 +97,7 @@ ds_get_logfile_name(int config_type)
{
char *filename;
char **ds_config = NULL;
- static char logfile[PATH_MAX];
+ static char logfile[PATH_MAX+1];
if ( (ds_config = ds_get_config(DS_REAL_CONFIG)) == NULL ) {
/* For DS 4.0, no error output if file doesn't exist - that's
@@ -117,7 +118,7 @@ ds_get_logfile_name(int config_type)
free(filename);
return(NULL);
}
- strcpy(logfile, filename);
+ strncpy(logfile, filename, PATH_MAX);
free(filename);
return(logfile);
}
diff --git a/ldap/admin/lib/dsalib_pw.c b/ldap/admin/lib/dsalib_pw.c
index 6b224514..4c560c92 100644
--- a/ldap/admin/lib/dsalib_pw.c
+++ b/ldap/admin/lib/dsalib_pw.c
@@ -20,7 +20,112 @@
#include "dsalib.h"
#include "dsalib_pw.h"
-extern char * salted_sha1_pw_enc(char *);
+#include "prtime.h"
+#include "prlong.h"
+#include "prmem.h"
+
+#if defined(NET_SSL)
+#include <pk11func.h>
+#include <pk11pqg.h>
+#endif /* NET_SSL */
+
+#define SHA1_SALT_LENGTH 8 /* number of bytes of data in salt */
+#define PWD_HASH_PREFIX_START '{'
+#define PWD_HASH_PREFIX_END '}'
+
+#define SALTED_SHA1_SCHEME_NAME "SSHA"
+#define SALTED_SHA1_NAME_LEN 4
+
+/*
+ WARNING: The following code is blatantly copied from the server
+ pwdstorage ssha_pwd.c plugin. It would be nice to share this
+ code with the server. The problem is that the server wants to
+ use slapi_ch_malloc to allocate the memory for the returned
+ password - this function is not available outside the server
+ (as in the setup programs that also want to hash the password)
+ We need to figure out a way to put this code into a library
+ in such a way that the memory allocation functions to use
+ can be passed in or set beforehand.
+*/
+
+static void
+ssha_rand_array(void *randx, size_t len)
+{
+ PK11_RandomUpdate(randx, len);
+ PK11_GenerateRandom((unsigned char *)randx, (int)len);
+}
+
+/*
+ * A salted SHA1 hash
+ * if salt is null, no salt is used (this is for backward compatibility)
+*/
+SECStatus
+sha1_salted_hash(unsigned char *hash_out, char *pwd, struct berval *salt)
+{
+ PK11Context *ctx;
+ unsigned int outLen;
+ SECStatus rc;
+
+ if (salt && salt->bv_len) {
+ ctx = PK11_CreateDigestContext(SEC_OID_SHA1);
+ if (ctx == NULL) {
+ rc = SECFailure;
+ }
+ else {
+ PK11_DigestBegin(ctx);
+ PK11_DigestOp(ctx, (unsigned char*)pwd, strlen(pwd));
+ PK11_DigestOp(ctx, (unsigned char*)(salt->bv_val), salt->bv_len);
+ PK11_DigestFinal(ctx, hash_out, &outLen, SHA1_LENGTH);
+ PK11_DestroyContext(ctx, 1);
+ if (outLen == SHA1_LENGTH)
+ rc = SECSuccess;
+ else
+ rc = SECFailure;
+ }
+ }
+ else {
+ /*backward compatibility*/
+ rc = PK11_HashBuf(SEC_OID_SHA1, hash_out, (unsigned char *)pwd, strlen(pwd));
+ }
+
+ return rc;
+}
+
+char *
+salted_sha1_pw_enc( char *pwd )
+{
+ unsigned char hash[ SHA1_LENGTH + SHA1_SALT_LENGTH ];
+ unsigned char *salt = hash + SHA1_LENGTH;
+ struct berval saltval;
+ char *enc;
+
+ saltval.bv_val = (void*)salt;
+ saltval.bv_len = SHA1_SALT_LENGTH;
+
+ /* generate a new random salt */
+ /* Note: the uninitialized salt array provides a little extra entropy
+ * to the random array generation, but it is not really needed since
+ * PK11_GenerateRandom takes care of seeding. In any case, it doesn't
+ * hurt. */
+ ssha_rand_array( salt, SHA1_SALT_LENGTH );
+
+ /* SHA1 hash the user's key */
+ if ( sha1_salted_hash( hash, pwd, &saltval ) != SECSuccess ) {
+ return( NULL );
+ }
+
+ if (( enc = PR_Malloc( 3 + SALTED_SHA1_NAME_LEN +
+ LDIF_BASE64_LEN(sizeof(hash)))) == NULL ) {
+ return( NULL );
+ }
+
+ sprintf( enc, "%c%s%c", PWD_HASH_PREFIX_START, SALTED_SHA1_SCHEME_NAME,
+ PWD_HASH_PREFIX_END );
+ (void)ldif_base64_encode( hash, enc + 2 + SALTED_SHA1_NAME_LEN,
+ sizeof(hash), -1 );
+
+ return( enc );
+}
DS_EXPORT_SYMBOL char *
ds_salted_sha1_pw_enc (char* pwd)
diff --git a/ldap/admin/lib/dsalib_updown.c b/ldap/admin/lib/dsalib_updown.c
index e151e963..b737406d 100644
--- a/ldap/admin/lib/dsalib_updown.c
+++ b/ldap/admin/lib/dsalib_updown.c
@@ -58,7 +58,7 @@ ds_get_updown_status()
fprintf(stderr, "ds_get_updown_status: could not get install root\n");
return(DS_SERVER_UNKNOWN);
}
- sprintf(pid_file_name, "%s/logs/pid", root);
+ PR_snprintf(pid_file_name, BIG_LINE, "%s/logs/pid", root);
pidfile = fopen(pid_file_name, "r");
if ( pidfile == NULL ) {
/*
@@ -147,9 +147,9 @@ ds_bring_up_server_install(int verbose, char *root, char *errorlog)
#if !defined( XP_WIN32 )
tmp_dir = ds_get_tmp_dir();
- sprintf(statfile, "%s%cstartup.%d", tmp_dir, FILE_SEP, (int)getpid());
+ PR_snprintf(statfile, PATH_MAX, "%s%cstartup.%d", tmp_dir, FILE_SEP, (int)getpid());
- sprintf(startup_line, "%s%c%s > %s 2>&1",
+ PR_snprintf(startup_line, BIG_LINE, "%s%c%s > %s 2>&1",
root, FILE_SEP, START_SCRIPT, statfile);
alter_startup_line(startup_line);
error = system(startup_line);
@@ -244,7 +244,7 @@ ds_bring_up_server_install(int verbose, char *root, char *errorlog)
}
if (verbose) {
char str[100];
- sprintf(str, "Had to retry %d times", tries);
+ PR_snprintf(str, sizeof(str), "Had to retry %d times", tries);
ds_send_status(str);
}
}
@@ -351,7 +351,7 @@ IsService()
HKEY hServerKey;
DWORD dwType, ValueLength, Result;
- sprintf(ServerKey,"%s\\%s\0", COMPANY_KEY, PRODUCT_KEY);
+ PR_snprintf(ServerKey,sizeof(ServerKey), "%s\\%s", COMPANY_KEY, PRODUCT_KEY);
Result = RegOpenKey(HKEY_LOCAL_MACHINE, ServerKey, &hServerKey);
if (Result != ERROR_SUCCESS) {
@@ -384,7 +384,7 @@ IsAdminService()
HKEY hAdminKey;
DWORD dwType, ValueLength, Result;
- sprintf(AdminKey,"%s\\%s\0", COMPANY_KEY, ADMIN_REGISTRY_ROOT_KEY);
+ PR_snprintf(AdminKey,sizeof(AdminKey), "%s\\%s", COMPANY_KEY, ADMIN_REGISTRY_ROOT_KEY);
Result = RegOpenKey(HKEY_LOCAL_MACHINE, AdminKey, &hAdminKey);
if (Result != ERROR_SUCCESS) {
@@ -421,7 +421,7 @@ StartServer()
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
))) {
- sprintf(ErrorString,
+ PR_snprintf(ErrorString, sizeof(ErrorString),
"Error: Could not open the ServiceControlManager:%d "
"Please restart the server %s from the Services Program Item "
"in the Control Panel", ds_get_server_name(), GetLastError());
@@ -449,7 +449,7 @@ StopandRestartServer()
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
))) {
- sprintf(ErrorString,
+ PR_snprintf(ErrorString, sizeof(ErrorString),
"Error: Could not restart server."
"Please restart the server %s from the Services Program Item "
"in the Control Panel", ds_get_server_name());
@@ -483,7 +483,7 @@ StopServer()
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
))) {
- sprintf(ErrorString,
+ PR_snprintf(ErrorString, sizeof(ErrorString),
"Error: Could not open the ServiceControlManager:%d "
"Please restart the server %s from the Services Program Item "
"in the Control Panel", ds_get_server_name(), GetLastError());
@@ -507,14 +507,14 @@ StartNetscapeProgram()
PROCESS_INFORMATION piProcInfo;
FILE *CmdFile;
- ZeroMemory(line, BIG_LINE);
+ ZeroMemory(line, sizeof(line));
- sprintf(line, "%s\\startsrv.bat", tmp);
+ PR_snprintf(line, BIG_LINE, "%s\\startsrv.bat", tmp);
CmdFile = fopen(line, "r");
if (!CmdFile)
{
- sprintf(ErrorString, "Error:Tried to start Netscape server %s "
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start Netscape server %s "
": Could not open the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
ds_get_server_name(), line, errno);
@@ -522,10 +522,10 @@ StartNetscapeProgram()
return(DS_SERVER_DOWN);
}
- ZeroMemory(cmd, BIG_LINE);
+ ZeroMemory(cmd, sizeof(cmd));
if (!fread(cmd, 1, BIG_LINE, CmdFile))
{
- sprintf(ErrorString, "Error:Tried to start Netscape server %s "
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start Netscape server %s "
": Could not read the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
ds_get_server_name(), line, errno);
@@ -542,7 +542,7 @@ StartNetscapeProgram()
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE,
0, NULL, NULL, &siStartInfo, &piProcInfo))
{
- sprintf(ErrorString, "Error:Tried to start Netscape server %s "
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Error:Tried to start Netscape server %s "
": Could not start up the startup script %s :Error %d. Please "
"run startsrv.bat from the server's root directory.",
ds_get_server_name(), line, GetLastError());
@@ -565,7 +565,7 @@ StopNetscapeProgram()
hEvent = CreateEvent(NULL, TRUE, FALSE, servid);
if(!SetEvent(hEvent))
{
- sprintf(ErrorString, "Tried to stop existing Netscape server %s"
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Tried to stop existing Netscape server %s"
": Could not signal it to stop :Error %d",
servid, GetLastError());
ds_send_error(ErrorString, 0);
@@ -588,7 +588,7 @@ StopNetscapeService()
if (schService == NULL)
{
- PR_snprintf(ErrorString, 512, "Tried to open Netscape service"
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Tried to open Netscape service"
" %s: Error %d (%s). Please"
" stop the server from the Services Item in the Control Panel",
serviceName, GetLastError(), ds_system_errmsg());
@@ -613,7 +613,7 @@ StopNetscapeService()
}
else if (Error != ERROR_SERVICE_NOT_ACTIVE)
{
- PR_snprintf(ErrorString, 512, "Tried to stop Netscape service"
+ PR_snprintf(ErrorString, sizeof(ErrorString), "Tried to stop Netscape service"
" %s: Error %d (%s)."
" Please stop the server from the Services Item in the"
" Control Panel", serviceName, Error, ds_system_errmsg());
@@ -638,7 +638,7 @@ StartNetscapeService()
if (schService == NULL)
{
CloseServiceHandle(schService);
- sprintf(ErrorString, "Tried to start"
+ PR_snprintf(ErrorString, sizeof(ErrorString),"Tried to start"
" the Netscape service %s: Error %d. Please"
" start the server from the Services Item in the Control Panel",
serviceName, GetLastError());
@@ -649,7 +649,7 @@ StartNetscapeService()
if (!StartService(schService, 0, NULL))
{
CloseServiceHandle(schService);
- sprintf(ErrorString, "StartService:Could not start "
+ PR_snprintf(ErrorString, sizeof(ErrorString), "StartService:Could not start "
"the Directory service %s: Error %d. Please restart the server "
"from the Services Item in the Control Panel",
serviceName, GetLastError());
@@ -671,8 +671,7 @@ WaitForServertoStop()
RETRY:
- newServiceName = (PCHAR)malloc(strlen(serviceName) + 5);
- sprintf(newServiceName, "NS_%s\0", serviceName);
+ newServiceName = PR_smprintf("NS_%s", serviceName);
hServDoneSemaphore = CreateSemaphore(
NULL, // security attributes
@@ -680,7 +679,7 @@ RETRY:
1, // maximum count for semaphore
newServiceName);
- free(newServiceName);
+ PR_smprintf_free(newServiceName);
if ( hServDoneSemaphore == NULL) {
result = GetLastError();
diff --git a/ldap/admin/lib/dsalib_util.c b/ldap/admin/lib/dsalib_util.c
index 6c6f336c..0b92acf7 100644
--- a/ldap/admin/lib/dsalib_util.c
+++ b/ldap/admin/lib/dsalib_util.c
@@ -23,7 +23,9 @@
#include <string.h>
#include <sys/stat.h>
#include <ctype.h>
-#include <nspr.h>
+
+#include "nspr.h"
+#include "plstr.h"
#define COPY_BUFFER_SIZE 4096
/* This is the separator string to use when outputting key/value pairs
@@ -98,7 +100,7 @@ ds_mkdir_p(char *dir, int mode)
if(t) *t = '\0';
if(stat(dir, &fi) == -1) {
if(ds_mkdir(dir, mode) == -1) {
- sprintf(errmsg, "mkdir %s failed (%s)", dir, ds_system_errmsg());
+ PR_snprintf(errmsg, sizeof(errmsg), "mkdir %s failed (%s)", dir, ds_system_errmsg());
return errmsg;
}
}
@@ -164,8 +166,8 @@ ds_get_file_list( char *dir )
if( ( ret = malloc( sizeof( char * ) ) ) == NULL )
return NULL;
- strcpy(szWildcardFileSpec, dir);
- strcat(szWildcardFileSpec, "/*");
+ PL_strncpyz(szWildcardFileSpec, dir, sizeof(szWildcardFileSpec));
+ PL_strcatn(szWildcardFileSpec, sizeof(szWildcardFileSpec), "/*");
hFile = _findfirst( szWildcardFileSpec, &fileinfo);
if( hFile == -1 )
@@ -226,14 +228,14 @@ ds_cp_file(char *sfile, char *dfile, int mode)
umask(022);
if( (sfd = open(sfile, O_RDONLY)) == -1) {
- sprintf(error, "Can't open file %s for reading.", sfile);
+ PR_snprintf(error, sizeof(error), "Can't open file %s for reading.", sfile);
ds_send_error(error, 1);
return(0);
}
fstat(sfd, &fi);
if (!(S_ISREG(fi.st_mode))) {
- sprintf(error, "File %s is not a regular file.", sfile);
+ PR_snprintf(error, sizeof(error), "File %s is not a regular file.", sfile);
ds_send_error(error, 1);
close(sfd);
return(0);
@@ -241,7 +243,7 @@ ds_cp_file(char *sfile, char *dfile, int mode)
len = fi.st_size;
if( (dfd = open(dfile, O_RDWR | O_CREAT | O_TRUNC, mode)) == -1) {
- sprintf(error, "can't write to file %s", dfile);
+ PR_snprintf(error, sizeof(error), "can't write to file %s", dfile);
ds_send_error(error, 1);
close(sfd);
return(0);
@@ -250,7 +252,7 @@ ds_cp_file(char *sfile, char *dfile, int mode)
read_len = len>COPY_BUFFER_SIZE?COPY_BUFFER_SIZE:len;
if ( (read_len = read(sfd, copy_buffer, read_len)) == -1) {
- sprintf(error, "Error reading file %s for copy.", sfile);
+ PR_snprintf(error, sizeof(error), "Error reading file %s for copy.", sfile);
ds_send_error(error, 1);
close(sfd);
close(dfd);
@@ -258,7 +260,7 @@ ds_cp_file(char *sfile, char *dfile, int mode)
}
if ( write(dfd, copy_buffer, read_len) != read_len) {
- sprintf(error, "Error writing file %s for copy.", dfile);
+ PR_snprintf(error, sizeof(error), "Error writing file %s for copy.", dfile);
ds_send_error(error, 1);
close(sfd);
close(dfd);
@@ -279,8 +281,6 @@ ds_get_tmp_dir()
{
static char tmpdir[] = "/tmp";
static char tmp[256] = {0};
- unsigned ilen;
- char pch;
char* instanceDir = ds_get_install_root();
if(instanceDir == NULL)
@@ -298,7 +298,7 @@ ds_get_tmp_dir()
#endif
}
- sprintf(tmp,"%s/tmp",instanceDir);
+ PR_snprintf(tmp, sizeof(tmp), "%s/tmp",instanceDir);
#if defined( XP_WIN32 )
for(ilen=0;ilen < strlen(tmp); ilen++)
@@ -637,7 +637,7 @@ alter_startup_line(char *startup_line)
#if (defined Linux && !defined LINUX2_4)
char temp_startup_line[BIG_LINE+40];
- sprintf(temp_startup_line, "/bin/sh -c \"%s\"", startup_line);
+ PR_snprintf(temp_startup_line, sizeof(temp_startup_line), "/bin/sh -c \"%s\"", startup_line);
strcpy(startup_line, temp_startup_line);
#else
/* do nothing */
@@ -654,7 +654,7 @@ ds_send_error(char *errstr, int print_errno)
fflush(stdout);
- if (logfp = get_logfp()) {
+ if ((logfp = get_logfp())) {
fprintf(logfp, "error%s%s\n", SEPARATOR, errstr);
if (print_errno && errno)
fprintf(logfp, "system_errno%s%d\n", SEPARATOR, errno);
@@ -670,7 +670,7 @@ ds_send_status(char *str)
fprintf(stdout, "[%s]: %s\n", ds_get_server_name(), str);
fflush(stdout);
- if (logfp = get_logfp()) {
+ if ((logfp = get_logfp())) {
fprintf(logfp, "[%s]: %s\n", ds_get_server_name(), str);
fclose(logfp);
}
@@ -689,11 +689,11 @@ report_error(int type, char *msg, char *details, int doexit)
if (msg)
{
- strcat(error, msg);
- strcat(error, SEPARATOR);
+ PL_strcatn(error, BIG_LINE*4, msg);
+ PL_strcatn(error, BIG_LINE*4, SEPARATOR);
}
if (details)
- strcat(error, details);
+ PL_strcatn(error, BIG_LINE*4, details);
ds_send_error(error, 1);
}
@@ -721,7 +721,7 @@ ds_show_message(const char *message)
printf("%s\n", message);
fflush(stdout);
- if (logfp = get_logfp()) {
+ if ((logfp = get_logfp())) {
fprintf(logfp, "%s\n", message);
fclose(logfp);
}
@@ -735,7 +735,7 @@ ds_show_key_value(char *key, char *value)
FILE *logfp;
printf("%s%s%s\n", key, SEPARATOR, value);
- if (logfp = get_logfp()) {
+ if ((logfp = get_logfp())) {
fprintf(logfp, "%s%s%s\n", key, SEPARATOR, value);
fclose(logfp);
}
@@ -813,7 +813,7 @@ ds_system_errmsg(void)
msglen = strlen(lmsg);
min = msglen > BUFSIZ ? BUFSIZ : msglen;
- strncpy(static_error, lmsg, min);
+ strncpy(static_error, lmsg, min-1);
static_error[min-1] = 0;
}
@@ -863,7 +863,6 @@ rm_db_dirs(char *fullpath, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
{
FILE *fp = fopen(fullpath, "r");
char buf[2][MAXPATHLEN];
- char rmbuf[MAXPATHLEN];
char *bufp, *nextbufp;
char *retp;
int readit = 0;
@@ -969,7 +968,6 @@ static int
internal_rm_rf(const char *path, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
{
struct PRFileInfo prfi;
- char *fullpath = NULL;
int retval = 0;
if (PR_GetFileInfo(path, &prfi) != PR_SUCCESS) {
@@ -990,7 +988,7 @@ internal_rm_rf(const char *path, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
return 0;
}
- while (dirent = PR_ReadDir(dir, PR_SKIP_BOTH)) {
+ while ((dirent = PR_ReadDir(dir, PR_SKIP_BOTH))) {
char *fullpath = PR_smprintf("%s%c%s", path, FILE_PATHSEP, dirent->name);
if (PR_GetFileInfo(fullpath, &prfi) != PR_SUCCESS) {
if (!ds_rm_rf_err_func(fullpath, "reading file", arg)) {
@@ -1053,7 +1051,6 @@ default_err_func(const char *path, const char *op, void *arg)
DS_EXPORT_SYMBOL int
ds_rm_rf(const char *dir, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
{
- int retval = 0;
struct PRFileInfo prfi;
if (!dir) {