[Vm-dev] [commit][3130] Merge Levente'
s recent changes to DNS lookup on Windows and SSL on Unix.
commits at squeakvm.org
commits at squeakvm.org
Wed Nov 12 19:52:37 UTC 2014
Revision: 3130
Author: eliot
Date: 2014-11-12 11:52:35 -0800 (Wed, 12 Nov 2014)
Log Message:
-----------
Merge Levente's recent changes to DNS lookup on Windows and SSL on Unix.
See http://squeakvm.org/cgi-bin/viewvc.cgi/squeak?view=revision&revision=2249
http://bugs.squeak.org/view.php?id=7824
Modified Paths:
--------------
branches/Cog/platforms/unix/plugins/SqueakSSL/sqUnixOpenSSL.c
branches/Cog/platforms/win32/vm/sqWin32Exports.c
Added Paths:
-----------
branches/Cog/platforms/win32/vm/sqWin32DnsInfo.c
Property Changed:
----------------
branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
Property changes on: branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
___________________________________________________________________
Modified: checkindate
- Mon Nov 10 10:34:43 PST 2014
+ Wed Nov 12 11:52:26 PST 2014
Modified: branches/Cog/platforms/unix/plugins/SqueakSSL/sqUnixOpenSSL.c
===================================================================
--- branches/Cog/platforms/unix/plugins/SqueakSSL/sqUnixOpenSSL.c 2014-11-10 18:34:19 UTC (rev 3129)
+++ branches/Cog/platforms/unix/plugins/SqueakSSL/sqUnixOpenSSL.c 2014-11-12 19:52:35 UTC (rev 3130)
@@ -11,6 +11,7 @@
char *certName;
char *peerName;
+ char *serverName;
SSL_METHOD *method;
SSL_CTX *ctx;
@@ -135,6 +136,7 @@
if(ssl->certName) free(ssl->certName);
if(ssl->peerName) free(ssl->peerName);
+ if(ssl->serverName) free(ssl->serverName);
free(ssl);
handleBuf[handle] = NULL;
@@ -184,6 +186,13 @@
if(ssl->loglevel) printf("sqConnectSSL: BIO_write failed\n");
return SQSSL_GENERIC_ERROR;
}
+
+ /* if a server name is provided, use it */
+ if(ssl->serverName) {
+ if(ssl->loglevel) printf("sqSetupSSL: Using server name %s\n", ssl->serverName);
+ SSL_set_tlsext_host_name(ssl->ssl, ssl->serverName);
+ }
+
if(ssl->loglevel) printf("sqConnectSSL: SSL_connect\n");
result = SSL_connect(ssl->ssl);
if(result <= 0) {
@@ -370,6 +379,7 @@
switch(propID) {
case SQSSL_PROP_PEERNAME: return ssl->peerName;
case SQSSL_PROP_CERTNAME: return ssl->certName;
+ case SQSSL_PROP_SERVERNAME: return ssl->serverName;
default:
if(ssl->loglevel) printf("sqGetStringPropertySSL: Unknown property ID %d\n", propID);
return NULL;
@@ -392,14 +402,22 @@
if(ssl == NULL) return 0;
if(propLen) {
- property = calloc(1, propLen+1);
- memcpy(property, propName, propLen);
+ property = malloc(propLen + 1);
+ memcpy(property, propName, propLen);
+ property[propLen] = '\0';
};
if(ssl->loglevel) printf("sqSetStringPropertySSL(%d): %s\n", propID, property);
switch(propID) {
- case SQSSL_PROP_CERTNAME: ssl->certName = property; break;
+ case SQSSL_PROP_CERTNAME:
+ if (ssl->certName) free(ssl->certName);
+ ssl->certName = property;
+ break;
+ case SQSSL_PROP_SERVERNAME:
+ if (ssl->serverName) free(ssl->serverName);
+ ssl->serverName = property;
+ break;
default:
if(property) free(property);
if(ssl->loglevel) printf("sqSetStringPropertySSL: Unknown property ID %d\n", propID);
Copied: branches/Cog/platforms/win32/vm/sqWin32DnsInfo.c (from rev 3129, trunk/platforms/win32/vm/sqWin32DnsInfo.c)
===================================================================
--- branches/Cog/platforms/win32/vm/sqWin32DnsInfo.c (rev 0)
+++ branches/Cog/platforms/win32/vm/sqWin32DnsInfo.c 2014-11-12 19:52:35 UTC (rev 3130)
@@ -0,0 +1,180 @@
+/* sqWin32DnsInfo.c: Gathers DNS information on Windows */
+#include <windows.h>
+#include "sq.h"
+
+extern struct VirtualMachine *interpreterProxy;
+#define vm interpreterProxy
+
+/* Large enough since we only use 3 entries with 1k bytes max */
+static char buf[20000];
+
+static char* lookup(HKEY hk, char *key) {
+ static char buf[1000];
+ DWORD dwLength, ret;
+ dwLength = sizeof(buf)-1;
+ *buf = 0;
+ ret = RegQueryValueEx(hk, key, NULL, NULL, buf, &dwLength);
+ if(buf[dwLength]) buf[dwLength] = 0;
+ return buf;
+}
+
+/* Print base registry info. Return true if DNS info was provided. */
+static int printBaseInfo(char *hkeyName) {
+ HKEY hkey;
+ DWORD ret;
+ char *value;
+ int result = 0;
+
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, hkeyName, 0, KEY_READ, &hkey);
+ if(ret != ERROR_SUCCESS) {
+ printf("RegOpenKeyEx failed\n");
+ return vm->primitiveFail();
+ }
+
+ /* Provide Hostname info if present */
+ value = lookup(hkey, "Hostname");
+ if(*value) {
+ strcat(buf, "\nhostname ");
+ strcat(buf, value);
+ }
+
+ /* The list of suffixes to search */
+ value = lookup(hkey, "SearchList");
+ if(*value) {
+ strcat(buf, "\nsearch ");
+ strcat(buf, value);
+ }
+
+ /* The (static or dhcp) domain */
+ value = lookup(hkey, "Domain");
+ if(*value) {
+ strcat(buf, "\ndomain ");
+ strcat(buf, value);
+ strcat(buf, " # static");
+ } else {
+ value = lookup(hkey, "DhcpDomain");
+ if(*value) {
+ strcat(buf, "\ndomain ");
+ strcat(buf, value);
+ strcat(buf, " # dhcp");
+ }
+ }
+
+ /* And the (static or dhcp) configured name servers */
+ value = lookup(hkey, "NameServer");
+ if(*value) {
+ strcat(buf, "\nnameserver ");
+ strcat(buf, value);
+ strcat(buf, " # static");
+ result = 1;
+ } else {
+ value = lookup(hkey, "DhcpNameServer");
+ if(*value) {
+ strcat(buf, "\nnameserver ");
+ strcat(buf, value);
+ strcat(buf, " # dhcp");
+ result = 1;
+ }
+ }
+ RegCloseKey(hkey);
+ return result;
+}
+
+static int printAdapterInfo(char *hkeyName) {
+ HKEY hkey;
+ DWORD ret;
+ char *value;
+ int result = 0;
+
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, hkeyName, 0, KEY_READ, &hkey);
+ if(ret != ERROR_SUCCESS) {
+ printf("RegOpenKeyEx failed\n");
+ return vm->primitiveFail();
+ }
+
+ /* Provide interface address if present */
+ value = lookup(hkey, "IPAddress");
+ if(*value && strcmp(value, "0.0.0.0")) {
+ /* Skip interface info since we can't currently determine
+ if the information is correct or a dead adapter */
+#if 0
+ strcat(buf, "\ninterface ");
+ strcat(buf, value);
+ strcat(buf, " # static");
+#endif
+ } else {
+ value = lookup(hkey, "DhcpIPAddress");
+ if(*value && strcmp(value, "0.0.0.0")) {
+#if 0
+ strcat(buf, "\ninterface ");
+ strcat(buf, value);
+ strcat(buf, " # dhcp ");
+#endif
+ } else {
+ /* Don't bother printing DNS for an adapter w/o IP */
+ goto done;
+ }
+ }
+
+ /* Print the (static or dhcp) configured name servers */
+ value = lookup(hkey, "NameServer");
+ if(*value) {
+ strcat(buf, "\nnameserver ");
+ strcat(buf, value);
+ strcat(buf, " # static");
+ result = 1;
+ } else {
+ value = lookup(hkey, "DhcpNameServer");
+ if(*value) {
+ strcat(buf, "\nnameserver ");
+ strcat(buf, value);
+ strcat(buf, " # dhcp");
+ result = 1;
+ }
+ }
+
+ done:
+ RegCloseKey(hkey);
+ return result;
+}
+
+#define BASE_KEY \
+ "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces"
+
+EXPORT(int) primitiveDnsInfo(void) {
+ HKEY hkey;
+ sqInt sz, stroop;
+ DWORD dwLength, ret, index;
+ char adapter[1024];
+
+ *buf = 0;
+ strcat(buf, "# Global config settings");
+
+ /* Print the global options */
+ if(printBaseInfo("SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters")) {
+ /* If we have DNS entries globally, skip enumerating all interfaces */
+ goto done;
+ }
+
+ /* Enumerate the available interfaces */
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, BASE_KEY, 0, KEY_READ, &hkey);
+ for(index=0;;index++) {
+ char keyName[1024];
+ dwLength = sizeof(adapter);
+ ret = RegEnumKeyEx(hkey, index, adapter, &dwLength, NULL, NULL, NULL, NULL);
+ if(ret != ERROR_SUCCESS) break;
+ strcpy(keyName, BASE_KEY);
+ strcat(keyName, "\\");
+ strcat(keyName, adapter);
+ /* Should look up and print the adapter name */
+ printAdapterInfo(keyName);
+ }
+
+ done:
+ sz = strlen(buf);
+ stroop = vm->instantiateClassindexableSize(vm->classString(), sz);
+ if(!vm->failed()) {
+ memcpy(vm->firstIndexableField(stroop), buf, sz);
+ vm->popthenPush(vm->methodArgumentCount()+1, stroop);
+ }
+}
Modified: branches/Cog/platforms/win32/vm/sqWin32Exports.c
===================================================================
--- branches/Cog/platforms/win32/vm/sqWin32Exports.c 2014-11-10 18:34:19 UTC (rev 3129)
+++ branches/Cog/platforms/win32/vm/sqWin32Exports.c 2014-11-12 19:52:35 UTC (rev 3130)
@@ -15,6 +15,7 @@
int primitivePluginRequestFileHandle(void);
int primitivePluginDestroyRequest(void);
int primitivePluginRequestState(void);
+int primitiveDnsInfo(void);
extern void* stWindow;
extern void* firstMessageHook;
@@ -36,6 +37,7 @@
{"","primitivePluginRequestFileHandle", primitivePluginRequestFileHandle},
{"","primitivePluginDestroyRequest", primitivePluginDestroyRequest},
{"","primitivePluginRequestState", primitivePluginRequestState},
+ {"","primitiveDnsInfo", primitiveDnsInfo},
{"","printf", printf},
{"","stWindow", &stWindow},
{"","firstMessageHook", &firstMessageHook},
More information about the Vm-dev
mailing list