Ver código fonte

Add -U option to skip root check and permit run as non-privileged user.

Adam Ierymenko 10 anos atrás
pai
commit
27c5f04d68
1 arquivos alterados com 13 adições e 5 exclusões
  1. 13 5
      one.cpp

+ 13 - 5
one.cpp

@@ -881,6 +881,7 @@ static void printHelp(const char *cn,FILE *out)
 	fprintf(out,"Available switches:"ZT_EOL_S);
 	fprintf(out,"  -h                - Display this help"ZT_EOL_S);
 	fprintf(out,"  -v                - Show version"ZT_EOL_S);
+	fprintf(out,"  -U                - Run as unprivileged user (skip privilege check)"ZT_EOL_S);
 	fprintf(out,"  -p<port>          - Port for UDP and TCP/HTTP (default: 9993)"ZT_EOL_S);
 	//fprintf(out,"  -T<path>          - Override root topology, do not authenticate or update"ZT_EOL_S);
 #ifdef __UNIX_LIKE__
@@ -945,6 +946,7 @@ int main(int argc,char **argv)
 	std::string overrideRootTopology;
 	std::string homeDir;
 	unsigned int port = ZT1_DEFAULT_PORT;
+	bool skipRootCheck = false;
 
 	for(int i=1;i<argc;++i) {
 		if (argv[i][0] == '-') {
@@ -964,6 +966,10 @@ int main(int argc,char **argv)
 					break;
 #endif // __UNIX_LIKE__
 
+				case 'U':
+					skipRootCheck = true;
+					break;
+
 				case 'T': // Override root topology
 					if (argv[i][2]) {
 						if (!OSUtils::readFile(argv[i] + 2,overrideRootTopology)) {
@@ -1082,11 +1088,10 @@ int main(int argc,char **argv)
 	}
 
 #ifdef __UNIX_LIKE__
-	if (getuid() != 0) {
+	if ((!skipRootCheck)&&(getuid() != 0)) {
 		fprintf(stderr,"%s: must be run as root (uid 0)"ZT_EOL_S,argv[0]);
 		return 1;
 	}
-
 	if (runAsDaemon) {
 		long p = (long)fork();
 		if (p < 0) {
@@ -1102,10 +1107,13 @@ int main(int argc,char **argv)
 	if (winRunFromCommandLine) {
 		// Running in "interactive" mode (mostly for debugging)
 		if (IsCurrentUserLocalAdministrator() != TRUE) {
-			fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
-			return 1;
+			if (!skipRootCheck) {
+				fprintf(stderr,"%s: must be run as a local administrator."ZT_EOL_S,argv[0]);
+				return 1;
+			}
+		} else {
+			_winPokeAHole();
 		}
-		_winPokeAHole();
 		SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE);
 		// continues on to ordinary command line execution code below...
 	} else {