~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to tosecurity.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****
2
 
*
3
 
* TOra - An Oracle Toolkit for DBA's and developers
4
 
* Copyright (C) 2003-2005 Quest Software, Inc
5
 
* Portions Copyright (C) 2005 Other Contributors
6
 
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation;  only version 2 of
10
 
* the License is valid for this program.
11
 
12
 
* This program is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
* GNU General Public License for more details.
16
 
17
 
* You should have received a copy of the GNU General Public License
18
 
* along with this program; if not, write to the Free Software
19
 
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*
21
 
*      As a special exception, you have permission to link this program
22
 
*      with the Oracle Client libraries and distribute executables, as long
23
 
*      as you follow the requirements of the GNU GPL in regard to all of the
24
 
*      software in the executable aside from Oracle client libraries.
25
 
*
26
 
*      Specifically you are not permitted to link this program with the
27
 
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
 
*      And you are not permitted to distribute binaries compiled against
29
 
*      these libraries without written consent from Quest Software, Inc.
30
 
*      Observe that this does not disallow linking to the Qt Free Edition.
31
 
*
32
 
*      You may link this product with any GPL'd Qt library such as Qt/Free
33
 
*
34
 
* All trademarks belong to their respective owners.
35
 
*
36
 
*****/
37
 
 
38
 
#include "utils.h"
39
 
 
40
 
#include "tochangeconnection.h"
41
 
#include "toconf.h"
42
 
#include "toconnection.h"
43
 
#include "tofilesize.h"
44
 
#include "tomain.h"
45
 
#include "tomemoeditor.h"
46
 
#include "toresultview.h"
47
 
#include "tosecurity.h"
48
 
#include "tosql.h"
49
 
#include "totool.h"
50
 
 
51
 
#ifdef TO_KDE
52
 
#  include <kmenubar.h>
53
 
#endif
54
 
 
55
 
#include <qcheckbox.h>
56
 
#include <qcombobox.h>
57
 
#include <qlabel.h>
58
 
#include <qlineedit.h>
59
 
#include <qmenubar.h>
60
 
#include <qmessagebox.h>
61
 
#include <qpopupmenu.h>
62
 
#include <qradiobutton.h>
63
 
#include <qsplitter.h>
64
 
#include <qstringlist.h>
65
 
#include <qtabwidget.h>
66
 
#include <qtoolbar.h>
67
 
#include <qtoolbutton.h>
68
 
#include <qvalidator.h>
69
 
#include <qworkspace.h>
70
 
 
71
 
#include "tosecurity.moc"
72
 
#include "tosecurityquotaui.moc"
73
 
#include "tosecurityroleui.moc"
74
 
#include "tosecurityuserui.moc"
75
 
 
76
 
#include "icons/addrole.xpm"
77
 
#include "icons/adduser.xpm"
78
 
#include "icons/commit.xpm"
79
 
#include "icons/copyuser.xpm"
80
 
#include "icons/refresh.xpm"
81
 
#include "icons/sql.xpm"
82
 
#include "icons/tosecurity.xpm"
83
 
#include "icons/trash.xpm"
84
 
 
85
 
static toSQL SQLUserInfo("toSecurity:UserInfo",
86
 
                         "SELECT Account_Status,\n"
87
 
                         "       Password,\n"
88
 
                         "       External_Name,\n"
89
 
                         "       Profile,\n"
90
 
                         "       Default_Tablespace,\n"
91
 
                         "       Temporary_Tablespace\n"
92
 
                         "  FROM sys.DBA_Users\n"
93
 
                         " WHERE UserName = :f1<char[100]>",
94
 
                         "Get information about a user, must have same columns and same binds.");
95
 
 
96
 
static toSQL SQLUserInfo7("toSecurity:UserInfo",
97
 
                          "SELECT 'OPEN',\n"
98
 
                          "       Password,\n"
99
 
                          "       NULL,\n"
100
 
                          "       Profile,\n"
101
 
                          "       Default_Tablespace,\n"
102
 
                          "       Temporary_Tablespace\n"
103
 
                          "  FROM sys.DBA_Users\n"
104
 
                          " WHERE UserName = :f1<char[100]>",
105
 
                          "",
106
 
                          "0703");
107
 
 
108
 
static toSQL SQLRoleInfo("toSecurity:RoleInfo",
109
 
                         "SELECT Role,Password_required FROM sys.DBA_Roles WHERE Role = :f1<char[101]>",
110
 
                         "Get information about a role, must have same columns and same binds.");
111
 
 
112
 
static toSQL SQLProfiles("toSecurity:Profiles",
113
 
                         "SELECT DISTINCT Profile FROM sys.DBA_Profiles ORDER BY Profile",
114
 
                         "Get profiles available.");
115
 
 
116
 
static toSQL SQLTablespace("toSecurity:Tablespaces",
117
 
                           "SELECT DISTINCT Tablespace_Name FROM sys.DBA_Tablespaces"
118
 
                           " ORDER BY Tablespace_Name",
119
 
                           "Get tablespaces available.");
120
 
 
121
 
static toSQL SQLRoles("toSecurity:Roles",
122
 
                      "SELECT Role FROM sys.Dba_Roles ORDER BY Role",
123
 
                      "Get roles available in DB, should return one entry");
124
 
 
125
 
static toSQL SQLListSystem("toSecurity:ListSystemPrivs",
126
 
                           "SELECT a.name\n"
127
 
                           "  FROM system_privilege_map a,\n"
128
 
                           "       v$enabledprivs b\n"
129
 
                           " WHERE b.priv_number = a.privilege\n"
130
 
                           " ORDER BY a.name",
131
 
                           "Get name of available system privileges");
132
 
 
133
 
static toSQL SQLQuota("toSecurity:Quota",
134
 
                      "SELECT Tablespace_name,\n"
135
 
                      "       Bytes,\n"
136
 
                      "       Max_bytes\n"
137
 
                      "  FROM sys.DBA_TS_Quotas\n"
138
 
                      " WHERE Username = :f1<char[200]>\n"
139
 
                      " ORDER BY Tablespace_name",
140
 
                      "Get information about what quotas the user has, "
141
 
                      "must have same columns and same binds.");
142
 
 
143
 
static toSQL SQLSystemGrant("toSecurity:SystemGrant",
144
 
                            "SELECT privilege, NVL(admin_option,'NO') FROM sys.dba_sys_privs WHERE grantee = :f1<char[100]>",
145
 
                            "Get information about the system privileges a user has, should have same bindings and columns");
146
 
 
147
 
static toSQL SQLObjectPrivs("toSecurity:ObjectPrivs",
148
 
                            "SELECT DECODE(:type<char[100]>,'FUNCTION','EXECUTE',\n"
149
 
                            "          'LIBRARY','EXECUTE',\n"
150
 
                            "          'PACKAGE','EXECUTE',\n"
151
 
                            "          'PROCEDURE','EXECUTE',\n"
152
 
                            "          'SEQUENCE','ALTER,SELECT',\n"
153
 
                            "          'TABLE','ALTER,DELETE,INDEX,INSERT,REFERENCES,SELECT,UPDATE',\n"
154
 
                            "          'TYPE','EXECUTE',\n"
155
 
                            "          'VIEW','DELETE,SELECT,INSERT,UPDATE',\n"
156
 
                            "          'OPERATOR','EXECUTE',\n"
157
 
                            "          'DIRECTORY','READ',\n"
158
 
                            "          NULL) FROM sys.DUAL",
159
 
                            "Takes a type as parameter and return ',' separated list of privileges");
160
 
 
161
 
static toSQL SQLObjectGrant("toSecurity:ObjectGrant",
162
 
                            "SELECT owner,\n"
163
 
                            "       table_name,\n"
164
 
                            "       privilege,\n"
165
 
                            "       grantable\n"
166
 
                            "  FROM sys.dba_tab_privs\n"
167
 
                            " WHERE grantee = :f1<char[100]>",
168
 
                            "Get the privilege on objects for a user or role, "
169
 
                            "must have same columns and binds");
170
 
 
171
 
static toSQL SQLRoleGrant("toSecurity:RoleGrant",
172
 
                          "SELECT granted_role,\n"
173
 
                          "       admin_option,\n"
174
 
                          "       default_role\n"
175
 
                          "  FROM sys.dba_role_privs\n"
176
 
                          " WHERE grantee = :f1<char[100]>",
177
 
                          "Get the roles granted to a user or role, "
178
 
                          "must have same columns and binds");
179
 
 
180
 
class toSecurityTool : public toTool
181
 
{
182
 
protected:
183
 
    virtual const char **pictureXPM(void)
184
 
    {
185
 
        return const_cast<const char**>(tosecurity_xpm);
186
 
    }
187
 
public:
188
 
    toSecurityTool()
189
 
            : toTool(40, "Security Manager")
190
 
    { }
191
 
    virtual const char *menuItem()
192
 
    {
193
 
        return "Security Manager";
194
 
    }
195
 
    virtual QWidget *toolWindow(QWidget *parent, toConnection &connection)
196
 
    {
197
 
        return new toSecurity(parent, connection);
198
 
    }
199
 
};
200
 
 
201
 
static toSecurityTool SecurityTool;
202
 
 
203
 
class toSecurityQuota : public toSecurityQuotaUI
204
 
{
205
 
    QListViewItem *CurrentItem;
206
 
    void clearItem(QListViewItem *item);
207
 
    virtual void changeTablespace(void);
208
 
    virtual void changeSize(void);
209
 
public:
210
 
    toSecurityQuota(QWidget *parent);
211
 
    void changeUser(const QString &);
212
 
    QString sql(void);
213
 
    void clear(void);
214
 
    void update(void);
215
 
};
216
 
 
217
 
void toSecurityQuota::changeSize(void)
218
 
