-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
252 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*---------------------------------------------------------------------------*\ | ||
____ _ _ __ _ __ ___ _ _ | ||
|_ / || | '_ \ '_ \/ -_) '_| | ||
/__|\_, | .__/ .__/\___|_| | ||
|__/|_| |_| | ||
\*---------------------------------------------------------------------------*/ | ||
|
||
#include "Zypper.h" | ||
#include "Table.h" | ||
#include "utils/misc.h" | ||
|
||
#include <zypp/ZYpp.h> | ||
#include <zypp/target/rpm/RpmDb.h> | ||
#include <zypp/KeyManager.h> | ||
|
||
|
||
extern ZYpp::Ptr God; | ||
|
||
template <class T> | ||
void dumpKeyList ( Zypper &zypp_r, const std::list<T> &keysFound_r, bool details ) | ||
{ | ||
if ( keysFound_r.empty() ) | ||
{ | ||
zypp_r.out().warning(_("No keys found.") ); | ||
} | ||
else | ||
{ | ||
zypp_r.out().gap(); | ||
if ( details || zypp_r.globalOpts().machine_readable ) | ||
{ | ||
for(const auto &key : keysFound_r) | ||
{ | ||
dumpKeyInfo( std::cout , key ); | ||
zypp_r.out().gap(); | ||
} | ||
} else { | ||
Table t; | ||
t << ( TableHeader() | ||
/* translators: Table column header */ << _("ID") | ||
/* translators: Table column header */ << _("Name") | ||
/* translators: Table column header */ << _("Expires")); | ||
|
||
for(const auto &key : keysFound_r) | ||
{ | ||
t << ( TableRow() | ||
<< key.id() | ||
<< key.name() | ||
<< key.expires().asString()); | ||
} | ||
t.dumpTo( std::cout ); | ||
zypp_r.out().gap(); | ||
} | ||
} | ||
zypp_r.setExitCode( ZYPPER_EXIT_OK ); | ||
} | ||
|
||
void listTrustedKeys ( Zypper &zypp_r ) | ||
{ | ||
if ( !God || !God->target() || !God->keyRing() ) | ||
return; | ||
|
||
KeyRing_Ptr keyRing = God->keyRing(); | ||
std::list<PublicKeyData> trustedKeys = keyRing->trustedPublicKeyData(); | ||
|
||
if ( zypp_r.arguments().size() ) | ||
{ | ||
std::list<PublicKeyData> pubKeys; | ||
for ( const std::string &arg : zypp_r.arguments() ) | ||
{ | ||
PublicKeyData foundKey = keyRing->trustedPublicKeyData(arg); | ||
if ( foundKey ) { | ||
//this is a key ID | ||
pubKeys.push_back(foundKey); | ||
} else { | ||
// is the current arg a path or a ID | ||
filesystem::PathInfo path (arg); | ||
if (!path.isExist()) | ||
{ | ||
zypp_r.out().warning( str::Format(_("Argument '%1%' is not a trusted ID nor a existing file.")) % arg ); | ||
zypp_r.setExitCode( ZYPPER_EXIT_ERR_INVALID_ARGS ); | ||
return; | ||
} | ||
|
||
KeyManagerCtx::Ptr keyMgr = KeyManagerCtx::createForOpenPGP(); | ||
if (!keyMgr) | ||
{ | ||
zypp_r.out().error( "Unable to initialize key manager backend" ); | ||
zypp_r.setExitCode( ZYPPER_EXIT_ERR_ZYPP ); | ||
return; | ||
} | ||
pubKeys.splice( pubKeys.end(), keyMgr->readKeyFromFile( arg )); | ||
} | ||
} | ||
//print always in detail mode here, the user most likely wants to know more about the key | ||
dumpKeyList( zypp_r, pubKeys, true ); | ||
} | ||
else | ||
{ | ||
const target::rpm::RpmDb &rpmdb = God->target()->rpmDb(); | ||
dumpKeyList( zypp_r, rpmdb.pubkeys(), zypp_r.cOpts().count("details") ); | ||
} | ||
} | ||
|
||
#if 0 | ||
void removeKey(Zypper &zypp_r ) | ||
{ | ||
|
||
} | ||
|
||
void exportKey( Zypper &zypp_r ) | ||
{ | ||
|
||
} | ||
|
||
void checkKey( Zypper &zypp_r ) | ||
{ | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*---------------------------------------------------------------------------*\ | ||
____ _ _ __ _ __ ___ _ _ | ||
|_ / || | '_ \ '_ \/ -_) '_| | ||
/__|\_, | .__/ .__/\___|_| | ||
|__/|_| |_| | ||
\*---------------------------------------------------------------------------*/ | ||
#ifndef ZYPPERKEYS_H_ | ||
#define ZYPPERKEYS_H_ | ||
|
||
#include <zypp/Pathname.h> | ||
|
||
class Zypper; | ||
|
||
void listTrustedKeys ( Zypper &zypp_r ); | ||
|
||
#if 0 | ||
void removeKey ( Zypper &zypp_r ); | ||
void exportKey ( Zypper &zypp_r ); | ||
void checkKey ( Zypper &zypp_r ); | ||
#endif | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.