From 5dec4e62addcb5252e25247d7fa43e09fba9505f Mon Sep 17 00:00:00 2001
From: Luke Dashjr <luke-jr+git@utopios.org>
Date: Thu, 3 Nov 2011 20:40:30 -0400
Subject: [PATCH 3/3] Integrate File I/O extension into the server distribution

---
 FileioDocs.txt     |   50 +++++++++++++++-----------------------------------
 README.fileio      |    5 -----
 extension-fileio.c |   12 +++++++-----
 extension-fileio.h |   15 ---------------
 functions.c        |    2 --
 options.h          |   22 ++++++++++++++++++++++
 6 files changed, 44 insertions(+), 62 deletions(-)
 delete mode 100644 README.fileio
 delete mode 100644 extension-fileio.h

diff --git a/FileioDocs.txt b/FileioDocs.txt
index 4f02a24..e2a838c 100644
--- a/FileioDocs.txt
+++ b/FileioDocs.txt
@@ -1,25 +1,25 @@
   File I/O
   Ken Fox, Andy Bakun, Todd Sundsted
 
-  This is the documentation for the File I/O (FIO) patch for the Lamb-
-  daMOO server.  FIO adds several administrator-only builtins for manip-
-  ulating files from inside the MOO.  Security is enforced by making
-  these builtins executable with wizard permissions only as well as only
-  allowing access to a directory under the current directory (the one
-  the server is running in).
+  This is the documentation for the File I/O (FIO) extension for the
+  LambdaMOO server.  FIO adds several administrator-only builtins for
+  manipulating files from inside the MOO.  Security is enforced by
+  making these builtins executable with wizard permissions only as well
+  as only allowing access to a directory under the current directory
+  (the one the server is running in).
 
   1.  Introduction
 
   1.1.  Purpose
 
-  This patch to the LambdaMOO server adds several new builtins that
+  This extension to the LambdaMOO server adds several new builtins that
   allow the manipulation of files from MOO code.   The new builtins are
   structured similarly to the stdio library for C.  This allows MOO-code
   to perform stream-oriented I/O to files.
 
   Granting MOO code direct access to files opens a hole in the otherwise
   fairly good wall that the LambdaMOO server puts up between the OS and
-  the database.  The patch contains the risk as much as possible by
+  the database.  The extension contains the risk as much as possible by
   restricting where files can be opened and allowing the new builtins to
   be called by wizard permissions only.  It is still possible execute
   various forms denial of service attacks, but the MOO server allows
@@ -54,34 +54,14 @@
 
   2.  Installation
 
-  Most of the new code for this patch are in the files extension-
-  fileio.c and extension-fileio.h.  These files contain the header and
-  implementation for all of the new builtin functions.  One line has to
-  be added to bf_register.h and a related line must be added
-  functions.c.
+  To enable this extension, you must edit options.h prior to compiling
+  and uncomment out the following line:
+         #define FILE_IO 1
 
-  The distribution archive should contain the text version of this
-  documentation (fileio-README), extension-fileio.c, extension-fileio.h,
-  and fileio.patch.
-
-  If you are going to use patch to install it, just copy fileio.patch
-  into the server directory and apply the patch:
-
-         patch < fileio.patch
-
-  It is recommended that you use patch to install it, but you can also
-  manually make the changes to the server source.  First, copy the
-  extension-fileio.c and .h files into a directory with the freshly
-  untarred server source.  Add extension-fileio.c to the CSRCS line of
-  Makefile.in, add
-
-          extern void register_fileio(void);
-
-  to bf_register.h and add
-
-         register_fileio
-
-  to the list of functions in functions.c.
+  You may also edit other detailed settings:
+    FILE_IO_MAX_FILES           the limit of files open
+    FILE_SUBDIR                 the File I/O jail directory
+    FILE_IO_BUFFER_LENGTH       the maximum line/data length
 
   Finally, make the files directory in the directory the MOO server is
   run in.  Only files in this directory will be accessible using this
diff --git a/README.fileio b/README.fileio
deleted file mode 100644
index c8a91b9..0000000
--- a/README.fileio
+++ /dev/null
@@ -1,5 +0,0 @@
-
-Welcome to FileIO.
-
-FileIO is a patch to the LambdaMOO server to allow stdio-style access to
-files.  Please see the file FileioDocs.txt for complete information.
diff --git a/extension-fileio.c b/extension-fileio.c
index 269ec2e..f876e36 100644
--- a/extension-fileio.c
+++ b/extension-fileio.c
@@ -1,8 +1,10 @@
 /*
- * file i/o server modification
+ * File I/O extension
  */
 
-#define FILE_IO 1
+#include "options.h"
+
+#ifdef FILE_IO
 
 #include <stdio.h>
 
@@ -33,8 +35,6 @@
 #include "tasks.h"
 #include "log.h"
 
-#include "extension-fileio.h"
-
 /* apparently, not defined on some SysVish systems -- AAB 06/03/97 */
 typedef unsigned short umode_t;
 /* your system may define o_mode_t instead -- AAB 06/03/97 */
@@ -1567,12 +1567,14 @@ bf_file_chmod(Var arglist, Byte next, void *vdata, Objid progr)
     return r;
 }
 
+#endif
+
 /************************************************************************/
 
 void
 register_fileio(void)
 {
-#if FILE_IO
+#ifdef FILE_IO
 
     register_function("file_version", 0, 0, bf_file_version);
 
diff --git a/extension-fileio.h b/extension-fileio.h
deleted file mode 100644
index 11cf885..0000000
--- a/extension-fileio.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * extension-fileio.h
- *
- */
-
-#ifndef EXT_FILE_IO_H
-
-#define EXT_FILE_IO_H 1
-
-#define FILE_IO_MAX_FILES 256
-#define FILE_SUBDIR "files/"
-
-#define FILE_IO_BUFFER_LENGTH 4096
-
-#endif
diff --git a/functions.c b/functions.c
index d8b0b5e..b67e863 100644
--- a/functions.c
+++ b/functions.c
@@ -55,9 +55,7 @@ static registry bi_function_registries[] =
     register_server,
     register_tasks,
     register_verbs,
-/***************************/
     register_fileio
-/***************************/
 };
 
 void
diff --git a/options.h b/options.h
index 4488f0f..079ed4d 100644
--- a/options.h
+++ b/options.h
@@ -183,6 +183,28 @@
 #define MAX_QUEUED_INPUT	MAX_QUEUED_OUTPUT
 #define DEFAULT_CONNECT_TIMEOUT	300
 
+ /******************************************************************************
+ * The File I/O extension adds several new builtins that allow the
+ * manipulation of files from MOO code. Please read FileioDocs.txt for more
+ * details.
+ *
+ * *** THINK VERY HARD BEFORE ENABLING THIS EXTENSION ***
+ * Granting MOO code direct access to files opens a hole in the otherwise
+ * fairly good wall that the LambdaMOO server puts up between the OS and
+ * the database.  The extension contains the risk as much as possible by
+ * restricting where files can be opened and allowing the new builtins to
+ * be called by wizard permissions only.  It is still possible execute
+ * various forms denial of service attacks, but the MOO server allows
+ * this form of attack as well.
+ */
+
+/* #define FILE_IO 1 */
+
+#define FILE_IO_MAX_FILES 256
+#define FILE_SUBDIR "files/"
+
+#define FILE_IO_BUFFER_LENGTH 4096
+
 /******************************************************************************
  * The server maintains a cache of the most recently used patterns from calls
  * to the match() and rmatch() built-in functions.  PATTERN_CACHE_SIZE controls
-- 
1.7.3.4

