3 * definitions used in the daemon's source code
6 * Copyright 1996-2017 Ian Jackson <ian@davenant.greenend.org.uk>.
7 * Copyright 2000 Ben Harris <bjh21@cam.ac.uk>
8 * Copyright 2016-2017 Peter Benie <pjb1008@cam.ac.uk>
10 * This is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with userv; if not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
29 #define RESET_CONFIGURATION " \n\
32 no-set-environment \n\
35 allow-fd 1-2 write \n\
38 include-lookup-quote-new \n\
41 #ifndef SYSTEMCONFIGDIR
43 # define SYSTEMCONFIGDIR "slash-etc"
45 # define SYSTEMCONFIGDIR "/etc"
49 #ifndef DEFAULTPATH_USER
50 # define DEFAULTPATH_USER "/usr/local/bin:/bin:/usr/bin"
53 #ifndef DEFAULTPATH_ROOT
54 # define DEFAULTPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
57 #ifndef SETENVIRONMENT
58 # define SETENVIRONMENT "environment"
61 #define USERRCFILE "rc"
62 #define SYSTEMUSERVCONFIGDIR "userv"
63 #define SHELLLIST "shells"
64 #define SYSTEMRCFILEDEFAULT "system.default"
65 #define SYSTEMRCFILEOVERRIDE "system.override"
66 #define NONEINCLUDELOOKUP ":none"
67 #define DEFAULTINCLUDELOOKUP ":default"
68 #define EMPTYINCLUDELOOKUP ":empty"
70 #define USERCONFIGDIRBASE SYSTEMUSERVCONFIGDIR
71 #define USERCONFIGDIR "." USERCONFIGDIRBASE
72 #define USERUSERVCONFIGPATH "~/" USERCONFIGDIR
73 #define USERRCFILEPATH USERUSERVCONFIGPATH "/" USERRCFILE
74 #define SYSTEMUSERVCONFIGPATH SYSTEMCONFIGDIR "/" SYSTEMUSERVCONFIGDIR
75 #define SYSTEMRCFILEDEFAULTPATH SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEDEFAULT
76 #define SYSTEMRCFILEOVERRIDEPATH SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEOVERRIDE
77 #define SHELLLISTPATH SYSTEMCONFIGDIR "/" SHELLLIST
78 #define SETENVIRONMENTPATH SYSTEMCONFIGDIR "/" SETENVIRONMENT
80 #define USERVD_LOGIDENT "uservd"
81 #define USERVDCHECK_LOGIDENT "uservd/check"
82 #define USERVD_LOGFACILITY LOG_DAEMON
83 #define DEFUSERLOGFACILITY LOG_USER
84 #define DEFUSERLOGLEVEL LOG_ERR
86 #define TOPLEVEL_CONFIGURATION " \n\
88 user-rcfile " USERRCFILEPATH " \n\
90 _include-sysconfig " SYSTEMRCFILEDEFAULTPATH " \n\
91 if grep service-user-shell " SHELLLISTPATH " \n\
94 _include-user-rcfile \n\
98 _include-sysconfig " SYSTEMRCFILEOVERRIDEPATH " \n\
102 #define TOPLEVEL_OVERRIDDEN_CONFIGURATION " \n\
105 _include-client-config \n\
109 #define USERVD_MYSELF_CHECK 3600
110 #define USERVD_MYSELF_TIMEOUT 60
111 #define USERVD_CHECKFORK_RETRY 60
112 #define MAX_INCLUDE_NEST 40
113 #define MAX_ERRMSG_LEN (MAX_ERRMSG_STRING-1024)
114 #define ERRMSG_RESERVE_ERRNO 128
116 int parse_string(const char *string, const char *descrip, int isinternal);
117 int parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2);
118 void ensurelogopen(int wantfacility);
119 void ensurefdarray(int fd);
120 const char *printtoken(int token);
121 void senderrmsgstderr(const char *errmsg);
122 void disconnect(int exitstatus) NONRETURNING;
124 void always_dumpparameter(const char *parm, char **values);
125 void always_dumpexecsettings(void);
127 void debug_dumprequest(pid_t mypid);
128 void debug_dumpexecsettings(void);
129 void debug_dumpparameter(const char *parm, char **values);
130 pid_t nondebug_fork(void);
131 const char *nondebug_serviceuserdir(const char *ifnondebug);
133 typedef void builtinserviceexec_fnt(const char *const *args);
134 builtinserviceexec_fnt NONRETURNING bisexec_environment, bisexec_parameter;
135 builtinserviceexec_fnt NONRETURNING bisexec_version, bisexec_help;
136 builtinserviceexec_fnt NONRETURNING bisexec_toplevel, bisexec_override, bisexec_reset;
137 builtinserviceexec_fnt NONRETURNING bisexec_execute, bisexec_shutdown;
138 extern const char *const builtinservicehelpstrings[];
140 void execservice(const int synchsocket[], int clientfd) NONRETURNING;
141 void servicerequest(int sfd) NONRETURNING;
142 int synchread(int fd, int ch);
143 const char *defaultpath(void);
146 int iswrite; /* 0 or 1; -1 if not open */
147 int realfd, holdfd; /* -1 if not open */
149 /* tokv_word_requirefd, tokv_word_allowfd, tokv_nullfd, tokv_word_rejectfd
150 * (all of which have tokt_wantfdstate set) */
151 int wantrw; /* tokv_word_read, tokv_word_write, 0 for either/both */
154 struct keyvaluepair { char *key, *value; };
156 extern pid_t overlordpid;
157 extern struct request_msg request_mbuf;
158 extern struct keyvaluepair *defvararray;
159 extern struct fdstate *fdarray; /* indexed by nominal fd */
160 extern int fdarraysize, fdarrayused;
161 extern int restfdwantstate, restfdwantrw;
162 extern int service_ngids;
163 extern char **argarray;
164 extern char *serviceuser, *service, *loginname, *cwd;
165 extern char *overridedata, *userrcfile;
166 extern char *serviceuser_dir, *serviceuser_shell, *callinguser_shell;
167 extern gid_t *calling_gids, *service_gids;
168 extern uid_t serviceuser_uid;
169 extern const char **calling_groups, **service_groups;
170 extern char *execpath, **execargs;
171 extern int execute; /* One of the execution modes tokt_execmode */
172 extern int setenvironment, suppressargs, disconnecthup;
173 extern builtinserviceexec_fnt *execbuiltin;
174 extern int syslogopenfacility;