diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libtdeldap.cpp | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/src/libtdeldap.cpp b/src/libtdeldap.cpp index 86bd60e..1bb51e0 100644 --- a/src/libtdeldap.cpp +++ b/src/libtdeldap.cpp @@ -834,10 +834,12 @@ int LDAPManager::updateUserInfo(LDAPUserInfo user) { TQString readFullLineFromPtyProcess(PtyProcess* proc) { TQString result = ""; - while ((!result.contains("\n")) && (!result.contains(":")) && (!result.contains(">"))) { + while ((!result.contains("\r")) && (!result.contains(":")) && (!result.contains(">"))) { result = result + TQString(proc->readLine(false)); tqApp->processEvents(); } + result.replace("\n", ""); + result.replace("\r", ""); return result; } @@ -873,22 +875,29 @@ int LDAPManager::setPasswordForUser(LDAPUserInfo user, TQString *errstr) { TQString prompt; PtyProcess kadminProc; kadminProc.exec(command, args); - prompt = kadminProc.readLine(true); + prompt = readFullLineFromPtyProcess(&kadminProc); prompt = prompt.stripWhiteSpace(); if (prompt == "kadmin>") { - kadminProc.writeLine(TQCString("passwd "+user.name), true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = readFullLineFromPtyProcess(&kadminProc); + command = TQCString("passwd "+user.name); + 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:")) && (prompt.startsWith(TQString(user.name + "@")))) { kadminProc.writeLine(user.new_password, true); - prompt = kadminProc.readLine(true); // Discard our own input - prompt = kadminProc.readLine(true); - prompt = prompt.stripWhiteSpace(); + do { // Discard our own input + prompt = readFullLineFromPtyProcess(&kadminProc); + printf("(kadmin) '%s'\n\r", prompt.ascii()); + } while (prompt == ""); + prompt = prompt.stripWhiteSpace(); if ((prompt.endsWith(" Password:")) && (prompt.startsWith("Verify"))) { kadminProc.writeLine(user.new_password, 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.endsWith(" Password:")) { @@ -901,8 +910,10 @@ int LDAPManager::setPasswordForUser(LDAPUserInfo user, TQString *errstr) { } if (admincreds.password != "") { kadminProc.writeLine(admincreds.password, 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(); } } @@ -1205,12 +1216,14 @@ int LDAPManager::obtainKerberosTicket(LDAPCredentials creds, TQString principal, TQString prompt; PtyProcess kadminProc; kadminProc.exec(command, args); - prompt = kadminProc.readLine(true); + prompt = readFullLineFromPtyProcess(&kadminProc); prompt = prompt.stripWhiteSpace(); if (prompt.endsWith(" Password:")) { kadminProc.writeLine(creds.password, 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 != "") { @@ -1504,12 +1517,15 @@ int LDAPManager::addServiceInfo(LDAPServiceInfo service, TQString *errstr) { TQString prompt; PtyProcess kadminProc; kadminProc.exec(command, args); - prompt = kadminProc.readLine(true); + prompt = readFullLineFromPtyProcess(&kadminProc); prompt = prompt.stripWhiteSpace(); if (prompt == "kadmin>") { - 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>") { @@ -1523,8 +1539,10 @@ int LDAPManager::addServiceInfo(LDAPServiceInfo service, TQString *errstr) { } if (admincreds.password != "") { kadminProc.writeLine(admincreds.password, 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(); } } @@ -1542,9 +1560,12 @@ int LDAPManager::addServiceInfo(LDAPServiceInfo service, TQString *errstr) { 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(); } } |