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