chiark / gitweb /
5fdfd76670a356105e03710135dace489bb4c17a
[userv.git] / common.h
1 /*
2  * userv - common.h
3  * definitions shared between client and daemon
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 COMMON_H
23 #define COMMON_H
24
25 #define PCSUMSIZE 16
26
27 static const unsigned char protocolchecksumversion[PCSUMSIZE]= {
28 #include "pcsum.h"
29 };
30
31 #ifndef VARDIR
32 # define VARDIR "/var/run/userv"
33 #endif
34
35 #ifndef RENDEZVOUS
36 # define RENDEZVOUS "socket"
37 #endif
38
39 #ifndef RENDEZVOUSPATH
40 # define RENDEZVOUSPATH VARDIR "/" RENDEZVOUS
41 #endif
42
43 #ifndef PIPEFORMAT
44 # define PIPEFORMAT "%lx.%lx.%x"
45 # define PIPEPATTERN "[0-9a-f]*.[0-9a-f]*.*[0-9a-f]"
46 # define PIPEFORMATEXTEND (sizeof(long)*2*2+sizeof(int)*2+1)
47 # define PIPEMAXLEN (sizeof(PIPEFORMAT)+PIPEFORMATEXTEND)
48 #endif
49
50 #ifndef PIPEPATHFORMAT
51 # define PIPEPATHFORMAT VARDIR "/" PIPEFORMAT
52 # define PIPEPATHMAXLEN (sizeof(PIPEPATHFORMAT)+PIPEFORMATEXTEND)
53 #endif
54
55 #define MAX_ALLOW_FD 1024
56 #define MAX_INCLUDE_NEST 40
57 #define MAX_GENERAL_STRING (1024*1024)
58 #define MAX_OVERRIDE_LEN MAX_GENERAL_STRING
59 #define MAX_ARGSDEFVARS 4096
60 #define MAX_GIDS 1024
61
62 #ifdef DEBUG
63 # define BASE_MAGIC 0x5deb7567 /* "\x5d\xebug" */
64 #else
65 # define BASE_MAGIC 0x755e7276 /* "u\x5erv" */
66 #endif
67
68 enum {
69   OPENING_MAGIC= BASE_MAGIC+1,
70   REQUEST_MAGIC,
71   REQUEST_END_MAGIC,
72   PROGRESS_MAGIC,
73   PROGRESS_ERRMSG_END_MAGIC,
74   EVENT_MAGIC
75 };
76
77 struct opening_msg {
78   unsigned long magic;
79   unsigned char protocolchecksumversion[PCSUMSIZE];
80   pid_t serverpid;
81 };
82
83 struct request_msg {
84   unsigned long magic;
85   pid_t clientpid;
86   int serviceuserlen;
87   int servicelen;
88   int lognamelen;
89   int cwdlen;
90   uid_t callinguid;
91   int ngids, nreadfds, nwritefds, nargs, nvars, overridelen;
92   /* Followed by:
93    *   serviceuserlen bytes for the service user (unterminated)
94    *   servicelen bytes for the service (unterminated)
95    *   lognamelen bytes for the login name (unterminated)
96    *   cwdlen bytes for the cwd (unterminated)
97    *   ngids gid_ts for the primary group and supplementary groups
98    *   nreadfds and then nwritefds ints for the file descriptors
99    *   for each of the nargs arguments
100    *    an int for the string length
101    *    that many characters (unterminated)
102    *   for each for the nvars variable keys
103    *    an int for the key length
104    *    that many characters (unterminated)
105    *    an int for the value length
106    *    that many characters (unterminated)
107    *   one unsigned long, endmagic;
108    */
109 };
110
111 struct progress_msg {
112   unsigned long magic;
113   enum { pt_ok, pt_errmsg, pt_failed, pt_terminated } type;
114   union {
115     struct { int messagelen; } errmsg;
116     struct { int status; } terminated;
117   } data;
118   /* follwed by variable-length part:
119    *  for ok: nothing
120    *  for errmsg: messagelen bytes for the error message (unterminated)
121    *              unsigned long PROGRESS_MAGIC
122    *  for terminated: nothing
123    */
124 };
125
126 struct event_msg {
127   unsigned long magic;
128   enum { et_confirm, et_closereadfd, et_disconnect } type;
129   union {
130     struct { int fd; } closereadfd;
131   } data;
132 };
133
134 #endif