Skip to content

Commit

Permalink
diod should listen on port 564 by default. Misc. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Apr 20, 2011
1 parent a434373 commit 3661e06
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 124 deletions.
12 changes: 0 additions & 12 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
Here are some diod configuration options that may be useful:

--disable-munge Build without MUNGE authentication

Without munge support enabled, authorization is based on source
IP address and is therefore spoofable. Munge provides authentication
based on a shared private key. You can get munge from
http://code.google.com/p/munge/
or grab your distro's package.

Generic autoconf installation instructions follow.

Installation Instructions
*************************

Expand Down
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//1.0-pre23:
1.0-pre23:
Make -s,--stdin option explicit in diod and diodctl.
Have diod listen by default on the well known 9pfs port 564.
Don't require explicit confirmation if munge isn't found (issue 23)
Terminate diod children when diodctl is terminated with SIGTERM.
Reconfigure diod children when diodctl is reconfiged with SIGHUP.
Expand Down
17 changes: 5 additions & 12 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
| Building |
+----------+

You need a few prerequisites (shared library versions):
To build all of diod's features, you need a few prerequisites:

lua, lua-devel
A LUA parser is used to parse the config file.
For config file support.

munge, munge-libs, munge-devel
Needed if --enable-munge (see below).
For authentication support.

tcp_wrappers, tcp_wrappers-libs, tcp_wrappers-devel
Needed if you want built-in TCP wrapper functionality.

configure options:

--enable-munge
Build with MUNGE support. Currrently this is the only
supported authentication method. If you don't enable
munge, you will have to run the server with --no-auth
which is likely a big security vulnerability.
For TCP wrapper functionality.

+---------+
| Testing |
Expand All @@ -30,6 +22,7 @@ Unit tests (make check):
./tests/misc
Miscellaneous unit tests.
Some tests will be skipped if not root.
Others will be skipped if valgrind is not installed.

./tests/user
User space client and server running across a socketpair.
Expand Down
33 changes: 10 additions & 23 deletions diod/diod.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ Do not change working directory to @X_LOCALSTATEDIR@/run,
drop the controlling terminal, or run in the background.
Send logs to stderr not syslog, unless sent somewhere else by \fI\-L\fR.
.TP
.I "-s, --stdin"
Serve a connected client inherited on stdin.
This option is mainly used in testing.
.TP
.I "-l, --listen IP:PORT"
Set the listen address.
Set the listen address (default 0.0.0.0:564).
This option may be specified more than once.
It overrides the \fIdiodlisten\fR config file setting.
If neither listen ports nor \fI-F\fR are specified, assume connected
client is inherited on file descriptor 0.
.TP
.I "-F, --listen-fds N"
Listen for connection on file descriptors zero through N.
.I "-F, --diodctl N"
Listen for connection on file descriptors 3 through N+3.
This is the mechanism that \fBdiodctl\fR uses to pass dynamically
allocated ports, possibly on multiple interfaces, to \fBdiod\fR.
If neither \fI-l\fR nor \fI-F\fR are specified, assume connected
client is inherited on file descriptor 0.
allocated sockets, possibly on multiple interfaces, to \fBdiod\fR.
.TP
.I "-w, --nwthreads INT"
Set the number of worker threads to spawn to handle 9P operations.
Expand All @@ -46,7 +46,7 @@ This option may be specified more than once.
It overrides the \fIexports\fR setting in diod.conf (5).
.TP
.I "-E, --export-all"
Export everything in /proc/mounts.
Export everything in the server's /proc/mounts.
.TP
.I "-n, --no-auth"
This option allows users to attach without security credentials.
Expand All @@ -55,7 +55,7 @@ It overrides the \fIauth_required\fR setting in diod.conf (5).
.I "-S, --allsquash"
Remap all users to "nobody".
The attaching user need not be present in the server's password file.
It overrides the \fIallsquash\fR setting in diod.conf (5).
This option overrides the \fIallsquash\fR setting in diod.conf (5).
.TP
.I "-u, --runas-uid UID"
Run the server as UID and only allow that user to attach.
Expand All @@ -78,24 +78,11 @@ Set the debug mask. The bit values are:
0x01 - log decoded 9P protocol messages
.br
.TP
.I "-s, --stats PATH"
Write I/O statistics to PATH as each file is closed.
Each line represents one file I/O session and is of the form:
.nf
path:read-ops:read-bytes:write-ops:write-bytes:time-seconds
.fi
.TP
.I "-c, --config-file PATH"
Set config file path.
.SH "LOGGING"
If listen ports were specified, \fBdiod\fR logs all messages to the
LOG_DAEMON syslog facility at LOG_ERR severity unless overridden as
described above. Otherwise it logs to stderr.
.SH "FILES"
@X_SBINDIR@/diod
.br
@X_SYSCONFDIR@/diod.conf
.br
@X_LOCALSTATEDIR@/run/diod.pid
.SH "SEE ALSO"
diodctl (8), diod.conf (5), mount.diod (8), hosts_access (5)
50 changes: 19 additions & 31 deletions diod/diod.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ static void _service_run (srvmode_t mode, int Fopt);
#define NR_OPEN 1048576 /* works on RHEL 5 x86_64 arch */
#endif

