diff --git a/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java b/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java
index 4fd7b3bf4e6..d7c5484ec0c 100644
--- a/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java
+++ b/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java
@@ -1,5 +1,5 @@
/*
- * Portions Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
+ * Portions Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -403,11 +403,11 @@ public class KeyTab implements KeyTabConstants {
/**
* Retrieves the key table entry with the specified service name.
* @param service the service which may have an entry in the key table.
+ * @param keyType the etype to match, returns the 1st one if -1 provided
* @return -1 if the entry is not found, else return the entry index
* in the list.
*/
private int retrieveEntry(PrincipalName service, int keyType) {
- int found = -1;
KeyTabEntry e;
if (entries != null) {
for (int i = 0; i < entries.size(); i++) {
@@ -418,7 +418,7 @@ public class KeyTab implements KeyTabConstants {
}
}
}
- return found;
+ return -1;
}
/**
@@ -476,12 +476,29 @@ public class KeyTab implements KeyTabConstants {
/**
* Removes an entry from the key table.
* @param service the service PrincipalName
.
+ * @param etype the etype to match, first one if -1 provided
+ * @return 1 if removed successfully, 0 otherwise
*/
- public void deleteEntry(PrincipalName service) {
- int result = retrieveEntry(service, -1);
+ public int deleteEntry(PrincipalName service, int etype) {
+ int result = retrieveEntry(service, etype);
if (result != -1) {
entries.removeElementAt(result);
+ return 1;
}
+ return 0;
+ }
+
+ /**
+ * Removes an entry from the key table.
+ * @param service the service PrincipalName
.
+ * @return number of entries removed
+ */
+ public int deleteEntry(PrincipalName service) {
+ int count = 0;
+ while (deleteEntry(service, -1) > 0) {
+ count++;
+ }
+ return count;
}
/**
diff --git a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java
index c4724fbd382..5cb919b9d52 100644
--- a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java
+++ b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Klist.java
@@ -1,4 +1,5 @@
/*
+ * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
diff --git a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Ktab.java b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Ktab.java
index b773189c113..30be1b51405 100644
--- a/jdk/src/windows/classes/sun/security/krb5/internal/tools/Ktab.java
+++ b/jdk/src/windows/classes/sun/security/krb5/internal/tools/Ktab.java
@@ -1,4 +1,5 @@
/*
+ * Portions Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,16 +31,15 @@
package sun.security.krb5.internal.tools;
import sun.security.krb5.*;
-import sun.security.krb5.internal.*;
import sun.security.krb5.internal.ktab.*;
-import sun.security.krb5.KrbCryptoException;
-import java.lang.RuntimeException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
-import java.io.FileOutputStream;
import java.io.File;
+import java.text.DateFormat;
import java.util.Arrays;
+import java.util.Date;
+import sun.security.krb5.internal.crypto.EType;
/**
* This class can execute as a command-line tool to help the user manage
* entires in the key table.
@@ -55,6 +55,9 @@ public class Ktab {
char action;
String name; // name and directory of key table
String principal;
+ boolean showEType;
+ boolean showTime;
+ int etype = -1;
char[] password = null;
/**
@@ -62,13 +65,14 @@ public class Ktab {
*
Usage: ktab
*
available options to Ktab:
*
- * - -l list the keytab name and entries
+ *
- -l [-e] [-t] list the keytab name and entries, -e show
+ * encryption etypes, -t show timestamps.
*
- -a <principal name>
* (<password>) add an entry to the keytab.
* The entry is added only to the keytab. No changes are made to the
* Kerberos database.
- *
- -d <principal name>
- * delete an entry from the keytab
+ *
- -d <principal name> [<etype>]
+ * delete an entry from the keytab.
* The entry is deleted only from the keytab. No changes are made to the
* Kerberos database.
*
- -k <keytab name >
@@ -182,6 +186,11 @@ public class Ktab {
i++;
if ((i < args.length) && (!args[i].startsWith("-"))) {
principal = args[i];
+ int j = i + 1;
+ if ((j < args.length) && (!args[j].startsWith("-"))) {
+ etype = Integer.parseInt(args[j]);
+ i = j;
+ }
} else {
System.out.println("Please specify the principal" +
"name of the entry you want to " +
@@ -207,6 +216,12 @@ public class Ktab {
System.exit(-1);
}
break;
+ case 'e':
+ showEType = true;
+ break;
+ case 't':
+ showTime = true;
+ break;
default:
printHelp();
System.exit(-1);
@@ -271,25 +286,54 @@ public class Ktab {
* Lists key table name and entries in it.
*/
void listKt() {
- int version;
- String principal;
- // System.out.println("Keytab name: " + admin.getKeyTabName());
- System.out.println("Keytab name: " + table.tabName());
- // KeyTabEntry[] entries = admin.getEntries();
+ System.out.println("Keytab name: " + KeyTab.tabName());
KeyTabEntry[] entries = table.getEntries();
if ((entries != null) && (entries.length > 0)) {
- System.out.println("KVNO Principal");
+ String[][] output = new String[entries.length+1][showTime?3:2];
+ int column = 0;
+ output[0][column++] = "KVNO";
+ if (showTime) output[0][column++] = "Timestamp";
+ output[0][column++] = "Principal";
for (int i = 0; i < entries.length; i++) {
- version = entries[i].getKey().getKeyVersionNumber().intValue();
- principal = entries[i].getService().toString();
- if (i == 0) {
- StringBuffer separator = new StringBuffer();
- for (int j = 0; j < 9 + principal.length(); j++) {
- separator.append("-");
- }
- System.out.println(separator.toString());
+ column = 0;
+ output[i+1][column++] = entries[i].getKey().
+ getKeyVersionNumber().toString();
+ if (showTime) output[i+1][column++] =
+ DateFormat.getDateTimeInstance(
+ DateFormat.SHORT, DateFormat.SHORT).format(
+ new Date(entries[i].getTimeStamp().getTime()));
+ String princ = entries[i].getService().toString();
+ if (showEType) {
+ int e = entries[i].getKey().getEType();
+ output[i+1][column++] = princ + " (" + e + ":" +
+ EType.toString(e) + ")";
+ } else {
+ output[i+1][column++] = princ;
}
- System.out.println(" " + version + " " + principal);
+ }
+ int[] width = new int[column];
+ for (int j=0; j width[j]) {
+ width[j] = output[i][j].length();
+ }
+ }
+ if (j != 0) width[j] = -width[j];
+ }
+ for (int j=0; j");
System.out.println("available options to Ktab:");
- System.out.println("-l\t\t\t\tlist the keytab name and entries");
+ System.out.println("-l [-e] [-t]\t\t\tlist the keytab name and entries,\n\t\t\t\t-e with etype, -t with timestamp");
System.out.println("-a ()add an entry " +
"to the keytab");
- System.out.println("-d \t\tdelete an entry from "+
- "the keytab");
+ System.out.println("-d []\tdelete an "+
+ "entry from the keytab");
System.out.println("-k \t\tspecify keytab name and "+
- " path with prefix FILE:");
+ "path with prefix FILE:");
}
}