Marcin Kasperski avatar Marcin Kasperski committed b1652e5

Initiating by shameless copy of gnome code

Comments (0)

Files changed (19)

+syntax: regexp
+
+~$
+^_build/
+^Build$
+^blib/
+^MYMETA\.
+\.c$
+\.o$
+\.pyc$
+\.bak$
+^META\.
+^Makefile\.PL
+^Passwd-Keyring-Gnome-v.*\.tar\.gz$
+use 5.006;
+use strict;
+use warnings;
+use Module::Build;
+use ExtUtils::PkgConfig;
+
+my %gnome_keyring_pkg_info = ExtUtils::PkgConfig->find("gnome-keyring-1");
+
+my $builder = Module::Build->new(
+    module_name         => 'Passwd::Keyring::Gnome',
+    dynamic_config      => 1,
+    license             => 'perl',
+    dist_author         => q{Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>},
+    dist_version_from   => 'lib/Passwd/Keyring/Gnome.pm',
+    build_requires => {
+        'Module::Build' => '0.19', # xs
+        'ExtUtils::CBuilder' => 0,
+        'Test::More' => 0,
+        'Test::Pod::Coverage' => '1.0.8',
+    },
+    requires => {
+        'perl' => 5.006,
+    },
+    add_to_cleanup      => [ 'Passwd-Keyring-Gnome-*' ],
+    create_makefile_pl => 'traditional',
+    # pkg-config --cflags gnome-keyring-1
+    #extra_compiler_flags => '-I/usr/include/gnome-keyring-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include',
+    extra_compiler_flags => $gnome_keyring_pkg_info{cflags},
+    # pkg-config --libs gnome-keyring-1
+    #extra_linker_flags => '-lgnome-keyring -lglib-2.0',
+    extra_linker_flags => $gnome_keyring_pkg_info{libs},
+    needs_compiler => 1,
+    #c_source => 'src',
+    #xs_files => {
+        #'./Costam.xs' => 'lib/MyMod/Costam.xs',
+    #},
+);
+
+$builder->create_build_script();
+Revision history for Keyring-Gnome
+
+0.01    Date/time
+        First version, released on an unsuspecting world.
+
+Build.PL
+Changes
+lib/Passwd/Keyring/Gnome.pm
+lib/Passwd/Keyring/Gnome.xs
+MANIFEST			This list of files
+README
+t/00-load.t
+t/01-set-and-get.t
+t/02-many-sets-and-gets.t
+t/03-recovering-in-sep-prog.t
+t/99-cleanup.t
+t/boilerplate.t
+t/manifest.t
+t/pod-coverage.t
+t/pod.t
+Makefile.PL
+META.yml
+META.json
+
+#!start included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+\B\.cvsignore$
+
+# Avoid VMS specific MakeMaker generated files
+\bDescrip.MMS$
+\bDESCRIP.MMS$
+\bdescrip.mms$
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$         # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+\bBuild.bat$
+\bBuild.COM$
+\bBUILD.COM$
+\bbuild.com$
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+\.tmp$
+\.#
+\.rej$
+
+# Avoid OS-specific files/dirs
+# Mac OSX metadata
+\B\.DS_Store
+# Mac OSX SMB mount metadata files
+\B\._
+
+# Avoid Devel::Cover and Devel::CoverX::Covered files.
+\bcover_db\b
+\bcovered\b
+
+# Avoid MYMETA files
+^MYMETA\.
+#!end included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP
+
+# Avoid configuration metadata file
+^MYMETA\.
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\bBuild.bat$
+\b_build
+\bBuild.COM$
+\bBUILD.COM$
+\bbuild.com$
+^MANIFEST\.SKIP
+
+# Avoid archives of this distribution
+\bPasswd-Keyring-Gnome-[\d\.\_]+
+
+# Repo-related
+^\.hg
+^\.bitbucket\.url
+^version_hook\.py
+^ignore\.txt
+
+# Produced
+^lib/Passwd/Keyring/Gnome\.[co]$
+Passwd::Keyring::Gnome
+
+Passwd::Keyring is about using secure storage for passwords
+and other credentials used in perl scripts and applications.
+
+Passwd::Keyring::Gnome uses GNOME Keyring API to securely
+preserve passwords and is available to people using GNOME 
+desktop environment.
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+	perl Build.PL
+	./Build
+	./Build test
+	./Build install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+    perldoc Keyring::Gnome
+
+You can also look for information at:
+
+    http://bitbucket.org/Mekk/perl-keyring
+
+
+LICENSE AND COPYRIGHT
+
+Copyright (C) 2012 Marcin Kasperski
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+blib*
+Makefile
+Makefile.old
+Build
+Build.bat
+_build*
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+Passwd-Keyring-Gnome-*

