1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.mortbay.setuid;
16
17 import java.io.File;
18
19
20
21
22
23
24
25
26 public class SetUID
27 {
28 public static final int OK = 0;
29 public static final int ERROR = -1;
30
31 public static native int setumask(int mask);
32 public static native int setuid(int uid);
33 public static native int setgid(int gid);
34
35 public static native Passwd getpwnam(String name) throws SecurityException;
36 public static native Passwd getpwuid(int uid) throws SecurityException;
37
38 public static native Group getgrnam(String name) throws SecurityException;
39 public static native Group getgrgid(int gid) throws SecurityException;
40
41 private static void loadLibrary()
42 {
43
44 try
45 {
46 if(System.getProperty("jetty.libsetuid.path") != null)
47 {
48 File lib = new File(System.getProperty("jetty.libsetuid.path"));
49 if(lib.exists())
50 {
51 System.load(lib.getCanonicalPath());
52 }
53 return;
54 }
55
56 }
57 catch (Throwable e)
58 {
59
60 }
61
62 try
63 {
64 System.loadLibrary("libsetuid");
65 return;
66 }
67 catch (Throwable e)
68 {
69
70 }
71
72
73 try
74 {
75 if(System.getProperty("jetty.home") != null)
76 {
77 File lib = new File(System.getProperty("jetty.home") + "/lib/ext/libsetuid.so");
78 if(lib.exists())
79 {
80 System.load(lib.getCanonicalPath());
81 }
82 return;
83 }
84
85 }
86 catch (Throwable e)
87 {
88
89 }
90
91
92 try
93 {
94 if(System.getProperty("jetty.lib") != null)
95 {
96 File lib = new File(System.getProperty("jetty.lib") + "/libsetuid.so");
97 if(lib.exists())
98 {
99 System.load(lib.getCanonicalPath());
100 }
101 return;
102 }
103
104 }
105 catch (Throwable e)
106 {
107 }
108
109 System.err.println("Error: libsetuid.so could not be found");
110 }
111
112
113 static
114 {
115 loadLibrary();
116 }
117
118 }