| 1 | /* |
|---|
| 2 | * ProFTPD - FTP server daemon |
|---|
| 3 | * Copyright (c) 1997, 1998 Public Flood Software |
|---|
| 4 | * Copyright (c) 1999, 2000 MacGyver aka Habeeb J. Dihu <macgyver@tos.net> |
|---|
| 5 | * Copyright (c) 2001-2011 The ProFTPD Project team |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. |
|---|
| 20 | * |
|---|
| 21 | * As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu |
|---|
| 22 | * and other respective copyright holders give permission to link this program |
|---|
| 23 | * with OpenSSL, and distribute the resulting executable, without including |
|---|
| 24 | * the source code for OpenSSL in the source distribution. |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | /* Logging, either to syslog or stderr, as well as debug logging |
|---|
| 28 | * and debug levels. |
|---|
| 29 | * |
|---|
| 30 | * $Id: log.h,v 1.34 2011/05/23 20:35:35 castaglia Exp $ |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | #ifndef PR_LOG_H |
|---|
| 34 | #define PR_LOG_H |
|---|
| 35 | |
|---|
| 36 | #ifndef LOG_AUTHPRIV |
|---|
| 37 | #define LOG_AUTHPRIV LOG_AUTH |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | #if !defined(WTMP_FILE) && defined(_PATH_WTMP) |
|---|
| 41 | #define WTMP_FILE _PATH_WTMP |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | /* These are the debug levels, higher numbers print more debugging |
|---|
| 45 | * info. DEBUG0 (the default) prints nothing. |
|---|
| 46 | */ |
|---|
| 47 | |
|---|
| 48 | #define DEBUG10 10 |
|---|
| 49 | #define DEBUG9 9 |
|---|
| 50 | #define DEBUG8 8 |
|---|
| 51 | #define DEBUG7 7 |
|---|
| 52 | #define DEBUG6 6 |
|---|
| 53 | #define DEBUG5 5 |
|---|
| 54 | #define DEBUG4 4 |
|---|
| 55 | #define DEBUG3 3 |
|---|
| 56 | #define DEBUG2 2 |
|---|
| 57 | #define DEBUG1 1 |
|---|
| 58 | #define DEBUG0 0 |
|---|
| 59 | |
|---|
| 60 | /* pr_log_openfile() return values */ |
|---|
| 61 | #define PR_LOG_WRITABLE_DIR -2 |
|---|
| 62 | #define PR_LOG_SYMLINK -3 |
|---|
| 63 | |
|---|
| 64 | /* Log file modes */ |
|---|
| 65 | #define PR_LOG_SYSTEM_MODE 0640 |
|---|
| 66 | #define PR_LOG_XFER_MODE 0644 |
|---|
| 67 | |
|---|
| 68 | #ifdef PR_USE_LASTLOG |
|---|
| 69 | |
|---|
| 70 | /* It is tempting to want to have these lastlog-related includes separated |
|---|
| 71 | * out into their own lastlog.h file. However, on some systems, such a |
|---|
| 72 | * proftpd-specific lastlog.h file may collide with the system's lastlog.h |
|---|
| 73 | * file. Ultimately it's an issue with the default search order of the |
|---|
| 74 | * system C preprocessor, not with us -- and not every installation has |
|---|
| 75 | * this problem. |
|---|
| 76 | * |
|---|
| 77 | * In the meantime, the most portable thing is to keep these lastlog-related |
|---|
| 78 | * includes in this file. Yay portability. |
|---|
| 79 | */ |
|---|
| 80 | |
|---|
| 81 | #ifdef HAVE_LASTLOG_H |
|---|
| 82 | # include <lastlog.h> |
|---|
| 83 | #endif |
|---|
| 84 | |
|---|
| 85 | #ifdef HAVE_LOGIN_H |
|---|
| 86 | # include <login.h> |
|---|
| 87 | #endif |
|---|
| 88 | |
|---|
| 89 | #ifdef HAVE_PATHS_H |
|---|
| 90 | # include <paths.h> |
|---|
| 91 | #endif |
|---|
| 92 | |
|---|
| 93 | #ifndef PR_LASTLOG_PATH |
|---|
| 94 | # ifdef _PATH_LASTLOG |
|---|
| 95 | # define PR_LASTLOG_PATH _PATH_LASTLOG |
|---|
| 96 | # else |
|---|
| 97 | # ifdef LASTLOG_FILE |
|---|
| 98 | # define PR_LASTLOG_PATH LASTLOG_FILE |
|---|
| 99 | # else |
|---|
| 100 | # error "Missing path to lastlog file (use --with-lastlog=PATH)" |
|---|
| 101 | # endif |
|---|
| 102 | # endif |
|---|
| 103 | #endif |
|---|
| 104 | |
|---|
| 105 | int log_lastlog(uid_t uid, const char *user_name, const char *tty, |
|---|
| 106 | pr_netaddr_t *remote_addr); |
|---|
| 107 | #endif /* PR_USE_LASTLOG */ |
|---|
| 108 | |
|---|
| 109 | /* Note: Like lastlog.h, it would be tempting to split out the declaration of |
|---|
| 110 | * this function, and its necessary system headers, into a proftpd-specific |
|---|
| 111 | * wtmp.h file. But that would collide with the system wtmp.h file on |
|---|
| 112 | * some systems. |
|---|
| 113 | */ |
|---|
| 114 | int log_wtmp(const char *, const char *, const char *, pr_netaddr_t *); |
|---|
| 115 | |
|---|
| 116 | /* file-based logging functions */ |
|---|
| 117 | int pr_log_openfile(const char *, int *, mode_t); |
|---|
| 118 | |
|---|
| 119 | int pr_log_writefile(int, const char *, const char *, ...) |
|---|
| 120 | #ifdef __GNUC__ |
|---|
| 121 | __attribute__ ((format (printf, 3, 4))); |
|---|
| 122 | #else |
|---|
| 123 | ; |
|---|
| 124 | #endif |
|---|
| 125 | |
|---|
| 126 | /* Same as pr_log_writefile(), only this function takes a va_list. |
|---|
| 127 | * Useful for modules which provide their own varargs wrapper log functions, |
|---|
| 128 | * but still want to use the core facilities for writing to the log fd. |
|---|
| 129 | */ |
|---|
| 130 | int pr_log_vwritefile(int, const char *, const char *, va_list ap); |
|---|
| 131 | |
|---|
| 132 | /* syslog-based logging functions. Note that the open/close functions are |
|---|
| 133 | * not part of the public API; use the pr_log_pri() function to log via |
|---|
| 134 | * syslog. |
|---|
| 135 | */ |
|---|
| 136 | void log_closesyslog(void); |
|---|
| 137 | int log_opensyslog(const char *); |
|---|
| 138 | int log_getfacility(void); |
|---|
| 139 | void log_setfacility(int); |
|---|
| 140 | |
|---|
| 141 | void pr_log_pri(int, const char *, ...) |
|---|
| 142 | #ifdef __GNUC__ |
|---|
| 143 | __attribute__ ((format (printf, 2, 3))); |
|---|
| 144 | #else |
|---|
| 145 | ; |
|---|
| 146 | #endif |
|---|
| 147 | |
|---|
| 148 | void pr_log_auth(int, const char *, ...) |
|---|
| 149 | #ifdef __GNUC__ |
|---|
| 150 | __attribute__ ((format (printf, 2, 3))); |
|---|
| 151 | #else |
|---|
| 152 | ; |
|---|
| 153 | #endif |
|---|
| 154 | |
|---|
| 155 | void pr_log_debug(int, const char *, ...) |
|---|
| 156 | #ifdef __GNUC__ |
|---|
| 157 | __attribute__ ((format (printf, 2, 3))); |
|---|
| 158 | #else |
|---|
| 159 | ; |
|---|
| 160 | #endif |
|---|
| 161 | |
|---|
| 162 | int pr_log_setdebuglevel(int); |
|---|
| 163 | |
|---|
| 164 | void log_stderr(int); |
|---|
| 165 | void log_discard(void); |
|---|
| 166 | void init_log(void); |
|---|
| 167 | |
|---|
| 168 | int pr_log_str2sysloglevel(const char *); |
|---|
| 169 | |
|---|
| 170 | /* Define a struct, and some constants, for logging events and any listeners |
|---|
| 171 | * for those events. |
|---|
| 172 | */ |
|---|
| 173 | typedef struct log_event { |
|---|
| 174 | |
|---|
| 175 | /* Type of log event/message; the values are defined below */ |
|---|
| 176 | unsigned int log_type; |
|---|
| 177 | |
|---|
| 178 | /* Log fd associated with this log for this event */ |
|---|
| 179 | int log_fd; |
|---|
| 180 | |
|---|
| 181 | /* Log level of this message; the semantics of the log level depend on |
|---|
| 182 | * on the log type. |
|---|
| 183 | */ |
|---|
| 184 | int log_level; |
|---|
| 185 | |
|---|
| 186 | /* The message being logged. */ |
|---|
| 187 | const char *log_msg; |
|---|
| 188 | size_t log_msglen; |
|---|
| 189 | |
|---|
| 190 | } pr_log_event_t; |
|---|
| 191 | |
|---|
| 192 | #define PR_LOG_TYPE_UNSPEC 0 |
|---|
| 193 | #define PR_LOG_TYPE_XFERLOG 1 |
|---|
| 194 | #define PR_LOG_TYPE_SYSLOG 2 |
|---|
| 195 | #define PR_LOG_TYPE_SYSTEMLOG 3 |
|---|
| 196 | #define PR_LOG_TYPE_EXTLOG 4 |
|---|
| 197 | #define PR_LOG_TYPE_TRACELOG 5 |
|---|
| 198 | |
|---|
| 199 | /* Helper function to generate the necessary log event, passing along the |
|---|
| 200 | * log event context data. |
|---|
| 201 | */ |
|---|
| 202 | int pr_log_event_generate(unsigned int log_type, int log_fd, int log_level, |
|---|
| 203 | const char *log_msg, size_t log_msglen); |
|---|
| 204 | |
|---|
| 205 | /* Returns TRUE if there are listeners for the specified log type, FALSE |
|---|
| 206 | * otherwise. |
|---|
| 207 | */ |
|---|
| 208 | int pr_log_event_listening(unsigned int log_type); |
|---|
| 209 | |
|---|
| 210 | #endif /* PR_LOG_H */ |
|---|