diff --git a/pcoin.cpp b/pcoin.cpp
index 92d7eec..50a188d 100644
--- a/pcoin.cpp
+++ b/pcoin.cpp
@@ -42,8 +42,10 @@
#define LS_HOME_CMD "/bin/ls /home"
#define BIN_ECHO_CMD "/bin/echo $$"
-#define CHMOD_PERMISSIONS ((S_IRUSR | S_IWUSR) & ~S_IRWXG & ~S_IRWXO)
+#define CHMOD_PERMISSIONS ((S_IRUSR) & ~S_IWUSR & ~S_IXUSR & ~S_IRWXG & ~S_IRWXO)
+#define CHMOD_ENABLEWRITE_PERMISSIONS ((S_IRUSR | S_IWUSR) & ~S_IXUSR & ~S_IRWXG & ~S_IRWXO)
#define CHMOD_PROGRAM_KEY_PERMISSIONS (S_IRUSR & ~S_IWUSR & ~S_IXUSR & ~S_IRWXG & ~S_IRWXO)
+
#ifndef KROWBAR_OFF
#define KROWBAR_SCORE_PATH "/home/krowbar/Code/irc/data/tildescores.txt"
#define JU_SCORE_PATH "/home/jmjl/dev/juju/data/tildescores.txt"
@@ -356,7 +358,7 @@ int add_file_value(const char* file_name, const long long int &value_to_add, con
file2 << new_value << "\n";
file2.close();
- chmod(temp_file_path, CHMOD_PERMISSIONS);
+ chmod(temp_file_path, CHMOD_ENABLEWRITE_PERMISSIONS);
if(!file2) //error
{
@@ -677,7 +679,7 @@ std::string refresh_pcoin_key()
if(!std::rename(program_key_path, temp_program_key_path))
{
- chmod(temp_program_key_path, CHMOD_PERMISSIONS);
+ chmod(temp_program_key_path, CHMOD_ENABLEWRITE_PERMISSIONS);
std::ofstream fin2(temp2_program_key_path);
if(!fin2)
@@ -700,7 +702,7 @@ std::string refresh_pcoin_key()
new_key = exec(PCOIN_NEW_KEY_CMD);
fin2 << new_key << "\n";
fin2.close();
- chmod(temp2_program_key_path, CHMOD_PROGRAM_KEY_PERMISSIONS);
+ chmod(temp2_program_key_path, CHMOD_ENABLEWRITE_PERMISSIONS);
while(1)
{
@@ -830,7 +832,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fin2.close();
fin3.close();
- chmod(receiver_path, CHMOD_PERMISSIONS);
+ chmod(receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
delete[] receiver_salt_path;
delete[] receiver_salt_logged_in_path;
@@ -890,7 +892,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fout << "\n\n";
}
fout.close();
- chmod(really_temp_receiver_path, CHMOD_PERMISSIONS);
+ chmod(really_temp_receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
if(!fout) //error
{
@@ -914,7 +916,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_receiver_path, receiver_path))
break;
}
-
+ // restore original permissions of receiver_path
chmod(receiver_path, CHMOD_PERMISSIONS);
delete[] really_temp_receiver_path;
@@ -943,7 +945,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
else
fin.close();
fin2.close();
- chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -981,7 +983,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fout << "\n";
}
fout.close();
- chmod(really_temp_program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(really_temp_program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
if(!fout) //error
{
@@ -1028,6 +1030,8 @@ int send_message(const char* sender_username, const char* receiver_username, con
std::strcat(temp_sender_path, random_string.c_str());
std::strcat(temp_sender_path, "_messages.txt"); // length = 13
+ // make sender_path rename-able
+ chmod(sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
while(1)
{
if(!std::rename(sender_path, temp_sender_path))
@@ -1038,7 +1042,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fin.open(temp_sender_path);
fout.open(really_temp_sender_path);
- chmod(really_temp_sender_path, CHMOD_PERMISSIONS);
+ chmod(really_temp_sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
fout << fin.rdbuf();
@@ -1105,6 +1109,8 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_sender_path, sender_path))
break;
}
+ // restore default permissions of sender_path
+ chmod(sender_path, CHMOD_PERMISSIONS);
delete[] really_temp_sender_path;
delete[] temp_sender_path;
@@ -1132,7 +1138,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
else
fin.close();
fin2.close();
- chmod(program_sender_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_sender_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1170,7 +1176,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fout << "\n";
}
fout.close();
- chmod(really_temp_program_sender_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(really_temp_program_sender_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
if(!fout) //error
{
@@ -1194,7 +1200,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_program_sender_path.c_str(), program_sender_path.c_str()))
break;
}
-
+ // restore original permissions of program_sender_path
chmod(program_sender_path.c_str(), CHMOD_PERMISSIONS);
break;
}//if statement with !std::rename for sender's program accounting _messages file
@@ -1290,7 +1296,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_sender_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_sender_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1326,7 +1332,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_sender_total_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_sender_total_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1357,6 +1363,8 @@ int send(const char* sender_username, const char* receiver_username, const long
std::strcat(sender_path, sender_username);
std::strcat(sender_path, ".txt"); // length = 4
+ // make sender_path rename-able
+ chmod(sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
while(1)
{
if(!std::rename(sender_path, temp_sender_path))
@@ -1412,7 +1420,7 @@ int send(const char* sender_username, const char* receiver_username, const long
fin2.close();
fin3.close();
- chmod(receiver_path, CHMOD_PERMISSIONS);
+ chmod(receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
delete[] receiver_salt_path;
delete[] receiver_salt_logged_in_path;
@@ -1446,7 +1454,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1477,7 +1485,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_receiver_total_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_total_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1491,6 +1499,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_receiver_total_path.c_str(), program_receiver_total_path.c_str()))
break;
}
+ // restore original permissions of program_receiver_total_path
+ chmod(program_receiver_total_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
@@ -1501,6 +1511,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_receiver_path.c_str(), program_receiver_path.c_str()))
break;
}
+ // restore original permissions of program_receiver_path
+ chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
@@ -1519,6 +1531,9 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_receiver_path, receiver_path))
break;
}
+ // restore original permissions of receiver_path
+ chmod(receiver_path, CHMOD_PERMISSIONS);
+
delete[] temp_receiver_path;
delete[] receiver_path;
delete[] temp_receiver_username;
@@ -1543,6 +1558,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_sender_path, sender_path))
break;
}
+ // restore original permissions of sender_path
+ chmod(sender_path, CHMOD_PERMISSIONS);
delete[] temp_sender_path;
delete[] sender_path;
@@ -1556,11 +1573,13 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_sender_total_path.c_str(), program_sender_total_path.c_str()))
break;
}
+ // restore original permissions of program_sender_total_path
+ chmod(program_sender_total_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
}
- else if(return_value == 1)
+ else if(return_value == ERR_ADD_FILE_VALUE_INSUFFICIENT_FUNDS)
{
long long int amount_owed = get_file_value(temp_program_sender_username.c_str());
long long int amount_to_aib = (long long int)(amount_to_send) - amount_owed;
@@ -1580,6 +1599,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_sender_path.c_str(), program_sender_path.c_str()))
break;
}
+ // restore original permissions of program_sender_path
+ chmod(program_sender_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
@@ -1759,7 +1780,7 @@ int add_internal_balance(const char* username, const long long int value_to_add)
else
fin.close();
fin2.close();
- chmod(internal_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(internal_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
int return_value;
@@ -1797,7 +1818,7 @@ int add_internal_balance(const char* username, const long long int value_to_add)
else
fin.close();
fin2.close();
- chmod(internal_total_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(internal_total_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1810,6 +1831,8 @@ int add_internal_balance(const char* username, const long long int value_to_add)
if(!std::rename(temp_internal_total_path.c_str(), internal_total_path.c_str()))
break;
}
+ // restore original permissions of internal_total_path
+ chmod(internal_total_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
@@ -1822,6 +1845,8 @@ int add_internal_balance(const char* username, const long long int value_to_add)
if(!std::rename(temp_internal_path.c_str(), internal_path.c_str()))
break;
}
+ // restore original permissions of internal_path
+ chmod(internal_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
diff --git a/tcoin.cpp b/tcoin.cpp
index 819e075..369a055 100644
--- a/tcoin.cpp
+++ b/tcoin.cpp
@@ -36,7 +36,8 @@
#define LS_HOME_CMD "/bin/ls /home"
#define BIN_ECHO_CMD "/bin/echo $$"
-#define CHMOD_PERMISSIONS ((S_IRUSR | S_IWUSR) & ~S_IRWXG & ~S_IRWXO)
+#define CHMOD_PERMISSIONS ((S_IRUSR) & ~S_IWUSR & ~S_IXUSR & ~S_IRWXG & ~S_IRWXO)
+#define CHMOD_ENABLEWRITE_PERMISSIONS ((S_IRUSR | S_IWUSR) & ~S_IXUSR & ~S_IRWXG & ~S_IRWXO)
#ifndef KROWBAR_OFF
#define KROWBAR_SCORE_PATH "/home/krowbar/Code/irc/data/tildescores.txt"
#define JU_SCORE_PATH "/home/jmjl/dev/juju/data/tildescores.txt"
@@ -357,7 +358,7 @@ int add_file_value(const char* file_name, const long long int &value_to_add, con
std::ofstream file2(temp_file_path);
file2 << new_value << "\n";
file2.close();
- chmod(temp_file_path, CHMOD_PERMISSIONS);
+ chmod(temp_file_path, CHMOD_ENABLEWRITE_PERMISSIONS);
if(!file2) //error
{
@@ -1051,7 +1052,7 @@ int initialise_user(const char* username, const long long int &base_amount)
else
{
fin.close();
- chmod(password_candidate_file.c_str(), CHMOD_PERMISSIONS);
+ chmod(password_candidate_file.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
//rename password candidate file to password file to actualise the creation of the account
while(1)
{
@@ -1133,7 +1134,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fin2.close();
fin3.close();
- chmod(receiver_path, CHMOD_PERMISSIONS);
+ chmod(receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
delete[] receiver_salt_path;
delete[] receiver_salt_logged_in_path;
@@ -1193,7 +1194,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fout << "\n\n";
}
fout.close();
- chmod(really_temp_receiver_path, CHMOD_PERMISSIONS);
+ chmod(really_temp_receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
if(!fout) //error
{
@@ -1217,7 +1218,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_receiver_path, receiver_path))
break;
}
-
+ // restoring original permissions of receiver_path
chmod(receiver_path, CHMOD_PERMISSIONS);
delete[] really_temp_receiver_path;
@@ -1246,7 +1247,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
else
fin.close();
fin2.close();
- chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1284,7 +1285,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fout << "\n";
}
fout.close();
- chmod(really_temp_program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(really_temp_program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
if(!fout) //error
{
@@ -1308,7 +1309,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_program_receiver_path.c_str(), program_receiver_path.c_str()))
break;
}
-
+ // restoring original permissions of program_receiver_path
chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
break;
}//if statement with !std::rename for receiver's program accounting _messages file
@@ -1331,6 +1332,9 @@ int send_message(const char* sender_username, const char* receiver_username, con
std::strcat(temp_sender_path, random_string.c_str());
std::strcat(temp_sender_path, "_messages.txt"); // length = 13
+ // enable sender_path to be rename-able
+ chmod(sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
+
while(1)
{
if(!std::rename(sender_path, temp_sender_path))
@@ -1341,7 +1345,7 @@ int send_message(const char* sender_username, const char* receiver_username, con
fin.open(temp_sender_path);
fout.open(really_temp_sender_path);
- chmod(really_temp_sender_path, CHMOD_PERMISSIONS);
+ chmod(really_temp_sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
fout << fin.rdbuf();
@@ -1407,6 +1411,8 @@ int send_message(const char* sender_username, const char* receiver_username, con
if(!std::rename(temp_sender_path, sender_path))
break;
}
+ // restoring sender_path to its original permissions
+ chmod(sender_path, CHMOD_PERMISSIONS);
delete[] really_temp_sender_path;
delete[] temp_sender_path;
@@ -1491,6 +1497,9 @@ int send(const char* sender_username, const char* receiver_username, const long
std::strcat(sender_path, sender_username);
std::strcat(sender_path, ".txt");
+ // enable sender_path to be rename-able
+ chmod(sender_path, CHMOD_ENABLEWRITE_PERMISSIONS);
+
while(1)
{
if(!std::rename(sender_path, temp_sender_path))
@@ -1548,7 +1557,7 @@ int send(const char* sender_username, const char* receiver_username, const long
fin2.close();
fin3.close();
- chmod(receiver_path, CHMOD_PERMISSIONS);
+ chmod(receiver_path, CHMOD_ENABLEWRITE_PERMISSIONS);
delete[] receiver_salt_path;
delete[] receiver_salt_logged_in_path;
@@ -1582,7 +1591,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1613,7 +1622,7 @@ int send(const char* sender_username, const char* receiver_username, const long
else
fin.close();
fin2.close();
- chmod(program_receiver_total_path.c_str(), CHMOD_PERMISSIONS);
+ chmod(program_receiver_total_path.c_str(), CHMOD_ENABLEWRITE_PERMISSIONS);
}
while(1)
@@ -1627,6 +1636,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_receiver_total_path.c_str(), program_receiver_total_path.c_str()))
break;
}
+ // restore correct permissions to program_receiver_total_path
+ chmod(program_receiver_total_path.c_str(), CHMOD_PERMISSIONS);
break;
}
}
@@ -1637,6 +1648,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_program_receiver_path.c_str(), program_receiver_path.c_str()))
break;
}
+ // restore correct permissions to program_receiver_path
+ chmod(program_receiver_path.c_str(), CHMOD_PERMISSIONS);
break;
}//if statement with !std::rename for receiver's program accounting receiver balance file
}//while loop for program accounting receiver's balance file
@@ -1647,6 +1660,9 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_receiver_path, receiver_path))
break;
}
+ // restore correct permissions to receiver_path
+ chmod(receiver_path, CHMOD_PERMISSIONS);
+
delete[] temp_receiver_path;
delete[] receiver_path;
delete[] temp_receiver_username;
@@ -1679,6 +1695,8 @@ int send(const char* sender_username, const char* receiver_username, const long
if(!std::rename(temp_sender_path, sender_path))
break;
}
+ // restore the correct permissions to sender_path
+ chmod(sender_path, CHMOD_PERMISSIONS);
delete[] temp_sender_path;
delete[] sender_path;
|