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