error.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /** --- BEGIN COPYRIGHT BLOCK ---
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. --- END COPYRIGHT BLOCK --- */
  38. /*
  39. * error.c -- error handling functions -- HTTP gateway
  40. */
  41. #include "dsgw.h"
  42. #include "dbtdsgw.h"
  43. static char *dsgw_ldaperr2longstring( int err, int options );
  44. struct dsgwerr {
  45. int dsgwerr_code;
  46. int dsgwerr_msg;
  47. };
  48. /* all of the DSGW_ERR_... #defines are in dsgw.h */
  49. static struct dsgwerr dsgw_errs[] = {
  50. { DSGW_ERR_BADMETHOD,
  51. DBT_unknownHttpRequestMethod_ },
  52. { DSGW_ERR_BADFORMDATA,
  53. DBT_invalidOrIncompleteHtmlFormData_ },
  54. { DSGW_ERR_NOMEMORY,
  55. DBT_outOfMemory_ },
  56. { DSGW_ERR_MISSINGINPUT,
  57. DBT_requiredQueryFormInputIsMissing_ },
  58. { DSGW_ERR_BADFILEPATH,
  59. DBT_illegalCharacterInFilePath_ },
  60. { DSGW_ERR_BADCONFIG,
  61. DBT_badOrMissingConfigurationFile_ },
  62. { DSGW_ERR_LDAPINIT,
  63. DBT_unableToInitializeLdap_ },
  64. { DSGW_ERR_LDAPGENERAL,
  65. DBT_anErrorOccurredWhileContactingTh_ },
  66. { DSGW_ERR_UNKSRCHTYPE,
  67. DBT_unknownSearchObjectType_ },
  68. { DSGW_ERR_UNKATTRLABEL,
  69. DBT_unknownAttributeLabel_ },
  70. { DSGW_ERR_UNKMATCHPROMPT,
  71. DBT_unknownMatchPrompt_ },
  72. { DSGW_ERR_NOFILTERS,
  73. DBT_noSearchFiltersForObjectType_ },
  74. { DSGW_ERR_OPENHTMLFILE,
  75. DBT_unableToOpenHtmlTemplateFile_ },
  76. { DSGW_ERR_SEARCHMODE,
  77. DBT_unknownSearchModeUseSmartComplex_ },
  78. { DSGW_ERR_LDAPURL_NODN,
  79. DBT_distinguishedNameMissingInUrl_ },
  80. { DSGW_ERR_LDAPURL_BADSCOPE,
  81. DBT_unknownScopeInUrlShouldBeBaseSub_ },
  82. { DSGW_ERR_LDAPURL_NOTLDAP,
  83. DBT_unrecognizedUrlOrUnknownError_ },
  84. { DSGW_ERR_LDAPURL_BAD,
  85. DBT_badUrlFormat_ },
  86. { DSGW_ERR_INTERNAL,
  87. DBT_internalError_ },
  88. { DSGW_ERR_WRITEINDEXFILE,
  89. DBT_unableToWriteTemplateIndexFile_ },
  90. { DSGW_ERR_OPENINDEXFILE,
  91. DBT_unableToOpenTemplateIndexFile_ },
  92. { DSGW_ERR_OPENDIR,
  93. DBT_unableToReadDirectory_ },
  94. { DSGW_ERR_SSLINIT,
  95. DBT_ldapSslInitializationFailedCheck_ },
  96. { DSGW_ERR_NOSECPATH,
  97. DBT_forTheUsersAndGroupsFormsToWorkO_ },
  98. { DSGW_CKDB_KEY_NOT_PRESENT,
  99. DBT_authenticationCredentialsNotFoun_ },
  100. { DSGW_CKDB_DBERROR,
  101. DBT_errorRetrievingDataFromTheAuthen_ },
  102. { DSGW_CKDB_EXPIRED,
  103. DBT_yourAuthenticationCredentialsHav_ },
  104. { DSGW_CKDB_RNDSTRFAIL,
  105. DBT_unableToCreateRandomString_ },
  106. { DSGW_CKDB_NODN,
  107. DBT_noDistinguishedNameWasProvidedWh_ },
  108. { DSGW_CKDB_CANTOPEN,
  109. DBT_cannotOpenAuthenticationDatabase_ },
  110. { DSGW_CKDB_CANTAPPEND,
  111. DBT_couldNotAppendDataToTheAuthentic_ },
  112. { DSGW_ERR_NO_MGRDN,
  113. DBT_noDirectoryManagerIsDefined_ },
  114. { DSGW_ERR_NOSEARCHSTRING,
  115. DBT_noSearchStringWasProvidedPleaseT_ },
  116. { DSGW_ERR_CONFIGTOOMANYARGS,
  117. DBT_tooManyArgumentsOnOneLineInTheCo_ },
  118. { DSGW_ERR_WSAINIT,
  119. DBT_failedToInitializeWindowsSockets_ },
  120. { DSGW_ERR_ADMSERV_CREDFAIL,
  121. DBT_authenticationCredentialsCouldNo_ },
  122. { DSGW_ERR_LDAPDBURL_NODN,
  123. DBT_distinguishedNameMissingInLdapdb_ },
  124. { DSGW_ERR_LDAPDBURL_NOTLDAPDB,
  125. DBT_unrecognizedUrlOrUnknownError_1 },
  126. { DSGW_ERR_LDAPDBURL_BAD,
  127. DBT_badUrlFormat_1 },
  128. { DSGW_ERR_LCACHEINIT,
  129. DBT_anErrorOccurredWhileInitializing_ },
  130. { DSGW_ERR_SERVICETYPE,
  131. DBT_unknownDirectoryServiceTypeUseLo_ },
  132. { DSGW_ERR_DBCONF,
  133. DBT_anErrorOccurredWhileReadingTheDb_ },
  134. { DSGW_ERR_USERDB_PATH,
  135. DBT_nshomeUserdbPathWasNull_ },
  136. { DSGW_ERR_UPDATE_DBSWITCH,
  137. DBT_theDirectoryServiceConfiguration_ },
  138. { DSGW_ERR_ENTRY_NOT_FOUND,
  139. DBT_theEntryCouldNotBeReadFromTheDir_ },
  140. { DSGW_ERR_DB_ERASE,
  141. DBT_theLdapDatabaseCouldNotBeErased_ },
  142. { DSGW_ERR_LOCALDB_PERMISSION_DENIED,
  143. DBT_youMayNotChangeEntriesBesidesYou_ },
  144. { DSGW_ERR_NOATTRVALUE,
  145. DBT_theAttributeValueRequestedWasNot_ },
  146. { DSGW_ERR_USERID_REQUIRED,
  147. /* "A value must be specified for NT User Id" */
  148. DBT_aValueMustBeSpecifiedForNTUserId },
  149. { DSGW_ERR_DOMAINID_NOTUNIQUE,
  150. /* "The combination of NT User Id, NT Domain Id */
  151. /* is not unique in the directory" */
  152. DBT_theCombinationOfNTUserIdNTDomain_ },
  153. { DSGW_ERR_USERID_DOMAINID_REQUIRED,
  154. /* "Values must be specified for both NT */
  155. /* User Id and NT Domain Id" */
  156. DBT_valuesMustBeSpecifiedForBothNTUser_ },
  157. { DSGW_ERR_USERID_MAXLEN_EXCEEDED,
  158. /* "The NT User Id value must not exceed 20 characters in length." */
  159. DBT_theNTUserIdValueMustNotExceed_ },
  160. { DSGW_ERR_CHARSET_NOT_SUPPORTED,
  161. /* "The charset %s is not supported" */
  162. DBT_theCharsetIsNotSupported },
  163. };
  164. #define DSGW_ERROR_CNT ( sizeof( dsgw_errs ) / sizeof( struct dsgwerr ))
  165. /*
  166. * dsgw_error -- report error as HTML text
  167. */
  168. void
  169. dsgw_error( int err, char *extra, int options, int ldaperr, char *lderrtxt )
  170. {
  171. char *msg, *prelude = XP_GetClientStr(DBT_problem_);
  172. if (( options & DSGW_ERROPT_IGNORE ) != 0 ) {
  173. return;
  174. }
  175. if (( options & DSGW_ERROPT_INLINE ) == 0 ) {
  176. dsgw_send_header();
  177. dsgw_html_begin( prelude, 1 );
  178. }
  179. msg = dsgw_err2string( err );
  180. dsgw_emitf( "<FONT SIZE=\"+1\">\n%s\n</FONT>\n", msg );
  181. if ( extra != NULL ) {
  182. if ( lderrtxt == NULL ) {
  183. dsgw_emitf( "<BR>(%s)", extra );
  184. } else {
  185. dsgw_emitf( "<BR>(%s - %s)", extra, lderrtxt );
  186. }
  187. } else if ( lderrtxt != NULL ) {
  188. dsgw_emitf( "<BR>(%s)", lderrtxt );
  189. }
  190. #ifdef DSGW_DEBUG
  191. if ( extra == NULL ) {
  192. dsgw_log( "%s: %s\n", prelude, msg );
  193. } else {
  194. dsgw_log( "%s: %s (%s)\n", prelude, msg, extra );
  195. }
  196. #endif
  197. if ( ldaperr != 0 ) {
  198. msg = dsgw_ldaperr2longstring( ldaperr, options );
  199. dsgw_emitf("<P>%s", msg );
  200. }
  201. if (( options & DSGW_ERROPT_INLINE ) == 0 ) {
  202. dsgw_html_end();
  203. }
  204. if (( options & DSGW_ERROPT_EXIT ) != 0 ) {
  205. exit( 0 );
  206. }
  207. }
  208. /*
  209. * special handling for cookie expired or cookie database problems
  210. * delete cookie on both server and client
  211. * send helpful error with appropriate buttons:
  212. * * if searching, display an error message, and a re-auth button, along
  213. * with a help button.
  214. * * if authenticating, (does this ever happen?)
  215. * * if generating an editable view, display an error messge, and tell
  216. * user to bring main window to front and requthenticate.
  217. * * if submitting a modify operation, include an "Authenticate" button
  218. * which brings up a new auth window, which only offers you a
  219. * "close" button when finished.
  220. *
  221. * returns 1 if the CGI should exit.
  222. * 0 if it should continue. - RJP
  223. */
  224. int
  225. dsgw_dn2passwd_error( int ckrc, int skipauthwarning )
  226. {
  227. char *authck;
  228. /*
  229. * cookie is expired or bad -- delete it on both server and client sides
  230. *
  231. */
  232. if (( authck = dsgw_get_auth_cookie()) != NULL ) {
  233. dsgw_delcookie( authck );
  234. }
  235. /* pop up a javascript alert */
  236. if (gc->gc_mode == DSGW_MODE_DOSEARCH) {
  237. /* Just display a helpful error message */
  238. if (ckrc != DSGW_CKDB_KEY_NOT_PRESENT && !skipauthwarning) {
  239. dsgw_send_header();
  240. dsgw_emit_alertForm();
  241. dsgw_emits( "<SCRIPT LANGUAGE=JavaScript><!--\n" );
  242. dsgw_emit_alert (NULL, NULL, dsgw_err2string( ckrc ),
  243. 0L, "", "", "");
  244. dsgw_emits( "// -->\n</SCRIPT>\n");
  245. }
  246. return(0);
  247. }
  248. dsgw_send_header();
  249. dsgw_html_begin( XP_GetClientStr(DBT_authenticationProblem_), 1 );
  250. dsgw_emits( "<SCRIPT LANGUAGE=\"JavaScript\">\n<!-- hide\n\n" );
  251. dsgw_emitf( "document.cookie = '%s=%s; path=/';\n\n", DSGW_AUTHCKNAME,
  252. DSGW_UNAUTHSTR );
  253. dsgw_emits( "function reAuth()\n{\n" );
  254. dsgw_emitf( " a = open( '%s?context=%s', 'AuthWin');\n",
  255. dsgw_getvp( DSGW_CGINUM_AUTH ), context);
  256. dsgw_emits( " a.opener = self;\n" );
  257. dsgw_emits( " a.closewin = false;\n" );
  258. dsgw_emits( "}\n// end hiding -->\n</SCRIPT>\n" );
  259. dsgw_emits( dsgw_err2string( ckrc ) );
  260. if (gc->gc_mode == DSGW_MODE_EDIT || gc->gc_mode == DSGW_MODE_DOMODIFY) {
  261. dsgw_emits( XP_GetClientStr(DBT_NPYouMustReAuthenticateBeforeCon_1) );
  262. dsgw_emits( "<P>\n" );
  263. dsgw_form_begin( NULL, NULL );
  264. dsgw_emits("\n<CENTER><TABLE border=2 width=\"100%\"><TR>\n" );
  265. dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
  266. dsgw_emitf( "<INPUT TYPE=\"button\" VALUE=\"%s\" "
  267. "onClick=\"top.close();\">\n",
  268. XP_GetClientStr(DBT_closeWindow_4) );
  269. dsgw_emits( "<TD WIDTH=\"50%\" ALIGN=\"center\">\n" );
  270. dsgw_emit_helpbutton( "AUTHEXPIRED" );
  271. dsgw_emits( "\n</TABLE></CENTER></FORM>\n" );
  272. }
  273. dsgw_html_end();
  274. return(1);
  275. }
  276. char *
  277. dsgw_err2string( int err )
  278. {
  279. int i;
  280. for ( i = 0; i < DSGW_ERROR_CNT; ++i ) {
  281. if ( dsgw_errs[ i ].dsgwerr_code == err ) {
  282. return( XP_GetClientStr(dsgw_errs[ i ].dsgwerr_msg) );
  283. }
  284. }
  285. return( XP_GetClientStr(DBT_unknownError_) );
  286. }
  287. static char *
  288. dsgw_ldaperr2longstring( int err, int options )
  289. {
  290. char *s = "";
  291. switch ( err ) {
  292. case LDAP_SUCCESS:
  293. s = XP_GetClientStr(DBT_theOperationWasSuccessful_);
  294. break;
  295. case LDAP_OPERATIONS_ERROR:
  296. s = XP_GetClientStr(DBT_anInternalErrorOccurredInTheServ_);
  297. break;
  298. case LDAP_PROTOCOL_ERROR:
  299. s = XP_GetClientStr(DBT_theServerCouldNotUnderstandTheRe_);
  300. break;
  301. case LDAP_TIMELIMIT_EXCEEDED:
  302. s = XP_GetClientStr(DBT_aTimeLimitWasExceededInRespondin_);
  303. break;
  304. case LDAP_SIZELIMIT_EXCEEDED:
  305. s = XP_GetClientStr(DBT_aSizeLimitWasExceededInRespondin_);
  306. break;
  307. case LDAP_COMPARE_FALSE:
  308. break;
  309. case LDAP_COMPARE_TRUE:
  310. break;
  311. case LDAP_STRONG_AUTH_NOT_SUPPORTED:
  312. s = XP_GetClientStr(DBT_theGatewayAttemptedToAuthenticat_);
  313. break;
  314. case LDAP_STRONG_AUTH_REQUIRED:
  315. s = XP_GetClientStr(DBT_theGatewayAttemptedToAuthenticat_1);
  316. break;
  317. #ifdef LDAP_REFERRAL /* new in LDAPv3 */
  318. case LDAP_REFERRAL:
  319. #endif
  320. case LDAP_PARTIAL_RESULTS:
  321. s = XP_GetClientStr(DBT_yourRequestCouldNotBeFulfilledPr_);
  322. break;
  323. #ifdef LDAP_ADMIN_LIMIT_EXCEEDED /* new in LDAPv3 */
  324. case LDAP_ADMIN_LIMIT_EXCEEDED:
  325. s = XP_GetClientStr(DBT_yourRequestExceededAnAdministrat_);
  326. break;
  327. #endif
  328. #ifdef LDAP_UNAVAILABLE_CRITICAL_EXTENSION /* new in LDAPv3 */
  329. case LDAP_UNAVAILABLE_CRITICAL_EXTENSION:
  330. s = XP_GetClientStr(DBT_aCriticalExtensionThatTheGateway_);
  331. break;
  332. #endif
  333. case LDAP_NO_SUCH_ATTRIBUTE:
  334. s = XP_GetClientStr(DBT_theServerWasUnableToProcessTheRe_);
  335. break;
  336. case LDAP_UNDEFINED_TYPE:
  337. break;
  338. case LDAP_INAPPROPRIATE_MATCHING:
  339. break;
  340. case LDAP_CONSTRAINT_VIOLATION:
  341. s = XP_GetClientStr(DBT_theServerWasUnableToFulfillYourR_);
  342. break;
  343. case LDAP_TYPE_OR_VALUE_EXISTS:
  344. s = XP_GetClientStr(DBT_theServerCouldNotAddAValueToTheE_);
  345. break;
  346. case LDAP_INVALID_SYNTAX:
  347. break;
  348. case LDAP_NO_SUCH_OBJECT:
  349. if (( options & DSGW_ERROPT_DURINGBIND ) == 0 ) {
  350. s = XP_GetClientStr(DBT_theServerCouldNotLocateTheEntryI_);
  351. } else {
  352. s = XP_GetClientStr(DBT_theServerCouldNotLocateTheEntryY_);
  353. }
  354. break;
  355. case LDAP_ALIAS_PROBLEM:
  356. break;
  357. case LDAP_INVALID_DN_SYNTAX:
  358. s = XP_GetClientStr(DBT_aDistinguishedNameWasNotInThePro_);
  359. break;
  360. case LDAP_IS_LEAF:
  361. break;
  362. case LDAP_ALIAS_DEREF_PROBLEM:
  363. break;
  364. case LDAP_INAPPROPRIATE_AUTH:
  365. s = XP_GetClientStr(DBT_theEntryYouAttemptedToAuthentica_);
  366. break;
  367. case LDAP_INVALID_CREDENTIALS:
  368. s = XP_GetClientStr(DBT_thePasswordOrOtherAuthentication_);
  369. break;
  370. case LDAP_INSUFFICIENT_ACCESS:
  371. s = XP_GetClientStr(DBT_youDoNotHaveSufficientPrivileges_);
  372. break;
  373. case LDAP_BUSY:
  374. s = XP_GetClientStr(DBT_theServerIsTooBusyToServiceYourR_);
  375. break;
  376. case LDAP_UNAVAILABLE:
  377. s = XP_GetClientStr(DBT_theLdapServerCouldNotBeContacted_);
  378. break;
  379. case LDAP_UNWILLING_TO_PERFORM:
  380. s = XP_GetClientStr(DBT_theServerWasUnwilliingToProcessY_);
  381. break;
  382. case LDAP_LOOP_DETECT:
  383. break;
  384. case LDAP_NAMING_VIOLATION:
  385. break;
  386. case LDAP_OBJECT_CLASS_VIOLATION:
  387. s = XP_GetClientStr(DBT_theDirectoryServerCouldNotHonorY_);
  388. break;
  389. case LDAP_NOT_ALLOWED_ON_NONLEAF:
  390. s = XP_GetClientStr(DBT_theDirectoryServerWillNotAllowYo_);
  391. break;
  392. case LDAP_NOT_ALLOWED_ON_RDN:
  393. break;
  394. case LDAP_ALREADY_EXISTS:
  395. s = XP_GetClientStr(DBT_theServerWasUnableToAddANewEntry_);
  396. break;
  397. case LDAP_NO_OBJECT_CLASS_MODS:
  398. break;
  399. case LDAP_RESULTS_TOO_LARGE:
  400. break;
  401. #ifdef LDAP_AFFECTS_MULTIPLE_DSAS /* new in LDAPv3 */
  402. case LDAP_AFFECTS_MULTIPLE_DSAS:
  403. s = XP_GetClientStr(DBT_yourRequestWouldAffectSeveralDir_);
  404. break;
  405. #endif
  406. case LDAP_OTHER:
  407. break;
  408. case LDAP_SERVER_DOWN:
  409. s = XP_GetClientStr(DBT_theDirectoryServerCouldNotBeCont_);
  410. break;
  411. case LDAP_LOCAL_ERROR:
  412. break;
  413. case LDAP_ENCODING_ERROR:
  414. s = XP_GetClientStr(DBT_anErrorOccuredWhileSendingDataTo_);
  415. break;
  416. case LDAP_DECODING_ERROR:
  417. s = XP_GetClientStr(DBT_anErrorOccuredWhileReadingDataFr_);
  418. break;
  419. case LDAP_TIMEOUT:
  420. s = XP_GetClientStr(DBT_theServerDidNotRespondToTheReque_);
  421. break;
  422. case LDAP_AUTH_UNKNOWN:
  423. s = XP_GetClientStr(DBT_theServerDoesNotSupportTheAuthen_);
  424. break;
  425. case LDAP_FILTER_ERROR:
  426. s = XP_GetClientStr(DBT_theSearchFilterConstructedByTheG_);
  427. break;
  428. case LDAP_USER_CANCELLED:
  429. s = XP_GetClientStr(DBT_theOperationWasCancelledAtYourRe_);
  430. break;
  431. case LDAP_PARAM_ERROR:
  432. break;
  433. case LDAP_NO_MEMORY:
  434. s = XP_GetClientStr(DBT_anInternalErrorOccurredInTheLibr_);
  435. break;
  436. case LDAP_CONNECT_ERROR:
  437. s = XP_GetClientStr(DBT_aConnectionToTheServerCouldNotBe_);
  438. break;
  439. default:
  440. s = XP_GetClientStr(DBT_anUnknownErrorWasEncountered_);
  441. }
  442. return s;
  443. }
  444. static struct dsgwerr LDAP_errs[] = {
  445. { LDAP_SUCCESS, DBT_LDAP_SUCCESS},
  446. { LDAP_OPERATIONS_ERROR, DBT_LDAP_OPERATIONS_ERROR},
  447. { LDAP_PROTOCOL_ERROR, DBT_LDAP_PROTOCOL_ERROR},
  448. { LDAP_TIMELIMIT_EXCEEDED, DBT_LDAP_TIMELIMIT_EXCEEDED},
  449. { LDAP_SIZELIMIT_EXCEEDED, DBT_LDAP_SIZELIMIT_EXCEEDED},
  450. { LDAP_COMPARE_FALSE, DBT_LDAP_COMPARE_FALSE},
  451. { LDAP_COMPARE_TRUE, DBT_LDAP_COMPARE_TRUE},
  452. { LDAP_STRONG_AUTH_NOT_SUPPORTED, DBT_LDAP_STRONG_AUTH_NOT_SUPPORTED},
  453. { LDAP_STRONG_AUTH_REQUIRED, DBT_LDAP_STRONG_AUTH_REQUIRED},
  454. { LDAP_PARTIAL_RESULTS, DBT_LDAP_PARTIAL_RESULTS},
  455. { LDAP_REFERRAL, DBT_LDAP_REFERRAL},
  456. { LDAP_ADMINLIMIT_EXCEEDED, DBT_LDAP_ADMINLIMIT_EXCEEDED},
  457. { LDAP_UNAVAILABLE_CRITICAL_EXTENSION, DBT_LDAP_UNAVAILABLE_CRITICAL_EXTENSION},
  458. { LDAP_CONFIDENTIALITY_REQUIRED,DBT_LDAP_CONFIDENTIALITY_REQUIRED},
  459. { LDAP_SASL_BIND_IN_PROGRESS, DBT_LDAP_SASL_BIND_IN_PROGRESS},
  460. { LDAP_NO_SUCH_ATTRIBUTE, DBT_LDAP_NO_SUCH_ATTRIBUTE},
  461. { LDAP_UNDEFINED_TYPE, DBT_LDAP_UNDEFINED_TYPE},
  462. { LDAP_INAPPROPRIATE_MATCHING, DBT_LDAP_INAPPROPRIATE_MATCHING},
  463. { LDAP_CONSTRAINT_VIOLATION, DBT_LDAP_CONSTRAINT_VIOLATION},
  464. { LDAP_TYPE_OR_VALUE_EXISTS, DBT_LDAP_TYPE_OR_VALUE_EXISTS},
  465. { LDAP_INVALID_SYNTAX, DBT_LDAP_INVALID_SYNTAX},
  466. { LDAP_NO_SUCH_OBJECT, DBT_LDAP_NO_SUCH_OBJECT},
  467. { LDAP_ALIAS_PROBLEM, DBT_LDAP_ALIAS_PROBLEM},
  468. { LDAP_INVALID_DN_SYNTAX, DBT_LDAP_INVALID_DN_SYNTAX},
  469. { LDAP_IS_LEAF, DBT_LDAP_IS_LEAF},
  470. { LDAP_ALIAS_DEREF_PROBLEM, DBT_LDAP_ALIAS_DEREF_PROBLEM},
  471. { LDAP_INAPPROPRIATE_AUTH, DBT_LDAP_INAPPROPRIATE_AUTH},
  472. { LDAP_INVALID_CREDENTIALS, DBT_LDAP_INVALID_CREDENTIALS},
  473. { LDAP_INSUFFICIENT_ACCESS, DBT_LDAP_INSUFFICIENT_ACCESS},
  474. { LDAP_BUSY, DBT_LDAP_BUSY},
  475. { LDAP_UNAVAILABLE, DBT_LDAP_UNAVAILABLE},
  476. { LDAP_UNWILLING_TO_PERFORM, DBT_LDAP_UNWILLING_TO_PERFORM},
  477. { LDAP_LOOP_DETECT, DBT_LDAP_LOOP_DETECT},
  478. { LDAP_NAMING_VIOLATION, DBT_LDAP_NAMING_VIOLATION},
  479. { LDAP_OBJECT_CLASS_VIOLATION, DBT_LDAP_OBJECT_CLASS_VIOLATION},
  480. { LDAP_NOT_ALLOWED_ON_NONLEAF, DBT_LDAP_NOT_ALLOWED_ON_NONLEAF},
  481. { LDAP_NOT_ALLOWED_ON_RDN, DBT_LDAP_NOT_ALLOWED_ON_RDN},
  482. { LDAP_ALREADY_EXISTS, DBT_LDAP_ALREADY_EXISTS},
  483. { LDAP_NO_OBJECT_CLASS_MODS, DBT_LDAP_NO_OBJECT_CLASS_MODS},
  484. { LDAP_RESULTS_TOO_LARGE, DBT_LDAP_RESULTS_TOO_LARGE},
  485. { LDAP_AFFECTS_MULTIPLE_DSAS, DBT_LDAP_AFFECTS_MULTIPLE_DSAS},
  486. { LDAP_OTHER, DBT_LDAP_OTHER},
  487. { LDAP_SERVER_DOWN, DBT_LDAP_SERVER_DOWN},
  488. { LDAP_LOCAL_ERROR, DBT_LDAP_LOCAL_ERROR},
  489. { LDAP_ENCODING_ERROR, DBT_LDAP_ENCODING_ERROR},
  490. { LDAP_DECODING_ERROR, DBT_LDAP_DECODING_ERROR},
  491. { LDAP_TIMEOUT, DBT_LDAP_TIMEOUT},
  492. { LDAP_AUTH_UNKNOWN, DBT_LDAP_AUTH_UNKNOWN},
  493. { LDAP_FILTER_ERROR, DBT_LDAP_FILTER_ERROR},
  494. { LDAP_USER_CANCELLED, DBT_LDAP_USER_CANCELLED},
  495. { LDAP_PARAM_ERROR, DBT_LDAP_PARAM_ERROR},
  496. { LDAP_NO_MEMORY, DBT_LDAP_NO_MEMORY},
  497. { LDAP_CONNECT_ERROR, DBT_LDAP_CONNECT_ERROR},
  498. { LDAP_NOT_SUPPORTED, DBT_LDAP_NOT_SUPPORTED},
  499. { LDAP_CONTROL_NOT_FOUND, DBT_LDAP_CONTROL_NOT_FOUND},
  500. { LDAP_NO_RESULTS_RETURNED, DBT_LDAP_NO_RESULTS_RETURNED},
  501. { LDAP_MORE_RESULTS_TO_RETURN, DBT_LDAP_MORE_RESULTS_TO_RETURN},
  502. { LDAP_CLIENT_LOOP, DBT_LDAP_CLIENT_LOOP},
  503. { LDAP_REFERRAL_LIMIT_EXCEEDED, DBT_LDAP_REFERRAL_LIMIT_EXCEEDED}};
  504. #define LDAP_ERROR_CNT ( sizeof( LDAP_errs ) / sizeof( struct dsgwerr ))
  505. char *
  506. dsgw_ldaperr2string( int lderr )
  507. {
  508. auto int msgno = 0;
  509. auto int i;
  510. for ( i = 0; i < LDAP_ERROR_CNT; ++i ) {
  511. if ( LDAP_errs[ i ].dsgwerr_code == lderr ) {
  512. msgno = LDAP_errs[ i ].dsgwerr_msg;
  513. break;
  514. }
  515. }
  516. if (msgno != 0) {
  517. auto char* msg = XP_GetClientStr(msgno);
  518. if (msg && *msg) return dsgw_ch_strdup( msg );
  519. }
  520. { /* get the message string from the LDAP SDK: */
  521. auto char* fmt = XP_GetClientStr(DBT_errorS_);
  522. auto char* s = ldap_err2string( lderr );
  523. auto char* msg = dsgw_ch_malloc( strlen( fmt ) + strlen( s ) + 20);
  524. PR_snprintf( msg, strlen(fmt) + strlen(s) + 20, fmt, s, lderr );
  525. return msg;
  526. }
  527. }