01: package org.mortbay.setuid;
02:
03: import org.mortbay.jetty.Server;
04: import org.mortbay.log.Log;
05:
06: /**
07: * This extension of {@link Server} will make a JNI call to set the unix UID
08: * after the server has been started.
09: * This can be used to start the server as root so that priviledged ports may
10: * be accessed and then switch to a non-root user for security.
11: *
12: * The configured umask is set before the server is started and the configured
13: * uid is set after the server is started.
14: *
15: * @author gregw
16: *
17: */
18: public class SetUIDServer extends Server {
19: int _uid = 0;
20: int _umask = 0;
21:
22: public int getUmask() {
23: return _umask;
24: }
25:
26: public void setUmask(int umask) {
27: _umask = umask;
28: }
29:
30: public int getUid() {
31: return _uid;
32: }
33:
34: public void setUid(int uid) {
35: _uid = uid;
36: }
37:
38: protected void doStart() throws Exception {
39: if (_umask != 0) {
40: Log.info("Setting umask=0" + Integer.toString(_umask, 8));
41: SetUID.setumask(_umask);
42: }
43: super .doStart();
44: if (_uid != 0) {
45: Log.info("Setting UID=" + _uid);
46: SetUID.setuid(_uid);
47: }
48: }
49:
50: }
|