Skip to content

proper setting of suid flag on auto-downloaded ncsvc #23

@benhuxley2

Description

@benhuxley2
    * Fix permissions on ncsvc and ncui before setting suid flag.
    * Set suid flag on ncsvc and ncui so running without root works on next execution.
    * Always compile ncui (but only fail on errors if mode=ncui).

diff --git a/jvpn.pl b/jvpn.pl
index af78e60..576aab0 100755
--- a/jvpn.pl
+++ b/jvpn.pl
@@ -368,21 +368,37 @@ if (!-e "./$mode") {
        if ($res->is_success) {
                print "Done, extracting\n";
                system("unzip -o ncLinuxApp.jar ncsvc libncui.so && chmod +x ./ncsvc");
+               system("chmod go-w ./ncsvc");
+               system("chmod ug+x ./ncsvc");
+               if( $> == 0 ) {
+                       system("chmod u+s ./ncsvc");
+               } else {
+                       printf "failed to chmod +s ncsvc (not running as root), please do this manually...\n";
+               }
+               if(!-e 'wrapper.c'){
+                       printf "wrapper.c not found in ".getcwd()."\n";
+                       printf "Please copy this file from jvpn distro and try again";
+               }
+               printf "Trying to compile 'ncui'. gcc must be installed to make this possible\n";
+               system("gcc -m32 -o ncui wrapper.c -ldl  -Wall >compile.log 2>&1 && chmod +x ./ncui");
+               if (!-e "./ncui") {
+                       printf("Error: Compilation failed, please compile.log\n");
+               }
+               else {
+                       printf("ncui binary compiled\n");
+                       system("chmod go-w ./ncui");
+                       system("chmod ug+x ./ncui");
+                       if( $> == 0 ) {
+                               system("chmod u+s ./ncui");
+                       } else {
+                               printf "failed to chmod +s ncui (not running as root), please do this manually...\n";
+                       }
+               }
                if($mode eq "ncui") {
                        if(!-e 'wrapper.c'){
-                               printf "wrapper.c not found in ".getcwd()."\n";
-                               printf "Please copy this file from jvpn distro and try again";
                                exit 1;
                        }
-                       printf "Trying to compile 'ncui'. gcc must be installed to make this possible\n";
-                       system("gcc -m32 -o ncui wrapper.c -ldl  -Wall >compile.log 2>&1 && chmod +x ./ncui");
                        if (!-e "./ncui") {
-                               printf("Error: Compilation failed, please compile.log\n");
                                exit 1;
                        }
-                       else {
-                               printf("ncui binary compiled\n");
-                       }
                }
        }
        else {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions