5f69d9f66fc4d5f8f29cf247742d7957573648eb
[oweals/cde.git] / cde / programs / dtksh / ksh93 / src / lib / libast / preroot / ispreroot.c
1 /* $XConsortium: ispreroot.c /main/3 1995/11/01 18:21:21 rswiston $ */
2 /***************************************************************
3 *                                                              *
4 *                      AT&T - PROPRIETARY                      *
5 *                                                              *
6 *         THIS IS PROPRIETARY SOURCE CODE LICENSED BY          *
7 *                          AT&T CORP.                          *
8 *                                                              *
9 *                Copyright (c) 1995 AT&T Corp.                 *
10 *                     All Rights Reserved                      *
11 *                                                              *
12 *           This software is licensed by AT&T Corp.            *
13 *       under the terms and conditions of the license in       *
14 *       http://www.research.att.com/orgs/ssr/book/reuse        *
15 *                                                              *
16 *               This software was created by the               *
17 *           Software Engineering Research Department           *
18 *                    AT&T Bell Laboratories                    *
19 *                                                              *
20 *               For further information contact                *
21 *                     gsf@research.att.com                     *
22 *                                                              *
23 ***************************************************************/
24
25 /* : : generated by proto : : */
26
27 #if !defined(__PROTO__)
28 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
29 #if defined(__cplusplus)
30 #define __MANGLE__      "C"
31 #else
32 #define __MANGLE__
33 #endif
34 #define __STDARG__
35 #define __PROTO__(x)    x
36 #define __OTORP__(x)
37 #define __PARAM__(n,o)  n
38 #if !defined(__STDC__) && !defined(__cplusplus)
39 #if !defined(c_plusplus)
40 #define const
41 #endif
42 #define signed
43 #define void            int
44 #define volatile
45 #define __V_            char
46 #else
47 #define __V_            void
48 #endif
49 #else
50 #define __PROTO__(x)    ()
51 #define __OTORP__(x)    x
52 #define __PARAM__(n,o)  o
53 #define __MANGLE__
54 #define __V_            char
55 #define const
56 #define signed
57 #define void            int
58 #define volatile
59 #endif
60 #if defined(__cplusplus) || defined(c_plusplus)
61 #define __VARARG__      ...
62 #else
63 #define __VARARG__
64 #endif
65 #if defined(__STDARG__)
66 #define __VA_START__(p,a)       va_start(p,a)
67 #else
68 #define __VA_START__(p,a)       va_start(p)
69 #endif
70 #endif
71 #include <ast.h>
72 #include <preroot.h>
73
74 #if FS_PREROOT
75
76 #include <ls.h>
77
78 /*
79  * return 1 if files a and b are the same under preroot
80  *
81  * NOTE: the kernel disables preroot for set-uid processes
82  */
83
84 static int
85 same __PARAM__((const char* a, const char* b), (a, b)) __OTORP__(const char* a; const char* b;){
86         int             i;
87         int             euid;
88         int             ruid;
89
90         struct stat     ast;
91         struct stat     bst;
92
93         if ((ruid = getuid()) != (euid = geteuid())) setuid(ruid);
94         i = !stat(a, &ast) && !stat(b, &bst) && ast.st_dev == bst.st_dev && ast.st_ino == bst.st_ino;
95         if (ruid != euid) setuid(euid);
96         return(i);
97 }
98
99 int
100 ispreroot __PARAM__((const char* dir), (dir)) __OTORP__(const char* dir;){
101         static int      prerooted = -1;
102
103         if (dir) return(same("/", dir));
104         if (prerooted < 0) prerooted = !same("/", PR_REAL);
105         return(prerooted);
106 }
107
108 #else
109
110 NoN(ispreroot)
111
112 #endif