*-S*::
- Log messages to *syslog*(3) instead of standard error.
+ Log messages to *syslog*(3) instead of standard error. Also
+ sets the environment ASHD_USESYSLOG environment variable in
+ the root handler process, which indicates to the standard ashd
+ programs to do the same thing.
*-f*::
SYNOPSIS
--------
-*userplex* [*-hI*] [*-g* 'GROUP'] [*-m* 'MIN-UID'] [*-d* 'PUBDIR'] ['PROGRAM' ['ARGS'...]]
+*userplex* [*-hIs*] [*-g* 'GROUP'] [*-m* 'MIN-UID'] [*-d* 'PUBDIR'] ['PROGRAM' ['ARGS'...]]
DESCRIPTION
-----------
If given, ignore any `~/.ashd/handler` file in a user's home
directory and use only the default handler.
+*-s*::
+
+ If given, set the ASHD_USESYSLOG environment variable in all
+ started children. If not given, *userplex* will actively clear
+ the variable from its children instead. The presence of the
+ variable indicates to the standard ashd programs to log
+ messages to *syslog*(3) instead of printing them on standard
+ error.
+
*-g* 'GROUP'::
If given, only users that are members of the named 'GROUP'
#include <config.h>
#endif
#include <utils.h>
+#include <log.h>
+static int inited = 0;
static int tostderr = 1, tosyslog = 0;
+static void initlog(void)
+{
+ inited = 1;
+ if(getenv("ASHD_USESYSLOG") != NULL)
+ opensyslog();
+}
+
void flog(int level, char *format, ...)
{
va_list args;
+ if(!inited)
+ initlog();
va_start(args, format);
if(tostderr) {
vfprintf(stderr, format, args);
void opensyslog(void)
{
+ if(!inited)
+ initlog();
openlog("ashd", 0, LOG_DAEMON);
tostderr = 0;
tosyslog = 1;
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#include <pwd.h>
static int plex;
static char *pidfile = NULL;
+static int daemonize, usesyslog;
static void trimx(struct hthead *req)
{
}
}
+static void initroot(void *uu)
+{
+ int fd;
+
+ if(daemonize) {
+ setsid();
+ chdir("/");
+ if((fd = open("/dev/null", O_RDWR)) >= 0) {
+ dup2(fd, 0);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ close(fd);
+ }
+ }
+ if(usesyslog)
+ putenv("ASHD_USESYSLOG=1");
+ else
+ unsetenv("ASHD_USESYSLOG");
+}
+
static void usage(FILE *out)
{
fprintf(out, "usage: htparser [-hSf] [-u USER] [-r ROOT] [-p PIDFILE] PORTSPEC... -- ROOT [ARGS...]\n");
{
int c;
int i, s1;
- int daemonize, logsys;
char *root;
FILE *pidout;
struct passwd *pwent;
- daemonize = logsys = 0;
+ daemonize = usesyslog = 0;
root = NULL;
pwent = NULL;
while((c = getopt(argc, argv, "+hSfu:r:p:")) >= 0) {
daemonize = 1;
break;
case 'S':
- logsys = 1;
+ usesyslog = 1;
break;
case 'u':
if((pwent = getpwnam(optarg)) == NULL) {
usage(stderr);
exit(1);
}
- if((plex = stdmkchild(argv + ++i, NULL, NULL)) < 0) {
+ if((plex = stdmkchild(argv + ++i, initroot, NULL)) < 0) {
flog(LOG_ERR, "could not spawn root multiplexer: %s", strerror(errno));
return(1);
}
return(1);
}
}
- if(logsys)
+ if(usesyslog)
opensyslog();
if(root) {
if(chroot(root)) {
static char *dirname = NULL;
static char **childspec;
static uid_t minuid = 0;
+static int usesyslog = 0;
static struct user *users = NULL;
static void login(struct passwd *pwd)
flog(LOG_ERR, "could not change to home directory for %s: %s", pwd->pw_name, strerror(errno));
exit(1);
}
+ if(usesyslog)
+ putenv("ASHD_USESYSLOG=1");
+ else
+ unsetenv("ASHD_USESYSLOG");
putenv(sprintf2("HOME=%s", pwd->pw_dir));
putenv(sprintf2("SHELL=%s", pwd->pw_shell));
putenv(sprintf2("USER=%s", pwd->pw_name));
static void usage(FILE *out)
{
- fprintf(out, "usage: userplex [-hI] [-g GROUP] [-m MIN-UID] [-d PUB-DIR] [PROGRAM ARGS...]\n");
+ fprintf(out, "usage: userplex [-hIs] [-g GROUP] [-m MIN-UID] [-d PUB-DIR] [PROGRAM ARGS...]\n");
}
int main(int argc, char **argv)
int fd;
struct charvbuf csbuf;
- while((c = getopt(argc, argv, "+hIg:m:d:")) >= 0) {
+ while((c = getopt(argc, argv, "+hIsg:m:d:")) >= 0) {
switch(c) {
case 'I':
ignore = 1;
break;
+ case 's':
+ usesyslog = 1;
+ break;
case 'm':
if((minuid = atoi(optarg)) < 1) {
fprintf(stderr, "userplex: argument to -m must be greater than 0\n");