error.c 17 KB

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