author | weijun |
Mon, 22 Nov 2010 09:43:58 +0800 | |
changeset 7288 | a38f3099e518 |
parent 5506 | 202f599c92aa |
child 7977 | f47f211cd627 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7288
a38f3099e518
6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* =========================================================================== |
|
28 |
* (C) Copyright IBM Corp. 1999 All Rights Reserved. |
|
29 |
* |
|
30 |
* Copyright 1997 The Open Group Research Institute. All rights reserved. |
|
31 |
* =========================================================================== |
|
32 |
* |
|
33 |
*/ |
|
34 |
package sun.security.krb5.internal.ccache; |
|
35 |
||
36 |
import sun.security.krb5.*; |
|
37 |
import sun.security.krb5.internal.*; |
|
38 |
import java.util.StringTokenizer; |
|
39 |
import java.util.Vector; |
|
40 |
import java.io.IOException; |
|
41 |
import java.io.File; |
|
42 |
import java.io.FileInputStream; |
|
43 |
import java.io.FileOutputStream; |
|
44 |
import java.io.BufferedReader; |
|
45 |
import java.io.InputStreamReader; |
|
46 |
import java.lang.reflect.*; |
|
47 |
||
48 |
/** |
|
49 |
* CredentialsCache stores credentials(tickets, session keys, etc) in a |
|
50 |
* semi-permanent store |
|
51 |
* for later use by different program. |
|
52 |
* |
|
53 |
* @author Yanni Zhang |
|
54 |
* @author Ram Marti |
|
55 |
*/ |
|
56 |
||
57 |
public class FileCredentialsCache extends CredentialsCache |
|
58 |
implements FileCCacheConstants { |
|
59 |
public int version; |
|
60 |
public Tag tag; // optional |
|
61 |
public PrincipalName primaryPrincipal; |
|
62 |
public Realm primaryRealm; |
|
63 |
private Vector<Credentials> credentialsList; |
|
64 |
private static String dir; |
|
65 |
private static boolean DEBUG = Krb5.DEBUG; |
|
66 |
||
67 |
public static synchronized FileCredentialsCache acquireInstance( |
|
68 |
PrincipalName principal, String cache) { |
|
69 |
try { |
|
70 |
FileCredentialsCache fcc = new FileCredentialsCache(); |
|
71 |
if (cache == null) { |
|
72 |
cacheName = fcc.getDefaultCacheName(); |
|
73 |
} else { |
|
74 |
cacheName = fcc.checkValidation(cache); |
|
75 |
} |
|
76 |
if ((cacheName == null) || !(new File(cacheName)).exists()) { |
|
77 |
// invalid cache name or the file doesn't exist |
|
78 |
return null; |
|
79 |
} |
|
80 |
if (principal != null) { |
|
81 |
fcc.primaryPrincipal = principal; |
|
82 |
fcc.primaryRealm = principal.getRealm(); |
|
83 |
} |
|
84 |
fcc.load(cacheName); |
|
85 |
return fcc; |
|
86 |
} catch (IOException e) { |
|
87 |
// we don't handle it now, instead we return a null at the end. |
|
88 |
if (DEBUG) { |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
} catch (KrbException e) { |
|
92 |
// we don't handle it now, instead we return a null at the end. |
|
93 |
if (DEBUG) { |
|
94 |
e.printStackTrace(); |
|
95 |
} |
|
96 |
} |
|
97 |
return null; |
|
98 |
} |
|
99 |
||
100 |
public static FileCredentialsCache acquireInstance() { |
|
101 |
return acquireInstance(null, null); |
|
102 |
} |
|
103 |
||
104 |
static synchronized FileCredentialsCache New(PrincipalName principal, |
|
105 |
String name) { |
|
106 |
try { |
|
107 |
FileCredentialsCache fcc = new FileCredentialsCache(); |
|
108 |
cacheName = fcc.checkValidation(name); |
|
109 |
if (cacheName == null) { |
|
110 |
// invalid cache name or the file doesn't exist |
|
111 |
return null; |
|
112 |
} |
|
113 |
fcc.init(principal, cacheName); |
|
114 |
return fcc; |
|
115 |
} |
|
116 |
catch (IOException e) { |
|
117 |
} |
|
118 |
catch (KrbException e) { |
|
119 |
} |
|
120 |
return null; |
|
121 |
} |
|
122 |
||
123 |
static synchronized FileCredentialsCache New(PrincipalName principal) { |
|
124 |
try { |
|
125 |
FileCredentialsCache fcc = new FileCredentialsCache(); |
|
126 |
cacheName = fcc.getDefaultCacheName(); |
|
127 |
fcc.init(principal, cacheName); |
|
128 |
return fcc; |
|
129 |
} |
|
130 |
catch (IOException e) { |
|
131 |
if (DEBUG) { |
|
132 |
e.printStackTrace(); |
|
133 |
} |
|
134 |
} catch (KrbException e) { |
|
135 |
if (DEBUG) { |
|
136 |
e.printStackTrace(); |
|
137 |
} |
|
138 |
||
139 |
} |
|
140 |
return null; |
|
141 |
} |
|
142 |
||
143 |
private FileCredentialsCache() { |
|
144 |
} |
|
145 |
||
146 |
boolean exists(String cache) { |
|
147 |
File file = new File(cache); |
|
148 |
if (file.exists()) { |
|
149 |
return true; |
|
150 |
} else return false; |
|
151 |
} |
|
152 |
||
153 |
synchronized void init(PrincipalName principal, String name) |
|
154 |
throws IOException, KrbException { |
|
155 |
primaryPrincipal = principal; |
|
156 |
primaryRealm = principal.getRealm(); |
|
157 |
CCacheOutputStream cos = |
|
158 |
new CCacheOutputStream(new FileOutputStream(name)); |
|
159 |
version = KRB5_FCC_FVNO_3; |
|
160 |
cos.writeHeader(primaryPrincipal, version); |
|
161 |
cos.close(); |
|
162 |
load(name); |
|
163 |
} |
|
164 |
||
165 |
synchronized void load(String name) throws IOException, KrbException { |
|
166 |
PrincipalName p; |
|
167 |
CCacheInputStream cis = |
|
168 |
new CCacheInputStream(new FileInputStream(name)); |
|
169 |
version = cis.readVersion(); |
|
170 |
if (version == KRB5_FCC_FVNO_4) { |
|
171 |
tag = cis.readTag(); |
|
172 |
} else { |
|
173 |
tag = null; |
|
174 |
if (version == KRB5_FCC_FVNO_1 || version == KRB5_FCC_FVNO_2) { |
|
175 |
cis.setNativeByteOrder(); |
|
176 |
} |
|
177 |
} |
|
178 |
p = cis.readPrincipal(version); |
|
179 |
||
180 |
if (primaryPrincipal != null) { |
|
181 |
if (!(primaryPrincipal.match(p))) { |
|
182 |
throw new IOException("Primary principals don't match."); |
|
183 |
} |
|
184 |
} else |
|
185 |
primaryPrincipal = p; |
|
186 |
primaryRealm = primaryPrincipal.getRealm(); |
|
187 |
credentialsList = new Vector<Credentials> (); |
|
188 |
while (cis.available() > 0) { |
|
7288
a38f3099e518
6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents:
5506
diff
changeset
|
189 |
Credentials cred = cis.readCred(version); |
a38f3099e518
6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents:
5506
diff
changeset
|
190 |
if (cred != null) { |
a38f3099e518
6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents:
5506
diff
changeset
|
191 |
credentialsList.addElement(cred); |
a38f3099e518
6979329: CCacheInputStream fails to read ticket cache files from Kerberos 1.8.1
weijun
parents:
5506
diff
changeset
|
192 |
} |
2 | 193 |
} |
194 |
cis.close(); |
|
195 |
} |
|
196 |
||
197 |
||
198 |
/** |
|
199 |
* Updates the credentials list. If the specified credentials for the |
|
200 |
* service is new, add it to the list. If there is an entry in the list, |
|
201 |
* replace the old credentials with the new one. |
|
202 |
* @param c the credentials. |
|
203 |
*/ |
|
204 |
||
205 |
public synchronized void update(Credentials c) { |
|
206 |
if (credentialsList != null) { |
|
207 |
if (credentialsList.isEmpty()) { |
|
208 |
credentialsList.addElement(c); |
|
209 |
} else { |
|
210 |
Credentials tmp = null; |
|
211 |
boolean matched = false; |
|
212 |
||
213 |
for (int i = 0; i < credentialsList.size(); i++) { |
|
214 |
tmp = credentialsList.elementAt(i); |
|
215 |
if (match(c.sname.getNameStrings(), |
|
216 |
tmp.sname.getNameStrings()) && |
|
217 |
((c.sname.getRealmString()).equalsIgnoreCase( |
|
218 |
tmp.sname.getRealmString()))) { |
|
219 |
matched = true; |
|
220 |
if (c.endtime.getTime() >= tmp.endtime.getTime()) { |
|
221 |
if (DEBUG) { |
|
222 |
System.out.println(" >>> FileCredentialsCache " |
|
223 |
+ "Ticket matched, overwrite " |
|
224 |
+ "the old one."); |
|
225 |
} |
|
226 |
credentialsList.removeElementAt(i); |
|
227 |
credentialsList.addElement(c); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
if (matched == false) { |
|
232 |
if (DEBUG) { |
|
233 |
System.out.println(" >>> FileCredentialsCache Ticket " |
|
234 |
+ "not exactly matched, " |
|
235 |
+ "add new one into cache."); |
|
236 |
} |
|
237 |
||
238 |
credentialsList.addElement(c); |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
public synchronized PrincipalName getPrimaryPrincipal() { |
|
245 |
return primaryPrincipal; |
|
246 |
} |
|
247 |
||
248 |
||
249 |
/** |
|
250 |
* Saves the credentials cache file to the disk. |
|
251 |
*/ |
|
252 |
public synchronized void save() throws IOException, Asn1Exception { |
|
253 |
CCacheOutputStream cos |
|
254 |
= new CCacheOutputStream(new FileOutputStream(cacheName)); |
|
255 |
cos.writeHeader(primaryPrincipal, version); |
|
256 |
Credentials[] tmp = null; |
|
257 |
if ((tmp = getCredsList()) != null) { |
|
258 |
for (int i = 0; i < tmp.length; i++) { |
|
259 |
cos.addCreds(tmp[i]); |
|
260 |
} |
|
261 |
} |
|
262 |
cos.close(); |
|
263 |
} |
|
264 |
||
265 |
boolean match(String[] s1, String[] s2) { |
|
266 |
if (s1.length != s2.length) { |
|
267 |
return false; |
|
268 |
} else { |
|
269 |
for (int i = 0; i < s1.length; i++) { |
|
270 |
if (!(s1[i].equalsIgnoreCase(s2[i]))) { |
|
271 |
return false; |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
return true; |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Returns the list of credentials entries in the cache file. |
|
280 |
*/ |
|
281 |
public synchronized Credentials[] getCredsList() { |
|
282 |
if ((credentialsList == null) || (credentialsList.isEmpty())) { |
|
283 |
return null; |
|
284 |
} else { |
|
285 |
Credentials[] tmp = new Credentials[credentialsList.size()]; |
|
286 |
for (int i = 0; i < credentialsList.size(); i++) { |
|
287 |
tmp[i] = credentialsList.elementAt(i); |
|
288 |
} |
|
289 |
return tmp; |
|
290 |
} |
|
291 |
||
292 |
} |
|
293 |
||
294 |
public Credentials getCreds(LoginOptions options, |
|
295 |
PrincipalName sname, Realm srealm) { |
|
296 |
if (options == null) { |
|
297 |
return getCreds(sname, srealm); |
|
298 |
} else { |
|
299 |
Credentials[] list = getCredsList(); |
|
300 |
if (list == null) { |
|
301 |
return null; |
|
302 |
} else { |
|
303 |
for (int i = 0; i < list.length; i++) { |
|
304 |
if (sname.match(list[i].sname) && |
|
305 |
(srealm.toString().equals(list[i].srealm.toString()))) { |
|
306 |
if (list[i].flags.match(options)) { |
|
307 |
return list[i]; |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
} |
|
312 |
return null; |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
||
317 |
/** |
|
318 |
* Gets a credentials for a specified service. |
|
319 |
* @param sname service principal name. |
|
320 |
* @param srealm the realm that the service belongs to. |
|
321 |
*/ |
|
322 |
public Credentials getCreds(PrincipalName sname, Realm srealm) { |
|
323 |
Credentials[] list = getCredsList(); |
|
324 |
if (list == null) { |
|
325 |
return null; |
|
326 |
} else { |
|
327 |
for (int i = 0; i < list.length; i++) { |
|
328 |
if (sname.match(list[i].sname) && |
|
329 |
(srealm.toString().equals(list[i].srealm.toString()))) { |
|
330 |
return list[i]; |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
334 |
return null; |
|
335 |
} |
|
336 |
||
337 |
public Credentials getDefaultCreds() { |
|
338 |
Credentials[] list = getCredsList(); |
|
339 |
if (list == null) { |
|
340 |
return null; |
|
341 |
} else { |
|
342 |
for (int i = list.length-1; i >= 0; i--) { |
|
343 |
if (list[i].sname.toString().startsWith("krbtgt")) { |
|
344 |
String[] nameStrings = list[i].sname.getNameStrings(); |
|
345 |
// find the TGT for the current realm krbtgt/realm@realm |
|
346 |
if (nameStrings[1].equals(list[i].srealm.toString())) { |
|
347 |
return list[i]; |
|
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
return null; |
|
353 |
} |
|
354 |
||
355 |
/* |
|
356 |
* Returns path name of the credentials cache file. |
|
357 |
* The path name is searched in the following order: |
|
358 |
* |
|
2919
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
359 |
* 1. KRB5CCNAME |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
360 |
* 2. /tmp/krb5cc_<uid> on unix systems |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
361 |
* 3. <user.home>/krb5cc_<user.name> |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
362 |
* 4. <user.home>/krb5cc (if can't get <user.name>) |
2 | 363 |
*/ |
364 |
||
365 |
public static String getDefaultCacheName() { |
|
2919
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
366 |
|
2 | 367 |
String stdCacheNameComponent = "krb5cc"; |
368 |
String name; |
|
2919
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
369 |
|
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
370 |
name = java.security.AccessController.doPrivileged( |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
371 |
new java.security.PrivilegedAction<String>() { |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
372 |
@Override |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
373 |
public String run() { |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
374 |
return System.getenv("KRB5CCNAME"); |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
375 |
} |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
376 |
}); |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
377 |
if (name != null) { |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
378 |
if (DEBUG) { |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
379 |
System.out.println(">>>KinitOptions cache name is " + name); |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
380 |
} |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
381 |
return name; |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
382 |
} |
85e23f3ff211
6832353: Krb5LoginModule: use the KRB5CCNAME when searching for Kerberos ticket cache
weijun
parents:
2
diff
changeset
|
383 |
|
2 | 384 |
// get cache name from system.property |
385 |
String osname = |
|
386 |
java.security.AccessController.doPrivileged( |
|
387 |
new sun.security.action.GetPropertyAction("os.name")); |
|
388 |
||
389 |
/* |
|
390 |
* For Unix platforms we use the default cache name to be |
|
391 |
* /tmp/krbcc_uid ; for all other platforms we use |
|
392 |
* {user_home}/krb5_cc{user_name} |
|
393 |
* Please note that for Windows 2K we will use LSA to get |
|
394 |
* the TGT from the the default cache even before we come here; |
|
395 |
* however when we create cache we will create a cache under |
|
396 |
* {user_home}/krb5_cc{user_name} for non-Unix platforms including |
|
397 |
* Windows 2K. |
|
398 |
*/ |
|
399 |
||
400 |
if (osname != null) { |
|
401 |
String cmd = null; |
|
402 |
String uidStr = null; |
|
403 |
long uid = 0; |
|
404 |
||
405 |
if (osname.startsWith("SunOS") || |
|
406 |
(osname.startsWith("Linux"))) { |
|
407 |
try { |
|
408 |
Class<?> c = Class.forName |
|
409 |
("com.sun.security.auth.module.UnixSystem"); |
|
410 |
Constructor<?> constructor = c.getConstructor(); |
|
411 |
Object obj = constructor.newInstance(); |
|
412 |
Method method = c.getMethod("getUid"); |
|
413 |
uid = ((Long)method.invoke(obj)).longValue(); |
|
414 |
name = File.separator + "tmp" + |
|
415 |
File.separator + stdCacheNameComponent + "_" + uid; |
|
416 |
if (DEBUG) { |
|
417 |
System.out.println(">>>KinitOptions cache name is " + |
|
418 |
name); |
|
419 |
} |
|
420 |
return name; |
|
421 |
} catch (Exception e) { |
|
422 |
if (DEBUG) { |
|
423 |
System.out.println("Exception in obtaining uid " + |
|
424 |
"for Unix platforms " + |
|
425 |
"Using user's home directory"); |
|
426 |
||
427 |
||
428 |
e.printStackTrace(); |
|
429 |
} |
|
430 |
} |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
// we did not get the uid; |
|
435 |
||
436 |
||
437 |
String user_name = |
|
438 |
java.security.AccessController.doPrivileged( |
|
439 |
new sun.security.action.GetPropertyAction("user.name")); |
|
440 |
||
441 |
String user_home = |
|
442 |
java.security.AccessController.doPrivileged( |
|
443 |
new sun.security.action.GetPropertyAction("user.home")); |
|
444 |
||
445 |
if (user_home == null) { |
|
446 |
user_home = |
|
447 |
java.security.AccessController.doPrivileged( |
|
448 |
new sun.security.action.GetPropertyAction("user.dir")); |
|
449 |
} |
|
450 |
||
451 |
if (user_name != null) { |
|
452 |
name = user_home + File.separator + |
|
453 |
stdCacheNameComponent + "_" + user_name; |
|
454 |
} else { |
|
455 |
name = user_home + File.separator + stdCacheNameComponent; |
|
456 |
} |
|
457 |
||
458 |
if (DEBUG) { |
|
459 |
System.out.println(">>>KinitOptions cache name is " + name); |
|
460 |
} |
|
461 |
||
462 |
return name; |
|
463 |
} |
|
464 |
||
465 |
public static String checkValidation(String name) { |
|
466 |
String fullname = null; |
|
467 |
if (name == null) { |
|
468 |
return null; |
|
469 |
} |
|
470 |
try { |
|
471 |
// get full path name |
|
472 |
fullname = (new File(name)).getCanonicalPath(); |
|
473 |
File fCheck = new File(fullname); |
|
474 |
if (!(fCheck.exists())) { |
|
475 |
// get absolute directory |
|
476 |
File temp = new File(fCheck.getParent()); |
|
477 |
// test if the directory exists |
|
478 |
if (!(temp.isDirectory())) |
|
479 |
fullname = null; |
|
480 |
temp = null; |
|
481 |
} |
|
482 |
fCheck = null; |
|
483 |
||
484 |
} catch (IOException e) { |
|
485 |
fullname = null; // invalid name |
|
486 |
} |
|
487 |
return fullname; |
|
488 |
} |
|
489 |
||
490 |
||
491 |
private static String exec(String c) { |
|
492 |
StringTokenizer st = new StringTokenizer(c); |
|
493 |
Vector<String> v = new Vector<String> (); |
|
494 |
while (st.hasMoreTokens()) { |
|
495 |
v.addElement(st.nextToken()); |
|
496 |
} |
|
497 |
final String[] command = new String[v.size()]; |
|
498 |
v.copyInto(command); |
|
499 |
try { |
|
500 |
||
501 |
Process p = |
|
502 |
java.security.AccessController.doPrivileged |
|
503 |
(new java.security.PrivilegedAction<Process> () { |
|
504 |
public Process run() { |
|
505 |
try { |
|
506 |
return (Runtime.getRuntime().exec(command)); |
|
507 |
} catch (java.io.IOException e) { |
|
508 |
if (DEBUG) { |
|
509 |
e.printStackTrace(); |
|
510 |
} |
|
511 |
return null; |
|
512 |
} |
|
513 |
} |
|
514 |
}); |
|
515 |
if (p == null) { |
|
516 |
// exception occured in execing the command |
|
517 |
return null; |
|
518 |
} |
|
519 |
||
520 |
BufferedReader commandResult = |
|
521 |
new BufferedReader |
|
522 |
(new InputStreamReader(p.getInputStream(), "8859_1")); |
|
523 |
String s1 = null; |
|
524 |
if ((command.length == 1) && |
|
525 |
(command[0].equals("/usr/bin/env"))) { |
|
526 |
while ((s1 = commandResult.readLine()) != null) { |
|
527 |
if (s1.length() >= 11) { |
|
528 |
if ((s1.substring(0, 11)).equalsIgnoreCase |
|
529 |
("KRB5CCNAME=")) { |
|
530 |
s1 = s1.substring(11); |
|
531 |
break; |
|
532 |
} |
|
533 |
} |
|
534 |
} |
|
535 |
} else s1 = commandResult.readLine(); |
|
536 |
commandResult.close(); |
|
537 |
return s1; |
|
538 |
} catch (Exception e) { |
|
539 |
if (DEBUG) { |
|
540 |
e.printStackTrace(); |
|
541 |
} |
|
542 |
} |
|
543 |
return null; |
|
544 |
} |
|
545 |
} |