X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=daemon.h;h=b41812d8c9a520d8f58b058d4e93e7cbe49460b7;hp=45bb10244c5602540d4d0f12d5b9f095aa42fd1f;hb=e5294e9e174ea671d2e8f3454d3fbf25fd106c36;hpb=703b99b834625829d6b285e5bca619475ef54511 diff --git a/daemon.h b/daemon.h index 45bb102..b41812d 100644 --- a/daemon.h +++ b/daemon.h @@ -2,11 +2,14 @@ * userv - daemon.h * definitions used in the daemon's source code * - * Copyright (C)1996-1997 Ian Jackson + * userv is + * Copyright 1996-2017 Ian Jackson . + * Copyright 2000 Ben Harris + * Copyright 2016-2017 Peter Benie * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but @@ -15,8 +18,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with userv; if not, write to the Free Software - * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with userv; if not, see . */ #ifndef DAEMON_H @@ -25,7 +27,7 @@ #include #define RESET_CONFIGURATION " \n\ - cd " USERDIRPREFIX " \n\ + cd ~/ \n\ reject \n\ no-set-environment \n\ suppress-args \n\ @@ -33,6 +35,7 @@ allow-fd 1-2 write \n\ reject-fd 3- \n\ disconnect-hup \n\ + include-lookup-quote-new \n\ " #ifndef SYSTEMCONFIGDIR @@ -43,6 +46,18 @@ # endif #endif +#ifndef DEFAULTPATH_USER +# define DEFAULTPATH_USER "/usr/local/bin:/bin:/usr/bin" +#endif + +#ifndef DEFAULTPATH_ROOT +# define DEFAULTPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" +#endif + +#ifndef SETENVIRONMENT +# define SETENVIRONMENT "environment" +#endif + #define USERRCFILE "rc" #define SYSTEMUSERVCONFIGDIR "userv" #define SHELLLIST "shells" @@ -52,22 +67,20 @@ #define DEFAULTINCLUDELOOKUP ":default" #define EMPTYINCLUDELOOKUP ":empty" -#define USERDIRPREFIX USERDIR DIRSEP #define USERCONFIGDIRBASE SYSTEMUSERVCONFIGDIR -#define USERCONFIGDIR HIDDENPREFIX USERCONFIGDIRBASE -#define USERUSERVCONFIGPATH USERDIR DIRSEP USERCONFIGDIR -#define USERRCFILEPATH USERUSERVCONFIGPATH DIRSEP USERRCFILE -#define SYSTEMUSERVCONFIGPATH SYSTEMCONFIGDIR DIRSEP SYSTEMUSERVCONFIGDIR -#define SYSTEMRCFILEDEFAULTPATH SYSTEMUSERVCONFIGPATH DIRSEP SYSTEMRCFILEDEFAULT -#define SYSTEMRCFILEOVERRIDEPATH SYSTEMUSERVCONFIGPATH DIRSEP SYSTEMRCFILEOVERRIDE -#define SHELLLISTPATH SYSTEMCONFIGDIR DIRSEP SHELLLIST - -#define USERDIR "~" -#define HIDDENPREFIX "." +#define USERCONFIGDIR "." USERCONFIGDIRBASE +#define USERUSERVCONFIGPATH "~/" USERCONFIGDIR +#define USERRCFILEPATH USERUSERVCONFIGPATH "/" USERRCFILE +#define SYSTEMUSERVCONFIGPATH SYSTEMCONFIGDIR "/" SYSTEMUSERVCONFIGDIR +#define SYSTEMRCFILEDEFAULTPATH SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEDEFAULT +#define SYSTEMRCFILEOVERRIDEPATH SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEOVERRIDE +#define SHELLLISTPATH SYSTEMCONFIGDIR "/" SHELLLIST +#define SETENVIRONMENTPATH SYSTEMCONFIGDIR "/" SETENVIRONMENT #define USERVD_LOGIDENT "uservd" +#define USERVDCHECK_LOGIDENT "uservd/check" #define USERVD_LOGFACILITY LOG_DAEMON -#define DEFUSERLOGFACILITY LOG_DAEMON +#define DEFUSERLOGFACILITY LOG_USER #define DEFUSERLOGLEVEL LOG_ERR #define TOPLEVEL_CONFIGURATION " \n\ @@ -93,51 +106,71 @@ quit \n\ " +#define USERVD_MYSELF_CHECK 3600 +#define USERVD_MYSELF_TIMEOUT 60 +#define USERVD_CHECKFORK_RETRY 60 #define MAX_INCLUDE_NEST 40 -#define MAX_ERRMSG_LEN 2048 +#define MAX_ERRMSG_LEN (MAX_ERRMSG_STRING-1024) #define ERRMSG_RESERVE_ERRNO 128 -int parse_string(const char *string, const char *descrip); -void parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2); +int parse_string(const char *string, const char *descrip, int isinternal); +int parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2); void ensurelogopen(int wantfacility); void ensurefdarray(int fd); const char *printtoken(int token); void senderrmsgstderr(const char *errmsg); void disconnect(int exitstatus) NONRETURNING; +void always_dumpparameter(const char *parm, char **values); +void always_dumpexecsettings(void); + void debug_dumprequest(pid_t mypid); void debug_dumpexecsettings(void); void debug_dumpparameter(const char *parm, char **values); pid_t nondebug_fork(void); const char *nondebug_serviceuserdir(const char *ifnondebug); +typedef void builtinserviceexec_fnt(const char *const *args); +builtinserviceexec_fnt NONRETURNING bisexec_environment, bisexec_parameter; +builtinserviceexec_fnt NONRETURNING bisexec_version, bisexec_help; +builtinserviceexec_fnt NONRETURNING bisexec_toplevel, bisexec_override, bisexec_reset; +builtinserviceexec_fnt NONRETURNING bisexec_execute, bisexec_shutdown; +extern const char *const builtinservicehelpstrings[]; + +void execservice(const int synchsocket[], int clientfd) NONRETURNING; +void servicerequest(int sfd) NONRETURNING; +int synchread(int fd, int ch); +const char *defaultpath(void); + struct fdstate { - int iswrite, realfd, holdfd; + int iswrite; /* 0 or 1; -1 if not open */ + int realfd, holdfd; /* -1 if not open */ int wantstate; /* tokv_word_requirefd, tokv_word_allowfd, tokv_nullfd, tokv_word_rejectfd * (all of which have tokt_wantfdstate set) */ - int wantrw; - /* tokv_word_read, tokv_word_write */ + int wantrw; /* tokv_word_read, tokv_word_write, 0 for either/both */ }; -extern gid_t *gidarray; -extern char **argarray; -extern char *((*defvararray)[2]); +struct keyvaluepair { char *key, *value; }; + +extern pid_t overlordpid; +extern struct request_msg request_mbuf; +extern struct keyvaluepair *defvararray; extern struct fdstate *fdarray; /* indexed by nominal fd */ extern int fdarraysize, fdarrayused; extern int restfdwantstate, restfdwantrw; -extern struct request_msg request_mbuf; -extern char *serviceuser, *service, *logname, *cwd; +extern int service_ngids; +extern char **argarray; +extern char *serviceuser, *service, *loginname, *cwd; extern char *overridedata, *userrcfile; -extern char *serviceuser_dir, *serviceuser_shell; +extern char *serviceuser_dir, *serviceuser_shell, *callinguser_shell; +extern gid_t *calling_gids, *service_gids; extern uid_t serviceuser_uid; -extern gid_t serviceuser_gid; +extern const char **calling_groups, **service_groups; extern char *execpath, **execargs; extern int execute; /* One of the execution modes tokt_execmode */ extern int setenvironment, suppressargs, disconnecthup; -extern int ehandling; /* One of the error handling modes tokt_ehandlemode */ -extern int ehlogfacility, ehloglevel, syslogopenfacility, ehfilekeep; -extern FILE *ehfile; -extern char *ehfilename; +extern builtinserviceexec_fnt *execbuiltin; +extern int syslogopenfacility; #endif