1 /*- 2 * Copyright (c) 2001-2003 Networks Associates Technology, Inc. 3 * Copyright (c) 2004-2011 Dag-Erling Smørgrav 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by ThinkSec AS and 7 * Network Associates Laboratories, the Security Research Division of 8 * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 9 * ("CBOSS"), as part of the DARPA CHATS research program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The name of the author may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef OPENPAM_DEBUG_H_INCLUDED 37 #define OPENPAM_DEBUG_H_INCLUDED 38 39 #ifdef OPENPAM_DEBUG 40 #define ENTER() openpam_log(PAM_LOG_LIBDEBUG, "entering") 41 #define ENTERI(i) do { \ 42 int i_ = (i); \ 43 if (i_ > 0 && i_ < PAM_NUM_ITEMS) \ 44 openpam_log(PAM_LOG_LIBDEBUG, "entering: %s", pam_item_name[i_]); \ 45 else \ 46 openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", i_); \ 47 } while (0) 48 #define ENTERN(n) do { \ 49 int n_ = (n); \ 50 openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", n_); \ 51 } while (0) 52 #define ENTERS(s) do { \ 53 const char *s_ = (s); \ 54 if (s_ == NULL) \ 55 openpam_log(PAM_LOG_LIBDEBUG, "entering: NULL"); \ 56 else \ 57 openpam_log(PAM_LOG_LIBDEBUG, "entering: '%s'", s_); \ 58 } while (0) 59 #define ENTERF(f) do { \ 60 int f_ = (f); \ 61 if (f_ >= 0 && f_ <= OPENPAM_NUM_FEATURES) \ 62 openpam_log(PAM_LOG_LIBDEBUG, "entering: %s", \ 63 openpam_features[f_].name); \ 64 else \ 65 openpam_log(PAM_LOG_LIBDEBUG, "entering: %d", f_); \ 66 } while (0) 67 #define RETURNV() openpam_log(PAM_LOG_LIBDEBUG, "returning") 68 #define RETURNC(c) do { \ 69 int c_ = (c); \ 70 if (c_ >= 0 && c_ < PAM_NUM_ERRORS) \ 71 openpam_log(PAM_LOG_LIBDEBUG, "returning %s", pam_err_name[c_]); \ 72 else \ 73 openpam_log(PAM_LOG_LIBDEBUG, "returning %d!", c_); \ 74 return (c_); \ 75 } while (0) 76 #define RETURNN(n) do { \ 77 int n_ = (n); \ 78 openpam_log(PAM_LOG_LIBDEBUG, "returning %d", n_); \ 79 return (n_); \ 80 } while (0) 81 #define RETURNP(p) do { \ 82 void *p_ = (p); \ 83 if (p_ == NULL) \ 84 openpam_log(PAM_LOG_LIBDEBUG, "returning NULL"); \ 85 else \ 86 openpam_log(PAM_LOG_LIBDEBUG, "returning %p", p_); \ 87 return (p_); \ 88 } while (0) 89 #define RETURNS(s) do { \ 90 const char *s_ = (s); \ 91 if (s_ == NULL) \ 92 openpam_log(PAM_LOG_LIBDEBUG, "returning NULL"); \ 93 else \ 94 openpam_log(PAM_LOG_LIBDEBUG, "returning '%s'", s_); \ 95 return (s_); \ 96 } while (0) 97 #else 98 #define ENTER() 99 #define ENTERI(i) 100 #define ENTERN(n) 101 #define ENTERS(s) 102 #define ENTERF(f) 103 #define RETURNV() return 104 #define RETURNC(c) return (c) 105 #define RETURNN(n) return (n) 106 #define RETURNP(p) return (p) 107 #define RETURNS(s) return (s) 108 #endif 109 110 #endif 111