Author: nhosoi
Update of /cvs/dirsec/adminserver/admserv/cgi-ds
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv11558/admserv/cgi-ds
Added Files:
addindex.c ds_bak2db.c ds_db2bak.c ds_db2ldif.c ds_ldif2db.c
ds_listdb.c ds_remove.c ds_rmdb.c ds_snmpctrl.c init_ds_env.c
init_ds_env.h restart.c shutdown.c start.c vlvindex.c
Log Message:
Resolves: #237356
Summary: Move DS Admin Code into Admin Server (Comment #54 -- adminserver side)
Description: moving DS task CGIs to the adminserver with libdsa.
--- NEW FILE addindex.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* addindex.c: Creates one or more indexes for specified attributes
*
* Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
#include "nspr.h"
int main(int argc, char *argv[])
{
int status;
char *attributes;
char *attrs;
char **attrList;
int nAttrs;
char *nextAttr = NULL;
char *backendName;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
/*
* Get value of the "attributes" variable.
*/
attributes = get_cgi_var("attributes", NULL, NULL);
if ( (NULL == attributes) || (strlen(attributes) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "attributes", NULL, NULL );
return 1;
}
backendName = get_cgi_var("backendID", NULL, NULL);
if ( (NULL == backendName) || (strlen(backendName) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "backendName", NULL, NULL );
return 1;
}
attrs = strdup( attributes );
if (attrs == NULL) {
rpt_err(DS_MEMORY_ERROR, "Out of memory!", NULL, NULL);
return 1;
}
/* Allocate for worst possible case */
attrList = (char **)malloc(sizeof(*attrList) * (strlen(attrs)+1));
nAttrs = 0;
/* strtok() is not MT safe, but it is okay to call here because this is a command line
*/
attrList[nAttrs++] = strtok( attrs, " " );
do {
nextAttr = strtok( NULL, " " );
attrList[nAttrs++] = nextAttr;
} while( nextAttr != NULL );
ds_send_status((nAttrs > 1) ? "Creating indexes ..." :
"Creating index ...");
status = ds_addindex( attrList, backendName );
if ( !status ) {
rpt_success((nAttrs > 1) ? "Success! The indexes have been created." :
"Success! The index has been created.");
status = 0;
} else {
char msg[BIG_LINE];
PR_snprintf( msg, sizeof(msg), "[%s] %s", backendName, attributes);
rpt_err( status, msg, NULL, NULL );
status = 1;
}
return status;
}
--- NEW FILE ds_bak2db.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Restores a database.
*
* Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
int main(int argc, char *argv[])
{
int isrunning;
char *filename = NULL;
int status;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
/*
* Get value of the "filename" variable.
*/
filename = get_cgi_var("filename", NULL, NULL);
if ( (NULL == filename) || (strlen(filename) < 1) ) {
fprintf(stdout, "Environment variable filename not defined.\n");
rpt_err( DS_UNDEFINED_VARIABLE, "filename", NULL, NULL );
return 1;
}
/* Check if server is up */
isrunning = ds_get_updown_status();
/* Stop it, if so */
if (isrunning != DS_SERVER_DOWN) {
status = ds_bring_down_server();
if(status != DS_SERVER_DOWN) {
rpt_err( DS_SERVER_MUST_BE_DOWN, filename, NULL, NULL );
return 1;
}
}
ds_send_status("restoring database ...");
status = ds_bak2db(filename);
if ( !status ) {
rpt_success("Success! The database has been restored.");
status = 0;
} else {
rpt_err( status, filename, NULL, NULL );
status = 1;
}
/* Restart the server if we brought it down */
if (isrunning != DS_SERVER_DOWN) {
if(ds_bring_up_server(1) != DS_SERVER_UP) {
ds_send_status( "An error occurred during startup" );
}
}
return status;
}
--- NEW FILE ds_db2bak.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Backs up the database.
*
* Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
#ifdef XP_UNIX
#include <unistd.h>
#endif
#include "nspr.h"
int main(int argc, char *argv[])
{
char *filename = NULL;
int status;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
/*
* Get value of the "filename" variable.
*/
filename = get_cgi_var("filename", NULL, NULL);
if ( (NULL == filename) || (strlen(filename) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "filename", NULL, NULL );
return 1;
}
ds_become_localuser (ds_get_config (DS_REAL_CONFIG));
#define NEWDIR_MODE 0755
/* Attempt to detect up front if file cannot be written */
status = -1;
/* Attempt to create the backup directory */
if ( 0 == ds_mkdir_p(filename, NEWDIR_MODE) ) {
char foo[256];
FILE *f;
/* Now attempt to create a file there (the directory might
already have existed */
PR_snprintf( foo, sizeof(foo), "%s%c%s", filename, FILE_PATHSEP,
"foo" );
f = fopen(foo, "w");
if ( NULL != f ) {
status = 0;
fclose( f );
unlink( foo );
}
}
if ( status ) {
rpt_err( DS_CANNOT_CREATE_FILE, filename, NULL, NULL );
return 1;
}
ds_send_status("backing up database ...");
status = ds_db2bak( filename ); /* prints errors as needed */
if ( !status ) {
rpt_success("Success! The database has been backed up.");
return 0;
} else {
rpt_err( status, filename, NULL, NULL );
return 1;
}
}
--- NEW FILE ds_db2ldif.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Converts the database into an ldif file.
*
* Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
#ifdef XP_UNIX
#include <unistd.h>
#endif
int main(int argc, char *argv[])
{
char *filename = NULL;
char *subtree = NULL;
int status;
FILE *f;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
/*
* Get value of the "filename" variable.
*/
filename = get_cgi_var("filename", NULL, NULL);
if ( (NULL == filename) || (strlen(filename) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "filename", NULL, NULL );
return 1;
}
ds_become_localuser (ds_get_config (DS_REAL_CONFIG));
/* Attempt to detect up front if file cannot be written */
f = fopen(filename, "w");
if ( NULL != f ) {
fclose( f );
unlink( filename );
} else {
rpt_err( DS_CANNOT_CREATE_FILE, filename, NULL, NULL );
return 1;
}
/*
* Get value of the "subtree" variable.
*/
subtree = get_cgi_var("subtree", NULL, NULL);
ds_send_status("creating LDIF file ...");
if ( (subtree != NULL) && (*subtree != 0) ) {
char *escaped = ds_escape_for_shell( subtree );
status = ds_db2ldif_subtree(filename, escaped);
free( escaped );
} else {
status = ds_db2ldif(filename); /* prints errors as needed */
}
if ( !status ) {
rpt_success("Success! The database has been exported.");
return 0;
} else {
rpt_err( status, filename, NULL, NULL );
return 1;
}
}
--- NEW FILE ds_ldif2db.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* ds_ldif2db.c: Converts an ldif file into a database.
*
* Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
#ifdef XP_UNIX
#include <unistd.h>
#endif
#ifdef XP_WIN32
#include <io.h>
#endif
int main(int argc, char *argv[])
{
int isrunning;
char *filename = NULL;
char *saveconfig = NULL;
int preserve;
int status;
setbuf(stdout, 0);
#ifdef DEBUG_CGI
freopen("\\tmp\\stderr.out", "w", stderr);
#else
dup2(fileno(stdout), fileno(stderr));
#endif /* DEBUG_CGI */
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
/*
* Get value of the "filename" variable.
*/
filename = get_cgi_var("filename", NULL, NULL);
if ( (NULL == filename) || (strlen(filename) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "filename", NULL, NULL );
return 1;
}
#ifdef DEBUG_CGI
fprintf(stderr, "filename=%s\n", filename);
#endif /* DEBUG_CGI */
/*
* Get value of the "saveconfig" variable.
*/
saveconfig = get_cgi_var("saveconfig", NULL, NULL);
preserve = ( (saveconfig == NULL) || !(strcmp(saveconfig,"true")) );
#ifdef DEBUG_CGI
fprintf(stderr, "preserve=%d\n", preserve);
#endif /* DEBUG_CGI */
/* Check if server is up */
isrunning = ds_get_updown_status();
#ifdef DEBUG_CGI
fprintf(stderr, "isrunning=%d\n", isrunning);
#endif /* DEBUG_CGI */
/* Stop it, if so */
if (isrunning != DS_SERVER_DOWN) {
status = ds_bring_down_server();
#ifdef DEBUG_CGI
fprintf(stderr, "status=%d\n", status);
#endif /* DEBUG_CGI */
if(status != DS_SERVER_DOWN) {
rpt_err( DS_SERVER_MUST_BE_DOWN, filename, NULL, NULL );
return 1;
}
}
ds_send_status("creating database ...");
if ( preserve )
status = ds_ldif2db_preserve(filename); /* prints errors as needed */
else
status = ds_ldif2db(filename); /* prints errors as needed */
if ( !status ) {
rpt_success("Success! The database has been imported.");
status = 0;
} else {
rpt_err( status, filename, NULL, NULL );
status = 1;
}
/* Restart the server if we brought it down */
if (isrunning != DS_SERVER_DOWN) {
int retval;
if((retval=ds_bring_up_server(1)) != DS_SERVER_UP) {
ds_send_status( "An error occurred during startup" );
}
}
return status;
}
--- NEW FILE ds_listdb.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* List the database backup directories.
* No HTML - this is for DS 4.0.
*
* Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "dsalib.h"
int main(int argc, char *argv[], char *envp[])
{
char **bak_dirs;
ds_become_localuser (ds_get_config (DS_REAL_CONFIG));
/* Tell the receiver we are about to start sending data */
fprintf(stdout, "\n");
bak_dirs = ds_get_bak_dirs();
if ( bak_dirs != NULL ) /* no error */ {
char **cur_file = bak_dirs;
while ( *cur_file != NULL ) {
fprintf(stdout, "%s\n", *cur_file);
cur_file++;
}
}
ds_become_original();
return 0;
}
--- NEW FILE ds_remove.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Remove the server
*
* Prasanta Behera
*/
#ifdef XP_WIN32
#include <windows.h>
#include <io.h>
#include "regparms.h"
extern BOOL DeleteServer(LPCSTR pszServiceId);
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#ifdef XP_UNIX
#include <sys/errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#else
#endif /* WIN32? */
#include <sys/stat.h>
#include "dsalib.h"
#include "init_ds_env.h"
#include "nspr.h"
/* this will be set to 1 if we need to retry the
rm -rf of the instance directory again */
static int try_rm_rf_again = 0;
static int
rm_rf_err_func(const char *path, const char *op, void *arg)
{
PRInt32 errcode = PR_GetError();
char *msg;
const char *errtext;
if (!errcode || (errcode == PR_UNKNOWN_ERROR)) {
errcode = PR_GetOSError();
errtext = ds_system_errmsg();
} else {
errtext = PR_ErrorToString(errcode, PR_LANGUAGE_I_DEFAULT);
}
/* ignore "file or directory already removed" errors */
if (errcode != PR_FILE_NOT_FOUND_ERROR) {
msg = PR_smprintf("%s %s: error code %d (%s)", op, path, errcode, errtext);
ds_send_error(msg, 0);
PR_smprintf_free(msg);
}
/* On Windows and HPUX, if the file/directory to remove is opened by another
application, it cannot be removed and will generate a busy error
This usually happens when we attempt to stop slapd then remove the
instance directory, but for some reason the process still has some
open files
In this case, we need to wait for some period of time then attempt to
remove the instance directory again
*/
if (errcode == PR_FILE_IS_BUSY_ERROR) {
try_rm_rf_again = 1;
return 0; /* just abort the operation */
}
#ifdef XP_WIN32
/* on windows, err 145 means dir not empty
145 The directory is not empty. ERROR_DIR_NOT_EMPTY
If there was a busy file, it wasn't able to be
removed, so when we go to remove the directory, it
won't be empty
*/
if (errcode == ERROR_DIR_NOT_EMPTY) {
if (try_rm_rf_again) {
return 0; /* don't continue */
}
}
#else /* unix */
if (errcode == EEXIST) { /* not empty */
if (try_rm_rf_again) {
return 0; /* don't continue */
}
}
#endif
return 1; /* just continue */
}
int main(int argc, char *argv[])
{
int status = -1;
char *servername;
char *installroot;
int isRunning;
#ifndef __LP64__
#if defined(__hpux) && !defined(__ia64)
_main();
#endif
#endif
#ifdef XP_WIN32
if ( getenv("DEBUG_DSINST") )
DebugBreak();
#endif
/* case 1: being called as program -f inffile */
if (argc > 2 && argv[1][0] == '-' && argv[1][1] ==
'f')
{
FILE *infFile = fopen(argv[2], "r");
if (!infFile)
{
ds_report_error (DS_INCORRECT_USAGE, argv[2],
"This file could not be opened. A valid file must be given.");
status = 1;
return status;
}
else
fclose(infFile);
#if 0
ds_uninst_set_cgi_env(argv[2]);
#else
fprintf(stdout, "Call Uninstall\n");
#endif
} else if (getenv("REQUEST_METHOD")) { /* case 2: called as a CGI */
fprintf(stdout, "Content-type: text/html\n\n");
fflush(stdout);
} else { /* case 3: run from the command line */
/* when being run from the command line, we require many command line arguments */
/* we need to do 2 or three things:
1 - stop the server and remove the server instance directory
2 - remove the server's information from the config ds
3 - On Windows, remove the registry information
We require the instance name as an argument. We also need the following:
For 1, we need the server root
For 2, we need the config ds host, port, admin domain, admin dn, admin password
For 3, just the instance name
There are two other arguments that are optional. -force will ignore errors and just
keep
going. On Windows, -allreg will clean up all known registry information for all
instances
of DS on this machine
*/
}
if ( init_ds_env() ) {
return 1;
}
/*
* Get the server path to delete.
* serverpath = /<server_root>/slapd-<id>
*/
if (!(servername = get_cgi_var("InstanceName", NULL, NULL)))
servername = ds_get_server_name();
/* Check again if the serevr is down or not */
if((isRunning = ds_get_updown_status()) == DS_SERVER_UP) {
if ((status = ds_bring_down_server()) != DS_SERVER_DOWN) {
char buf[1024];
PR_snprintf(buf, sizeof(buf), "Could not stop server: error %d", status);
ds_report_error (DS_GENERAL_FAILURE, servername, buf);
return 1;
}
}
if (servername) {
char line[1024];
int busy_retries = 3; /* if busy, retry this many times */
installroot = ds_get_install_root();
/* We may get busy errors if files are in use when we try
to remove them, so if that happens, sleep for 30 seconds
and try again */
status = ds_rm_rf(installroot, rm_rf_err_func, NULL);
while (status && try_rm_rf_again && busy_retries) {
PR_snprintf(line, sizeof(line), "Some files or directories in %s are still in use.
Will sleep for 30 seconds and try again.",
installroot);
ds_show_message(line);
PR_Sleep(PR_SecondsToInterval(30));
try_rm_rf_again = 0;
--busy_retries;
status = ds_rm_rf(installroot, rm_rf_err_func, NULL);
}
if (status) {
PR_snprintf(line, sizeof(line), "Could not remove %s. Please check log messages
and try again.",
installroot);
ds_send_error(line, 0);
}
}
#ifdef XP_WIN32
if (servername) {
status += ds_remove_reg_key(HKEY_LOCAL_MACHINE, "%s\\%s\\%s\\%s",
KEY_SOFTWARE_NETSCAPE,
DS_NAME_SHORT, DS_VERSION, servername);
/* also try to remove version key in case this is the last instance */
status += ds_remove_reg_key(HKEY_LOCAL_MACHINE, "%s\\%s\\%s",
KEY_SOFTWARE_NETSCAPE,
DS_NAME_SHORT, DS_VERSION);
/* also try to remove product key in case this is the last instance */
status += ds_remove_reg_key(HKEY_LOCAL_MACHINE, "%s\\%s",
KEY_SOFTWARE_NETSCAPE,
DS_NAME_SHORT);
/* also need to remove service */
if (!DeleteServer(servername)) {
status += 1;
}
/* Remove Event Log Key */
status += ds_remove_reg_key(HKEY_LOCAL_MACHINE, "%s\\%s\\%s", KEY_SERVICES,
KEY_EVENTLOG_APP, servername);
}
#endif
if (status == 0) {
char buf[1024];
PR_snprintf(buf, sizeof(buf), "Server %s was successfully removed",
servername);
ds_show_message(buf);
rpt_success("");
} else {
char buf[1024];
PR_snprintf(buf, sizeof(buf), "Could not remove server %s", servername);
ds_send_error(buf, 0);
}
return status;
}
--- NEW FILE ds_rmdb.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Delete backed-up database files.
*
* Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
#ifdef XP_UNIX
#include <unistd.h>
#endif
#ifdef XP_WIN32
#include <direct.h>
#endif
#include "nspr.h"
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
int main(int argc, char *argv[], char *envp[])
{
char *del_file = NULL;
char **bak_files;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
ds_become_localuser (ds_get_config (DS_REAL_CONFIG));
/*
* Get value of the "deletefile" variable.
*/
del_file = get_cgi_var("deletefile", NULL, NULL);
if ( (NULL == del_file) || (strlen(del_file) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "deletefile", NULL, NULL );
return 1;
}
bak_files = ds_get_file_list( del_file );
if ( bak_files == NULL ) {
rpt_err( DS_NO_SUCH_FILE, del_file, NULL, NULL );
return 1;
} else {
int j;
char buf[ MAXPATHLEN ];
for ( j = 0; bak_files[ j ] != NULL; j++ ) {
PR_snprintf( buf, sizeof(buf), "%s/%s", del_file, bak_files[ j ]);
if ( unlink(buf) != 0 ) {
rpt_err( DS_CANNOT_DELETE_FILE, buf, NULL, NULL );
return 1;
}
}
if ( rmdir( del_file ) < 0 ) {
rpt_err( DS_CANNOT_DELETE_FILE, del_file, NULL, NULL );
return 1;
}
}
rpt_success("Success! Deleted directory.");
return 0;
}
--- NEW FILE ds_snmpctrl.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* snmpctrl.c - start/stop/restart LDAP-based SNMP subagent
*
* Steve Ross -- 08/12/97
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include "nspr.h"
#if !defined(_WIN32)
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#else
#include <windows.h>
#endif
#define SUBAGT_PATH "bin/slapd/server"
#define SUBAGT_NAME "ns-ldapagt"
#define START 1
#define STOP 2
#define RESTART 3
#define NSLDAPAGT_PID "NSLDAPAGT.LK"
#ifdef __cplusplus
extern "C" {
#endif
int nsldapagt_is_running(void);
int nsldapagt_shutdown(void);
int nsldapagt_start(void);
int nsldapagt_restart(void);
#ifdef __cplusplus
}
#endif
int main(int argc, char *argv[])
{
char *action_type = NULL;
int status = 1;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
action_type = get_cgi_var("ACTION", "Missing Command",
"Need to specify Start, Stop, or Restart");
if (!action_type)
return 1;
if (!strcmp(action_type, "START")) {
status = nsldapagt_start();
} else if (!strcmp(action_type, "STOP")) {
status = nsldapagt_shutdown();
} else if (!strcmp(action_type, "RESTART")) {
status = nsldapagt_restart();
} else {
status = DS_UNKNOWN_SNMP_COMMAND;
}
if ( !status ) {
rpt_success("Success!");
return 0;
} else {
rpt_err( status, action_type, NULL, NULL );
return 1;
}
}
#if !defined(_WIN32)
int
get_nsldapagt_pid(pid_t *pid)
{
char *SLAPD_ROOT;
char path[PATH_MAX];
FILE *fp;
*pid = -1;
SLAPD_ROOT = ds_get_install_root();
PR_snprintf(path, sizeof(path), "%s/logs/%s", SLAPD_ROOT, NSLDAPAGT_PID);
if (!ds_file_exists(path)) {
return(-1);
}
if ((fp = fopen(path, "r")) != (FILE *) NULL) {
if ((fscanf(fp, "%d\n", (int *) pid)) != -1) {
(void) fclose(fp);
return(0);
}
}
(void) fclose(fp);
return(-1);
}
#endif
#if defined(_WIN32)
BOOL isServiceRunning(LPCTSTR szServiceId)
{
BOOL bReturn = FALSE;
DWORD dwError = 0;
SC_HANDLE schService = NULL;
SC_HANDLE schSCManager = NULL;
SERVICE_STATUS lpss;
if((schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))
{
if((schService = OpenService(schSCManager,
szServiceId,
SERVICE_ALL_ACCESS)))
{
bReturn = ControlService(schService, SERVICE_CONTROL_INTERROGATE , &lpss);
if(SERVICE_RUNNING == lpss.dwCurrentState)
{
bReturn = TRUE;
}
CloseServiceHandle(schService);
}
dwError = GetLastError();
CloseServiceHandle(schSCManager);
}
return(bReturn);
}
#endif
/*
* This routine returns:
* 0 if nsldapagt is NOT running
* 1 if nsldapagt is actually running
*/
int
nsldapagt_is_running()
{
#if defined(_WIN32)
if (FALSE == isServiceRunning("SNMP") )
{
return(0);
}
#else
pid_t pid;
if (get_nsldapagt_pid(&pid) != 0) {
return(0);
}
if (kill(pid, 0) == -1) {
return(0);
}
#endif
return(1);
}
#if !defined(_WIN32)
/*
* This routine returns:
* 0 if magt is NOT running
* 1 if magt is actually running
*
* The run state is determined whether one can successfully bind to the
* smux port.
*
* this is for UNIX only
*/
int
smux_master_is_running()
{
struct servent *pse;
struct protoent *ppe;
struct sockaddr_in sin;
int s;
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
if ((pse = getservbyname("smux", "tcp"))) {
sin.sin_port = ntohs(pse->s_port);
} else {
sin.sin_port = 199;
}
if ((ppe = getprotobyname("tcp")) == 0) {
return(0);
}
if ((s = socket(AF_INET, SOCK_STREAM, ppe->p_proto)) < 0) {
return(0);
}
/* bind expects port number to be in network order
we should do this for all platforms, not just OSF. */
sin.sin_port = htons(sin.sin_port);
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
close(s);
return(1);
} else {
}
close(s);
return(0);
}
#endif
int
nsldapagt_start()
{
if (nsldapagt_is_running()) {
return(0);
}
#if defined(_WIN32)
/* NT version -- just try to start the SNMP service */
/* Bug 612322: redirecting the output to null device */
system("net start SNMP > nul");
#else
/*
* Check if smux master agent is running before firing off the subagent!
*/
if (!smux_master_is_running()) {
return(-1);
} else {
char *NETSITE_ROOT = getenv("NETSITE_ROOT");
char *SLAPD_ROOT = ds_get_install_root();
char command[1024];
PR_snprintf(command, sizeof(command), "cd %s/%s; ./%s -d %s", NETSITE_ROOT,
SUBAGT_PATH,
SUBAGT_NAME, SLAPD_ROOT);
(void) system(command);
sleep(2);
}
#endif
if (!nsldapagt_is_running()) {
return(-1);
}
return(0);
}
int
nsldapagt_shutdown()
{
if (!nsldapagt_is_running()) {
rpt_success("NOT_RUNNING");
exit(0);
} else {
int status = -1;
#if defined(_WIN32)
/* NT version -- just try to stop the SNMP service */
/* Bug 612322: redirecting the output to null device */
status = system("net stop SNMP > nul");
#else
/* UNIX version */
pid_t pid;
if (get_nsldapagt_pid(&pid) == 0)
{
if (kill(pid, SIGTERM) == 0)
{
sleep(2);
if (!nsldapagt_is_running())
{
status = 0;
}
}
}
#endif
return(status);
}
return(0);
}
int
nsldapagt_restart()
{
int status;
if ( (status = nsldapagt_shutdown()) != 0 )
return status;
else
return nsldapagt_start();
}
--- NEW FILE init_ds_env.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Set up environment for CGIs.
*
* Rob Weltman
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "libadminutil/distadm.h"
#include "init_ds_env.h"
#include "dsalib.h"
#include "prprf.h"
int init_ds_env()
{
char *m = getenv("REQUEST_METHOD");
char *qs = NULL;
int proceed = 0;
(void)ADMUTIL_Init();
if ( m != NULL ) {
if( !strcmp(m, "GET") ) {
qs = GET_QUERY_STRING();
if ( qs && *qs ) {
get_begin(qs);
}
proceed = 1;
} else if(!strcmp(m, "POST")) {
if (post_begin(stdin)) {
proceed = 0;
} else {
proceed = 1;
}
}
}
if(!proceed) {
char msg[2000];
PR_snprintf(msg, sizeof(msg), "ErrorString: REQUEST_METHOD=%s,"
"QUERY_STRING=%s\n",
(m == NULL) ? "<undefined>" : m,
(qs == NULL) ? "<undefined>" : qs);
rpt_err( GENERAL_FAILURE,
msg,
"",
"" );
return 1;
}
return 0;
}
--- NEW FILE init_ds_env.h ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* Set up environment for CGIs.
*
* Rob Weltman
*/
extern int init_ds_env();
--- NEW FILE restart.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* restart.c: Stops and the starts up the server.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#ifdef XP_WIN32
#define sleep(sec) Sleep(sec)
#endif
int main(int argc, char *argv[])
{
int status = -1;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
if (DS_SERVER_UP == ds_get_updown_status()) {
status = ds_bring_down_server();
if(status != DS_SERVER_DOWN) {
rpt_err( status, "", NULL, NULL );
return 1;
}
}
status = ds_bring_up_server(1);
if(status == DS_SERVER_UP) {
rpt_success("Success! The server has been restarted.");
return 0;
} else {
rpt_err( status, "", NULL, NULL );
return 1;
}
}
--- NEW FILE shutdown.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* shutdown.c: Kills the server.
*
* DS changes: Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
* Mike McCool
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
int main(int argc, char *argv[])
{
int status = -1;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
status = ds_bring_down_server();
if(status == DS_SERVER_DOWN) {
rpt_success("Success! The server has been shut down.");
return 0;
} else {
rpt_err( status, "", NULL, NULL );
return 1;
}
}
--- NEW FILE start.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* start.c: Starts up the server.
*
* DS changes: Anil Bhavnani
* Removed all HTML output for DS 4.0: Rob Weltman
* Mike McCool
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
int main(int argc, char *argv[])
{
int status = -1;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 0;
status = ds_bring_up_server(1);
if(status == DS_SERVER_UP) {
rpt_success("Success! The server has been started.");
return 0;
} else {
rpt_err( status, "", NULL, NULL );
return 1;
}
}
--- NEW FILE vlvindex.c ---
/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* In addition, as a special exception, Red Hat, Inc. gives You the additional
* right to link the code of this Program with code not covered under the GNU
* General Public License ("Non-GPL Code") and to distribute linked
combinations
* including the two, subject to the limitations in this paragraph. Non-GPL Code
* permitted under this exception must only link to the code of this Program
* through those well defined interfaces identified in the file named EXCEPTION
* found in the source code files (the "Approved Interfaces"). The files of
* Non-GPL Code may instantiate templates or use macros or inline functions from
* the Approved Interfaces without causing the resulting work to be covered by
* the GNU General Public License. Only Red Hat, Inc. may make changes or
* additions to the list of Approved Interfaces. You must obey the GNU General
* Public License in all respects for all of the Program code and other code used
* in conjunction with the Program except the Non-GPL Code covered by this
* exception. If you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you do not wish to
* provide this exception without modification, you must delete this exception
* statement from your version and license this file solely under the GPL without
* exception.
*
*
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
* vlvindex.c: Creates a VLV index for a given search
*
* Rob Weltman
*/
#include <stdio.h>
#include <stdlib.h>
#include "libadminutil/admutil.h"
#include "dsalib.h"
#include "init_ds_env.h"
#include <string.h>
int main(int argc, char *argv[])
{
int status;
char *backendNames = NULL;
char *attributes = NULL;
char *tmparg = NULL;
char **attrList = NULL;
char **backendList = NULL;
int nItem = 0;
char *nextItem = NULL;
int i=0;
fprintf(stdout, "Content-type: text/html\n\n");
if ( init_ds_env() )
return 1;
ds_send_status("Creating vlv index ...");
/*
* Get var's value
*/
backendNames = get_cgi_var("backendID", NULL, NULL);
if ( (NULL == backendNames) || (strlen(backendNames) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "backendID", NULL, NULL );
return 1;
}
attributes = get_cgi_var("vlvTags", NULL, NULL);
if ( (NULL == attributes) || (strlen(attributes) < 1) ) {
rpt_err( DS_UNDEFINED_VARIABLE, "vlvTags", NULL, NULL );
return 1;
}
tmparg = strdup( attributes );
nItem = 0;
for(i=0 ; i < strlen(attributes) ; i++) {
if ( tmparg[i] == ';' ) nItem++;
}
/* Allocate for worst possible case */
attrList = (char **)malloc(sizeof(*attrList) * (nItem + 2) );
nItem = 0;
/* strtok() is not MT safe, but it is okay to call here because this is a command line
*/
attrList[nItem++] = strtok( tmparg, ";" );
do {
nextItem = strtok( NULL, ";" );
attrList[nItem++] = nextItem;
} while( nextItem != NULL );
tmparg = strdup( backendNames );
nItem = 0;
for(i=0;i<strlen(tmparg); i++) {
if ( tmparg[i] == ';' ) nItem++;
}
backendList = (char **)malloc(sizeof(*backendList) * nItem + 2);
nItem = 0;
backendList[nItem++] = strtok( tmparg, ";" );
do {
nextItem = strtok( NULL, ";" );
backendList[nItem++] = nextItem;
} while( nextItem != NULL );
status = ds_vlvindex(backendList, attrList);
if ( !status ) {
rpt_success("Success! The index has been created.");
status = 0;
} else {
rpt_err( status, backendList[0], NULL, NULL );
status = 1;
}
return status;
}