in kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java [39:91]
public void execute(String input) {
String[] commands = input.split(" ");
String principal = null;
String keytabFileLocation = null;
boolean glob = false;
//Since commands[0] is ktadd, the initial index is 1.
int index = 1;
while (index < commands.length) {
String command = commands[index];
if (command.equals("-k")) {
index++;
if (index >= commands.length) {
System.err.println(USAGE);
return;
}
keytabFileLocation = commands[index].trim();
} else if (command.equals("-glob")) {
glob = true;
} else if (!command.startsWith("-")) {
principal = command;
}
index++;
}
if (keytabFileLocation == null) {
keytabFileLocation = DEFAULT_KEYTAB_FILE_LOCATION;
}
File keytabFile = new File(keytabFileLocation);
if (principal == null) {
System.out.println((glob ? "princ-exp" : "principal") + " not specified!");
System.err.println(USAGE);
return;
}
try {
if (glob) {
List<String> principals = getKadmin().getPrincipals(principal);
if (principals.size() != 0) {
getKadmin().exportKeytab(keytabFile, principals);
}
} else {
getKadmin().exportKeytab(keytabFile, principal);
}
System.out.println("Export Keytab to " + keytabFileLocation);
} catch (KrbException e) {
System.err.println("Principal \"" + principal + "\" fail to add entry to keytab."
+ e.getMessage());
}
}