]> eyrie.org Git - kerberos/perl-kerberos.git/commitdiff
Add initial Authen::Kerberos module
authorRuss Allbery <eagle@eyrie.org>
Thu, 6 Mar 2014 21:54:45 +0000 (13:54 -0800)
committerRuss Allbery <eagle@eyrie.org>
Thu, 6 Mar 2014 21:54:45 +0000 (13:54 -0800)
All this module supports so far is creating a Kerberos context.

.gitignore
lib/Authen/Kerberos.pm [new file with mode: 0644]
lib/Authen/Kerberos.xs [new file with mode: 0644]
t/data/krb5.conf [new file with mode: 0644]
t/kerberos/basic.t [new file with mode: 0755]
typemap

index e84b718bd575155ca036ca20f9f168abdaa8764f..4bbe5917b9eec1dc01ba4ab715e362f2a96061b7 100644 (file)
@@ -5,5 +5,6 @@
 /_build/
 /blib/
 /cover_db
+/lib/Authen/Kerberos.c
 /lib/Authen/Kerberos/Kadmin.c
 *.o
diff --git a/lib/Authen/Kerberos.pm b/lib/Authen/Kerberos.pm
new file mode 100644 (file)
index 0000000..7aa0134
--- /dev/null
@@ -0,0 +1,105 @@
+# Perl bindings for the Kerberos API.
+#
+# This is the Perl boostrap file for the Authen::Kerberos module, nearly all
+# of which is implemented in XS.  For the actual source, see Kerberos.xs.
+# This file contains the bootstrap and export code and the documentation.
+#
+# Currently, this only provides an interface to the Heimdal libkrb5 library.
+# This module will eventually become a level of indirection that can select
+# from several XS modules to support both MIT Kerberos and Heimdal.
+#
+# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2014
+#     The Board of Trustees of the Leland Stanford Junior University
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+package Authen::Kerberos;
+
+use 5.010;
+use strict;
+use warnings;
+
+use base qw(DynaLoader);
+
+use Authen::Kerberos::Exception;
+use Exporter qw(import);
+
+our $VERSION;
+
+# Set $VERSION in a BEGIN block for robustness.
+BEGIN {
+    $VERSION = '0.02';
+}
+
+# Load the binary module.
+bootstrap Authen::Kerberos $VERSION;
+
+1;
+__END__
+
+=for stopwords
+Allbery Heimdal keytabs libkrb5
+
+=head1 NAME
+
+Authen::Kerberos - Perl bindings for the Kerberos API
+
+=head1 SYNOPSIS
+
+    use Authen::Kerberos;
+
+    my $krb5 = Authen::Kerberos->new;
+
+=head1 REQUIREMENTS
+
+Perl 5.10 or later and the Heimdal libkrb5 library.
+
+=head1 DESCRIPTION
+
+Authen::Kerberos provides Perl bindings for the Kerberos library API, used
+to perform Kerberos operations such as acquiring tickets and examining
+ticket caches and keytabs.
+
+Currently, this module only supports Heimdal and only supports a small
+fraction of the Kerberos library API.  More functionality will be added
+later.
+
+=head1 CLASS METHODS
+
+All class methods throw Authen::Kerberos::Exception objects on any error.
+
+=over 4
+
+=item new([ARGS])
+
+Create a new Authen::Kerberos object, which holds the internal library
+state.  All further operations must be done with this object.
+
+=back
+
+=head1 AUTHOR
+
+Russ Allbery <eagle@eyrie.org>
+
+=head1 SEE ALSO
+
+L<Authen::Kerberos::Exception>
+
+=cut
diff --git a/lib/Authen/Kerberos.xs b/lib/Authen/Kerberos.xs
new file mode 100644 (file)
index 0000000..5102934
--- /dev/null
@@ -0,0 +1,77 @@
+/* -*- c -*-
+ * Perl bindings for the Kerberos API
+ *
+ * This is an XS source file, suitable for processing by xsubpp, that
+ * generates Perl bindings for the Kerberos API (libkrb5).  It also provides
+ * enough restructuring so that the C function calls can be treated as method
+ * calls on a Kerberos context object.
+ *
+ * Written by Russ Allbery <eagle@eyrie.org>
+ * Copyright 2014
+ *     The Board of Trustees of the Leland Stanford Junior University
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+
+#include <krb5.h>
+
+/*
+ * This typedefs are needed for xsubpp to work its magic with type translation
+ * to Perl objects.  The krb5_context pointer is used as the Authen::Kerberos
+ * object, wrapped in an SV and blessed.
+ */
+typedef krb5_context Authen__Kerberos;
+
+
+/* XS code below this point. */
+
+MODULE = Authen::Kerberos       PACKAGE = Authen::Kerberos
+
+PROTOTYPES: DISABLE
+
+
+Authen::Kerberos
+new(class)
+    const char *class
+  PREINIT:
+    krb5_context ctx;
+    krb5_error_code code;
+  CODE:
+{
+    code = krb5_init_context(&ctx);
+    if (code != 0)
+        krb5_croak(NULL, code, "krb5_init_context", FALSE);
+    RETVAL = ctx;
+}
+  OUTPUT:
+    RETVAL
+
+
+void
+DESTROY(self)
+    Authen::Kerberos self
+  CODE:
+{
+    if (self != NULL)
+        krb5_free_context(self);
+}
diff --git a/t/data/krb5.conf b/t/data/krb5.conf
new file mode 100644 (file)
index 0000000..eab68a9
--- /dev/null
@@ -0,0 +1,2 @@
+[libdefaults]
+    default_realm = TEST.EXAMPLE.COM
diff --git a/t/kerberos/basic.t b/t/kerberos/basic.t
new file mode 100755 (executable)
index 0000000..6f639e4
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+#
+# Test suite for Authen::Kerberos basic functionality.
+#
+# Written by Russ Allbery <eagle@eyrie.org>
+# Copyright 2014
+#     The Board of Trustees of the Leland Stanford Junior University
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+use 5.010;
+use autodie;
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+BEGIN {
+    use_ok('Authen::Kerberos');
+}
+
+# Force use of our local krb5.conf so that testing doesn't depend on the local
+# system Kerberos configuration.
+local $ENV{KRB5_CONFIG} = 't/data/krb5.conf';
+
+# Test creation of a Kerberos context (Authen::Kerberos object).
+my $krb5 = Authen::Kerberos->new;
+isa_ok($krb5, 'Authen::Kerberos');
diff --git a/typemap b/typemap
index b9176d3cfcb81c6e311db953473c6eb78e644979..d92bbc0c35f3b42ff92056eb8daad5fb3d62aa8c 100644 (file)
--- a/typemap
+++ b/typemap
@@ -1,4 +1,4 @@
-# Typemap file for the Perl bindings to the Kerberos library.
+# Typemap file for the Perl bindings to the Kerberos library.  -*- conf -*-
 #
 # Written by Russ Allbery <eagle@eyrie.org>
 # Copyright 2014
@@ -24,6 +24,7 @@
 
 TYPEMAP
 
+Authen::Kerberos                T_PTROBJ_NU
 Authen::Kerberos::Kadmin        T_PTROBJ_NU
 
 INPUT