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 public static native RLimit getrlimitnofiles();
42 public static native int setrlimitnofiles(RLimit rlimit);
43
44 private static void loadLibrary()
45 {
46
47 try
48 {
49 if(System.getProperty("jetty.libsetuid.path") != null)
50 {
51 File lib = new File(System.getProperty("jetty.libsetuid.path"));
52 if(lib.exists())
53 {
54 System.load(lib.getCanonicalPath());
55 }
56 return;
57 }
58
59 }
60 catch (Throwable e)
61 {
62
63 }
64
65 try
66 {
67 System.loadLibrary("libsetuid");
68 return;
69 }
70 catch (Throwable e)
71 {
72
73 }
74
75
76 try
77 {
78 if(System.getProperty("jetty.home") != null)
79 {
80 File lib = new File(System.getProperty("jetty.home") + "/lib/ext/libsetuid.so");
81 if(lib.exists())
82 {
83 System.load(lib.getCanonicalPath());
84 }
85 return;
86 }
87
88 }
89 catch (Throwable e)
90 {
91
92 }
93
94
95 try
96 {
97 if(System.getProperty("jetty.lib") != null)
98 {
99 File lib = new File(System.getProperty("jetty.lib") + "/libsetuid.so");
100 if(lib.exists())
101 {
102 System.load(lib.getCanonicalPath());
103 }
104 return;
105 }
106
107 }
108 catch (Throwable e)
109 {
110 }
111
112 System.err.println("Error: libsetuid.so could not be found");
113 }
114
115
116 static
117 {
118 loadLibrary();
119 }
120
121 }