Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keylist pr 163 #511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions doc/zypper.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1580,10 +1580,34 @@ Examples: :: {nop}

$ *zypper locales en**:::
Get all locales with lang code _en_ with or without country code.

$ *zypper aloc --packages de_CH*:::
Request *de_CH* and install language dependent packages.

Key Management
~~~~~~~~~~~~~~
The *keys*, *addkey*, and *removekey* commands serve for manipulating the trusted key database. A key is specified by its ID, which is the last 16 characters of its fingerprint.

*keys* (*lk*) ['options'] ['part-of-keyid-or-name'] ['key-filename'] ...::
List all trusted keys or show detailed information about those specified as arguments, supports also keyfiles as argument.
+
--
*-d*, *--detail*::
Shows the keys in a more detailed multiline output, also shows subkey information
--

*addkey* (*ak*) ['options'] 'url'...::
Imports a new key into the trusted database, the file can be specified as a URL.

*removekey* (*rk*) ['options'] 'string' ::
Remove specified key from the trusted database. The query string can be the beginning or end of the key ID, or any part of the key name.
+
--
*--all-matches*::
Continue with removing even if the query matches multiple keys.
--



Other Commands
~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1845,7 +1869,7 @@ Target Options: :: {nop}

*-R*, *--root* _dir_::
Operates on a different root directory. This option influences the location of the repos.d directory and the metadata cache directory and also causes rpm to be run with the *--root* option to do the actual installation or removal of packages. See also the *FILES* section.

*--installroot* _dir_::
Behaves like *--root* but shares the repositories with the host system.

Expand Down
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SET (zypper_HEADERS
SolverRequester.h
Summary.h
CommitSummary.h
keys.h
global-settings.h
issue.h
callbacks/keyring.h
Expand All @@ -40,6 +41,10 @@ SET (zypper_HEADERS
commands/commandhelpformatter.h
commands/conditions.h
commands/basecommand.h
commands/keycmds.h
commands/keys/keyscmd.h
commands/keys/addkeycmd.h
commands/keys/removekeycmd.h
commands/locks.h
commands/locks/common.h
commands/locks/add.h
Expand Down Expand Up @@ -118,13 +123,17 @@ SET( zypper_SRCS
SolverRequester.cc
Summary.cc
CommitSummary.cc
keys.cc
global-settings.cc
issue.cc
callbacks/media.cc
commands/optionsets.cc
commands/commandhelpformatter.cc
commands/conditions.cc
commands/basecommand.cc
commands/keys/keyscmd.cc
commands/keys/addkeycmd.cc
commands/keys/removekeycmd.cc
commands/locks/common.cc
commands/locks/add.cc
commands/locks/clean.cc
Expand Down
9 changes: 9 additions & 0 deletions src/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "commands/locale/localescmd.h"
#include "commands/locale/addlocalecmd.h"
#include "commands/locale/removelocalecmd.h"
#include "commands/keycmds.h"

using namespace zypp;

Expand Down Expand Up @@ -156,6 +157,10 @@ namespace
makeCmd<AddLocaleCmd> ( ZypperCommand::ADD_LOCALE_e , std::string(), { "addlocale", "aloc" } ),
makeCmd<RemoveLocaleCmd> ( ZypperCommand::REMOVE_LOCALE_e , std::string(), { "removelocale", "rloc" } ),

makeCmd<KeysCmd> ( ZypperCommand::KEYS_e, _("Key Management:"), { "keys", "lk" } ),
makeCmd<AddKeyCmd> ( ZypperCommand::ADDKEY_e, std::string(), { "addkey", "ak" } ),
makeCmd<RemoveKeyCmd> ( ZypperCommand::REMOVEKEY_e, std::string(), { "removekey", "rk" } ),

makeCmd<VersionCompareCmd> ( ZypperCommand::VERSION_CMP_e , _("Other Commands:"), { "versioncmp", "vcmp" } ),
makeCmd<TargetOSCmd> ( ZypperCommand::TARGET_OS_e , std::string(), { "targetos", "tos" } ),
makeCmd<LicensesCmd> ( ZypperCommand::LICENSES_e , std::string(), { "licenses" } ),
Expand Down Expand Up @@ -263,6 +268,10 @@ DEF_ZYPPER_COMMAND( REMOVE_LOCALE );

DEF_ZYPPER_COMMAND( NEEDS_REBOOTING );

DEF_ZYPPER_COMMAND( KEYS );
DEF_ZYPPER_COMMAND( ADDKEY );
DEF_ZYPPER_COMMAND( REMOVEKEY );

#undef DEF_ZYPPER_COMMAND
///////////////////////////////////////////////////////////////////

Expand Down
11 changes: 10 additions & 1 deletion src/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ struct ZypperCommand
static const ZypperCommand RUG_PATTERN_INFO;
static const ZypperCommand RUG_PRODUCT_INFO;
//!@}
//!

static const ZypperCommand KEYS;
static const ZypperCommand ADDKEY;
static const ZypperCommand REMOVEKEY;

static const ZypperCommand NEEDS_REBOOTING;

Expand Down Expand Up @@ -168,7 +173,11 @@ struct ZypperCommand
ADD_LOCALE_e,
REMOVE_LOCALE_e,

NEEDS_REBOOTING_e
NEEDS_REBOOTING_e,

KEYS_e,
ADDKEY_e,
REMOVEKEY_e
};

using CmdFactory = std::function<ZypperBaseCommandPtr ()>;
Expand Down
3 changes: 0 additions & 3 deletions src/Zypper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ void Zypper::assertZYppPtrGod()
}
}

