mirror of https://github.com/login000/tcoin
pcoin_keys fixed
Thanks to ~jmjl, I was able to find that pcoin_keys didn't work. To fix it, tcoin uses sneaky magic but with stdin isntead of an argument, and a new library imported called popen2, that lets me send both stdin and receive stdout, to successfully get "ls <path to the pcoin_keys directory>" to work (it execl's another instance of the tcoin comand so that it runs under setuid instead of as the original user who ran it.
This commit is contained in:
parent
bd53b1ec0c
commit
b0de38eafe
Binary file not shown.
36
ntcoin
36
ntcoin
|
@ -17,13 +17,15 @@ then
|
|||
#define TCOIN_PASS_PATH "'`/usr/bin/realpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/bin/realpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define PCOIN_BIN_PATH "'`/usr/bin/realpath -s $2`'/pcoin"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/bin/realpath -s $2`'/tcoin "
|
||||
#define TCOIN_PATH_W_SLASH "'`/usr/bin/realpath -s $1`'/tcoin/"
|
||||
#define TCOIN_SCRYPT_PATH "'`/usr/bin/realpath -s $1`'/tcoin/bin/scrypt"
|
||||
#define PCOIN_BIN_PATH "'`/usr/bin/realpath -s $2`'/pcoin"
|
||||
#define PCOIN_BIN_PATH_W_SPACE "'`/usr/bin/realpath -s $2`'/pcoin "
|
||||
#define TCOIN_HOST_NAME "'$3'"
|
||||
#define KROWBAR_OFF
|
||||
|
@ -124,7 +126,7 @@ else
|
|||
/bin/echo "Sorry, '`/usr/bin/realpath -s $1`/tcoin/secrets/tcoin_codez' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/echo "`cat /dev/urandom | base64 | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | base64 | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/usr/bin/realpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/echo "`cat /dev/urandom | base64 | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | base64 | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | base64 | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/usr/bin/realpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/chmod 400 "`/usr/bin/realpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
fi
|
||||
fi
|
||||
|
@ -144,6 +146,22 @@ else
|
|||
/bin/cp ./scrypt "`/usr/bin/realpath -s $1`/tcoin/bin/scrypt"
|
||||
/bin/chmod 500 "`/usr/bin/realpath -s $1`/tcoin/bin/scrypt"
|
||||
fi
|
||||
if [ -e "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.c" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/bin/realpath -s $1`/tcoin/bin/popen2.c' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./popen2.c "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.c"
|
||||
/bin/chmod 500 "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.c"
|
||||
fi
|
||||
if [ -e "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.h" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/bin/realpath -s $1`/tcoin/bin/popen2.h' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./popen2.h "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.h"
|
||||
/bin/chmod 500 "`/usr/bin/realpath -s $1`/tcoin/bin/popen2.h"
|
||||
fi
|
||||
if [ -e "`/usr/bin/realpath -s $1`/tcoin/bin/tcoin_defs.cpp" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/bin/realpath -s $1`/tcoin/bin/tcoin_defs.cpp' already exists."
|
||||
|
@ -155,6 +173,9 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/usr/bin/realpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/bin/realpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/bin/realpath -s $2`'/tcoin "
|
||||
|
@ -177,12 +198,15 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/usr/bin/realpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/bin/realpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/usr/bin/realpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/bin/realpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_PATH_W_SLASH "'`/usr/bin/realpath -s $1`'/tcoin/"
|
||||
#define TCOIN_SCRYPT_PATH "'`/usr/bin/realpath -s $1`'/tcoin/bin/scrypt"
|
||||
#define PCOIN_BIN_PATH "'`/usr/bin/realpath -s $2`'/pcoin"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/bin/realpath -s $2`'/tcoin "
|
||||
#define PCOIN_BIN_PATH_W_SPACE "'`/usr/bin/realpath -s $2`'/pcoin "
|
||||
#define KROWBAR_OFF
|
||||
#define DA_OFF
|
||||
|
@ -195,7 +219,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/bin/bash
|
||||
(/usr/bin/g++ -I"'`/usr/bin/realpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" -o "'`/usr/bin/realpath -s $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
(/usr/bin/g++ -I"'`/usr/bin/realpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" "'`/usr/bin/realpath -s $1`'/tcoin/bin/popen2.c" -o "'`/usr/bin/realpath -s $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/usr/bin/realpath -s $1`'/tcoin/bin/tcoin") \
|
||||
&& (/bin/chmod u+s "'`/usr/bin/realpath -s $1`'/tcoin/bin/tcoin") \
|
||||
&& (([ -f "'`/usr/bin/realpath -s $2`'/tcoin" ] && (/bin/chmod u+w "'`/usr/bin/realpath -s $2`'/tcoin")) || /bin/true) \
|
||||
|
@ -217,7 +241,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/bin/bash
|
||||
(/usr/bin/g++ -I"'`/usr/bin/realpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" -o "'`/usr/bin/realpath -s $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
(/usr/bin/g++ -I"'`/usr/bin/realpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" "'`/usr/bin/realpath -s $1`'/tcoin/bin/popen2.c" -o "'`/usr/bin/realpath -s $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/usr/bin/realpath -s $1`'/tcoin/bin/pcoin") \
|
||||
&& (/bin/chmod u+s "'`/usr/bin/realpath -s $1`'/tcoin/bin/pcoin") \
|
||||
&& (([ -f "'`/usr/bin/realpath -s $2`'/pcoin" ] && (/bin/chmod u+w "'`/usr/bin/realpath -s $2`'/pcoin")) || /bin/true) \
|
||||
|
|
|
@ -17,8 +17,10 @@ then
|
|||
#define TCOIN_PASS_PATH "'`/bin/realpath -q $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/bin/realpath -q $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/bin/realpath -q $2`'/tcoin "
|
||||
#define TCOIN_PATH_W_SLASH "'`/bin/realpath -q $1`'/tcoin/"
|
||||
|
@ -125,7 +127,7 @@ else
|
|||
/bin/echo "Sorry, '`/bin/realpath -q $1`/tcoin/secrets/tcoin_codez' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/echo "`cat /dev/urandom | b64encode -r . | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | b64encode -r . | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/bin/realpath -q $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/echo "`cat /dev/urandom | b64encode -r . | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | b64encode -r . | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | b64encode -r . | head -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/bin/realpath -q $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/chmod 400 "`/bin/realpath -q $1`/tcoin/secrets/tcoin_codez"
|
||||
fi
|
||||
fi
|
||||
|
@ -145,6 +147,22 @@ else
|
|||
/bin/cp ./scrypt_freebsd "`/bin/realpath -q $1`/tcoin/bin/scrypt"
|
||||
/bin/chmod 500 "`/bin/realpath -q $1`/tcoin/bin/scrypt"
|
||||
fi
|
||||
if [ -e "`/bin/realpath -q $1`/tcoin/bin/popen2.c" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/bin/realpath -q $1`/tcoin/bin/popen2.c' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./popen2.c "`/bin/realpath -q $1`/tcoin/bin/popen2.c"
|
||||
/bin/chmod 500 "`/bin/realpath -q $1`/tcoin/bin/popen2.c"
|
||||
fi
|
||||
if [ -e "`/bin/realpath -q $1`/tcoin/bin/popen2.h" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/bin/realpath -q $1`/tcoin/bin/popen2.h' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./scrypt_freebsd "`/bin/realpath -q $1`/tcoin/bin/popen2.h"
|
||||
/bin/chmod 500 "`/bin/realpath -q $1`/tcoin/bin/popen2.h"
|
||||
fi
|
||||
if [ -e "`/bin/realpath -q $1`/tcoin/bin/tcoin_defs.cpp" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/bin/realpath -q $1`/tcoin/bin/tcoin_defs.cpp' already exists."
|
||||
|
@ -156,6 +174,9 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/bin/realpath -q $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/bin/realpath -q $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define TCOIN_CODEZ_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/bin/realpath -q $2`'/tcoin "
|
||||
|
@ -179,12 +200,15 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/bin/realpath -q $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/bin/realpath -q $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/bin/realpath -q $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/bin/realpath -q $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_PATH_W_SLASH "'`/bin/realpath -q $1`'/tcoin/"
|
||||
#define TCOIN_SCRYPT_PATH "'`/bin/realpath -q $1`'/tcoin/bin/scrypt"
|
||||
#define PCOIN_BIN_PATH "'`/bin/realpath -q $2`'/pcoin"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/bin/realpath -q $2`'/tcoin "
|
||||
#define PCOIN_BIN_PATH_W_SPACE "'`/bin/realpath -q $2`'/pcoin "
|
||||
#define KROWBAR_OFF
|
||||
#define DA_OFF
|
||||
|
@ -198,7 +222,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/usr/local/bin/bash
|
||||
(/usr/local/bin/g++ -I"'`/bin/realpath -q $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" -o "'`/bin/realpath -q $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
(/usr/local/bin/g++ -I"'`/bin/realpath -q $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" "'`/bin/realpath -q $1`'/tcoin/bin/popen2.c" -o "'`/bin/realpath -q $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/bin/realpath -q $1`'/tcoin/bin/tcoin") \
|
||||
&& (/bin/chmod u+s "'`/bin/realpath -q $1`'/tcoin/bin/tcoin") \
|
||||
&& (([ -f "'`/bin/realpath -q $2`'/tcoin" ] && (/bin/chmod u+w "'`/bin/realpath -q $2`'/tcoin")) || /usr/bin/true) \
|
||||
|
@ -221,7 +245,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/usr/local/bin/bash
|
||||
(/usr/local/bin/g++ -I"'`/bin/realpath -q $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" -o "'`/bin/realpath -q $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
(/usr/local/bin/g++ -I"'`/bin/realpath -q $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" "'`/bin/realpath -q $1`'/tcoin/bin/popen2.c" -o "'`/bin/realpath -q $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/bin/realpath -q $1`'/tcoin/bin/pcoin") \
|
||||
&& (/bin/chmod u+s "'`/bin/realpath -q $1`'/tcoin/bin/pcoin") \
|
||||
&& (([ -f "'`/bin/realpath -q $2`'/pcoin" ] && (/bin/chmod u+w "'`/bin/realpath -q $2`'/pcoin")) || /usr/bin/true) \
|
||||
|
|
|
@ -17,8 +17,10 @@ then
|
|||
#define TCOIN_PASS_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/local/bin/grealpath -s $2`'/tcoin "
|
||||
#define TCOIN_PATH_W_SLASH "'`/usr/local/bin/grealpath -s $1`'/tcoin/"
|
||||
|
@ -125,7 +127,7 @@ else
|
|||
/bin/echo "Sorry, '`/usr/local/bin/grealpath -s $1`/tcoin/secrets/tcoin_codez' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/echo "`cat /dev/urandom | gbase64 | ghead -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | gbase64 | ghead -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/usr/local/bin/grealpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/echo "`cat /dev/urandom | gbase64 | ghead -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | gbase64 | ghead -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'` `cat /dev/urandom | gbase64 | ghead -c 512 | tr -d '\n' | tr '+' '-' | tr '/' '_'`" > "`/usr/local/bin/grealpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
/bin/chmod 400 "`/usr/local/bin/grealpath -s $1`/tcoin/secrets/tcoin_codez"
|
||||
fi
|
||||
fi
|
||||
|
@ -145,6 +147,22 @@ else
|
|||
/bin/cp ./scrypt "`/usr/local/bin/grealpath -s $1`/tcoin/bin/scrypt"
|
||||
/bin/chmod 500 "`/usr/local/bin/grealpath -s $1`/tcoin/bin/scrypt"
|
||||
fi
|
||||
if [ -e "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.c" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.c' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./popen2.c "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.c"
|
||||
/bin/chmod 500 "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.c"
|
||||
fi
|
||||
if [ -e "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.h" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.h' already exists."
|
||||
exit 1
|
||||
else
|
||||
/bin/cp ./popen2.h "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.h"
|
||||
/bin/chmod 500 "`/usr/local/bin/grealpath -s $1`/tcoin/bin/popen2.h"
|
||||
fi
|
||||
if [ -e "`/usr/local/bin/grealpath -s $1`/tcoin/bin/tcoin_defs.cpp" ]
|
||||
then
|
||||
/bin/echo "Sorry, '`/usr/local/bin/grealpath -s $1`/tcoin/bin/tcoin_defs.cpp' already exists."
|
||||
|
@ -156,6 +174,9 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/local/bin/grealpath -s $2`'/tcoin "
|
||||
|
@ -179,12 +200,15 @@ else
|
|||
#define TCOIN_PASS_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/passwords/"
|
||||
#define TCOIN_PROG_ACT_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/program_accounting/"
|
||||
#define PROG_ACT_W_SLASH "program_accounting/"
|
||||
#define LS_PATH "/bin/ls"
|
||||
#define PIPED_WORD_COUNT_CMD " | /usr/bin/wc -c"
|
||||
#define PCOIN_KEY_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define PCOIN_KEY_PATH_W_SLASH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys/"
|
||||
#define LS_PCOIN_KEY_CMD "/bin/ls '`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/pcoin_keys"
|
||||
#define TCOIN_CODEZ_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/secrets/tcoin_codez"
|
||||
#define TCOIN_PATH_W_SLASH "'`/usr/local/bin/grealpath -s $1`'/tcoin/"
|
||||
#define TCOIN_SCRYPT_PATH "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/scrypt"
|
||||
#define PCOIN_BIN_PATH "'`/usr/local/bin/grealpath -s $2`'/pcoin"
|
||||
#define TCOIN_BIN_PATH_W_SPACE "'`/usr/local/bin/grealpath -s $2`'/tcoin "
|
||||
#define PCOIN_BIN_PATH_W_SPACE "'`/usr/local/bin/grealpath -s $2`'/pcoin "
|
||||
#define KROWBAR_OFF
|
||||
#define DA_OFF
|
||||
|
@ -198,7 +222,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/usr/local/bin/bash
|
||||
(/usr/local/bin/eg++ -I"'`/usr/local/bin/grealpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" -o "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
(/usr/local/bin/eg++ -I"'`/usr/local/bin/grealpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/tcoin.cpp" "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/popen2.c" -o "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/tcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/tcoin") \
|
||||
&& (/bin/chmod u+s "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/tcoin") \
|
||||
&& (([ -f "'`/usr/local/bin/grealpath -s $2`'/tcoin" ] && (/bin/chmod u+w "'`/usr/local/bin/grealpath -s $2`'/tcoin")) || /usr/bin/true) \
|
||||
|
@ -220,7 +244,7 @@ else
|
|||
exit 1
|
||||
else
|
||||
/bin/echo '#!/usr/local/bin/bash
|
||||
(/usr/local/bin/eg++ -I"'`/usr/local/bin/grealpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" -o "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
(/usr/local/bin/eg++ -I"'`/usr/local/bin/grealpath -s $1`'/tcoin/bin" "'`/bin/pwd`'/pcoin.cpp" "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/popen2.c" -o "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/pcoin" -std=c++11) \
|
||||
&& (/bin/chmod 550 "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/pcoin") \
|
||||
&& (/bin/chmod u+s "'`/usr/local/bin/grealpath -s $1`'/tcoin/bin/pcoin") \
|
||||
&& (([ -f "'`/usr/local/bin/grealpath -s $2`'/pcoin" ] && (/bin/chmod u+w "'`/usr/local/bin/grealpath -s $2`'/pcoin")) || /usr/bin/true) \
|
||||
|
|
45
pcoin.cpp
45
pcoin.cpp
|
@ -14,7 +14,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "popen2.h"
|
||||
//set to 1 to enable some debug std::cout statements
|
||||
#define DEBUG 0
|
||||
|
||||
|
@ -224,6 +224,25 @@ std::string exec(const char* cmd) {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string exec2(const char* cmd, std::string input) {
|
||||
std::string data_length_str = exec((std::string(cmd) + std::string(PIPED_WORD_COUNT_CMD)).c_str());
|
||||
long long int data_length = strtol_fast(data_length_str.c_str())+1;
|
||||
std::vector <char> buffer;
|
||||
buffer.reserve(data_length);
|
||||
std::string result;
|
||||
files_t *fp = popen2(cmd);
|
||||
if (!fp) throw std::runtime_error("popen2() failed!");
|
||||
|
||||
fputs((input+std::string("\n")).c_str(), fp->in);
|
||||
std::fflush(fp->in);
|
||||
|
||||
while (!feof(fp->out)) {
|
||||
if (fgets(buffer.data(), data_length, fp->out) != nullptr)
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
long long int get_file_value(const char* file_name)
|
||||
{
|
||||
char* file_path = new char[strlen(file_name)+sizeof(TCOIN_PATH_W_SLASH)+4];
|
||||
|
@ -1473,10 +1492,17 @@ bool is_number(const char* test_string)
|
|||
|
||||
std::string get_username_from_key(std::string &key)
|
||||
{
|
||||
const static std::string all_usernames_dot_txt = exec(LS_PCOIN_KEY_CMD);
|
||||
std::ifstream codefin(TCOIN_CODEZ_PATH);
|
||||
char code1[513], code2[513], code3[513];
|
||||
codefin >> code1;
|
||||
codefin >> code2;
|
||||
codefin >> code3;
|
||||
codefin.close();
|
||||
const static std::string all_usernames_dot_txt = exec2((std::string(TCOIN_BIN_PATH_W_SPACE) + std::string("pcoin_list")).c_str(), std::string(code3));
|
||||
|
||||
std::istringstream iss(all_usernames_dot_txt);
|
||||
|
||||
std::string word1, word2;
|
||||
std::string word1, word2, program_name("n/a");
|
||||
//first word is program username with .txt on the end, second word is key
|
||||
while(iss >> word1)
|
||||
{
|
||||
|
@ -1492,14 +1518,15 @@ std::string get_username_from_key(std::string &key)
|
|||
{
|
||||
fin.close();
|
||||
delete[] program_key_path;
|
||||
return word1.substr(0, word1.size()-4); //removing .txt from the username returned
|
||||
program_name = word1.substr(0, word1.size()-4); //removing .txt from the username returned
|
||||
}
|
||||
else
|
||||
{
|
||||
fin.close();
|
||||
delete[] program_key_path;
|
||||
}
|
||||
fin.close();
|
||||
delete[] program_key_path;
|
||||
}
|
||||
|
||||
word1.assign("n/a");
|
||||
return word1;
|
||||
return program_name;
|
||||
}
|
||||
|
||||
long long int get_internal_balance(const char* username)
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
#include"popen2.h"
|
||||
#include<errno.h>
|
||||
#include<stdlib.h>
|
||||
#include<sys/wait.h>
|
||||
#include<unistd.h>
|
||||
|
||||
#define CLEANUP_PIPE(pipe) close((pipe)[0]); close((pipe)[1])
|
||||
|
||||
//https://github.com/iximiuz/popen2
|
||||
//https://iximiuz.com/en/posts/how-to-on-processes/
|
||||
|
||||
typedef struct files_t files_t;
|
||||
|
||||
struct files_chain_t {
|
||||
files_t files;
|
||||
pid_t pid;
|
||||
struct files_chain_t *next;
|
||||
};
|
||||
typedef struct files_chain_t files_chain_t;
|
||||
|
||||
static files_chain_t *files_chain;
|
||||
|
||||
static int _do_popen2(files_chain_t *link, const char *command)
|
||||
{
|
||||
int child_in[2];
|
||||
int child_out[2];
|
||||
if (0 != pipe(child_in)) {
|
||||
return -1;
|
||||
}
|
||||
if (0 != pipe(child_out)) {
|
||||
CLEANUP_PIPE(child_in);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_t cpid = link->pid = fork();
|
||||
if (0 > cpid) {
|
||||
CLEANUP_PIPE(child_in);
|
||||
CLEANUP_PIPE(child_out);
|
||||
return -1;
|
||||
}
|
||||
if (0 == cpid) {
|
||||
if (0 > dup2(child_in[0], 0) || 0 > dup2(child_out[1], 1)) {
|
||||
_Exit(127);
|
||||
}
|
||||
CLEANUP_PIPE(child_in);
|
||||
CLEANUP_PIPE(child_out);
|
||||
|
||||
for (files_chain_t *p = files_chain; p; p = p->next) {
|
||||
int fd_in = fileno(p->files.in);
|
||||
if (fd_in != 0) {
|
||||
close(fd_in);
|
||||
}
|
||||
int fd_out = fileno(p->files.out);
|
||||
if (fd_out != 1) {
|
||||
close(fd_out);
|
||||
}
|
||||
}
|
||||
|
||||
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
||||
_Exit(127);
|
||||
}
|
||||
|
||||
close(child_in[0]);
|
||||
close(child_out[1]);
|
||||
link->files.in = fdopen(child_in[1], "w");
|
||||
link->files.out = fdopen(child_out[0], "r");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* NAME
|
||||
* popen2 -- bidirectional popen()
|
||||
*
|
||||
* DESCRIPTION
|
||||
* popen2(const char *command) opens two pipes, forks a child process,
|
||||
* then binds the pipes to its stdin and stdout and execve shell to
|
||||
* execute given command.
|
||||
*
|
||||
* RETURN VALUES:
|
||||
* On success it returns a pointer to the struct with two fields
|
||||
* { FILE *in; FILE *out; }. The struct should be released via pclose2()
|
||||
* call. On failure returns NULL, check errno for more informaion about
|
||||
* the error.
|
||||
*/
|
||||
files_t *popen2(const char *command)
|
||||
{
|
||||
files_chain_t *link = (files_chain_t *) malloc(sizeof (files_chain_t));
|
||||
if (NULL == link) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (0 > _do_popen2(link, command)) {
|
||||
free(link);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
link->next = files_chain;
|
||||
files_chain = link;
|
||||
return (files_t *) link;
|
||||
}
|
||||
|
||||
int pclose2(files_t *fp) {
|
||||
files_chain_t **p = &files_chain;
|
||||
int found = 0;
|
||||
while (*p) {
|
||||
if (*p == (files_chain_t *) fp) {
|
||||
*p = (*p)->next;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
p = &(*p)->next;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return -1;
|
||||
}
|
||||
if (0 > fclose(fp->in) || 0 > fclose(fp->out)) {
|
||||
free((files_chain_t *) fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int status = -1;
|
||||
pid_t wait_pid;
|
||||
do {
|
||||
wait_pid = waitpid(((files_chain_t *) fp)->pid, &status, 0);
|
||||
} while (-1 == wait_pid && EINTR == errno);
|
||||
|
||||
free((files_chain_t *) fp);
|
||||
|
||||
if (wait_pid == -1) {
|
||||
return -1;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef _IXIMIUZ_POPEN2
|
||||
#define _IXIMIUZ_POPEN2
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
//https://github.com/iximiuz/popen2
|
||||
//https://iximiuz.com/en/posts/how-to-on-processes/
|
||||
|
||||
struct files_t {
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
};
|
||||
|
||||
struct files_t *popen2(const char *command);
|
||||
|
||||
int pclose2(struct files_t *fp);
|
||||
|
||||
#endif // _IXIMIUZ_POPEN2
|
60
tcoin.cpp
60
tcoin.cpp
|
@ -15,6 +15,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
#include "popen2.h"
|
||||
|
||||
#include "tcoin_defs.cpp"
|
||||
|
||||
|
@ -206,15 +207,39 @@ int strctcmp(const char*a, const char*b)
|
|||
}
|
||||
|
||||
std::string exec(const char* cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
while (!feof(pipe.get())) {
|
||||
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
while (!feof(pipe.get())) {
|
||||
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string exec2(const char* cmd, std::string input) {
|
||||
std::string data_length_str = exec((std::string(cmd) + std::string(PIPED_WORD_COUNT_CMD)).c_str());
|
||||
long long int data_length = strtol_fast(data_length_str.c_str())+1;
|
||||
std::vector <char> buffer;
|
||||
buffer.reserve(data_length);
|
||||
std::string result;
|
||||
files_t *fp = popen2(cmd);
|
||||
if (!fp)
|
||||
{
|
||||
pclose2(fp);
|
||||
throw std::runtime_error("popen2() failed!");
|
||||
}
|
||||
|
||||
fputs((input + std::string("\n")).c_str(), fp->in);
|
||||
std::fflush(fp->in);
|
||||
|
||||
while (!feof(fp->out)) {
|
||||
if (fgets(buffer.data(), data_length, fp->out) != nullptr)
|
||||
result += buffer.data();
|
||||
}
|
||||
pclose2(fp);
|
||||
return result;
|
||||
}
|
||||
|
||||
long long int get_file_value(const char* file_name)
|
||||
|
@ -771,9 +796,10 @@ int log_on(const char* username)
|
|||
fin.close();
|
||||
|
||||
std::ifstream codefin(TCOIN_CODEZ_PATH);
|
||||
char code1[513], code2[513];
|
||||
char code1[513], code2[513], code3[513];
|
||||
codefin >> code1;
|
||||
codefin >> code2;
|
||||
codefin >> code3;
|
||||
codefin.close();
|
||||
exec((std::string(TCOIN_BIN_PATH_W_SPACE) + std::string(code2)).c_str());
|
||||
|
||||
|
@ -869,8 +895,10 @@ int initialise_user(const char* username, const long long int &base_amount)
|
|||
std::cout << "\nYour salt and/or password file(s) are missing. A new salt and password file will be created. Please enter your desired passphrase and re-enter to confirm the same below. You will need to enter it to log onto tildecoin. If you ^C before confirming the passphrase, you'll have created an empty password file and would have to run `tcoin init` again.\n\n";
|
||||
|
||||
std::ifstream codefin(TCOIN_CODEZ_PATH);
|
||||
char code1[513], code2[513];
|
||||
char code1[513], code2[513], code3[513];
|
||||
codefin >> code1;
|
||||
codefin >> code2;
|
||||
codefin >> code3;
|
||||
codefin.close();
|
||||
exec((std::string(TCOIN_BIN_PATH_W_SPACE) + std::string(code1)).c_str());
|
||||
|
||||
|
@ -1563,9 +1591,10 @@ int main(int argc, char *argv[])
|
|||
//sneaky scrypt magic (process overlaying to maintain suid)
|
||||
{
|
||||
std::ifstream codefin(TCOIN_CODEZ_PATH);
|
||||
char code1[513], code2[513];
|
||||
char code1[513], code2[513], code3[513], codecheck[514];
|
||||
codefin >> code1;
|
||||
codefin >> code2;
|
||||
codefin >> code3;
|
||||
codefin.close();
|
||||
if(argc==2 && !strctcmp(argv[1], code1))
|
||||
{
|
||||
|
@ -1579,6 +1608,13 @@ int main(int argc, char *argv[])
|
|||
std::string password_file = std::string(TCOIN_PASS_PATH) + get_username() + std::string("_password.txt");
|
||||
execl(TCOIN_SCRYPT_PATH, "scrypt", "dec", password_file.c_str(), decrypted_password_file.c_str(), NULL);
|
||||
}
|
||||
if(argc==2 && !strctcmp(argv[1], "pcoin_list"))
|
||||
{
|
||||
std::fgets(codecheck, 514, stdin);
|
||||
codecheck[513] = codecheck[514] = '\0';
|
||||
if(!strctcmp(codecheck, code3))
|
||||
execl(LS_PATH, "ls", PCOIN_KEY_PATH, NULL);
|
||||
}
|
||||
}
|
||||
//If ^C is sent while doing `tcoin on`, <username>_dercrypted_password.txt gets left behind
|
||||
//this might cause the program to interpret the salt and password to be corrupted, and might
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
#ftc -> full tcoin check
|
||||
|
||||
|
||||
/usr/bin/diff <(/bin/ls /home/login/tcoin/*.txt | /usr/bin/xargs -n 1 /bin/cat) <(/bin/ls /home/login/tcoin/messages/* | /usr/bin/xargs -n 1 /home/login/bin/mstss)
|
|
@ -0,0 +1,179 @@
|
|||
#!/usr/bin/gawk -Mf
|
||||
|
||||
#mst.awk -> message_sum_tcoin.awk
|
||||
|
||||
BEGIN {
|
||||
supersummary=1
|
||||
summary=0
|
||||
sum=0
|
||||
sumplus=0
|
||||
summinus=0
|
||||
self_user=""
|
||||
self_user_found=0
|
||||
FS=""
|
||||
}
|
||||
|
||||
(NR == 1) {
|
||||
#Determining onlyo (only other-user) from first line (see /home/login/mst)
|
||||
if($0 ~ /^[a-zA-Z0-9_.\-]+/) {
|
||||
if(substr($0,NF-12) == "_messages.txt") {
|
||||
onlyo=substr($0,1,NF-13)
|
||||
}
|
||||
else {
|
||||
onlyo=$0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(NR != 1) {
|
||||
term=0
|
||||
other_user=""
|
||||
other_user_found=0
|
||||
if ($0 == "" || $1==" ") {
|
||||
next
|
||||
}
|
||||
|
||||
for (a=1;a!=NF;a++) {
|
||||
# other-user determination
|
||||
if ($a == ":" && a == 25) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b ~ /^[a-zA-Z0-9_\-]/) {
|
||||
for(c=b;;c++) {
|
||||
if ($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
other_user = ((other_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
other_user_found=1
|
||||
}
|
||||
# self-username determination
|
||||
else if ($a == "<" && !self_user_found) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b == " ") {
|
||||
for(c=b+1;;c++) {
|
||||
if($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!supersummary) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
else if ($a == ">" && !self_user_found) {
|
||||
for (b=a+2;;b++) {
|
||||
if($b ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($b))
|
||||
}
|
||||
}
|
||||
if (!supersummary) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyo && (onlyo != other_user)) {
|
||||
#print other_user, "SKIPPED!"
|
||||
next
|
||||
}
|
||||
|
||||
if (self_user == other_user) {
|
||||
#print "EQUAL USER!"
|
||||
next
|
||||
}
|
||||
|
||||
for (i=1;i!=NF;i++) {
|
||||
if (i <= 26 && !summary && !supersummary) {
|
||||
old_ors=ORS;ORS=""; if (!supersummary) { print $i; } ORS=old_ors
|
||||
}
|
||||
else if ($i == "<") {
|
||||
for(j=i+4;;j++) {
|
||||
if ($j == ".") {
|
||||
l=10
|
||||
for(k=j+1;;k++) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + $k/l
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
term = term*10 + $j
|
||||
}
|
||||
}
|
||||
sum = sum - term;
|
||||
summinus = summinus + term;
|
||||
olistminus[other_user] += term;
|
||||
olist[other_user] -= term;
|
||||
if(!summary && !supersummary) { print -1*term, "O:", other_user }
|
||||
next
|
||||
}
|
||||
else if($i == ">") {
|
||||
multiplier=1
|
||||
for(j=i-5;;j--) {
|
||||
if ($j == ".") {
|
||||
multiplier=1
|
||||
l=1
|
||||
for(k=j-1;;k--) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + ($k)*l;
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
multiplier = multiplier*10
|
||||
term = (term + $j)/10
|
||||
}
|
||||
}
|
||||
term = term * multiplier
|
||||
sum = sum + term;
|
||||
sumplus = sumplus + term;
|
||||
olistplus[other_user] += term;
|
||||
olist[other_user] += term;
|
||||
if (!summary && !supersummary) { print 1*term, "O:", other_user }
|
||||
next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if (!supersummary)
|
||||
{
|
||||
print "--USERLIST-START--"
|
||||
for (key in olist) {
|
||||
print key, 1*olist[key], "Cr:", 1*olistplus[key], "Dr:", -1*olistminus[key]
|
||||
}
|
||||
print "---USERLIST-END---"
|
||||
print "GRAND TOTAL:", 1*sum
|
||||
print "CREDIT:", 1*sumplus
|
||||
print "DEBIT:", -1*summinus
|
||||
}
|
||||
else
|
||||
{
|
||||
printf "%.0f\n", 100*sum
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
#!/usr/bin/gawk -Mf
|
||||
|
||||
#mst.awk -> message_sum_tcoin.awk
|
||||
|
||||
BEGIN {
|
||||
supersummary=0
|
||||
summary=0
|
||||
sum=0
|
||||
sumplus=0
|
||||
summinus=0
|
||||
self_user=""
|
||||
self_user_found=0
|
||||
FS=""
|
||||
}
|
||||
|
||||
(NR == 1) {
|
||||
#Determining onlyo (only other-user) from first line (see /home/login/mst)
|
||||
if($0 ~ /^[a-zA-Z0-9_.\-]+/) {
|
||||
if(substr($0,NF-12) == "_messages.txt") {
|
||||
onlyo=substr($0,1,NF-13)
|
||||
}
|
||||
else {
|
||||
onlyo=$0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(NR != 1) {
|
||||
term=0
|
||||
other_user=""
|
||||
other_user_found=0
|
||||
if ($0 == "" || $1==" ") {
|
||||
next
|
||||
}
|
||||
|
||||
for (a=1;a!=NF;a++) {
|
||||
# other-user determination
|
||||
if ($a == ":" && a == 25) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b ~ /^[a-zA-Z0-9_\-]/) {
|
||||
for(c=b;;c++) {
|
||||
if ($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
other_user = ((other_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
other_user_found=1
|
||||
}
|
||||
# self-username determination
|
||||
else if ($a == "<" && !self_user_found) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b == " ") {
|
||||
for(c=b+1;;c++) {
|
||||
if($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!supersummary) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
else if ($a == ">" && !self_user_found) {
|
||||
for (b=a+2;;b++) {
|
||||
if($b ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($b))
|
||||
}
|
||||
}
|
||||
if (!supersummary) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyo && (onlyo != other_user)) {
|
||||
#print other_user, "SKIPPED!"
|
||||
next
|
||||
}
|
||||
|
||||
if (self_user == other_user) {
|
||||
#print "EQUAL USER!"
|
||||
next
|
||||
}
|
||||
|
||||
for (i=1;i!=NF;i++) {
|
||||
if (i <= 26 && !summary && !supersummary) {
|
||||
old_ors=ORS;ORS=""; if (!supersummary) { print $i; } ORS=old_ors
|
||||
}
|
||||
else if ($i == "<") {
|
||||
for(j=i+4;;j++) {
|
||||
if ($j == ".") {
|
||||
l=10
|
||||
for(k=j+1;;k++) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + $k/l
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
term = term*10 + $j
|
||||
}
|
||||
}
|
||||
sum = sum - term;
|
||||
summinus = summinus + term;
|
||||
olistminus[other_user] += term;
|
||||
olist[other_user] -= term;
|
||||
if(!summary && !supersummary) { printf "%.2f %s %s\n", -1*term, "O:", other_user }
|
||||
next
|
||||
}
|
||||
else if($i == ">") {
|
||||
multiplier=1
|
||||
for(j=i-5;;j--) {
|
||||
if ($j == ".") {
|
||||
multiplier=1
|
||||
l=1
|
||||
for(k=j-1;;k--) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + ($k)*l;
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
multiplier = multiplier*10
|
||||
term = (term + $j)/10
|
||||
}
|
||||
}
|
||||
term = term * multiplier
|
||||
sum = sum + term;
|
||||
sumplus = sumplus + term;
|
||||
olistplus[other_user] += term;
|
||||
olist[other_user] += term;
|
||||
if (!summary && !supersummary) { printf "%.2f %s %s\n", 1*term, "O:", other_user }
|
||||
next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if (!supersummary)
|
||||
{
|
||||
print "--USERLIST-START--"
|
||||
for (key in olist) {
|
||||
printf "%s %.2f %s %.2f %s %s\n", key, 1*olist[key], "Cr:", 1*olistplus[key], "Dr:", -1*olistminus[key]
|
||||
}
|
||||
print "---USERLIST-END---"
|
||||
printf "%s %.2f\n", "GRAND TOTAL:", 1*sum
|
||||
printf "%s %.2f\n", "CREDIT:", 1*sumplus
|
||||
printf "%s %.2f\n", "DEBIT:", -1*summinus
|
||||
}
|
||||
else
|
||||
{
|
||||
printf "%d\n", 100*sum
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
#!/usr/bin/awk -f
|
||||
|
||||
#mst.awk -> message_sum_tcoin.awk
|
||||
|
||||
BEGIN {
|
||||
tsv=1
|
||||
summary=0
|
||||
sum=0
|
||||
sumplus=0
|
||||
summinus=0
|
||||
self_user=""
|
||||
self_user_found=0
|
||||
prev_self_txn=0
|
||||
FS=""
|
||||
}
|
||||
|
||||
(NR == 1) {
|
||||
#Determining onlyo (only other-user) from first line (see /home/login/mst)
|
||||
if($0 ~ /^[a-zA-Z0-9_.\-]+/) {
|
||||
if(substr($0,NF-12) == "_messages.txt") {
|
||||
onlyo=substr($0,1,NF-13)
|
||||
}
|
||||
else {
|
||||
onlyo=$0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(NR != 1) {
|
||||
term=0
|
||||
other_user=""
|
||||
other_user_found=0
|
||||
if ($0 == "" || $1==" ") {
|
||||
if($1==" " && !prev_self_txn) {
|
||||
i=1;
|
||||
while($i != ":") { ++i }
|
||||
message_user = substr($0, 5, i-10); #position (i-5) - position (5) + 1 = length of message_user, where position (i-5) is the position of the last character of message_user
|
||||
old_ofs=OFS;OFS="";print "\n", message_user, "\t", substr($0,i+2);OFS=old_ofs;
|
||||
}
|
||||
next
|
||||
}
|
||||
|
||||
for (a=1;a!=NF;a++) {
|
||||
# other-user determination
|
||||
if ($a == ":" && a == 25) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b ~ /^[a-zA-Z0-9_\-]/) {
|
||||
for(c=b;;c++) {
|
||||
if ($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
other_user = ((other_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
other_user_found=1
|
||||
}
|
||||
# self-username determination
|
||||
else if ($a == "<" && !self_user_found) {
|
||||
for (b=a+1;;b++) {
|
||||
if ($b == " ") {
|
||||
for(c=b+1;;c++) {
|
||||
if($c ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($c))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!tsv) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
else if ($a == ">" && !self_user_found) {
|
||||
for (b=a+2;;b++) {
|
||||
if($b ~ /^[^a-zA-Z0-9_\-]?$/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
self_user = ((self_user) ($b))
|
||||
}
|
||||
}
|
||||
if (!tsv) { print "S:", self_user }
|
||||
self_user_found = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (onlyo && (onlyo != other_user)) {
|
||||
#print other_user, "SKIPPED!"
|
||||
next
|
||||
}
|
||||
|
||||
if (self_user == other_user) {
|
||||
prev_self_txn = 1
|
||||
#print "EQUAL USER!"
|
||||
next
|
||||
}
|
||||
else {
|
||||
prev_self_txn = 0
|
||||
}
|
||||
|
||||
for (i=1;i!=NF;i++) {
|
||||
if (i <= 26 && !summary) {
|
||||
if(tsv && i == 25) {
|
||||
old_ors=ORS;ORS="";print "\t";ORS=old_ors
|
||||
}
|
||||
else if(tsv && i == 26) {
|
||||
#do nothing, don't print the "space"
|
||||
}
|
||||
else {
|
||||
old_ors=ORS;ORS="";print $i;ORS=old_ors
|
||||
}
|
||||
}
|
||||
else if ($i == "<") {
|
||||
for(j=i+4;;j++) {
|
||||
if ($j == ".") {
|
||||
l=10
|
||||
for(k=j+1;;k++) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + $k/l
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
term = term*10 + $j
|
||||
}
|
||||
}
|
||||
sum = sum - term;
|
||||
summinus = summinus + term;
|
||||
olistminus[other_user] += term;
|
||||
olist[other_user] -= term;
|
||||
if(!summary) { if(tsv){ old_ofs=OFS;OFS="\t"; print other_user, self_user, -1*term; OFS=old_ofs } else { print -1*term, "O:", other_user } }
|
||||
next
|
||||
}
|
||||
else if($i == ">") {
|
||||
multiplier=1
|
||||
for(j=i-5;;j--) {
|
||||
if ($j == ".") {
|
||||
multiplier=1
|
||||
l=1
|
||||
for(k=j-1;;k--) {
|
||||
if ($k ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
term = term + ($k)*l;
|
||||
l=l*10
|
||||
}
|
||||
break
|
||||
}
|
||||
else if ($j ~ /^[^0-9]/) {
|
||||
break
|
||||
}
|
||||
else {
|
||||
multiplier = multiplier*10
|
||||
term = (term + $j)/10
|
||||
}
|
||||
}
|
||||
term = term * multiplier
|
||||
sum = sum + term;
|
||||
sumplus = sumplus + term;
|
||||
olistplus[other_user] += term;
|
||||
olist[other_user] += term;
|
||||
if (!summary) { if(tsv){ old_ofs=OFS;OFS="\t"; print other_user, self_user, term; OFS=old_ofs } else{ print 1*term, "O:", other_user } }
|
||||
next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if(!tsv) {
|
||||
print "--USERLIST-START--"
|
||||
for (key in olist) {
|
||||
print key, 1*olist[key], "Cr:", 1*olistplus[key], "Dr:", -1*olistminus[key]
|
||||
}
|
||||
print "---USERLIST-END---"
|
||||
print "GRAND TOTAL:", 1*sum
|
||||
print "CREDIT:", 1*sumplus
|
||||
print "DEBIT:", -1*summinus
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
(/bin/echo "$2"; /bin/cat "$1") | /home/login/bin/message-sum-tcoin-helper.awk -
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
(/bin/echo "$2"; /bin/cat "$1") | /home/login/bin/message-sum-tcoin-helper-supersummary.awk -
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
#Message Tcoin Converter
|
||||
(/bin/echo;/bin/cat "$1") | /home/login/bin/message-tcoin-converter.awk - | /bin/sed -e 'H;${x;s/\n\n/\t/g;p;};d' | /usr/bin/awk -F'\t' -v OFS='\t' '$1 {cmd="/bin/date -d \""$1"\" +%s"; cmd | getline $1; close(cmd)} 1' -
|
||||
|
Loading…
Reference in New Issue