Make bonding and unbonding methods slightly more robust

pull/1/head
Timothy Pearson 11 years ago
parent 571e1739fb
commit 5bfd539b84

@ -4143,6 +4143,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
prompt = prompt.stripWhiteSpace(); prompt = prompt.stripWhiteSpace();
if (prompt == "kadmin>") { if (prompt == "kadmin>") {
command = TQCString("ext "+hoststring); command = TQCString("ext "+hoststring);
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(command, true); kadminProc.writeLine(command, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4150,6 +4151,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
} while ((prompt == TQString(command)) || (prompt == "")); } while ((prompt == TQString(command)) || (prompt == ""));
prompt = prompt.stripWhiteSpace(); prompt = prompt.stripWhiteSpace();
if (prompt.endsWith(" Password:")) { if (prompt.endsWith(" Password:")) {
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(adminPassword, true); kadminProc.writeLine(adminPassword, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4159,6 +4161,11 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
} }
if (prompt.contains("authentication failed")) { if (prompt.contains("authentication failed")) {
if (errstr) *errstr = prompt; if (errstr) *errstr = prompt;
do { // Wait for command prompt
prompt = readFullLineFromPtyProcess(&kadminProc);
printf("(kadmin) '%s'\n", prompt.ascii());
} while (prompt == "");
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 1; return 1;
} }
@ -4168,6 +4175,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
printf("(kadmin) '%s'\n", prompt.ascii()); printf("(kadmin) '%s'\n", prompt.ascii());
} while (prompt == ""); } while (prompt == "");
command = TQCString("ank --random-key "+hoststring); command = TQCString("ank --random-key "+hoststring);
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(command, true); kadminProc.writeLine(command, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4177,6 +4185,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
// Use all defaults // Use all defaults
while (prompt != "kadmin>") { while (prompt != "kadmin>") {
if (prompt.endsWith(" Password:")) { if (prompt.endsWith(" Password:")) {
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(adminPassword, true); kadminProc.writeLine(adminPassword, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4186,6 +4195,11 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
} }
if (prompt.contains("authentication failed")) { if (prompt.contains("authentication failed")) {
if (errstr) *errstr = prompt; if (errstr) *errstr = prompt;
do { // Wait for command prompt
prompt = readFullLineFromPtyProcess(&kadminProc);
printf("(kadmin) '%s'\n", prompt.ascii());
} while (prompt == "");
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 1; return 1;
} }
@ -4199,6 +4213,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
defaultParam = prompt.mid(leftbracket, rightbracket-leftbracket); defaultParam = prompt.mid(leftbracket, rightbracket-leftbracket);
} }
command = TQCString(defaultParam); command = TQCString(defaultParam);
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(command, true); kadminProc.writeLine(command, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4208,6 +4223,7 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
} }
} }
command = TQCString("ext "+hoststring); command = TQCString("ext "+hoststring);
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(command, true); kadminProc.writeLine(command, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4216,17 +4232,24 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
prompt = prompt.stripWhiteSpace(); prompt = prompt.stripWhiteSpace();
if (prompt != "kadmin>") { if (prompt != "kadmin>") {
if (errstr) *errstr = prompt; if (errstr) *errstr = prompt;
do { // Wait for command prompt
prompt = readFullLineFromPtyProcess(&kadminProc);
printf("(kadmin) '%s'\n", prompt.ascii());
} while (prompt == "");
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 1; return 1;
} }
// Success! // Success!
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 0; return 0;
} }
else if (prompt == "kadmin>") { else if (prompt == "kadmin>") {
// Success! // Success!
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 0; return 0;
@ -4234,6 +4257,11 @@ int LDAPManager::bondRealm(TQString adminUserName, const char * adminPassword, T
// Failure // Failure
if (errstr) *errstr = prompt; if (errstr) *errstr = prompt;
while (prompt == "") { // Wait for command prompt
prompt = readFullLineFromPtyProcess(&kadminProc);
printf("(kadmin) '%s'\n", prompt.ascii());
}
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 1; return 1;
} }
@ -4261,6 +4289,7 @@ int LDAPManager::unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, c
prompt = prompt.stripWhiteSpace(); prompt = prompt.stripWhiteSpace();
if (prompt == "kadmin>") { if (prompt == "kadmin>") {
command = TQCString("delete "+hoststring); command = TQCString("delete "+hoststring);
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(command, true); kadminProc.writeLine(command, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4268,6 +4297,7 @@ int LDAPManager::unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, c
} while ((prompt == TQString(command)) || (prompt == "")); } while ((prompt == TQString(command)) || (prompt == ""));
prompt = prompt.stripWhiteSpace(); prompt = prompt.stripWhiteSpace();
if (prompt.endsWith(" Password:")) { if (prompt.endsWith(" Password:")) {
kadminProc.enableLocalEcho(false);
kadminProc.writeLine(adminPassword, true); kadminProc.writeLine(adminPassword, true);
do { // Discard our own input do { // Discard our own input
prompt = readFullLineFromPtyProcess(&kadminProc); prompt = readFullLineFromPtyProcess(&kadminProc);
@ -4277,11 +4307,17 @@ int LDAPManager::unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, c
} }
if (prompt != "kadmin>") { if (prompt != "kadmin>") {
if (errstr) *errstr = prompt; if (errstr) *errstr = prompt;
do { // Wait for command prompt
prompt = readFullLineFromPtyProcess(&kadminProc);
printf("(kadmin) '%s'\n", prompt.ascii());
} while (prompt == "");
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
return 1; return 1;
} }
// Success! // Success!
kadminProc.enableLocalEcho(false);
kadminProc.writeLine("quit", true); kadminProc.writeLine("quit", true);
// Delete keys from keytab // Delete keys from keytab

Loading…
Cancel
Save