pCloudCC/ formatting
This commit is contained in:
parent
6a5c1960bf
commit
8c3d737815
6
Makefile
6
Makefile
|
|
@ -8,5 +8,11 @@ all:
|
||||||
clean:
|
clean:
|
||||||
make -C pCloudCC/lib/pclsync clean
|
make -C pCloudCC/lib/pclsync clean
|
||||||
make -C pCloudCC/lib/mbedtls clean
|
make -C pCloudCC/lib/mbedtls clean
|
||||||
|
rm -rf pCloudCC/lib/mbedtls/CMakeFiles
|
||||||
|
rm pCloudCC/lib/mbedtls/CMakeCache.txt
|
||||||
|
rm pCloudCC/lib/mbedtls/Makefile
|
||||||
make -C pCloudCC clean
|
make -C pCloudCC clean
|
||||||
|
rm -rf pCloudCC/CMakeFiles
|
||||||
|
rm pCloudCC/CMakeCache.txt
|
||||||
|
rm pCloudCC/Makefile
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,120 +1,147 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <string.h>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "control_tools.h"
|
#include "control_tools.h"
|
||||||
#include "pclsync_lib.h"
|
#include "pclsync_lib.h"
|
||||||
#include "overlay_client.h"
|
#include "overlay_client.h"
|
||||||
|
|
||||||
namespace control_tools{
|
namespace cc = console_client;
|
||||||
|
|
||||||
static const int STOP = 0;
|
namespace control_tools {
|
||||||
|
|
||||||
enum command_ids_ {
|
static const int STOP = 0;
|
||||||
STARTCRYPTO = 20,
|
|
||||||
STOPCRYPTO,
|
enum command_ids_ {
|
||||||
FINALIZE,
|
STARTCRYPTO = 20,
|
||||||
LISTSYNC,
|
STOPCRYPTO,
|
||||||
ADDSYNC,
|
FINALIZE,
|
||||||
STOPSYNC
|
LISTSYNC,
|
||||||
};
|
ADDSYNC,
|
||||||
|
STOPSYNC
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int start_crypto(const char * pass) {
|
int
|
||||||
int ret;
|
start_crypto(const char * pass) {
|
||||||
char* errm;
|
int ret;
|
||||||
if (SendCall(STARTCRYPTO, pass, &ret, &errm))
|
char* errm;
|
||||||
std::cout << "Start Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
|
|
||||||
else
|
if (SendCall(STARTCRYPTO, pass, &ret, &errm)) {
|
||||||
std::cout << "Crypto started. "<< std::endl;
|
std::cout << "Start Crypto failed. return is "
|
||||||
|
<< ret << " and message is "<< errm
|
||||||
|
<< std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Crypto started. "<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
free(errm);
|
free(errm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
int stop_crypto(){
|
|
||||||
int ret;
|
|
||||||
char* errm;
|
|
||||||
if (SendCall(STOPCRYPTO, "", &ret, &errm))
|
|
||||||
std::cout << "Stop Crypto failed. return is " << ret<< " and message is "<<errm << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "Crypto Stopped. "<< std::endl;
|
|
||||||
|
|
||||||
free(errm);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
int finalize(){
|
|
||||||
int ret;
|
|
||||||
char* errm;
|
|
||||||
if (SendCall(FINALIZE, "", &ret, &errm))
|
|
||||||
std::cout << "Finalize failed. return is " << ret<< " and message is "<<errm << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "Exiting ..."<< std::endl;
|
|
||||||
|
|
||||||
free(errm);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
void process_commands()
|
|
||||||
{
|
|
||||||
std::cout<< "Supported commands are:" << std::endl << "startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
|
|
||||||
std::cout<< "> " ;
|
|
||||||
for (std::string line; std::getline(std::cin, line);) {
|
|
||||||
if (!line.compare("finalize")) {
|
|
||||||
finalize();
|
|
||||||
break;}
|
|
||||||
else if (!line.compare("stopcrypto"))
|
|
||||||
stop_crypto();
|
|
||||||
else if (!line.compare(0,11,"startcrypto",0,11) && (line.length() > 12))
|
|
||||||
start_crypto(line.c_str() + 12);
|
|
||||||
else if (!line.compare("q") || !line.compare("quit"))
|
|
||||||
break;
|
|
||||||
|
|
||||||
std::cout<< "> " ;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
int
|
||||||
|
stop_crypto(){
|
||||||
|
int ret;
|
||||||
|
char* errm;
|
||||||
|
|
||||||
int daemonize(bool do_commands) {
|
if (SendCall(STOPCRYPTO, "", &ret, &errm)) {
|
||||||
pid_t pid, sid;
|
std::cout << "Stop Crypto failed. return is " << ret
|
||||||
|
<< " and message is "<<errm << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "Crypto Stopped. " << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
pid = fork();
|
free(errm);
|
||||||
if (pid < 0)
|
return ret;
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
if (pid > 0) {
|
|
||||||
std::cout << "Daemon process created. Process id is: " << pid << std::endl;
|
|
||||||
if (do_commands) {
|
|
||||||
process_commands();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cout << "sudo kill -9 "<<pid<< std::endl<<" To stop it."<< std::endl;
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
umask(0);
|
|
||||||
/* Open any logs here */
|
int
|
||||||
sid = setsid();
|
finalize() {
|
||||||
if (sid < 0)
|
int ret;
|
||||||
exit(EXIT_FAILURE);
|
char* errm;
|
||||||
|
|
||||||
if ((chdir("/")) < 0)
|
if (SendCall(FINALIZE, "", &ret, &errm)) {
|
||||||
exit(EXIT_FAILURE);
|
std::cout << "Finalize failed. return is "
|
||||||
close(STDIN_FILENO);
|
<< ret << " and message is "<< errm
|
||||||
close(STDOUT_FILENO);
|
<< std::endl;
|
||||||
close(STDERR_FILENO);
|
} else {
|
||||||
|
std::cout << "Exiting ..."<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (console_client::clibrary::pclsync_lib::get_lib().init())
|
free(errm);
|
||||||
exit(EXIT_FAILURE);
|
return ret;
|
||||||
while (1) {
|
}
|
||||||
sleep(10);
|
|
||||||
|
void
|
||||||
|
process_commands() {
|
||||||
|
std::cout << "Supported commands are:" << std::endl
|
||||||
|
<< "startcrypto <crypto pass>, "
|
||||||
|
<< "stopcrypto, "
|
||||||
|
<< "finalize, "
|
||||||
|
<< "q, quit" << std::endl;
|
||||||
|
std::cout << "> " ;
|
||||||
|
|
||||||
|
for (std::string line; std::getline(std::cin, line);) {
|
||||||
|
if (!line.compare("finalize")) {
|
||||||
|
finalize();
|
||||||
|
break;
|
||||||
|
} else if (!line.compare("stopcrypto")) {
|
||||||
|
stop_crypto();
|
||||||
|
} else if (!line.compare(0,11,"startcrypto",0,11)
|
||||||
|
&& (line.length() > 12)) {
|
||||||
|
start_crypto(line.c_str() + 12);
|
||||||
|
} else if (!line.compare("q") || !line.compare("quit")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cout<< "> " ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
daemonize(bool do_commands) {
|
||||||
|
pid_t pid, sid;
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else if (pid > 0) {
|
||||||
|
std::cout << "Daemon process created. Process id is: " << pid << std::endl;
|
||||||
|
if (do_commands) {
|
||||||
|
process_commands();
|
||||||
|
} else {
|
||||||
|
std::cout << "kill -9 "<< pid << std::endl
|
||||||
|
<< " to stop it." << std::endl;
|
||||||
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open any logs here */
|
||||||
|
umask(0);
|
||||||
|
sid = setsid();
|
||||||
|
if (sid < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((chdir("/")) < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(STDIN_FILENO);
|
||||||
|
close(STDOUT_FILENO);
|
||||||
|
close(STDERR_FILENO);
|
||||||
|
|
||||||
|
if (cc::clibrary::pclsync_lib::get_lib().init()) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
sleep(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,66 @@
|
||||||
namespace cc = console_client;
|
namespace cc = console_client;
|
||||||
namespace clib = cc::clibrary;
|
namespace clib = cc::clibrary;
|
||||||
|
|
||||||
clib::pclsync_lib &clib::pclsync_lib::get_lib() {
|
const std::string&
|
||||||
|
clib::pclsync_lib::get_username() {
|
||||||
|
return username_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &
|
||||||
|
clib::pclsync_lib::get_password() {
|
||||||
|
return password_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &
|
||||||
|
clib::pclsync_lib::get_crypto_pass() {
|
||||||
|
return crypto_pass_;
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::string &
|
||||||
|
clib::pclsync_lib::get_mount() {
|
||||||
|
return mount_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_username(const std::string &arg) {
|
||||||
|
username_ = arg;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_password(const std::string &arg) {
|
||||||
|
password_ = arg;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_crypto_pass(const std::string &arg) {
|
||||||
|
crypto_pass_ = arg;
|
||||||
|
};
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_mount(const std::string &arg) {
|
||||||
|
mount_ = arg;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_savepass(bool s) {
|
||||||
|
save_pass_ = s;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::setupsetup_crypto(bool p) {
|
||||||
|
setup_crypto_ = p;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_newuser(bool p) {
|
||||||
|
newuser_ = p;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_daemon(bool p) {
|
||||||
|
daemon_ = p;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
clib::pclsync_lib::set_status_callback(status_callback_t p) {
|
||||||
|
status_callback_ = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
clib::pclsync_lib &
|
||||||
|
clib::pclsync_lib::get_lib() {
|
||||||
static clib::pclsync_lib g_lib;
|
static clib::pclsync_lib g_lib;
|
||||||
return g_lib;
|
return g_lib;
|
||||||
}
|
}
|
||||||
|
|
@ -67,17 +126,21 @@ exec(const char *cmd) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *clib::pclsync_lib::get_token() { return psync_get_token(); }
|
char *
|
||||||
|
clib::pclsync_lib::get_token() { return psync_get_token(); }
|
||||||
|
|
||||||
void clib::pclsync_lib::get_pass_from_console() {
|
void
|
||||||
|
clib::pclsync_lib::get_pass_from_console() {
|
||||||
do_get_pass_from_console(password_);
|
do_get_pass_from_console(password_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clib::pclsync_lib::get_cryptopass_from_console() {
|
void
|
||||||
|
clib::pclsync_lib::get_cryptopass_from_console() {
|
||||||
do_get_pass_from_console(crypto_pass_);
|
do_get_pass_from_console(crypto_pass_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clib::pclsync_lib::do_get_pass_from_console(std::string &password) {
|
void
|
||||||
|
clib::pclsync_lib::do_get_pass_from_console(std::string &password) {
|
||||||
if (daemon_) {
|
if (daemon_) {
|
||||||
std::cout << "Not able to read password when started as daemon."
|
std::cout << "Not able to read password when started as daemon."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
@ -263,7 +326,7 @@ static void status_change(pstatus_t *status) {
|
||||||
(int)status->status, status2string(status->status));
|
(int)status->status, status2string(status->status));
|
||||||
}
|
}
|
||||||
|
|
||||||
int clib::pclsync_lib::statrt_crypto(const char *pass, void *rep) {
|
int clib::pclsync_lib::start_crypto(const char *pass, void *rep) {
|
||||||
std::cout << "calling startcrypto pass: " << pass << std::endl;
|
std::cout << "calling startcrypto pass: " << pass << std::endl;
|
||||||
get_lib().crypto_pass_ = pass;
|
get_lib().crypto_pass_ = pass;
|
||||||
return lib_setup_cripto();
|
return lib_setup_cripto();
|
||||||
|
|
@ -326,7 +389,7 @@ int clib::pclsync_lib::init() // std::string& username, std::string& password,
|
||||||
psync_free(username_old);
|
psync_free(username_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
psync_add_overlay_callback(20, &clib::pclsync_lib::statrt_crypto);
|
psync_add_overlay_callback(20, &clib::pclsync_lib::start_crypto);
|
||||||
psync_add_overlay_callback(21, &clib::pclsync_lib::stop_crypto);
|
psync_add_overlay_callback(21, &clib::pclsync_lib::stop_crypto);
|
||||||
psync_add_overlay_callback(22, &clib::pclsync_lib::finalize);
|
psync_add_overlay_callback(22, &clib::pclsync_lib::finalize);
|
||||||
psync_add_overlay_callback(23, &clib::pclsync_lib::list_sync_folders);
|
psync_add_overlay_callback(23, &clib::pclsync_lib::list_sync_folders);
|
||||||
|
|
|
||||||
|
|
@ -36,70 +36,70 @@
|
||||||
struct pstatus_struct_;
|
struct pstatus_struct_;
|
||||||
|
|
||||||
namespace console_client {
|
namespace console_client {
|
||||||
namespace clibrary {
|
namespace clibrary {
|
||||||
|
|
||||||
class pclsync_lib {
|
class pclsync_lib {
|
||||||
public:
|
public:
|
||||||
~pclsync_lib();
|
~pclsync_lib();
|
||||||
pclsync_lib();
|
pclsync_lib();
|
||||||
|
|
||||||
// Getters
|
bool crypto_on_;
|
||||||
const std::string &get_username() { return username_; }
|
bool save_pass_;
|
||||||
const std::string &get_password() { return password_; }
|
bool setup_crypto_;
|
||||||
const std::string &get_crypto_pass() { return crypto_pass_; };
|
pstatus_struct_ *status_;
|
||||||
const std::string &get_mount() { return mount_; }
|
bool newuser_;
|
||||||
|
status_callback_t status_callback_;
|
||||||
|
bool was_init_;
|
||||||
|
|
||||||
// Setters
|
// Getters
|
||||||
void set_username(const std::string &arg) { username_ = arg; }
|
const std::string &get_username();
|
||||||
void set_password(const std::string &arg) { password_ = arg; }
|
const std::string &get_password();
|
||||||
void set_crypto_pass(const std::string &arg) { crypto_pass_ = arg; };
|
const std::string &get_crypto_pass();
|
||||||
void set_mount(const std::string &arg) { mount_ = arg; }
|
const std::string &get_mount();
|
||||||
void set_savepass(bool s) { save_pass_ = s; }
|
|
||||||
void setupsetup_crypto(bool p) { setup_crypto_ = p; }
|
|
||||||
void set_newuser(bool p) { newuser_ = p; }
|
|
||||||
void set_daemon(bool p) { daemon_ = p; }
|
|
||||||
void set_status_callback(status_callback_t p) { status_callback_ = p; }
|
|
||||||
|
|
||||||
// Console
|
// Setters
|
||||||
void get_pass_from_console();
|
void set_username(const std::string &arg);
|
||||||
void get_cryptopass_from_console();
|
void set_password(const std::string &arg);
|
||||||
|
void set_crypto_pass(const std::string &arg);
|
||||||
|
void set_mount(const std::string &arg);
|
||||||
|
void set_savepass(bool s);
|
||||||
|
void setupsetup_crypto(bool p);
|
||||||
|
void set_newuser(bool p);
|
||||||
|
void set_daemon(bool p);
|
||||||
|
void set_status_callback(status_callback_t p);
|
||||||
|
|
||||||
// API calls
|
// Singleton
|
||||||
int init(); // std::string& username, std::string& password, std::string*
|
static pclsync_lib &get_lib();
|
||||||
// crypto_pass, int setup_crypto = 1, int usesrypto_userpass = 0);
|
|
||||||
static int statrt_crypto(const char *pass, void *rep);
|
// Console
|
||||||
static int stop_crypto(const char *path, void *rep);
|
void get_pass_from_console();
|
||||||
static int finalize(const char *path, void *rep);
|
void get_cryptopass_from_console();
|
||||||
static int list_sync_folders(const char *path, void *rep);
|
|
||||||
// Singelton
|
|
||||||
static pclsync_lib &get_lib();
|
|
||||||
char *get_token();
|
|
||||||
int logout();
|
|
||||||
int unlink();
|
|
||||||
int login(const char *user, const char *pass, int save);
|
|
||||||
|
|
||||||
bool crypto_on_;
|
// API calls
|
||||||
bool save_pass_;
|
int init();
|
||||||
bool setup_crypto_;
|
// std::string& username, std::string& password, std::string*
|
||||||
pstatus_struct_ *status_;
|
// crypto_pass, int setup_crypto = 1, int usesrypto_userpass = 0);
|
||||||
bool newuser_;
|
static int start_crypto(const char *pass, void *rep);
|
||||||
status_callback_t status_callback_;
|
static int stop_crypto(const char *path, void *rep);
|
||||||
bool was_init_;
|
static int finalize(const char *path, void *rep);
|
||||||
|
static int list_sync_folders(const char *path, void *rep);
|
||||||
|
|
||||||
private:
|
char *get_token();
|
||||||
std::string username_;
|
int logout();
|
||||||
std::string password_;
|
int unlink();
|
||||||
std::string crypto_pass_;
|
int login(const char *user, const char *pass, int save);
|
||||||
std::string mount_;
|
|
||||||
|
|
||||||
bool to_set_mount_;
|
private:
|
||||||
bool daemon_;
|
std::string username_;
|
||||||
|
std::string password_;
|
||||||
|
std::string crypto_pass_;
|
||||||
|
std::string mount_;
|
||||||
|
|
||||||
private:
|
bool to_set_mount_;
|
||||||
void do_get_pass_from_console(std::string &password);
|
bool daemon_;
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace clibrary
|
|
||||||
} // namespace console_client
|
|
||||||
|
|
||||||
|
void do_get_pass_from_console(std::string &password);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // PCLSYNC_LIB_H
|
#endif // PCLSYNC_LIB_H
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ extern "C" {
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int statrt_crypto (const char* pass) {
|
int start_crypto (const char* pass) {
|
||||||
return cc::pclsync_lib::statrt_crypto (pass, NULL);
|
return cc::pclsync_lib::start_crypto (pass, NULL);
|
||||||
}
|
}
|
||||||
int stop_crypto () {
|
int stop_crypto () {
|
||||||
return cc::pclsync_lib::stop_crypto (NULL, NULL);
|
return cc::pclsync_lib::stop_crypto (NULL, NULL);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ void psync_fs_pause_until_login();
|
||||||
typedef void (*status_callback_t)(int status, const char *stat_string);
|
typedef void (*status_callback_t)(int status, const char *stat_string);
|
||||||
|
|
||||||
int init();
|
int init();
|
||||||
int statrt_crypto(const char *pass);
|
int start_crypto(const char *pass);
|
||||||
int stop_crypto();
|
int stop_crypto();
|
||||||
int finalize();
|
int finalize();
|
||||||
char *get_token();
|
char *get_token();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue