keepassxc

Форк
0
/
DatabaseCommand.cpp 
70 строк · 2.5 Кб
1
/*
2
 *  Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "DatabaseCommand.h"
19

20
#include "Utils.h"
21
#include "config-keepassx.h"
22

23
#include <QCommandLineParser>
24

25
DatabaseCommand::DatabaseCommand()
26
{
27
    positionalArguments.append({QString("database"), QObject::tr("Path of the database."), QString("")});
28
    options.append(Command::KeyFileOption);
29
    options.append(Command::NoPasswordOption);
30
#ifdef WITH_XC_YUBIKEY
31
    options.append(Command::YubiKeyOption);
32
#endif
33
}
34

35
int DatabaseCommand::execute(const QStringList& arguments)
36
{
37
    QStringList amendedArgs(arguments);
38
    if (currentDatabase) {
39
        amendedArgs.insert(1, currentDatabase->filePath());
40
    }
41
    QSharedPointer<QCommandLineParser> parser = getCommandLineParser(amendedArgs);
42

43
    if (parser.isNull()) {
44
        return EXIT_FAILURE;
45
    }
46

47
    QStringList args = parser->positionalArguments();
48
    auto db = currentDatabase;
49
    if (!db) {
50
        // It would be nice to update currentDatabase here, but the CLI tests frequently
51
        // re-use Command objects to exercise non-interactive behavior. Updating the current
52
        // database confuses these tests. Because of this, we leave it up to the interactive
53
        // mode implementation in the main command loop to update currentDatabase
54
        // (see keepassxc-cli.cpp).
55
        db = Utils::unlockDatabase(args.at(0),
56
                                   !parser->isSet(Command::NoPasswordOption),
57
                                   parser->value(Command::KeyFileOption),
58
#ifdef WITH_XC_YUBIKEY
59
                                   parser->value(Command::YubiKeyOption),
60
#else
61
                                   "",
62
#endif
63
                                   parser->isSet(Command::QuietOption));
64
        if (!db) {
65
            return EXIT_FAILURE;
66
        }
67
    }
68

69
    return executeWithDatabase(db, parser);
70
}
71

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.