[Solved]client-connect exits on printing to file

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Locked
almogbaku
OpenVpn Newbie
Posts: 3
Joined: Wed Mar 11, 2015 2:18 am

[Solved]client-connect exits on printing to file

Post by almogbaku » Wed Mar 11, 2015 2:27 am

Hey guys,
I have a really wired problem with the `client-connect`..
I'm trying to create very simple script called `test.sh`(with +x mode):

Code: Select all

#!/bin/bash
echo "User connected!" > test.log
I defined it on my `server.conf`:

Code: Select all

script-security 3 system
client-connect /etc/openvpn/test.sh
The problem:
This very simple script always throws error status 2 for some reason, and prevent me from connection: WARNING: Failed running command (--client-connect): external program exited with error status: 1.
When i'm trying to add `exit 0` at the end, i'm able to connect but it not creates the file.

Does someone have an idea?

User avatar
maikcat
Forum Team
Posts: 4200
Joined: Wed Jan 12, 2011 9:23 am
Location: Athens,Greece
Contact:

Re: client-connect exits on printing to file

Post by maikcat » Wed Mar 11, 2015 6:52 am

naive question,

where do you want test.log to be created?
do you have permissions to write to this folder?

Michael.

almogbaku
OpenVpn Newbie
Posts: 3
Joined: Wed Mar 11, 2015 2:18 am

Re: client-connect exits on printing to file

Post by almogbaku » Wed Mar 11, 2015 10:43 am

I solved it! (and it took me the whole... night.)

In case someone tackling the problem and found this post:
The problem was permissions, of course! The `test.sh` script doesn't had the right permission to write on the file.

Commenting these directives on the `server.conf` solved it:

Code: Select all

# user nobody
# group nobody
Because the `openvpn` changed the user and group after of the daemon after logging in, the script suddenly hadn't the permission to write on files at all.


Thanks!

User avatar
maikcat
Forum Team
Posts: 4200
Joined: Wed Jan 12, 2011 9:23 am
Location: Athens,Greece
Contact:

Re: client-connect exits on printing to file

Post by maikcat » Wed Mar 11, 2015 11:03 am

commenting out these directives you understand that you degrade security...

a more correct approach would be to write to a location with proper permissions.

Marked as solved.

Michael.

almogbaku
OpenVpn Newbie
Posts: 3
Joined: Wed Mar 11, 2015 2:18 am

Re: [Solved]client-connect exits on printing to file

Post by almogbaku » Wed Mar 11, 2015 12:34 pm

of course, thanks. I commented them only for the test mode..

Locked