Skip to content

Commit 92d375f

Browse files
committed
ts-warp-1.5.4
1 parent a39fcef commit 92d375f

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
* **2024.07.23 ts-warp-1.5.4, gui-warp-1.0.25 (gui-warp-v1.0.30-mac), ns-warp-1.0.7**
4+
* `ts-warp.c`: `ACT`-file created as `RUNAS_USER` user owner
5+
* `ts-warp.c`: On `macOS` delayed `setuid()`/`setgid()` disabled as almost useless
6+
37
* **2024.07.23 ts-warp-1.5.3, gui-warp-1.0.25 (gui-warp-v1.0.30-mac), ns-warp-1.0.7**
48
* `ts-warp.c`: Enable on `macOS` delayed `setuid()`/`setgid()` to run as non-privileged user
59
* `ts-warp.c`: SSH2 proxy connection fixed, thanks Stefan Hildebrandt for the bug-hunting

ts-warp.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

ts-warp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#define ACT_FILE_NAME PREFIX"/var/spool/ts-warp/ts-warp.act"
3838
#define PID_FILE_NAME PREFIX"/var/run/ts-warp.pid"
3939

40-
#define RUNAS_USER "nobody"
40+
#if !defined(__APPLE__)
41+
#define RUNAS_USER "nobody"
42+
#else
43+
#define RUNAS_USER "root"
44+
#endif
4145

4246
/* -- Function prototypes ------------------------------------------------------------------------------------------- */
4347
void trap_signal(int sig);

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define PROG_NAME_SHORT "TSW"
3030
#define PROG_VERSION_MAJOR "1"
3131
#define PROG_VERSION_MINOR "5"
32-
#define PROG_VERSION_BUILD "3"
32+
#define PROG_VERSION_BUILD "4"
3333
#define PROG_VERSION PROG_VERSION_MAJOR "." PROG_VERSION_MINOR "." PROG_VERSION_BUILD
3434
#define PROG_NAME_FULL PROG_NAME " " PROG_VERSION
3535
#define PROG_NAME_CODE PROG_NAME_SHORT PROG_VERSION

0 commit comments

Comments
 (0)