///////////////////////////////////////////////////////////////////

namespace {

/** Whether user may create \a dir_r or has rw-access to it. */
Expand All @@ -169,7 +167,6 @@ namespace {

} //namespace

///////////////////////////////////////////////////////////////////

Zypper::Zypper()
: Application( std::make_shared<::Config>() )
Expand Down
1 change: 1 addition & 0 deletions src/callbacks/keyring.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Zypper.h"
#include "utils/prompt.h"
#include "Table.h"
#include "utils/misc.h"

///////////////////////////////////////////////////////////////////
namespace zypp
Expand Down
22 changes: 19 additions & 3 deletions src/commands/conditions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@
#include "conditions.h"
#include "global-settings.h"
#include "Zypper.h"
#include "utils/misc.h"

#include <sys/vfs.h>
#include <sys/statvfs.h>
#include <linux/magic.h>

extern ZYpp::Ptr God;

int NeedsRootCondition::check(std::string &err)
{
if ( geteuid() != 0 && !Zypper::instance().config().changedRoot )
Zypper &zypp = Zypper::instance();
if ( geteuid() != 0 )
{
err = _("Root privileges are required to run this command.");
return ZYPPER_EXIT_ERR_PRIVILEGES;
if ( ! zypp.config().changedRoot )
{
err = _("Root privileges are required to run this command.");
return ZYPPER_EXIT_ERR_PRIVILEGES;
}
else
{
Pathname homeDir( zypp.config().root_dir / God->homePath() );
if ( ! userMayUseDir( homeDir ) )
{
err = ( str::Format(_("Insufficient privileges to use directory '%s'.")) % homeDir );
return ( ZYPPER_EXIT_ERR_PRIVILEGES );
}
}
}
return ZYPPER_EXIT_OK;
}
Expand Down
8 changes: 8 additions & 0 deletions src/commands/keycmds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef ZYPPER_COMMANDS_KEYS_H_INCLUDED
#define ZYPPER_COMMANDS_KEYS_H_INCLUDED

#include "keys/keyscmd.h"
#include "keys/addkeycmd.h"
#include "keys/removekeycmd.h"

#endif
60 changes: 60 additions & 0 deletions src/commands/keys/addkeycmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
____ _ _ __ _ __ ___ _ _
|_ / || | '_ \ '_ \/ -_) '_|
/__|\_, | .__/ .__/\___|_|
|__/|_| |_|
\*---------------------------------------------------------------------------*/
#include "addkeycmd.h"
#include "Zypper.h"
#include "keys.h"
#include "commands/conditions.h"
#include "utils/messages.h"

AddKeyCmd::AddKeyCmd(std::vector<std::string> &&commandAliases_r) :
ZypperBaseCommand (
std::move( commandAliases_r ),
// translators: command synopsis; do not translate the command 'name (abbreviations)' or '-option' names
_("addkey <URL>"),
// translators: command summary
_("Add a new key to trust."),
// translators: command description
_("Imports a new key into the trusted database, the file can be specified as a URL."),
InitTarget )
{ }


zypp::ZyppFlags::CommandGroup AddKeyCmd::cmdOptions() const
{
return {};
}

