chiark / gitweb /
debian/control: Add missing build-dependency on flex. Fixes FTBFS. Report from Aurel...
[userv.git] / daemon.h
1 /*
2  * userv - daemon.h
3  * definitions used in the daemon's source code
4  *
5  * userv is
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>
9  *
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.
14  *
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.
19  *
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/>.
22  */
23
24 #ifndef DAEMON_H
25 #define DAEMON_H
26
27 #include <sys/types.h>
28
29 #define RESET_CONFIGURATION " \n\
30   cd ~/                       \n\
31   reject                      \n\
32   no-set-environment          \n\
33   suppress-args               \n\
34   allow-fd 0 read             \n\
35   allow-fd 1-2 write          \n\
36   reject-fd 3-                \n\
37   disconnect-hup              \n\
38   include-lookup-quote-new    \n\
39 "
40
41 #ifndef SYSTEMCONFIGDIR
42 # ifdef DEBUG
43 #  define SYSTEMCONFIGDIR             "slash-etc"
44 # else
45 #  define SYSTEMCONFIGDIR             "/etc"
46 # endif
47 #endif
48
49 #ifndef DEFAULTPATH_USER
50 # define DEFAULTPATH_USER "/usr/local/bin:/bin:/usr/bin"
51 #endif
52
53 #ifndef DEFAULTPATH_ROOT
54 # define DEFAULTPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
55 #endif
56   
57 #ifndef SETENVIRONMENT
58 # define SETENVIRONMENT "environment"
59 #endif
60
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"
69
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
79
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
85
86 #define TOPLEVEL_CONFIGURATION "                   \n\
87   reset                                            \n\
88   user-rcfile " USERRCFILEPATH "                   \n\
89   errors-to-stderr                                 \n\
90   _include-sysconfig " SYSTEMRCFILEDEFAULTPATH "   \n\
91   if grep service-user-shell " SHELLLISTPATH "     \n\
92     errors-push                                    \n\
93       catch-quit                                   \n\
94         _include-user-rcfile                       \n\
95       hctac                                        \n\
96     srorre                                         \n\
97   fi                                               \n\
98   _include-sysconfig " SYSTEMRCFILEOVERRIDEPATH "  \n\
99   quit                                             \n\
100 "
101
102 #define TOPLEVEL_OVERRIDDEN_CONFIGURATION "        \n\
103   reset                                            \n\
104   errors-to-stderr                                 \n\
105   _include-client-config                           \n\
106   quit                                             \n\
107 "
108
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
115
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;
123
124 void always_dumpparameter(const char *parm, char **values);
125 void always_dumpexecsettings(void);
126
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);
132
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[];
139
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);
144
145 struct fdstate {
146   int iswrite; /* 0 or 1; -1 if not open */
147   int realfd, holdfd; /* -1 if not open */
148   int wantstate;
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 */
152 };
153
154 struct keyvaluepair { char *key, *value; };
155
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;
175
176 #endif