gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/Makefile.am server/Strea...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/Makefile.am server/Strea...
Date: Wed, 23 Aug 2006 23:03:21 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/08/23 23:03:21

Modified files:
        .              : ChangeLog 
        server         : Makefile.am StreamProvider.cpp 
        server/swf     : ASHandlers.cpp 
Added files:
        server         : URLAccessManager.cpp URLAccessManager.h 

Log message:
                * server/swf/ASHandlers.cpp (CommonGetUrl): simplified and fixed
                  URL parsing code by use of the URL class; added check for
                  NULL urls and comments about future improvements; use the
                  newly-exported URLAccessManager::allow function
                * server/URLAccessManager.h, server/URLAccessManager.cpp,
                  server/Makefile.am, server/StreamProvider.cpp:
                  moved URLAccessManager code into it's own file, export a
                  single allow(URL&) function of it, updated StreamProvider
                  accordingly

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.693&r2=1.694
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Makefile.am?cvsroot=gnash&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/gnash/server/StreamProvider.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/server/URLAccessManager.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/server/URLAccessManager.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/ASHandlers.cpp?cvsroot=gnash&r1=1.54&r2=1.55

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.693
retrieving revision 1.694
diff -u -b -r1.693 -r1.694
--- ChangeLog   23 Aug 2006 22:13:18 -0000      1.693
+++ ChangeLog   23 Aug 2006 23:03:21 -0000      1.694
@@ -1,3 +1,15 @@
+2006-08-23 Sandro Santilli  <address@hidden>
+
+       * server/swf/ASHandlers.cpp (CommonGetUrl): simplified and fixed
+         URL parsing code by use of the URL class; added check for
+         NULL urls and comments about future improvements; use the
+         newly-exported URLAccessManager::allow function
+       * server/URLAccessManager.h, server/URLAccessManager.cpp,
+         server/Makefile.am, server/StreamProvider.cpp:
+         moved URLAccessManager code into it's own file, export a
+         single allow(URL&) function of it, updated StreamProvider
+         accordingly
+
 2006-08-23 Markus Gothe <address@hidden>
        
        * server/movie_def_impl.cpp: Use pthread_cancel(pthread_self())

Index: server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/Makefile.am,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- server/Makefile.am  23 Aug 2006 21:30:49 -0000      1.58
+++ server/Makefile.am  23 Aug 2006 23:03:21 -0000      1.59
@@ -107,6 +107,7 @@
        movie_instance.cpp \
         stream.cpp \
         StreamProvider.cpp \
+       URLAccessManager.cpp    \
         styles.cpp \
         tesselate.cpp \
         text.cpp \
@@ -166,6 +167,7 @@
        movie_instance.h \
        stream.h \
        StreamProvider.h        \
+       URLAccessManager.h      \
        styles.h \
        swf.h \
        tesselate.h \

Index: server/StreamProvider.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/StreamProvider.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- server/StreamProvider.cpp   30 Jul 2006 00:11:50 -0000      1.5
+++ server/StreamProvider.cpp   23 Aug 2006 23:03:21 -0000      1.6
@@ -54,15 +54,6 @@
 #include "log.h"
 #include "rc.h" // for rcfile
 
-// temporary use of console for confirm load of network urls
-#include <iostream>
-
-#ifdef WIN32
-#      include <io.h>
-#else
-#      include <unistd.h>
-#endif
-
 #include <cstdio>
 #include <map>
 #include <string>
