So heres what the program is supposed to do: Restrict applications from opening on a mac by typing restrict . It is supposed to allow access to the application by typing restrict again using the same name as before.
What the program is doing instead: Restricting the application is working fine. But when I type restrict again, it comes up with the following output:
CandyBar \277_\377CandyBar \277_\377Restricting application chmod: /Applications/CandyBar \277_\377.app: No such file or directory chown: /Applications/CandyBar \277_\377.app: No such file or directory chmod: /Applications/CandyBar \277_\377.app: No such file or directory As you can see it adds the characters \277_\377 at the end of the string. Here is my source code:
for (int i = 0; strlen(argument) + 14 >= i; i++) { argument[i] = '\0'; } cout << argument; getArguments(); argument[strlen(argument) - 1] = '\0'; cout << argument; string application(argument); cout << application; if (!restrictedApplication[application]) { restrictedApplication[application] = false; } if (restrictedApplication[application] == false) { cout << "Restricting application\n"; restrictedApplication[application] = true; string fullCommand = "chmod -x '/Applications/" + application + ".app';" + "chown root '/Applications/" + application + ".app';" + "chmod 000 '/Applications/" + application + ".app'"; char fullCommandChar[256]; for (int i = 0; fullCommand[i] != '\0'; i++) { fullCommandChar[i] = fullCommand[i]; } system(fullCommandChar); } else { cout << "Restoring application\n"; restrictedApplication[application] = false; string fullCommand = "chmod +x '/Applications/" + application + ".app';" + "chown jamespickering '/Applications/" + application + ".app';" + "chmod 777 '/Applications/" + application + ".app'"; char fullCommandChar[256]; for (int i = 0; fullCommand[i] != '\0'; i++) { fullCommandChar[i] = fullCommand[i]; } system(fullCommandChar); }
getArguments()do? How isargumentdeclared?