Imported Upstream version 1.8.7
[debian/sudo] / include / sudo_debug.h
index 81fbfac07da68b994742202bb09100ef72e1d7d5..ed1cd7147ef583e5a2ba81f02b24fbed07d51f62 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2011-2012 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
 
 /*
  * The priority and subsystem are encoded in a single 32-bit value.
- * The lower 4 bits are the priority and the top 28 bits are the subsystem.
+ * The lower 4 bits are the priority and the top 26 bits are the subsystem.
  * This allows for 16 priorities and a very large number of subsystems.
+ * Bit 5 is used as a flag to specify whether to log the errno value.
+ * Bit 6 specifies whether to log the function, file and line number data.
  */
 
 /*
  * This includes subsystems in the sudoers plugin.
  * Note: order must match sudo_debug_subsystems[]
  */
-#define SUDO_DEBUG_MAIN                (1<<4)  /* sudo main() */
-#define SUDO_DEBUG_ARGS                (2<<4)  /* command line argument processing */
-#define SUDO_DEBUG_EXEC                (3<<4)  /* command execution */
-#define SUDO_DEBUG_PTY         (4<<4)  /* pseudo-tty */
-#define SUDO_DEBUG_UTMP                (5<<4)  /* utmp file ops */
-#define SUDO_DEBUG_CONV                (6<<4)  /* user conversation */
-#define SUDO_DEBUG_PCOMM       (7<<4)  /* plugin communications */
-#define SUDO_DEBUG_UTIL                (8<<4)  /* utility functions */
-#define SUDO_DEBUG_NETIF       (9<<4)  /* network interface functions */
-#define SUDO_DEBUG_AUDIT       (10<<4) /* audit */
-#define SUDO_DEBUG_EDIT                (11<<4) /* sudoedit */
-#define SUDO_DEBUG_SELINUX     (12<<4) /* selinux */
-#define SUDO_DEBUG_LDAP                (13<<4) /* sudoers LDAP */
-#define SUDO_DEBUG_MATCH       (14<<4) /* sudoers matching */
-#define SUDO_DEBUG_PARSER      (15<<4) /* sudoers parser */
-#define SUDO_DEBUG_ALIAS       (16<<4) /* sudoers alias functions */
-#define SUDO_DEBUG_DEFAULTS    (17<<4) /* sudoers defaults settings */
-#define SUDO_DEBUG_AUTH                (18<<4) /* authentication functions */
-#define SUDO_DEBUG_ENV         (19<<4) /* environment handling */
-#define SUDO_DEBUG_LOGGING     (20<<4) /* logging functions */
-#define SUDO_DEBUG_NSS         (21<<4) /* network service switch */
-#define SUDO_DEBUG_RBTREE      (22<<4) /* red-black tree functions */
-#define SUDO_DEBUG_PERMS       (23<<4) /* uid/gid swapping functions */
-#define SUDO_DEBUG_PLUGIN      (24<<4) /* main plugin functions */
+#define SUDO_DEBUG_MAIN                ( 1<<6) /* sudo main() */
+#define SUDO_DEBUG_ARGS                ( 2<<6) /* command line argument processing */
+#define SUDO_DEBUG_EXEC                ( 3<<6) /* command execution */
+#define SUDO_DEBUG_PTY         ( 4<<6) /* pseudo-tty */
+#define SUDO_DEBUG_UTMP                ( 5<<6) /* utmp file ops */
+#define SUDO_DEBUG_CONV                ( 6<<6) /* user conversation */
+#define SUDO_DEBUG_PCOMM       ( 7<<6) /* plugin communications */
+#define SUDO_DEBUG_UTIL                ( 8<<6) /* utility functions */
+#define SUDO_DEBUG_NETIF       ( 9<<6) /* network interface functions */
+#define SUDO_DEBUG_AUDIT       (10<<6) /* audit */
+#define SUDO_DEBUG_EDIT                (11<<6) /* sudoedit */
+#define SUDO_DEBUG_SELINUX     (12<<6) /* selinux */
+#define SUDO_DEBUG_LDAP                (13<<6) /* sudoers LDAP */
+#define SUDO_DEBUG_MATCH       (14<<6) /* sudoers matching */
+#define SUDO_DEBUG_PARSER      (15<<6) /* sudoers parser */
+#define SUDO_DEBUG_ALIAS       (16<<6) /* sudoers alias functions */
+#define SUDO_DEBUG_DEFAULTS    (17<<6) /* sudoers defaults settings */
+#define SUDO_DEBUG_AUTH                (18<<6) /* authentication functions */
+#define SUDO_DEBUG_ENV         (19<<6) /* environment handling */
+#define SUDO_DEBUG_LOGGING     (20<<6) /* logging functions */
+#define SUDO_DEBUG_NSS         (21<<6) /* network service switch */
+#define SUDO_DEBUG_RBTREE      (22<<6) /* red-black tree functions */
+#define SUDO_DEBUG_PERMS       (23<<6) /* uid/gid swapping functions */
+#define SUDO_DEBUG_PLUGIN      (24<<6) /* main plugin functions */
+#define SUDO_DEBUG_HOOKS       (25<<6) /* hook functions */
+#define SUDO_DEBUG_SSSD                (26<<6) /* sudoers SSSD */
 #define SUDO_DEBUG_ALL         0xfff0  /* all subsystems */
 
+/* Flag to include string version of errno in debug info. */
+#define SUDO_DEBUG_ERRNO       (1<<4)
+
+/* Flag to include function, file and line number in debug info. */
+#define SUDO_DEBUG_LINENO      (1<<5)
+
 /* Extract priority and convert to an index. */
 #define SUDO_DEBUG_PRI(n) (((n) & 0xf) - 1)
 
 /* Extract subsystem and convert to an index. */
-#define SUDO_DEBUG_SUBSYS(n) (((n) >> 4) - 1)
+#define SUDO_DEBUG_SUBSYS(n) (((n) >> 6) - 1)
 
 /*
  * Wrapper for sudo_debug_enter() that declares __func__ as needed
  */
 #if defined(__GNUC__) && __GNUC__ == 2
 # define sudo_debug_printf(pri, fmt...) \
-    sudo_debug_printf2((pri)|sudo_debug_subsys, (fmt))
+    sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \
+    fmt)
 #else
 # define sudo_debug_printf(pri, ...) \
-    sudo_debug_printf2((pri)|sudo_debug_subsys, __VA_ARGS__)
+    sudo_debug_printf2(__func__, __FILE__, __LINE__, (pri)|sudo_debug_subsys, \
+    __VA_ARGS__)
 #endif
 
 #define sudo_debug_execve(pri, path, argv, envp) \
@@ -189,7 +201,10 @@ void sudo_debug_exit_str_masked(const char *func, const char *file, int line, in
 void sudo_debug_exit_ptr(const char *func, const char *file, int line, int subsys, const void *rval);
 int sudo_debug_fd_set(int fd);
 int sudo_debug_init(const char *debugfile, const char *settings);
-void sudo_debug_printf2(int level, const char *format, ...) __printflike(2, 3);
-void sudo_debug_write(const char *str, int len);
+void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printflike(5, 6);
+void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap);
+void sudo_debug_write(const char *str, int len, int errno_val);
+void sudo_debug_write2(const char *func, const char *file, int line, const char *str, int len, int errno_val);
+pid_t sudo_debug_fork(void);
 
 #endif /* _SUDO_DEBUG_H */