Author: rmeggins
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/tools
In directory
cvs-int.fedora.redhat.com:/tmp/cvs-serv14112/ldapserver/ldap/servers/slapd/tools
Modified Files:
pwenc.c
Log Message:
Resolves: bug 237356
Description: Move DS Admin Code into Admin Server - ldif templates, pwdhash
Reviewed by: nhosoi (Thanks!)
Fix Description: These changes are primarily to allow the admin server setup to run
completely in perl with no more setuputil code.
1) Added LDIF templates for DS config. template-dse.ldif is the core minimal directory
server configuration. Values can be replaced with parameters in the same style as used
with register_server.pl - %token%. For the plugin entries, the plugin shared library name
is now just a name. There is no more full path. The code in dynalib.c handles this case
by using the compiled in PLUGINDIR. The NSPR function PR_GetLibraryName knows the correct
shared lib suffix for the platform. All of this allows us to do 2).
2) Added ability to run pwdhash with no server configuration. If no configuration is
given, it uses the template-dse.ldif above. And instead of having to worry about where
the plugins are installed and the shared lib suffix, it just depends on the above changes.
This allows us to generate password hashes during setup before the directory server
instance is created, and also to keep clear text password usage to a minimum.
3) Added defaultuser and defaultgroup.
4) Added support for continuation lines in Inf files.
5) All user visible messages during setup should be localizable
Platforms tested: RHEL4
Flag Day: Yes, autotool file changes.
Doc impact: Yes, along with the previous fixes for this bug.
Index: pwenc.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/tools/pwenc.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pwenc.c 10 Nov 2006 23:45:51 -0000 1.8
+++ pwenc.c 19 Jun 2007 18:24:58 -0000 1.9
@@ -80,7 +80,7 @@
struct pw_scheme *pwdhashscheme;
int heflag = 0;
-static int slapd_config(const char *configdir);
+static int slapd_config(const char *configdir, const char *configfile);
static int entry_has_attr_and_value(Slapi_Entry *e, const char *attrname, char *value);
static void
@@ -124,6 +124,41 @@
}
+static slapdFrontendConfig_t *
+init_config(char *configdir)
+{
+ char *abs_configdir = NULL;
+ char *configfile = NULL;
+ char errorbuf[SLAPI_DSE_RETURNTEXT_SIZE];
+ slapdFrontendConfig_t *slapdFrontendConfig = NULL;
+
+ if (configdir == NULL) { /* use default */
+ configdir = TEMPLATEDIR;
+ configfile = "template-dse.ldif";
+ }
+ /* kexcoff: quite the same as slapd_bootstrap_config */
+ FrontendConfig_init();
+
+ abs_configdir = rel2abspath( configdir );
+ if ( config_set_configdir( "configdir (-D)", abs_configdir,
+ errorbuf, 1) != LDAP_SUCCESS ) {
+ fprintf( stderr, "%s\n", errorbuf );
+ return( NULL );
+ }
+ slapi_ch_free((void **)&abs_configdir);
+
+ slapdFrontendConfig = getFrontendConfig();
+ if (0 == slapd_config(slapdFrontendConfig->configdir, configfile)) {
+ fprintf(stderr,
+ "The configuration files in directory %s could not be read or were
not found. Please refer to the error log or output for more information.\n",
+ slapdFrontendConfig->configdir);
+ return(NULL);
+ }
+
+ return slapdFrontendConfig;
+}
+
+
int
main( argc, argv )
int argc;
@@ -159,31 +194,22 @@
while (( i = getopt( argc, argv, opts )) != EOF ) {
switch ( i ) {
case 'D':
- /* kexcoff: quite the same as slapd_bootstrap_config */
- FrontendConfig_init();
-
- configdir = rel2abspath( optarg );
- if ( config_set_configdir( "configdir (-D)", configdir,
- errorbuf, 1) != LDAP_SUCCESS ) {
- fprintf( stderr, "%s\n", errorbuf );
- return( 1 );
+ if (slapdFrontendConfig) {
+ fprintf(stderr, "The -D configdir argument must be given only once, and must be
the first argument given\n");
+ usage(name);
+ return 1;
}
- slapi_ch_free((void **)&configdir);
-
-
- slapdFrontendConfig = getFrontendConfig();
- if (0 == slapd_config(slapdFrontendConfig->configdir)) {
- fprintf(stderr,
- "The configuration files in directory %s could not be read or were not found.
Please refer to the error log or output for more information.\n",
- slapdFrontendConfig->configdir);
+ if (!(slapdFrontendConfig = init_config(optarg))) {
return(1);
}
break;
case 's': /* set hash scheme */
if (!slapdFrontendConfig) {
- usage( name );
- return( 1 );
+ if (!(slapdFrontendConfig = init_config(NULL))) {
+ usage( name );
+ return(1);
+ }
}
if (( pwsp = pw_name2scheme( optarg )) == NULL ) {
fprintf( stderr, "%s: unknown hash scheme \"%s\"\n", name,
@@ -194,19 +220,23 @@
case 'c': /* compare encoded password to password */
if (!slapdFrontendConfig) {
- usage( name );
- return( 1 );
+ if (!(slapdFrontendConfig = init_config(NULL))) {
+ usage( name );
+ return(1);
+ }
}
cpwd = optarg;
break;
case 'H': /* password(s) is(are) hex-encoded */
if (!slapdFrontendConfig) {
- usage( name );
- return( 1 );
+ if (!(slapdFrontendConfig = init_config(NULL))) {
+ usage( name );
+ return(1);
}
- heflag = 1;
- break;
+ }
+ heflag = 1;
+ break;
default:
usage( name );
@@ -214,8 +244,10 @@
}
if (!slapdFrontendConfig) {
- usage( name );
- return( 1 );
+ if (!(slapdFrontendConfig = init_config(NULL))) {
+ usage( name );
+ return(1);
+ }
}
if ( cpwd != NULL ) {
@@ -272,7 +304,7 @@
but it only loads password storage scheme plugins
*/
static int
-slapd_config(const char *configdir)
+slapd_config(const char *configdir, const char *givenconfigfile)
{
char configfile[MAXPATHLEN+1];
PRFileInfo prfinfo;
@@ -284,7 +316,11 @@
char *lastp = 0;
char *entrystr = 0;
- PR_snprintf(configfile, sizeof(configfile), "%s/%s", configdir,
CONFIG_FILENAME);
+ if (!givenconfigfile) {
+ givenconfigfile = CONFIG_FILENAME;
+ }
+
+ PR_snprintf(configfile, sizeof(configfile), "%s/%s", configdir,
givenconfigfile);
if ( (rc = PR_GetFileInfo( configfile, &prfinfo )) != PR_SUCCESS )
{
fprintf(stderr,