pam 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,102 @@
1
+ Ruby/PAM Module
2
+
3
+ Original Copyright (C) 2000,2001,2002,2003
4
+ Takaaki Tateishi (ttate@users.sourceforge.net)
5
+ Subsequent Copyright Bryan Kearney (bkearney@redhat.com)
6
+
7
+ Ruby/PAM is an extension libraries which provides PAM bindings for Ruby.
8
+ It is a fork of the original Ruby/PAM project written by Takaaki Tateishi
9
+ that was distributed at http://ruby-pam.sourceforge.net/.
10
+
11
+ System Requirements
12
+ --------------------
13
+ I checked that this module can work on the following operating systems and
14
+ environments.
15
+
16
+ * linux-2.6 + ruby-1.8.1
17
+
18
+ The previous incarnation was tested on:
19
+
20
+ * linux-2.4.0 + ruby-1.6.4 + glibc2.1.2
21
+ * solaris8 + ruby-1.6.0
22
+ * solaris7 + ruby-1.6.0
23
+
24
+ Installation
25
+ -------------
26
+
27
+ 1. rake package
28
+ 2. cd pkg
29
+ 3. gem install ruby-pam*.gem
30
+
31
+ Methods
32
+ ---------
33
+ service, user, item : String
34
+ conv : Proc or Symbol
35
+ msec, type, flag : Integer
36
+
37
+ * PAM.start(service, user, conv, conv_data = nil){ ... }
38
+ * PAM::Handle.new(service, user, conv, conv_data = nil){ ... }
39
+ * PAM::Handle.start(service, user, conv, conv_data = nil){ ... }
40
+ * PAM::Handle#end() -- called at the above block end.
41
+ * PAM::Handle#status()
42
+ * PAM::Handle#conv(msg)
43
+ * PAM::Handle#authenticate(flag)
44
+ * PAM::Handle#acct_mgmt(flag = 0)
45
+ * PAM::Handle#set_fail_delay(msec)
46
+ * PAM::Handle#setcred(flag = 0)
47
+ * PAM::Handle#chauthtok(flag = 0)
48
+ * PAM::Handle#open_session(flag = 0){ ... }
49
+ * PAM::Handle#close_session(flag = 0)
50
+ * PAM::Handle#set_item(type, item)
51
+ * PAM::Handle#get_item(type, item)
52
+ * PAM::Handle#strerror(errnum)
53
+ * PAM::Handle#putenv("veriable=value")
54
+ * PAM::Handle#getenv("veriable")
55
+
56
+ Structures
57
+ ------------
58
+ * Message (Struct) -- Message.new(msg_style, msg)
59
+ * Response (Struct) -- Response.new(resp, resp_retcode)
60
+
61
+ Exceptions
62
+ ------------
63
+ * PAMError (Class)
64
+ * PAM_SUCCESS
65
+ * PAM_OPEN_ERR
66
+ * ...
67
+ see 'pam_appl.h'
68
+
69
+
70
+ 'PAM::' Constants
71
+ ------------------
72
+ * PAM_VERSION
73
+ * PAM_MAJOR_VERSION
74
+ * PAM_MINOR_VERSION
75
+ * PAM_CONV
76
+ * PAM_CHANGE_EXPIRED_AUTHTOK
77
+ * PAM_DELETE_CRED
78
+ * PAM_ERROR_MSG
79
+ * PAM_ESTABLISH_CRED
80
+ * PAM_OLDAUTHTOK
81
+ * PAM_PROMPT_ECHO_OFF
82
+ * PAM_PROMPT_ECHO_ON
83
+ * PAM_REFRESH_CRED
84
+ * PAM_REINITIALIZE_CRED
85
+ * PAM_RHOST
86
+ * PAM_RUSER
87
+ * PAM_SERVICE
88
+ * PAM_SILENT
89
+ * PAM_TEXT_INFO
90
+ * PAM_TTY
91
+ * PAM_USER
92
+ * PAM_USER_PROMPT
93
+ * PAM_DISALLOW_NULL_AUTHTOK
94
+
95
+
96
+ Others
97
+ -------
98
+ * http://www.kernel.org/pub/linux/libs/pam/
99
+ Linux-PAM (PAM implementation for Linux)
100
+ * http://pam.sourceforge.net/mod_auth_pam/
101
+ mod_auth_pam (apache authentication module using PAM)
102
+
data/Rakefile ADDED
@@ -0,0 +1,100 @@
1
+ # -*- ruby -*-
2
+ # Rakefile: build ruby pam bindings
3
+ #
4
+ # Copyright (C) 2008 Red Hat, Inc.
5
+ #
6
+ # Distributed under the GNU Lesser General Public License v2.1 or later.
7
+ # See COPYING for details
8
+ #
9
+ # Bryan Kearney <bkearney@redhat.com>
10
+
11
+ require 'rake/clean'
12
+ require 'rake/rdoctask'
13
+ require 'rake/testtask'
14
+ require 'rake/gempackagetask'
15
+
16
+ PKG_NAME='ruby-pam'
17
+ GEM_NAME='pam'
18
+ PKG_VERSION='1.5.2'
19
+ EXT_CONF='ext/extconf.rb'
20
+ MAKEFILE="Makefile"
21
+ PAM_MODULE="ext/pam.so"
22
+ SPEC_FILE="rubygem-pam.spec"
23
+
24
+ #
25
+ # Building the actual bits
26
+ #
27
+ CLEAN.include [ "**/*~",
28
+ "ext/**/*.o", PAM_MODULE,
29
+ "pkg/**" ]
30
+
31
+ file MAKEFILE => EXT_CONF do |t|
32
+ Dir::chdir(File::dirname(EXT_CONF)) do
33
+ unless sh "ruby #{File::basename(EXT_CONF)}"
34
+ $stderr.puts "Failed to run extconf"
35
+ break
36
+ end
37
+ end
38
+ end
39
+
40
+ file PAM_MODULE => MAKEFILE do |t|
41
+ Dir::chdir(File::dirname(EXT_CONF)) do
42
+ unless sh "make"
43
+ $stderr.puts "make failed"
44
+ break
45
+ end
46
+ end
47
+ end
48
+ desc "Build the native library"
49
+ task :build => PAM_MODULE
50
+
51
+ #
52
+ # Generate the documentation
53
+ #
54
+ Rake::RDocTask.new do |rd|
55
+ rd.main = "README.rdoc"
56
+ rd.rdoc_dir = "doc/site/api"
57
+ rd.rdoc_files.include("README.rdoc", "ext/**/*.[ch]","lib/**/*.rb")
58
+ end
59
+
60
+
61
+ #
62
+ # Packaging
63
+ #
64
+ PKG_FILES = FileList[
65
+ "Rakefile", "COPYING", "LICENSE", "README", "ChangeLog",
66
+ "ext/*.[ch]", "ext/*.rb", "test/*.rb", "MANIFEST", EXT_CONF]
67
+
68
+ DIST_FILES = FileList[
69
+ "pkg/*.tgz", "pkg/*.gem"
70
+ ]
71
+
72
+ SPEC = Gem::Specification.new do |s|
73
+ s.name = GEM_NAME
74
+ s.version = PKG_VERSION
75
+ s.email = "bkearney@redhat.com"
76
+ s.homepage = "http://sourceforge.net/projects/ruby-pam"
77
+ s.summary = "Ruby bindings for pam"
78
+ s.files = PKG_FILES
79
+ s.autorequire = "pam-devel"
80
+ s.required_ruby_version = '>= 1.8.1'
81
+ s.extensions = "ext/extconf.rb"
82
+ s.description = "Ruby bindings pam."
83
+ end
84
+
85
+ Rake::GemPackageTask.new(SPEC) do |pkg|
86
+ pkg.need_tar = true
87
+ pkg.need_zip = true
88
+ end
89
+
90
+ desc "Build (S)RPM for #{PKG_NAME}"
91
+ task :rpm => [ :package ] do |t|
92
+ system("sed -e 's/@VERSION@/#{PKG_VERSION}/' #{SPEC_FILE} > pkg/#{SPEC_FILE}")
93
+ Dir::chdir("pkg") do |dir|
94
+ dir = File::expand_path(".")
95
+ system("rpmbuild --define '_topdir #{dir}' --define '_sourcedir #{dir}' --define '_srcrpmdir #{dir}' --define '_rpmdir #{dir}' --define '_builddir #{dir}' -ba #{SPEC_FILE} > rpmbuild.log 2>&1")
96
+ if $? != 0
97
+ raise "rpmbuild failed"
98
+ end
99
+ end
100
+ end
data/ext/extconf.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby-1.6
2
+ # -*- ruby -*-
3
+ # extconf.rb
4
+ #
5
+ # $Id: extconf.rb,v 1.1.1.1 2002/11/06 08:04:48 ttate Exp $
6
+ #
7
+
8
+ require 'mkmf'
9
+
10
+ $CFLAGS = ""
11
+ $LDFLAGS = ""
12
+
13
+ have_pam_appl_h = have_header("security/pam_appl.h")
14
+ have_pam_modules_h = have_header("security/pam_modules.h")
15
+
16
+ have_pam_lib = have_library("pam","pam_start")
17
+
18
+ have_func("pam_end")
19
+ have_func("pam_open_session")
20
+ have_func("pam_close_session")
21
+ have_func("pam_authenticate")
22
+ have_func("pam_acct_mgmt")
23
+ # have_func("pam_fail_delay")
24
+ have_func("pam_setcred")
25
+ have_func("pam_chauthtok")
26
+ have_func("pam_putenv")
27
+ have_func("pam_getenv")
28
+
29
+ create_makefile("pam")
data/ext/pam.c ADDED
@@ -0,0 +1,164 @@
1
+ /* -*- C -*-
2
+ * $Id: pam.c,v 1.2 2004/10/09 09:19:43 ttate Exp $
3
+ */
4
+
5
+ #include "pam.h"
6
+
7
+ #ifdef HAVE_STDARG_PROTOTYPES
8
+ #include <stdarg.h>
9
+ #define va_init_list(a,b) va_start(a,b)
10
+ #else
11
+ #include <varargs.h>
12
+ #define va_init_list(a,b) va_start(a)
13
+ #endif
14
+
15
+ VALUE rb_mPAM; /* PAM module */
16
+ VALUE rb_cPAMHandle; /* PAM Handle Class */
17
+ VALUE rb_ePAMError; /* PAM Runtime Error */
18
+ VALUE rb_pam_errors[RBPAM_MAX_ERRORS]; /* PAM Errors */
19
+
20
+ VALUE rb_sPAMMessage;
21
+ VALUE rb_sPAMResponse;
22
+
23
+ static VALUE
24
+ rb_pam_define_err(int err, const char *name)
25
+ {
26
+ if( 0 < err && err < RBPAM_MAX_ERRORS ){
27
+ rb_pam_errors[err] = rb_define_class_under(rb_mPAM, name, rb_ePAMError);
28
+ }
29
+ else{
30
+ rb_define_class_under(rb_mPAM, name, rb_ePAMError);
31
+ };
32
+ };
33
+
34
+ static void
35
+ rb_pam_init_errors()
36
+ {
37
+ int i;
38
+
39
+ for( i=0; i < RBPAM_MAX_ERRORS; i++ ){
40
+ rb_pam_errors[i] = Qnil;
41
+ };
42
+ rb_pam_define_err(PAM_SUCCESS, "PAM_SUCCESS");
43
+ rb_pam_define_err(PAM_OPEN_ERR, "PAM_OPEN_ERR");
44
+ rb_pam_define_err(PAM_SYMBOL_ERR, "PAM_SYMBOL_ERR");
45
+ rb_pam_define_err(PAM_SERVICE_ERR, "PAM_SERVICE_ERR");
46
+ rb_pam_define_err(PAM_SYSTEM_ERR, "PAM_SYSTEM_ERR");
47
+ rb_pam_define_err(PAM_BUF_ERR, "PAM_BUF_ERR");
48
+ rb_pam_define_err(PAM_PERM_DENIED, "PAM_PERM_DENIED");
49
+ rb_pam_define_err(PAM_AUTH_ERR, "PAM_AUTH_ERR");
50
+ rb_pam_define_err(PAM_CRED_INSUFFICIENT, "PAM_CRED_INSUFFICIENT");
51
+ rb_pam_define_err(PAM_AUTHINFO_UNAVAIL, "PAM_AUTHINFO_UNAVAIL");
52
+ rb_pam_define_err(PAM_USER_UNKNOWN, "PAM_USER_UNKNOWN");
53
+ rb_pam_define_err(PAM_MAXTRIES, "PAM_MAXTRIES");
54
+ rb_pam_define_err(PAM_NEW_AUTHTOK_REQD, "PAM_NEW_AUTHOK_REQD");
55
+ rb_pam_define_err(PAM_ACCT_EXPIRED, "PAM_ACCT_EXPIRED");
56
+ rb_pam_define_err(PAM_SESSION_ERR, "PAM_SESSION_ERR");
57
+ rb_pam_define_err(PAM_CRED_UNAVAIL, "PAM_CRED_UNAVAIL");
58
+ rb_pam_define_err(PAM_CRED_EXPIRED, "PAM_CRED_EXPIRED");
59
+ rb_pam_define_err(PAM_CRED_ERR, "PAM_CRED_ERR");
60
+ rb_pam_define_err(PAM_NO_MODULE_DATA, "PAM_NO_MODULE_DATA");
61
+ rb_pam_define_err(PAM_CONV_ERR, "PAM_CONV_ERR");
62
+ rb_pam_define_err(PAM_AUTHTOK_ERR, "PAM_AUTHTOK_ERR");
63
+ #if defined(PAM_AUTHTOK_RECOVER_ERR)
64
+ rb_pam_define_err(PAM_AUTHTOK_RECOVER_ERR, "PAM_AUTHTOK_RECOVERY_ERR");
65
+ #elif defined(PAM_AUTHTOK_RECOVERY_ERR)
66
+ rb_pam_define_err(PAM_AUTHTOK_RECOVERY_ERR, "PAM_AUTHTOK_RECOVERY_ERR");
67
+ #endif
68
+ rb_pam_define_err(PAM_AUTHTOK_LOCK_BUSY, "PAM_AUTHTOK_LOCK_BUSY");
69
+ rb_pam_define_err(PAM_AUTHTOK_DISABLE_AGING, "PAM_AUTHTOK_DISABLE_AGING");
70
+ rb_pam_define_err(PAM_TRY_AGAIN, "PAM_TRY_AGAIN");
71
+ rb_pam_define_err(PAM_IGNORE, "PAM_IGNORE");
72
+ rb_pam_define_err(PAM_ABORT, "PAM_ABORT");
73
+ rb_pam_define_err(PAM_AUTHTOK_EXPIRED, "PAM_AUTHTOK_EXPIRED");
74
+ #if defined(PAM_MODULE_UNKNOWN)
75
+ rb_pam_define_err(PAM_MODULE_UNKNOWN, "PAM_MODULE_UNKNOWN");
76
+ #endif
77
+ #if defined(PAM_BAD_ITEM)
78
+ rb_pam_define_err(PAM_BAD_ITEM, "PAM_BAD_ITEM");
79
+ #endif
80
+ #if defined(PAM_CONV_AGAIN)
81
+ rb_pam_define_err(PAM_CONV_AGAIN, "PAM_CONV_AGAIN");
82
+ #endif
83
+ #if defined(PAM_INCOMPLETE)
84
+ rb_pam_define_err(PAM_INCOMPLETE, "PAM_INCOMPLETE");
85
+ #endif
86
+ };
87
+
88
+ void
89
+ #ifdef HAVE_STDARG_PROTOTYPES
90
+ rb_pam_raise(int err, const char *fmt, ...)
91
+ #else
92
+ rb_pam_raise(err, fmt, va_alist)
93
+ int err;
94
+ const char *fmt;
95
+ va_dcl
96
+ #endif
97
+ {
98
+ va_list args;
99
+ char buf[BUFSIZ];
100
+
101
+ if( 0 < err && err < RBPAM_MAX_ERRORS && rb_pam_errors[err] ){
102
+ va_init_list(args,fmt);
103
+ vsnprintf(buf, BUFSIZ, fmt, args);
104
+ va_end(args);
105
+ rb_exc_raise(rb_exc_new2(rb_pam_errors[err],buf));
106
+ }
107
+ else{
108
+ rb_raise(rb_ePAMError, "undefined pam exception (error code = %d)",err);
109
+ };
110
+ };
111
+
112
+ VALUE
113
+ rb_pam_start(int argc, VALUE argv[], VALUE self)
114
+ {
115
+ return rb_pam_handle_s_start(argc, argv, rb_cPAMHandle);
116
+ };
117
+
118
+
119
+ void
120
+ Init_pam()
121
+ {
122
+ extern Init_pam_handle();
123
+
124
+ rb_mPAM = rb_define_module("PAM");
125
+ rb_ePAMError = rb_define_class_under(rb_mPAM, "PAMError",rb_eRuntimeError);
126
+
127
+ rb_sPAMMessage = rb_struct_define("Message","msg_style","msg",0);
128
+ rb_sPAMResponse = rb_struct_define("Response","resp","resp_retcode",0);
129
+
130
+ rb_define_const(rb_mPAM,"Message",rb_sPAMMessage);
131
+ rb_define_const(rb_mPAM,"Response",rb_sPAMResponse);
132
+
133
+ rb_define_const(rb_mPAM,"PAM_VERSION", rb_tainted_str_new2(RUBY_PAM_VERSION));
134
+ rb_define_const(rb_mPAM,"PAM_MAJOR_VERSION", INT2FIX(RUBY_PAM_MAJOR_VERSION));
135
+ rb_define_const(rb_mPAM,"PAM_MINOR_VERSION", INT2FIX(RUBY_PAM_MINOR_VERSION));
136
+
137
+ rb_define_module_function(rb_mPAM, "start", rb_pam_start, -1);
138
+
139
+ rb_pam_init_errors();
140
+
141
+ #define rb_pam_define_const(c) rb_define_const(rb_mPAM,#c,INT2NUM(c))
142
+ rb_pam_define_const(PAM_CONV);
143
+ rb_pam_define_const(PAM_CHANGE_EXPIRED_AUTHTOK);
144
+ rb_pam_define_const(PAM_DELETE_CRED);
145
+ rb_pam_define_const(PAM_ERROR_MSG);
146
+ rb_pam_define_const(PAM_ESTABLISH_CRED);
147
+ rb_pam_define_const(PAM_OLDAUTHTOK);
148
+ rb_pam_define_const(PAM_PROMPT_ECHO_OFF);
149
+ rb_pam_define_const(PAM_PROMPT_ECHO_ON);
150
+ rb_pam_define_const(PAM_REFRESH_CRED);
151
+ rb_pam_define_const(PAM_REINITIALIZE_CRED);
152
+ rb_pam_define_const(PAM_RHOST);
153
+ rb_pam_define_const(PAM_RUSER);
154
+ rb_pam_define_const(PAM_SERVICE);
155
+ rb_pam_define_const(PAM_SILENT);
156
+ rb_pam_define_const(PAM_TEXT_INFO);
157
+ rb_pam_define_const(PAM_TTY);
158
+ rb_pam_define_const(PAM_USER);
159
+ rb_pam_define_const(PAM_USER_PROMPT);
160
+ rb_pam_define_const(PAM_DISALLOW_NULL_AUTHTOK);
161
+ #undef rb_pam_define_const
162
+
163
+ Init_pam_handle();
164
+ };
data/ext/pam.h ADDED
@@ -0,0 +1,47 @@
1
+ /* -*- C -*-
2
+ * $Id: pam.h,v 1.1.1.1 2002/11/06 08:04:48 ttate Exp $
3
+ */
4
+
5
+ #ifndef RB_PAM_H
6
+ #define RB_PAM_H 1
7
+
8
+ #include <ruby.h>
9
+ #include <version.h>
10
+ #include <security/pam_appl.h>
11
+ #include <security/pam_modules.h>
12
+
13
+ #define RUBY_PAM_MAJOR_VERSION 1
14
+ #define RUBY_PAM_MINOR_VERSION 5
15
+ #define RUBY_PAM_VERSION "1.5"
16
+
17
+ typedef struct rb_pam_struct {
18
+ pam_handle_t *ptr;
19
+ int start;
20
+ int status;
21
+ struct pam_conv *conv;
22
+ } *RPAM;
23
+
24
+ extern VALUE rb_mPAM; /* PAM module */
25
+ extern VALUE rb_cPAMHandle; /* PAM Handle Class */
26
+ extern VALUE rb_ePAMError;
27
+ extern VALUE rb_pam_errors[];
28
+
29
+ #define RBPAM_MAX_ERRORS 40
30
+
31
+ extern VALUE rb_sPAMMessage;
32
+ extern VALUE rb_sPAMResponse;
33
+
34
+ extern void rb_pam_raise(int, const char *, ...);
35
+ extern VALUE rb_pam_start(int, VALUE[], VALUE);
36
+
37
+ extern VALUE rb_pam_handle_new(pam_handle_t *);
38
+ extern VALUE rb_pam_handle_s_start(int, VALUE[], VALUE);
39
+ extern VALUE rb_pam_handle_end(VALUE);
40
+ extern VALUE rb_pam_handle_authenticate(int, VALUE[], VALUE);
41
+ extern VALUE rb_pam_handle_acct_mgmt(int, VALUE[], VALUE);
42
+ extern VALUE rb_pam_handle_setcred(int, VALUE[], VALUE);
43
+ extern VALUE rb_pam_handle_chauthtok(int, VALUE[], VALUE);
44
+ extern VALUE rb_pam_handle_open_session(int, VALUE[], VALUE);
45
+ extern VALUE rb_pam_handle_close_session(int, VALUE[], VALUE);
46
+
47
+ #endif /* RB_PAM_H */