{
219
 
    if (CurrentItem)
220
 
    {
221
 
        if (Value->isChecked())
222
 
        {
223
 
            QString siz;
224
 
            siz.sprintf("%.0f KB", double(Size->value()));
225
 
            CurrentItem->setText(1, siz);
226
 
        }
227
 
        else if (None->isChecked())
228
 
        {
229
 
            CurrentItem->setText(1, qApp->translate("toSecurityQuota", "None"));
230
 
        }
231
 
        else if (Unlimited->isChecked())
232
 
        {
233
 
            CurrentItem->setText(1, qApp->translate("toSecurityQuota", "Unlimited"));
234
 
        }
235
 
    }
236
 
    else
237
 
        SizeGroup->setEnabled(false);
238
 
}
239
 
 
240
 
toSecurityQuota::toSecurityQuota(QWidget *parent)
241
 
        : toSecurityQuotaUI(parent)
242
 
{
243
 
    CurrentItem = NULL;
244
 
    update();
245
 
}
246
 
 
247
 
void toSecurityQuota::update(void)
248
 
{
249
 
    Tablespaces->clear();
250
 
    try
251
 
    {
252
 
        toQuery tablespaces(toCurrentConnection(this), SQLTablespace);
253
 
        QListViewItem *item = NULL;
254
 
        while (!tablespaces.eof())
255
 
        {
256
 
            item = new toResultViewItem(Tablespaces, item, tablespaces.readValue());
257
 
            item->setText(1, qApp->translate("toSecurityQuota", "None"));
258
 
            item->setText(3, qApp->translate("toSecurityQuota", "None"));
259
 
        }
260
 
    }
261
 
    TOCATCH
262
 
}
263
 
 
264
 
void toSecurityQuota::clearItem(QListViewItem *item)
265
 
{
266
 
    item->setText(1, qApp->translate("toSecurityQuota", "None"));
267
 
    item->setText(2, QString::null);
268
 
    item->setText(3, qApp->translate("toSecurityQuota", "None"));
269
 
}
270
 
 
271
 
void toSecurityQuota::clear(void)
272
 
{
273
 
    for (QListViewItem *item = Tablespaces->firstChild();item;item = item->nextSibling())
274
 
        item->setText(3, qApp->translate("toSecurityQuota", "None"));
275
 
}
276
 
 
277
 
void toSecurityQuota::changeUser(const QString &user)
278
 
{
279
 
    Tablespaces->show();
280
 
    SizeGroup->show();
281
 
    Disabled->hide(); // Do we really have to bother about this?
282
 
 
283
 
    Tablespaces->clearSelection();
284
 
    QListViewItem *item = Tablespaces->firstChild();
285
 
    if (!user.isEmpty())
286
 
    {
287
 
        try
288
 
        {
289
 
            toQuery quota(toCurrentConnection(this), SQLQuota, user);
290
 
            while (!quota.eof())
291
 
            {
292
 
                double maxQuota;
293
 
                double usedQuota;
294
 
                QString tbl(quota.readValue());
295
 
                while (item && item->text(0) != tbl)
296
 
                {
297
 
                    clearItem(item);
298
 
                    item = item->nextSibling();
299
 
                }
300
 
                usedQuota = quota.readValue().toDouble();
301
 
                maxQuota = quota.readValue().toDouble();
302
 
                if (item)
303
 
                {
304
 
                    QString usedStr;
305
 
                    QString maxStr;
306
 
                    usedStr.sprintf("%.0f KB", usedQuota / 1024);
307
 
                    if (maxQuota < 0)
308
 
                        maxStr = qApp->translate("toSecurityQuota", "Unlimited");
309
 
                    else if (maxQuota == 0)
310
 
                        maxStr = qApp->translate("toSecurityQuota", "None");
311
 
                    else
312
 
                    {
313
 
                        maxStr.sprintf("%.0f KB", maxQuota / 1024);
314
 
                    }
315
 
                    item->setText(1, maxStr);
316
 
                    item->setText(2, usedStr);
317
 
                    item->setText(3, maxStr);
318
 
                    item = item->nextSibling();
319
 
                }
320
 
            }
321
 
        }
322
 
        TOCATCH
323
 
    }
324
 
    while (item)
325
 
    {
326
 
        clearItem(item);
327
 
        item = item->nextSibling();
328
 
    }
329
 
    SizeGroup->setEnabled(false);
330
 
    CurrentItem = NULL;
331
 
}
332
 
 
333
 
void toSecurityQuota::changeTablespace(void)
334
 
{
335
 
    CurrentItem = Tablespaces->selectedItem();
336
 
    if (CurrentItem)
337
 
    {
338
 
        QString siz = CurrentItem->text(1);
339
 
        if (siz == qApp->translate("toSecurityQuota", "None"))
340
 
            None->setChecked(true);
341
 
        else if (siz == qApp->translate("toSecurityQuota", "Unlimited"))
342
 
            Unlimited->setChecked(true);
343
 
        else
344
 
        {
345
 
            Value->setChecked(true);
346
 
            Size->setValue(siz.toInt());
347
 
        }
348
 
    }
349
 
    SizeGroup->setEnabled(true);
350
 
}
351
 
 
352
 
QString toSecurityQuota::sql(void)
353
 
{
354
 
    QString ret;
355
 
    for (QListViewItem *item = Tablespaces->firstChild();item;item = item->nextSibling())
356
 
    {
357
 
        if (item->text(1) != item->text(3))
358
 
        {
359
 
            QString siz = item->text(1);
360
 
            if (siz.right(2) == QString::fromLatin1("KB"))
361
 
                siz.truncate(siz.length() - 1);
362
 
            else if (siz == qApp->translate("toSecurityQuota", "None"))
363
 
                siz = QString::fromLatin1("0 K");
364
 
            else if (siz == qApp->translate("toSecurityQuota", "Unlimited"))
365
 
                siz = QString::fromLatin1("UNLIMITED");
366
 
            ret += QString::fromLatin1(" QUOTA ");
367
 
            ret += siz;
368
 
            ret += QString::fromLatin1(" ON ");
369
 
            ret += item->text(0);
370
 
        }
371
 
    }
372
 
    return ret;
373
 
}
374
 
 
375
 
class toSecurityUpper : public QValidator
376
 
{
377
 
public:
378
 
    toSecurityUpper(QWidget *parent)
379
 
            : QValidator(parent)
380
 
    { }
381
 
    virtual State validate(QString &str, int &) const
382
 
    {
383
 
        str = str.upper();
384
 
        return Acceptable;
385
 
    }
386
 
};
387
 
 
388
 
class toSecurityUser : public toSecurityUserUI
389
 
{
390
 
    toConnection &Connection;
391
 
 
392
 
    toSecurityQuota *Quota;
393
 
    enum {
394
 
        password,
395
 
        global,
396
 
        external
397
 
    } AuthType;
398
 
    QString OrgProfile;
399
 
    QString OrgDefault;
400
 
    QString OrgTemp;
401
 
    QString OrgGlobal;
402
 
    QString OrgPassword;
403
 
 
404
 
    bool OrgLocked;
405
 
    bool OrgExpired;
406
 
public:
407
 
    toSecurityUser(toSecurityQuota *quota, toConnection &conn, QWidget *parent);
408
 
    void clear(bool all = true);
409
 
    void changeUser(const QString &);
410
 
    QString name(void)
411
 
    {
412
 
        return Name->text();
413
 
    }
414
 
    QString sql(void);
415
 
};
416
 
 
417
 
QString toSecurityUser::sql(void)
418
 
{
419
 
    QString extra;
420
 
    if (Authentication->currentPage() == PasswordTab)
421
 
    {
422
 
        if (Password->text() != Password2->text())
423
 
        {
424
 
            switch (TOMessageBox::warning(this,
425
 
                                          qApp->translate("toSecurityUser", "Passwords don't match"),
426
 
                                          qApp->translate("toSecurityUser", "The two versions of the password doesn't match"),
427
 
                                          qApp->translate("toSecurityUser", "Don't save"),
428
 
                                          qApp->translate("toSecurityUser", "Cancel")))
429
 
            {
430
 
            case 0:
431
 
                return QString::null;
432
 
            case 1:
433
 
                throw qApp->translate("toSecurityUser", "Passwords don't match");
434
 
            }
435
 
        }
436
 
        if (Password->text() != OrgPassword)
437
 
        {
438
 
            extra = QString::fromLatin1(" IDENTIFIED BY \"");
439
 
            extra += Password->text();
440
 
            extra += QString::fromLatin1("\"");
441
 
        }
442
 
        if (OrgExpired != ExpirePassword->isChecked())
443
 
        {
444
 
            if (ExpirePassword->isChecked())
445
 
                extra += QString::fromLatin1(" PASSWORD EXPIRE");
446
 
        }
447
 
    }
448
 
    else if (Authentication->currentPage() == GlobalTab)
449
 
    {
450
 
        if (OrgGlobal != GlobalName->text())
451
 
        {
452
 
            extra = QString::fromLatin1(" IDENTIFIED GLOBALLY AS '");
453
 
            extra += GlobalName->text();
454
 
            extra += QString::fromLatin1("'");
455
 
        }
456
 
    }
457
 
    else if ((AuthType != external) && (Authentication->currentPage() == ExternalTab))
458
 
        extra = QString::fromLatin1(" IDENTIFIED EXTERNALLY");
459
 
 
460
 
    if (OrgProfile != Profile->currentText())
461
 
    {
462
 
        extra += QString::fromLatin1(" PROFILE \"");
463
 
        extra += Profile->currentText();
464
 
        extra += QString::fromLatin1("\"");
465
 
    }
466
 
    if (OrgDefault != DefaultSpace->currentText())
467
 
    {
468
 
        extra += QString::fromLatin1(" DEFAULT TABLESPACE \"");
469
 
        extra += DefaultSpace->currentText();
470
 
        extra += QString::fromLatin1("\"");
471
 
    }
472
 
    if (OrgTemp != TempSpace->currentText())
473
 
    {
474
 
        extra += QString::fromLatin1(" TEMPORARY TABLESPACE \"");
475
 
        extra += TempSpace->currentText();
476
 
        extra += QString::fromLatin1("\"");
477
 
    }
478
 
    if (OrgLocked != Locked->isChecked())
479
 
    {
480
 
        extra += QString::fromLatin1(" ACCOUNT ");
481
 
        if (Locked->isChecked())
482
 
            extra += QString::fromLatin1("LOCK");
483
 
        else
484
 
            extra += QString::fromLatin1("UNLOCK");
485
 
    }
486
 
    extra += Quota->sql();
487
 
 
488
 
    QString sql;
489
 
    if (Name->isEnabled())
490
 
    {
491
 
        if (Name->text().isEmpty())
492
 
            return QString::null;
493
 
        sql = QString::fromLatin1("CREATE ");
494
 
    }
495
 
    else
496
 
    {
497
 
        if (extra.isEmpty())
498
 
            return QString::null;
499
 
        sql = QString::fromLatin1("ALTER ");
500
 
    }
501
 
    sql += QString::fromLatin1("USER \"");
502
 
    sql += Name->text();
503
 
    sql += QString::fromLatin1("\"");
504
 
    sql += extra;
505
 
    return sql;
506
 
}
507
 
 
508
 
