Skip to content

Commit 66f6a3b

Browse files
schwabecron2
authored andcommitted
Fix regression of ignoring --user
Commit facb6ff changed a call in the style of if(a() | b()) to if(a() || b()). While this looks identical, it is not. The first statement always executes b() while the second only executes b() if a() returns false. This lead to to the platform_state_user never to set as side effect and thus --user being ignored. Rewrite the code to make this more explicit. Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20221019133627.2918110-1-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25430.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
1 parent 22bc63c commit 66f6a3b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/openvpn/init.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,10 +3551,14 @@ do_init_first_time(struct context *c)
35513551
ALLOC_OBJ_CLEAR_GC(c->c0, struct context_0, &c->gc);
35523552
c0 = c->c0;
35533553

3554-
/* get user and/or group that we want to setuid/setgid to */
3555-
c0->uid_gid_specified =
3556-
platform_group_get(c->options.groupname, &c0->platform_state_group)
3557-
|| platform_user_get(c->options.username, &c0->platform_state_user);
3554+
/* get user and/or group that we want to setuid/setgid to,
3555+
* sets also platform_x_state */
3556+
bool group_defined = platform_group_get(c->options.groupname,
3557+
&c0->platform_state_group);
3558+
bool user_defined = platform_user_get(c->options.username,
3559+
&c0->platform_state_user);
3560+
3561+
c0->uid_gid_specified = user_defined || group_defined;
35583562

35593563
/* perform postponed chdir if --daemon */
35603564
if (c->did_we_daemonize && c->options.cd_dir == NULL)

0 commit comments

Comments
 (0)