chiark / gitweb /
spec.sgml: Update for update copyright notices
[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   include-lookup-quote-new    \n\
37 "
38
39 #ifndef SYSTEMCONFIGDIR
40 # ifdef DEBUG
41 #  define SYSTEMCONFIGDIR             "slash-etc"
42 # else
43 #  define SYSTEMCONFIGDIR             "/etc"
44 # endif
45 #endif
46
47 #ifndef DEFAULTPATH_USER
48 # define DEFAULTPATH_USER "/usr/local/bin:/bin:/usr/bin"
49 #endif
50
51 #ifndef DEFAULTPATH_ROOT
52 # define DEFAULTPATH_ROOT "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
53 #endif
54   
55 #ifndef SETENVIRONMENT
56 # define SETENVIRONMENT "environment"
57 #endif
58
59 #define USERRCFILE                  "rc"
60 #define SYSTEMUSERVCONFIGDIR        "userv"
61 #define SHELLLIST                   "shells"
62 #define SYSTEMRCFILEDEFAULT         "system.default"
63 #define SYSTEMRCFILEOVERRIDE        "system.override"
64 #define NONEINCLUDELOOKUP           ":none"
65 #define DEFAULTINCLUDELOOKUP        ":default"
66 #define EMPTYINCLUDELOOKUP          ":empty"
67
68 #define USERCONFIGDIRBASE           SYSTEMUSERVCONFIGDIR
69 #define USERCONFIGDIR               "." USERCONFIGDIRBASE
70 #define USERUSERVCONFIGPATH         "~/" USERCONFIGDIR
71 #define USERRCFILEPATH              USERUSERVCONFIGPATH "/" USERRCFILE
72 #define SYSTEMUSERVCONFIGPATH       SYSTEMCONFIGDIR "/" SYSTEMUSERVCONFIGDIR
73 #define SYSTEMRCFILEDEFAULTPATH     SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEDEFAULT
74 #define SYSTEMRCFILEOVERRIDEPATH    SYSTEMUSERVCONFIGPATH "/" SYSTEMRCFILEOVERRIDE
75 #define SHELLLISTPATH               SYSTEMCONFIGDIR "/" SHELLLIST
76 #define SETENVIRONMENTPATH          SYSTEMCONFIGDIR "/" SETENVIRONMENT
77
78 #define USERVD_LOGIDENT "uservd"
79 #define USERVDCHECK_LOGIDENT "uservd/check"
80 #define USERVD_LOGFACILITY LOG_DAEMON
81 #define DEFUSERLOGFACILITY LOG_USER
82 #define DEFUSERLOGLEVEL LOG_ERR
83
84 #define TOPLEVEL_CONFIGURATION "                   \n\
85   reset                                            \n\
86   user-rcfile " USERRCFILEPATH "                   \n\
87   errors-to-stderr                                 \n\
88   _include-sysconfig " SYSTEMRCFILEDEFAULTPATH "   \n\
89   if grep service-user-shell " SHELLLISTPATH "     \n\
90     errors-push                                    \n\
91       catch-quit                                   \n\
92         _include-user-rcfile                       \n\
93       hctac                                        \n\
94     srorre                                         \n\
95   fi                                               \n\
96   _include-sysconfig " SYSTEMRCFILEOVERRIDEPATH "  \n\
97   quit                                             \n\
98 "
99
100 #define TOPLEVEL_OVERRIDDEN_CONFIGURATION "        \n\
101   reset                                            \n\
102   errors-to-stderr                                 \n\
103   _include-client-config                           \n\
104   quit                                             \n\
105 "
106
107 #define USERVD_MYSELF_CHECK 3600
108 #define USERVD_MYSELF_TIMEOUT 60
109 #define USERVD_CHECKFORK_RETRY 60
110 #define MAX_INCLUDE_NEST 40
111 #define MAX_ERRMSG_LEN (MAX_ERRMSG_STRING-1024)
112 #define ERRMSG_RESERVE_ERRNO 128
113
114 int parse_string(const char *string, const char *descrip, int isinternal);
115 int parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2);
116 void ensurelogopen(int wantfacility);
117 void ensurefdarray(int fd);
118 const char *printtoken(int token);
119 void senderrmsgstderr(const char *errmsg);
120 void disconnect(int exitstatus) NONRETURNING;
121
122 void always_dumpparameter(const char *parm, char **values);
123 void always_dumpexecsettings(void);
124
125 void debug_dumprequest(pid_t mypid);
126 void debug_dumpexecsettings(void);
127 void debug_dumpparameter(const char *parm, char **values);
128 pid_t nondebug_fork(void);
129 const char *nondebug_serviceuserdir(const char *ifnondebug);
130
131 typedef void builtinserviceexec_fnt(const char *const *args);
132 builtinserviceexec_fnt NONRETURNING bisexec_environment, bisexec_parameter;
133 builtinserviceexec_fnt NONRETURNING bisexec_version, bisexec_help;
134 builtinserviceexec_fnt NONRETURNING bisexec_toplevel, bisexec_override, bisexec_reset;
135 builtinserviceexec_fnt NONRETURNING bisexec_execute, bisexec_shutdown;
136 extern const char *const builtinservicehelpstrings[];
137
138 void execservice(const int synchsocket[], int clientfd) NONRETURNING;
139 void servicerequest(int sfd) NONRETURNING;
140 int synchread(int fd, int ch);
141 const char *defaultpath(void);
142
143 struct fdstate {
144   int iswrite; /* 0 or 1; -1 if not open */
145   int realfd, holdfd; /* -1 if not open */
146   int wantstate;
147   /* tokv_word_requirefd, tokv_word_allowfd, tokv_nullfd, tokv_word_rejectfd
148    * (all of which have tokt_wantfdstate set) */
149   int wantrw; /* tokv_word_read, tokv_word_write, 0 for either/both */
150 };
151
152 struct keyvaluepair { char *key, *value; };
153
154 extern pid_t overlordpid;
155 extern struct request_msg request_mbuf;
156 extern struct keyvaluepair *defvararray;
157 extern struct fdstate *fdarray; /* indexed by nominal fd */
158 extern int fdarraysize, fdarrayused;
159 extern int restfdwantstate, restfdwantrw;
160 extern int service_ngids;
161 extern char **argarray;
162 extern char *serviceuser, *service, *loginname, *cwd;
163 extern char *overridedata, *userrcfile;
164 extern char *serviceuser_dir, *serviceuser_shell, *callinguser_shell;
165 extern gid_t *calling_gids, *service_gids;
166 extern uid_t serviceuser_uid;
167 extern const char **calling_groups, **service_groups;
168 extern char *execpath, **execargs;
169 extern int execute; /* One of the execution modes tokt_execmode */
170 extern int setenvironment, suppressargs, disconnecthup;
171 extern builtinserviceexec_fnt *execbuiltin;
172 extern int syslogopenfacility;
173
174 #endif