void AddKeyCmd::doReset()
{
return;
}

int AddKeyCmd::execute( Zypper &zypper, const std::vector<std::string> &positionalArgs )
{
// too many arguments
if ( positionalArgs.size() > 1 ) {
report_too_many_arguments( help() );
return ( ZYPPER_EXIT_ERR_INVALID_ARGS );
}

//not enough args
if ( positionalArgs.size() < 1 ) {
report_too_few_arguments( help() );
return ( ZYPPER_EXIT_ERR_INVALID_ARGS );
}

importKey( zypper, positionalArgs.front() );
return zypper.exitCode();
}


std::vector<BaseCommandConditionPtr> AddKeyCmd::conditions() const
{
return {
std::make_shared<NeedsRootCondition>()
};
}
26 changes: 26 additions & 0 deletions src/commands/keys/addkeycmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------*\
____ _ _ __ _ __ ___ _ _
|_ / || | '_ \ '_ \/ -_) '_|
/__|\_, | .__/ .__/\___|_|
|__/|_| |_|
\*---------------------------------------------------------------------------*/
#ifndef ZYPPER_COMMANDS_KEYS_ADDKEYCMD_H_INCLUDED
#define ZYPPER_COMMANDS_KEYS_ADDKEYCMD_H_INCLUDED

#include "commands/basecommand.h"
#include "utils/flags/zyppflags.h"

class AddKeyCmd : public ZypperBaseCommand
{
public:
AddKeyCmd( std::vector<std::string> &&commandAliases_r );

// ZypperBaseCommand interface
protected:
zypp::ZyppFlags::CommandGroup cmdOptions() const override;
void doReset() override;
int execute( Zypper &zypper, const std::vector<std::string> &positionalArgs ) override;
std::vector<BaseCommandConditionPtr> conditions() const override;
};

#endif
48 changes: 48 additions & 0 deletions src/commands/keys/keyscmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
____ _ _ __ _ __ ___ _ _
|_ / || | '_ \ '_ \/ -_) '_|
/__|\_, | .__/ .__/\___|_|
|__/|_| |_|
\*---------------------------------------------------------------------------*/
#include "keyscmd.h"
#include "Zypper.h"
#include "keys.h"
#include "commands/commonflags.h"

KeysCmd::KeysCmd( std::vector<std::string> &&commandAliases_r ) :
ZypperBaseCommand (
std::move( commandAliases_r ),
// translators: command synopsis; do not translate the command 'name (abbreviations)' or '-option' names
_("keys [OPTIONS] [KEYID] [KEYFILE] ..."),
// translators: command summary
_("List all keys."),
// translators: command description
_("List all trusted keys or show detailed information about those specified as arguments, supports also keyfiles as argument."),
InitTarget )
{
init();
}

void KeysCmd::init()
{
_showDetails = false;
}

zypp::ZyppFlags::CommandGroup KeysCmd::cmdOptions() const
{
auto &that = *const_cast<KeysCmd *>(this);
return {{
CommonFlags::detailsFlag( that._showDetails, '\0', _("Show more details.") )
}};
}

void KeysCmd::doReset()
{
init();
}

int KeysCmd::execute( Zypper &zypper, const std::vector<std::string> & )
{
listTrustedKeys( zypper, positionalArguments(), _showDetails );
return zypper.exitCode();
}
29 changes: 29 additions & 0 deletions src/commands/keys/keyscmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------*\
____ _ _ __ _ __ ___ _ _
|_ / || | '_ \ '_ \/ -_) '_|
/__|\_, | .__/ .__/\___|_|
|__/|_| |_|
\*---------------------------------------------------------------------------*/
#ifndef ZYPPER_COMMANDS_KEYS_KEYSCMD_H_INCLUDED
#define ZYPPER_COMMANDS_KEYS_KEYSCMD_H_INCLUDED

#include "commands/basecommand.h"
#include "utils/flags/zyppflags.h"

class KeysCmd : public ZypperBaseCommand
{
public:
KeysCmd( std::vector<std::string> &&commandAliases_r );

private:
void init ();
bool _showDetails;

// ZypperBaseCommand interface
protected:
zypp::ZyppFlags::CommandGroup cmdOptions() const override;
void doReset() override;
int execute(Zypper &zypper, const std::vector<std::string> &) override;
};

#endif
Loading