summaryrefslogtreecommitdiffstats
path: root/ldap/servers/slapd/tools/pwenc.c
diff options
context:
space:
mode:
authorRich Megginson <rmeggins@redhat.com>2007-06-19 18:24:58 +0000
committerRich Megginson <rmeggins@redhat.com>2007-06-19 18:24:58 +0000
commit72da2df3bae21741217e3175e020cdc3b83ac172 (patch)
tree4e12d324257ca8cfe4ba39ceb4337adfe0df588e /ldap/servers/slapd/tools/pwenc.c
parent0046d389d23bd217e3109949064c33de07dbc017 (diff)
downloadds-72da2df3bae21741217e3175e020cdc3b83ac172.tar.gz
ds-72da2df3bae21741217e3175e020cdc3b83ac172.tar.xz
ds-72da2df3bae21741217e3175e020cdc3b83ac172.zip
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.
Diffstat (limited to 'ldap/servers/slapd/tools/pwenc.c')
-rw-r--r--ldap/servers/slapd/tools/pwenc.c94
1 files changed, 65 insertions, 29 deletions
diff --git a/ldap/servers/slapd/tools/pwenc.c b/ldap/servers/slapd/tools/pwenc.c
index c833bb2e..16aa4fc4 100644
--- a/ldap/servers/slapd/tools/pwenc.c
+++ b/ldap/servers/slapd/tools/pwenc.c
@@ -80,7 +80,7 @@ FILE *access_logfp;
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 @@ decode( char *orig )
}
+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 @@ main( argc, argv )
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 @@ main( argc, argv )
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 @@ main( argc, argv )
}
if (!slapdFrontendConfig) {
- usage( name );
- return( 1 );
+ if (!(slapdFrontendConfig = init_config(NULL))) {
+ usage( name );
+ return(1);
+ }
}
if ( cpwd != NULL ) {
@@ -272,7 +304,7 @@ main( argc, argv )
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 @@ slapd_config(const char *configdir)
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,