toSecurityUser::toSecurityUser(toSecurityQuota *quota, toConnection &conn, QWidget *parent)
509
 
        : toSecurityUserUI(parent), Connection(conn), Quota(quota)
510
 
{
511
 
    Name->setValidator(new toSecurityUpper(Name));
512
 
    setFocusProxy(Name);
513
 
    try
514
 
    {
515
 
        toQuery profiles(Connection, SQLProfiles);
516
 
        while (!profiles.eof())
517
 
            Profile->insertItem(profiles.readValue());
518
 
 
519
 
        toQuery tablespaces(Connection,
520
 
                            SQLTablespace);
521
 
        while (!tablespaces.eof())
522
 
        {
523
 
            QString buf = tablespaces.readValue();
524
 
            DefaultSpace->insertItem(buf);
525
 
            TempSpace->insertItem(buf);
526
 
        }
527
 
    }
528
 
    TOCATCH
529
 
}
530
 
 
531
 
void toSecurityUser::clear(bool all)
532
 
{
533
 
    Name->setText(QString::null);
534
 
    Password->setText(QString::null);
535
 
    Password2->setText(QString::null);
536
 
    GlobalName->setText(QString::null);
537
 
    if (all)
538
 
    {
539
 
        Profile->setCurrentItem(0);
540
 
        Authentication->showPage(PasswordTab);
541
 
        ExpirePassword->setChecked(false);
542
 
        ExpirePassword->setEnabled(true);
543
 
        TempSpace->setCurrentItem(0);
544
 
        DefaultSpace->setCurrentItem(0);
545
 
        Locked->setChecked(false);
546
 
    }
547
 
 
548
 
    OrgProfile = OrgDefault = OrgTemp = OrgGlobal = QString::null;
549
 
    AuthType = password;
550
 
    Name->setEnabled(true);
551
 
    OrgLocked = OrgExpired = false;
552
 
}
553
 
 
554
 
void toSecurityUser::changeUser(const QString &user)
555
 
{
556
 
    clear();
557
 
    try
558
 
    {
559
 
        toQuery query(Connection, SQLUserInfo, user);
560
 
        if (!query.eof())
561
 
        {
562
 
            Name->setEnabled(false);
563
 
            Name->setText(user);
564
 
 
565
 
            QString str(query.readValue());
566
 
            if (str.startsWith(QString::fromLatin1("EXPIRED")))
567
 
            {
568
 
                ExpirePassword->setChecked(true);
569
 
                ExpirePassword->setEnabled(false);
570
 
                OrgExpired = true;
571
 
            }
572
 
            else if (str.startsWith(QString::fromLatin1("LOCKED")))
573
 
            {
574
 
                Locked->setChecked(true);
575
 
                OrgLocked = true;
576
 
            }
577
 
 
578
 
            OrgPassword = query.readValue();
579
 
            QString pass = query.readValue();
580
 
            if (OrgPassword == QString::fromLatin1("GLOBAL"))
581
 
            {
582
 
                OrgPassword = QString::null;
583
 
                Authentication->showPage(GlobalTab);
584
 
                OrgGlobal = pass;
585
 
                GlobalName->setText(OrgGlobal);
586
 
                AuthType = global;
587
 
            }
588
 
            else if (OrgPassword == QString::fromLatin1("EXTERNAL"))
589
 
            {
590
 
                OrgPassword = QString::null;
591
 
                Authentication->showPage(ExternalTab);
592
 
                AuthType = external;
593
 
            }
594
 
            else
595
 
            {
596
 
                Password->setText(OrgPassword);
597
 
                Password2->setText(OrgPassword);
598
 
                AuthType = password;
599
 
            }
600
 
 
601
 
            {
602
 
                str = query.readValue();
603
 
                for (int i = 0;i < Profile->count();i++)
604
 
                {
605
 
                    if (Profile->text(i) == str)
606
 
                    {
607
 
                        Profile->setCurrentItem(i);
608
 
                        OrgProfile = str;
609
 
                        break;
610
 
                    }
611
 
                }
612
 
            }
613
 
 
614
 
            {
615
 
                str = query.readValue();
616
 
                for (int i = 0;i < DefaultSpace->count();i++)
617
 
                {
618
 
                    if (DefaultSpace->text(i) == str)
619
 
                    {
620
 
                        DefaultSpace->setCurrentItem(i);
621
 
                        OrgDefault = str;
622
 
                        break;
623
 
                    }
624
 
                }
625
 
            }
626
 
 
627
 
            {
628
 
                str = query.readValue();
629
 
                for (int i = 0;i < TempSpace->count();i++)
630
 
                {
631
 
                    if (TempSpace->text(i) == str)
632
 
                    {
633
 
                        TempSpace->setCurrentItem(i);
634
 
                        OrgTemp = str;
635
 
                        break;
636
 
                    }
637
 
                }
638
 
            }
639
 
        }
640
 
    }
641
 
    TOCATCH
642
 
}
643
 
 
644
 
class toSecurityRole : public toSecurityRoleUI
645
 
{
646
 
    toConnection &Connection;
647
 
    toSecurityQuota *Quota;
648
 
    enum {
649
 
        password,
650
 
        global,
651
 
        external,
652
 
        none
653
 
    } AuthType;
654
 
public:
655
 
    toSecurityRole(toSecurityQuota *quota, toConnection &conn, QWidget *parent)
656
 
            : toSecurityRoleUI(parent), Connection(conn), Quota(quota)
657
 
    {
658
 
        Name->setValidator(new toSecurityUpper(Name));
659
 
        setFocusProxy(Name);
660
 
    }
661
 
    void clear(void);
662
 
    void changeRole(const QString &);
663
 
    QString sql(void);
664
 
    QString name(void)
665
 
    {
666
 
        return Name->text();
667
 
    }
668
 
};
669
 
 
670
 
QString toSecurityRole::sql(void)
671
 
{
672
 
    QString extra;
673
 
    if (Authentication->currentPage() == PasswordTab)
674
 
    {
675
 
        if (Password->text() != Password2->text())
676
 
        {
677
 
            switch (TOMessageBox::warning(this,
678
 
                                          qApp->translate("toSecurityRole", "Passwords don't match"),
679
 
                                          qApp->translate("toSecurityRole", "The two versions of the password doesn't match"),
680
 
                                          qApp->translate("toSecurityRole", "Don't save"),
681
 
                                          qApp->translate("toSecurityRole", "Cancel")))
682
 
            {
683
 
            case 0:
684
 
                return QString::null;
685
 
            case 1:
686
 
                throw qApp->translate("toSecurityRole", "Passwords don't match");
687
 
            }
688
 
        }
689
 
        if (Password->text().length() > 0)
690
 
        {
691
 
            extra = QString::fromLatin1(" IDENTIFIED BY \"");
692
 
            extra += Password->text();
693
 
            extra += QString::fromLatin1("\"");
694
 
        }
695
 
    }
696
 
    else if ((AuthType != global) && (Authentication->currentPage() == GlobalTab))
697
 
        extra = QString::fromLatin1(" IDENTIFIED GLOBALLY");
698
 
    else if ((AuthType != external) && (Authentication->currentPage() == ExternalTab))
699
 
        extra = QString::fromLatin1(" IDENTIFIED EXTERNALLY");
700
 
    else if ((AuthType != none) && (Authentication->currentPage() == NoneTab))
701
 
        extra = QString::fromLatin1(" NOT IDENTIFIED");
702
 
    extra += Quota->sql();
703
 
    QString sql;
704
 
    if (Name->isEnabled())
705
 
    {
706
 
        if (Name->text().isEmpty())
707
 
            return QString::null;
708
 
        sql = QString::fromLatin1("CREATE ");
709
 
    }
710
 
    else
711
 
    {
712
 
        if (extra.isEmpty())
713
 
            return QString::null;
714
 
        sql = QString::fromLatin1("ALTER ");
715
 
    }
716
 
    sql += QString::fromLatin1("ROLE \"");
717
 
    sql += Name->text();
718
 
    sql += QString::fromLatin1("\"");
719
 
    sql += extra;
720
 
    return sql;
721
 
}
722
 
 
723
 
void toSecurityRole::clear(void)
724
 
