1 /* Copyright (C) 1998-99 Martin Baulig
2 This file is part of LibGTop 1.0.
3
4 Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
5
6 LibGTop is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 LibGTop is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with LibGTop; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20 */
21
22 #ifndef __GLIBTOP_SUID_H__
23 #define __GLIBTOP_SUID_H__
24
25 G_BEGIN_DECLS
26
27 #if _IN_LIBGTOP
28 #include <sys/param.h>
29 #endif
30
31 #include <glibtop_machine.h>
32
33 #define KI_PROC(ki) (&(ki))->kp_proc)
34 #define KI_EPROC(ki) (&(ki))->kp_eproc)
35
36 #define FORCEUREAD 1
37 #define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
38
glibtop_suid_enter(glibtop * server)39 static inline void glibtop_suid_enter (glibtop *server) {
40 glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
41 setregid (server->machine->gid, server->machine->egid);
42 glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
43 };
44
glibtop_suid_leave(glibtop * server)45 static inline void glibtop_suid_leave (glibtop *server) {
46 glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
47 if (setregid (server->machine->egid, server->machine->gid))
48 _exit (1);
49 glibtop_debug ("uid=%d euid=%d gid=%d egid=%d", getuid(), geteuid(), getgid(), getegid());
50 };
51
52 void
53 glibtop_init_p (glibtop *server, const unsigned long features,
54 const unsigned flags);
55 void
56 glibtop_open_p (glibtop *server, const char *program_name,
57 const unsigned long features,
58 const unsigned flags);
59
60 G_END_DECLS
61
62 #endif
63