chiark / gitweb /
Build bugfixes (re version.h) and changelog updated.
[userv.git] / daemon.h
1 /*
2  * userv - daemon.h
3  * definitions used in the daemon's source code
4  *
5  * Copyright (C)1996-1997,1999 Ian Jackson
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with userv; if not, write to the Free Software
19  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef DAEMON_H
23 #define DAEMON_H
24
25 #include <sys/types.h>
26
27 #define RESET_CONFIGURATION " \n\
28   cd ~/                       \n\
29   reject                      \n\
30   no-set-environment          \n\
31   suppress-args               \n\
32   allow-fd 0 read             \n\
33   allow-fd 1-2 write          \n\
34   reject-fd 3-                \n\
35   disconnect-hup              \n\
36 "
37
38 #ifndef SYSTEMCONFIGDIR
39 # ifdef DEBUG
40 #  define SYSTEMCONFIGDIR             "slash-etc"
41 # else
42 #  define SYSTEMCONFIGDIR             "/etc"
43 # endif
44 #endif
45
46 #ifndef DEFAULTPATH_USER
47 # define DEFAULTPATH_USER "/usr/local/bin:/bin:/usr/bin"
48 #endif
49
50 #ifndef DEFAULTPATH_ROOT
51 # define DEFAULTPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
52 #endif
53   
54 #ifndef SETENVIRONMENT
55 # define SETENVIRONMENT "environment"
56 #endif
57
58 #define USERRCFILE                  "rc"
59 #define SYSTEMUSERVCONFIGDIR        "userv"
60 #define SHELLLIST                   "shells"
61 #define SYSTEMRCFILEDEFAULT         "system.default"
62 #define SYSTEMRCFILEOVERRIDE        "system.override"
63 #define NONEINCLUDELOOKUP           ":none"
64 #define DEFAULTINCLUDELOOKUP        ":default"
65 #define EMPTYINCLUDELOOKUP          ":empty"
66
67 #define USERCONFIGDIRBASE           SYSTEMUSERVCONFIGDIR
68 #define USERCONFIGDIR               "." USERCONFIGDIRBASE
69 #define USERUSERVCONFIGPATH         "~/" USERCONFIGDIR
70 #define USERRCFILEPATH              USERUSERVCONFIGPATH "/" USERRCFILE
71 #define SYSTEMUSERVCONFIGPATH       SYSTEMCONFIGDIR "/" SYSTEMUSERVCONFIGDIR
72 #define SYSTEMRCFILEDEFAULTPATH     SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEDEFAULT
73 #define SYSTEMRCFILEOVERRIDEPATH    SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEOVERRIDE
74 #define SHELLLISTPATH               SYSTEMCONFIGDIR "/" SHELLLIST
75 #define SETENVIRONMENTPATH          SYSTEMCONFIGDIR "/" SETENVIRONMENT
76
77 #define USERVD_LOGIDENT "uservd"
78 #define USERVDCHECK_LOGIDENT "uservd/check"
79 #define USERVD_LOGFACILITY LOG_DAEMON
80 #define DEFUSERLOGFACILITY LOG_USER
81 #define DEFUSERLOGLEVEL LOG_ERR
82
83 #define TOPLEVEL_CONFIGURATION "                   \n\
84   reset                                            \n\
85   user-rcfile " USERRCFILEPATH "                   \n\
86   errors-to-stderr                                 \n\
87   _include-sysconfig " SYSTEMRCFILEDEFAULTPATH "   \n\
88   if grep service-user-shell " SHELLLISTPATH "     \n\
89     errors-push                                    \n\
90       catch-quit                                   \n\
91         _include-user-rcfile                       \n\
92       hctac                                        \n\
93     srorre                                         \n\
94   fi                                               \n\
95   _include-sysconfig " SYSTEMRCFILEOVERRIDEPATH "  \n\
96   quit                                             \n\
97 "
98
99 #define TOPLEVEL_OVERRIDDEN_CONFIGURATION "        \n\
100   reset                                            \n\
101   errors-to-stderr                                 \n\
102   _include-client-config                           \n\
103   quit                                             \n\
104 "
105
106 #define USERVD_MYSELF_CHECK 3600
107 #define USERVD_MYSELF_TIMEOUT 60
108 #define USERVD_CHECKFORK_RETRY 60
109 #define MAX_INCLUDE_NEST 40
110 #define MAX_ERRMSG_LEN (MAX_ERRMSG_STRING-1024)
111 #define ERRMSG_RESERVE_ERRNO 128
112
113 int parse_string(const char *string, const char *descrip, int isinternal);
114 void parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2);
115 void ensurelogopen(int wantfacility);
116 void ensurefdarray(int fd);
117 const char *printtoken(int token);
118 void senderrmsgstderr(const char *errmsg);
119 void disconnect(int exitstatus) NONRETURNING;
120
121 void always_dumpparameter(const char *parm, char **values);
122 void always_dumpexecsettings(void);
123
124 void debug_dumprequest(pid_t mypid);
125 void debug_dumpexecsettings(void);
126 void debug_dumpparameter(const char *parm, char **values);
127 pid_t nondebug_fork(void);
128 const char *nondebug_serviceuserdir(const char *ifnondebug);
129
130 typedef void builtinserviceexec_fnt(const char *const *args);
131 builtinserviceexec_fnt NONRETURNING bisexec_environment, bisexec_parameter;
132 builtinserviceexec_fnt NONRETURNING bisexec_version, bisexec_help;
133 builtinserviceexec_fnt NONRETURNING bisexec_toplevel, bisexec_override, bisexec_reset;
134 builtinserviceexec_fnt NONRETURNING bisexec_execute;
135 extern const char *const builtinservicehelpstrings[];
136
137 void execservice(const int synchsocket[], int clientfd) NONRETURNING;
138 void servicerequest(int sfd) NONRETURNING;
139 int synchread(int fd, int ch);
140 const char *defaultpath(void);
141
142 struct fdstate {
143   int iswrite; /* 0 or 1; -1 if not open */
144   int realfd, holdfd; /* -1 if not open */
145   int wantstate;
146   /* tokv_word_requirefd, tokv_word_allowfd, tokv_nullfd, tokv_word_rejectfd
147    * (all of which have tokt_wantfdstate set) */
148   int wantrw; /* tokv_word_read, tokv_word_write, 0 for either/both */
149 };
150
151 struct keyvaluepair { char *key, *value; };
152
153 extern pid_t overlordpid;
154 extern struct request_msg request_mbuf;
155 extern struct keyvaluepair *defvararray;
156 extern struct fdstate *fdarray; /* indexed by nominal fd */
157 extern int fdarraysize, fdarrayused;
158 extern int restfdwantstate, restfdwantrw;
159 extern int service_ngids;
160 extern char **argarray;
161 extern char *serviceuser, *service, *loginname, *cwd;
162 extern char *overridedata, *userrcfile;
163 extern char *serviceuser_dir, *serviceuser_shell, *callinguser_shell;
164 extern gid_t *calling_gids, *service_gids;
165 extern uid_t serviceuser_uid;
166 extern const char **calling_groups, **service_groups;
167 extern char *execpath, **execargs;
168 extern int execute; /* One of the execution modes tokt_execmode */
169 extern int setenvironment, suppressargs, disconnecthup;
170 extern builtinserviceexec_fnt *execbuiltin;
171 extern int syslogopenfacility;
172
173 #endif