{
725
 
    Name->setText(QString::null);
726
 
    Name->setEnabled(true);
727
 
}
728
 
 
729
 
void toSecurityRole::changeRole(const QString &role)
730
 
{
731
 
    try
732
 
    {
733
 
        toQuery query(Connection, SQLRoleInfo, role);
734
 
        Password->setText(QString::null);
735
 
        Password2->setText(QString::null);
736
 
        if (!query.eof())
737
 
        {
738
 
            Name->setText(role);
739
 
            Name->setEnabled(false);
740
 
 
741
 
            QString str(query.readValue());
742
 
            if (str == QString::fromLatin1("YES"))
743
 
            {
744
 
                AuthType = password;
745
 
                Authentication->showPage(PasswordTab);
746
 
            }
747
 
            else if (str == QString::fromLatin1("GLOBAL"))
748
 
            {
749
 
                AuthType = global;
750
 
                Authentication->showPage(GlobalTab);
751
 
            }
752
 
            else if (str == QString::fromLatin1("EXTERNAL"))
753
 
            {
754
 
                AuthType = external;
755
 
                Authentication->showPage(ExternalTab);
756
 
            }
757
 
            else
758
 
            {
759
 
                AuthType = none;
760
 
                Authentication->showPage(NoneTab);
761
 
            }
762
 
        }
763
 
        else
764
 
        {
765
 
            Name->setText(QString::null);
766
 
            Name->setEnabled(true);
767
 
            AuthType = none;
768
 
            Authentication->showPage(NoneTab);
769
 
        }
770
 
    }
771
 
    TOCATCH
772
 
}
773
 
 
774
 
class toSecurityPage : public QVBox
775
 
{
776
 
    toSecurityRole *Role;
777
 
    toSecurityUser *User;
778
 
public:
779
 
    toSecurityPage(toSecurityQuota *quota, toConnection &conn, QWidget *parent)
780
 
            : QVBox(parent)
781
 
    {
782
 
        Role = new toSecurityRole(quota, conn, this);
783
 
        Role->hide();
784
 
        User = new toSecurityUser(quota, conn, this);
785
 
        setFocusProxy(User);
786
 
    }
787
 
    void changePage(const QString &nam, bool user)
788
 
    {
789
 
        if (user)
790
 
        {
791
 
            Role->hide();
792
 
            User->show();
793
 
            User->changeUser(nam);
794
 
            setFocusProxy(User);
795
 
        }
796
 
        else
797
 
        {
798
 
            User->hide();
799
 
            Role->show();
800
 
            Role->changeRole(nam);
801
 
            setFocusProxy(Role);
802
 
        }
803
 
    }
804
 
    QString name(void)
805
 
    {
806
 
        if (User->isHidden())
807
 
            return Role->name();
808
 
        else
809
 
            return User->name();
810
 
    }
811
 
    void clear(void)
812
 
    {
813
 
        if (User->isHidden())
814
 
            Role->clear();
815
 
        else
816
 
            User->clear(false);
817
 
    }
818
 
    bool user(void)
819
 
    {
820
 
        if (User->isHidden())
821
 
            return false;
822
 
        return true;
823
 
    }
824
 
    QString sql(void)
825
 
    {
826
 
        if (User->isHidden())
827
 
            return Role->sql();
828
 
        else
829
 
            return User->sql();
830
 
    }
831
 
};
832
 
 
833
 
toSecurityObject::toSecurityObject(QWidget *parent)
834
 
        : toListView(parent)
835
 
{
836
 
    addColumn(tr("Object"));
837
 
    setRootIsDecorated(true);
838
 
    update();
839
 
    setSorting(0);
840
 
    connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(changed(QListViewItem *)));
841
 
}
842
 
 
843
 
 
844
 
void toSecurityObject::update(void)
845
 
{
846
 
    clear();
847
 
    try
848
 
    {
849
 
        QString oType;
850
 
        QString oOwner;
851
 
        QString oName;
852
 
        std::list<toConnection::objectName> &objectList = toCurrentConnection(this).objects(true);
853
 
        std::map<QString, QStringList> TypeOptions;
854
 
        toQuery typelst(toCurrentConnection(this));
855
 
        QListViewItem *typeItem = NULL;
856
 
        QListViewItem *ownerItem = NULL;
857
 
        QListViewItem *nameItem = NULL;
858
 
        QStringList Options;
859
 
        for (std::list<toConnection::objectName>::iterator i = objectList.begin();i != objectList.end();i++)
860
 
        {
861
 
            QString type = (*i).Type;
862
 
            QString owner = (*i).Owner;
863
 
            QString name = (*i).Name;
864
 
            if (owner != oOwner)
865
 
            {
866
 
                oType = oName = QString::null;
867
 
                typeItem = nameItem = NULL;
868
 
                oOwner = owner;
869
 
                ownerItem = new toResultViewItem(this, ownerItem, owner);
870
 
            }
871
 
            if (type != oType)
872
 
            {
873
 
                oName = QString::null;
874
 
                nameItem = NULL;
875
 
                oType = type;
876
 
                if (TypeOptions.find(type) == TypeOptions.end())
877
 
                {
878
 
                    toQList args;
879
 
                    toPush(args, toQValue(type));
880
 
                    typelst.execute(SQLObjectPrivs, args);
881
 
                    Options = QStringList::split(QString::fromLatin1(","), typelst.readValue());
882
 
                    TypeOptions[type] = Options;
883
 
                }
884
 
                else
885
 
                    Options = TypeOptions[type];
886
 
 
887
 
                if (Options.count() > 0)
888
 
                {
889
 
                    for (typeItem = ownerItem->firstChild();typeItem;typeItem = typeItem->nextSibling())
890
 
                    {
891
 
                        if (typeItem->text(0) == type)
892
 
                            break;
893
 
                    }
894
 
                    if (!typeItem)
895
 
                        typeItem = new toResultViewItem(ownerItem, typeItem, type);
896
 
                }
897
 
            }
898
 
            if (Options.count() > 0)
899
 
            {
900
 
                nameItem = new toResultViewItem(typeItem, nameItem, name);
901
 
                for (QStringList::Iterator i = Options.begin();i != Options.end();i++)
902
 
                {
903
 
                    QListViewItem *item = new toResultViewCheck(nameItem, *i, QCheckListItem::CheckBox);
904
 
                    item->setText(2, name);
905
 
                    item->setText(3, owner);
906
 
                    new toResultViewCheck(item, tr("Admin"), QCheckListItem::CheckBox);
907
 
                }
908
 
            }
909
 
        }
910
 
    }
911
 
    TOCATCH
912
 
}
913
 
 
914
 
void toSecurityObject::eraseUser(bool all)
915
 
{
916
 
    QListViewItem *next = NULL;
917
 
    for (QListViewItem *item = firstChild();item;item = next)
918
 
    {
919
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
920
 
        if (chk)
921
 
        {
922
 
            if (all)
923
 
                chk->setOn(false);
924
 
            chk->setText(1, QString::null);
925
 
        }
926
 
        if (all)
927
 
            item->setOpen(false);
928
 
        if (item->firstChild())
929
 
            next = item->firstChild();
930
 
        else if (item->nextSibling())
931
 
            next = item->nextSibling();
932
 
        else
933
 
        {
934
 
            next = item;
935
 
            do
936
 
            {
937
 
                next = next->parent();
938
 
            }
939
 
            while (next && !next->nextSibling());
940
 
            if (next)
941
 
                next = next->nextSibling();
942
 
        }
943
 
    }
944
 
}
945
 
 
946
 
void toSecurityObject::changeUser(const QString &user)
947
 
{
948
 
    bool open = true;
949
 
    eraseUser();
950
 
    try
951
 
    {
952
 
        std::map<QString, std::map<QString, std::map<QString, QString> > > privs;
953
 
        toQuery grant(toCurrentConnection(this), SQLObjectGrant, user);
954
 
        QString yes = "YES";
955
 
        QString admstr = "ADMIN";
956
 
        QString normalstr = "normal";
957
 
        while (!grant.eof())
958
 
        {
959
 
            QString owner(grant.readValue());
960
 
            QString object(grant.readValue());
961
 
            QString priv(grant.readValue());
962
 
            QString admin(grant.readValue());
963
 
 
964
 
            ((privs[owner])[object])[priv] = (admin == yes ? admstr : normalstr);
965
 
        }
966
 
 
967
 
        for (QListViewItem *ownerItem = firstChild();ownerItem;ownerItem = ownerItem->nextSibling())
968
 
        {
969
 
            for (QListViewItem * tmpitem = ownerItem->firstChild();tmpitem;tmpitem = tmpitem->nextSibling())
970
 
            {
971
 
                for (QListViewItem * object = tmpitem->firstChild();object;object = object->nextSibling())
972
 
                {
973
 
                    for (QListViewItem * type = object->firstChild();type;type = type->nextSibling())
974
 
                    {
975
 
                        QString t = ((privs[ownerItem->text(0)])[object->text(0)])[type->text(0)];
976
 
                        if (!t.isNull())
977
 
                        {
978
 
                            toResultViewCheck *chk = dynamic_cast<toResultViewCheck *>(type);
979
 
                            if (chk)
980
 
                            {
981
 
                                chk->setText(1, tr("ON"));
982
 
                                chk->setOn(true);
983
 
                                if (t == admstr)
984
 
                                {
985
 
                                    toResultViewCheck *chld = dynamic_cast<toResultViewCheck *>(type->firstChild());
986
 
                                    if (chld)
987
 
                                    {
988
 
                                        chld->setText(1, tr("ON"));
989
 
                                        chld->setOn(true);
990
 
                                        if (open)
991
 
                                            chk->setOpen(true);
992
 
                                    }
993
 
                                }
994
 
                            }
995
 
                            if (open)
996
 
                                for (QListViewItem *par = chk->parent();par;par = par->parent())
997
 
                                    par->setOpen(true);
998
 
                        }
999
 
                    }
1000
 
                }
1001
 
            }
1002
 
        }
1003
 
    }
1004
 
    TOCATCH
1005
 
}
1006
 
 
1007
 
