src/share/classes/sun/security/krb5/Config.java

Print this page




1216             // if no DNS TXT records found, try again using sub-realm
1217         }
1218         if (records != null) {
1219             for (int i = 0; i < records.length; i++) {
1220                 if (records[i].equalsIgnoreCase(mapRealm)) {
1221                     return records[i];
1222                 }
1223             }
1224         }
1225         return null;
1226     }
1227 
1228     /**
1229      * Locate KDC using DNS
1230      *
1231      * @param realm the realm for which the master KDC is desired
1232      * @return the KDC
1233      */
1234     private String getKDCFromDNS(String realm) throws KrbException {
1235         // use DNS to locate KDC
1236         String kdcs = null;
1237         String[] srvs = null;
1238         // locate DNS SRV record using UDP
1239         if (DEBUG) {
1240             System.out.println("getKDCFromDNS using UDP");
1241         }
1242         srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
1243         if (srvs == null) {
1244             // locate DNS SRV record using TCP
1245             if (DEBUG) {
1246                 System.out.println("getKDCFromDNS using UDP");
1247             }
1248             srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
1249         }
1250         if (srvs == null) {
1251             // no DNS SRV records
1252             throw new KrbException(Krb5.KRB_ERR_GENERIC,
1253                 "Unable to locate KDC for realm " + realm);
1254         }
1255         for (int i = 0; i < srvs.length; i++) {
1256             String value = srvs[i];
1257             for (int j = 0; j < srvs[i].length(); j++) {
1258                 // filter the KDC name
1259                 if (value.charAt(j) == ':') {
1260                     kdcs = (value.substring(0, j)).trim();
1261                 }
1262             }



1263         }
1264         return kdcs;
1265     }
1266 
1267     private boolean fileExists(String name) {
1268         return java.security.AccessController.doPrivileged(
1269                                 new FileExistsAction(name));
1270     }
1271 
1272     static class FileExistsAction
1273         implements java.security.PrivilegedAction<Boolean> {
1274 
1275         private String fileName;
1276 
1277         public FileExistsAction(String fileName) {
1278             this.fileName = fileName;
1279         }
1280 
1281         public Boolean run() {
1282             return new File(fileName).exists();




1216             // if no DNS TXT records found, try again using sub-realm
1217         }
1218         if (records != null) {
1219             for (int i = 0; i < records.length; i++) {
1220                 if (records[i].equalsIgnoreCase(mapRealm)) {
1221                     return records[i];
1222                 }
1223             }
1224         }
1225         return null;
1226     }
1227 
1228     /**
1229      * Locate KDC using DNS
1230      *
1231      * @param realm the realm for which the master KDC is desired
1232      * @return the KDC
1233      */
1234     private String getKDCFromDNS(String realm) throws KrbException {
1235         // use DNS to locate KDC
1236         String kdcs = "";
1237         String[] srvs = null;
1238         // locate DNS SRV record using UDP
1239         if (DEBUG) {
1240             System.out.println("getKDCFromDNS using UDP");
1241         }
1242         srvs = KrbServiceLocator.getKerberosService(realm, "_udp");
1243         if (srvs == null) {
1244             // locate DNS SRV record using TCP
1245             if (DEBUG) {
1246                 System.out.println("getKDCFromDNS using TCP");
1247             }
1248             srvs = KrbServiceLocator.getKerberosService(realm, "_tcp");
1249         }
1250         if (srvs == null) {
1251             // no DNS SRV records
1252             throw new KrbException(Krb5.KRB_ERR_GENERIC,
1253                 "Unable to locate KDC for realm " + realm);
1254         }
1255         for (int i = 0; i < srvs.length; i++) {
1256             kdcs += srvs[i] + " ";





1257         }
1258         kdcs = kdcs.trim();
1259         if (kdcs.equals("")) {
1260             return null;   
1261         }
1262         return kdcs;
1263     }
1264 
1265     private boolean fileExists(String name) {
1266         return java.security.AccessController.doPrivileged(
1267                                 new FileExistsAction(name));
1268     }
1269 
1270     static class FileExistsAction
1271         implements java.security.PrivilegedAction<Boolean> {
1272 
1273         private String fileName;
1274 
1275         public FileExistsAction(String fileName) {
1276             this.fileName = fileName;
1277         }
1278 
1279         public Boolean run() {
1280             return new File(fileName).exists();