@@ -71,167 +62,6 @@
 namespace gnash
 {
 
-// stuff for an URLAccessManager
-namespace URLAccessManager {
-
-/// Possible access policies for URLs
-enum AccessPolicy {    
-
-       /// Forbid access 
-       BLOCK,
-
-       /// Allow access
-       GRANT
-};
-
-const char*
-accessPolicyString(AccessPolicy policy)
-{
-       switch(policy)
-       {
-               case BLOCK:
-                       return "BLOCKED";
-               case GRANT:
-                       return "GRANTED";
-               default:
-                       return "UNKNOWN";
-       }
-}
-
-/// The default AccessPolicy when prompting user is not possible
-/// (this happens when input is not a tty, at the moment)
-static AccessPolicy defaultAccessPolicy = GRANT;
-
-/// A cache of AccessPolicy defined for URLs
-typedef std::map< std::string, AccessPolicy > AccessPolicyCache;
-
-/// A global AccessPolicyCache
-static AccessPolicyCache policyCache;
-
-
-/// Is access allowed to given url ?
-/// This function uses the global AccessPolicyCache
-/// so once a policy is defined for an url it will
-/// be remembered for the whole run.
-///
-/// Prompts the user on the tty. If inut is not a tty
-/// uses the global defaultAccessPolicy.
-///
-bool
-allow(std::string& url)
-{
-       // Look in cached policy first
-       AccessPolicyCache::iterator it = policyCache.find(url);
-       if ( it != policyCache.end() )
-       {
-               log_msg("%s access to %s (cached).\n",
-                       accessPolicyString(it->second),
-                       url.c_str());
-
-               return ( it->second == GRANT );
-       }
-
-       if ( ! isatty(fileno(stdin)) )
-       {
-               log_msg("%s access to %s (input is not a terminal).\n",
-                       accessPolicyString(defaultAccessPolicy),
-                       url.c_str());
-
-               // If we can't prompt user return default policy
-               return ( defaultAccessPolicy == GRANT );
-       }
-
-       /// I still don't like this method, typing just
-       /// a newline doesn't spit another prompt
-       std::string yesno;
-       do {
-               std::cout << "Attempt to access url " << url << std::endl;
-               std::cout << "Block it [yes/no] ? "; 
-               std::cin >> yesno;
-       } while (yesno != "yes" && yesno != "no");
-
-       AccessPolicy userChoice;
-
-       if ( yesno == "yes" ) {
-               userChoice = BLOCK;
-       } else {
-               userChoice = GRANT;
-       }
-
-       // cache for next time
-       policyCache[url] = userChoice;
-       
-       log_msg("%s access to %s (user choice).\n",
-               accessPolicyString(userChoice),
-               url.c_str());
-
-       return userChoice;
-
-}
-
-bool
-host_check(const std::string& host)
-{
-    GNASH_REPORT_FUNCTION;
-
-    std::cerr << "Checking security of host: " << host << std::endl;
-    
-    assert(host.size() > 0);
-#if 0
-    if (host.size() == 0) {
-        return true;
-    }
-#endif
-    
-    bool check_domain = rcfile.useLocalDomain();
-    bool check_localhost = rcfile.useLocalHost();
-    char name[200];
-    memset(name, 0, 200);
-    gethostname(name, 200);
-
-    if (check_domain) {
-        char *domain = strchr(name, '.') + 1;
-        if (host != domain) {
-//        throw gnash::GnashException("Not in the local domain!");
-            log_error("Not in the local domain!");
-            return false;
-        }
-    }
-    
-    if (check_localhost) {
-        *(strchr(name, '.')) = 0;
-        if ((host != name) || (host == "localhost")) {
-//        throw gnash::GnashException("Not on the localhost!");
-            log_error("Not on the localhost!");
-            return false;
-        }
-    }
-    
-    std::vector<std::string> whitelist = rcfile.getWhiteList();
-    std::vector<std::string>::iterator it;
-    for (it = whitelist.begin(); it != whitelist.end(); ++it) {
-        if (*it == host) {
-            dbglogfile << "Whitelisted host " << host.c_str() << "!" <<
-               std::endl;
-            return true;
-        }
-    }
-
-    std::vector<std::string> blacklist = rcfile.getBlackList();
-    for (it = blacklist.begin(); it != blacklist.end(); ++it) {
-        if (*it == host) {
-            dbglogfile << "Blacklisted host " << host.c_str() << "!"
-               << std::endl;
-            return false;
-        }
-    }
-    
-    return true;
-}
-
-
-} // AccessManager
-
 tu_file*
 StreamProvider::getStream(const URL& url)
 {
@@ -255,8 +85,8 @@
 #ifdef USE_CURL
                std::string url_str = url.str();
                const char* c_url = url_str.c_str();
-               //if ( URLAccessManager::allow(url_str) ) {
-               if ( URLAccessManager::host_check(url.hostname()) ) {
+               if ( URLAccessManager::allow(url) ) {
+               //if ( URLAccessManager::host_check(url.hostname()) ) {
                        return curl_adapter::make_stream(c_url);
                } else {
                        return NULL;

Index: server/swf/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/ASHandlers.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -b -r1.54 -r1.55
--- server/swf/ASHandlers.cpp   21 Aug 2006 12:54:47 -0000      1.54
+++ server/swf/ASHandlers.cpp   23 Aug 2006 23:03:21 -0000      1.55
@@ -51,6 +51,8 @@
 #include "ActionExec.h"
 #include "sprite_instance.h"
 #include "as_environment.h"
+#include "URL.h"
+#include "URLAccessManager.h" // for GetUrl actions
 
 #include <string>
 #include <map>
@@ -1550,71 +1552,65 @@
 void 
 SWFHandlers::CommonGetUrl(as_environment& env,
                const char* target, // the target window, or _level1..10
-               const char* url,
+               const char* url_c,
                 uint8_t /* method */ // 0:NONE, 1:GET, 2:POST
                )
 {
 
+       assert(target);
+       assert(url_c);
+
+       if ( *url_c == '\0' )
+       {
+               log_warning("Bogus GetUrl2 url (empty) in SWF file, skipping");
+               return;
+       }
+
        // If the url starts with "FSCommand:", then this is
        // a message for the host app.
-       if (strncmp(url, "FSCommand:", 10) == 0)
+       if (strncmp(url_c, "FSCommand:", 10) == 0)
        {
                if (s_fscommand_handler)
                {
                        // Call into the app.
-                       
(*s_fscommand_handler)(env.get_target()->get_root_interface(), url + 10, 
target);
+                       
(*s_fscommand_handler)(env.get_target()->get_root_interface(), url_c + 10, 
target);
                }
        }
        else
        {
+               string url_s(url_c);
+
+               // @@ TODO: find out how should 'relative' urls be
+               //          resolved (against who? target or self?)
+
+               URL url(url_s);
+
+               log_msg("get url: target=%s, url=%s (%s)", target,
+                       url.str().c_str(), url_c);
+
+                // Check host security
+               if ( ! URLAccessManager::allow(url) )
+               {
+                       return;
+               }
+
 #ifdef EXTERN_MOVIE
-//             log_error("get url2: target=%s, url=%s", target, url);
+//             log_msg("get url: target=%s, url=%s", target, url_c);
                      
                character* target_movie = env.find_target(target);
                if (target_movie != NULL)
                {
                        sprite_instance* root_movie = 
env.get_target()->get_root_movie();
-                       attach_extern_movie(url, target_movie, root_movie);
+                       attach_extern_movie(url_c, target_movie, root_movie);
                }
                else
                {
                        log_error("get url2: target %s not found", target);
                }
 #else
-                // Strip the hostname off the URL and make sure it's
-                // not on the blacklist. For Blacklisted items, we
-                // ignor all attempts by the movie to allow the
-                // external domain.
-                string::size_type first_colon;
-                string::size_type second_colon;
-                string::size_type single_slash;
-                string::size_type double_slash;
-                
-                // protocol:[//host][:port]/appname/[instanceName]
-                string urlstr = url;
-                string host;
-                first_colon = urlstr.find(':', 0);
-                second_colon = urlstr.find(':', first_colon + 1);
-                double_slash = urlstr.find("//", 0) + 2;
-                single_slash = urlstr.find("/", double_slash);
-                if (second_colon != string::npos) {
-                    host = urlstr.substr(double_slash, second_colon - 
double_slash);
-                } else {
-                    host = urlstr.substr(double_slash, single_slash - 
double_slash);
-                } 
-
-                std::vector<std::string>::iterator it;
-                std::vector<std::string> blacklist = rcfile.getBlackList();
-                for (it = blacklist.begin(); it != blacklist.end(); ++it) {
-                    if (*it == host) {
-                        dbglogfile << "Blacklisted host " << host.c_str() << 
"!"
-                                   << std::endl;
-                        return;
-                    }
-                }
                 
                 string command = "firefox -remote \"openurl(";
-                command += url;
+                command += url.str();
                 command += ")\"";
                 dbglogfile << "Launching URL... " << command << endl;
                 system(command.c_str());
@@ -1646,7 +1642,6 @@
 
        const char*     target = env.top(0).to_string();
        const char*     url = env.top(1).to_string();
-
        CommonGetUrl(env, target, url, method);
                  
        env.drop(2);

Index: server/URLAccessManager.cpp
===================================================================
RCS file: server/URLAccessManager.cpp
diff -N server/URLAccessManager.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ server/URLAccessManager.cpp 23 Aug 2006 23:03:21 -0000      1.1
@@ -0,0 +1,233 @@
+// 
+//   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+// 
+//
+//
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "URLAccessManager.h"
+#include "URL.h"
+#include "log.h"
+#include "rc.h" // for rcfile
+
+// temporary use of console for confirm load of network urls
+#include <iostream>
+
+#ifdef WIN32
+#      include <io.h>
+#else
+#      include <unistd.h>
+#endif
+
+#include <cstdio>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace gnash {
+namespace URLAccessManager {
+
+/// Possible access policies for URLs
+enum AccessPolicy {    
+
+       /// Forbid access 
+       BLOCK,
+
+       /// Allow access
+       GRANT
+};
+
+const char*
+accessPolicyString(AccessPolicy policy)
+{
+       switch(policy)
+       {
+               case BLOCK:
+                       return "BLOCKED";
+               case GRANT:
+                       return "GRANTED";
+               default:
+                       return "UNKNOWN";
+       }
+}
+
+// The default AccessPolicy when prompting user is not possible
+// (this happens when input is not a tty, at the moment)
+//static AccessPolicy defaultAccessPolicy = GRANT;
+
+/// A cache of AccessPolicy defined for URLs
+typedef std::map< std::string, AccessPolicy > AccessPolicyCache;
+
+/// A global AccessPolicyCache
+static AccessPolicyCache policyCache;
+
+
+#if 0 // @@ this function has been replaced with a wrapper around host_check
+
+// Is access allowed to given url ?
+// This function uses the global AccessPolicyCache
+// so once a policy is defined for an url it will
+// be remembered for the whole run.
+//
+// Prompts the user on the tty. If inut is not a tty
+// uses the global defaultAccessPolicy.
+//
+static bool
+allow(std::string& url)
+{
+       // Look in cached policy first
+       AccessPolicyCache::iterator it = policyCache.find(url);
+       if ( it != policyCache.end() )
+       {
+               log_msg("%s access to %s (cached).\n",
+                       accessPolicyString(it->second),
+                       url.c_str());
+
+               return ( it->second == GRANT );
+       }
+
+       if ( ! isatty(fileno(stdin)) )
+       {
+               log_msg("%s access to %s (input is not a terminal).\n",
+                       accessPolicyString(defaultAccessPolicy),
+                       url.c_str());
+
+               // If we can't prompt user return default policy
+               return ( defaultAccessPolicy == GRANT );
+       }
+
+       /// I still don't like this method, typing just
+       /// a newline doesn't spit another prompt
+       std::string yesno;
+       do {
+               std::cout << "Attempt to access url " << url << std::endl;
+               std::cout << "Block it [yes/no] ? "; 
+               std::cin >> yesno;
+       } while (yesno != "yes" && yesno != "no");
+
+       AccessPolicy userChoice;
+
+       if ( yesno == "yes" ) {
+               userChoice = BLOCK;
+       } else {
+               userChoice = GRANT;
+       }
+
+       // cache for next time
+       policyCache[url] = userChoice;
+       
+       log_msg("%s access to %s (user choice).\n",
+               accessPolicyString(userChoice),
+               url.c_str());
+
+       return userChoice;
+
+}
+#endif
+
+static bool
+host_check(const std::string& host)
+{
+    GNASH_REPORT_FUNCTION;
+
+    std::cerr << "Checking security of host: " << host << std::endl;
+    
+    assert(host.size() > 0);
+#if 0
+    if (host.size() == 0) {
+        return true;
+    }
+#endif
+    
+    bool check_domain = rcfile.useLocalDomain();
+    bool check_localhost = rcfile.useLocalHost();
+    char name[200];
+    memset(name, 0, 200);
+    gethostname(name, 200);
+
+    if (check_domain) {
+        char *domain = strchr(name, '.') + 1;
+        if (host != domain) {
+//        throw gnash::GnashException("Not in the local domain!");
+            log_error("Not in the local domain!");
+            return false;
+        }
+    }
+    
+    if (check_localhost) {
+        *(strchr(name, '.')) = 0;
+        if ((host != name) || (host == "localhost")) {
+//        throw gnash::GnashException("Not on the localhost!");
+            log_error("Not on the localhost!");
+            return false;
+        }
+    }
+    
+    std::vector<std::string> whitelist = rcfile.getWhiteList();
+    std::vector<std::string>::iterator it;
+    for (it = whitelist.begin(); it != whitelist.end(); ++it) {
+        if (*it == host) {
+            dbglogfile << "Whitelisted host " << host.c_str() << "!" <<
+               std::endl;
+            return true;
+        }
+    }
+
+    std::vector<std::string> blacklist = rcfile.getBlackList();
+    for (it = blacklist.begin(); it != blacklist.end(); ++it) {
+        if (*it == host) {
+            dbglogfile << "Blacklisted host " << host.c_str() << "!"
+               << std::endl;
+            return false;
+        }
+    }
+    
+    return true;
+}
+
+bool
+allow(const URL& url)
+{
+       // We might reintroduce use of an AccessPolicy cache
+       return host_check(url.hostname());
+}
+
+
+} // AccessManager
+} // namespace gnash
+

Index: server/URLAccessManager.h
===================================================================
RCS file: server/URLAccessManager.h
diff -N server/URLAccessManager.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ server/URLAccessManager.h   23 Aug 2006 23:03:21 -0000      1.1
@@ -0,0 +1,62 @@
+// 
+//   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+// 
+//
+
+#ifndef _GNASH_URLACCESSMANAGER_H
+#define _GNASH_URLACCESSMANAGER_H
+
+// Forward declarations
+namespace gnash {
+       class URL;
+}
+
+namespace gnash {
+
+/// Manage a list of URL access configuration
+// stuff for an URLAccessManager
+namespace URLAccessManager {
+
+/// Return true if access to given url is allowed, false otherwise.
+//
+/// Will use rc file for whitelist/blacklist.
+///
+bool allow(const URL& url);
+
+} // AccessManager
+
+} // namespace gnash
+
+#endif // _GNASH_URLACCESSMANAGER_H




reply via email to

[Prev in Thread] Current Thread [Next in Thread]