From 3d34730e2167f92131bafd4ea8e30c0183f16788 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 8 Jul 2012 23:48:26 -0500 Subject: [PATCH] Update to use more robust kadmin communication --- src/ldapbonding.cpp | 67 +++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/ldapbonding.cpp b/src/ldapbonding.cpp index b9ed7eb..f523f88 100644 --- a/src/ldapbonding.cpp +++ b/src/ldapbonding.cpp @@ -409,17 +409,22 @@ int LDAPConfig::bondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, cons TQString prompt; PtyProcess kadminProc; kadminProc.exec(command, args); - prompt = kadminProc.readLine(true); + prompt = readFullLineFromPtyProcess(&kadminProc); prompt = prompt.stripWhiteSpace(); if (prompt == "kadmin>") { - kadminProc.writeLine(TQCString("ext "+hoststring), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = readFullLineFromPtyProcess(&kadminProc); + command = TQCString("ext "+hoststring); + kadminProc.writeLine(command, true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == TQString(command)); prompt = prompt.stripWhiteSpace(); if (prompt.endsWith(" Password:")) { kadminProc.writeLine(adminPassword, true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = kadminProc.readLine(true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == ""); prompt = prompt.stripWhiteSpace(); } if (prompt.contains("authentication failed")) { @@ -428,16 +433,21 @@ int LDAPConfig::bondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, cons return 1; } else if (prompt.endsWith("Principal does not exist")) { - kadminProc.writeLine(TQCString("ank --random-key "+hoststring), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = readFullLineFromPtyProcess(&kadminProc); + command = TQCString("ank --random-key "+hoststring); + kadminProc.writeLine(command, true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == TQString(command)); prompt = prompt.stripWhiteSpace(); // Use all defaults while (prompt != "kadmin>") { if (prompt.endsWith(" Password:")) { kadminProc.writeLine(adminPassword, true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = kadminProc.readLine(true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == ""); prompt = prompt.stripWhiteSpace(); } if (prompt.contains("authentication failed")) { @@ -454,15 +464,21 @@ int LDAPConfig::bondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, cons leftbracket++; defaultParam = prompt.mid(leftbracket, rightbracket-leftbracket); } - kadminProc.writeLine(TQCString(defaultParam), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = kadminProc.readLine(true); + command = TQCString(defaultParam); + kadminProc.writeLine(command, true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == TQString(command)); prompt = prompt.stripWhiteSpace(); } } - kadminProc.writeLine(TQCString("ext "+hoststring), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = readFullLineFromPtyProcess(&kadminProc); + command = TQCString("ext "+hoststring); + kadminProc.writeLine(command, true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == TQString(command)); prompt = prompt.stripWhiteSpace(); if (prompt != "kadmin>") { if (errstr) *errstr = prompt; @@ -500,17 +516,22 @@ int LDAPConfig::unbondRealm(LDAPRealmConfig realmcfg, TQString adminUserName, co TQString prompt; PtyProcess kadminProc; kadminProc.exec(command, args); - prompt = kadminProc.readLine(true); + prompt = readFullLineFromPtyProcess(&kadminProc); prompt = prompt.stripWhiteSpace(); if (prompt == "kadmin>") { - kadminProc.writeLine(TQCString("delete "+hoststring), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = readFullLineFromPtyProcess(&kadminProc); + command = TQCString("delete "+hoststring); + kadminProc.writeLine(command, true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == TQString(command)); prompt = prompt.stripWhiteSpace(); if (prompt.endsWith(" Password:")) { kadminProc.writeLine(adminPassword, true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = kadminProc.readLine(true); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == ""); prompt = prompt.stripWhiteSpace(); } if (prompt != "kadmin>") {