/**
* PROPRIETARY/CONFIDENTIAL. Use of this product is subject to
* license terms. Copyright © 2001 Sun Microsystems, Inc.
* Some preexisting portions Copyright © 2001 Netscape Communications Corp.
* All rights reserved.
*/
/*
* error.c -- error handling functions -- HTTP gateway
*
* Copyright (c) 1996 Netscape Communications Corp.
* All rights reserved.
*/
#include "dsgw.h"
#include "dbtdsgw.h"
static char *dsgw_ldaperr2longstring( int err, int options );
struct dsgwerr {
int dsgwerr_code;
int dsgwerr_msg;
};
/* all of the DSGW_ERR_... #defines are in dsgw.h */
static struct dsgwerr dsgw_errs[] = {
{ DSGW_ERR_BADMETHOD,
DBT_unknownHttpRequestMethod_ },
{ DSGW_ERR_BADFORMDATA,
DBT_invalidOrIncompleteHtmlFormData_ },
{ DSGW_ERR_NOMEMORY,
DBT_outOfMemory_ },
{ DSGW_ERR_MISSINGINPUT,
DBT_requiredQueryFormInputIsMissing_ },
{ DSGW_ERR_BADFILEPATH,
DBT_illegalCharacterInFilePath_ },
{ DSGW_ERR_BADCONFIG,
DBT_badOrMissingConfigurationFile_ },
{ DSGW_ERR_LDAPINIT,
DBT_unableToInitializeLdap_ },
{ DSGW_ERR_LDAPGENERAL,
DBT_anErrorOccurredWhileContactingTh_ },
{ DSGW_ERR_UNKSRCHTYPE,
DBT_unknownSearchObjectType_ },
{ DSGW_ERR_UNKATTRLABEL,
DBT_unknownAttributeLabel_ },
{ DSGW_ERR_UNKMATCHPROMPT,
DBT_unknownMatchPrompt_ },
{ DSGW_ERR_NOFILTERS,
DBT_noSearchFiltersForObjectType_ },
{ DSGW_ERR_OPENHTMLFILE,
DBT_unableToOpenHtmlTemplateFile_ },
{ DSGW_ERR_SEARCHMODE,
DBT_unknownSearchModeUseSmartComplex_ },
{ DSGW_ERR_LDAPURL_NODN,
DBT_distinguishedNameMissingInUrl_ },
{ DSGW_ERR_LDAPURL_BADSCOPE,
DBT_unknownScopeInUrlShouldBeBaseSub_ },
{ DSGW_ERR_LDAPURL_NOTLDAP,
DBT_unrecognizedUrlOrUnknownError_ },
{ DSGW_ERR_LDAPURL_BAD,
DBT_badUrlFormat_ },
{ DSGW_ERR_INTERNAL,
DBT_internalError_ },
{ DSGW_ERR_WRITEINDEXFILE,
DBT_unableToWriteTemplateIndexFile_ },
{ DSGW_ERR_OPENINDEXFILE,
DBT_unableToOpenTemplateIndexFile_ },
{ DSGW_ERR_OPENDIR,
DBT_unableToReadDirectory_ },
{ DSGW_ERR_SSLINIT,
DBT_ldapSslInitializationFailedCheck_ },
{ DSGW_ERR_NOSECPATH,
DBT_forTheUsersAndGroupsFormsToWorkO_ },
{ DSGW_CKDB_KEY_NOT_PRESENT,
DBT_authenticationCredentialsNotFoun_ },
{ DSGW_CKDB_DBERROR,
DBT_errorRetrievingDataFromTheAuthen_ },
{ DSGW_CKDB_EXPIRED,
DBT_yourAuthenticationCredentialsHav_ },
{ DSGW_CKDB_RNDSTRFAIL,
DBT_unableToCreateRandomString_ },
{ DSGW_CKDB_NODN,
DBT_noDistinguishedNameWasProvidedWh_ },
{ DSGW_CKDB_CANTOPEN,
DBT_cannotOpenAuthenticationDatabase_ },
{ DSGW_CKDB_CANTAPPEND,
DBT_couldNotAppendDataToTheAuthentic_ },
{ DSGW_ERR_NO_MGRDN,
DBT_noDirectoryManagerIsDefined_ },
{ DSGW_ERR_NOSEARCHSTRING,
DBT_noSearchStringWasProvidedPleaseT_ },
{ DSGW_ERR_CONFIGTOOMANYARGS,
DBT_tooManyArgumentsOnOneLineInTheCo_ },
{ DSGW_ERR_WSAINIT,
DBT_failedToInitializeWindowsSockets_ },
{ DSGW_ERR_ADMSERV_CREDFAIL,
DBT_authenticationCredentialsCouldNo_ },
{ DSGW_ERR_LDAPDBURL_NODN,
DBT_distinguishedNameMissingInLdapdb_ },
{ DSGW_ERR_LDAPDBURL_NOTLDAPDB,
DBT_unrecognizedUrlOrUnknownError_1 },
{ DSGW_ERR_LDAPDBURL_BAD,
DBT_badUrlFormat_1 },
{ DSGW_ERR_LCACHEINIT,
DBT_anErrorOccurredWhileInitializing_ },
{ DSGW_ERR_SERVICETYPE,
DBT_unknownDirectoryServiceTypeUseLo_ },
{ DSGW_ERR_DBCONF,
DBT_anErrorOccurredWhileReadingTheDb_ },
{ DSGW_ERR_USERDB_PATH,
DBT_nshomeUserdbPathWasNull_ },
{ DSGW_ERR_UPDATE_DBSWITCH,
DBT_theDirectoryServiceConfiguration_ },
{ DSGW_ERR_ENTRY_NOT_FOUND,
DBT_theEntryCouldNotBeReadFromTheDir_ },
{ DSGW_ERR_DB_ERASE,
DBT_theLdapDatabaseCouldNotBeErased_ },
{ DSGW_ERR_LOCALDB_PERMISSION_DENIED,
DBT_youMayNotChangeEntriesBesidesYou_ },
{ DSGW_ERR_NOATTRVALUE,
DBT_theAttributeValueRequestedWasNot_ },
{ DSGW_ERR_USERID_REQUIRED,
/* "A value must be specified for NT User Id" */
DBT_aValueMustBeSpecifiedForNTUserId },
{ DSGW_ERR_DOMAINID_NOTUNIQUE,
/* "The combination of NT User Id, NT Domain Id */
/* is not unique in the directory" */
DBT_theCombinationOfNTUserIdNTDomain_ },
{ DSGW_ERR_USERID_DOMAINID_REQUIRED,
/* "Values must be specified for both NT */
/* User Id and NT Domain Id" */
DBT_valuesMustBeSpecifiedForBothNTUser_ },
{ DSGW_ERR_USERID_MAXLEN_EXCEEDED,
/* "The NT User Id value must not exceed 20 characters in length." */
DBT_theNTUserIdValueMustNotExceed_ },
{ DSGW_ERR_CHARSET_NOT_SUPPORTED,
/* "The charset %s is not supported" */
DBT_theCharsetIsNotSupported },
};
#define DSGW_ERROR_CNT ( sizeof( dsgw_errs ) / sizeof( struct dsgwerr ))
/*
* dsgw_error -- report error as HTML text
*/
void
dsgw_error( int err, char *extra, int options, int ldaperr, char *lderrtxt )
{
char *msg, *prelude = XP_GetClientStr(DBT_problem_);
if (( options & DSGW_ERROPT_IGNORE ) != 0 ) {
return;
}
if (( options & DSGW_ERROPT_INLINE ) == 0 ) {
dsgw_send_header();
dsgw_html_begin( prelude, 1 );
}
msg = dsgw_err2string( err );
dsgw_emitf( "\n%s\n\n", msg );
if ( extra != NULL ) {
if ( lderrtxt == NULL ) {
dsgw_emitf( "
(%s)", extra );
} else {
dsgw_emitf( "
(%s - %s)", extra, lderrtxt );
}
} else if ( lderrtxt != NULL ) {
dsgw_emitf( "
(%s)", lderrtxt );
}
#ifdef DSGW_DEBUG
if ( extra == NULL ) {
dsgw_log( "%s: %s\n", prelude, msg );
} else {
dsgw_log( "%s: %s (%s)\n", prelude, msg, extra );
}
#endif
if ( ldaperr != 0 ) {
msg = dsgw_ldaperr2longstring( ldaperr, options );
dsgw_emitf("
%s", msg ); } if (( options & DSGW_ERROPT_INLINE ) == 0 ) { dsgw_html_end(); } if (( options & DSGW_ERROPT_EXIT ) != 0 ) { exit( 0 ); } } /* * special handling for cookie expired or cookie database problems * delete cookie on both server and client * send helpful error with appropriate buttons: * * if searching, display an error message, and a re-auth button, along * with a help button. * * if authenticating, (does this ever happen?) * * if generating an editable view, display an error messge, and tell * user to bring main window to front and requthenticate. * * if submitting a modify operation, include an "Authenticate" button * which brings up a new auth window, which only offers you a * "close" button when finished. * * returns 1 if the CGI should exit. * 0 if it should continue. - RJP */ int dsgw_dn2passwd_error( int ckrc, int skipauthwarning ) { char *authck; /* * cookie is expired or bad -- delete it on both server and client sides * */ if (( authck = dsgw_get_auth_cookie()) != NULL ) { dsgw_delcookie( authck ); } /* pop up a javascript alert */ if (gc->gc_mode == DSGW_MODE_DOSEARCH) { /* Just display a helpful error message */ if (ckrc != DSGW_CKDB_KEY_NOT_PRESENT && !skipauthwarning) { dsgw_send_header(); dsgw_emit_alertForm(); dsgw_emits( "\n"); } return(0); } dsgw_send_header(); dsgw_html_begin( XP_GetClientStr(DBT_authenticationProblem_), 1 ); dsgw_emits( "\n" ); dsgw_emits( dsgw_err2string( ckrc ) ); if (gc->gc_mode == DSGW_MODE_EDIT || gc->gc_mode == DSGW_MODE_DOMODIFY) { dsgw_emits( XP_GetClientStr(DBT_NPYouMustReAuthenticateBeforeCon_1) ); dsgw_emits( "
\n" ); dsgw_form_begin( NULL, NULL ); dsgw_emits("\n
\n" ); dsgw_emitf( "\n", XP_GetClientStr(DBT_closeWindow_4) ); dsgw_emits( " | \n" ); dsgw_emit_helpbutton( "AUTHEXPIRED" ); dsgw_emits( "\n |