chiark / gitweb /
debian: Use debhelper to generate maint scripts
[userv.git] / common.h
1 /*
2  * userv - common.h
3  * definitions shared between client and daemon
4  *
5  * userv is copyright Ian Jackson and other contributors.
6  * See README for full authorship information.
7  *
8  * This is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with userv; if not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef COMMON_H
23 #define COMMON_H
24
25 #define COPYRIGHT(indent,nl)                                                  \
26  indent "Copyright 1996-2021 Ian Jackson; copyright 2000 Ben Harris;"      nl \
27  indent "Copyright 2021 Genome Research Limited apropos work by"           nl \
28  indent "Matthew Vernon."                                                  nl \
29  indent "there is NO WARRANTY; type `userv --copyright' for details."      nl
30
31 #define PCSUMSIZE 16
32
33 static const unsigned char protocolchecksumversion[PCSUMSIZE]= {
34 #include "pcsum.h"
35 };
36
37 #ifndef VARDIR
38 # define VARDIR "/var/run/userv"
39 #endif
40
41 #ifndef RENDEZVOUS
42 # define RENDEZVOUS "socket"
43 #endif
44
45 #ifndef RENDEZVOUSPATH
46 # define RENDEZVOUSPATH VARDIR "/" RENDEZVOUS
47 #endif
48
49 #ifndef PIPEFORMAT
50 # define PIPEFORMAT "%lx.%lx.%x"
51 # define PIPEPATTERN "[0-9a-f]*.[0-9a-f]*.*[0-9a-f]"
52 # define PIPEFORMATEXTEND ((int)(sizeof(unsigned long)*2*2+(int)sizeof(int)*2+3))
53 # define PIPEMAXLEN ((int)(sizeof(PIPEFORMAT)+PIPEFORMATEXTEND))
54 #endif
55
56 #ifndef PIPEPATHFORMAT
57 # define PIPEPATHFORMAT VARDIR "/" PIPEFORMAT
58 # define PIPEPATHMAXLEN ((int)(sizeof(PIPEPATHFORMAT)+PIPEFORMATEXTEND))
59 #endif
60
61 #define MAX_ALLOW_FD 1024
62 #define MAX_GENERAL_STRING (1024*1024)
63 #define MAX_OVERRIDE_LEN MAX_GENERAL_STRING
64 #define MAX_ERRMSG_STRING 4096
65 #define MAX_ARGSDEFVAR 4096
66 #define MAX_GIDS 1024
67
68 #ifdef DEBUG
69 # define BASE_MAGIC 0x5deb7567UL /* "\x5d\xebug" */
70 #else
71 # define BASE_MAGIC 0x755e7276UL /* "u\x5erv" */
72 #endif
73
74 enum {
75   OPENING_MAGIC= BASE_MAGIC+1,
76   REQUEST_MAGIC,
77   REQUEST_END_MAGIC,
78   PROGRESS_MAGIC,
79   PROGRESS_ERRMSG_END_MAGIC,
80   EVENT_MAGIC
81 };
82
83 struct opening_msg {
84   unsigned long magic;
85   unsigned char protocolchecksumversion[PCSUMSIZE];
86   pid_t overlordpid, serverpid;
87 };
88
89 struct request_msg {
90   unsigned long magic;
91   pid_t clientpid; /* or -1 if no service is required and this was a version check */
92   int serviceuserlen;
93   int servicelen;
94   int loginnamelen, spoofed; /* spoofed is 0 or 1 */
95   int cwdlen, overridelen;
96   uid_t callinguid;
97   int ngids, nreadfds, nwritefds, nargs, nvars;
98   /* Followed by:
99    *   serviceuserlen bytes for the service user (unterminated)
100    *   servicelen bytes for the service (unterminated)
101    *   loginnamelen bytes for the login name (unterminated)
102    *   cwdlen bytes for the cwd (unterminated)
103    *   overridelen bytes for the override data (with extra \n but unterminated),
104    *    or nothing if overridelen==-1
105    *   ngids gid_ts for the primary group and supplementary groups
106    *   nreadfds and then nwritefds ints for the file descriptors
107    *   for each of the nargs arguments
108    *    an int for the string length
109    *    that many characters (unterminated)
110    *   for each for the nvars variable keys
111    *    an int for the key length
112    *    that many characters (unterminated)
113    *    an int for the value length
114    *    that many characters (unterminated)
115    *   one unsigned long, endmagic;
116    */
117 };
118
119 struct progress_msg {
120   unsigned long magic;
121   enum { pt_ok, pt_errmsg, pt_failed, pt_terminated } type;
122   union {
123     struct { int messagelen; } errmsg;
124     struct { int status; } terminated;
125   } data;
126   /* follwed by variable-length part:
127    *  for ok, failed, terminated: nothing
128    *  for errmsg: messagelen bytes for the error message (unterminated, no \n)
129    *              unsigned long PROGRESS_ERRMSG_END_MAGIC
130    */
131 };
132
133 struct event_msg {
134   unsigned long magic;
135   enum { et_confirm, et_closereadfd, et_disconnect } type;
136   union {
137     struct { int fd; } closereadfd;
138   } data;
139 };
140
141 #endif