errors.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include <ldaputil/errors.h>
  42. #include <ldaputil/certmap.h>
  43. NSAPI_PUBLIC char *ldapu_err2string(int err)
  44. {
  45. char *rv;
  46. switch(err) {
  47. /* Error codes defined in certmap.h */
  48. case LDAPU_SUCCESS:
  49. rv = "success";
  50. break;
  51. case LDAPU_FAILED:
  52. rv = "ldap search didn't find an ldap entry";
  53. break;
  54. case LDAPU_CERT_MAP_FUNCTION_FAILED:
  55. rv = "Cert mapping function failed";
  56. break;
  57. case LDAPU_CERT_SEARCH_FUNCTION_FAILED:
  58. rv = "Cert search function failed";
  59. break;
  60. case LDAPU_CERT_VERIFY_FUNCTION_FAILED:
  61. rv = "Cert verify function failed";
  62. break;
  63. case LDAPU_CERT_MAP_INITFN_FAILED:
  64. rv = "Certmap InitFn function failed";
  65. break;
  66. /* Error codes returned by ldapdb.c */
  67. case LDAPU_ERR_URL_INVALID_PREFIX:
  68. rv = "invalid local ldap database url prefix -- must be ldapdb://";
  69. break;
  70. case LDAPU_ERR_URL_NO_BASEDN:
  71. rv = "base dn is missing in ldapdb url";
  72. break;
  73. case LDAPU_ERR_OUT_OF_MEMORY:
  74. rv = "out of memory";
  75. break;
  76. case LDAPU_ERR_LDAP_INIT_FAILED:
  77. rv = "Couldn't initialize connection to the ldap directory server";
  78. break;
  79. case LDAPU_ERR_LCACHE_INIT_FAILED:
  80. rv = "Couldn't initialize connection to the local ldap directory";
  81. break;
  82. case LDAPU_ERR_LDAP_SET_OPTION_FAILED:
  83. rv = "ldap_set_option failed for local ldap database";
  84. break;
  85. case LDAPU_ERR_NO_DEFAULT_CERTDB:
  86. rv = "default cert database not initialized when using LDAP over SSL";
  87. break;
  88. /* Errors returned by ldapauth.c */
  89. case LDAPU_ERR_CIRCULAR_GROUPS:
  90. rv = "Circular groups were detected during group membership check";
  91. break;
  92. case LDAPU_ERR_INVALID_STRING:
  93. rv = "Invalid string";
  94. break;
  95. case LDAPU_ERR_INVALID_STRING_INDEX:
  96. rv = "Invalid string index";
  97. break;
  98. case LDAPU_ERR_MISSING_ATTR_VAL:
  99. rv = "Missing attribute value from the search result";
  100. break;
  101. /* Errors returned by dbconf.c */
  102. case LDAPU_ERR_CANNOT_OPEN_FILE:
  103. rv = "cannot open the config file";
  104. break;
  105. case LDAPU_ERR_DBNAME_IS_MISSING:
  106. rv = "database name is missing";
  107. break;
  108. case LDAPU_ERR_PROP_IS_MISSING:
  109. rv = "database property is missing";
  110. break;
  111. case LDAPU_ERR_DIRECTIVE_IS_MISSING:
  112. rv = "illegal directive in the config file";
  113. break;
  114. case LDAPU_ERR_NOT_PROPVAL:
  115. rv = "internal error - LDAPU_ERR_NOT_PROPVAL";
  116. break;
  117. /* Error codes returned by certmap.c */
  118. case LDAPU_ERR_NO_ISSUERDN_IN_CERT:
  119. rv = "cannot extract issuer DN from the cert";
  120. break;
  121. case LDAPU_ERR_NO_ISSUERDN_IN_CONFIG_FILE:
  122. rv = "issuer DN missing for non-default certmap";
  123. break;
  124. case LDAPU_ERR_CERTMAP_INFO_MISSING:
  125. rv = "cert to ldap entry mapping information is missing";
  126. break;
  127. case LDAPU_ERR_MALFORMED_SUBJECT_DN:
  128. rv = "Found malformed subject DN in the certificate";
  129. break;
  130. case LDAPU_ERR_MAPPED_ENTRY_NOT_FOUND:
  131. rv = "Certificate couldn't be mapped to an ldap entry";
  132. break;
  133. case LDAPU_ERR_UNABLE_TO_LOAD_PLUGIN:
  134. rv = "Unable to load certmap plugin library";
  135. break;
  136. case LDAPU_ERR_MISSING_INIT_FN_IN_CONFIG:
  137. rv = "InitFn must be provided when using certmap plugin library";
  138. break;
  139. case LDAPU_ERR_MISSING_INIT_FN_IN_LIB:
  140. rv = "Could not find InitFn in the certmap plugin library";
  141. break;
  142. case LDAPU_ERR_CERT_VERIFY_FAILED:
  143. rv = "Could not matching certificate in User's LDAP entry";
  144. break;
  145. case LDAPU_ERR_CERT_VERIFY_NO_CERTS:
  146. rv = "User's LDAP entry doesn't have any certificates to compare";
  147. break;
  148. case LDAPU_ERR_MISSING_LIBNAME:
  149. rv = "Library name is missing in the config file";
  150. break;
  151. case LDAPU_ERR_MISSING_INIT_FN_NAME:
  152. rv = "Init function name is missing in the config file";
  153. break;
  154. case LDAPU_ERR_WRONG_ARGS:
  155. rv = "ldaputil API function called with wrong arguments";
  156. break;
  157. case LDAPU_ERR_RENAME_FILE_FAILED:
  158. rv = "Renaming of file failed";
  159. break;
  160. case LDAPU_ERR_MISSING_VERIFYCERT_VAL:
  161. rv = "VerifyCert property value must be on or off";
  162. break;
  163. case LDAPU_ERR_CANAME_IS_MISSING:
  164. rv = "Cert issuer name is missing";
  165. break;
  166. case LDAPU_ERR_CAPROP_IS_MISSING:
  167. rv = "property name is missing";
  168. break;
  169. case LDAPU_ERR_UNKNOWN_CERT_ATTR:
  170. rv = "unknown cert attribute";
  171. break;
  172. case LDAPU_ERR_EMPTY_LDAP_RESULT:
  173. rv = "ldap search returned empty result";
  174. break;
  175. case LDAPU_ERR_MULTIPLE_MATCHES:
  176. rv = "ldap search returned multiple matches when one expected";
  177. break;
  178. case LDAPU_ERR_MISSING_RES_ENTRY:
  179. rv = "Could not extract entry from the ldap search result";
  180. break;
  181. case LDAPU_ERR_MISSING_UID_ATTR:
  182. rv = "ldap entry is missing the 'uid' attribute value";
  183. break;
  184. case LDAPU_ERR_INVALID_ARGUMENT:
  185. rv = "invalid argument passed to the certmap API function";
  186. break;
  187. case LDAPU_ERR_INVALID_SUFFIX:
  188. rv = "invalid LDAP directory suffix";
  189. break;
  190. /* Error codes returned by cert.c */
  191. case LDAPU_ERR_EXTRACT_SUBJECTDN_FAILED:
  192. rv = "Couldn't extract the subject DN from the certificate";
  193. break;
  194. case LDAPU_ERR_EXTRACT_ISSUERDN_FAILED:
  195. rv = "Couldn't extract the issuer DN from the certificate";
  196. break;
  197. case LDAPU_ERR_EXTRACT_DERCERT_FAILED:
  198. rv = "Couldn't extract the original DER encoding from the certificate";
  199. break;
  200. case LDAPU_ERR_NOT_IMPLEMENTED:
  201. rv = "function not implemented yet";
  202. break;
  203. case LDAPU_ERR_INTERNAL:
  204. rv = "ldaputil internal error";
  205. break;
  206. default:
  207. if (err > 0) {
  208. /* LDAP errors are +ve */
  209. rv = ldap_err2string(err);
  210. }
  211. else {
  212. rv = "internal error - unknown error code";
  213. }
  214. break;
  215. }
  216. return rv;
  217. }