Remove additional unneeded tq method conversions

pull/2/head
Timothy Pearson 13 years ago
parent f37be37207
commit afe3f974bb

@ -121,7 +121,7 @@ int writefile(const char * filename, TQString contents) {
TQString exec(const char * cmd) { TQString exec(const char * cmd) {
TQString bashcommand = cmd; TQString bashcommand = cmd;
bashcommand = bashcommand.replace("\"", "\\\""); bashcommand = bashcommand.replace("\"", "\\\"");
bashcommand = TQString("/bin/bash -c \"%1\"").tqarg(bashcommand); bashcommand = TQString("/bin/bash -c \"%1\"").arg(bashcommand);
FILE* pipe = popen(bashcommand.ascii(), "r"); FILE* pipe = popen(bashcommand.ascii(), "r");
if (!pipe) return "ERROR"; if (!pipe) return "ERROR";
char buffer[128]; char buffer[128];
@ -139,14 +139,14 @@ TQString exec(const char * cmd) {
int systemexec(const char * cmd) { int systemexec(const char * cmd) {
TQString bashcommand = cmd; TQString bashcommand = cmd;
bashcommand = bashcommand.replace("\"", "\\\""); bashcommand = bashcommand.replace("\"", "\\\"");
bashcommand = TQString("/bin/bash -c \"%1\"").tqarg(bashcommand); bashcommand = TQString("/bin/bash -c \"%1\"").arg(bashcommand);
return system(bashcommand.ascii()) >> 8; return system(bashcommand.ascii()) >> 8;
} }
TQString execret(const char * cmd, int * retcode) { TQString execret(const char * cmd, int * retcode) {
TQString bashcommand = cmd; TQString bashcommand = cmd;
bashcommand = bashcommand.replace("\"", "\\\""); bashcommand = bashcommand.replace("\"", "\\\"");
bashcommand = TQString("/bin/bash -c \"%1\"").tqarg(bashcommand); bashcommand = TQString("/bin/bash -c \"%1\"").arg(bashcommand);
FILE* pipe = popen(bashcommand.ascii(), "r"); FILE* pipe = popen(bashcommand.ascii(), "r");
if (!pipe) return "ERROR"; if (!pipe) return "ERROR";
char buffer[128]; char buffer[128];
@ -179,45 +179,45 @@ int rmrf(const char *path)
TQString get_file(TQString prefix, TQString mode) { TQString get_file(TQString prefix, TQString mode) {
if (command_mode == "acos") { if (command_mode == "acos") {
// Select EF prefix under DF 1000 // Select EF prefix under DF 1000
systemexec((TQString("echo \"%1 %2\" > %3/query").tqarg(select_file).tqarg(prefix).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"%1 %2\" > %3/query").arg(select_file).arg(prefix).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
// printf("[DEBUG 100.0] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); // printf("[DEBUG 100.0] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
// Read binary // Read binary
systemexec((TQString("echo \"%1\" > %2/query").tqarg(read_binary).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"%1\" > %2/query").arg(read_binary).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
TQString authokresponse="90 00 : Normal processing"; TQString authokresponse="90 00 : Normal processing";
TQString response1 = exec((TQString("cat %1/response2 | grep \"%2\"").tqarg(secure_directory).tqarg(authokresponse)).ascii()); TQString response1 = exec((TQString("cat %1/response2 | grep \"%2\"").arg(secure_directory).arg(authokresponse)).ascii());
if (response1 != "") { if (response1 != "") {
systemexec((TQString("cat %1/response2 | tr -d '\n' > %2/response4").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("cat %1/response2 | tr -d '\n' > %2/response4").arg(secure_directory).arg(secure_directory)).ascii());
TQString stringtoreplace="Using T=0 protocol00 B0 00 00 FF> 00 B0 00 00 FF< "; TQString stringtoreplace="Using T=0 protocol00 B0 00 00 FF> 00 B0 00 00 FF< ";
TQString newstring=""; TQString newstring="";
systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").tqarg(stringtoreplace).tqarg(newstring).tqarg(secure_directory)).ascii()); systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").arg(stringtoreplace).arg(newstring).arg(secure_directory)).ascii());
stringtoreplace=" 90 00 : Normal processing."; stringtoreplace=" 90 00 : Normal processing.";
newstring=""; newstring="";
systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").tqarg(stringtoreplace).tqarg(newstring).tqarg(secure_directory)).ascii()); systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").arg(stringtoreplace).arg(newstring).arg(secure_directory)).ascii());
if (mode == "text") { if (mode == "text") {
stringtoreplace=" 00"; stringtoreplace=" 00";
newstring=""; newstring="";
systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").tqarg(stringtoreplace).tqarg(newstring).tqarg(secure_directory)).ascii()); systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").arg(stringtoreplace).arg(newstring).arg(secure_directory)).ascii());
} }
// printf("[DEBUG 100.1] %s\n\r", readfile((TQString("%1/response4").tqarg(secure_directory))).ascii()); fflush(stdout); // printf("[DEBUG 100.1] %s\n\r", readfile((TQString("%1/response4").arg(secure_directory))).ascii()); fflush(stdout);
unlink((TQString("%1/lukskey").tqarg(secure_directory)).ascii()); unlink((TQString("%1/lukskey").arg(secure_directory)).ascii());
systemexec((TQString("xxd -r -p %1/response4 %2/lukskey").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("xxd -r -p %1/response4 %2/lukskey").arg(secure_directory).arg(secure_directory)).ascii());
return(TQString("%1/lukskey").tqarg(secure_directory)); return(TQString("%1/lukskey").arg(secure_directory));
} }
} }
if (command_mode == "cryptoflex") { if (command_mode == "cryptoflex") {
TQString file = TQString(prefix).replace(' ', ""); TQString file = TQString(prefix).replace(' ', "");
unlink((TQString("3F00_%1").tqarg(file)).ascii()); unlink((TQString("3F00_%1").arg(file)).ascii());
// systemexec((TQString("echo \"get %1\" | opensc-explorer").tqarg(file)).ascii()); // systemexec((TQString("echo \"get %1\" | opensc-explorer").arg(file)).ascii());
fputs((TQString("get %1\n").tqarg(file)).ascii(), opensc_explorer_file); fputs((TQString("get %1\n").arg(file)).ascii(), opensc_explorer_file);
fflush(opensc_explorer_file); fflush(opensc_explorer_file);
int j; int j;
// Wait up to 2 seconds for the file to be written // Wait up to 2 seconds for the file to be written
for (j=0;j<200;j++) { for (j=0;j<200;j++) {
FILE* fp1 = fopen((TQString("3F00_%1").tqarg(file)).ascii(), "r"); FILE* fp1 = fopen((TQString("3F00_%1").arg(file)).ascii(), "r");
if (fp1) { if (fp1) {
// file exists // file exists
fclose(fp1); fclose(fp1);
@ -226,7 +226,7 @@ TQString get_file(TQString prefix, TQString mode) {
usleep(10000); usleep(10000);
} }
usleep(100000); // [FIXME] Here I assume that the entire file will be written (after it was created) within 100us. This may not be correct in all cases! usleep(100000); // [FIXME] Here I assume that the entire file will be written (after it was created) within 100us. This may not be correct in all cases!
return TQString("3F00_%1").tqarg(file); return TQString("3F00_%1").arg(file);
} }
} }
@ -235,8 +235,8 @@ void createfile(TQString prefix, TQString mode)
if (command_mode == "cryptoflex") { if (command_mode == "cryptoflex") {
// Create transparent file with permissions: // Create transparent file with permissions:
// delete, terminate, activate, deactivate, update, read for Key 1 and Key 2 only // delete, terminate, activate, deactivate, update, read for Key 1 and Key 2 only
systemexec((TQString("echo \"F0 E0 00 FF 10 FF FF 00 %1 %2 01 3F 44 FF 44 01 03 11 FF 11\" > %3/query").tqarg(prefix).tqarg(mode).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"F0 E0 00 FF 10 FF FF 00 %1 %2 01 3F 44 FF 44 01 03 11 FF 11\" > %3/query").arg(prefix).arg(mode).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
} }
if (command_mode == "acos") { if (command_mode == "acos") {
@ -245,43 +245,43 @@ void createfile(TQString prefix, TQString mode)
// created in DF 1000 under MF, SE file is 10FE // created in DF 1000 under MF, SE file is 10FE
// SIZE TRANSPARENT // SIZE TRANSPARENT
systemexec((TQString("echo \"00 E0 00 00 1A 62 18 80 02 00 %1 82 01 01 83 02 %2 8A 01 %3 8C 08 7F 04 04 04 04 04 04 04\" > %4/query").tqarg(prefix).tqarg(mode).tqarg(CREATE_LIFE_CYCLE).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"00 E0 00 00 1A 62 18 80 02 00 %1 82 01 01 83 02 %2 8A 01 %3 8C 08 7F 04 04 04 04 04 04 04\" > %4/query").arg(prefix).arg(mode).arg(CREATE_LIFE_CYCLE).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").arg(secure_directory)).ascii());
printf("[DEBUG 300.0] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 300.0] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
} }
} }
void update_file(TQString prefix, TQString mode) { void update_file(TQString prefix, TQString mode) {
if (command_mode == "acos") { if (command_mode == "acos") {
// Select EF prefix under DF 1000 // Select EF prefix under DF 1000
systemexec((TQString("echo \"$SELECT_FILE %1\" > %2/query").tqarg(prefix).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"$SELECT_FILE %1\" > %2/query").arg(prefix).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
printf("[DEBUG 200.0] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 200.0] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
// Update existing file // Update existing file
// Zero pad input file // Zero pad input file
systemexec((TQString("dd if=/dev/zero of=%1/response2 bs=1 count=255 2>/dev/null 1>/dev/null").tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=/dev/zero of=%1/response2 bs=1 count=255 2>/dev/null 1>/dev/null").arg(secure_directory)).ascii());
systemexec((TQString("dd if=%1 of=%2/response2 bs=1 count=255 conv=notrunc 2>/dev/null 1>/dev/null").tqarg(mode).tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=%1 of=%2/response2 bs=1 count=255 conv=notrunc 2>/dev/null 1>/dev/null").arg(mode).arg(secure_directory)).ascii());
// Truncate to 255 bytes and expand to standard hex listing format // Truncate to 255 bytes and expand to standard hex listing format
systemexec((TQString("xxd -l 255 -ps -c 1 %1/response2 > %2/response").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("xxd -l 255 -ps -c 1 %1/response2 > %2/response").arg(secure_directory).arg(secure_directory)).ascii());
systemexec((TQString("cat %1/response | tr '\n' ' ' > %1/hexready").tqarg(secure_directory)).ascii()); systemexec((TQString("cat %1/response | tr '\n' ' ' > %1/hexready").arg(secure_directory)).ascii());
TQString hexready = readfile((TQString("%1/hexready").tqarg(secure_directory)).ascii()); TQString hexready = readfile((TQString("%1/hexready").arg(secure_directory)).ascii());
systemexec((TQString("echo \"%1 %2\" > %3/query").tqarg(update_binary).tqarg(hexready).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"%1 %2\" > %3/query").arg(update_binary).arg(hexready).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
printf("[DEBUG 200.1] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 200.1] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
} }
if (command_mode == "cryptoflex") { if (command_mode == "cryptoflex") {
// Delete old file // Delete old file
systemexec((TQString("echo \"%1 $1\" > %2/query").tqarg(delete_file).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"%1 $1\" > %2/query").arg(delete_file).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2 2>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
printf("[DEBUG 200.2] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 200.2] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
// Create new file // Create new file
createfile("FF", prefix); createfile("FF", prefix);
TQString file = TQString(prefix).replace(' ', ""); TQString file = TQString(prefix).replace(' ', "");
systemexec((TQString("echo \"put %1 %2\" | opensc-explorer").tqarg(file).tqarg(mode)).ascii()); systemexec((TQString("echo \"put %1 %2\" | opensc-explorer").arg(file).arg(mode)).ascii());
} }
} }
@ -365,16 +365,16 @@ int main (int argc, char *argv[])
systemexec("echo \"TAuthenticating SmartCard...\" > /tmp/ksocket-global/kdesktoplockcontrol &"); systemexec("echo \"TAuthenticating SmartCard...\" > /tmp/ksocket-global/kdesktoplockcontrol &");
// Get card ATR // Get card ATR
systemexec((TQString("echo \"RESET\" > %1/query").tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"RESET\" > %1/query").arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
TQString authokresponse="OK: "; TQString authokresponse="OK: ";
TQString response1 = exec((TQString("cat %1/response2 | grep \"%2\"").tqarg(secure_directory).tqarg(authokresponse)).ascii()); TQString response1 = exec((TQString("cat %1/response2 | grep \"%2\"").arg(secure_directory).arg(authokresponse)).ascii());
if (response1 != "") { if (response1 != "") {
systemexec((TQString("cat %1/response2 | tr -d '\n' > %2/response4").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("cat %1/response2 | tr -d '\n' > %2/response4").arg(secure_directory).arg(secure_directory)).ascii());
TQString stringtoreplace="Using T=0 protocolRESET> RESET< OK: "; TQString stringtoreplace="Using T=0 protocolRESET> RESET< OK: ";
TQString newstring=""; TQString newstring="";
systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").tqarg(stringtoreplace).tqarg(newstring).tqarg(secure_directory)).ascii()); systemexec((TQString("sed -i \"s#%1#%2#g\" %3/response4").arg(stringtoreplace).arg(newstring).arg(secure_directory)).ascii());
TQString smartatr = readfile((TQString("%1/response4").tqarg(secure_directory)).ascii()); TQString smartatr = readfile((TQString("%1/response4").arg(secure_directory)).ascii());
printf("[DEBUG 400.2] Got ATR: %s\n\r", smartatr.ascii()); fflush(stdout); printf("[DEBUG 400.2] Got ATR: %s\n\r", smartatr.ascii()); fflush(stdout);
if (smartatr == "3B BE 18 00 00 41 05 10 00 00 00 00 00 00 00 00 00 90 00 ") { if (smartatr == "3B BE 18 00 00 41 05 10 00 00 00 00 00 00 00 00 00 90 00 ") {
printf("[DEBUG 400.3] Detected ACOS5 card\n\r"); fflush(stdout); printf("[DEBUG 400.3] Detected ACOS5 card\n\r"); fflush(stdout);
@ -410,59 +410,59 @@ int main (int argc, char *argv[])
if (command_mode == "acos") { if (command_mode == "acos") {
// Select MF // Select MF
systemexec((TQString("echo \"00 A4 00 00 00\" > %1/query").tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"00 A4 00 00 00\" > %1/query").arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
printf("[DEBUG 400.4] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 400.4] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
// Select DF 1000 under MF // Select DF 1000 under MF
systemexec((TQString("echo \"%1 10 00\" > %2/query").tqarg(select_file).tqarg(secure_directory)).ascii()); systemexec((TQString("echo \"%1 10 00\" > %2/query").arg(select_file).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/query 1> %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/query 1> %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
printf("[DEBUG 400.5] %s\n\r", readfile((TQString("%1/response2").tqarg(secure_directory))).ascii()); fflush(stdout); printf("[DEBUG 400.5] %s\n\r", readfile((TQString("%1/response2").arg(secure_directory))).ascii()); fflush(stdout);
} }
systemexec((TQString("echo %1 > %2/authscript").tqarg(get_challenge).tqarg(secure_directory)).ascii()); systemexec((TQString("echo %1 > %2/authscript").arg(get_challenge).arg(secure_directory)).ascii());
systemexec((TQString("scriptor %1/authscript | grep 'Normal processing' > %2/challenge").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/authscript | grep 'Normal processing' > %2/challenge").arg(secure_directory).arg(secure_directory)).ascii());
systemexec((TQString("perl -pi -e 's/ //g' %1/challenge").tqarg(secure_directory)).ascii()); systemexec((TQString("perl -pi -e 's/ //g' %1/challenge").arg(secure_directory)).ascii());
systemexec((TQString("perl -pi -e 's/:Normalprocessing.//g' %1/challenge").tqarg(secure_directory)).ascii()); systemexec((TQString("perl -pi -e 's/:Normalprocessing.//g' %1/challenge").arg(secure_directory)).ascii());
systemexec((TQString("perl -pi -e 's/<//g' %1/challenge").tqarg(secure_directory)).ascii()); systemexec((TQString("perl -pi -e 's/<//g' %1/challenge").arg(secure_directory)).ascii());
systemexec((TQString("xxd -r -p %1/challenge %2/challenge").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("xxd -r -p %1/challenge %2/challenge").arg(secure_directory).arg(secure_directory)).ascii());
// Now DES encrypt the challenge // Now DES encrypt the challenge
// Later, change the initialization vector to random if possible // Later, change the initialization vector to random if possible
// Create the response from the challenge // Create the response from the challenge
systemexec((TQString("openssl des-ecb -in %1/challenge -out %2/response -K %3 -iv 1").tqarg(secure_directory).tqarg(secure_directory).tqarg(hexidecimal_key)).ascii()); systemexec((TQString("openssl des-ecb -in %1/challenge -out %2/response -K %3 -iv 1").arg(secure_directory).arg(secure_directory).arg(hexidecimal_key)).ascii());
if (command_mode == "acos") { if (command_mode == "acos") {
// Truncate to 8 bytes // Truncate to 8 bytes
systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=8 2>/dev/null 1>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=8 2>/dev/null 1>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
// Expand to standard hex listing format // Expand to standard hex listing format
systemexec((TQString("xxd -g 1 %1/response2 %2/response").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("xxd -g 1 %1/response2 %2/response").arg(secure_directory).arg(secure_directory)).ascii());
systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=23 skip=9 2>/dev/null 1>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=23 skip=9 2>/dev/null 1>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
} }
if (command_mode == "cryptoflex") { if (command_mode == "cryptoflex") {
// Truncate to 6 bytes // Truncate to 6 bytes
systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=6 2>/dev/null 1>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=6 2>/dev/null 1>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
// Expand to standard hex listing format // Expand to standard hex listing format
systemexec((TQString("xxd -g 1 %1/response2 %2/response").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("xxd -g 1 %1/response2 %2/response").arg(secure_directory).arg(secure_directory)).ascii());
systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=17 skip=9 2>/dev/null 1>/dev/null").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("dd if=%1/response of=%2/response2 bs=1 count=17 skip=9 2>/dev/null 1>/dev/null").arg(secure_directory).arg(secure_directory)).ascii());
} }
// Assemble the response file // Assemble the response file
TQString response2 = readfile((TQString("%1/response2").tqarg(secure_directory)).ascii()); TQString response2 = readfile((TQString("%1/response2").arg(secure_directory)).ascii());
response1 = TQString("%1 %2").tqarg(external_auth).tqarg(response2); response1 = TQString("%1 %2").arg(external_auth).arg(response2);
systemexec((TQString("echo %1 > %2/response").tqarg(response1).tqarg(secure_directory)).ascii()); systemexec((TQString("echo %1 > %2/response").arg(response1).arg(secure_directory)).ascii());
// Send the response! // Send the response!
systemexec((TQString("scriptor %1/response > %2/response2").tqarg(secure_directory).tqarg(secure_directory)).ascii()); systemexec((TQString("scriptor %1/response > %2/response2").arg(secure_directory).arg(secure_directory)).ascii());
// Get the result // Get the result
authokresponse = "< 90 00 : Normal processing"; authokresponse = "< 90 00 : Normal processing";
response1 = exec((TQString("cat %1/response2 | grep \"%2\"").tqarg(secure_directory).tqarg(authokresponse)).ascii()); response1 = exec((TQString("cat %1/response2 | grep \"%2\"").arg(secure_directory).arg(authokresponse)).ascii());
printf("[DEBUG 400.6] %s\n\r", response1.ascii()); fflush(stdout); printf("[DEBUG 400.6] %s\n\r", response1.ascii()); fflush(stdout);
if (response1 != "") { if (response1 != "") {
printf("[DEBUG 400.7] Smart card validation successfull!\n\r"); fflush(stdout); printf("[DEBUG 400.7] Smart card validation successfull!\n\r"); fflush(stdout);
@ -497,7 +497,7 @@ int main (int argc, char *argv[])
systemexec("echo \"EInvalid SmartCard Inserted\" > /tmp/ksocket-global/kdesktoplockcontrol &"); systemexec("echo \"EInvalid SmartCard Inserted\" > /tmp/ksocket-global/kdesktoplockcontrol &");
sleep(1); sleep(1);
smartcard_username=""; smartcard_username="";
unlink((TQString("%1/password").tqarg(secure_directory)).ascii()); unlink((TQString("%1/password").arg(secure_directory)).ascii());
smartcard_slave=""; smartcard_slave="";
} }
@ -512,19 +512,19 @@ int main (int argc, char *argv[])
// Decrement minutes on card // Decrement minutes on card
if (smartcard_minutes > 0) { if (smartcard_minutes > 0) {
smartcard_minutes=smartcard_minutes-1; smartcard_minutes=smartcard_minutes-1;
systemexec((TQString("echo %1 > %2/minutes").tqarg(smartcard_minutes).tqarg(secure_directory)).ascii()); systemexec((TQString("echo %1 > %2/minutes").arg(smartcard_minutes).arg(secure_directory)).ascii());
update_file("10 05", TQString("%1/minutes").tqarg(secure_directory)); update_file("10 05", TQString("%1/minutes").arg(secure_directory));
} }
if (smartcard_minutes == 0) { if (smartcard_minutes == 0) {
printf("[DEBUG 400.8] Minutes have been used up!\n\r"); fflush(stdout); printf("[DEBUG 400.8] Minutes have been used up!\n\r"); fflush(stdout);
// Prohibit logon // Prohibit logon
smartcard_username=""; smartcard_username="";
unlink((TQString("%1/password").tqarg(secure_directory)).ascii()); unlink((TQString("%1/password").arg(secure_directory)).ascii());
} }
mkdir("/etc/smartmon", 644); mkdir("/etc/smartmon", 644);
systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").tqarg(smartcard_minutes)).ascii()); systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").arg(smartcard_minutes)).ascii());
chmod("/etc/smartmon/minutesremaining", 755); chmod("/etc/smartmon/minutesremaining", 755);
} }
@ -577,12 +577,12 @@ int main (int argc, char *argv[])
if (darray[index] != "") { if (darray[index] != "") {
printf("[DEBUG 400.a] Found existing session on desktop: %d\n\r", index); fflush(stdout); printf("[DEBUG 400.a] Found existing session on desktop: %d\n\r", index); fflush(stdout);
foundsession=1; foundsession=1;
udisplay = TQString(":%1").tqarg(index); udisplay = TQString(":%1").arg(index);
// Check password // Check password
if (check_password(smartcard_username.ascii(), smartcard_password.ascii()) == 0) { if (check_password(smartcard_username.ascii(), smartcard_password.ascii()) == 0) {
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface quit\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface quit\"").arg(smartcard_username).arg(udisplay)).ascii());
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable false\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable false\"").arg(smartcard_username).arg(udisplay)).ascii());
systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl activate %1").tqarg(udisplay)).ascii()); systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl activate %1").arg(udisplay)).ascii());
} }
else { else {
systemexec("echo \"EUnauthorized SmartCard Inserted\" > /tmp/ksocket-global/kdesktoplockcontrol &"); systemexec("echo \"EUnauthorized SmartCard Inserted\" > /tmp/ksocket-global/kdesktoplockcontrol &");
@ -622,7 +622,7 @@ int main (int argc, char *argv[])
TQString tempdisplaystr; TQString tempdisplaystr;
tempdisplaystr = fi->fileName(); tempdisplaystr = fi->fileName();
printf( "%s\n", fi->fileName().latin1() ); fflush(stdout); printf( "%s\n", fi->fileName().latin1() ); fflush(stdout);
if (fi->fileName().tqcontains("kdmctl-sak-")) { if (fi->fileName().contains("kdmctl-sak-")) {
tempdisplaystr = tempdisplaystr.replace("kdmctl-sak-", ""); tempdisplaystr = tempdisplaystr.replace("kdmctl-sak-", "");
tempdisplayint = tempdisplaystr.toInt(&isint); tempdisplayint = tempdisplaystr.toInt(&isint);
if (isint) { if (isint) {
@ -632,7 +632,7 @@ int main (int argc, char *argv[])
} }
} }
} }
else if (fi->fileName().tqcontains("kdmctl-")) { else if (fi->fileName().contains("kdmctl-")) {
tempdisplaystr = tempdisplaystr.replace("kdmctl-", ""); tempdisplaystr = tempdisplaystr.replace("kdmctl-", "");
tempdisplayint = tempdisplaystr.toInt(&isint); tempdisplayint = tempdisplaystr.toInt(&isint);
if (isint) { if (isint) {
@ -645,10 +645,10 @@ int main (int argc, char *argv[])
++it; ++it;
} }
if (display_has_sak) { if (display_has_sak) {
if (writefile(TQString(KDM_CONTROL_FIFO_SAK_FILE).tqarg(newdisplayint), "CLOSE\n") < 0) { if (writefile(TQString(KDM_CONTROL_FIFO_SAK_FILE).arg(newdisplayint), "CLOSE\n") < 0) {
// Uh oh, something failed... // Uh oh, something failed...
printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_SAK_FILE).tqarg(newdisplayint)).ascii()); fflush(stdout); printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_SAK_FILE).arg(newdisplayint)).ascii()); fflush(stdout);
unlink((TQString(KDM_CONTROL_FIFO_SAK_FILE).tqarg(newdisplayint)).ascii()); unlink((TQString(KDM_CONTROL_FIFO_SAK_FILE).arg(newdisplayint)).ascii());
writeerror = true; writeerror = true;
} }
else { else {
@ -656,7 +656,7 @@ int main (int argc, char *argv[])
int status = -1; int status = -1;
int timeout_counter = 0; int timeout_counter = 0;
while ((status != 0) && (timeout_counter < 30)) { while ((status != 0) && (timeout_counter < 30)) {
status = stat((TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint)).ascii(), &buffer); status = stat((TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint)).ascii(), &buffer);
timeout_counter++; timeout_counter++;
usleep(100000); usleep(100000);
} }
@ -664,10 +664,10 @@ int main (int argc, char *argv[])
} }
else { else {
// Make sure the control socket is writable // Make sure the control socket is writable
if (writefile(TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint), "PING\n") < 0) { if (writefile(TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint), "PING\n") < 0) {
// Uh oh, something failed... // Uh oh, something failed...
printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint)).ascii()); fflush(stdout); printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint)).ascii()); fflush(stdout);
unlink((TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint)).ascii()); unlink((TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint)).ascii());
writeerror = true; writeerror = true;
} }
} }
@ -689,27 +689,27 @@ int main (int argc, char *argv[])
} }
} }
newdisplay = TQString(":%1").tqarg(newdisplayint); newdisplay = TQString(":%1").arg(newdisplayint);
printf("[DEBUG 400.f] Logging in on display %s\n\r", newdisplay.ascii()); fflush(stdout); printf("[DEBUG 400.f] Logging in on display %s\n\r", newdisplay.ascii()); fflush(stdout);
// Construct login string // Construct login string
TQString logincommand = TQString("LOGIN\t%1\t%2\n").tqarg(smartcard_username).tqarg(smartcard_password); TQString logincommand = TQString("LOGIN\t%1\t%2\n").arg(smartcard_username).arg(smartcard_password);
if (writefile(TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint), logincommand) < 0) { if (writefile(TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint), logincommand) < 0) {
// Uh oh, something failed... // Uh oh, something failed...
printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_FILE).tqarg(newdisplayint)).ascii()); fflush(stdout); printf("Unable to write to KDM control socket %s\n\r", (TQString(KDM_CONTROL_FIFO_FILE).arg(newdisplayint)).ascii()); fflush(stdout);
} }
systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl -g activate %1").tqarg(newdisplay)).ascii()); systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl -g activate %1").arg(newdisplay)).ascii());
udisplay=newdisplay; udisplay=newdisplay;
} }
if (smartcard_slave == "SLAVE") { if (smartcard_slave == "SLAVE") {
if (smartcard_minutes < 5) { if (smartcard_minutes < 5) {
systemexec((TQString("su %1 -c \"export DISPLAY=%2; zenity --warning --text 'You have less than 5 minutes of computer time remaining' || exit 0\" &").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; zenity --warning --text 'You have less than 5 minutes of computer time remaining' || exit 0\" &").arg(smartcard_username).arg(udisplay)).ascii());
} }
} }
unlink((TQString("%1/password").tqarg(secure_directory)).ascii()); unlink((TQString("%1/password").arg(secure_directory)).ascii());
// if (loginok == 1) { // if (loginok == 1) {
// Wait for SmartCard removal // Wait for SmartCard removal
@ -719,35 +719,35 @@ int main (int argc, char *argv[])
while (output == 0) { while (output == 0) {
sleep(1); sleep(1);
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface quit\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface quit\"").arg(smartcard_username).arg(udisplay)).ascii());
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable false\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable false\"").arg(smartcard_username).arg(udisplay)).ascii());
output = systemexec("echo \"exit\" | scriptor 2>/dev/null 1>/dev/null"); output = systemexec("echo \"exit\" | scriptor 2>/dev/null 1>/dev/null");
if (smartcard_slave == "SLAVE") { if (smartcard_slave == "SLAVE") {
timer--; timer--;
if (timer == 0) { if (timer == 0) {
// 60 seconds have passed, decrement minutes on card // 60 seconds have passed, decrement minutes on card
smartcard_minutes--; smartcard_minutes--;
systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").tqarg(smartcard_minutes)).ascii()); systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").arg(smartcard_minutes)).ascii());
chmod("/etc/smartmon/minutesremaining", 755); chmod("/etc/smartmon/minutesremaining", 755);
timer=60; timer=60;
systemexec((TQString("echo %1 > %2/minutes").tqarg(smartcard_minutes).tqarg(secure_directory)).ascii()); systemexec((TQString("echo %1 > %2/minutes").arg(smartcard_minutes).arg(secure_directory)).ascii());
update_file("10 05", TQString("%1/minutes").tqarg(secure_directory)); update_file("10 05", TQString("%1/minutes").arg(secure_directory));
if (smartcard_minutes == 0) { if (smartcard_minutes == 0) {
printf("[DEBUG 401.0] Minutes have been used up!\n\r"); fflush(stdout); printf("[DEBUG 401.0] Minutes have been used up!\n\r"); fflush(stdout);
// Prohibit logon // Prohibit logon
smartcard_username=""; smartcard_username="";
unlink((TQString("%1/password").tqarg(secure_directory)).ascii()); unlink((TQString("%1/password").arg(secure_directory)).ascii());
} }
mkdir("/etc/smartmon", 644); mkdir("/etc/smartmon", 644);
systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").tqarg(smartcard_minutes)).ascii()); systemexec((TQString("echo %1 > /etc/smartmon/minutesremaining").arg(smartcard_minutes)).ascii());
chmod("/etc/smartmon/minutesremaining", 755); chmod("/etc/smartmon/minutesremaining", 755);
if (smartcard_minutes == 5) { if (smartcard_minutes == 5) {
systemexec((TQString("su %1 -c \"export DISPLAY=%2; zenity --warning --text 'You have less than 5 minutes of computer time remaining' || exit 0\" &").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; zenity --warning --text 'You have less than 5 minutes of computer time remaining' || exit 0\" &").arg(smartcard_username).arg(udisplay)).ascii());
} }
if (smartcard_minutes == 0) { if (smartcard_minutes == 0) {
@ -794,23 +794,23 @@ int main (int argc, char *argv[])
if (darray[index] == smartcard_username) { if (darray[index] == smartcard_username) {
if (darray[index] != "") { if (darray[index] != "") {
printf("[DEBUG 401.5] Found existing session on desktop: %d\n\r", index); fflush(stdout); printf("[DEBUG 401.5] Found existing session on desktop: %d\n\r", index); fflush(stdout);
udisplay = TQString(":%1").tqarg(index); udisplay = TQString(":%1").arg(index);
foundsession=1; foundsession=1;
errcode=1; errcode=1;
timeout=0; timeout=0;
blankresult=""; blankresult="";
while (blankresult != "true") { while (blankresult != "true") {
systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl -g activate %1").tqarg(udisplay)).ascii()); systemexec((TQString(TRINITY_BIN_PREFIX "kdmctl -g activate %1").arg(udisplay)).ascii());
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable true\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface enable true\"").arg(smartcard_username).arg(udisplay)).ascii());
systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface lock\"").tqarg(smartcard_username).tqarg(udisplay)).ascii()); systemexec((TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface lock\"").arg(smartcard_username).arg(udisplay)).ascii());
int retcode; int retcode;
blankresult = execret(TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface isBlanked\"").tqarg(smartcard_username).tqarg(udisplay).ascii(), &retcode); blankresult = execret(TQString("su %1 -c \"export DISPLAY=%2; " TRINITY_BIN_PREFIX "dcop kdesktop KScreensaverIface isBlanked\"").arg(smartcard_username).arg(udisplay).ascii(), &retcode);
if (retcode != 0) { if (retcode != 0) {
blankresult="true"; blankresult="true";
} }
blankresult = blankresult.replace('\n', ""); blankresult = blankresult.replace('\n', "");
logouttest = exec((TQString("echo %1 | grep 'target display has no VT assigned'").tqarg(blankresult)).ascii()); logouttest = exec((TQString("echo %1 | grep 'target display has no VT assigned'").arg(blankresult)).ascii());
if (logouttest != "") { if (logouttest != "") {
printf("[DEBUG 401.6] User has logged out\n\r"); fflush(stdout); printf("[DEBUG 401.6] User has logged out\n\r"); fflush(stdout);
blankresult="true"; blankresult="true";

Loading…
Cancel
Save