/*********************************************************************\ * Copyright (c) 2003-2005 by Radim Kolar (hsn netmag.cz ) * * Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu) * * * * You may copy or modify this file in any manner you wish, provided * * that this notice is always included, and that you hold the author * * harmless for any loss or damage resulting from the installation or * * use of this software. * \*********************************************************************/ #include "tweak.h" #include "server_def.h" #include "s_extern.h" #include "co_extern.h" #include "my-string.h" #include "pidfile.h" #define NULL_DEV "/dev/null" static int inetd_mode = 0; static const char *config_file = CONF_FILE ; static void display_version (void) { printf( #ifndef LAMERPACK "File Service Protocol Daemon - FSP "PACKAGE_VERSION"\n" "Copyright (c) 1991-1996 by A. J. Doherty, 2001-2005 by Radim Kolar.\n" "All of the FSP code is free software with revised BSD license.\n" "Portions copyright by BSD, Wen-King Su, Philip G. Richards, Michael Meskes.\n" #ifdef __GNUC__ "Compiled "__DATE__" by GCC "__VERSION__"\n" #endif #else "FSP server "PACKAGE_VERSION"\n" "Antiscan protection actived!\n" "For lamah by FSP Gods!\n" #endif ); } /* flush the log message to file */ static void arg_err (void) { #ifndef LAMERPACK fputs("Usage: fspd [-f configfile] [-d directory] [-v|-V] [-i] [-F] [-p port] [-X] [-t inetd timeout] [-T temporary directory] [-l logfile] [-P pidlogname] [-b bytes/sec] [-s packetsize]\n", stderr); #else fputs("Usage: fspd [-d directory] [-p port] [-T temporary directory] [-l logfile] [-b bytes/sec] [-s packetsize]\n", stderr); #endif } static void check_required_vars (void) { double rnd; #ifdef LAMERPACK inetd_mode = 0; daemonize = 0; dbug = 0; dir_cache_limit = 500; udp_port = 80; #endif if(!inetd_mode && udp_port==0) { #ifdef LAMERPACK #else fprintf(stderr, "Error: No port set. (Use 65535 for random port)\n"); exit(1); #endif } if(udp_port == 65535) { /* generate random port in 1024-65535 range */ rnd=(random())/(double)RAND_MAX; udp_port=rnd*(65535-1024)+1024; } if(packetsize > UBUF_MAXSPACE) packetsize = UBUF_MAXSPACE; else if (packetsize == 0) packetsize = DEFAULT_SPACE; else if(packetsize < 64) packetsize = 64; if(!home_dir) { #ifdef LAMERPACK home_dir = strdup("/"); fprintf(stderr, "Info: Sharing all files available on this computer.\n"); #else fprintf(stderr, "Error: No home directory set.\n"); exit(1); #endif } #if 0 if(*home_dir != '/') { fprintf(stderr,"Error: home directory [%s] does not start with a /.\n", home_dir); exit(1); } #endif #if 0 if(!pidlogname) { fprintf(stderr, "No pidlogname set in your fspd.conf.\n"); exit(1); } #endif if(!readme_file) { readme_file = strdup(".README"); } if(logging && !logname) { logging=0; } if(daemonize && dbug) daemonize = 0; if(inetd_mode && dbug) dbug = 0; if(!tmp_dir && !read_only) { #ifndef LAMERPACK if(!inetd_mode) fprintf(stderr,"Warning: no tmpdir set, switching to readonly mode.\n"); #else fprintf(stderr,"Info: Writes disabled because tmpdir not set.\n"); #endif read_only = 1; } } static void init_random (void) { #ifdef HAVE_SRANDOMDEV srandomdev(); #else unsigned int seed; FILE *f; f=fopen("/dev/urandom","rb"); if(f) { fread(&seed,sizeof(unsigned int),1,f); fclose(f); } else seed=getpid()*time(NULL); srandom(seed); #endif } int main (int argc, char ** argv) { int opt; long inetd_timeout=0; if(strlen(argv[0])>=7) inetd_mode = !strcasecmp(&argv[0][strlen(argv[0])-7],"in.fspd"); /* we need to check if we have config file at command line */ for(opt=1;opt 0) { /* father prozess */ _exit(0); } #endif #if HAVE_SETSID setsid(); #endif } } while(1) { server_loop(opt,inetd_timeout); if(inetd_mode||dbug||shutdowning) break; } pidfile_cleanup(pidlogname); shutdown_caches(); destroy_configuration(); exit(0); }