chiark / gitweb /
Version -> 0.50.
[userv.git] / daemon.h
1 /*
2  * userv - daemon.h
3  * definitions used in the daemon's source code
4  *
5  * Copyright (C)1996-1997 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 " USERDIRPREFIX "        \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 #define USERRCFILE                  "rc"
47 #define SYSTEMUSERVCONFIGDIR        "userv"
48 #define SHELLLIST                   "shells"
49 #define SYSTEMRCFILEDEFAULT         "system.default"
50 #define SYSTEMRCFILEOVERRIDE        "system.override"
51 #define NONEINCLUDELOOKUP           ":none"
52 #define DEFAULTINCLUDELOOKUP        ":default"
53 #define EMPTYINCLUDELOOKUP          ":empty"
54
55 #define USERDIRPREFIX               USERDIR DIRSEP
56 #define USERCONFIGDIRBASE           SYSTEMUSERVCONFIGDIR
57 #define USERCONFIGDIR               HIDDENPREFIX USERCONFIGDIRBASE
58 #define USERUSERVCONFIGPATH         USERDIR DIRSEP USERCONFIGDIR
59 #define USERRCFILEPATH              USERUSERVCONFIGPATH DIRSEP USERRCFILE
60 #define SYSTEMUSERVCONFIGPATH       SYSTEMCONFIGDIR DIRSEP SYSTEMUSERVCONFIGDIR
61 #define SYSTEMRCFILEDEFAULTPATH     SYSTEMUSERVCONFIGPATH DIRSEP SYSTEMRCFILEDEFAULT
62 #define SYSTEMRCFILEOVERRIDEPATH    SYSTEMUSERVCONFIGPATH DIRSEP SYSTEMRCFILEOVERRIDE
63 #define SHELLLISTPATH               SYSTEMCONFIGDIR DIRSEP SHELLLIST
64
65 #define USERDIR                     "~"
66 #define HIDDENPREFIX                "."
67
68 #define USERVD_LOGIDENT "uservd"
69 #define USERVD_LOGFACILITY LOG_DAEMON
70 #define DEFUSERLOGFACILITY LOG_DAEMON
71 #define DEFUSERLOGLEVEL LOG_ERR
72
73 #define TOPLEVEL_CONFIGURATION "                   \n\
74   reset                                            \n\
75   user-rcfile " USERRCFILEPATH "                   \n\
76   errors-to-stderr                                 \n\
77   _include-sysconfig " SYSTEMRCFILEDEFAULTPATH "   \n\
78   if grep service-user-shell " SHELLLISTPATH "     \n\
79     errors-push                                    \n\
80       catch-quit                                   \n\
81         _include-user-rcfile                       \n\
82       hctac                                        \n\
83     srorre                                         \n\
84   fi                                               \n\
85   _include-sysconfig " SYSTEMRCFILEOVERRIDEPATH "  \n\
86   quit                                             \n\
87 "
88
89 #define TOPLEVEL_OVERRIDDEN_CONFIGURATION "        \n\
90   reset                                            \n\
91   errors-to-stderr                                 \n\
92   _include-client-config                           \n\
93   quit                                             \n\
94 "
95
96 #define MAX_INCLUDE_NEST 40
97 #define MAX_ERRMSG_LEN 2048
98 #define ERRMSG_RESERVE_ERRNO 128
99
100 int parse_string(const char *string, const char *descrip);
101 void parseerrprint(const char *fmt, ...) PRINTFFORMAT(1,2);
102 void ensurelogopen(int wantfacility);
103 void ensurefdarray(int fd);
104 const char *printtoken(int token);
105 void senderrmsgstderr(const char *errmsg);
106 void disconnect(int exitstatus) NONRETURNING;
107
108 void debug_dumprequest(pid_t mypid);
109 void debug_dumpexecsettings(void);
110 void debug_dumpparameter(const char *parm, char **values);
111 pid_t nondebug_fork(void);
112 const char *nondebug_serviceuserdir(const char *ifnondebug);
113
114 struct fdstate {
115   int iswrite, realfd, holdfd;
116   int wantstate;
117   /* tokv_word_requirefd, tokv_word_allowfd, tokv_nullfd, tokv_word_rejectfd
118    * (all of which have tokt_wantfdstate set) */
119   int wantrw;
120   /* tokv_word_read, tokv_word_write */
121 };
122
123 extern gid_t *gidarray;
124 extern char **argarray;
125 extern char *((*defvararray)[2]);
126 extern struct fdstate *fdarray; /* indexed by nominal fd */
127 extern int fdarraysize, fdarrayused;
128 extern int restfdwantstate, restfdwantrw;
129 extern struct request_msg request_mbuf;
130 extern char *serviceuser, *service, *logname, *cwd;
131 extern char *overridedata, *userrcfile;
132 extern char *serviceuser_dir, *serviceuser_shell, *callinguser_shell;
133 extern uid_t serviceuser_uid, callinguser_uid;
134 extern gid_t serviceuser_gid;
135 extern char *execpath, **execargs;
136 extern int execute; /* One of the execution modes tokt_execmode */
137 extern int setenvironment, suppressargs, disconnecthup;
138 extern int ehandling; /* One of the error handling modes tokt_ehandlemode */
139 extern int ehlogfacility, ehloglevel, syslogopenfacility, ehfilekeep;
140 extern FILE *ehfile;
141 extern char *ehfilename;
142
143 #endif