#define OPTIONS "fd:l:w:e:EF:u:SL:nc:"
#define OPTIONS "fsd:l:w:e:EF:u:SL:nc:"

#if HAVE_GETOPT_LONG
#define GETOPT(ac,av,opt,lopt) getopt_long (ac,av,opt,lopt,NULL)
static const struct option longopts[] = {
{"foreground", no_argument, 0, 'f'},
{"stdin", no_argument, 0, 's'},
{"debug", required_argument, 0, 'd'},
{"listen", required_argument, 0, 'l'},
{"nwthreads", required_argument, 0, 'w'},
{"export", required_argument, 0, 'e'},
{"export-all", no_argument, 0, 'E'},
{"no-auth", no_argument, 0, 'n'},
{"listen-fds", required_argument, 0, 'F'},
{"diodctl", required_argument, 0, 'F'},
{"runas-uid", required_argument, 0, 'u'},
{"allsquash", no_argument, 0, 'S'},
{"logdest", required_argument, 0, 'L'},
Expand All @@ -100,8 +101,9 @@ usage()
fprintf (stderr,
"Usage: diod [OPTIONS]\n"
" -f,--foreground do not fork and disassociate with tty\n"
" -s,--stdin service connected client on stdin\n"
" -l,--listen IP:PORT set interface to listen on (multiple -l allowed)\n"
" -F,--listen-fds N listen for connections on the first N fds\n"
" -F,--diodctl N listen for connections on the first N fds\n"
" -w,--nwthreads INT set number of I/O worker threads to spawn\n"
" -e,--export PATH export PATH (multiple -e allowed)\n"
" -E,--export-all export all mounted file systems\n"
Expand All @@ -120,11 +122,9 @@ main(int argc, char **argv)
{
int c;
int Fopt = 0;
int eopt = 0;
int lopt = 0;
char *copt = NULL;
char *end;
srvmode_t mode = SRV_STDIN;
srvmode_t mode = SRV_NORMAL;

diod_log_init (argv[0]);
diod_conf_init ();
Expand All @@ -151,14 +151,16 @@ main(int argc, char **argv)
case 'f': /* --foreground */
diod_conf_set_foreground (1);
break;
case 's': /* --stdin */
mode = SRV_STDIN;
diod_conf_set_foreground (1);
break;
case 'd': /* --debug MASK */
diod_conf_set_debuglevel (strtoul (optarg, NULL, 0));
break;
case 'l': /* --listen HOST:PORT */
if (!lopt) {
if (!diod_conf_opt_diodlisten ())
diod_conf_clr_diodlisten ();
lopt = 1;
}
if (!strchr (optarg, ':'))
usage ();
diod_conf_add_diodlisten (optarg);
Expand All @@ -169,10 +171,8 @@ main(int argc, char **argv)
case 'c': /* --config-file PATH */
break;
case 'e': /* --export PATH */
if (!eopt) {
if (!diod_conf_opt_exports ())
diod_conf_clr_exports ();
eopt = 1;
}
diod_conf_add_exports (optarg);
break;
case 'E': /* --export-all */
Expand All @@ -184,9 +184,10 @@ main(int argc, char **argv)
case 'S': /* --allsquash */
diod_conf_set_allsquash (1);
break;
case 'F': /* --listen-fds N */
Fopt = strtoul (optarg, NULL, 10);
case 'F': /* --diodctl N */
mode = SRV_DIODCTL;
Fopt = strtoul (optarg, NULL, 10);
diod_conf_set_foreground (1);
break;
case 'u': /* --runas-uid UID */
if (geteuid () == 0) {
Expand Down Expand Up @@ -215,26 +216,9 @@ main(int argc, char **argv)

diod_conf_validate_exports ();

if (mode == SRV_STDIN) {
List hplist = diod_conf_get_diodlisten ();

if (hplist && list_count (hplist) > 0)
mode = SRV_NORMAL;
}
if (mode == SRV_STDIN)
diod_conf_set_foreground (1);

if (geteuid () == 0)
_setrlimit ();

if (!diod_conf_get_foreground ()) {
char *logdest = diod_conf_get_logdest ();

if (mode != SRV_DIODCTL)
_daemonize ();
diod_log_set_dest (logdest ? logdest : "syslog");
}

/* Drop root permission if running as one user.
* If not root, arrange to run (only) as current effective uid.
*/
Expand Down Expand Up @@ -443,6 +427,10 @@ _service_run (srvmode_t mode, int Fopt)
msg_exit ("failed to set up listen ports");
break;
}
if (!diod_conf_get_foreground ()) {
_daemonize ();
diod_log_set_dest (diod_conf_get_logdest ());
}

if ((n = pthread_create (&ss.t, NULL, _service_loop, NULL))) {
errno = n;
Expand Down
48 changes: 29 additions & 19 deletions diodctl/diodctl.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,31 @@ Do not change working directory to @X_LOCALSTATEDIR@/run,
drop the controlling terminal, or run in the background.
Send logs to stderr not syslog, unless sent somewhere else by \fI\-L\fR.
.TP
.I "-d, --debug MASK"
Set the debug mask. The bit values are:
.br
0x01 - log decoded 9P protocol messages
.br
The debug level is inherited by any spawned \fBdiod\fR processes.
.I "-s, --stdin"
Serve a connected client inherited on stdin.
This option is mainly used in testing.
.TP
.I "-l, --listen IP:PORT"
Set the listen address (default 0.0.0.0:10005),
the \fIdiodctllisten\fR config file setting.
Set the listen address (default 0.0.0.0:10005).
This option may be specified more than once.
It overrides the \fIdiodctllisten\fR config file setting.
.TP
.I "-w, --nwthreads INT"
Set the number of \fBdiodctl\fR worker threads to spawn handle 9P operations.
This overrides the \fInwthreads\fR setting in the config file.
The default is 16.
It is not inerited by any spawned \fBdiod\fR processes.
It is not inherited by any spawned \fBdiod\fR processes.
.TP
.I "-c, --config-file PATH"
Set config file path.
.I "-e, --export PATH"
Set the file system to be exported.
This option may be specified more than once.
It overrides the \fIexports\fR setting in diod.conf (5)
and is inherited by spawned \fBdiod\fR processes.
.TP
.I "-E, --export-all"
Export everything in the server's /proc/mounts.
This potion overrides the \fIexportall\fR setting in diod.conf (5)
and is inherited by spawned \fBdiod\fR processes.
.TP
.I "-n, --no-auth"
Allow users to attach without security credentials.
Expand All @@ -49,7 +54,7 @@ and is inherited by spawned \fBdiod\fR processes.
.I "-S, --allsquash"
Remap all users to "nobody".
The attaching user need not be present in the server's password file.
It overrides the \fIallsquash\fR setting in diod.conf (5).
This option overrides the \fIallsquash\fR setting in diod.conf (5).
.TP
.I "-D, --diod-path PATH"
Override the default path to the \fBdiod\fR server executable.
Expand All @@ -62,18 +67,25 @@ Set the destination for logging. Possible destinations are
a file name.
This option is inherited by any spawned \fBdiod\fR processes.
It overrides the logdest setting in diod.conf (5).
.TP
.I "-d, --debug MASK"
Set the debug mask. The bit values are:
.br
0x01 - log decoded 9P protocol messages
.br
The debug level is inherited by any spawned \fBdiod\fR processes.
.TP
.I "-c, --config-file PATH"
Set config file path.
.SH "NOTES"
\fBdiod\fR servers spawned by \fBdiodctl\fR can be shared by multiple
clients. They are assigned random ports to listen on, which are given out
to clients upon request by \fBmount.diod\fR.
Servers run until they have had no connections for 30 seconds then terminate.
\fBdiodctl\fR reaps these children and logs their exit status.
.LP
If \fBdiodctl\fR restarts with running children, any children should continue
to run as orphans, but their port numbers will no longer be handed out
to new clients.
A mount request in progress may fail if the server is
restarted in the middle of a conversation with \fBmount.diod\fR.
\fBdiod\fR children of \fBdiodctl\fR are terminated when \fBdiodctl\fR
is shut down cleanly with a SIGTERM.
.LP
When \fBdiodctl\fR receives a SIGHUP, it rereads its config file.
Any original command line arguments will continue to override config file
Expand All @@ -87,7 +99,5 @@ allow new attaches but will continue to serve old ones.
@X_SYSCONFDIR@/diod.conf
.br
@X_SYSCONFDIR@/sysconfig/diodctl
.br
@X_LOCALSTATEDIR@/run/diodctl.pid
.SH "SEE ALSO"
diod (8), mount.diod (8), diodexp (8), diod.conf (5), hosts_access (5)
Loading

0 comments on commit 3661e06

Please sign in to comment.