openvpn/lladdr.c
james 0aee9ca7e7 Allow OpenVPN to run completely unprivileged under Linux
by allowing openvpn --mktun to be used with --user and --group
to set the UID/GID of the tun device node.  Also added --iproute
option to allow an alternative command to be executed in place
of the default iproute2 command (Alon Bar-Lev).


git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2639 e7ae566f-a301-0410-adde-c780ea21d3b5
2008-01-21 19:34:13 +00:00

59 lines
1.4 KiB
C

/*
* Support routine for configuring link layer address
*/
#ifdef WIN32
#include "config-win32.h"
#else
#include "config.h"
#endif
#include "syshead.h"
#include "error.h"
#include "misc.h"
int set_lladdr(const char *ifname, const char *lladdr,
const struct env_set *es)
{
char cmd[256];
int r;
if (!ifname || !lladdr)
return -1;
#if defined(TARGET_LINUX)
#ifdef CONFIG_FEATURE_IPROUTE
openvpn_snprintf (cmd, sizeof (cmd),
"%s link set addr %s dev %s",
iproute_path, lladdr, ifname);
#else
openvpn_snprintf (cmd, sizeof (cmd),
IFCONFIG_PATH " %s hw ether %s",
ifname, lladdr);
#endif
#elif defined(TARGET_SOLARIS)
openvpn_snprintf (cmd, sizeof (cmd),
IFCONFIG_PATH " %s ether %s",
ifname, lladdr);
#elif defined(TARGET_OPENBSD)
openvpn_snprintf (cmd, sizeof (cmd),
IFCONFIG_PATH " %s lladdr %s",
ifname, lladdr);
#elif defined(TARGET_DARWIN)
openvpn_snprintf (cmd, sizeof (cmd),
IFCONFIG_PATH " %s lladdr %s",
ifname, lladdr);
#elif defined(TARGET_FREEBSD)
openvpn_snprintf (cmd, sizeof (cmd),
IFCONFIG_PATH " %s ether %s",
ifname, lladdr);
#else
msg (M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system.");
return -1;
#endif
r = system_check (cmd, es, M_WARN, "ERROR: Unable to set link layer address.");
if (r)
msg (M_INFO, "TUN/TAP link layer address set to %s", lladdr);
return r;
}