void toSecurityObject::sql(const QString &user, std::list<QString> &sqlLst)
1008
 
{
1009
 
    QListViewItem *next = NULL;
1010
 
    for (QListViewItem *item = firstChild();item;item = next)
1011
 
    {
1012
 
        toResultViewCheck * check = dynamic_cast<toResultViewCheck *>(item);
1013
 
        toResultViewCheck *chld = dynamic_cast<toResultViewCheck *>(item->firstChild());
1014
 
        if (check)
1015
 
        {
1016
 
            QString sql;
1017
 
            QString what = item->text(0);
1018
 
            what += QString::fromLatin1(" ON \"");
1019
 
            what += item->text(3);
1020
 
            what += QString::fromLatin1("\".\"");
1021
 
            what += item->text(2);
1022
 
            what += QString::fromLatin1("\" ");
1023
 
            if (chld && chld->isOn() && chld->text(1).isEmpty())
1024
 
            {
1025
 
                sql = QString::fromLatin1("GRANT ");
1026
 
                sql += what;
1027
 
                sql += QString::fromLatin1("TO \"");
1028
 
                sql += user;
1029
 
                sql += QString::fromLatin1("\" WITH GRANT OPTION");
1030
 
                sqlLst.insert(sqlLst.end(), sql);
1031
 
            }
1032
 
            else if (check->isOn() && !item->text(1).isEmpty())
1033
 
            {
1034
 
                if (chld && !chld->isOn() && !chld->text(1).isEmpty())
1035
 
                {
1036
 
                    sql = QString::fromLatin1("REVOKE ");
1037
 
                    sql += what;
1038
 
                    sql += QString::fromLatin1("FROM \"");
1039
 
                    sql += user;
1040
 
                    sql += QString::fromLatin1("\"");
1041
 
                    sqlLst.insert(sqlLst.end(), sql);
1042
 
 
1043
 
                    sql = QString::fromLatin1("GRANT ");
1044
 
                    sql += what;
1045
 
                    sql += QString::fromLatin1("TO \"");
1046
 
                    sql += user;
1047
 
                    sql += QString::fromLatin1("\"");
1048
 
                    sqlLst.insert(sqlLst.end(), sql);
1049
 
                }
1050
 
            }
1051
 
            else if (check->isOn() && item->text(1).isEmpty())
1052
 
            {
1053
 
                sql = QString::fromLatin1("GRANT ");
1054
 
                sql += what;
1055
 
                sql += QString::fromLatin1("TO \"");
1056
 
                sql += user;
1057
 
                sql += QString::fromLatin1("\"");
1058
 
                sqlLst.insert(sqlLst.end(), sql);
1059
 
            }
1060
 
            else if (!check->isOn() && !item->text(1).isEmpty())
1061
 
            {
1062
 
                sql = QString::fromLatin1("REVOKE ");
1063
 
                sql += what;
1064
 
                sql += QString::fromLatin1("FROM \"");
1065
 
                sql += user;
1066
 
                sql += QString::fromLatin1("\"");
1067
 
                sqlLst.insert(sqlLst.end(), sql);
1068
 
            }
1069
 
        }
1070
 
        if (!check && item->firstChild())
1071
 
            next = item->firstChild();
1072
 
        else if (item->nextSibling())
1073
 
            next = item->nextSibling();
1074
 
        else
1075
 
        {
1076
 
            next = item;
1077
 
            do
1078
 
            {
1079
 
                next = next->parent();
1080
 
            }
1081
 
            while (next && !next->nextSibling());
1082
 
            if (next)
1083
 
                next = next->nextSibling();
1084
 
        }
1085
 
    }
1086
 
}
1087
 
 
1088
 
void toSecurityObject::changed(QListViewItem *org)
1089
 
{
1090
 
    toResultViewCheck *item = dynamic_cast<toResultViewCheck *>(org);
1091
 
    if (item)
1092
 
    {
1093
 
        if (item->isOn())
1094
 
        {
1095
 
            item = dynamic_cast<toResultViewCheck *>(item->parent());
1096
 
            if (item)
1097
 
                item->setOn(true);
1098
 
        }
1099
 
        else
1100
 
        {
1101
 
            item = dynamic_cast<toResultViewCheck *>(item->firstChild());
1102
 
            if (item)
1103
 
                item->setOn(false);
1104
 
        }
1105
 
    }
1106
 
}
1107
 
 
1108
 
toSecuritySystem::toSecuritySystem(QWidget *parent)
1109
 
        : toListView(parent)
1110
 
{
1111
 
    addColumn(tr("Privilege name"));
1112
 
    setRootIsDecorated(true);
1113
 
    update();
1114
 
    setSorting(0);
1115
 
    connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(changed(QListViewItem *)));
1116
 
}
1117
 
 
1118
 
void toSecuritySystem::update(void)
1119
 
{
1120
 
    clear();
1121
 
    try
1122
 
    {
1123
 
        toQuery priv(toCurrentConnection(this), SQLListSystem);
1124
 
        while (!priv.eof())
1125
 
        {
1126
 
            toResultViewCheck *item = new toResultViewCheck(this, priv.readValue(),
1127
 
                                      QCheckListItem::CheckBox);
1128
 
            new toResultViewCheck(item, tr("Admin"), QCheckListItem::CheckBox);
1129
 
        }
1130
 
    }
1131
 
    TOCATCH
1132
 
}
1133
 
 
1134
 
void toSecuritySystem::sql(const QString &user, std::list<QString> &sqlLst)
1135
 
{
1136
 
    for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1137
 
    {
1138
 
        QString sql;
1139
 
        toResultViewCheck *check = dynamic_cast<toResultViewCheck *>(item);
1140
 
        toResultViewCheck *chld = dynamic_cast<toResultViewCheck *>(item->firstChild());
1141
 
        if (chld && chld->isOn() && chld->text(1).isEmpty())
1142
 
        {
1143
 
            sql = QString::fromLatin1("GRANT ");
1144
 
            sql += item->text(0);
1145
 
            sql += QString::fromLatin1(" TO \"");
1146
 
            sql += user;
1147
 
            sql += QString::fromLatin1("\" WITH ADMIN OPTION");
1148
 
            sqlLst.insert(sqlLst.end(), sql);
1149
 
        }
1150
 
        else if (check->isOn() && !item->text(1).isEmpty())
1151
 
        {
1152
 
            if (chld && !chld->isOn() && !chld->text(1).isEmpty())
1153
 
            {
1154
 
                sql = QString::fromLatin1("REVOKE ");
1155
 
                sql += item->text(0);
1156
 
                sql += QString::fromLatin1(" FROM \"");
1157
 
                sql += user;
1158
 
                sql += QString::fromLatin1("\"");
1159
 
                sqlLst.insert(sqlLst.end(), sql);
1160
 
 
1161
 
                sql = QString::fromLatin1("GRANT ");
1162
 
                sql += item->text(0);
1163
 
                sql += QString::fromLatin1(" TO \"");
1164
 
                sql += user;
1165
 
                sql += QString::fromLatin1("\"");
1166
 
                sqlLst.insert(sqlLst.end(), sql);
1167
 
            }
1168
 
        }
1169
 
        else if (check->isOn() && item->text(1).isEmpty())
1170
 
        {
1171
 
            sql = QString::fromLatin1("GRANT ");
1172
 
            sql += item->text(0);
1173
 
            sql += QString::fromLatin1(" TO \"");
1174
 
            sql += user;
1175
 
            sql += QString::fromLatin1("\"");
1176
 
            sqlLst.insert(sqlLst.end(), sql);
1177
 
        }
1178
 
        else if (!check->isOn() && !item->text(1).isEmpty())
1179
 
        {
1180
 
            sql = QString::fromLatin1("REVOKE ");
1181
 
            sql += item->text(0);
1182
 
            sql += QString::fromLatin1(" FROM \"");
1183
 
            sql += user;
1184
 
            sql += QString::fromLatin1("\"");
1185
 
            sqlLst.insert(sqlLst.end(), sql);
1186
 
        }
1187
 
    }
1188
 
}
1189
 
 
1190
 
void toSecuritySystem::changed(QListViewItem *org)
1191
 
{
1192
 
    toResultViewCheck *item = dynamic_cast<toResultViewCheck *>(org);
1193
 
    if (item)
1194
 
    {
1195
 
        if (item->isOn())
1196
 
        {
1197
 
            item = dynamic_cast<toResultViewCheck *>(item->parent());
1198
 
            if (item)
1199
 
                item->setOn(true);
1200
 
        }
1201
 
        else
1202
 
        {
1203
 
            item = dynamic_cast<toResultViewCheck *>(item->firstChild());
1204
 
            if (item)
1205
 
                item->setOn(false);
1206
 
        }
1207
 
    }
1208
 
}
1209
 
 
1210
 
void toSecuritySystem::eraseUser(bool all)
1211
 
{
1212
 
    for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1213
 
    {
1214
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
1215
 
        if (chk && all)
1216
 
            chk->setOn(false);
1217
 
        item->setText(1, QString::null);
1218
 
        for (QListViewItem *chld = item->firstChild();chld;chld = chld->nextSibling())
1219
 
        {
1220
 
            chld->setText(1, QString::null);
1221
 
            toResultViewCheck *chk = dynamic_cast<toResultViewCheck *>(chld);
1222
 
            if (chk && all)
1223
 
                chk->setOn(false);
1224
 
        }
1225
 
    }
1226
 
}
1227
 
 
1228
 
