aclerror.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /*
  42. * Description (aclerror.c)
  43. *
  44. * This module provides error-handling facilities for ACL-related
  45. * errors.
  46. */
  47. #include "base/systems.h"
  48. #include "public/nsapi.h"
  49. #include "prprf.h"
  50. #include "prlog.h"
  51. #include "libaccess/nserror.h"
  52. #include "libaccess/nsautherr.h"
  53. #include "libaccess/aclerror.h"
  54. #include <libaccess/dbtlibaccess.h>
  55. #include <libaccess/aclerror.h>
  56. #define aclerrnomem XP_GetAdminStr(DBT_AclerrfmtAclerrnomem)
  57. #define aclerropen XP_GetAdminStr(DBT_AclerrfmtAclerropen)
  58. #define aclerrdupsym1 XP_GetAdminStr(DBT_AclerrfmtAclerrdupsym1)
  59. #define aclerrdupsym3 XP_GetAdminStr(DBT_AclerrfmtAclerrdupsym3)
  60. #define aclerrsyntax XP_GetAdminStr(DBT_AclerrfmtAclerrsyntax)
  61. #define aclerrundef XP_GetAdminStr(DBT_AclerrfmtAclerrundef)
  62. #define aclaclundef XP_GetAdminStr(DBT_AclerrfmtAclaclundef)
  63. #define aclerradb XP_GetAdminStr(DBT_AclerrfmtAclerradb)
  64. #define aclerrparse1 XP_GetAdminStr(DBT_AclerrfmtAclerrparse1)
  65. #define aclerrparse2 XP_GetAdminStr(DBT_AclerrfmtAclerrparse2)
  66. #define aclerrparse3 XP_GetAdminStr(DBT_AclerrfmtAclerrparse3)
  67. #define aclerrnorlm XP_GetAdminStr(DBT_AclerrfmtAclerrnorlm)
  68. #define unknownerr XP_GetAdminStr(DBT_AclerrfmtUnknownerr)
  69. #define aclerrinternal XP_GetAdminStr(DBT_AclerrfmtAclerrinternal)
  70. #define aclerrinval XP_GetAdminStr(DBT_AclerrfmtAclerrinval)
  71. #define aclerrfail XP_GetAdminStr(DBT_AclerrfmtAclerrfail)
  72. #define aclerrio XP_GetAdminStr(DBT_AclerrfmtAclerrio)
  73. char * NSAuth_Program = "NSAUTH";
  74. char * ACL_Program = "NSACL"; /* ACL facility name */
  75. /*
  76. * Description (aclErrorFmt)
  77. *
  78. * This function formats an ACL error message into a buffer provided
  79. * by the caller. The ACL error information is passed in an error
  80. * list structure. The caller can indicate how many error frames
  81. * should be processed. A newline is inserted between messages for
  82. * different error frames. The error frames on the error list are
  83. * all freed, regardless of the maximum depth for traceback.
  84. *
  85. * Arguments:
  86. *
  87. * errp - error frame list pointer
  88. * msgbuf - pointer to error message buffer
  89. * maxlen - maximum length of generated message
  90. * maxdepth - maximum depth for traceback
  91. */
  92. void aclErrorFmt(NSErr_t * errp, char * msgbuf, int maxlen, int maxdepth)
  93. {
  94. NSEFrame_t * efp; /* error frame pointer */
  95. int len = 0; /* length of error message text */
  96. int depth = 0; /* current depth */
  97. msgbuf[0] = 0;
  98. while ((efp = errp->err_first) != 0) {
  99. /* Stop if the message buffer is full */
  100. if (maxlen <= 0) break;
  101. if (depth > 0) {
  102. /* Put a newline & tab between error frame messages */
  103. *msgbuf++ = '\n';
  104. if (--maxlen <= 0) break;
  105. *msgbuf++ = '\t';
  106. if (--maxlen <= 0) break;
  107. }
  108. if (!strcmp(efp->ef_program, ACL_Program)) {
  109. /* Identify the facility generating the error and the id number */
  110. len = PR_snprintf(msgbuf, maxlen,
  111. "[%s%d] ", efp->ef_program, efp->ef_errorid);
  112. msgbuf += len;
  113. maxlen -= len;
  114. if (maxlen <= 0) break;
  115. len = 0;
  116. switch (efp->ef_retcode) {
  117. case ACLERRFAIL:
  118. case ACLERRNOMEM:
  119. case ACLERRINTERNAL:
  120. case ACLERRINVAL:
  121. switch (efp->ef_errc) {
  122. case 3:
  123. PR_snprintf(msgbuf, maxlen, efp->ef_errv[0], efp->ef_errv[1], efp->ef_errv[2]);
  124. break;
  125. case 2:
  126. PR_snprintf(msgbuf, maxlen, efp->ef_errv[0], efp->ef_errv[1]);
  127. break;
  128. case 1:
  129. strncpy(msgbuf, efp->ef_errv[0], maxlen);
  130. break;
  131. default:
  132. PR_ASSERT(0); /* don't break -- continue into case 0 */
  133. case 0:
  134. switch (efp->ef_retcode) {
  135. case ACLERRFAIL:
  136. strncpy(msgbuf, XP_GetAdminStr(DBT_AclerrfmtAclerrfail), maxlen);
  137. break;
  138. case ACLERRNOMEM:
  139. strncpy(msgbuf, aclerrnomem, maxlen);
  140. break;
  141. case ACLERRINTERNAL:
  142. strncpy(msgbuf, aclerrinternal, maxlen);
  143. break;
  144. case ACLERRINVAL:
  145. strncpy(msgbuf, aclerrinval, maxlen);
  146. break;
  147. }
  148. break;
  149. }
  150. msgbuf[maxlen-1] = '\0';
  151. len = strlen(msgbuf);
  152. break;
  153. case ACLERROPEN:
  154. /* File open error: filename, system_errmsg */
  155. if (efp->ef_errc == 2) {
  156. len = PR_snprintf(msgbuf, maxlen, aclerropen,
  157. efp->ef_errv[0], efp->ef_errv[1]);
  158. }
  159. break;
  160. case ACLERRDUPSYM:
  161. /* Duplicate symbol */
  162. if (efp->ef_errc == 1) {
  163. /* Duplicate symbol: filename, line#, symbol */
  164. len = PR_snprintf(msgbuf, maxlen, aclerrdupsym1,
  165. efp->ef_errv[0]);
  166. }
  167. else if (efp->ef_errc == 3) {
  168. /* Duplicate symbol: symbol */
  169. len = PR_snprintf(msgbuf, maxlen, aclerrdupsym3,
  170. efp->ef_errv[0], efp->ef_errv[1],
  171. efp->ef_errv[2]);
  172. }
  173. break;
  174. case ACLERRSYNTAX:
  175. if (efp->ef_errc == 2) {
  176. /* Syntax error: filename, line# */
  177. len = PR_snprintf(msgbuf, maxlen, aclerrsyntax,
  178. efp->ef_errv[0], efp->ef_errv[1]);
  179. }
  180. break;
  181. case ACLERRUNDEF:
  182. if (efp->ef_errorid == ACLERR3800) {
  183. /* Undefined symbol: acl, method/database name */
  184. len = PR_snprintf(msgbuf, maxlen, aclaclundef,
  185. efp->ef_errv[0], efp->ef_errv[1],
  186. efp->ef_errv[2]);
  187. }
  188. else if (efp->ef_errc == 3) {
  189. /* Undefined symbol: filename, line#, symbol */
  190. len = PR_snprintf(msgbuf, maxlen, aclerrundef,
  191. efp->ef_errv[0], efp->ef_errv[1],
  192. efp->ef_errv[2]);
  193. }
  194. break;
  195. case ACLERRADB:
  196. if (efp->ef_errc == 2) {
  197. /* Authentication database error: DB name, symbol */
  198. len = PR_snprintf(msgbuf, maxlen, aclerradb,
  199. efp->ef_errv[0], efp->ef_errv[1]);
  200. }
  201. break;
  202. case ACLERRPARSE:
  203. if (efp->ef_errc == 2) {
  204. /* Parse error: filename, line# */
  205. len = PR_snprintf(msgbuf, maxlen, aclerrparse2,
  206. efp->ef_errv[0], efp->ef_errv[1]);
  207. }
  208. else if (efp->ef_errc == 3) {
  209. /* Parse error: filename, line#, token */
  210. len = PR_snprintf(msgbuf, maxlen, aclerrparse3,
  211. efp->ef_errv[0], efp->ef_errv[1],
  212. efp->ef_errv[2]);
  213. }
  214. else if (efp->ef_errc == 1) {
  215. /* Parse error: line or pointer */
  216. len = PR_snprintf(msgbuf, maxlen, aclerrparse1,
  217. efp->ef_errv[0]);
  218. }
  219. break;
  220. case ACLERRNORLM:
  221. if (efp->ef_errc == 1) {
  222. /* No realm: name */
  223. len = PR_snprintf(msgbuf, maxlen, aclerrnorlm,
  224. efp->ef_errv[0]);
  225. }
  226. break;
  227. case ACLERRIO:
  228. if (efp->ef_errc == 2) {
  229. len = PR_snprintf(msgbuf, maxlen, aclerrio,
  230. efp->ef_errv[0], efp->ef_errv[1]);
  231. }
  232. break;
  233. default:
  234. len = PR_snprintf(msgbuf, maxlen, unknownerr, efp->ef_retcode);
  235. break;
  236. }
  237. }
  238. else if (!strcmp(efp->ef_program, NSAuth_Program)) {
  239. nsadbErrorFmt(errp, msgbuf, maxlen, maxdepth - depth);
  240. }
  241. else {
  242. len = PR_snprintf(msgbuf, maxlen, unknownerr, efp->ef_retcode);
  243. }
  244. msgbuf += len;
  245. maxlen -= len;
  246. /* Free this frame */
  247. nserrFFree(errp, efp);
  248. if (++depth >= maxdepth) break;
  249. }
  250. /* Free any remaining error frames */
  251. nserrDispose(errp);
  252. }