krbpwd 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ #
2
+
3
+ require 'mkmf'
4
+
5
+ extension_name = 'krbpwd'
6
+
7
+ dir_config(extension_name, '/usr/local')
8
+
9
+ have_header('krb5.h')
10
+ have_library('krb5')
11
+
12
+ create_makefile(extension_name)
13
+
@@ -0,0 +1,97 @@
1
+ #include <stdio.h>
2
+ #include <strings.h>
3
+ #include <kerberosv5/krb5.h>
4
+ #include <ruby.h>
5
+
6
+ //#define DEBUG
7
+
8
+ #define KADM5_CHANGEPW_SERVICE "kadmin/changepw"
9
+
10
+ VALUE cKrbPwd = Qnil;
11
+
12
+ VALUE change_passwd(VALUE self, VALUE v_user, VALUE v_old_pwd, VALUE v_new_pwd)
13
+ {
14
+ Check_Type(v_user, T_STRING);
15
+ Check_Type(v_old_pwd, T_STRING);
16
+ Check_Type(v_new_pwd, T_STRING);
17
+ char* user = StringValuePtr(v_user);
18
+ char* old_pwd = StringValuePtr(v_old_pwd);
19
+ char* new_pwd = StringValuePtr(v_new_pwd);
20
+ int iRubyRetCode=-1;
21
+ krb5_error_code krbret;
22
+ krb5_context ctx;
23
+ krb5_creds creds;
24
+ krb5_principal princ;
25
+ int pw_result;
26
+ krb5_data pw_res_string, res_string;
27
+
28
+ memset(&princ, 0, sizeof(princ));
29
+ memset(&creds, 0, sizeof(creds));
30
+
31
+ #ifdef DEBUG
32
+ printf("Old=%s\n", old_pwd);
33
+ printf("New=%s\n", new_pwd);
34
+ #endif
35
+
36
+ if ((krbret = krb5_init_context(&ctx))) {
37
+ #ifdef DEBUG
38
+ printf("Error to init.\n");
39
+ #endif
40
+ iRubyRetCode=1;
41
+ return INT2NUM(iRubyRetCode);
42
+ }
43
+
44
+ if ((krbret = krb5_parse_name(ctx, user, &princ))) {
45
+ krb5_free_context(ctx);
46
+ #ifdef DEBUG
47
+ printf("Error to parse name.\n");
48
+ #endif
49
+ iRubyRetCode=2;
50
+ return INT2NUM(iRubyRetCode);
51
+ }
52
+
53
+ if ((krbret = krb5_get_init_creds_password( ctx, &creds, princ, old_pwd, NULL, NULL, 0, KADM5_CHANGEPW_SERVICE, NULL))) {
54
+ #ifdef DEBUG
55
+ printf("Error to init cred %d %s.\n", krbret, error_message(krbret));
56
+ #endif
57
+ krb5_free_principal(ctx, princ);
58
+ krb5_free_context(ctx);
59
+ iRubyRetCode=3;
60
+ return INT2NUM(iRubyRetCode);
61
+ }
62
+
63
+ if ((krbret = krb5_change_password(ctx, &creds, new_pwd, &pw_result, &pw_res_string, &res_string ))) {
64
+ iRubyRetCode=4;
65
+ pw_result=0;
66
+ #ifdef DEBUG
67
+ printf("Error set password.\n");
68
+ #endif
69
+ }
70
+
71
+ if (pw_result!=0) {
72
+ iRubyRetCode=5;
73
+ #ifdef DEBUG
74
+ printf("DEBUG: Fehler to change pwd.\n");
75
+ #endif
76
+ }
77
+ else {
78
+ iRubyRetCode=0;
79
+ #ifdef DEBUG
80
+ printf("DEBUG: Pwd changed.\n");
81
+ #endif
82
+ }
83
+
84
+ krb5_free_cred_contents(ctx, &creds);
85
+ krb5_free_principal(ctx, princ);
86
+ krb5_free_context(ctx);
87
+
88
+ return INT2NUM(iRubyRetCode);
89
+ }
90
+
91
+
92
+ void Init_krbpwd()
93
+ {
94
+ cKrbPwd = rb_define_class("KrbPwd", rb_cObject);
95
+ rb_define_method(cKrbPwd, "change_passwd", change_passwd, 3);
96
+
97
+ }
data/krbpwd.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'krbpwd'
5
+ spec.version = '0.2'
6
+ spec.author = 'Stephan Toggweiler'
7
+ spec.license = 'MIT'
8
+ spec.email = 'stephan@rheoli.net'
9
+ spec.homepage = 'http://www.rheoli.net'
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.summary = 'A Ruby interface for the the Kerberos library'
12
+ spec.has_rdoc = false
13
+ #spec.test_files = Dir['test/test*']
14
+ spec.extensions = ['ext/krbpwd/extconf.rb']
15
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') || f.include?('tmp') }
16
+
17
+ #spec.rubyforge_project = 'krb5-auth'
18
+ #spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST'] + Dir['ext/krb5_auth/*.c']
19
+
20
+ #spec.add_dependency('rake-compiler')
21
+
22
+ #spec.add_development_dependency('test-unit', '>= 2.0.6')
23
+ #spec.add_development_dependency('dbi-dbrc', '>= 1.1.6')
24
+
25
+ spec.description = <<-EOF
26
+ Interface to Kerberos for change password.
27
+ EOF
28
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: krbpwd
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.2"
6
+ platform: ruby
7
+ authors:
8
+ - Stephan Toggweiler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-05 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: " Interface to Kerberos for change password.\n"
18
+ email: stephan@rheoli.net
19
+ executables: []
20
+
21
+ extensions:
22
+ - ext/krbpwd/extconf.rb
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - krbpwd.gemspec
27
+ - ext/krbpwd/krbpwd.c
28
+ - ext/krbpwd/extconf.rb
29
+ has_rdoc: true
30
+ homepage: http://www.rheoli.net
31
+ licenses:
32
+ - MIT
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.6.2
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A Ruby interface for the the Kerberos library
57
+ test_files: []
58
+