@@ -228,6 +228,9 @@ All parameters are optional:
228228
229229 case 'u' :
230230 runas_user = optarg ;
231+ #if defined(__APPLE__ )
232+ fprintf (stderr , "Note, -u option has no effect on macOS\n" );
233+ #endif
231234 break ;
232235
233236 case 'h' : /* Help */
@@ -260,20 +263,22 @@ All parameters are optional:
260263 printl (LOG_INFO , "ts-warp Internal Socks address: [%s:%s]" , saddr , sport );
261264 printl (LOG_INFO , "ts-warp Internal HTTP address: [%s:%s]" , haddr , hport );
262265
266+ struct passwd * pwd = getpwnam (runas_user );
267+
263268 if (mkfifo (tfile_name , S_IFIFO |S_IRWXU |S_IRGRP |S_IROTH ) == -1 && errno != EEXIST )
264269 printl (LOG_WARN , "Unable to create active connections and traffic log pipe: [%s]" , tfile_name );
265- else
270+ else {
271+ chown (tfile_name , pwd ? pwd -> pw_uid : 0 , pwd ? pwd -> pw_gid : 0 );
266272 if ((tfd = open (tfile_name , O_RDWR ) ) == -1 )
267273 printl (LOG_WARN , "Unable to open active connections and traffic log pipe: [%s]" , tfile_name );
268274 else
269275 printl (LOG_INFO , "Active connections and traffic log pipe available: [%s]" , tfile_name );
276+ }
270277
271278 #if !defined(linux )
272279 pfd = pf_open (); /* Open PF device-file on *BSD */
273280 #endif
274281
275- struct passwd * pwd = getpwnam (runas_user );
276-
277282 #if (WITH_LIBSSH2 ) /* Init LIBSSH2 */
278283 if ((ret = libssh2_init (0 ))) {
279284 fprintf (stderr , "libssh2 initialization failed (%d)\n" , ret );
@@ -315,7 +320,7 @@ All parameters are optional:
315320 mpid = pid ;
316321
317322 #if !defined(__APPLE__ )
318- /* MacOS won't allow reading /dev/pf under non-root user. So, let's try user switching later */
323+ /* unfortunately, macOS won't allow reading /dev/pf under non-root user */
319324 if (setuid (pwd -> pw_uid ) && setgid (pwd -> pw_gid )) {
320325 printl (LOG_CRIT , "Failed to set privilege level to UID:GID [%d:%d]" , pwd -> pw_uid , pwd -> pw_gid );
321326 exit (1 );
@@ -635,14 +640,6 @@ All parameters are optional:
635640 if (cpid == 0 ) {
636641 /* -- Client processing (child) ------------------------------------------------------------------------- */
637642
638- #if defined(__APPLE__ )
639- /* Switch to a non-privileged user on macOS */
640- if (setuid (pwd -> pw_uid ) && setgid (pwd -> pw_gid )) {
641- printl (LOG_CRIT , "Failed to set privilege level to UID:GID [%d:%d]" , pwd -> pw_uid , pwd -> pw_gid );
642- exit (1 );
643- }
644- #endif
645-
646643 ssock .t = CHS_SOCKET ; /* Type socket */
647644 #if (WITH_LIBSSH2 )
648645 ssock .c = NULL ;
@@ -1174,7 +1171,7 @@ All parameters are optional:
11741171 tmessage .mtype = 1 ;
11751172 memset (& tmessage .mtext , 0 , sizeof (struct traffic_data ));
11761173 tmessage .mtext .pid = pid ;
1177- tmessage .mtext .timestamp = 0 ;
1174+ tmessage .mtext .timestamp = time ( NULL ) ;
11781175 tmessage .mtext .caddr = caddr ;
11791176 tmessage .mtext .cbytes = 0 ;
11801177 tmessage .mtext .daddr = daddr .ip_addr ;
@@ -1440,7 +1437,7 @@ All parameters are optional:\n\
14401437 -p file.pid\t PID filename, default: %s\n\
14411438 -f\t\t Force start\n\
14421439 \n\
1443- -u user\t A user to run ts-warp, default: %s\n\
1440+ -u user\t A user to run ts-warp, default: %s. Note, this option has no effect on macOS \n\
14441441 \n\
14451442 -h\t\t This message\n\n" ,
14461443 PROG_NAME , PROG_VERSION , INI_FILE_NAME , LOG_FILE_NAME , LOG_LEVEL_DEFAULT , PID_FILE_NAME , RUNAS_USER );
0 commit comments