From patchwork Sat Nov 18 06:40:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 85 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director6.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id U68sFeVwEFpTGQAAgoeIoA for ; Sat, 18 Nov 2017 12:41:57 -0500 Received: from proxy1.mail.ord1c.rsapps.net ([172.28.255.1]) by director6.mail.ord1d.rsapps.net (Dovecot) with LMTP id a6cDFeVwEFriNwAAhgvE6Q ; Sat, 18 Nov 2017 12:41:57 -0500 Received: from smtp9.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy1.mail.ord1c.rsapps.net (Dovecot) with LMTP id WhUME+VwEFqKfAAA2VeTtA ; Sat, 18 Nov 2017 12:41:57 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp9.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Classification-ID: c5d704bc-cc87-11e7-8dc2-0026b95bddb7-1-1 Received: from [216.34.181.88] ([216.34.181.88:32626] helo=lists.sourceforge.net) by smtp9.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id D4/C4-16890-5E0701A5; Sat, 18 Nov 2017 12:41:57 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eG77B-0005VB-DK; Sat, 18 Nov 2017 17:41:13 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eG77A-0005V5-Fz for openvpn-devel@lists.sourceforge.net; Sat, 18 Nov 2017 17:41:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=QxLby2hxXhR3hO8u39WwfoWHzWw9zqAt38mSAfpqZO4=; b=NqBmfEtMqMONhtq8iZD2vTXMBD Y9rpIaRGoAJSjXC76CylHfzwm0KrJP2MK7nskdI1MVdTkSzO2OanHBWWFQ9Xq4eTtVuojxEKd6jMI IQJQMh54i+0g528XDB/u1sDcV00GOSnCY3K+hbO+W/Bc2QqKEnLiFOHGyvIoccGSqvcw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=QxLby2hxXhR3hO8u39WwfoWHzWw9zqAt38mSAfpqZO4=; b=BeOO0C+NGGgR1JQllEcdOYgiiu t/lr+R7NRpVp/f8GC3uwkCBKzMBbyL9mZUp0ctIv01x07kk1AGj9jQACxauB80vFBHVzmMPCk3x2W HXyOIHLPHqtJCrxTPdJZzvX6/KWH0FbohO3E9YnkIGJRhjQs3raNZ97xcW82HUNtS7yw=; Received: from mail-io0-f194.google.com ([209.85.223.194]) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1eG779-0000lJ-GD for openvpn-devel@lists.sourceforge.net; Sat, 18 Nov 2017 17:41:12 +0000 Received: by mail-io0-f194.google.com with SMTP id h205so11123181iof.5 for ; Sat, 18 Nov 2017 09:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QxLby2hxXhR3hO8u39WwfoWHzWw9zqAt38mSAfpqZO4=; b=Ry3YPY7QCLEZA++DvUYyjPS9K55curxr7N449LSz3Mil9r9Y7ZK4U2STP0OrIBRyZo dVSs9gzT+XGqs08hwTNHyuZnBcQziTe0Hh3xabfo98cCYm4YbstQUS21/CDGJkviQUN5 dPP7vZeMS+ikZU8x3+E+Was6FEdRucfPqi1LEGW3CB+97ptjuga92JPUIhydpv+B6Q4c 7rtgkst+eqIr33QWhzZb6MpTEJrDQi0PHX7iR5BzcfMZr6JPnG4wmdylbKflM+inxpEz Lwwyzm7tCgzgtxX/6kj2QZOeS2FdWLfr4UKh+UaC8plDKUj+pqC0t42k3d9Wp8sN84wB OgMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QxLby2hxXhR3hO8u39WwfoWHzWw9zqAt38mSAfpqZO4=; b=DOPgObY3QbJjry0QRlH/tO1PZuGwuSLBLJeVLouWX+gVY7Q2QEcrBDBJLt+vb1WXMM Xv64w15uWt3T7YuOpFhPzJyYq8zwjJb5DvJiIwfR1Bj324taB+oYin0plqnbAoaq8Pp/ sVQkCckyO/SCUz6o4/9ZZjuSICEVHzkAdxUk0guAs6zl3/JuKmQaRyBW+T+UCGUNQwBG TA77if9qVbFciHmVmad/48hVrzxWGE4ssFxTlbnD+7c4HHvn3n00eu7G+iKtglMfzjUX Ud/JVUJzf/1t2MeUlKuxpRHh5Bwxr4PyZNIJxbBm+KKyLleQVhztAn1l6FQzKxpt/XSt EsRA== X-Gm-Message-State: AJaThX78RAr/I6fFsJwTixaDy1V2g+beNwLCf/cV3ubjNkmWl0Uq6CYc YlYXYdIaoxtQRM3OEwgD2pfSP5eV X-Google-Smtp-Source: AGs4zMaSLzDIHO9XLbziFwOQiSeMilBql3Or9wq4ZehwKaZ3/wntfAqnujuJy9VrjaAtkO+u75NOvA== X-Received: by 10.107.112.14 with SMTP id l14mr4582232ioc.185.1511026865882; Sat, 18 Nov 2017 09:41:05 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.215.92]) by smtp.gmail.com with ESMTPSA id p134sm537169iop.75.2017.11.18.09.41.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Nov 2017 09:41:05 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Sat, 18 Nov 2017 12:40:57 -0500 Message-Id: <1511026858-23281-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.223.194 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.223.194 listed in dnsbl.sorbs.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1eG779-0000lJ-GD Subject: [Openvpn-devel] [PATCH 1/2] Ensure strings read from registry are null-terminated X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Selva Nair - Strings stored in registry are not guaranteed to be null-terminated. So, use RegGetValue() instead of RegQueryValueEx() as the former adds null termination to the returned string if missing. (Needs Windows Vista+) - While at it also add a default value parameter to GetRegString() to process optional registry values (such as ovpn_admin_group) without causing an otherwise confusing error logged to the eventlog[*]. [*] see Trac: #892 Signed-off-by: Selva Nair Acked-by: Gert Doering --- src/openvpnserv/common.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index e77d7ab..bc99584 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -56,14 +56,18 @@ openvpn_sntprintf(LPTSTR str, size_t size, LPCTSTR format, ...) #define REG_KEY TEXT("SOFTWARE\\" PACKAGE_NAME) static DWORD -GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size) +GetRegString(HKEY key, LPCTSTR value, LPTSTR data, DWORD size, LPCTSTR default_value) { - DWORD type; - LONG status = RegQueryValueEx(key, value, NULL, &type, (LPBYTE) data, &size); + LONG status = RegGetValue(key, NULL, value, RRF_RT_REG_SZ|RRF_RT_REG_EXPAND_SZ, + NULL, (LPBYTE) data, &size); - if (status == ERROR_SUCCESS && type != REG_SZ) + if (status == ERROR_FILE_NOT_FOUND && default_value) { - status = ERROR_DATATYPE_MISMATCH; + size_t len = size/sizeof(data[0]); + if (openvpn_sntprintf(data, len, default_value) > 0) + { + status = ERROR_SUCCESS; + } } if (status != ERROR_SUCCESS) @@ -91,48 +95,48 @@ GetOpenvpnSettings(settings_t *s) return MsgToEventLog(M_SYSERR, TEXT("Could not open Registry key HKLM\\%s not found"), REG_KEY); } - error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path)); + error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), NULL); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir)); + error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir), NULL); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string)); + error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string), NULL); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir)); + error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), NULL); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("priority"), priority, sizeof(priority)); + error = GetRegString(key, TEXT("priority"), priority, sizeof(priority), NULL); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("log_append"), append, sizeof(append)); + error = GetRegString(key, TEXT("log_append"), append, sizeof(append), NULL); if (error != ERROR_SUCCESS) { goto out; } /* read if present, else use default */ - error = GetRegString(key, TEXT("ovpn_admin_group"), s->ovpn_admin_group, sizeof(s->ovpn_admin_group)); + error = GetRegString(key, TEXT("ovpn_admin_group"), s->ovpn_admin_group, + sizeof(s->ovpn_admin_group), OVPN_ADMIN_GROUP); if (error != ERROR_SUCCESS) { - openvpn_sntprintf(s->ovpn_admin_group, _countof(s->ovpn_admin_group), OVPN_ADMIN_GROUP); - error = 0; /* this error is not fatal */ + goto out; } /* set process priority */ if (!_tcsicmp(priority, TEXT("IDLE_PRIORITY_CLASS"))) From patchwork Sat Nov 18 06:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 86 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director2.mail.ord1d.rsapps.net ([172.28.255.1]) by backend31.mail.ord1d.rsapps.net (Dovecot) with LMTP id m7OCIuVwEFrRLAAAgoeIoA for ; Sat, 18 Nov 2017 12:41:57 -0500 Received: from director3.mail.ord1c.rsapps.net ([172.28.255.1]) by director2.mail.ord1d.rsapps.net (Dovecot) with LMTP id Jcu4C+VwEFoFDgAAgYhSiA ; Sat, 18 Nov 2017 12:41:57 -0500 Received: from smtp55.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director3.mail.ord1c.rsapps.net (Dovecot) with LMTP id jV6dA+VwEFqJSgAAdSFV8w ; Sat, 18 Nov 2017 12:41:57 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.34.181.88] Authentication-Results: smtp55.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.34.181.88"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Classification-ID: c5d7d112-cc87-11e7-a0f4-b8ca3a5ddb28-1-1 Received: from [216.34.181.88] ([216.34.181.88:37840] helo=lists.sourceforge.net) by smtp55.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 46/7D-05008-5E0701A5; Sat, 18 Nov 2017 12:41:57 -0500 Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.89) (envelope-from ) id 1eG77L-0005cJ-1W; Sat, 18 Nov 2017 17:41:23 +0000 Received: from sfi-mx-1.v28.ch3.sourceforge.com ([172.29.28.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eG77K-0005cD-2n for openvpn-devel@lists.sourceforge.net; Sat, 18 Nov 2017 17:41:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4ld15zzqjOSLBu3ZQX7fgIFeyPLqiRSDTG1WYLi5AiA=; b=mgOLPbh2WIE3kahAkmIKS2SzDT msWe/rT29XhT7nP43XFxALBPz0GTpBXLTJ7Xcn54FtPDWKgnaaHCip5KhA8NjIsJP13ZPAXdif1dw +R5wpazr2SyR3OSTzR6X2a7Su3OzXd33fZG2qM2yS2GNeYVfZtHrXw6ygJV8GDJ4a6l8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4ld15zzqjOSLBu3ZQX7fgIFeyPLqiRSDTG1WYLi5AiA=; b=YQAEqbHd9yAg53rZaWrFVNJw9g ZDfn97fvvP3Xsw/fvIQWwdJClu3KQLvpugIwg0f6CwPOvrr8UATWez7vM2F8zEN1geDdOmJN3tk4f 5Kbgma+LcGU85hZuUC1Ct7p7NUr9NTsHSgSIGnXDATaNHtAqbhRQhaxBq/yeCvvOCZcw=; Received: from mail-io0-f195.google.com ([209.85.223.195]) by sfi-mx-1.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) id 1eG77J-0007cj-8Q for openvpn-devel@lists.sourceforge.net; Sat, 18 Nov 2017 17:41:22 +0000 Received: by mail-io0-f195.google.com with SMTP id 79so4292582ioi.3 for ; Sat, 18 Nov 2017 09:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4ld15zzqjOSLBu3ZQX7fgIFeyPLqiRSDTG1WYLi5AiA=; b=uob4EPOaE+hZwqEoFtsvCDhJX4IyQ7VE3pv6uQhZhsxqe7bE7IAO+jk6TSUl+F69Uk 4G4gLuZGPzb0s2+Ptyggx0R5Dyfba0x85p6RAZycShnJ/Xju8qGHMMqoG1dfn6C8lh6J 7SYdtcbwmcO5PgxWgU1Elg2Ho9OD7r6zxb5+8Q0ijhRZwdUA4vT0XBQP+hOy7i/f1584 xz2sv0L6w5phtA6QhXK2wL0r1f8ne+/38xdGK7iyHVglAbZP828EXhS/1YF1kKU1n9xF mttIn3O51piOK2joy+tOlyg0v7MCi8HhKw/8m7lMPnPdsr1+oR5xDmBKsjmkZ6IajZzr uOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4ld15zzqjOSLBu3ZQX7fgIFeyPLqiRSDTG1WYLi5AiA=; b=Q764GAuozpGrM2ogk8tdGnTT/NRhtbVRnZXdj4Hh1NtonVZcsbamt8hdLS6kVbAFLA 1VzobQhPmv+S4Y/Yogsg+vCdx12Haqt/T+Sa8+mkK+FVOdb8yltofwhQIdPFdesQrMAD F5uxEMOusG/ZetQdSEKC8gBf2cAYIwKT/XAuvP/ou2w6bkU+DVehnecPxrFmZ9I/WW0u dJEJ8I9DZ00CjVPRUaNPMsTIMKfWIIxfUexw/vnS6kynQFwX25eUvPiH8ZeVamWA6mL5 Kr0u9ubXyFYKN+Ifx+WpVPLM9Jq0vQta7laz0XhP2ruCFHhLyHmbJMJASoy9noYhTaUL sQiw== X-Gm-Message-State: AJaThX7JT35vzuFmNiSN8Y/dMWjqCiwtr0ai9+JpSCVbbeBJMub+lhfd UaQpvPSXZ6XV60peMxxP2xUgx2TP X-Google-Smtp-Source: AGs4zMYuqp5fZsBh4xm6XFq3gVaUsCFZvzHGv8AV7aqnyk8V4Ae5N3HBik/gU1q8Z3RvayuOyIxcEQ== X-Received: by 10.107.47.1 with SMTP id j1mr947432ioo.217.1511026875763; Sat, 18 Nov 2017 09:41:15 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.215.92]) by smtp.gmail.com with ESMTPSA id p134sm537169iop.75.2017.11.18.09.41.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Nov 2017 09:41:15 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Sat, 18 Nov 2017 12:40:58 -0500 Message-Id: <1511026858-23281-2-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1511026858-23281-1-git-send-email-selva.nair@gmail.com> References: <1511026858-23281-1-git-send-email-selva.nair@gmail.com> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.223.195 listed in list.dnswl.org] 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.223.195 listed in dnsbl.sorbs.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1eG77J-0007cj-8Q Subject: [Openvpn-devel] [PATCH 2/2] Make most registry values optional X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Selva Nair Not all installations need registry values such as log_dir and config_dir especially if automatic service is not in use. This patch provides reasonable defaults for registry values. - Read the default value of HKLM\Software\PACKAGE_NAME to get the install path and construct defaults for exe_path, config_dir, log_dir from it. Use "ovpn", "0", NORMAL_PRIORITY as the defaults for config file extension, log-append flag and process priority. The only remaining required registry entry is the root key (usually HKLM\Software\OpenVPN) whose default value should be set to the installation path. Signed-off-by: Selva Nair Acked-by: Gert Doering --- src/openvpnserv/common.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index bc99584..759e6a0 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -87,6 +87,8 @@ GetOpenvpnSettings(settings_t *s) TCHAR append[2]; DWORD error; HKEY key; + TCHAR install_path[MAX_PATH]; + TCHAR default_value[MAX_PATH]; LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_KEY, 0, KEY_READ, &key); if (status != ERROR_SUCCESS) @@ -95,37 +97,50 @@ GetOpenvpnSettings(settings_t *s) return MsgToEventLog(M_SYSERR, TEXT("Could not open Registry key HKLM\\%s not found"), REG_KEY); } - error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), NULL); + /* The default value of REG_KEY is the install path */ + if (GetRegString(key, NULL, install_path, sizeof(install_path), NULL) != ERROR_SUCCESS) + { + goto out; + } + + openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\bin\\openvpn.exe"), + install_path); + error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), default_value); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir), NULL); + openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\config"), install_path); + error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir), + default_value); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string), NULL); + error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string), + TEXT(".ovpn")); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), NULL); + openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\log"), install_path); + error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), default_value); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("priority"), priority, sizeof(priority), NULL); + error = GetRegString(key, TEXT("priority"), priority, sizeof(priority), + TEXT("NORMAL_PRIORITY_CLASS")); if (error != ERROR_SUCCESS) { goto out; } - error = GetRegString(key, TEXT("log_append"), append, sizeof(append), NULL); + error = GetRegString(key, TEXT("log_append"), append, sizeof(append), TEXT("0")); if (error != ERROR_SUCCESS) { goto out;