void toSecuritySystem::changeUser(const QString &user)
1229
 
{
1230
 
    eraseUser();
1231
 
    try
1232
 
    {
1233
 
        toQuery query(toCurrentConnection(this), SQLSystemGrant, user);
1234
 
        while (!query.eof())
1235
 
        {
1236
 
            QString str = query.readValue();
1237
 
            QString admin = query.readValue();
1238
 
            for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1239
 
            {
1240
 
                if (item->text(0) == str)
1241
 
                {
1242
 
                    toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
1243
 
                    if (chk)
1244
 
                        chk->setOn(true);
1245
 
                    item->setText(1, tr("ON"));
1246
 
                    if (admin != tr("NO") && item->firstChild())
1247
 
                    {
1248
 
                        chk = dynamic_cast<toResultViewCheck *>(item->firstChild());
1249
 
                        if (chk)
1250
 
                            chk->setOn(true);
1251
 
                        if (chk->parent())
1252
 
                            chk->parent()->setOpen(true);
1253
 
                        item->firstChild()->setText(1, tr("ON"));
1254
 
                    }
1255
 
                    break;
1256
 
                }
1257
 
            }
1258
 
        }
1259
 
    }
1260
 
    TOCATCH
1261
 
}
1262
 
 
1263
 
toSecurityRoleGrant::toSecurityRoleGrant(QWidget *parent)
1264
 
        : toListView(parent)
1265
 
{
1266
 
    addColumn(tr("Role name"));
1267
 
    setRootIsDecorated(true);
1268
 
    update();
1269
 
    setSorting(0);
1270
 
    connect(this, SIGNAL(clicked(QListViewItem *)), this, SLOT(changed(QListViewItem *)));
1271
 
}
1272
 
 
1273
 
void toSecurityRoleGrant::update(void)
1274
 
{
1275
 
    clear();
1276
 
    try
1277
 
    {
1278
 
        toQuery priv(toCurrentConnection(this), SQLRoles);
1279
 
        while (!priv.eof())
1280
 
        {
1281
 
            toResultViewCheck *item = new toResultViewCheck(this, priv.readValue(), QCheckListItem::CheckBox);
1282
 
            new toResultViewCheck(item, tr("Admin"), QCheckListItem::CheckBox);
1283
 
            new toResultViewCheck(item, tr("Default"), QCheckListItem::CheckBox);
1284
 
        }
1285
 
    }
1286
 
    TOCATCH
1287
 
}
1288
 
 
1289
 
QCheckListItem *toSecurityRoleGrant::findChild(QListViewItem *parent, const QString &name)
1290
 
{
1291
 
    for (QListViewItem *item = parent->firstChild();item;item = item->nextSibling())
1292
 
    {
1293
 
        if (item->text(0) == name)
1294
 
        {
1295
 
            toResultViewCheck * ret = dynamic_cast<toResultViewCheck *>(item);
1296
 
            if (ret->isEnabled())
1297
 
                return ret;
1298
 
            else
1299
 
                return NULL;
1300
 
        }
1301
 
    }
1302
 
    return NULL;
1303
 
}
1304
 
 
1305
 
void toSecurityRoleGrant::sql(const QString &user, std::list<QString> &sqlLst)
1306
 
{
1307
 
    bool any = false;
1308
 
    bool chg = false;
1309
 
    QString except;
1310
 
    QString sql;
1311
 
    for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1312
 
    {
1313
 
        toResultViewCheck * check = dynamic_cast<toResultViewCheck *>(item);
1314
 
        QCheckListItem *chld = findChild(item, tr("Admin"));
1315
 
        QCheckListItem *def = findChild(item, tr("Default"));
1316
 
        if (def && check)
1317
 
        {
1318
 
            if (!def->isOn() && check->isOn())
1319
 
            {
1320
 
                if (!except.isEmpty())
1321
 
                    except += QString::fromLatin1(",\"");
1322
 
                else
1323
 
                    except += QString::fromLatin1(" EXCEPT \"");
1324
 
                except += item->text(0);
1325
 
                except += QString::fromLatin1("\"");
1326
 
            }
1327
 
            else if (check->isOn() && def->isOn())
1328
 
                any = true;
1329
 
            if (def->isOn() == def->text(1).isEmpty())
1330
 
                chg = true;
1331
 
        }
1332
 
        if (chld && chld->isOn() && chld->text(1).isEmpty())
1333
 
        {
1334
 
            if (check->isOn() && !item->text(1).isEmpty())
1335
 
            {
1336
 
                sql = QString::fromLatin1("REVOKE \"");
1337
 
                sql += item->text(0);
1338
 
                sql += QString::fromLatin1("\" FROM \"");
1339
 
                sql += user;
1340
 
                sql += QString::fromLatin1("\"");
1341
 
                sqlLst.insert(sqlLst.end(), sql);
1342
 
            }
1343
 
            sql = QString::fromLatin1("GRANT \"");
1344
 
            sql += item->text(0);
1345
 
            sql += QString::fromLatin1("\" TO \"");
1346
 
            sql += user;
1347
 
            sql += QString::fromLatin1("\" WITH ADMIN OPTION");
1348
 
            sqlLst.insert(sqlLst.end(), sql);
1349
 
            chg = true;
1350
 
        }
1351
 
        else if (check->isOn() && !item->text(1).isEmpty())
1352
 
        {
1353
 
            if (chld && !chld->isOn() && !chld->text(1).isEmpty())
1354
 
            {
1355
 
                sql = QString::fromLatin1("REVOKE \"");
1356
 
                sql += item->text(0);
1357
 
                sql += QString::fromLatin1("\" FROM \"");
1358
 
                sql += user;
1359
 
                sql += QString::fromLatin1("\"");
1360
 
                sqlLst.insert(sqlLst.end(), sql);
1361
 
 
1362
 
                sql = QString::fromLatin1("GRANT \"");
1363
 
                sql += item->text(0);
1364
 
                sql += QString::fromLatin1("\" TO \"");
1365
 
                sql += user;
1366
 
                sql += QString::fromLatin1("\"");
1367
 
                sqlLst.insert(sqlLst.end(), sql);
1368
 
                chg = true;
1369
 
            }
1370
 
        }
1371
 
        else if (check->isOn() && item->text(1).isEmpty())
1372
 
        {
1373
 
            sql = QString::fromLatin1("GRANT \"");
1374
 
            sql += item->text(0);
1375
 
            sql += QString::fromLatin1("\" TO \"");
1376
 
            sql += user;
1377
 
            sql += QString::fromLatin1("\"");
1378
 
            sqlLst.insert(sqlLst.end(), sql);
1379
 
            chg = true;
1380
 
        }
1381
 
        else if (!check->isOn() && !item->text(1).isEmpty())
1382
 
        {
1383
 
            sql = QString::fromLatin1("REVOKE \"");
1384
 
            sql += item->text(0);
1385
 
            sql += QString::fromLatin1("\" FROM \"");
1386
 
            sql += user;
1387
 
            sql += QString::fromLatin1("\"");
1388
 
            sqlLst.insert(sqlLst.end(), sql);
1389
 
            chg = true;
1390
 
        }
1391
 
    }
1392
 
    if (chg)
1393
 
    {
1394
 
        sql = QString::fromLatin1("ALTER USER \"");
1395
 
        sql += user;
1396
 
        sql += QString::fromLatin1("\" DEFAULT ROLE ");
1397
 
        if (any)
1398
 
        {
1399
 
            sql += QString::fromLatin1("ALL");
1400
 
            sql += except;
1401
 
        }
1402
 
        else
1403
 
            sql += QString::fromLatin1("NONE");
1404
 
        sqlLst.insert(sqlLst.end(), sql);
1405
 
    }
1406
 
}
1407
 
 
1408
 
void toSecurityRoleGrant::changed(QListViewItem *org)
1409
 
{
1410
 
    toResultViewCheck *item = dynamic_cast<toResultViewCheck *>(org);
1411
 
    if (item)
1412
 
    {
1413
 
        if (item->isOn())
1414
 
        {
1415
 
            QCheckListItem *chld = findChild(item, tr("Default"));
1416
 
            if (chld)
1417
 
                chld->setOn(true);
1418
 
            item = dynamic_cast<toResultViewCheck *>(item->parent());
1419
 
            if (item)
1420
 
                item->setOn(true);
1421
 
        }
1422
 
        else
1423
 
        {
1424
 
            for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1425
 
            {
1426
 
                toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item->firstChild());
1427
 
                if (chk)
1428
 
                    chk->setOn(false);
1429
 
            }
1430
 
        }
1431
 
    }
1432
 
}
1433
 
 
1434
 
void toSecurityRoleGrant::eraseUser(bool user, bool all)
1435
 
{
1436
 
    for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1437
 
    {
1438
 
        toResultViewCheck * chk = dynamic_cast<toResultViewCheck *>(item);
1439
 
        if (chk && all)
1440
 
            chk->setOn(false);
1441
 
        item->setText(1, QString::null);
1442
 
        for (QListViewItem *chld = item->firstChild();chld;chld = chld->nextSibling())
1443
 
        {
1444
 
            chld->setText(1, QString::null);
1445
 
            toResultViewCheck *chk = dynamic_cast<toResultViewCheck *>(chld);
1446
 
            if (chk)
1447
 
            {
1448
 
                if (all)
1449
 
                {
1450
 
                    chk->setOn(false);
1451
 
                    if (chk->text(0) == tr("Default"))
1452
 
                        chk->setEnabled(user);
1453
 
                }
1454
 
            }
1455
 
        }
1456
 
    }
1457
 
}
1458
 
 
1459
 
void toSecurityRoleGrant::changeUser(bool user, const QString &username)
1460
 
