| 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-2010 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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 | /* Scoreboard routines. |
|---|
| 28 | * |
|---|
| 29 | * $Id: utils.h,v 1.25.2.1 2010/03/25 17:37:49 castaglia Exp $ |
|---|
| 30 | */ |
|---|
| 31 | |
|---|
| 32 | #ifndef UTILS_UTILS_H |
|---|
| 33 | #define UTILS_UTILS_H |
|---|
| 34 | |
|---|
| 35 | #include "config.h" |
|---|
| 36 | #include "version.h" |
|---|
| 37 | #include "options.h" |
|---|
| 38 | |
|---|
| 39 | #include <ctype.h> |
|---|
| 40 | #include <errno.h> |
|---|
| 41 | #include <fcntl.h> |
|---|
| 42 | #include <stdio.h> |
|---|
| 43 | #include <stdlib.h> |
|---|
| 44 | #include <string.h> |
|---|
| 45 | #include <time.h> |
|---|
| 46 | |
|---|
| 47 | #ifdef HAVE_GETOPT_H |
|---|
| 48 | # include <getopt.h> |
|---|
| 49 | #else |
|---|
| 50 | # include "../lib/getopt.h" |
|---|
| 51 | #endif /* !HAVE_GETOPT_H */ |
|---|
| 52 | |
|---|
| 53 | #ifdef HAVE_UNISTD_H |
|---|
| 54 | # include <unistd.h> |
|---|
| 55 | #endif |
|---|
| 56 | |
|---|
| 57 | #ifdef HAVE_NETINET_IN_H |
|---|
| 58 | # include <netinet/in.h> |
|---|
| 59 | #endif |
|---|
| 60 | |
|---|
| 61 | #ifdef HAVE_SYS_FILE_H |
|---|
| 62 | # include <sys/file.h> |
|---|
| 63 | #endif |
|---|
| 64 | |
|---|
| 65 | #ifdef HAVE_SYS_SOCKET_H |
|---|
| 66 | # include <sys/socket.h> |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | #ifdef HAVE_SYS_STAT_H |
|---|
| 70 | # include <sys/stat.h> |
|---|
| 71 | #endif |
|---|
| 72 | |
|---|
| 73 | #include "default_paths.h" |
|---|
| 74 | |
|---|
| 75 | #define FALSE 0 |
|---|
| 76 | #define TRUE 1 |
|---|
| 77 | |
|---|
| 78 | #ifndef INET_ADDRSTRLEN |
|---|
| 79 | # define INET_ADDRSTRLEN 16 |
|---|
| 80 | #endif /* INET_ADDRSTRLEN */ |
|---|
| 81 | |
|---|
| 82 | #ifndef INET6_ADDRSTRLEN |
|---|
| 83 | # define INET6_ADDRSTRLEN 46 |
|---|
| 84 | #endif /* INET6_ADDRSTRLEN */ |
|---|
| 85 | |
|---|
| 86 | /* UTIL_SCOREBOARD_VERSION is used for checking for scoreboard compatibility |
|---|
| 87 | */ |
|---|
| 88 | #define UTIL_SCOREBOARD_VERSION 0x01040003 |
|---|
| 89 | |
|---|
| 90 | /* Structure used as a header for scoreboard files. |
|---|
| 91 | */ |
|---|
| 92 | #define UTIL_SCOREBOARD_MAGIC 0xdeadbeef |
|---|
| 93 | |
|---|
| 94 | typedef struct { |
|---|
| 95 | |
|---|
| 96 | /* Always 0xDEADBEEF */ |
|---|
| 97 | unsigned long sch_magic; |
|---|
| 98 | |
|---|
| 99 | /* Version of proftpd that created the scoreboard file */ |
|---|
| 100 | unsigned long sch_version; |
|---|
| 101 | |
|---|
| 102 | /* PID of the process to which this scoreboard belongs, or zero if inetd */ |
|---|
| 103 | pid_t sch_pid; |
|---|
| 104 | |
|---|
| 105 | /* Time when the daemon wrote this header */ |
|---|
| 106 | time_t sch_uptime; |
|---|
| 107 | |
|---|
| 108 | } pr_scoreboard_header_t; |
|---|
| 109 | |
|---|
| 110 | /* Structure used for writing scoreboard file entries. |
|---|
| 111 | */ |
|---|
| 112 | |
|---|
| 113 | typedef struct { |
|---|
| 114 | pid_t sce_pid; |
|---|
| 115 | uid_t sce_uid; |
|---|
| 116 | gid_t sce_gid; |
|---|
| 117 | char sce_user[32]; |
|---|
| 118 | |
|---|
| 119 | int sce_server_port; |
|---|
| 120 | char sce_server_addr[80], sce_server_label[32]; |
|---|
| 121 | |
|---|
| 122 | #ifdef PR_USE_IPV6 |
|---|
| 123 | char sce_client_addr[INET6_ADDRSTRLEN]; |
|---|
| 124 | #else |
|---|
| 125 | char sce_client_addr[INET_ADDRSTRLEN]; |
|---|
| 126 | #endif /* PR_USE_IPV6 */ |
|---|
| 127 | char sce_client_name[PR_TUNABLE_SCOREBOARD_BUFFER_SIZE]; |
|---|
| 128 | |
|---|
| 129 | char sce_class[32]; |
|---|
| 130 | char sce_protocol[32]; |
|---|
| 131 | char sce_cwd[PR_TUNABLE_SCOREBOARD_BUFFER_SIZE]; |
|---|
| 132 | |
|---|
| 133 | char sce_cmd[65]; |
|---|
| 134 | char sce_cmd_arg[PR_TUNABLE_SCOREBOARD_BUFFER_SIZE]; |
|---|
| 135 | |
|---|
| 136 | time_t sce_begin_idle, sce_begin_session; |
|---|
| 137 | |
|---|
| 138 | off_t sce_xfer_size, sce_xfer_done, sce_xfer_len; |
|---|
| 139 | unsigned long sce_xfer_elapsed; |
|---|
| 140 | |
|---|
| 141 | } pr_scoreboard_entry_t; |
|---|
| 142 | |
|---|
| 143 | /* Scoreboard error values */ |
|---|
| 144 | #define UTIL_SCORE_ERR_BAD_MAGIC -2 |
|---|
| 145 | #define UTIL_SCORE_ERR_OLDER_VERSION -3 |
|---|
| 146 | #define UTIL_SCORE_ERR_NEWER_VERSION -4 |
|---|
| 147 | |
|---|
| 148 | char *util_sstrncpy(char *, const char *, size_t); |
|---|
| 149 | |
|---|
| 150 | const char *util_get_scoreboard(void); |
|---|
| 151 | int util_set_scoreboard(const char *); |
|---|
| 152 | |
|---|
| 153 | char *util_scan_config(const char *, const char *); |
|---|
| 154 | |
|---|
| 155 | int util_close_scoreboard(void); |
|---|
| 156 | int util_open_scoreboard(int); |
|---|
| 157 | pid_t util_scoreboard_get_daemon_pid(void); |
|---|
| 158 | time_t util_scoreboard_get_daemon_uptime(void); |
|---|
| 159 | pr_scoreboard_entry_t *util_scoreboard_entry_read(void); |
|---|
| 160 | int util_scoreboard_scrub(int); |
|---|
| 161 | |
|---|
| 162 | #endif /* UTILS_UTILS_H */ |
|---|