[OpenVPN home] [Date Prev] [Date Index] [Date Next]
[OpenVPN mailing lists] [Thread Prev] [Thread Index] [Thread Next]
Google
 
Web openvpn.net

[Openvpn-users] Bug in status.c when building with VC


  • Subject: [Openvpn-users] Bug in status.c when building with VC
  • From: Blaine Fleming <groups@xxxxxxxxxxxxx>
  • Date: Tue, 07 Dec 2004 17:14:09 -0700

I recently ran into a bug when using the --status option on windows with a MSVC generated binary. The problem is that the status file is created as read-only. This is fine when the file is first created and works until the tunnel is stopped. When the tunnel is restarted, openvpn is unable to open the file for writing because it is read only. The problem originates with the difference between mingw and msvc. In msvc, S_IRUSR and S_IWUSR are not available but _S_IREAD and _S_IWRITE are. Below is the MSVC patched version of status_open in status.c from beta20. This was a quick patch but it seems to have fixed the problem.

status_open (const char *filename,
const int refresh_freq,
const int msglevel,
const struct virtual_output *vout,
const unsigned int flags)
{
struct status_output *so = NULL;
if (filename || msglevel >= 0 || vout)
{
ALLOC_OBJ_CLEAR (so, struct status_output);
so->flags = flags;
so->msglevel = msglevel;
so->vout = vout;
so->fd = -1;
buf_reset (&so->read_buf);
event_timeout_clear (&so->et);
if (filename)
{
switch (so->flags)
{
#ifdef _MSC_VER
case STATUS_OUTPUT_WRITE:
so->fd = open (filename,
O_CREAT | O_TRUNC | O_WRONLY,
_S_IREAD | _S_IWRITE);
break;
case STATUS_OUTPUT_READ:
so->fd = open (filename,
O_RDONLY,
_S_IREAD | _S_IWRITE);
break;
case STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE:
so->fd = open (filename,
O_CREAT | O_RDWR,
_S_IREAD | _S_IWRITE);
break;
#else
case STATUS_OUTPUT_WRITE:
so->fd = open (filename,
O_CREAT | O_TRUNC | O_WRONLY,
S_IRUSR | S_IWUSR);
break;
case STATUS_OUTPUT_READ:
so->fd = open (filename,
O_RDONLY,
S_IRUSR | S_IWUSR);
break;
case STATUS_OUTPUT_READ|STATUS_OUTPUT_WRITE:
so->fd = open (filename,
O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR);
break;
#endif
default:
ASSERT (0);
}
if (so->fd >= 0)
{
so->filename = string_alloc (filename, NULL);
/* allocate read buffer */
if (so->flags & STATUS_OUTPUT_READ)
so->read_buf = alloc_buf (512);
}
else
{
msg (M_WARN, "Note: cannot open %s for %s", filename, print_status_mode (so->flags));
so->errors = true;
}
}
else
so->flags = STATUS_OUTPUT_WRITE;
if ((so->flags & STATUS_OUTPUT_WRITE) && refresh_freq > 0)
{
event_timeout_init (&so->et, refresh_freq, 0);
}
}
return so;
}


On a slightly related note, the file size and performance on the MSVC version seems to be much better on windows. Is there any interest in a binary version being available for download?

--Blaine Fleming


____________________________________________ Openvpn-users mailing list Openvpn-users@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/openvpn-users