{
1461
 
    eraseUser(user);
1462
 
    try
1463
 
    {
1464
 
        toQuery query(toCurrentConnection(this), SQLRoleGrant, username);
1465
 
        while (!query.eof())
1466
 
        {
1467
 
            QString str = query.readValue();
1468
 
            QString admin = query.readValue();
1469
 
            QString def = query.readValue();
1470
 
            for (QListViewItem *item = firstChild();item;item = item->nextSibling())
1471
 
            {
1472
 
                if (item->text(0) == str)
1473
 
                {
1474
 
                    QCheckListItem * chk = dynamic_cast<toResultViewCheck *>(item);
1475
 
                    if (chk)
1476
 
                        chk->setOn(true);
1477
 
                    item->setText(1, tr("ON"));
1478
 
                    chk = findChild(item, tr("Admin"));
1479
 
                    if (admin == tr("YES") && chk)
1480
 
                    {
1481
 
                        chk->setOn(true);
1482
 
                        chk->setText(1, tr("ON"));
1483
 
                        if (chk->parent())
1484
 
                            chk->parent()->setOpen(true);
1485
 
                    }
1486
 
                    chk = findChild(item, tr("Default"));
1487
 
                    if (def == tr("YES") && chk)
1488
 
                    {
1489
 
                        chk->setOn(true);
1490
 
                        chk->setText(1, tr("ON"));
1491
 
                        if (chk->parent())
1492
 
                            chk->parent()->setOpen(true);
1493
 
                    }
1494
 
                    break;
1495
 
                }
1496
 
            }
1497
 
        }
1498
 
    }
1499
 
    TOCATCH
1500
 
}
1501
 
 
1502
 
toSecurity::toSecurity(QWidget *main, toConnection &connection)
1503
 
        : toToolWidget(SecurityTool, "security.html", main, connection)
1504
 
{
1505
 
    toBusy busy;
1506
 
 
1507
 
    QToolBar *toolbar = toAllocBar(this, tr("Security manager"));
1508
 
    toolbar->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1509
 
 
1510
 
    new QToolButton(QPixmap(const_cast<const char**>(refresh_xpm)),
1511
 
                    tr("Update user and role list"),
1512
 
                    tr("Update user and role list"),
1513
 
                    this, SLOT(refresh(void)),
1514
 
                    toolbar);
1515
 
    toolbar->addSeparator();
1516
 
    new QToolButton(QPixmap(const_cast<const char**>(commit_xpm)),
1517
 
                    tr("Save changes"),
1518
 
                    tr("Save changes"),
1519
 
                    this, SLOT(saveChanges(void)),
1520
 
                    toolbar);
1521
 
    DropButton = new QToolButton(QPixmap(const_cast<const char**>(trash_xpm)),
1522
 
                                 tr("Remove user/role"),
1523
 
                                 tr("Remove user/role"),
1524
 
                                 this, SLOT(drop(void)),
1525
 
                                 toolbar);
1526
 
    DropButton->setEnabled(false);
1527
 
    toolbar->addSeparator();
1528
 
    new QToolButton(QPixmap(const_cast<const char**>(adduser_xpm)),
1529
 
                    tr("Add new user"),
1530
 
                    tr("Add new user"),
1531
 
                    this, SLOT(addUser(void)),
1532
 
                    toolbar);
1533
 
    new QToolButton(QPixmap(const_cast<const char**>(addrole_xpm)),
1534
 
                    tr("Add new role"),
1535
 
                    tr("Add new role"),
1536
 
                    this, SLOT(addRole(void)),
1537
 
                    toolbar);
1538
 
    CopyButton = new QToolButton(QPixmap(const_cast<const char**>(copyuser_xpm)),
1539
 
                                 tr("Copy current user or role"),
1540
 
                                 tr("Copy current user or role"),
1541
 
                                 this, SLOT(copy(void)),
1542
 
                                 toolbar);
1543
 
    CopyButton->setEnabled(false);
1544
 
    toolbar->addSeparator();
1545
 
    new QToolButton(QPixmap(const_cast<const char**>(sql_xpm)),
1546
 
                    tr("Display SQL needed to make current changes"),
1547
 
                    tr("Display SQL needed to make current changes"),
1548
 
                    this, SLOT(displaySQL(void)),
1549
 
                    toolbar);
1550
 
    toolbar->setStretchableWidget(new QLabel(toolbar, TO_KDE_TOOLBAR_WIDGET));
1551
 
    new toChangeConnection(toolbar, TO_KDE_TOOLBAR_WIDGET);
1552
 
 
1553
 
    QSplitter *splitter = new QSplitter(Horizontal, this);
1554
 
    UserList = new toListView(splitter);
1555
 
    UserList->addColumn(tr("Users/Roles"));
1556
 
    UserList->setSQLName(QString::fromLatin1("toSecurity:Users/Roles"));
1557
 
    UserList->setRootIsDecorated(true);
1558
 
    UserList->setSelectionMode(QListView::Single);
1559
 
    Tabs = new QTabWidget(splitter);
1560
 
    Quota = new toSecurityQuota(Tabs);
1561
 
    General = new toSecurityPage(Quota, connection, Tabs);
1562
 
    Tabs->addTab(General, tr("&General"));
1563
 
    RoleGrant = new toSecurityRoleGrant(Tabs);
1564
 
    Tabs->addTab(RoleGrant, tr("&Roles"));
1565
 
    SystemGrant = new toSecuritySystem(Tabs);
1566
 
    Tabs->addTab(SystemGrant, tr("&System Privileges"));
1567
 
    ObjectGrant = new toSecurityObject(Tabs);
1568
 
    Tabs->addTab(ObjectGrant, tr("&Object Privileges"));
1569
 
    Tabs->addTab(Quota, tr("&Quota"));
1570
 
    UserList->setSelectionMode(QListView::Single);
1571
 
    connect(UserList, SIGNAL(selectionChanged(QListViewItem *)),
1572
 
            this, SLOT(changeUser(QListViewItem *)));
1573
 
    ToolMenu = NULL;
1574
 
    connect(toMainWidget()->workspace(), SIGNAL(windowActivated(QWidget *)),
1575
 
            this, SLOT(windowActivated(QWidget *)));
1576
 
    refresh();
1577
 
    connect(this, SIGNAL(connectionChange()),
1578
 
            this, SLOT(refresh()));
1579
 
    setFocusProxy(Tabs);
1580
 
}
1581
 
 
1582
 
#define TO_ID_COPY  (toMain::TO_TOOL_MENU_ID+ 0)
1583
 
#define TO_ID_DROP  (toMain::TO_TOOL_MENU_ID+ 1)
1584
 
 
1585
 
void toSecurity::windowActivated(QWidget *widget)
1586
 
{
1587
 
    if (widget == this)
1588
 
    {
1589
 
        if (!ToolMenu)
1590
 
        {
1591
 
            ToolMenu = new QPopupMenu(this);
1592
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(refresh_xpm)), tr("&Refresh"),
1593
 
                                 this, SLOT(refresh(void)),
1594
 
                                 toKeySequence(tr("F5", "Security|Refresh")));
1595
 
            ToolMenu->insertSeparator();
1596
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(commit_xpm)), tr("&Save changes"),
1597
 
                                 this, SLOT(saveChanges()),
1598
 
                                 toKeySequence(tr("Ctrl+Return", "Security|Save changes")));
1599
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(trash_xpm)), tr("&Remove user/role"),
1600
 
                                 this, SLOT(drop()), 0, TO_ID_DROP);
1601
 
            ToolMenu->insertSeparator();
1602
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(adduser_xpm)), tr("Add &user"),
1603
 
                                 this, SLOT(addUser()),
1604
 
                                 toKeySequence(tr("Ctrl+Shift+U", "Security|Add user")));
1605
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(addrole_xpm)), tr("Add &role"),
1606
 
                                 this, SLOT(addRole()),
1607
 
                                 toKeySequence(tr("Ctrl+Shift+R", "Security|Add role")));
1608
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(copyuser_xpm)), tr("&Copy current"),
1609
 
                                 this, SLOT(copy()),
1610
 
                                 toKeySequence(tr("Ctrl+Shift+O", "Security|Copy current")), TO_ID_COPY);
1611
 
            ToolMenu->insertSeparator();
1612
 
            ToolMenu->insertItem(QPixmap(const_cast<const char**>(sql_xpm)), tr("Display SQL..."),
1613
 
                                 this, SLOT(displaySQL()),
1614
 
                                 toKeySequence(tr("F4", "Security|Display SQL")));
1615
 
            toMainWidget()->menuBar()->insertItem(tr("&Security"), ToolMenu, -1, toToolMenuIndex());
1616
 
            ToolMenu->setItemEnabled(TO_ID_DROP, DropButton->isEnabled());
1617
 
            ToolMenu->setItemEnabled(TO_ID_COPY, CopyButton->isEnabled());
1618
 
        }
1619
 
    }
1620
 
    else
1621
 
    {
1622
 
        delete ToolMenu;
1623
 
        ToolMenu = NULL;
1624
 
    }
1625
 
}
1626
 
 
1627
 
void toSecurity::displaySQL(void)
1628
 
{
1629
 
    std::list<QString> lines = sql();
1630
 
    QString res;
1631
 
    for (std::list<QString>::iterator i = lines.begin();i != lines.end();i++)
1632
 
    {
1633
 
        res += *i;
1634
 
        res += QString::fromLatin1(";\n");
1635
 
    }
1636
 
    if (res.length() > 0)
1637
 
        new toMemoEditor(this, res, -1, -1, true);
1638
 
    else
1639
 
        toStatusMessage(tr("No changes made"));
1640
 
}
1641
 
 
1642
 
std::list<QString> toSecurity::sql(void)
1643
 
