diff --git a/src/Cedar/Interop_OpenVPN.c b/src/Cedar/Interop_OpenVPN.c index 366ce95f..d248259b 100644 --- a/src/Cedar/Interop_OpenVPN.c +++ b/src/Cedar/Interop_OpenVPN.c @@ -673,6 +673,7 @@ void OvsBeginIPCAsyncConnectionIfEmpty(OPENVPN_SERVER *s, OPENVPN_SESSION *se, O if (se->IpcAsync == NULL) { + LIST *pi; IPC_PARAM p; ETHERIP_ID id; @@ -702,6 +703,24 @@ void OvsBeginIPCAsyncConnectionIfEmpty(OPENVPN_SERVER *s, OPENVPN_SESSION *se, O StrCpy(p.CryptName, sizeof(p.CryptName), c->CipherEncrypt->Name); } + // OpenVPN sends the default gateway's MAC address, + // if the option --push-peer-info is enabled. + // It also sends all of the client's environment + // variables whose names start with "UV_". + pi = OvsParsePeerInfo(c->ClientKey.PeerInfo); + + // Check presence of custom hostname + if (OvsHasOption(pi, "UV_HOSTNAME")) + { + StrCpy(p.ClientHostname, sizeof(p.ClientHostname), IniStrValue(pi, "UV_HOSTNAME")); + } + else // Use the default gateway's MAC address + { + StrCpy(p.ClientHostname, sizeof(p.ClientHostname), IniStrValue(pi, "IV_HWADDR")); + } + + OvsFreeOptions(pi); + if (se->Mode == OPENVPN_MODE_L3) { // L3 Mode @@ -1000,6 +1019,41 @@ LIST *OvsParseOptions(char *str) return o; } +// Parse the peer info string +LIST *OvsParsePeerInfo(char *str) +{ + LIST *o = NewListFast(NULL); + TOKEN_LIST *t; + + t = ParseTokenWithoutNullStr(str, "\n"); + if (t != NULL) + { + UINT i; + + for (i = 0;i < t->NumTokens;i++) + { + char key[MAX_SIZE]; + char value[MAX_SIZE]; + char *line = t->Token[i]; + Trim(line); + + if (GetKeyAndValue(line, key, sizeof(key), value, sizeof(value), "=\t")) + { + INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY)); + + e->Key = CopyStr(key); + e->Value = CopyStr(value); + + Add(o, e); + } + } + + FreeToken(t); + } + + return o; +} + // Release the option list void OvsFreeOptions(LIST *o) { diff --git a/src/Cedar/Interop_OpenVPN.h b/src/Cedar/Interop_OpenVPN.h index 4157206a..a1b3901a 100644 --- a/src/Cedar/Interop_OpenVPN.h +++ b/src/Cedar/Interop_OpenVPN.h @@ -362,6 +362,7 @@ BUF *OvsBuildKeyMethod2(OPENVPN_KEY_METHOD_2 *d); void OvsWriteStringToBuf(BUF *b, char *str, UINT max_size); LIST *OvsParseOptions(char *str); +LIST *OvsParsePeerInfo(char *str); void OvsFreeOptions(LIST *o); LIST *OvsNewOptions(); void OvsAddOption(LIST *o, char *key, char *value);