lib/Passwd/Keyring/Gnome.pm

+package Passwd::Keyring::Gnome;
+
+use warnings;
+use strict;
+#use parent 'Keyring';
+
+require DynaLoader;
+require AutoLoader;
+
+use base 'DynaLoader';
+
+=head1 NAME
+
+Passwd::Keyring::Gnome - Password storage implementation based on GNOME Keyring.
+
+=head1 VERSION
+
+Version 0.21
+
+=cut
+
+our $VERSION = '0.21';
+
+bootstrap Passwd::Keyring::Gnome $VERSION;
+
+=head1 SYNOPSIS
+
+Gnome Keyring based implementation of L<Keyring>.
+
+    use Passwd::Keyring::Gnome;
+
+    my $keyring = Passwd::Keyring::Gnome->new();
+
+    $keyring->set_password("John", "verysecret", "my-pseudodomain");
+    # And later, on next run maybe
+    my $password = $keyring->get_password("John", "my-pseudodomain");
+    # plus
+    $keyring->clear_password("John", "my-pseudodomain");
+
+=head1 SUBROUTINES/METHODS
+
+=head2 new
+
+Initializes the processing. Croaks if gnome keyring does not 
+seem to be available.
+
+=cut
+
+sub new {
+    my $self = {};
+    bless $self;
+
+    # TODO: catch and rethrow exceptions
+    my $name = Passwd::Keyring::Gnome::_get_default_keyring_name();
+    croak ("Gnome Keyring seems unavailable") unless $name;
+
+    return $self;
+}
+
+=head2 set_password(username, password, domain)
+
+Sets (stores) password identified by given domain for given user 
+
+=cut
+
+sub set_password {
+    my ($self, $user_name, $user_password, $domain) = @_;
+    Passwd::Keyring::Gnome::_set_password($user_name, $user_password, $domain);
+}
+
+=head2 get_password($user_name, $domain)
+
+Reads previously stored password for given user in given app.
+If such password can not be found, returns undef.
+
+=cut
+
+sub get_password {
+    my ($self, $user_name, $domain) = @_;
+    my $pwd = Passwd::Keyring::Gnome::_get_password($user_name, $domain);
+    return undef if (!defined($pwd)) or $pwd eq "";
+    return $pwd;
+}
+
+=head2 clear_password($user_name, $domain)
+
+Removes given password (if present)
+
+=cut
+
+sub clear_password {
+    my ($self, $user_name, $domain) = @_;
+    Passwd::Keyring::Gnome::_set_password($user_name, "", $domain);
+}
+
+=head1 AUTHOR
+
+Marcin Kasperski, C<< <Marcin.Kasperski at mekk.waw.pl> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to 
+issue tracker at L<https://bitbucket.org/Mekk/perl-keyring-gnome>.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc Passwd::Keyring::Gnome
+
+You can also look for information at:
+
+    L<https://bitbucket.org/Mekk/perl-keyring-gnome>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2010-2012 Marcin Kasperski.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+=cut
+
+
+1; # End of Passwd::Keyring::Gnome
+
+

lib/Passwd/Keyring/Gnome.xs