{
1644
 
    std::list<QString> ret;
1645
 
    try
1646
 
    {
1647
 
        QString tmp = General->sql();
1648
 
        if (!tmp.isEmpty())
1649
 
            ret.insert(ret.end(), tmp);
1650
 
        QString name = General->name();
1651
 
        if (!name.isEmpty())
1652
 
        {
1653
 
            SystemGrant->sql(name, ret);
1654
 
            ObjectGrant->sql(name, ret);
1655
 
            RoleGrant->sql(name, ret);
1656
 
        }
1657
 
    }
1658
 
    catch (const QString &str)
1659
 
    {
1660
 
        toStatusMessage(str);
1661
 
        std::list<QString> empty;
1662
 
        return empty;
1663
 
    }
1664
 
 
1665
 
    return ret;
1666
 
}
1667
 
 
1668
 
void toSecurity::changeUser(bool ask)
1669
 
{
1670
 
    if (ask)
1671
 
    {
1672
 
        try
1673
 
        {
1674
 
            std::list<QString> sqlList = sql();
1675
 
            if (sqlList.size() != 0)
1676
 
            {
1677
 
                switch (TOMessageBox::warning(this,
1678
 
                                              tr("Save changes?"),
1679
 
                                              tr("Save the changes made to this user?"),
1680
 
                                              tr("Save"), tr("Discard"), tr("Cancel")))
1681
 
                {
1682
 
                case 0:
1683
 
                    saveChanges();
1684
 
                    return ;
1685
 
                case 1:
1686
 
                    break;
1687
 
                case 2:
1688
 
                    return ;
1689
 
                }
1690
 
            }
1691
 
        }
1692
 
        catch (const QString &str)
1693
 
        {
1694
 
            toStatusMessage(str);
1695
 
            return ;
1696
 
        }
1697
 
    }
1698
 
 
1699
 
    try
1700
 
    {
1701
 
        QString sel;
1702
 
        QListViewItem *item = UserList->selectedItem();
1703
 
        if (item)
1704
 
        {
1705
 
            toBusy busy;
1706
 
            UserID = item->text(1);
1707
 
            DropButton->setEnabled(item->parent());
1708
 
            CopyButton->setEnabled(item->parent());
1709
 
            if (ToolMenu)
1710
 
            {
1711
 
                ToolMenu->setItemEnabled(TO_ID_DROP, DropButton->isEnabled());
1712
 
                ToolMenu->setItemEnabled(TO_ID_COPY, CopyButton->isEnabled());
1713
 
            }
1714
 
 
1715
 
            if (UserID[4].latin1() != ':')
1716
 
                throw tr("Invalid security ID");
1717
 
            bool user = false;
1718
 
            if (UserID.startsWith(QString::fromLatin1("USER")))
1719
 
                user = true;
1720
 
            QString username = UserID.right(UserID.length() - 5);
1721
 
            General->changePage(username, user);
1722
 
            Quota->changeUser(username);
1723
 
            Tabs->setTabEnabled(Quota, user);
1724
 
            RoleGrant->changeUser(user, username);
1725
 
            SystemGrant->changeUser(username);
1726
 
            ObjectGrant->changeUser(username);
1727
 
        }
1728
 
    }
1729
 
    TOCATCH
1730
 
}
1731
 
 
1732
 
void toSecurity::refresh(void)
1733
 
{
1734
 
    toBusy busy;
1735
 
    disconnect(UserList, SIGNAL(selectionChanged(QListViewItem *)),
1736
 
               this, SLOT(changeUser(QListViewItem *)));
1737
 
    SystemGrant->update();
1738
 
    RoleGrant->update();
1739
 
    ObjectGrant->update();
1740
 
    Quota->update();
1741
 
    UserList->clear();
1742
 
    try
1743
 
    {
1744
 
        QListViewItem *parent = new toResultViewItem(UserList, NULL, QString::fromLatin1("Users"));
1745
 
        parent->setText(1, QString::fromLatin1("USER:"));
1746
 
        parent->setOpen(true);
1747
 
        toQuery user(connection(), toSQL::string(toSQL::TOSQL_USERLIST, connection()));
1748
 
        QListViewItem *item = NULL;
1749
 
        while (!user.eof())
1750
 
        {
1751
 
            QString tmp = user.readValue();
1752
 
            QString id = QString::fromLatin1("USER:");
1753
 
            id += tmp;
1754
 
            item = new toResultViewItem(parent, item, tmp);
1755
 
            item->setText(1, id);
1756
 
            if (id == UserID)
1757
 
                UserList->setSelected(item, true);
1758
 
        }
1759
 
        parent = new toResultViewItem(UserList, parent, tr("Roles"));
1760
 
        parent->setText(1, QString::fromLatin1("ROLE:"));
1761
 
        parent->setOpen(true);
1762
 
        toQuery roles(connection(), SQLRoles);
1763
 
        item = NULL;
1764
 
        while (!roles.eof())
1765
 
        {
1766
 
            QString tmp = roles.readValue();
1767
 
            QString id = QString::fromLatin1("ROLE:");
1768
 
            id += tmp;
1769
 
            item = new toResultViewItem(parent, item, tmp);
1770
 
            item->setText(1, id);
1771
 
            if (id == UserID)
1772
 
                UserList->setSelected(item, true);
1773
 
        }
1774
 
    }
1775
 
    TOCATCH
1776
 
    connect(UserList, SIGNAL(selectionChanged(QListViewItem *)),
1777
 
            this, SLOT(changeUser(QListViewItem *)));
1778
 
}
1779
 
 
1780
 
void toSecurity::saveChanges()
1781
 
{
1782
 
    std::list<QString> sqlList = sql();
1783
 
    for (std::list<QString>::iterator i = sqlList.begin();i != sqlList.end();i++)
1784
 
    {
1785
 
        try
1786
 
        {
1787
 
            connection().execute(*i);
1788
 
        }
1789
 
        TOCATCH
1790
 
    }
1791
 
    if (General->user())
1792
 
        UserID = QString::fromLatin1("USER:");
1793
 
    else
1794
 
        UserID = QString::fromLatin1("ROLE:");
1795
 
    UserID += General->name();
1796
 
    refresh();
1797
 
    changeUser(false);
1798
 
}
1799
 
 
1800
 
void toSecurity::drop()
1801
 
{
1802
 
    if (UserID.length() > 5)
1803
 
    {
1804
 
        QString str = QString::fromLatin1("DROP ");
1805
 
        if (General->user())
1806
 
            str += QString::fromLatin1("USER");
1807
 
        else
1808
 
            str += QString::fromLatin1("ROLE");
1809
 
        str += QString::fromLatin1(" \"");
1810
 
        str += UserID.right(UserID.length() - 5);
1811
 
        str += QString::fromLatin1("\"");
1812
 
        try
1813
 
        {
1814
 
            connection().execute(str);
1815
 
            refresh();
1816
 
            changeUser(false);
1817
 
        }
1818
 
        catch (...)
1819
 
        {
1820
 
            switch (TOMessageBox::warning(this,
1821
 
                                          tr("Are you sure?"),
1822
 
                                          tr("The user still owns objects, add the cascade option?"),
1823
 
                                          tr("Yes"), tr("No")))
1824
 
            {
1825
 
            case 0:
1826
 
                str += QString::fromLatin1(" CASCADE");
1827
 
                try
1828
 
                {
1829
 
                    connection().execute(str);
1830
 
                    refresh();
1831
 
                    changeUser(false);
1832
 
                }
1833
 
                TOCATCH
1834
 
                return ;
1835
 
            case 1:
1836
 
                break;
1837
 
            }
1838
 
        }
1839
 
    }
1840
 
}
1841
 
 
1842
 
void toSecurity::addUser(void)
1843
 
{
1844
 
    for (QListViewItem *item = UserList->firstChild();item;item = item->nextSibling())
1845
 
        if (item->text(1) == QString::fromLatin1("USER:"))
1846
 
        {
1847
 
            UserList->clearSelection();
1848
 
            UserList->setCurrentItem(item);
1849
 
            Tabs->showPage(General);
1850
 
            General->setFocus();
1851
 
            break;
1852
 
        }
1853
 
}
1854
 
 
1855
 
void toSecurity::addRole(void)
1856
 
{
1857
 
    for (QListViewItem *item = UserList->firstChild();item;item = item->nextSibling())
1858
 
        if (item->text(1) == QString::fromLatin1("ROLE:"))
1859
 
        {
1860
 
            UserList->clearSelection();
1861
 
            UserList->setCurrentItem(item);
1862
 
            Tabs->showPage(General);
1863
 
            General->setFocus();
1864
 
            break;
1865
 
        }
1866
 
}
1867
 
 
1868
 
void toSecurity::copy(void)
1869
 
{
1870
 
    General->clear();
1871
 
    SystemGrant->eraseUser(false);
1872
 
    RoleGrant->eraseUser(General->user(), false);
1873
 
    ObjectGrant->eraseUser(false);
1874
 
    Quota->clear();
1875
 
    if (General->user())
1876
 
        UserID = QString::fromLatin1("USER:");
1877
 
    else
1878
 
        UserID = QString::fromLatin1("ROLE:");
1879
 
    for (QListViewItem *item = UserList->firstChild();item;item = item->nextSibling())
1880
 
        if (item->text(1) == UserID)
1881
 
        {
1882
 
            disconnect(UserList, SIGNAL(selectionChanged(QListViewItem *)),
1883
 
                       this, SLOT(changeUser(QListViewItem *)));
1884
 
            UserList->clearSelection();
1885
 
            UserList->setCurrentItem(item);
1886
 
            connect(UserList, SIGNAL(selectionChanged(QListViewItem *)),
1887
 
                    this, SLOT(changeUser(QListViewItem *)));
1888
 
            break;
1889
 
        }
1890
 
}