Annotation of embedaddon/sudo/include/sudo_debug.h, revision 1.1.1.5
1.1 misho 1: /*
1.1.1.3 misho 2: * Copyright (c) 2011-2012 Todd C. Miller <Todd.Miller@courtesan.com>
1.1 misho 3: *
4: * Permission to use, copy, modify, and distribute this software for any
5: * purpose with or without fee is hereby granted, provided that the above
6: * copyright notice and this permission notice appear in all copies.
7: *
8: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15: */
16:
17: #ifndef _SUDO_DEBUG_H
18: #define _SUDO_DEBUG_H
19:
20: #include <stdarg.h>
21:
22: /*
23: * The priority and subsystem are encoded in a single 32-bit value.
24: * The lower 4 bits are the priority and the top 26 bits are the subsystem.
25: * This allows for 16 priorities and a very large number of subsystems.
26: * Bit 5 is used as a flag to specify whether to log the errno value.
27: * Bit 6 specifies whether to log the function, file and line number data.
28: */
29:
30: /*
31: * Sudo debug priorities, ordered least to most verbose,
32: * in other words, highest to lowest priority. Max pri is 15.
33: * Note: order must match sudo_debug_priorities[]
34: */
35: #define SUDO_DEBUG_CRIT 1 /* critical errors */
36: #define SUDO_DEBUG_ERROR 2 /* non-critical errors */
37: #define SUDO_DEBUG_WARN 3 /* non-fatal warnings */
38: #define SUDO_DEBUG_NOTICE 4 /* non-error condition notices */
39: #define SUDO_DEBUG_DIAG 5 /* diagnostic messages */
40: #define SUDO_DEBUG_INFO 6 /* informational message */
41: #define SUDO_DEBUG_TRACE 7 /* log function enter/exit */
42: #define SUDO_DEBUG_DEBUG 8 /* very verbose debugging */
43:
44: /*
45: * Sudo debug subsystems.
46: * This includes subsystems in the sudoers plugin.
47: * Note: order must match sudo_debug_subsystems[]
48: */
49: #define SUDO_DEBUG_MAIN ( 1<<6) /* sudo main() */
50: #define SUDO_DEBUG_ARGS ( 2<<6) /* command line argument processing */
51: #define SUDO_DEBUG_EXEC ( 3<<6) /* command execution */
52: #define SUDO_DEBUG_PTY ( 4<<6) /* pseudo-tty */
53: #define SUDO_DEBUG_UTMP ( 5<<6) /* utmp file ops */
54: #define SUDO_DEBUG_CONV ( 6<<6) /* user conversation */
55: #define SUDO_DEBUG_PCOMM ( 7<<6) /* plugin communications */
56: #define SUDO_DEBUG_UTIL ( 8<<6) /* utility functions */
57: #define SUDO_DEBUG_NETIF ( 9<<6) /* network interface functions */
58: #define SUDO_DEBUG_AUDIT (10<<6) /* audit */
59: #define SUDO_DEBUG_EDIT (11<<6) /* sudoedit */
60: #define SUDO_DEBUG_SELINUX (12<<6) /* selinux */
61: #define SUDO_DEBUG_LDAP (13<<6) /* sudoers LDAP */
62: #define SUDO_DEBUG_MATCH (14<<6) /* sudoers matching */
63: #define SUDO_DEBUG_PARSER (15<<6) /* sudoers parser */
64: #define SUDO_DEBUG_ALIAS (16<<6) /* sudoers alias functions */
65: #define SUDO_DEBUG_DEFAULTS (17<<6) /* sudoers defaults settings */
66: #define SUDO_DEBUG_AUTH (18<<6) /* authentication functions */
67: #define SUDO_DEBUG_ENV (19<<6) /* environment handling */
68: #define SUDO_DEBUG_LOGGING (20<<6) /* logging functions */
69: #define SUDO_DEBUG_NSS (21<<6) /* network service switch */
70: #define SUDO_DEBUG_RBTREE (22<<6) /* red-black tree functions */
71: #define SUDO_DEBUG_PERMS (23<<6) /* uid/gid swapping functions */
72: #define SUDO_DEBUG_PLUGIN (24<<6) /* main plugin functions */
73: #define SUDO_DEBUG_HOOKS (25<<6) /* hook functions */
1.1.1.2 misho 74: #define SUDO_DEBUG_SSSD (26<<6) /* sudoers SSSD */
1.1.1.5 ! misho 75: #define SUDO_DEBUG_EVENT (27<<6) /* event handling */
1.1 misho 76: #define SUDO_DEBUG_ALL 0xfff0 /* all subsystems */
77:
78: /* Flag to include string version of errno in debug info. */
79: #define SUDO_DEBUG_ERRNO (1<<4)
80:
81: /* Flag to include function, file and line number in debug info. */
82: #define SUDO_DEBUG_LINENO (1<<5)
83:
84: /* Extract priority and convert to an index. */
85: #define SUDO_DEBUG_PRI(n) (((n) & 0xf) - 1)
86:
87: /* Extract subsystem and convert to an index. */
88: #define SUDO_DEBUG_SUBSYS(n) (((n) >> 6) - 1)
89:
90: /*
91: * Wrapper for sudo_debug_enter() that declares __func__ as needed
92: * and sets sudo_debug_subsys for sudo_debug_exit().
93: */
94: #ifdef HAVE___FUNC__
95: # define debug_decl(funcname, subsys) \
96: const int sudo_debug_subsys = (subsys); \
97: sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys);
98: #else
99: # define debug_decl(funcname, subsys) \
100: const int sudo_debug_subsys = (subsys); \
101: const char *__func__ = #funcname; \
102: sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys);
103: #endif
104:
105: /*
106: * Wrappers for sudo_debug_exit() and friends.
107: */
108: #define debug_return \
109: do { \
110: sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys); \
111: return; \
112: } while (0)
113:
114: #define debug_return_int(rval) \
115: do { \
116: int sudo_debug_rval = (rval); \
117: sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
118: sudo_debug_rval); \
119: return sudo_debug_rval; \
120: } while (0)
121:
122: #define debug_return_size_t(rval) \
123: do { \
124: size_t sudo_debug_rval = (rval); \
125: sudo_debug_exit_size_t(__func__, __FILE__, __LINE__, sudo_debug_subsys,\
126: sudo_debug_rval); \
127: return sudo_debug_rval; \
128: } while (0)
129:
130: #define debug_return_long(rval) \
131: do { \
132: long sudo_debug_rval = (rval); \
133: sudo_debug_exit_long(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
134: sudo_debug_rval); \
135: return sudo_debug_rval; \
136: } while (0)
137:
138: #define debug_return_bool(rval) \
139: do { \
140: int sudo_debug_rval = (rval); \
141: sudo_debug_exit_bool(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
142: sudo_debug_rval); \
143: return sudo_debug_rval; \
144: } while (0)
145:
146: #define debug_return_str(rval) \
147: do { \
1.1.1.5 ! misho 148: char *sudo_debug_rval = (rval); \
1.1 misho 149: sudo_debug_exit_str(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
150: sudo_debug_rval); \
1.1.1.5 ! misho 151: return sudo_debug_rval; \
1.1 misho 152: } while (0)
153:
1.1.1.5 ! misho 154: #define debug_return_const_str(rval) \
1.1 misho 155: do { \
156: const char *sudo_debug_rval = (rval); \
1.1.1.5 ! misho 157: sudo_debug_exit_str(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
! 158: sudo_debug_rval); \
! 159: return sudo_debug_rval; \
! 160: } while (0)
! 161:
! 162: #define debug_return_str_masked(rval) \
! 163: do { \
! 164: char *sudo_debug_rval = (rval); \
1.1 misho 165: sudo_debug_exit_str_masked(__func__, __FILE__, __LINE__, \
166: sudo_debug_subsys, sudo_debug_rval); \
1.1.1.5 ! misho 167: return sudo_debug_rval; \
1.1 misho 168: } while (0)
169:
170: #define debug_return_ptr(rval) \
171: do { \
1.1.1.5 ! misho 172: void *sudo_debug_rval = (rval); \
! 173: sudo_debug_exit_ptr(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
! 174: sudo_debug_rval); \
! 175: return sudo_debug_rval; \
! 176: } while (0)
! 177:
! 178: #define debug_return_const_ptr(rval) \
! 179: do { \
1.1 misho 180: const void *sudo_debug_rval = (rval); \
181: sudo_debug_exit_ptr(__func__, __FILE__, __LINE__, sudo_debug_subsys, \
182: sudo_debug_rval); \
1.1.1.5 ! misho 183: return sudo_debug_rval; \
1.1 misho 184: } while (0)
185:
186: /*
187: * Variadic macros are a C99 feature but GNU cpp has supported
188: * a (different) version of them for a long time.
189: */
1.1.1.5 ! misho 190: #if defined(NO_VARIADIC_MACROS)
! 191: # define sudo_debug_printf sudo_debug_printf_nvm
! 192: #elif defined(__GNUC__) && __GNUC__ == 2
1.1 misho 193: # define sudo_debug_printf(pri, fmt...) \
194: sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \
1.1.1.2 misho 195: fmt)
1.1 misho 196: #else
197: # define sudo_debug_printf(pri, ...) \
198: sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \
199: __VA_ARGS__)
200: #endif
201:
202: #define sudo_debug_execve(pri, path, argv, envp) \
203: sudo_debug_execve2((pri)|sudo_debug_subsys, (path), (argv), (envp))
204:
205: /*
206: * NULL-terminated string lists of priorities and subsystems.
207: */
208: extern const char *const sudo_debug_priorities[];
209: extern const char *const sudo_debug_subsystems[];
210:
211: void sudo_debug_enter(const char *func, const char *file, int line, int subsys);
212: void sudo_debug_execve2(int level, const char *path, char *const argv[], char *const envp[]);
213: void sudo_debug_exit(const char *func, const char *file, int line, int subsys);
214: void sudo_debug_exit_int(const char *func, const char *file, int line, int subsys, int rval);
215: void sudo_debug_exit_long(const char *func, const char *file, int line, int subsys, long rval);
216: void sudo_debug_exit_size_t(const char *func, const char *file, int line, int subsys, size_t rval);
217: void sudo_debug_exit_bool(const char *func, const char *file, int line, int subsys, int rval);
218: void sudo_debug_exit_str(const char *func, const char *file, int line, int subsys, const char *rval);
219: void sudo_debug_exit_str_masked(const char *func, const char *file, int line, int subsys, const char *rval);
220: void sudo_debug_exit_ptr(const char *func, const char *file, int line, int subsys, const void *rval);
1.1.1.5 ! misho 221: int sudo_debug_fd_get(void);
1.1 misho 222: int sudo_debug_fd_set(int fd);
223: int sudo_debug_init(const char *debugfile, const char *settings);
1.1.1.5 ! misho 224: void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3);
1.1.1.4 misho 225: void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6);
226: void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0);
1.1 misho 227: void sudo_debug_write(const char *str, int len, int errno_val);
228: void sudo_debug_write2(const char *func, const char *file, int line, const char *str, int len, int errno_val);
229: pid_t sudo_debug_fork(void);
230:
231: #endif /* _SUDO_DEBUG_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>