From 48d69282339d5d6e55364ae6dbbf31b516fcf76f Mon Sep 17 00:00:00 2001 From: Lakindu Date: Wed, 6 May 2020 15:25:20 +0530 Subject: [PATCH 1/2] Now config file is always writen to /etc/wh.config --- src/ui/h_prop.c | 4 ++-- src/ui/read_config.cpp | 11 ++++++----- src/ui/read_config.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ui/h_prop.c b/src/ui/h_prop.c index 4e2629e..dc917a9 100644 --- a/src/ui/h_prop.c +++ b/src/ui/h_prop.c @@ -98,7 +98,7 @@ const char *build_wh_mkconfig_command(ConfigValues* cv){ const char* a=get_config_file(CONFIG_FILE_NAME); - snprintf(cmd_mkconfig, BUFSIZE, "%s %s %s %s %s %s %s", CREATE_AP, cv->iface_wifi, cv->iface_inet, cv->ssid, cv->pass,MKCONFIG,a); + snprintf(cmd_mkconfig, BUFSIZE, "%s %s %s %s %s %s %s %s",SUDO, CREATE_AP, cv->iface_wifi, cv->iface_inet, cv->ssid, cv->pass,MKCONFIG,a); if(cv->freq!=NULL){ strcat(cmd_mkconfig," --freq-band "); @@ -184,7 +184,7 @@ const char* build_kill_create_ap_command(char* pid){ static int init_get_running(){ - const char* cmd="create_ap --list-running"; + const char* cmd="pkexec --user root create_ap --list-running"; FILE *fp; if ((fp = popen(cmd, "r")) == NULL) { diff --git a/src/ui/read_config.cpp b/src/ui/read_config.cpp index 5338c3d..79fd993 100644 --- a/src/ui/read_config.cpp +++ b/src/ui/read_config.cpp @@ -124,12 +124,13 @@ const char* get_config_file(const char* file){ static char a[BUFSIZE]; - if ((homedir = getenv("HOME")) == nullptr) { - homedir = getpwuid(getuid())->pw_dir; - } - snprintf(a,BUFSIZE,"%s%s%s",homedir,"/",file); + // if ((homedir = getenv("HOME")) == nullptr) { + // homedir = getpwuid(getuid())->pw_dir; + // } + // snprintf(a,BUFSIZE,"%s%s%s",homedir,"/",file); + + snprintf(a,BUFSIZE,"%s",file); - //printf(" from %s \n",a); return (const char*)a; } diff --git a/src/ui/read_config.h b/src/ui/read_config.h index 4911a3d..b56291a 100644 --- a/src/ui/read_config.h +++ b/src/ui/read_config.h @@ -68,7 +68,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#define CONFIG_FILE_NAME ".wh.config" +#define CONFIG_FILE_NAME "/etc/wh.config" #ifdef __cplusplus extern "C" { From 93f64fa11e1f40a7362cae501be02bd01d5bae53 Mon Sep 17 00:00:00 2001 From: Lakindu Date: Wed, 6 May 2020 16:30:28 +0530 Subject: [PATCH 2/2] Remove pkexec from desktop Add create_ap to execute without password with sudo --- src/CMakeLists.txt | 1 + src/desktop/wifihotspot.desktop | 2 +- src/scripts/Makefile | 2 ++ src/scripts/sudors_edit.sh | 2 ++ src/ui/h_prop.c | 4 ++-- 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/scripts/sudors_edit.sh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a15ed61..e7acf04 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,5 +49,6 @@ add_custom_target(uninstall_build COMMAND rm -rf $ENV{DESTDIR}${appdir}/${PROJECT_NAME} COMMAND rm -f $ENV{DESTDIR}${appbin}/${PROJECT_NAME} COMMAND rm -f $ENV{DESTDIR}${appdir}/applications/${PROJECT_NAME}.desktop + COMMAND rm -f $ENV{DESTDIR}${appdir}/${PROJECT_NAME}/${PROJECT_NAME}.desktop COMMENT Unstalling files... ) \ No newline at end of file diff --git a/src/desktop/wifihotspot.desktop b/src/desktop/wifihotspot.desktop index 3a53719..e21f50a 100644 --- a/src/desktop/wifihotspot.desktop +++ b/src/desktop/wifihotspot.desktop @@ -2,7 +2,7 @@ Type=Application Name=WifiHotspot Icon=/usr/share/wihotspot/hotspot.png -Exec=sh -c 'pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sudo /usr/bin/wihotspot' +Exec=sh -c 'env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/wihotspot' Terminal=false Categories=System Keywords=Hotspot;WiFi diff --git a/src/scripts/Makefile b/src/scripts/Makefile index 60bf3b2..ae6a6a5 100644 --- a/src/scripts/Makefile +++ b/src/scripts/Makefile @@ -12,6 +12,7 @@ install: [ ! -d /lib/systemd/system ] || install -Dm644 create_ap.service $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service install -Dm644 bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap install -Dm644 README.md $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md + echo 'ALL ALL=NOPASSWD: /usr/bin/create_ap' | sudo EDITOR='tee -a' visudo -f /etc/sudoers.d/create_ap uninstall: @@ -20,3 +21,4 @@ uninstall: [ ! -f /lib/systemd/system/create_ap.service ] || rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap rm -f $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md + rm -f /etc/sudoers.d/create_ap diff --git a/src/scripts/sudors_edit.sh b/src/scripts/sudors_edit.sh new file mode 100644 index 0000000..8583e7a --- /dev/null +++ b/src/scripts/sudors_edit.sh @@ -0,0 +1,2 @@ +#Execute create_ap without asking password +echo 'ALL ALL=NOPASSWD: /usr/bin/create_ap' | sudo EDITOR='tee -a' visudo -f /etc/sudoers.d/create_ap \ No newline at end of file diff --git a/src/ui/h_prop.c b/src/ui/h_prop.c index dc917a9..cfd84fe 100644 --- a/src/ui/h_prop.c +++ b/src/ui/h_prop.c @@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define BUFSIZE 512 -#define SUDO "pkexec --user root" +#define SUDO "sudo" #define CREATE_AP "create_ap" #define MKCONFIG "--mkconfig" @@ -184,7 +184,7 @@ const char* build_kill_create_ap_command(char* pid){ static int init_get_running(){ - const char* cmd="pkexec --user root create_ap --list-running"; + const char* cmd="sudo create_ap --list-running"; FILE *fp; if ((fp = popen(cmd, "r")) == NULL) {