Source code: com/neuron/jaffer/OS_Server.java
1 /*
2 * Copyright (c) 2003 Stewart Allen <stewart@neuron.com>. All rights reserved.
3 * This program is free software. See the 'License' file for details.
4 */
5
6 package com.neuron.jaffer;
7
8 import java.io.*;
9 import java.net.*;
10 import java.util.*;
11
12 public class OS_Server extends AFP_Server
13 {
14 private static boolean loaded = false;
15
16 static
17 {
18 String libname = System.getProperty("os.name");
19 if (libname.indexOf(' ') >= 0)
20 {
21 StringBuffer sb = new StringBuffer(libname.length());
22 for (int i=0; i<libname.length(); i++)
23 {
24 if (!Character.isWhitespace(libname.charAt(i)))
25 {
26 sb.append(libname.charAt(i));
27 }
28 }
29 libname = sb.toString();
30 }
31 if (LibHelper.load(libname, "lib/lib"+libname+".so"))
32 {
33 loaded = true;
34 }
35 else
36 {
37 System.out.println("Unable to load Unix Helper. Disabling authentication.");
38 }
39 }
40
41 public OS_Server(String rname, int port)
42 throws IOException
43 {
44 super(rname, port);
45 }
46
47 public OS_Server(String rname, String bind, int port)
48 throws IOException
49 {
50 super(rname, bind, port);
51 }
52
53 private String guest;
54
55 public void setGuestUser(String user)
56 {
57 this.guest = user;
58 }
59
60 // AFP_Server abstract methods
61
62 public boolean hasUser(String user)
63 {
64 //System.out.println("--> CHECK USER ("+user+") <--");
65 if (user == null)
66 {
67 return false;
68 }
69 return loaded ? validUser(CString(user)) : true;
70 }
71
72 public boolean checkPassword(String user, String pass)
73 {
74 //System.out.println("--> CHECK AUTH ("+user+","+pass+") <--");
75 if (user == null || pass == null)
76 {
77 return false;
78 }
79 return loaded ? validPassword(CString(user), CString(pass)) : true;
80 }
81
82 public boolean setThreadOwner(String user)
83 {
84 if (user == null)
85 {
86 return false;
87 }
88 return loaded ? switchUser(CString(user)) : true;
89 }
90
91 public boolean hasCleartextPasswords()
92 {
93 return false;
94 }
95
96 public String getPassword(String userName)
97 {
98 return null;
99 }
100
101 public String getGuestUser()
102 {
103 return guest;
104 }
105
106 // native helpers
107
108 private static byte[] CString(String s)
109 {
110 return (s+"\0").getBytes();
111 }
112
113 private static native boolean validUser(byte u[])
114 ;
115
116 private static native boolean validPassword(byte u[], byte p[])
117 ;
118
119 private static native boolean switchUser(byte u[])
120 ;
121 }
122