1 /*
2   Copyright Ⓒ 1997, 1998, 1999, 2000, 2001  joost witteveen
3   Copyright Ⓒ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009  Clint Adams
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 */
15 
16 #ifndef FAKEROOT_MESSAGE_H
17 #define FAKEROOT_MESSAGE_H
18 
19 #ifdef HAVE_STDINT_H
20 #include <stdint.h>
21 #else
22 # ifdef HAVE_INTTYPES_H
23 # include <inttypes.h>
24 # else
25 #  error Problem
26 # endif
27 #endif
28 
29 /* On Solaris, use the native htonll(n)/ntohll(n) */
30 #if !defined(sun) && !defined(_NETINET_IN_H)
31 #if __BYTE_ORDER == __BIG_ENDIAN
32 # define htonll(n)  (n)
33 # define ntohll(n)  (n)
34 #elif __BYTE_ORDER == __LITTLE_ENDIAN
35 # define htonll(n)  ((((uint64_t) htonl(n)) << 32LL) | htonl((n) >> 32LL))
36 # define ntohll(n)  ((((uint64_t) ntohl(n)) << 32LL) | ntohl((n) >> 32LL))
37 #endif
38 #endif /* !defined(sun) && !defined(_NETINET_IN_H) */
39 
40 #define FAKEROOTKEY_ENV "FAKEROOTKEY"
41 
42 typedef uint32_t func_id_t;
43 
44 typedef uint64_t fake_ino_t;
45 typedef uint64_t fake_dev_t;
46 typedef uint32_t fake_uid_t;
47 typedef uint32_t fake_gid_t;
48 typedef uint32_t fake_mode_t;
49 typedef uint32_t fake_nlink_t;
50 
51 #if __SUNPRO_C
52 #pragma pack(4)
53 #endif
54 struct fakestat {
55 	fake_uid_t   uid;
56 	fake_gid_t   gid;
57 	fake_ino_t   ino;
58 	fake_dev_t   dev;
59 	fake_dev_t   rdev;
60 	fake_mode_t  mode;
61 	fake_nlink_t nlink;
62 } FAKEROOT_ATTR(packed);
63 #if __SUNPRO_C
64 #pragma pack()
65 #endif
66 
67 #define MAX_IPC_BUFFER_SIZE 1024
68 
69 #if __SUNPRO_C
70 #pragma pack(4)
71 #endif
72 struct fakexattr {
73 	uint32_t   buffersize;
74 	char       buf[MAX_IPC_BUFFER_SIZE];
75 	int32_t    flags_rc; /* flags from setxattr. Return code on round trip */
76 } FAKEROOT_ATTR(packed);
77 #if __SUNPRO_C
78 #pragma pack()
79 #endif
80 
81 #if __SUNPRO_C
82 #pragma pack(4)
83 #endif
84 struct fake_msg {
85 #ifndef FAKEROOT_FAKENET
86 	long mtype; /* message type in SYSV message sending */
87 #endif
88 	func_id_t       id; /* the requested function */
89 #ifndef FAKEROOT_FAKENET
90 	pid_t pid;
91 	int serial;
92 #endif
93 	struct fakestat st;
94 	struct fakexattr xattr;
95 	uint32_t        remote;
96 } FAKEROOT_ATTR(packed);
97 #if __SUNPRO_C
98 #pragma pack()
99 #endif
100 
101 #endif
102