[Fedora-directory-commits] adminserver configure.ac, 1.24.2.1, 1.24.2.2 aclocal.m4, 1.38.2.1, 1.38.2.2 configure, 1.42.2.1, 1.42.2.2 missing, 1.28.2.1, 1.28.2.2 install-sh, 1.28.2.1, 1.28.2.2 depcomp, 1.28.2.1, 1.28.2.2 config.sub, 1.28.2.1, 1.28.2.2 config.guess, 1.28.2.1, 1.28.2.2 compile, 1.27.2.1, 1.27.2.2 Makefile.in, 1.45.2.1, 1.45.2.2
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/adminserver
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv8064
Modified Files:
Tag: Directory_Server_8_0_Branch
configure.ac aclocal.m4 configure missing install-sh depcomp
config.sub config.guess compile Makefile.in
Log Message:
bump rev to 1.1.4
Index: configure.ac
===================================================================
RCS file: /cvs/dirsec/adminserver/configure.ac,v
retrieving revision 1.24.2.1
retrieving revision 1.24.2.2
diff -u -r1.24.2.1 -r1.24.2.2
--- configure.ac 15 Apr 2008 16:44:34 -0000 1.24.2.1
+++ configure.ac 15 Apr 2008 16:47:30 -0000 1.24.2.2
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([dirsrv-admin], [1.1.3], [http://bugzilla.redhat.com/])
+AC_INIT([dirsrv-admin], [1.1.4], [http://bugzilla.redhat.com/])
AC_CONFIG_SRCDIR([admserv/cgi-src40/viewlog.c])
AM_INIT_AUTOMAKE([1.9 foreign subdir-objects])
AM_MAINTAINER_MODE
Index: configure
===================================================================
RCS file: /cvs/dirsec/adminserver/configure,v
retrieving revision 1.42.2.1
retrieving revision 1.42.2.2
diff -u -r1.42.2.1 -r1.42.2.2
--- configure 15 Apr 2008 16:44:34 -0000 1.42.2.1
+++ configure 15 Apr 2008 16:47:30 -0000 1.42.2.2
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for dirsrv-admin 1.1.3.
+# Generated by GNU Autoconf 2.59 for dirsrv-admin 1.1.4.
#
# Report bugs to <http://bugzilla.redhat.com/>.
#
@@ -423,8 +423,8 @@
# Identity of this package.
PACKAGE_NAME='dirsrv-admin'
PACKAGE_TARNAME='dirsrv-admin'
-PACKAGE_VERSION='1.1.3'
-PACKAGE_STRING='dirsrv-admin 1.1.3'
+PACKAGE_VERSION='1.1.4'
+PACKAGE_STRING='dirsrv-admin 1.1.4'
PACKAGE_BUGREPORT='http://bugzilla.redhat.com/'
ac_unique_file="admserv/cgi-src40/viewlog.c"
@@ -957,7 +957,7 @@
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures dirsrv-admin 1.1.3 to adapt to many kinds of systems.
+\`configure' configures dirsrv-admin 1.1.4 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1023,7 +1023,7 @@
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of dirsrv-admin 1.1.3:";;
+ short | recursive ) echo "Configuration of dirsrv-admin 1.1.4:";;
esac
cat <<\_ACEOF
@@ -1202,7 +1202,7 @@
test -n "$ac_init_help" && exit 0
if $ac_init_version; then
cat <<\_ACEOF
-dirsrv-admin configure 1.1.3
+dirsrv-admin configure 1.1.4
generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc.
@@ -1216,7 +1216,7 @@
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by dirsrv-admin $as_me 1.1.3, which was
+It was created by dirsrv-admin $as_me 1.1.4, which was
generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@
@@ -1860,7 +1860,7 @@
# Define the identity of the package.
PACKAGE='dirsrv-admin'
- VERSION='1.1.3'
+ VERSION='1.1.4'
cat >>confdefs.h <<_ACEOF
@@ -25613,7 +25613,7 @@
} >&5
cat >&5 <<_CSEOF
-This file was extended by dirsrv-admin $as_me 1.1.3, which was
+This file was extended by dirsrv-admin $as_me 1.1.4, which was
generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -25676,7 +25676,7 @@
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-dirsrv-admin config.status 1.1.3
+dirsrv-admin config.status 1.1.4
configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
16 years, 1 month
[Fedora-directory-commits] adminserver configure, 1.42, 1.42.2.1 configure.ac, 1.24, 1.24.2.1 aclocal.m4, 1.38, 1.38.2.1 missing, 1.28, 1.28.2.1 install-sh, 1.28, 1.28.2.1 depcomp, 1.28, 1.28.2.1 compile, 1.27, 1.27.2.1 Makefile.in, 1.45, 1.45.2.1 config.sub, 1.28, 1.28.2.1 config.guess, 1.28, 1.28.2.1
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/adminserver
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv7894/adminserver
Modified Files:
Tag: Directory_Server_8_0_Branch
configure configure.ac aclocal.m4 missing install-sh depcomp
compile Makefile.in config.sub config.guess
Log Message:
Resolves: bugs 437301 and 437320
Description: Directory Server: shell command injection in CGI replication monitor
Directory Server: unrestricted access to CGI scripts
Fix Description: remove ScriptAlias for bin/admin/admin/bin - do not use that directory for CGI URIs - use only protected URIs for CGIs requiring authentication
Remove most CGI parameters from repl-monitor-cgi.pl - user must supply replmon.conf in the admin server config directory instead of passing in this pathname - repl-monitor-cgi.pl does not use system to call repl-monitor.pl, it "includes" that script (using perl import).
Platforms tested: all supported platforms
Flag Day: no
Doc impact: release notes are available
Index: configure
===================================================================
RCS file: /cvs/dirsec/adminserver/configure,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -u -r1.42 -r1.42.2.1
--- configure 18 Dec 2007 19:55:22 -0000 1.42
+++ configure 15 Apr 2008 16:44:34 -0000 1.42.2.1
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for dirsrv-admin 1.1.1.
+# Generated by GNU Autoconf 2.59 for dirsrv-admin 1.1.3.
#
# Report bugs to <http://bugzilla.redhat.com/>.
#
@@ -423,8 +423,8 @@
# Identity of this package.
PACKAGE_NAME='dirsrv-admin'
PACKAGE_TARNAME='dirsrv-admin'
-PACKAGE_VERSION='1.1.1'
-PACKAGE_STRING='dirsrv-admin 1.1.1'
+PACKAGE_VERSION='1.1.3'
+PACKAGE_STRING='dirsrv-admin 1.1.3'
PACKAGE_BUGREPORT='http://bugzilla.redhat.com/'
ac_unique_file="admserv/cgi-src40/viewlog.c"
@@ -957,7 +957,7 @@
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures dirsrv-admin 1.1.1 to adapt to many kinds of systems.
+\`configure' configures dirsrv-admin 1.1.3 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1023,7 +1023,7 @@
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of dirsrv-admin 1.1.1:";;
+ short | recursive ) echo "Configuration of dirsrv-admin 1.1.3:";;
esac
cat <<\_ACEOF
@@ -1202,7 +1202,7 @@
test -n "$ac_init_help" && exit 0
if $ac_init_version; then
cat <<\_ACEOF
-dirsrv-admin configure 1.1.1
+dirsrv-admin configure 1.1.3
generated by GNU Autoconf 2.59
Copyright (C) 2003 Free Software Foundation, Inc.
@@ -1216,7 +1216,7 @@
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by dirsrv-admin $as_me 1.1.1, which was
+It was created by dirsrv-admin $as_me 1.1.3, which was
generated by GNU Autoconf 2.59. Invocation command line was
$ $0 $@
@@ -1860,7 +1860,7 @@
# Define the identity of the package.
PACKAGE='dirsrv-admin'
- VERSION='1.1.1'
+ VERSION='1.1.3'
cat >>confdefs.h <<_ACEOF
@@ -25613,7 +25613,7 @@
} >&5
cat >&5 <<_CSEOF
-This file was extended by dirsrv-admin $as_me 1.1.1, which was
+This file was extended by dirsrv-admin $as_me 1.1.3, which was
generated by GNU Autoconf 2.59. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -25676,7 +25676,7 @@
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-dirsrv-admin config.status 1.1.1
+dirsrv-admin config.status 1.1.3
configured by $0, generated by GNU Autoconf 2.59,
with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
Index: configure.ac
===================================================================
RCS file: /cvs/dirsec/adminserver/configure.ac,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -u -r1.24 -r1.24.2.1
--- configure.ac 18 Dec 2007 19:55:22 -0000 1.24
+++ configure.ac 15 Apr 2008 16:44:34 -0000 1.24.2.1
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([dirsrv-admin], [1.1.1], [http://bugzilla.redhat.com/])
+AC_INIT([dirsrv-admin], [1.1.3], [http://bugzilla.redhat.com/])
AC_CONFIG_SRCDIR([admserv/cgi-src40/viewlog.c])
AM_INIT_AUTOMAKE([1.9 foreign subdir-objects])
AM_MAINTAINER_MODE
16 years, 1 month
[Fedora-directory-commits] adminserver/admserv/cgi-src40 repl-monitor-cgi.pl.in, 1.1, 1.1.2.1
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/adminserver/admserv/cgi-src40
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv7894/adminserver/admserv/cgi-src40
Modified Files:
Tag: Directory_Server_8_0_Branch
repl-monitor-cgi.pl.in
Log Message:
Resolves: bugs 437301 and 437320
Description: Directory Server: shell command injection in CGI replication monitor
Directory Server: unrestricted access to CGI scripts
Fix Description: remove ScriptAlias for bin/admin/admin/bin - do not use that directory for CGI URIs - use only protected URIs for CGIs requiring authentication
Remove most CGI parameters from repl-monitor-cgi.pl - user must supply replmon.conf in the admin server config directory instead of passing in this pathname - repl-monitor-cgi.pl does not use system to call repl-monitor.pl, it "includes" that script (using perl import).
Platforms tested: all supported platforms
Flag Day: no
Doc impact: release notes are available
Index: repl-monitor-cgi.pl.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/cgi-src40/repl-monitor-cgi.pl.in,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- repl-monitor-cgi.pl.in 5 Sep 2007 16:45:59 -0000 1.1
+++ repl-monitor-cgi.pl.in 15 Apr 2008 16:44:35 -0000 1.1.2.1
@@ -42,22 +42,25 @@
my $query = CGI->new;
-$params = "";
-$params .= " -h " . $query->url_param('servhost') if $query->url_param('servhost');
-$params .= " -p " . $query->url_param('servport') if $query->url_param('servport');
-$params .= " -f " . $query->url_param('configfile') if $query->url_param('configfile');
-$params .= " -t " . $query->url_param('refreshinterval') if $query->url_param('refreshinterval');
-if ($query->url_param('admurl')) {
- $admurl = $query->url_param('admurl');
- if ( $ENV{'QUERY_STRING'} ) {
- $admurl .= "?$ENV{'QUERY_STRING'}";
- }
- elsif ( $ENV{'CONTENT_LENGTH'} ) {
- $admurl .= "?$CGI::CONTENT";
- }
- $params .= " -u \"$admurl\"";
+@ARGV = (); # clear it out
+my $configfile;
+if ($ENV{DS_CONFIG_DIR} and -d $ENV{DS_CONFIG_DIR}) {
+ $configfile = "$ENV{DS_CONFIG_DIR}/@instancename(a)/replmon.conf";
+} elsif ("@instconfigdir@" and -d "@instconfigdir@") {
+ $configfile = "@instconfigdir(a)/replmon.conf";
}
+push @ARGV, '-f', $configfile;
+
+my $refreshinterval = $query->url_param('refreshinterval') ? int($query->url_param('refreshinterval')) : "300";
+push @ARGV, '-t', $refreshinterval;
+
+my $admurl = "http://";
+if ($ENV{HTTPS} and (lc($ENV{HTTPS}) eq "on")) {
+ $admurl = "https://";
+}
+$admurl .= $ENV{HTTP_HOST} . $ENV{SCRIPT_NAME} . "?refreshinterval=$refreshinterval";
+push @ARGV, '-u', $admurl;
+
# Now the real work
-$replmon = "@bindir(a)/repl-monitor.pl";
-system("$replmon $params");
+require "@bindir(a)/repl-monitor.pl";
16 years, 1 month
[Fedora-directory-commits] adminserver/admserv/cfgstuff admserv.conf.in, 1.10, 1.10.2.1
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/adminserver/admserv/cfgstuff
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv7894/adminserver/admserv/cfgstuff
Modified Files:
Tag: Directory_Server_8_0_Branch
admserv.conf.in
Log Message:
Resolves: bugs 437301 and 437320
Description: Directory Server: shell command injection in CGI replication monitor
Directory Server: unrestricted access to CGI scripts
Fix Description: remove ScriptAlias for bin/admin/admin/bin - do not use that directory for CGI URIs - use only protected URIs for CGIs requiring authentication
Remove most CGI parameters from repl-monitor-cgi.pl - user must supply replmon.conf in the admin server config directory instead of passing in this pathname - repl-monitor-cgi.pl does not use system to call repl-monitor.pl, it "includes" that script (using perl import).
Platforms tested: all supported platforms
Flag Day: no
Doc impact: release notes are available
Index: admserv.conf.in
===================================================================
RCS file: /cvs/dirsec/adminserver/admserv/cfgstuff/admserv.conf.in,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -r1.10 -r1.10.2.1
--- admserv.conf.in 7 Dec 2007 17:43:50 -0000 1.10
+++ admserv.conf.in 15 Apr 2008 16:44:35 -0000 1.10.2.1
@@ -25,7 +25,6 @@
ADMServerVersionString "@capbrand@-Administrator/@PACKAGE_VERSION@"
ADMConfigDir "@configdir@"
-ScriptAlias /bin/admin/admin/bin/ "@cgibindir@/"
ScriptAlias /dist/ "@cgibindir@/"
ScriptAlias /manual/help/ "@cgibindir@/"
@@ -63,7 +62,7 @@
# remap / requests to the download CGI
RewriteEngine on
-RewriteRule ^/$ /bin/admin/admin/bin/download [R,L,QSA]
+RewriteRule ^/$ /dist/download [R,L,QSA]
# remap admin server icons
Alias /admin-serv/tasks/icons/ @icondir@/
16 years, 1 month
[Fedora-directory-commits] ldapserver/ldap/servers/plugins/memberof memberof.c, 1.5, 1.6
by Doctor Conrad
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/plugins/memberof
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv24511
Modified Files:
memberof.c
Log Message:
Resolves: 440474
Summary: Fixed memory leaks in memberOf plug-in.
Index: memberof.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/plugins/memberof/memberof.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- memberof.c 3 Apr 2008 16:52:46 -0000 1.5
+++ memberof.c 3 Apr 2008 23:04:11 -0000 1.6
@@ -585,7 +585,7 @@
/* get the mod set */
slapi_pblock_get(pb, SLAPI_MODIFY_MODS, &mods);
smods = slapi_mods_new();
- slapi_mods_init_passin(smods, mods);
+ slapi_mods_init_byref(smods, mods);
next_mod = slapi_mod_new();
smod = slapi_mods_get_first_smod(smods, next_mod);
@@ -653,6 +653,7 @@
}
slapi_mod_free(&next_mod);
+ slapi_mods_free(&smods);
}
slapi_log_error( SLAPI_LOG_TRACE, MEMBEROF_PLUGIN_SUBSYSTEM,
@@ -923,7 +924,7 @@
slapi_log_error( SLAPI_LOG_PLUGIN,
MEMBEROF_PLUGIN_SUBSYSTEM,
"memberof_modop_one_r: not processing memberOf "
- "operations on self entry: %s\n", this_dn_val);
+ "operations on self entry: %s\n", this_dn_val);
slapi_value_free(&to_dn_val);
slapi_value_free(&this_dn_val);
goto bail;
@@ -1009,6 +1010,7 @@
}
bail:
+ slapi_entry_free(e);
return rc;
}
@@ -1307,6 +1309,7 @@
rc = 0 == slapi_attr_value_find(
attr, slapi_value_get_berval(memberdn));
}
+ slapi_entry_free(group_e);
}
slapi_sdn_free(&sdn);
@@ -1612,6 +1615,8 @@
}
}
}
+ slapi_ch_free((void **)&pre_array);
+ slapi_ch_free((void **)&post_array);
}
return 0;
@@ -1825,6 +1830,8 @@
}
bail:
+ slapi_entry_free(group_e);
+ slapi_entry_free(opto_e);
slapi_ch_free_string(&filter_str);
slapi_log_error( SLAPI_LOG_TRACE, MEMBEROF_PLUGIN_SUBSYSTEM,
16 years, 2 months
[Fedora-directory-commits] ldapserver/ldap/servers/slapd detach.c, 1.6, 1.7 main.c, 1.23, 1.24 proto-slap.h, 1.31, 1.32
by Doctor Conrad
Author: rmeggins
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv2319/ldap/servers/slapd
Modified Files:
detach.c main.c proto-slap.h
Log Message:
Resolves: bug 439829
Bug Description: simple password auth fails using NSS 3.11.99 or later
Reviewed by: nkinder (Thanks!)
Fix Description: The new softokn in NSS 3.11.99 and later requires that
the server calls NSS_Init() after forking, but before detaching from the
controlling terminal. In fact, this was always a requirement, but the
softokn in older NSS allow it. However, it's possible that some
hardware crypto devices do not allow this and may not work with older
directory servers. The fix is to move the nss/ssl initialization so
that it can be called at the right point, or from other points in cases
where the server does not fork (e.g. db2ldif).
Platforms tested: Fedora 9 i386, RHEL5 x86_64
Flag Day: no
Doc impact: no
Index: detach.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/detach.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- detach.c 10 Nov 2006 23:45:40 -0000 1.6
+++ detach.c 3 Apr 2008 21:07:55 -0000 1.7
@@ -76,7 +76,8 @@
#endif /* USE_SYSCONF */
void
-detach()
+detach( int slapd_exemode, int importexport_encrypt,
+ int s_port, daemon_ports_t *ports_info )
{
#ifndef _WIN32
int i, sd;
@@ -108,6 +109,12 @@
break;
}
+ /* call this right after the fork, but before closing stdin */
+ if (slapd_do_all_nss_ssl_init(slapd_exemode, importexport_encrypt,
+ s_port, ports_info)) {
+ exit(1);
+ }
+
workingdir = config_get_workingdir();
if ( NULL == workingdir ) {
errorlog = config_get_errorlog();
@@ -150,7 +157,12 @@
#endif /* USE_SETSID */
g_set_detached(1);
- }
+ } else { /* not detaching - call nss/ssl init */
+ if (slapd_do_all_nss_ssl_init(slapd_exemode, importexport_encrypt,
+ s_port, ports_info)) {
+ exit(1);
+ }
+ }
(void) SIGNAL( SIGPIPE, SIG_IGN );
#endif /* _WIN32 */
Index: main.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/main.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- main.c 3 Apr 2008 16:52:46 -0000 1.23
+++ main.c 3 Apr 2008 21:07:55 -0000 1.24
@@ -901,48 +901,14 @@
}
#endif
- /*
- * Initialise NSS once for the whole slapd process, whether SSL
- * is enabled or not. We use NSS for random number generation and
- * other things even if we are not going to accept SSL connections.
- * We also need NSS for attribute encryption/decryption on import and export.
- */
- init_ssl = ( (slapd_exemode == SLAPD_EXEMODE_SLAPD) || importexport_encrypt)
- && config_get_security()
- && (0 != s_port) && (s_port <= LDAP_PORT_MAX);
- /* As of DS 6.1, always do a full initialization so that other
- * modules can assume NSS is available
- */
- if ( slapd_nss_init((slapd_exemode == SLAPD_EXEMODE_SLAPD),
- (slapd_exemode != SLAPD_EXEMODE_REFERRAL) /* have config? */ )) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: NSS Initialization Failed.\n", 0, 0, 0);
- exit (1);
- }
-
- if (slapd_exemode == SLAPD_EXEMODE_SLAPD) {
- client_auth_init();
- }
-
- if ( init_ssl && ( 0 != slapd_ssl_init())) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: SSL Initialization Failed.\n", 0, 0, 0 );
- exit( 1 );
- }
-
- if ((slapd_exemode == SLAPD_EXEMODE_SLAPD) ||
- (slapd_exemode == SLAPD_EXEMODE_REFERRAL)) {
- if ( init_ssl ) {
- PRFileDesc **sock;
- for (sock = ports_info.s_socket; sock && *sock; sock++) {
- if ( 0 != slapd_ssl_init2(sock, 0) ) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: SSL Initialization phase 2 Failed.\n", 0, 0, 0 );
- exit( 1 );
- }
- }
- }
- }
+ /* Do NSS and/or SSL init for those modes other than listening modes */
+ if ((slapd_exemode != SLAPD_EXEMODE_REFERRAL) &&
+ (slapd_exemode != SLAPD_EXEMODE_SLAPD)) {
+ if (slapd_do_all_nss_ssl_init(slapd_exemode, importexport_encrypt,
+ s_port, &ports_info)) {
+ return 1;
+ }
+ }
/*
* if we were called upon to do special database stuff, do it and be
@@ -1002,7 +968,8 @@
* Have to detach after ssl_init - the user may be prompted for the PIN
* on the terminal, so it must be open.
*/
- detach();
+ detach(slapd_exemode, importexport_encrypt,
+ s_port, &ports_info);
/*
* Now write our PID to the startup PID file.
@@ -2885,3 +2852,67 @@
}
#endif /* LDAP_DEBUG */
+/*
+ This function does all NSS and SSL related initialization
+ required during startup. We use this function rather
+ than just call this code from main because we must perform
+ all of this initialization after the fork() but before
+ we detach from the controlling terminal. This is because
+ the NSS softokn requires that NSS_Init is called after the
+ fork - this was always the case, but it is a hard error in
+ NSS 3.11.99 and later. We also have to call NSS_Init before
+ doing the detach because NSS may prompt the user for the
+ token (h/w or softokn) password on stdin. So we use this
+ function that we can call from detach() if running in
+ regular slapd exemode or from main() if running in other
+ modes (or just not detaching).
+*/
+int
+slapd_do_all_nss_ssl_init(int slapd_exemode, int importexport_encrypt,
+ int s_port, daemon_ports_t *ports_info)
+{
+ /*
+ * Initialise NSS once for the whole slapd process, whether SSL
+ * is enabled or not. We use NSS for random number generation and
+ * other things even if we are not going to accept SSL connections.
+ * We also need NSS for attribute encryption/decryption on import and export.
+ */
+ int init_ssl = ( (slapd_exemode == SLAPD_EXEMODE_SLAPD) || importexport_encrypt)
+ && config_get_security()
+ && (0 != s_port) && (s_port <= LDAP_PORT_MAX);
+ /* As of DS 6.1, always do a full initialization so that other
+ * modules can assume NSS is available
+ */
+ if ( slapd_nss_init((slapd_exemode == SLAPD_EXEMODE_SLAPD),
+ (slapd_exemode != SLAPD_EXEMODE_REFERRAL) /* have config? */ )) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: NSS Initialization Failed.\n", 0, 0, 0);
+ exit (1);
+ }
+
+ if (slapd_exemode == SLAPD_EXEMODE_SLAPD) {
+ client_auth_init();
+ }
+
+ if ( init_ssl && ( 0 != slapd_ssl_init())) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: SSL Initialization Failed.\n", 0, 0, 0 );
+ exit( 1 );
+ }
+
+ if ((slapd_exemode == SLAPD_EXEMODE_SLAPD) ||
+ (slapd_exemode == SLAPD_EXEMODE_REFERRAL)) {
+ if ( init_ssl ) {
+ PRFileDesc **sock;
+ for (sock = ports_info->s_socket; sock && *sock; sock++) {
+ if ( 0 != slapd_ssl_init2(sock, 0) ) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: SSL Initialization phase 2 Failed.\n", 0, 0, 0 );
+ exit( 1 );
+ }
+ }
+ }
+ }
+
+ return 0;
+}
Index: proto-slap.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/proto-slap.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- proto-slap.h 18 Oct 2007 01:22:29 -0000 1.31
+++ proto-slap.h 3 Apr 2008 21:07:55 -0000 1.32
@@ -483,7 +483,8 @@
/*
* detach.c
*/
-void detach( void );
+void detach( int slapd_exemode, int importexport_encrypt,
+ int s_port, daemon_ports_t *ports_info );
#ifndef _WIN32
void close_all_files( void );
#endif
@@ -879,7 +880,6 @@
int slapd_ssl_listener_is_initialized();
int sasl_io_cleanup(Connection *c);
-
/*
* security_wrappers.c
*/
@@ -1277,4 +1277,7 @@
#if ( defined( hpux ) || defined( irix ))
void signal2sigaction( int s, void *a );
#endif
+int slapd_do_all_nss_ssl_init(int slapd_exemode, int importexport_encrypt,
+ int s_port, daemon_ports_t *ports_info);
+
#endif /* _PROTO_SLAP */
16 years, 2 months
[Fedora-directory-commits] ldapserver/ldap/servers/slapd log.c, 1.21, 1.22
by Doctor Conrad
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25728/slapd
Modified Files:
log.c
Log Message:
Resolves: 440333
Summary: Fixed valrgind errors about use of unitialized values.
Index: log.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/log.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- log.c 3 Dec 2007 18:16:32 -0000 1.21
+++ log.c 3 Apr 2008 17:18:11 -0000 1.22
@@ -4007,7 +4007,7 @@
static time_t
log_reverse_convert_time(char *tbuf)
{
- struct tm tm;
+ struct tm tm = {0};
if (strchr(tbuf, '-')) { /* short format */
strptime(tbuf, "%Y%m%d-%H%M%S", &tm);
16 years, 2 months
[Fedora-directory-commits] ldapserver/ldap/servers/plugins/acl acl_ext.c, 1.7, 1.8
by Doctor Conrad
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/plugins/acl
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25728/plugins/acl
Modified Files:
acl_ext.c
Log Message:
Resolves: 440333
Summary: Fixed valrgind errors about use of unitialized values.
Index: acl_ext.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/plugins/acl/acl_ext.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- acl_ext.c 18 Oct 2007 00:08:27 -0000 1.7
+++ acl_ext.c 3 Apr 2008 17:18:10 -0000 1.8
@@ -647,7 +647,7 @@
struct acl_cblock *aclcb = NULL;
char *authType;
void *conn;
- unsigned long op_type;
+ int op_type;
if ( NULL == aclpb ) {
16 years, 2 months
[Fedora-directory-commits] ldapserver/ldap/servers/slapd/test-plugins sampletask.c, 1.2, 1.3
by Doctor Conrad
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/test-plugins
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv18174/ldap/servers/slapd/test-plugins
Modified Files:
sampletask.c
Log Message:
Resolves: 439907
Summary: Enhanced SLAPI task API and ported existing tasks to use new API.
Index: sampletask.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/test-plugins/sampletask.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sampletask.c 13 Aug 2007 15:35:35 -0000 1.2
+++ sampletask.c 3 Apr 2008 16:52:47 -0000 1.3
@@ -47,7 +47,7 @@
* objectClass: nsSlapdPlugin
* objectClass: extensibleObject
* cn: sampletask
- * nsslapd-pluginPath: <prefix>/usr/lib/<PACKAGE_NAME>/plugins/libsampletask-plugin.so
+ * nsslapd-pluginPath: libsampletask-plugin
* nsslapd-pluginInitfunc: sampletask_init
* nsslapd-pluginType: object
* nsslapd-pluginEnabled: on
@@ -58,26 +58,26 @@
*
* 4. create a config task entry in dse.ldif
* Task entry:
- * dn: cn=sample task, cn=tasks, cn=config
+ * dn: cn=sampletask, cn=tasks, cn=config
* objectClass: top
* objectClass: extensibleObject
- * cn: sample task
+ * cn: sampletask
*
* 5. to invoke the sample task, run the command line:
* $ ./ldapmodify -h <host> -p <port> -D "cn=Directory Manager" -w <pw> -a
- * dn: cn=sample task 0, cn=sample task, cn=tasks, cn=config
+ * dn: cn=sampletask 0, cn=sample task, cn=tasks, cn=config
* objectClass: top
* objectClass: extensibleObject
* cn: sample task 0
- * arg0: sample task arg0
+ * myarg: sample task myarg
*
* Result is in the errors log
- * [...] - Sample task starts (arg: sample task arg0) ...
+ * [...] - Sample task starts (arg: sample task myarg) ...
* [...] - Sample task finished.
*/
-#include "slap.h"
-#include "slapi-private.h"
+#include "slapi-plugin.h"
+#include "nspr.h"
static int task_sampletask_add(Slapi_PBlock *pb, Slapi_Entry *e,
Slapi_Entry *eAfter, int *returncode, char *returntext,
@@ -118,33 +118,32 @@
static void
task_sampletask_thread(void *arg)
{
- Slapi_PBlock *pb = (Slapi_PBlock *)arg;
- Slapi_Task *task = pb->pb_task;
- int rv;
-
- task->task_work = 1;
- task->task_progress = 0;
- task->task_state = SLAPI_TASK_RUNNING;
- slapi_task_status_changed(task);
-
- slapi_task_log_notice(task, "Sample task starts (arg: %s) ...\n",
- pb->pb_seq_val);
- LDAPDebug(LDAP_DEBUG_ANY, "Sample task starts (arg: %s) ...\n",
- pb->pb_seq_val, 0, 0);
- /* do real work */
- rv = 0;
+ Slapi_Task *task = (Slapi_Task *)arg;
+ char *myarg = NULL;
+ int i, rv = 0;
+ int total_work = 3;
+
+ /* fetch our argument from the task */
+ myarg = (char *)slapi_task_get_data(task);
+
+ /* update task state to show it's running */
+ slapi_task_begin(task, total_work);
+ slapi_task_log_notice(task, "Sample task starts (arg: %s) ...\n", myarg);
+ slapi_log_error(SLAPI_LOG_FATAL, "sampletask", "Sample task starts (arg: %s) ...\n", myarg);
+
+ /* real work would be done here */
+ for (i = 0; i < total_work; i++) {
+ PR_Sleep(10000);
+ slapi_task_inc_progress(task);
+ }
+ /* update task state to say we're finished */
slapi_task_log_notice(task, "Sample task finished.");
slapi_task_log_status(task, "Sample task finished.");
- LDAPDebug(LDAP_DEBUG_ANY, "Sample task finished.\n", 0, 0, 0);
-
- task->task_progress = 1;
- task->task_exitcode = rv;
- task->task_state = SLAPI_TASK_FINISHED;
- slapi_task_status_changed(task);
+ slapi_log_error(SLAPI_LOG_FATAL, "sampletask", "Sample task finished.\n");
- slapi_ch_free((void **)&pb->pb_seq_val);
- slapi_pblock_destroy(pb);
+ /* this will queue the destruction of the task */
+ slapi_task_finish(task, rv);
}
/* extract a single value from the entry (as a string) -- if it's not in the
@@ -163,6 +162,17 @@
return slapi_value_get_string(val);
}
+static void
+task_sampletask_destructor(Slapi_Task *task)
+{
+ if (task) {
+ char *myarg = (char *)slapi_task_get_data(task);
+ if (myarg) {
+ slapi_ch_free_string(&myarg);
+ }
+ }
+}
+
/*
* Invoked when the task instance is added by the client (step 5 of the comment)
* Get the necessary attributes from the task entry, and spawns a thread to do
@@ -178,7 +188,7 @@
int rv = SLAPI_DSE_CALLBACK_OK;
Slapi_PBlock *mypb = NULL;
Slapi_Task *task = NULL;
- const char *arg0;
+ const char *myarg;
*returncode = LDAP_SUCCESS;
if ((cn = fetch_attr(e, "cn", NULL)) == NULL) {
@@ -188,7 +198,7 @@
}
/* get arg(s) */
- if ((arg0 = fetch_attr(e, "arg0", NULL)) == NULL) {
+ if ((myarg = fetch_attr(e, "myarg", NULL)) == NULL) {
*returncode = LDAP_OBJECT_CLASS_VIOLATION;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
@@ -197,46 +207,33 @@
/* allocate new task now */
task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
- LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
- *returncode = LDAP_OPERATIONS_ERROR;
- rv = SLAPI_DSE_CALLBACK_ERROR;
- goto out;
- }
- task->task_state = SLAPI_TASK_SETUP;
- task->task_work = 1;
- task->task_progress = 0;
-
- /* create a pblock to pass the necessary info to the task thread */
- mypb = slapi_pblock_new();
- if (mypb == NULL) {
+ slapi_log_error(SLAPI_LOG_FATAL, "sampletask", "unable to allocate new task!\n");
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- mypb->pb_seq_val = slapi_ch_strdup(arg0);
- mypb->pb_task = task;
- mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
+
+ /* set a destructor that will clean up myarg for us when the task is complete */
+ slapi_task_set_destructor_fn(task, task_sampletask_destructor);
+
+ /* Stash our argument in the task for use by the task thread */
+ slapi_task_set_data(task, slapi_ch_strdup(myarg));
/* start the sample task as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_sampletask_thread,
- (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ (void *)task, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
if (thread == NULL) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "unable to create sample task thread!\n", 0, 0, 0);
+ slapi_log_error(SLAPI_LOG_FATAL, "sampletask",
+ "unable to create sample task thread!\n");
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
- slapi_ch_free((void **)&mypb->pb_seq_val);
- slapi_pblock_destroy(mypb);
- goto out;
+ slapi_task_finish(task, *returncode);
+ } else {
+ /* thread successful */
+ rv = SLAPI_DSE_CALLBACK_OK;
}
- /* thread successful -- don't free the pb, let the thread do that. */
- return SLAPI_DSE_CALLBACK_OK;
-
out:
- if (task) {
- slapi_destroy_task(task);
- }
return rv;
}
16 years, 2 months
[Fedora-directory-commits] ldapserver/ldap/servers/slapd main.c, 1.22, 1.23 slap.h, 1.30, 1.31 slapi-plugin.h, 1.19, 1.20 slapi-private.h, 1.20, 1.21 task.c, 1.14, 1.15
by Doctor Conrad
Author: nkinder
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv18174/ldap/servers/slapd
Modified Files:
main.c slap.h slapi-plugin.h slapi-private.h task.c
Log Message:
Resolves: 439907
Summary: Enhanced SLAPI task API and ported existing tasks to use new API.
Index: main.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/main.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- main.c 18 Oct 2007 00:08:34 -0000 1.22
+++ main.c 3 Apr 2008 16:52:46 -0000 1.23
@@ -2118,7 +2118,7 @@
pb.pb_ldif_files = ldif_file;
pb.pb_ldif_include = db2ldif_include;
pb.pb_ldif_exclude = db2ldif_exclude;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
#ifndef _WIN32
main_setuid(slapdFrontendConfig->localuser);
#endif
@@ -2245,7 +2245,7 @@
pb.pb_ldif_dump_uniqueid = db2ldif_dump_uniqueid;
pb.pb_ldif_encrypt = importexport_encrypt;
pb.pb_instance_name = *instp;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
if (is_slapd_running())
pb.pb_server_running = 1;
else
@@ -2431,7 +2431,7 @@
pb.pb_plugin = plugin;
pb.pb_db2index_attrs = db2index_attrs;
pb.pb_instance_name = cmd_line_instance_name;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
#ifndef _WIN32
main_setuid(slapdFrontendConfig->localuser);
#endif
@@ -2489,7 +2489,7 @@
pb.pb_plugin = backend_plugin;
pb.pb_instance_name = cmd_line_instance_name;
pb.pb_seq_val = archive_name;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
#ifndef _WIN32
main_setuid(slapdFrontendConfig->localuser);
#endif
@@ -2539,7 +2539,7 @@
pb.pb_plugin = backend_plugin;
pb.pb_instance_name = cmd_line_instance_name;
pb.pb_seq_val = archive_name;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
#ifndef _WIN32
main_setuid(slapdFrontendConfig->localuser);
#endif
@@ -2601,7 +2601,7 @@
pb.pb_plugin = backend_plugin;
pb.pb_seq_val = archive_name;
pb.pb_seq_type = upgradedb_force;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
/* borrowing import code, so need to set up the import variables */
pb.pb_ldif_generate_uniqueid = ldif2db_generate_uniqueid;
pb.pb_ldif_namespaceid = ldif2db_namespaceid;
@@ -2656,7 +2656,7 @@
pb.pb_seq_type = dbverify_verbose;
pb.pb_plugin = backend_plugin;
pb.pb_instance_name = (char *)cmd_line_instance_names;
- pb.pb_task_flags = TASK_RUNNING_FROM_COMMANDLINE;
+ pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
if ( backend_plugin->plg_dbverify != NULL ) {
return_value = (*backend_plugin->plg_dbverify)( &pb );
Index: slap.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/slap.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- slap.h 18 Oct 2007 01:22:29 -0000 1.30
+++ slap.h 3 Apr 2008 16:52:46 -0000 1.31
@@ -1283,6 +1283,27 @@
#define SLAPD_POLL_FLAGS (PR_POLL_READ)
#endif
+/******************************************************************************
+ * * Online tasks interface (to support import, export, etc)
+ * * After some cleanup, we could consider making these public.
+ * */
+struct slapi_task {
+ struct slapi_task *next;
+ char *task_dn;
+ int task_exitcode; /* for the end user */
+ int task_state; /* current state of task */
+ int task_progress; /* number between 0 and task_work */
+ int task_work; /* "units" of work to be done */
+ int task_flags; /* (see above) */
+ char *task_status; /* transient status info */
+ char *task_log; /* appended warnings, etc */
+ void *task_private; /* allow opaque data to be stashed in the task */
+ TaskCallbackFn cancel; /* task has been cancelled by user */
+ TaskCallbackFn destructor; /* task entry is being destroyed */
+ int task_refcount;
+} slapi_task;
+/* End of interface to support online tasks **********************************/
+
typedef struct slapi_pblock {
/* common */
Slapi_Backend *pb_backend;
@@ -2016,10 +2037,6 @@
#include "intrinsics.h"
-/* task flag (pb_task_flags)*/
-#define TASK_RUNNING_AS_TASK 0x0
-#define TASK_RUNNING_FROM_COMMANDLINE 0x1
-
/* printkey: import & export */
#define EXPORT_PRINTKEY 0x1
#define EXPORT_NOWRAP 0x2
Index: slapi-plugin.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/slapi-plugin.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- slapi-plugin.h 5 Oct 2007 23:31:07 -0000 1.19
+++ slapi-plugin.h 3 Apr 2008 16:52:46 -0000 1.20
@@ -149,9 +149,10 @@
typedef struct slapi_mod Slapi_Mod;
typedef struct slapi_mods Slapi_Mods;
typedef struct slapi_componentid Slapi_ComponentId;
+
/* Online tasks interface (to support import, export, etc) */
-typedef struct _slapi_task Slapi_Task;
-typedef int (*TaskCallbackFn)(Slapi_Task *task);
+typedef struct slapi_task Slapi_Task;
+typedef void (*TaskCallbackFn)(Slapi_Task *task);
/*
* The default thread stacksize for nspr21 is 64k (except on IRIX! It's 32k!).
@@ -1206,6 +1207,22 @@
typedef int (*dseCallbackFn)(Slapi_PBlock *, Slapi_Entry *, Slapi_Entry *,
int *, char*, void *);
+/*
+ * Note: DSE callback functions MUST return one of these three values:
+ *
+ * SLAPI_DSE_CALLBACK_OK -- no errors occurred; apply changes.
+ * SLAPI_DSE_CALLBACK_ERROR -- an error occurred; don't apply changes.
+ * SLAPI_DSE_CALLBACK_DO_NOT_APPLY -- no error, but do not apply changes.
+ *
+ * SLAPI_DSE_CALLBACK_DO_NOT_APPLY should only be returned by modify
+ * callbacks (i.e., those registered with operation==SLAPI_OPERATION_MODIFY).
+ * A return value of SLAPI_DSE_CALLBACK_DO_NOT_APPLY is treated the same as
+ * SLAPI_DSE_CALLBACK_ERROR for all other operations.
+ */
+#define SLAPI_DSE_CALLBACK_OK (1)
+#define SLAPI_DSE_CALLBACK_ERROR (-1)
+#define SLAPI_DSE_CALLBACK_DO_NOT_APPLY (0)
+
/******************************************************************************
* Online tasks interface (to support import, export, etc)
* After some cleanup, we could consider making these public.
@@ -1217,10 +1234,26 @@
#define SLAPI_TASK_FINISHED 2
#define SLAPI_TASK_CANCELLED 3
+/* task flag (pb_task_flags)*/
+#define SLAPI_TASK_RUNNING_AS_TASK 0x0
+#define SLAPI_TASK_RUNNING_FROM_COMMANDLINE 0x1
+
/* task flags (set by the task-control code) */
#define SLAPI_TASK_DESTROYING 0x01 /* queued event for destruction */
int slapi_task_register_handler(const char *name, dseCallbackFn func);
+void slapi_task_begin(Slapi_Task *task, int total_work);
+void slapi_task_inc_progress(Slapi_Task *task);
+void slapi_task_finish(Slapi_Task *task, int rc);
+void slapi_task_cancel(Slapi_Task *task, int rc);
+int slapi_task_get_state(Slapi_Task *task);
+void slapi_task_set_data(Slapi_Task *task, void *data);
+void * slapi_task_get_data(Slapi_Task *task);
+void slapi_task_inc_refcount(Slapi_Task *task);
+void slapi_task_dec_refcount(Slapi_Task *task);
+int slapi_task_get_refcount(Slapi_Task *task);
+void slapi_task_set_destructor_fn(Slapi_Task *task, TaskCallbackFn func);
+void slapi_task_set_cancel_fn(Slapi_Task *task, TaskCallbackFn func);
void slapi_task_status_changed(Slapi_Task *task);
void slapi_task_log_status(Slapi_Task *task, char *format, ...)
#ifdef __GNUC__
Index: slapi-private.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/slapi-private.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- slapi-private.h 18 Oct 2007 22:40:18 -0000 1.20
+++ slapi-private.h 3 Apr 2008 16:52:46 -0000 1.21
@@ -1060,22 +1060,6 @@
*/
/*
- * Note: DSE callback functions MUST return one of these three values:
- *
- * SLAPI_DSE_CALLBACK_OK -- no errors occurred; apply changes.
- * SLAPI_DSE_CALLBACK_ERROR -- an error occurred; don't apply changes.
- * SLAPI_DSE_CALLBACK_DO_NOT_APPLY -- no error, but do not apply changes.
- *
- * SLAPI_DSE_CALLBACK_DO_NOT_APPLY should only be returned by modify
- * callbacks (i.e., those registered with operation==SLAPI_OPERATION_MODIFY).
- * A return value of SLAPI_DSE_CALLBACK_DO_NOT_APPLY is treated the same as
- * SLAPI_DSE_CALLBACK_ERROR for all other operations.
- */
-#define SLAPI_DSE_CALLBACK_OK (1)
-#define SLAPI_DSE_CALLBACK_ERROR (-1)
-#define SLAPI_DSE_CALLBACK_DO_NOT_APPLY (0)
-
-/*
* Flags for slapi_config_register_callback() and
* slapi_config_remove_callback()
*/
@@ -1198,30 +1182,6 @@
/***** End of items added for the replication plugin. ***********************/
-/******************************************************************************
- * Online tasks interface (to support import, export, etc)
- * After some cleanup, we could consider making these public.
- */
-struct _slapi_task {
- struct _slapi_task *next;
- char *task_dn;
- int task_exitcode; /* for the end user */
- int task_state; /* (see above) */
- int task_progress; /* number between 0 and task_work */
- int task_work; /* "units" of work to be done */
- int task_flags; /* (see above) */
-
- /* it is the task's responsibility to allocate this memory & free it: */
- char *task_status; /* transient status info */
- char *task_log; /* appended warnings, etc */
-
- void *task_private; /* for use by backends */
- TaskCallbackFn cancel; /* task has been cancelled by user */
- TaskCallbackFn destructor; /* task entry is being destroyed */
- int task_refcount;
-};
-/* End of interface to support online tasks **********************************/
-
void DS_Sleep(PRIntervalTime ticks);
/* macro to specify the behavior of upgradedb */
Index: task.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/task.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- task.c 18 Oct 2007 00:08:34 -0000 1.14
+++ task.c 3 Apr 2008 16:52:46 -0000 1.15
@@ -47,6 +47,9 @@
#include "slap.h"
+/***********************************
+ * Static Global Variables
+ ***********************************/
/* don't panic, this is only used when creating new tasks or removing old
* ones...
*/
@@ -54,7 +57,9 @@
static PRLock *global_task_lock = NULL;
static int shutting_down = 0;
-
+/***********************************
+ * Private Defines
+ ***********************************/
#define TASK_BASE_DN "cn=tasks, cn=config"
#define TASK_IMPORT_DN "cn=import, cn=tasks, cn=config"
#define TASK_EXPORT_DN "cn=export, cn=tasks, cn=config"
@@ -71,13 +76,398 @@
#define DEFAULT_TTL "120" /* seconds */
+#define LOG_BUFFER 256
+/* if the cumul. log gets larger than this, it's truncated: */
+#define MAX_SCROLLBACK_BUFFER 8192
+
+#define NEXTMOD(_type, _val) do { \
+ modlist[cur].mod_op = LDAP_MOD_REPLACE; \
+ modlist[cur].mod_type = (_type); \
+ modlist[cur].mod_values = (char **)slapi_ch_malloc(2*sizeof(char *)); \
+ modlist[cur].mod_values[0] = (_val); \
+ modlist[cur].mod_values[1] = NULL; \
+ mod[cur] = &modlist[cur]; \
+ cur++; \
+} while (0)
+
+/***********************************
+ * Static Function Prototypes
+ ***********************************/
+static Slapi_Task *new_task(const char *dn);
+static void destroy_task(time_t when, void *arg);
static int task_modify(Slapi_PBlock *pb, Slapi_Entry *e,
Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
static int task_deny(Slapi_PBlock *pb, Slapi_Entry *e,
Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
-static int task_generic_destructor(Slapi_Task *task);
+static void task_generic_destructor(Slapi_Task *task);
+static const char *fetch_attr(Slapi_Entry *e, const char *attrname,
+ const char *default_val);
+static Slapi_Entry *get_internal_entry(Slapi_PBlock *pb, char *dn);
+static void modify_internal_entry(char *dn, LDAPMod **mods);
+
+/***********************************
+ * Public Functions
+ ***********************************/
+/*
+ * slapi_new_task: create a new task, fill in DN, and setup modify callback
+ * argument:
+ * dn: task dn
+ * result:
+ * Success: Slapi_Task object
+ * Failure: NULL
+ */
+Slapi_Task *
+slapi_new_task(const char *dn)
+{
+ return new_task(dn);
+}
+
+/* slapi_destroy_task: destroy a task
+ * argument:
+ * task: task to destroy
+ * result:
+ * none
+ */
+void
+slapi_destroy_task(void *arg)
+{
+ if (arg) {
+ destroy_task(1, arg);
+ }
+}
+
+/*
+ * Sets the initial task state and updated status
+ */
+void slapi_task_begin(Slapi_Task *task, int total_work)
+{
+ if (task) {
+ task->task_work = total_work;
+ task->task_progress = 0;
+ task->task_state = SLAPI_TASK_RUNNING;
+ slapi_task_status_changed(task);
+ }
+}
+
+/*
+ * Increments task progress and updates status
+ */
+void slapi_task_inc_progress(Slapi_Task *task)
+{
+ if (task) {
+ task->task_progress++;
+ slapi_task_status_changed(task);
+ }
+}
+
+/*
+ * Sets completed task state and updates status
+ */
+void slapi_task_finish(Slapi_Task *task, int rc)
+{
+ if (task) {
+ task->task_exitcode = rc;
+ task->task_state = SLAPI_TASK_FINISHED;
+ slapi_task_status_changed(task);
+ }
+}
+
+/*
+ * Cancels a task
+ */
+void slapi_task_cancel(Slapi_Task *task, int rc)
+{
+ if (task) {
+ task->task_exitcode = rc;
+ task->task_state = SLAPI_TASK_CANCELLED;
+ slapi_task_status_changed(task);
+ }
+}
+
+/*
+ * Get the current state of a task
+ */
+int slapi_task_get_state(Slapi_Task *task)
+{
+ if (task) {
+ return task->task_state;
+ }
+}
+/* this changes the 'nsTaskStatus' value, which is transient (anything logged
+ * here wipes out any previous status)
+ */
+void slapi_task_log_status(Slapi_Task *task, char *format, ...)
+{
+ va_list ap;
+
+ if (! task->task_status)
+ task->task_status = (char *)slapi_ch_malloc(10 * LOG_BUFFER);
+ if (! task->task_status)
+ return; /* out of memory? */
+
+ va_start(ap, format);
+ PR_vsnprintf(task->task_status, (10 * LOG_BUFFER), format, ap);
+ va_end(ap);
+ slapi_task_status_changed(task);
+}
+
+/* this adds a line to the 'nsTaskLog' value, which is cumulative (anything
+ * logged here is added to the end)
+ */
+void slapi_task_log_notice(Slapi_Task *task, char *format, ...)
+{
+ va_list ap;
+ char buffer[LOG_BUFFER];
+ size_t len;
+
+ va_start(ap, format);
+ PR_vsnprintf(buffer, LOG_BUFFER, format, ap);
+ va_end(ap);
+
+ len = 2 + strlen(buffer) + (task->task_log ? strlen(task->task_log) : 0);
+ if ((len > MAX_SCROLLBACK_BUFFER) && task->task_log) {
+ size_t i;
+ char *newbuf;
+
+ /* start from middle of buffer, and find next linefeed */
+ i = strlen(task->task_log)/2;
+ while (task->task_log[i] && (task->task_log[i] != '\n'))
+ i++;
+ if (task->task_log[i])
+ i++;
+ len = strlen(task->task_log) - i + 2 + strlen(buffer);
+ newbuf = (char *)slapi_ch_malloc(len);
+ if (! newbuf)
+ return; /* out of memory? */
+ strcpy(newbuf, task->task_log + i);
+ slapi_ch_free((void **)&task->task_log);
+ task->task_log = newbuf;
+ } else {
+ if (! task->task_log) {
+ task->task_log = (char *)slapi_ch_malloc(len);
+ task->task_log[0] = 0;
+ } else {
+ task->task_log = (char *)slapi_ch_realloc(task->task_log, len);
+ }
+ if (! task->task_log)
+ return; /* out of memory? */
+ }
+
+ if (task->task_log[0])
+ strcat(task->task_log, "\n");
+ strcat(task->task_log, buffer);
+
+ slapi_task_status_changed(task);
+}
+
+/* update attributes in the entry under "cn=tasks" to match the current
+ * status of the task. */
+void slapi_task_status_changed(Slapi_Task *task)
+{
+ LDAPMod modlist[20];
+ LDAPMod *mod[20];
+ int cur = 0, i;
+ char s1[20], s2[20], s3[20];
+
+ if (shutting_down) {
+ /* don't care about task status updates anymore */
+ return;
+ }
+
+ NEXTMOD(TASK_LOG_NAME, task->task_log);
+ NEXTMOD(TASK_STATUS_NAME, task->task_status);
+ sprintf(s1, "%d", task->task_exitcode);
+ sprintf(s2, "%d", task->task_progress);
+ sprintf(s3, "%d", task->task_work);
+ NEXTMOD(TASK_PROGRESS_NAME, s2);
+ NEXTMOD(TASK_WORK_NAME, s3);
+ /* only add the exit code when the job is done */
+ if ((task->task_state == SLAPI_TASK_FINISHED) ||
+ (task->task_state == SLAPI_TASK_CANCELLED)) {
+ NEXTMOD(TASK_EXITCODE_NAME, s1);
+ /* make sure the console can tell the task has ended */
+ if (task->task_progress != task->task_work) {
+ task->task_progress = task->task_work;
+ }
+ }
+
+ mod[cur] = NULL;
+ modify_internal_entry(task->task_dn, mod);
+
+ for (i = 0; i < cur; i++)
+ slapi_ch_free((void **)&modlist[i].mod_values);
+
+ if (((task->task_state == SLAPI_TASK_FINISHED) ||
+ (task->task_state == SLAPI_TASK_CANCELLED)) &&
+ !(task->task_flags & SLAPI_TASK_DESTROYING)) {
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Entry *e;
+ int ttl;
+ time_t expire;
+
+ e = get_internal_entry(pb, task->task_dn);
+ if (e == NULL)
+ return;
+ ttl = atoi(fetch_attr(e, "ttl", DEFAULT_TTL));
+ if (ttl > 3600)
+ ttl = 3600; /* be reasonable. */
+ expire = time(NULL) + ttl;
+ task->task_flags |= SLAPI_TASK_DESTROYING;
+ /* queue an event to destroy the state info */
+ slapi_eq_once(destroy_task, (void *)task, expire);
+
+ slapi_free_search_results_internal(pb);
+ slapi_pblock_destroy(pb);
+ }
+}
+
+/*
+ * Stash some opaque task specific data in the task for later use.
+ */
+void slapi_task_set_data(Slapi_Task *task, void *data)
+{
+ if (task) {
+ task->task_private = data;
+ }
+}
+
+/*
+ * Retrieve some opaque task specific data from the task.
+ */
+void * slapi_task_get_data(Slapi_Task *task)
+{
+ if (task) {
+ return task->task_private;
+ }
+}
+
+/*
+ * Increment the task reference count
+ */
+void slapi_task_inc_refcount(Slapi_Task *task)
+{
+ if (task) {
+ task->task_refcount++;
+ }
+}
+
+/*
+ * Decrement the task reference count
+ */
+void slapi_task_dec_refcount(Slapi_Task *task)
+{
+ if (task) {
+ task->task_refcount--;
+ }
+}
+
+/*
+ * Returns the task reference count
+ */
+int slapi_task_get_refcount(Slapi_Task *task)
+{
+ if (task) {
+ return task->task_refcount;
+ }
+}
+
+/* name is, for example, "import" */
+int slapi_task_register_handler(const char *name, dseCallbackFn func)
+{
+ char *dn = NULL;
+ Slapi_PBlock *pb = NULL;
+ Slapi_Operation *op;
+ LDAPMod *mods[3];
+ LDAPMod mod[3];
+ const char *objectclass[3];
+ const char *cnvals[2];
+ int ret = -1;
+ int x;
+
+ dn = slapi_ch_smprintf("cn=%s, %s", name, TASK_BASE_DN);
+ if (dn == NULL) {
+ goto out;
+ }
+
+ pb = slapi_pblock_new();
+ if (pb == NULL) {
+ goto out;
+ }
+
+ /* this is painful :( */
+ mods[0] = &mod[0];
+ mod[0].mod_op = LDAP_MOD_ADD;
+ mod[0].mod_type = "objectClass";
+ mod[0].mod_values = (char **)objectclass;
+ objectclass[0] = "top";
+ objectclass[1] = "extensibleObject";
+ objectclass[2] = NULL;
+ mods[1] = &mod[1];
+ mod[1].mod_op = LDAP_MOD_ADD;
+ mod[1].mod_type = "cn";
+ mod[1].mod_values = (char **)cnvals;
+ cnvals[0] = name;
+ cnvals[1] = NULL;
+ mods[2] = NULL;
+ slapi_add_internal_set_pb(pb, dn, mods, NULL,
+ plugin_get_default_component_id(), 0);
+ x = 1;
+ slapi_pblock_set(pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &x);
+ /* Make sure these adds don't appear in the audit and change logs */
+ slapi_pblock_get(pb, SLAPI_OPERATION, &op);
+ operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
+
+ slapi_add_internal_pb(pb);
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &x);
+ if ((x != LDAP_SUCCESS) && (x != LDAP_ALREADY_EXISTS)) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "Can't create task node '%s' (error %d)\n",
+ name, x, 0);
+ ret = x;
+ goto out;
+ }
+
+ /* register add callback */
+ slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP,
+ dn, LDAP_SCOPE_SUBTREE, "(objectclass=*)", func, NULL);
+ /* deny modify/delete of the root task entry */
+ slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
+ dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
+ slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP,
+ dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
+
+ ret = 0;
+
+out:
+ if (dn) {
+ slapi_ch_free((void **)&dn);
+ }
+ if (pb) {
+ slapi_pblock_destroy(pb);
+ }
+ return ret;
+}
+
+void slapi_task_set_destructor_fn(Slapi_Task *task, TaskCallbackFn func)
+{
+ if (task) {
+ task->destructor = func;
+ }
+}
+
+void slapi_task_set_cancel_fn(Slapi_Task *task, TaskCallbackFn func)
+{
+ if (task) {
+ task->cancel = func;
+ }
+}
+
+
+/***********************************
+ * Static Helper Functions
+ ***********************************/
/* create a new task, fill in DN, and setup modify callback */
static Slapi_Task *
new_task(const char *dn)
@@ -92,7 +482,11 @@
PR_Unlock(global_task_lock);
task->task_dn = slapi_ch_strdup(dn);
- task->destructor = task_generic_destructor;
+ task->task_state = SLAPI_TASK_SETUP;
+ task->task_flags = SLAPI_TASK_RUNNING_AS_TASK;
+ task->destructor = NULL;
+ task->cancel = NULL;
+ task->task_private = NULL;
slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, dn,
LDAP_SCOPE_BASE, "(objectclass=*)", task_modify, (void *)task);
slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, dn,
@@ -100,8 +494,8 @@
/* don't add entries under this one */
#if 0
/* don't know why, but this doesn't work. it makes the current add
- * operation fail. :(
- */
+ * * operation fail. :(
+ * */
slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, dn,
LDAP_SCOPE_SUBTREE, "(objectclass=*)", task_deny, NULL);
#endif
@@ -117,8 +511,13 @@
Slapi_Task *t1;
Slapi_PBlock *pb = slapi_pblock_new();
- if (task->destructor != NULL)
+ /* Call the custom destructor callback if one was provided,
+ * then perform the internal task destruction. */
+ if (task->destructor != NULL) {
(*task->destructor)(task);
+ }
+
+ task_generic_destructor(task);
/* if when == 0, we're already locked (called during shutdown) */
if (when != 0) {
@@ -141,45 +540,16 @@
slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_modify);
slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP,
- task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny);
- slapi_delete_internal_set_pb(pb, task->task_dn, NULL, NULL,
- (void *)plugin_get_default_component_id(), 0);
-
- slapi_delete_internal_pb(pb);
- slapi_pblock_destroy(pb);
-
- slapi_ch_free((void **)&task->task_dn);
- slapi_ch_free((void **)&task);
-}
-
-/*
- * slapi_new_task: create a new task, fill in DN, and setup modify callback
- * argument:
- * dn: task dn
- * result:
- * Success: Slapi_Task object
- * Failure: NULL
- */
-Slapi_Task *
-slapi_new_task(const char *dn)
-{
- return new_task(dn);
-}
-
-/* slapi_destroy_task: destroy a task
- * argument:
- * task: task to destroy
- * result:
- * none
- */
-void
-slapi_destroy_task(void *arg)
-{
- destroy_task(1, arg);
-}
+ task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny);
+ slapi_delete_internal_set_pb(pb, task->task_dn, NULL, NULL,
+ (void *)plugin_get_default_component_id(), 0);
-/********** some useful helper functions **********/
+ slapi_delete_internal_pb(pb);
+ slapi_pblock_destroy(pb);
+ slapi_ch_free((void **)&task->task_dn);
+ slapi_ch_free((void **)&task);
+}
/* extract a single value from the entry (as a string) -- if it's not in the
* entry, the default will be returned (which can be NULL).
@@ -268,81 +638,7 @@
} while (ret != LDAP_SUCCESS);
}
-
-/********** helper functions for dealing with task logging **********/
-
-#define LOG_BUFFER 256
-/* if the cumul. log gets larger than this, it's truncated: */
-#define MAX_SCROLLBACK_BUFFER 8192
-
-/* this changes the 'nsTaskStatus' value, which is transient (anything logged
- * here wipes out any previous status)
- */
-void slapi_task_log_status(Slapi_Task *task, char *format, ...)
-{
- va_list ap;
-
- if (! task->task_status)
- task->task_status = (char *)slapi_ch_malloc(10 * LOG_BUFFER);
- if (! task->task_status)
- return; /* out of memory? */
-
- va_start(ap, format);
- PR_vsnprintf(task->task_status, (10 * LOG_BUFFER), format, ap);
- va_end(ap);
- slapi_task_status_changed(task);
-}
-
-/* this adds a line to the 'nsTaskLog' value, which is cumulative (anything
- * logged here is added to the end)
- */
-void slapi_task_log_notice(Slapi_Task *task, char *format, ...)
-{
- va_list ap;
- char buffer[LOG_BUFFER];
- size_t len;
-
- va_start(ap, format);
- PR_vsnprintf(buffer, LOG_BUFFER, format, ap);
- va_end(ap);
-
- len = 2 + strlen(buffer) + (task->task_log ? strlen(task->task_log) : 0);
- if ((len > MAX_SCROLLBACK_BUFFER) && task->task_log) {
- size_t i;
- char *newbuf;
-
- /* start from middle of buffer, and find next linefeed */
- i = strlen(task->task_log)/2;
- while (task->task_log[i] && (task->task_log[i] != '\n'))
- i++;
- if (task->task_log[i])
- i++;
- len = strlen(task->task_log) - i + 2 + strlen(buffer);
- newbuf = (char *)slapi_ch_malloc(len);
- if (! newbuf)
- return; /* out of memory? */
- strcpy(newbuf, task->task_log + i);
- slapi_ch_free((void **)&task->task_log);
- task->task_log = newbuf;
- } else {
- if (! task->task_log) {
- task->task_log = (char *)slapi_ch_malloc(len);
- task->task_log[0] = 0;
- } else {
- task->task_log = (char *)slapi_ch_realloc(task->task_log, len);
- }
- if (! task->task_log)
- return; /* out of memory? */
- }
-
- if (task->task_log[0])
- strcat(task->task_log, "\n");
- strcat(task->task_log, buffer);
-
- slapi_task_status_changed(task);
-}
-
-static int task_generic_destructor(Slapi_Task *task)
+static void task_generic_destructor(Slapi_Task *task)
{
if (task->task_log) {
slapi_ch_free((void **)&task->task_log);
@@ -351,7 +647,6 @@
slapi_ch_free((void **)&task->task_status);
}
task->task_log = task->task_status = NULL;
- return 0;
}
@@ -553,13 +848,12 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
rv = LDAP_OPERATIONS_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
memset(&mypb, 0, sizeof(mypb));
mypb.pb_backend = be;
@@ -575,7 +869,7 @@
mypb.pb_ldif_include = include;
mypb.pb_ldif_exclude = exclude;
mypb.pb_task = task;
- mypb.pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb.pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
if (NULL != encrypt_on_import && 0 == strcasecmp(encrypt_on_import, "true") ) {
mypb.pb_ldif_encrypt = 1;
}
@@ -618,10 +912,7 @@
g_incr_active_threadcnt();
for (count = 0, inp = instance_names; *inp; inp++, count++)
;
- task->task_work = count;
- task->task_progress = 0;
- task->task_state = SLAPI_TASK_RUNNING;
- slapi_task_status_changed(task);
+ slapi_task_begin(task, count);
for (inp = instance_names; *inp; inp++) {
int release_me = 0;
@@ -693,8 +984,7 @@
if (rv != 0)
break;
- task->task_progress++;
- slapi_task_status_changed(task);
+ slapi_task_inc_progress(task);
}
/* free the memory now */
@@ -712,9 +1002,7 @@
LDAPDebug(LDAP_DEBUG_ANY, "Export failed.\n", 0, 0, 0);
}
- task->task_exitcode = rv;
- task->task_state = SLAPI_TASK_FINISHED;
- slapi_task_status_changed(task);
+ slapi_task_finish(task, rv);
g_decr_active_threadcnt();
}
@@ -888,16 +1176,13 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
- task->task_work = instance_cnt;
- task->task_progress = 0;
mypb = slapi_pblock_new();
if (mypb == NULL) {
@@ -914,7 +1199,7 @@
/* horrible hack */
mypb->pb_instance_name = (char *)instance_names;
mypb->pb_task = task;
- mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb->pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
if (NULL != decrypt_on_export && 0 == strcasecmp(decrypt_on_export, "true") ) {
mypb->pb_ldif_encrypt = 1;
}
@@ -957,10 +1242,7 @@
int rv;
g_incr_active_threadcnt();
- task->task_work = 1;
- task->task_progress = 0;
- task->task_state = SLAPI_TASK_RUNNING;
- slapi_task_status_changed(task);
+ slapi_task_begin(task, 1);
slapi_task_log_notice(task, "Beginning backup of '%s'",
pb->pb_plugin->plg_name);
@@ -978,11 +1260,7 @@
LDAPDebug(LDAP_DEBUG_ANY, "Backup finished.\n", 0, 0, 0);
}
- task->task_progress = 1;
- task->task_exitcode = rv;
- task->task_state = SLAPI_TASK_FINISHED;
- slapi_task_status_changed(task);
-
+ slapi_task_finish(task, rv);
slapi_ch_free((void **)&pb->pb_seq_val);
slapi_pblock_destroy(pb);
g_decr_active_threadcnt();
@@ -1048,16 +1326,13 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
- task->task_work = 1;
- task->task_progress = 0;
mypb = slapi_pblock_new();
if (mypb == NULL) {
@@ -1068,7 +1343,7 @@
mypb->pb_seq_val = slapi_ch_strdup(archive_dir);
mypb->pb_plugin = be->be_database;
mypb->pb_task = task;
- mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb->pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
/* start the backup as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_backup_thread,
@@ -1102,10 +1377,7 @@
int rv;
g_incr_active_threadcnt();
- task->task_work = 1;
- task->task_progress = 0;
- task->task_state = SLAPI_TASK_RUNNING;
- slapi_task_status_changed(task);
+ slapi_task_begin(task, 1);
slapi_task_log_notice(task, "Beginning restore to '%s'",
pb->pb_plugin->plg_name);
@@ -1123,11 +1395,7 @@
LDAPDebug(LDAP_DEBUG_ANY, "Restore finished.\n", 0, 0, 0);
}
- task->task_progress = 1;
- task->task_exitcode = rv;
- task->task_state = SLAPI_TASK_FINISHED;
- slapi_task_status_changed(task);
-
+ slapi_task_finish(task, rv);
slapi_ch_free((void **)&pb->pb_seq_val);
slapi_pblock_destroy(pb);
g_decr_active_threadcnt();
@@ -1199,16 +1467,13 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
- task->task_work = 1;
- task->task_progress = 0;
mypb = slapi_pblock_new();
if (mypb == NULL) {
@@ -1221,7 +1486,7 @@
if (NULL != instance_name)
mypb->pb_instance_name = slapi_ch_strdup(instance_name);
mypb->pb_task = task;
- mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb->pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
/* start the restore as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_restore_thread,
@@ -1255,10 +1520,7 @@
int rv;
g_incr_active_threadcnt();
- task->task_work = 1;
- task->task_progress = 0;
- task->task_state = SLAPI_TASK_RUNNING;
- slapi_task_status_changed(task);
+ slapi_task_begin(task, 1);
rv = (*pb->pb_plugin->plg_db2index)(pb);
if (rv != 0) {
@@ -1267,11 +1529,7 @@
LDAPDebug(LDAP_DEBUG_ANY, "Index failed (error %d)\n", rv, 0, 0);
}
- task->task_progress = task->task_work;
- task->task_exitcode = rv;
- task->task_state = SLAPI_TASK_FINISHED;
- slapi_task_status_changed(task);
-
+ slapi_task_finish(task, rv);
charray_free(pb->pb_db2index_attrs);
slapi_ch_free((void **)&pb->pb_instance_name);
slapi_pblock_destroy(pb);
@@ -1353,16 +1611,13 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
- task->task_work = 1;
- task->task_progress = 0;
mypb = slapi_pblock_new();
if (mypb == NULL) {
@@ -1375,7 +1630,7 @@
mypb->pb_instance_name = slapi_ch_strdup(instance_name);
mypb->pb_db2index_attrs = indexlist;
mypb->pb_task = task;
- mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb->pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
/* start the db2index as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_index_thread,
@@ -1460,14 +1715,14 @@
}
/* allocate new task now */
- task = new_task(slapi_entry_get_ndn(e));
+ task = slapi_new_task(slapi_entry_get_ndn(e));
if (task == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "unable to allocate new task!\n", 0, 0, 0);
*returncode = LDAP_OPERATIONS_ERROR;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
}
- task->task_state = SLAPI_TASK_SETUP;
+ /* NGK - This could use some cleanup to use the SLAPI task API, such as slapi_task_begin() */
task->task_work = 1;
task->task_progress = 0;
@@ -1478,7 +1733,7 @@
mypb.pb_seq_type = SLAPI_UPGRADEDB_FORCE; /* force; reindex all regardless the dbversion */
mypb.pb_seq_val = slapi_ch_strdup(archive_dir);
mypb.pb_task = task;
- mypb.pb_task_flags = TASK_RUNNING_AS_TASK;
+ mypb.pb_task_flags = SLAPI_TASK_RUNNING_AS_TASK;
rv = (mypb.pb_plugin->plg_upgradedb)(&mypb);
if (rv == 0) {
@@ -1502,76 +1757,6 @@
return SLAPI_DSE_CALLBACK_OK;
}
-/* update attributes in the entry under "cn=tasks" to match the current
- * status of the task.
- */
-#define NEXTMOD(_type, _val) do { \
- modlist[cur].mod_op = LDAP_MOD_REPLACE; \
- modlist[cur].mod_type = (_type); \
- modlist[cur].mod_values = (char **)slapi_ch_malloc(2*sizeof(char *)); \
- modlist[cur].mod_values[0] = (_val); \
- modlist[cur].mod_values[1] = NULL; \
- mod[cur] = &modlist[cur]; \
- cur++; \
-} while (0)
-void slapi_task_status_changed(Slapi_Task *task)
-{
- LDAPMod modlist[20];
- LDAPMod *mod[20];
- int cur = 0, i;
- char s1[20], s2[20], s3[20];
-
- if (shutting_down) {
- /* don't care about task status updates anymore */
- return;
- }
-
- NEXTMOD(TASK_LOG_NAME, task->task_log);
- NEXTMOD(TASK_STATUS_NAME, task->task_status);
- sprintf(s1, "%d", task->task_exitcode);
- sprintf(s2, "%d", task->task_progress);
- sprintf(s3, "%d", task->task_work);
- NEXTMOD(TASK_PROGRESS_NAME, s2);
- NEXTMOD(TASK_WORK_NAME, s3);
- /* only add the exit code when the job is done */
- if ((task->task_state == SLAPI_TASK_FINISHED) ||
- (task->task_state == SLAPI_TASK_CANCELLED)) {
- NEXTMOD(TASK_EXITCODE_NAME, s1);
- /* make sure the console can tell the task has ended */
- if (task->task_progress != task->task_work) {
- task->task_progress = task->task_work;
- }
- }
-
- mod[cur] = NULL;
- modify_internal_entry(task->task_dn, mod);
-
- for (i = 0; i < cur; i++)
- slapi_ch_free((void **)&modlist[i].mod_values);
-
- if ((task->task_state == SLAPI_TASK_FINISHED) &&
- !(task->task_flags & SLAPI_TASK_DESTROYING)) {
- Slapi_PBlock *pb = slapi_pblock_new();
- Slapi_Entry *e;
- int ttl;
- time_t expire;
-
- e = get_internal_entry(pb, task->task_dn);
- if (e == NULL)
- return;
- ttl = atoi(fetch_attr(e, "ttl", DEFAULT_TTL));
- if (ttl > 3600)
- ttl = 3600; /* be reasonable. */
- expire = time(NULL) + ttl;
- task->task_flags |= SLAPI_TASK_DESTROYING;
- /* queue an event to destroy the state info */
- slapi_eq_once(destroy_task, (void *)task, expire);
-
- slapi_free_search_results_internal(pb);
- slapi_pblock_destroy(pb);
- }
-}
-
/* cleanup old tasks that may still be in the DSE from a previous session
* (this can happen if the server crashes [no matter how unlikely we like
* to think that is].)
@@ -1636,84 +1821,6 @@
slapi_pblock_destroy(pb);
}
-/* name is, for exmaple, "import" */
-int slapi_task_register_handler(const char *name, dseCallbackFn func)
-{
- char *dn = NULL;
- Slapi_PBlock *pb = NULL;
- Slapi_Operation *op;
- LDAPMod *mods[3];
- LDAPMod mod[3];
- const char *objectclass[3];
- const char *cnvals[2];
- int ret = -1;
- int x;
-
- dn = slapi_ch_smprintf("cn=%s, %s", name, TASK_BASE_DN);
- if (dn == NULL) {
- goto out;
- }
-
- pb = slapi_pblock_new();
- if (pb == NULL) {
- goto out;
- }
-
- /* this is painful :( */
- mods[0] = &mod[0];
- mod[0].mod_op = LDAP_MOD_ADD;
- mod[0].mod_type = "objectClass";
- mod[0].mod_values = (char **)objectclass;
- objectclass[0] = "top";
- objectclass[1] = "extensibleObject";
- objectclass[2] = NULL;
- mods[1] = &mod[1];
- mod[1].mod_op = LDAP_MOD_ADD;
- mod[1].mod_type = "cn";
- mod[1].mod_values = (char **)cnvals;
- cnvals[0] = name;
- cnvals[1] = NULL;
- mods[2] = NULL;
- slapi_add_internal_set_pb(pb, dn, mods, NULL,
- plugin_get_default_component_id(), 0);
- x = 1;
- slapi_pblock_set(pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &x);
- /* Make sure these adds don't appear in the audit and change logs */
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
-
- slapi_add_internal_pb(pb);
- slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &x);
- if ((x != LDAP_SUCCESS) && (x != LDAP_ALREADY_EXISTS)) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "Can't create task node '%s' (error %d)\n",
- name, x, 0);
- ret = x;
- goto out;
- }
-
- /* register add callback */
- slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_SUBTREE, "(objectclass=*)", func, NULL);
- /* deny modify/delete of the root task entry */
- slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
- slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
-
- ret = 0;
-
-out:
- if (dn) {
- slapi_ch_free((void **)&dn);
- }
- if (pb) {
- slapi_pblock_destroy(pb);
- }
- return ret;
-}
-
-
void task_init(void)
{
global_task_lock = PR_NewLock();
16 years, 2 months