+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#include "glib.h"
+#include "gnome-keyring.h"
+
+const char* SERVER = "using_gnome_keyring";
+
+MODULE=Passwd::Keyring::Gnome    PACKAGE=Passwd::Keyring::Gnome 
+
+SV*
+_get_default_keyring_name()
+    CODE:
+        char *name;
+        gnome_keyring_get_default_keyring_sync(&name);
+        RETVAL = newSVpv(name, 0);
+        g_free(name);
+    OUTPUT:
+        RETVAL
+
+void
+_set_password(const char *user, const char* password, const char *domain)
+    CODE:
+        guint32 item_id;
+        if(GNOME_KEYRING_RESULT_OK == 
+           gnome_keyring_set_network_password_sync(
+              NULL, /* keyring (null=default) */
+              user,
+              domain,
+              SERVER, /* server */
+              NULL, /* remote object */
+              NULL, /* protocol */
+              NULL, /* auth-type */
+              0,    /* port */
+              password,    
+              &item_id))
+        {
+              /* printf("Saved password, id: %d\n", item_id); */
+              return;
+        }
+        else
+        {
+                croak("Failed to set password");
+        }
+
+
+SV*
+_get_password(const char *user, const char *domain)
+    CODE:
+        GList *results;
+        GnomeKeyringResult status = 
+             gnome_keyring_find_network_password_sync(
+                user,
+                domain,
+                SERVER, /* server */
+                NULL, /* remote object */
+                NULL, /* protocol */
+                NULL, /* auth-type */
+                0,    /* port */
+                &results);
+        if(status == GNOME_KEYRING_RESULT_OK)
+        {
+            GList *node;
+            GnomeKeyringNetworkPasswordData *item;
+            RETVAL = 0;
+            for (node = g_list_first (results);
+                 node != NULL;
+                 node = g_list_next (node))
+            {
+              item = (GnomeKeyringNetworkPasswordData *) node->data;
+              RETVAL = newSVpv(item->password, 0);
+              /*
+              printf("Found item.\n");
+              printf("  item-id: %d\n", item->item_id);
+              printf("  keyring: %s\n", item->keyring);
+              printf("  server: %s\n", item->server);
+              printf("  object: %s\n", item->object);
+              printf("  port: %d\n", item->port);
+              printf("  user: %s\n", item->user);
+              printf("  domain: %s\n", item->domain);
+              printf("  password: %s\n", item->password); */
+              break;
+            }
+
+            if(! RETVAL)
+            {
+               RETVAL = newSV(0);
+            }
+
+            gnome_keyring_network_password_list_free(results);
+        }
+        else if (status == GNOME_KEYRING_RESULT_NO_MATCH)
+        {
+            RETVAL = newSV(0);
+        }
+        else
+        {
+            croak("Failed to find a password. Error code: %d", status);
+        }
+    OUTPUT:
+        RETVAL
+
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+    use_ok( 'Passwd::Keyring::Gnome' ) || print "Bail out!\n";
+}
+
+diag( "Testing Passwd::Keyring::Gnome $Passwd::Keyring::Gnome::VERSION, Perl $], $^X" );

t/01-set-and-get.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 3;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->set_password("John", "secret", 'my@@domain');
+#$ring->set_password("John", "secret", 'my@@domain');
+#$ring->set_password("John", "secret", 'my@@domain');
+
+ok( 1, "set_password works" );
+
+ok( $ring->get_password("John", 'my@@domain') eq 'secret', "get works");
+

t/02-many-sets-and-gets.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 11;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->set_password("Paul", "secret-Paul", 'my@@domain');
+$ring->set_password("Gregory", "secret-Greg", 'my@@domain');#
+$ring->set_password("Paul", "secret-Paul2", 'other@@domain');
+$ring->set_password("Duke", "secret-Duke", 'my@@domain');
+
+ok( 1, "set_password works" );
+
+ok( $ring->get_password("Paul", 'my@@domain') eq 'secret-Paul', "get works");
+
+ok( $ring->get_password("Gregory", 'my@@domain') eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", 'other@@domain') eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", 'my@@domain') eq 'secret-Duke', "get works");
+
+$ring->clear_password("Paul", 'my@@domain');
+ok(1, "clear_password works");
+
+ok( ! defined($ring->get_password("Paul", 'my@@domain')), "get works");
+
+ok( $ring->get_password("Gregory", 'my@@domain') eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", 'other@@domain') eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", 'my@@domain') eq 'secret-Duke', "get works");
+
+

t/03-recovering-in-sep-prog.t

