1 /*
2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8009875
27  * @summary Provide a default udp_preference_limit for krb5.conf
28  * @modules java.security.jgss/sun.security.krb5:+open
29  * @run main/othervm DefUdpLimit -1 1465
30  * @run main/othervm DefUdpLimit 0 0
31  * @run main/othervm DefUdpLimit 1234 1234
32  * @run main/othervm DefUdpLimit 12345 12345
33  * @run main/othervm DefUdpLimit 123456 32700
34  *
35  */
36 
37 import sun.security.krb5.KdcComm;
38 
39 import java.lang.reflect.Field;
40 import java.nio.file.Files;
41 import java.nio.file.Paths;
42 
43 public class DefUdpLimit {
44 
main(String[] args)45     public static void main(String[] args) throws Exception {
46         int set = Integer.valueOf(args[0]);
47         int expected = Integer.valueOf(args[1]);
48         Field f = KdcComm.class.getDeclaredField("defaultUdpPrefLimit");
49         f.setAccessible(true);
50         writeConf(set);
51         int actual = (Integer)f.get(null);
52         if (actual != expected) {
53             throw new Exception("Expected: " + expected + ", get " + actual);
54         }
55     }
56 
writeConf(int i)57     static void writeConf(int i) throws Exception {
58         String file = "krb5.conf." + i;
59         String content = "[libdefaults]\n";
60         if (i >= 0) {
61             content += "udp_preference_limit = " + i;
62         }
63         Files.write(Paths.get(file), content.getBytes());
64         System.setProperty("java.security.krb5.conf", file);
65     }
66 }
67 
68