| 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 | /* General options |
|---|
| 28 | * $Id: proftpd.h,v 1.71 2011/09/21 05:40:04 castaglia Exp $ |
|---|
| 29 | */ |
|---|
| 30 | |
|---|
| 31 | #ifndef PR_PROFTPD_H |
|---|
| 32 | #define PR_PROFTPD_H |
|---|
| 33 | |
|---|
| 34 | #include "class.h" |
|---|
| 35 | |
|---|
| 36 | #ifndef TRUE |
|---|
| 37 | # define TRUE 1 |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | #ifndef FALSE |
|---|
| 41 | # define FALSE 0 |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | /* Definition of root user/group IDs (non-Unix platforms may have these as |
|---|
| 45 | * different from 0/0). |
|---|
| 46 | */ |
|---|
| 47 | #ifdef __CYGWIN__ |
|---|
| 48 | # define PR_ROOT_UID 18 |
|---|
| 49 | # define PR_ROOT_GID 544 |
|---|
| 50 | #else |
|---|
| 51 | # define PR_ROOT_UID 0 |
|---|
| 52 | # define PR_ROOT_GID 0 |
|---|
| 53 | #endif /* __CYGWIN__ */ |
|---|
| 54 | |
|---|
| 55 | #define CALLBACK_FRAME \ |
|---|
| 56 | unsigned long p1, unsigned long p2, unsigned long p3, void *data |
|---|
| 57 | |
|---|
| 58 | #define ASSERT(x) assert(x) |
|---|
| 59 | #include <assert.h> |
|---|
| 60 | |
|---|
| 61 | typedef int (*callback_t)(CALLBACK_FRAME); |
|---|
| 62 | |
|---|
| 63 | struct conn_struc; |
|---|
| 64 | struct cmd_struc; |
|---|
| 65 | struct config_struc; |
|---|
| 66 | struct modret_struc; |
|---|
| 67 | |
|---|
| 68 | typedef struct { |
|---|
| 69 | pool *pool; |
|---|
| 70 | |
|---|
| 71 | volatile int sf_flags; /* Session/State flags */ |
|---|
| 72 | volatile int sp_flags; /* Session/Protection flags */ |
|---|
| 73 | |
|---|
| 74 | pr_netaddr_t data_addr; /* Remote data address */ |
|---|
| 75 | unsigned short data_port; /* Remote data port */ |
|---|
| 76 | |
|---|
| 77 | const char *auth_mech; /* Name of the authentication |
|---|
| 78 | * module/mechanism that successfully |
|---|
| 79 | * authenticated the client |
|---|
| 80 | */ |
|---|
| 81 | |
|---|
| 82 | const char *rfc2228_mech; /* RFC2228 authentication mechanism |
|---|
| 83 | * used |
|---|
| 84 | */ |
|---|
| 85 | |
|---|
| 86 | char cwd[PR_TUNABLE_PATH_MAX]; /* Current working directory */ |
|---|
| 87 | char vwd[PR_TUNABLE_PATH_MAX]; /* Current virtual working directory */ |
|---|
| 88 | |
|---|
| 89 | struct config_struc *dir_config; /* Closest matching configuration |
|---|
| 90 | * for current operation |
|---|
| 91 | */ |
|---|
| 92 | |
|---|
| 93 | /* Process ID of the session */ |
|---|
| 94 | pid_t pid; |
|---|
| 95 | |
|---|
| 96 | /* The uid/gids are manipulated by the PRIVS macros in |
|---|
| 97 | * privs.h |
|---|
| 98 | */ |
|---|
| 99 | |
|---|
| 100 | int disable_id_switching; /* Disable UID/GID switching */ |
|---|
| 101 | uid_t uid, ouid; /* Current and original UIDs */ |
|---|
| 102 | gid_t gid; /* Current GID */ |
|---|
| 103 | |
|---|
| 104 | array_header *gids; |
|---|
| 105 | array_header *groups; |
|---|
| 106 | |
|---|
| 107 | /* fsuid/fsgid are used for automagic chown after creation or upload. |
|---|
| 108 | * They are initially -1, meaning no chown/chgrp. |
|---|
| 109 | */ |
|---|
| 110 | uid_t fsuid; /* Saved file UID */ |
|---|
| 111 | gid_t fsgid; /* Saved file GID */ |
|---|
| 112 | |
|---|
| 113 | char *user,*group; /* Username/groupname after login */ |
|---|
| 114 | uid_t login_uid; /* UID after login, but before |
|---|
| 115 | * session.uid is changed |
|---|
| 116 | */ |
|---|
| 117 | gid_t login_gid; /* GID after login, but before |
|---|
| 118 | * session.gid is changed |
|---|
| 119 | */ |
|---|
| 120 | |
|---|
| 121 | pr_table_t *notes; /* Session notes table */ |
|---|
| 122 | |
|---|
| 123 | pr_class_t *class; /* Session class */ |
|---|
| 124 | char *proc_prefix; /* The "prefix" of our process name */ |
|---|
| 125 | |
|---|
| 126 | int wtmp_log; /* Are we logging to wtmp? */ |
|---|
| 127 | int multiline_rfc2228; /* Are we using RFC2228-style multiline responses ? */ |
|---|
| 128 | |
|---|
| 129 | struct conn_struc *c; /* Control connection */ |
|---|
| 130 | struct conn_struc *d; /* Data connection */ |
|---|
| 131 | |
|---|
| 132 | int hide_password; /* Hide password in logs/ps listing */ |
|---|
| 133 | |
|---|
| 134 | char *chroot_path; /* Chroot directory */ |
|---|
| 135 | |
|---|
| 136 | struct config_struc *anon_config; /* Anonymous FTP configuration */ |
|---|
| 137 | char *anon_user; /* E-mail address sent to us */ |
|---|
| 138 | |
|---|
| 139 | char *curr_cmd; /* Current FTP command */ |
|---|
| 140 | int curr_cmd_id; /* Current FTP command ID */ |
|---|
| 141 | struct cmd_struc *curr_cmd_rec; /* Current command */ |
|---|
| 142 | |
|---|
| 143 | int curr_phase; /* Current handler phase */ |
|---|
| 144 | |
|---|
| 145 | off_t restart_pos; /* Restart marked position */ |
|---|
| 146 | |
|---|
| 147 | struct { |
|---|
| 148 | struct pool *p; |
|---|
| 149 | |
|---|
| 150 | int xfer_type; /* xfer session attributes, default/append/hidden */ |
|---|
| 151 | int direction; |
|---|
| 152 | char *filename; /* As shown to user */ |
|---|
| 153 | char *path; /* As used in transfer */ |
|---|
| 154 | char *path_hidden; /* As used in hidden stor */ |
|---|
| 155 | |
|---|
| 156 | unsigned int bufsize,buflen; |
|---|
| 157 | |
|---|
| 158 | struct timeval start_time; /* Time current transfer started */ |
|---|
| 159 | off_t file_size; /* Total size of file (if known) */ |
|---|
| 160 | off_t total_bytes; /* Total bytes transfered */ |
|---|
| 161 | |
|---|
| 162 | char *bufstart,*buf; |
|---|
| 163 | } xfer; |
|---|
| 164 | |
|---|
| 165 | /* Total number of bytes uploaded in this session. */ |
|---|
| 166 | off_t total_bytes_in; |
|---|
| 167 | |
|---|
| 168 | /* Total number of bytes downloaded in this session. */ |
|---|
| 169 | off_t total_bytes_out; |
|---|
| 170 | |
|---|
| 171 | /* Total number of bytes transfered in this session. */ |
|---|
| 172 | off_t total_bytes; |
|---|
| 173 | |
|---|
| 174 | /* Total number of files uploaded in this session. */ |
|---|
| 175 | unsigned int total_files_in; |
|---|
| 176 | |
|---|
| 177 | /* Total number of files downloaded in this session. */ |
|---|
| 178 | unsigned int total_files_out; |
|---|
| 179 | |
|---|
| 180 | /* Total number of files transfered (both uploaded and downloaded) in |
|---|
| 181 | * this session. |
|---|
| 182 | */ |
|---|
| 183 | unsigned int total_files_xfer; |
|---|
| 184 | |
|---|
| 185 | /* Total number of "raw" protocol bytes read in from the network for |
|---|
| 186 | * the session. |
|---|
| 187 | */ |
|---|
| 188 | off_t total_raw_in; |
|---|
| 189 | |
|---|
| 190 | /* Total number of "raw" protocol bytes written out to the network for |
|---|
| 191 | * the session. |
|---|
| 192 | */ |
|---|
| 193 | off_t total_raw_out; |
|---|
| 194 | |
|---|
| 195 | /* Reason code for end of session/disconnection; in reality, the values |
|---|
| 196 | * come from the pr_disconnect_reason_e enum in session.h. |
|---|
| 197 | */ |
|---|
| 198 | int disconnect_reason; |
|---|
| 199 | |
|---|
| 200 | /* Module which disconnected/ended the session */ |
|---|
| 201 | struct module_struc *disconnect_module; |
|---|
| 202 | |
|---|
| 203 | } session_t; |
|---|
| 204 | |
|---|
| 205 | /* Daemon identity values, defined in main.c */ |
|---|
| 206 | extern uid_t daemon_uid; |
|---|
| 207 | extern gid_t daemon_gid; |
|---|
| 208 | extern array_header *daemon_gids; |
|---|
| 209 | |
|---|
| 210 | /* Possible values for xfer.xfer_type, mutually exclusive */ |
|---|
| 211 | #define STOR_DEFAULT 0 |
|---|
| 212 | #define STOR_APPEND 1 |
|---|
| 213 | #define STOR_HIDDEN 2 |
|---|
| 214 | #define STOR_UNIQUE 3 |
|---|
| 215 | |
|---|
| 216 | extern session_t session; |
|---|
| 217 | extern char AddressCollisionCheck; |
|---|
| 218 | extern char ServerType; |
|---|
| 219 | |
|---|
| 220 | /* Session/State flags */ |
|---|
| 221 | |
|---|
| 222 | #define SF_PASSIVE 0x0001 /* Data connection is in passive mode */ |
|---|
| 223 | #define SF_ABORT 0x0002 /* Abort in progess */ |
|---|
| 224 | #define SF_XFER 0x0004 /* Transfer in progress */ |
|---|
| 225 | #define SF_ASCII 0x0010 /* ASCII mode transfer */ |
|---|
| 226 | #define SF_ASCII_OVERRIDE 0x0020 /* ASCII override this xfer only */ |
|---|
| 227 | #define SF_ANON 0x0040 /* Anonymous (chroot) login */ |
|---|
| 228 | #define SF_POST_ABORT 0x0100 /* After abort has occured */ |
|---|
| 229 | #define SF_PORT 0x0200 /* Port command given */ |
|---|
| 230 | #define SF_EPSV_ALL 0x0400 /* EPSV ALL in effect */ |
|---|
| 231 | |
|---|
| 232 | #define SF_ALL (SF_PASSIVE|SF_ABORT|SF_XFER|SF_ASCII| \ |
|---|
| 233 | SF_ASCII_OVERRIDE|SF_ANON|SF_POST_ABORT|SF_PORT| \ |
|---|
| 234 | SF_EPSV_ALL) |
|---|
| 235 | |
|---|
| 236 | /* Session/Protection flags (RFC 2228) */ |
|---|
| 237 | |
|---|
| 238 | #define SP_CCC (1 << 0) /* Clear command channel */ |
|---|
| 239 | #define SP_ENC (1 << 1) /* Privacy protected command */ |
|---|
| 240 | #define SP_MIC (1 << 2) /* Integrity protected command */ |
|---|
| 241 | #define SP_CONF (1 << 3) /* Confidentiality protected command */ |
|---|
| 242 | |
|---|
| 243 | /* Macro to test global abort flag */ |
|---|
| 244 | #define XFER_ABORTED (session.sf_flags & SF_ABORT) |
|---|
| 245 | |
|---|
| 246 | /* Server Types */ |
|---|
| 247 | #define SERVER_INETD 0 |
|---|
| 248 | #define SERVER_STANDALONE 1 |
|---|
| 249 | |
|---|
| 250 | /* Signals */ |
|---|
| 251 | #define RECEIVED_SIG_RESTART 0x0001 |
|---|
| 252 | #define RECEIVED_SIG_EXIT 0x0002 |
|---|
| 253 | #define RECEIVED_SIG_SHUTDOWN 0x0004 |
|---|
| 254 | #define RECEIVED_SIG_SEGV 0x0008 |
|---|
| 255 | #define RECEIVED_SIG_TERMINATE 0x0010 |
|---|
| 256 | #define RECEIVED_SIG_XCPU 0x0020 |
|---|
| 257 | #define RECEIVED_SIG_TERM_OTHER 0x0040 |
|---|
| 258 | #define RECEIVED_SIG_ABORT 0x0080 |
|---|
| 259 | #define RECEIVED_SIG_EVENT 0x0100 |
|---|
| 260 | #define RECEIVED_SIG_CHLD 0x0200 |
|---|
| 261 | #define RECEIVED_SIG_ALRM 0x0400 |
|---|
| 262 | |
|---|
| 263 | /* Timers */ |
|---|
| 264 | #define PR_TIMER_LOGIN 1 |
|---|
| 265 | #define PR_TIMER_IDLE 2 |
|---|
| 266 | #define PR_TIMER_NOXFER 3 |
|---|
| 267 | #define PR_TIMER_STALLED 4 |
|---|
| 268 | #define PR_TIMER_SESSION 5 |
|---|
| 269 | |
|---|
| 270 | /* Developer code */ |
|---|
| 271 | |
|---|
| 272 | #ifdef PR_DEVEL_TIMING |
|---|
| 273 | # define PR_DEVEL_CLOCK(code) \ |
|---|
| 274 | { \ |
|---|
| 275 | int local_errno; \ |
|---|
| 276 | struct timeval local_before, local_after, local_since; \ |
|---|
| 277 | timerclear(&local_before); \ |
|---|
| 278 | timerclear(&local_after); \ |
|---|
| 279 | timerclear(&local_since); \ |
|---|
| 280 | (void) gettimeofday(&local_before, NULL); \ |
|---|
| 281 | (code); \ |
|---|
| 282 | local_errno = errno; \ |
|---|
| 283 | (void) gettimeofday(&local_after, NULL); \ |
|---|
| 284 | timersub(&local_after, &local_before, &local_since); \ |
|---|
| 285 | (void) pr_trace_msg("timing", 9, "code at %s:%d took %lu sec, %lu usec", __FILE__, __LINE__, (unsigned long) local_since.tv_sec, (unsigned long) local_since.tv_usec); \ |
|---|
| 286 | errno = local_errno; \ |
|---|
| 287 | } |
|---|
| 288 | #else |
|---|
| 289 | # define PR_DEVEL_CLOCK(code) (code) |
|---|
| 290 | #endif /* PR_DEVEL_TIMING */ |
|---|
| 291 | |
|---|
| 292 | /* Misc Prototypes */ |
|---|
| 293 | void pr_signals_handle(void); |
|---|
| 294 | void session_exit(int, void *, int, void *); |
|---|
| 295 | void set_daemon_rlimits(void); |
|---|
| 296 | void set_session_rlimits(void); |
|---|
| 297 | |
|---|
| 298 | #endif /* PR_PROFTPD_H */ |
|---|