+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 5;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+ok( ! defined($ring->get_password("Paul", 'my@@domain')), "get works");
+
+ok( $ring->get_password("Gregory", 'my@@domain') eq 'secret-Greg', "get works");
+
+ok( $ring->get_password("Paul", 'other@@domain') eq 'secret-Paul2', "get works");
+
+ok( $ring->get_password("Duke", 'my@@domain') eq 'secret-Duke', "get works");
+
+
+#!perl -T
+
+use strict;
+use warnings;
+use Test::Simple tests => 8;
+
+use Passwd::Keyring::Gnome;
+
+my $ring = Passwd::Keyring::Gnome->new;
+
+ok( defined($ring) && ref $ring eq 'Passwd::Keyring::Gnome',   'new() works' );
+
+$ring->clear_password("Paul", 'my@@domain');
+ok(1, "clear_password works");
+
+ok( $ring->clear_password("Gregory", 'my@@domain'));
+ok(1, "clear_password works");
+
+ok( $ring->clear_password("Paul", 'other@@domain'));
+ok(1, "clear_password works");
+
+ok( $ring->clear_password("Duke", 'my@@domain'));
+ok(1, "clear_password works");
+
+
+#!perl -T
+
+use 5.006;
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+sub not_in_file_ok {
+    my ($filename, %regex) = @_;
+    open( my $fh, '<', $filename )
+        or die "couldn't open $filename for reading: $!";
+
+    my %violated;
+
+    while (my $line = <$fh>) {
+        while (my ($desc, $regex) = each %regex) {
+            if ($line =~ $regex) {
+                push @{$violated{$desc}||=[]}, $.;
+            }
+        }
+    }
+
+    if (%violated) {
+        fail("$filename contains boilerplate text");
+        diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
+    } else {
+        pass("$filename contains no boilerplate text");
+    }
+}
+
+sub module_boilerplate_ok {
+    my ($module) = @_;
+    not_in_file_ok($module =>
+        'the great new $MODULENAME'   => qr/ - The great new /,
+        'boilerplate description'     => qr/Quick summary of what the module/,
+        'stub function definition'    => qr/function[12]/,
+    );
+}
+
+TODO: {
+  local $TODO = "Need to replace the boilerplate text";
+
+  not_in_file_ok(README =>
+    "The README is used..."       => qr/The README is used/,
+    "'version information here'"  => qr/to provide version information/,
+  );
+
+  not_in_file_ok(Changes =>
+    "placeholder date/time"       => qr(Date/time)
+  );
+
+  module_boilerplate_ok('lib/Passwd/Keyring/Gnome.pm');
+
+
+}
+
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+unless ( $ENV{RELEASE_TESTING} ) {
+    plan( skip_all => "Author tests not required for installation" );
+}
+
+eval "use Test::CheckManifest 0.9";
+plan skip_all => "Test::CheckManifest 0.9 required" if $@;
+ok_manifest();
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod::Coverage
+my $min_tpc = 1.08;
+eval "use Test::Pod::Coverage $min_tpc";
+plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
+    if $@;
+
+# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
+# but older versions don't recognize some common documentation styles
+my $min_pc = 0.18;
+eval "use Pod::Coverage $min_pc";
+plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
+    if $@;
+
+all_pod_coverage_ok();
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod
+my $min_tp = 1.22;
+eval "use Test::Pod $min_tp";
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
+
+all_pod_files_ok();
+# -*- coding: utf-8 -*-
+
+"""
+Updating version number on "hg tag".
+
+To use:
+
+  [hooks]
+  pre-tag=python:version_hook.py:version_update
+
+Note: pre-tag, not pretag! In the latter the changeset being tagged
+is already set.
+"""
+
+VERSION = "0.21"
+
+UPDATED_FILES = [
+    "lib/Passwd/Keyring/Gnome.pm",
+    ]
+
+def _patch_perl_files(ui, new_version_no):
+    """
+    Patches all perl files to new version number, returns modified files.
+    """
+    import os, re
+    version_regexps = [
+        re.compile(r"^(?P<pfx>our +\$VERSION *= *').*?(?P<sfx>'.*)$"),
+        re.compile(r"^(?P<pfx>Version +)\d+\.\d+(\.\d+)?(?P<sfx>\.? *)$"),
+        ]
+
+    location = os.path.dirname(__file__)
+    updated_files = []
+    for candidate in UPDATED_FILES:
+        full_name = os.path.join(location, candidate)
+        changes = 0
+        file_lines = []
+        ui.note("Checking file %s\n" % candidate)
+        with open(full_name, "r") as input:
+            for line in input.readlines():
+                m = None
+                for rgxp in version_regexps:
+                    m = rgxp.search(line)
+                    if m:
+                        ui.note("Patching line %s" % line)
+                        break
+                if m:
+                    file_lines.append(
+                        m.group('pfx') + new_version_no + m.group('sfx') + "\n")
+                    changes += 1
+                else:
+                    file_lines.append(line)
+        if changes:
+            ui.status("Version updater: Replacing old version number with {0:>s} in {1}\n".format(new_version_no, full_name))
+            with open(full_name, "w") as output:
+                output.writelines(file_lines)
+            updated_files.append(full_name)
+    return updated_files
+    
+def version_update(repo, ui, hooktype, pats, opts, **kwargs):
+    """
+    Method used in mercurial version-update hook. Don't call directly.
+    """
+    import re
+    import mercurial.commands
+
+    # Regexps for handled version number syntaxes
+    tag_regexps = [
+        # something_1-2, something-1.2 and similar
+        re.compile(r"[^-_0-9][-_](?P<major>[0-9]+)[-_\.](?P<minor>[0-9]+)$"),
+        # 1.2, 1-2, 1_2
+        re.compile(r"^(?P<major>[0-9]+)[-_\.](?P<minor>[0-9]+)$"),
+        ]
+
+    if opts.get('local'):
+        ui.note("Version updater: ignoring local tag\n")
+        return
+    if opts.get('remove'):
+        ui.note("Version updater: ignoring tag removal\n")
+        return
+    if opts.get('rev'):
+        ui.note("Version updater: ignoring tag placed by rev\n")
+        return
+
+    if len(pats) != 1:
+        ui.warn("Version updater: unexpected arguments, pats=%s\n" % pats)
+        return True # means fail
+
+    tag_name = pats[0]
+
+    version_no = None
+    for tag_regexp in tag_regexps:
+        m = tag_regexp.search(tag_name)
+        if m:
+            version_no = "{major:>s}.{minor:>s}".format(**m.groupdict())
+            break
+    if not version_no:
+        ui.warn("Version updater: Given tag does not seem to be versioned. Please make proper tags (1.2, xxxx_1-2, xaear-aera-1.2 or similar\n")
+        return True # means fail
+
+    if version_no == VERSION:
+        ui.note("Version updater: version number {0:>s} is already correct\n".format(version_no))
+        return False # means OK
+
+    # Regexp for VERSION= line
+    py_version_regexp = re.compile(r"^VERSION *= *")
+
+    my_name = __file__
+    if my_name.endswith(".pyc") or my_name.endswith(".pyo"):
+        my_name = my_name[:-1]
+
+    ui.status("Version updater: Replacing old version number {0:>s} with {1:>s} in {2}\n".format(
+        VERSION, version_no, my_name))
+
+    file_lines = []
+    changes = 0
+    with open(my_name, "r") as input:
+        for line in input.readlines():
+            if py_version_regexp.search(line):
+                file_lines.append('VERSION = "%s"\n' % version_no)
+                changes += 1
+            else:
+                file_lines.append(line)
+    if not changes:
+        ui.warn("Version updater: Line starting with VERSION= not found in {0:>s}.\nPlease correct this file and retry\n".format(my_name))
+        return True #means fail
+    with open(my_name, "w") as output:
+        output.writelines(file_lines)
+
+    updated_perl_files = _patch_perl_files(ui, version_no)
+
+    ui.note("Commiting updated version number\n")
+    mercurial.commands.commit(
+        ui, repo,
+        my_name,
+        *updated_perl_files,
+        message="Version number set to %s" % version_no)
+    return False #means ok
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.