~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to kexi/scripting/kexidb/kexidbdrivermanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 * kexidbdrivermanager.cpp
 
3
 * This file is part of the KDE project
 
4
 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 * You should have received a copy of the GNU Library General Public License
 
15
 * along with this program; see the file COPYING.  If not, write to
 
16
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 ***************************************************************************/
 
19
 
 
20
#include "kexidbdrivermanager.h"
 
21
#include "kexidbdriver.h"
 
22
#include "kexidbconnectiondata.h"
 
23
#include "kexidbfield.h"
 
24
#include "kexidbschema.h"
 
25
 
 
26
#include "../api/exception.h"
 
27
 
 
28
#include <qguardedptr.h>
 
29
#include <klocale.h>
 
30
#include <kdebug.h>
 
31
 
 
32
#include <kexidb/driver.h>
 
33
#include <kexidb/connectiondata.h>
 
34
#include <kexidb/field.h>
 
35
#include <kexidb/tableschema.h>
 
36
#include <kexidb/queryschema.h>
 
37
 
 
38
using namespace Kross::KexiDB;
 
39
 
 
40
KexiDBDriverManager::KexiDBDriverManager()
 
41
    : Kross::Api::Class<KexiDBDriverManager>("KexiDBDriverManager")
 
42
{
 
43
    addFunction("driverNames", &KexiDBDriverManager::driverNames,
 
44
        Kross::Api::ArgumentList(),
 
45
        i18n("Returns a stringlist of all available drivernames.")
 
46
    );
 
47
    addFunction("driver", &KexiDBDriverManager::driver,
 
48
        Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
 
49
        i18n("Returns the to name matching KexiDBDriver object.")
 
50
    );
 
51
    addFunction("lookupByMime", &KexiDBDriverManager::lookupByMime,
 
52
        Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
 
53
        i18n("Looks up a drivers list by MIME type of database file. "
 
54
             "Only file-based database drivers are checked. "
 
55
             "The lookup is case insensitive.")
 
56
    );
 
57
 
 
58
    addFunction("connectionData", &KexiDBDriverManager::connectionData,
 
59
        Kross::Api::ArgumentList(),
 
60
        i18n("Return a new KexiDBConnectionData object.")
 
61
    );
 
62
    addFunction("field", &KexiDBDriverManager::field,
 
63
        Kross::Api::ArgumentList(),
 
64
        i18n("Return a new KexiDBField object.")
 
65
    );
 
66
    addFunction("tableSchema", &KexiDBDriverManager::tableSchema,
 
67
        Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
 
68
        i18n("Return a new KexiDBTableSchema object.")
 
69
    );
 
70
    addFunction("querySchema", &KexiDBDriverManager::querySchema,
 
71
        Kross::Api::ArgumentList(),
 
72
        i18n("Return a new KexiDBQuerySchema object.")
 
73
    );
 
74
}
 
75
 
 
76
KexiDBDriverManager::~KexiDBDriverManager()
 
77
{
 
78
}
 
79
 
 
80
const QString KexiDBDriverManager::getClassName() const
 
81
{
 
82
    return "Kross::KexiDB::KexiDBDriverManager";
 
83
}
 
84
 
 
85
const QString KexiDBDriverManager::getDescription() const
 
86
{
 
87
    return i18n("KexiDB::DriverManager wrapper for database driver "
 
88
                "management, e.g. finding and loading drivers.");
 
89
}
 
90
 
 
91
KexiDB::DriverManager& KexiDBDriverManager::driverManager()
 
92
{
 
93
    if(m_drivermanager.error())
 
94
        throw Kross::Api::RuntimeException(i18n("KexiDB::DriverManager error: %1").arg(m_drivermanager.errorMsg()));
 
95
    return m_drivermanager;
 
96
}
 
97
 
 
98
Kross::Api::Object* KexiDBDriverManager::driverNames(Kross::Api::List*)
 
99
{
 
100
    return Kross::Api::Variant::create(driverManager().driverNames(), "Kross::KexiDB::DriverManager::driverNames::StringList");
 
101
}
 
102
 
 
103
Kross::Api::Object* KexiDBDriverManager::driver(Kross::Api::List* args)
 
104
{
 
105
    QString drivername = Kross::Api::Variant::toString(args->item(0));
 
106
    QGuardedPtr< ::KexiDB::Driver > driver = driverManager().driver(drivername); // caching is done by the DriverManager
 
107
    if(! driver)
 
108
        throw Kross::Api::AttributeException(i18n("No such KexiDB::Driver object for the defined drivername '%1'.").arg(drivername));
 
109
    if(driver->error())
 
110
        throw Kross::Api::RuntimeException(i18n("KexiDB::Driver error for drivername '%1': %2").arg(drivername).arg(driver->errorMsg()));
 
111
    return new KexiDBDriver(this, driver);
 
112
}
 
113
 
 
114
Kross::Api::Object* KexiDBDriverManager::lookupByMime(Kross::Api::List* args)
 
115
{
 
116
    return Kross::Api::Variant::create(
 
117
        driverManager().lookupByMime( Kross::Api::Variant::toString(args->item(0)) ),
 
118
        "Kross::KexiDB::DriverManager::lookupByMime::String");
 
119
}
 
120
 
 
121
Kross::Api::Object* KexiDBDriverManager::connectionData(Kross::Api::List*)
 
122
{
 
123
    return new KexiDBConnectionData( new ::KexiDB::ConnectionData() );
 
124
}
 
125
 
 
126
Kross::Api::Object* KexiDBDriverManager::field(Kross::Api::List*)
 
127
{
 
128
    return new KexiDBField( new ::KexiDB::Field() );
 
129
}
 
130
 
 
131
Kross::Api::Object* KexiDBDriverManager::tableSchema(Kross::Api::List* args)
 
132
{
 
133
    return new KexiDBTableSchema(
 
134
               new ::KexiDB::TableSchema(Kross::Api::Variant::toString(args->item(0)))
 
135
           );
 
136
}
 
137
 
 
138
Kross::Api::Object* KexiDBDriverManager::querySchema(Kross::Api::List*)
 
139
{
 
140
    return new KexiDBQuerySchema( new ::KexiDB::QuerySchema() );
 
141
}
 
142