1/* -*- C -*- 2 * Copyright (c) 1997, 99, 2000, 01 3 * Motoyuki Kasahara 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 */ 15 16#ifndef DEFS_H 17#define DEFS_H 18 19#ifdef HAVE_CONFIG_H 20#include "config.h" 21#endif 22 23#include <stdio.h> 24#include <time.h> 25#include <sys/types.h> 26#include <sys/socket.h> 27 28#if defined(EBNETD) || defined(USE_TINYEB) 29#include "ebtiny/eb.h" 30#include "ebtiny/error.h" 31#else 32#if defined(NDTPD) || defined(EBHTTPD) 33#include <eb/eb.h> 34#include <eb/error.h> 35#endif 36#endif 37 38#include "readconf.h" 39#include "permission.h" 40#include "ticket.h" 41 42/* 43 * Software name and program names. 44 */ 45#ifdef EBNETD 46#define SOFTWARE_NAME "EBNETD" 47#define SERVER_PROGRAM_NAME "ebnetd" 48#define CHECK_PROGRAM_NAME "ebncheck" 49#define CONTROL_PROGRAM_NAME "ebncontrol" 50#endif 51#ifdef NDTPD 52#define SOFTWARE_NAME "NDTPD" 53#define SERVER_PROGRAM_NAME "ndtpd" 54#define CHECK_PROGRAM_NAME "ndtpcheck" 55#define CONTROL_PROGRAM_NAME "ndtpcontorl" 56#endif 57#ifdef EBHTTPD 58#define SOFTWARE_NAME "ebHTTPD" 59#define SERVER_PROGRAM_NAME "ebhttpd" 60#define CHECK_PROGRAM_NAME "ebhtcheck" 61#define CONTROL_PROGRAM_NAME "ebhtcontrol" 62#endif 63 64/* 65 * Configuration filename. 66 */ 67#define DEFAULT_CONFIGURATION_FILE_NAME "@sysconfdir@/ebnetd.conf" 68 69/* 70 * Path to a working directory. 71 */ 72#define DEFAULT_WORK_PATH "@pkglocalstatedir@" 73 74/* 75 * Basename of the file on which the sever writes its process ID. 76 * (Its length must not exceed MAX_WORK_PATH_BASE_NAME_LENGTH characters.) 77 */ 78#ifdef EBNETD 79#define PID_BASE_NAME "ebnd.pid" 80#endif 81#ifdef NDTPD 82#define PID_BASE_NAME "ndtpd.pid" 83#endif 84#ifdef EBHTTPD 85#define PID_BASE_NAME "ebhttpd.pid" 86#endif 87 88/* 89 * Basename of the lock file that records the number of running 90 * server processes invoked by inetd. 91 * (Its length must not exceed MAX_WORK_PATH_BASE_NAME_LENGTH characters. 92 * It must not conflict with "<book-name>.<lock-suffix>".) 93 */ 94#ifdef EBNETD 95#define LOCK_BASE_NAME "ebnetd.lock" 96#endif 97#ifdef NDTPD 98#define LOCK_BASE_NAME "ndtpd.lock" 99#endif 100#ifdef EBHTTPD 101#define LOCK_BASE_NAME "ebhttpd.lock" 102#endif 103 104/* 105 * Base name of the mtime file. 106 * Last modified time of this file becomes last modified time of all 107 * contents on the server. 108 */ 109#ifdef EBHTTPD 110#define MTIME_BASE_NAME "ebhttpd.mtime" 111#endif 112 113/* 114 * Port number on which the server listens. 115 * It must be a TCP protocol name or a port number. 116 */ 117#ifdef EBNETD 118#define SERVICE_NAME "ebnet" 119#define DEFAULT_PORT 22010 120#endif 121#ifdef NDTPD 122#define SERVICE_NAME "ndtp" 123#define DEFAULT_PORT 2010 124#endif 125#ifdef EBHTTPD 126#define SERVICE_NAME "http" 127#define DEFAULT_PORT 80 128#endif 129 130/* 131 * Suffix of the lock file. 132 * (The length of the "<book-name>.<lock-suffix>" file must not exceed 133 * MAX_WORK_PATH_BASE_NAME_LENGTH characters.) 134 */ 135#define BOOK_LOCK_SUFFIX "lock" 136 137/* 138 * How many connections the server accepts at the same time. 139 */ 140#define DEFAULT_MAX_CLIENTS 1 141 142/* 143 * How many clients can use a book at the same time. 144 */ 145#define DEFAULT_BOOK_MAX_CLIENTS 1 146 147/* 148 * Seconds until the server closes a idle connection. 149 */ 150#define DEFAULT_IDLE_TIMEOUT 900 151 152/* 153 * Syslog facility. 154 */ 155#define DEFAULT_SYSLOG_FACILITY LOG_DAEMON 156 157/* 158 * The number of hit entries the server give up searching. 159 */ 160#define DEFAULT_MAX_HITS 50 161 162/* 163 * The default maximum size of text the server may send as a response to 164 * a client. 165 */ 166#define DEFAULT_MAX_TEXT_SIZE 32768 167 168/* 169 * The umask value of the server. 170 */ 171#define SERVER_UMASK 022 172 173/* 174 * Maximum lengh of a generic string. 175 */ 176#define MAX_STRING_LENGTH 511 177 178/* 179 * Maximum lengh of a book name. 180 */ 181#define MAX_BOOK_NAME_LENGTH 14 182 183/* 184 * Maximum lengh of a book title. 185 */ 186#define MAX_BOOK_TITLE_LENGTH 80 187 188/* 189 * Maximum length of a basename written in the work-path directory. 190 */ 191#define MAX_WORK_PATH_BASE_NAME_LENGTH 32 192 193/* 194 * Backlog for listen(). 195 */ 196#define LISTENING_BACKLOG 5 197 198/* 199 * Running modes of the server. 200 */ 201#define SERVER_MODE_STANDALONE 0 202#define SERVER_MODE_INETD 1 203#define SERVER_MODE_TEST 2 204#define SERVER_MODE_CHECK 3 205#define SERVER_MODE_CONTROL 4 206 207/* 208 * Book -- represents a book. 209 */ 210typedef struct Book_Struct Book; 211struct Book_Struct { 212 /* 213 * Path of the book. 214 */ 215 char *path; 216 217 /* 218 * Path of the book. 219 */ 220 char *appendix_path; 221 222 /* 223 * Name of the book. 224 */ 225 char name[MAX_BOOK_NAME_LENGTH + 1]; 226 227 /* 228 * Access permission to the current client. 229 */ 230 int permission_flag; 231 232 /* 233 * Title of the book. 234 */ 235 char title[MAX_BOOK_TITLE_LENGTH + 1]; 236 237 /* 238 * The maximum number of connections to the book. 239 */ 240 int max_clients; 241 242 /* 243 * Access permission list to the book. 244 */ 245 Permission permissions; 246 247 /* 248 * Ticket stock (`max-clients' controler). 249 */ 250 Ticket_Stock ticket_stock; 251 252 /* 253 * Entity of the CD-ROM book. 254 */ 255 EB_Book book; 256 257 /* 258 * Appendix entitiy of the CD-ROM book. 259 */ 260 EB_Appendix appendix; 261 262 /* 263 * Refer to a next book. 264 * Set to NULL when there is no more book. 265 */ 266 Book *next; 267}; 268 269/* 270 * Trick for function protypes. 271 */ 272#ifndef EBNETD_P 273#ifdef __STDC__ 274#define EBNETD_P(p) p 275#else /* not __STDC__ */ 276#define EBNETD_P(p) () 277#endif /* not __STDC__ */ 278#endif /* EBNETD_P */ 279 280/* 281 * Function declarations. 282 */ 283/* book.c */ 284void initialize_book_registry EBNETD_P((void)); 285void finalize_book_registry EBNETD_P((void)); 286void terminate_book_registry EBNETD_P((void)); 287int count_book_registry EBNETD_P((void)); 288int activate_book_registry EBNETD_P((void)); 289Book *add_book EBNETD_P((void)); 290int delete_book EBNETD_P((Book *)); 291Book *find_book EBNETD_P((const char *)); 292EB_Subbook_Code find_subbook EBNETD_P((Book *, const char *)); 293EB_Subbook_Code find_appendix_subbook EBNETD_P((Book *, const char *)); 294void check_book_permissions EBNETD_P((void)); 295void set_all_book_permissions EBNETD_P((void)); 296/* global.c */ 297int initialize_global_variables EBNETD_P((void)); 298void finalize_global_variables EBNETD_P((void)); 299/* misc.c */ 300void output_version EBNETD_P((void)); 301void output_try_help EBNETD_P((void)); 302/* ndtp.c */ 303int protocol_main EBNETD_P((void)); 304 305/* 306 * Global variables. 307 */ 308extern Configuration configuration_table[]; 309extern const char *invoked_name; 310extern const char *program_name; 311extern const char *program_version; 312extern char work_path[]; 313extern char configuration_file_name[]; 314extern in_port_t listening_port; 315extern in_port_t old_listening_port; 316extern fd_set listening_files; 317extern int max_listening_file; 318extern int accepted_in_file; 319extern int accepted_out_file; 320extern uid_t user_id; 321extern gid_t group_id; 322extern char pid_file_name[]; 323extern char old_pid_file_name[]; 324extern char connection_lock_file_name[]; 325extern Ticket_Stock connection_ticket_stock; 326extern int max_clients; 327extern int connection_count; 328extern int idle_timeout; 329extern Permission permissions; 330extern Book *book_registry; 331extern Book *book_registry_tail; 332extern int book_count; 333extern int max_hits; 334extern size_t max_text_size; 335extern char client_host_name[]; 336extern char client_address[]; 337extern int server_mode; 338extern int syslog_facility; 339 340#endif /* not DEFS_H */ 341