12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'ext/krbpwd/krbpwd.c', line 12
VALUE change_passwd(VALUE self, VALUE v_user, VALUE v_old_pwd, VALUE v_new_pwd)
{
Check_Type(v_user, T_STRING);
Check_Type(v_old_pwd, T_STRING);
Check_Type(v_new_pwd, T_STRING);
char* user = StringValuePtr(v_user);
char* old_pwd = StringValuePtr(v_old_pwd);
char* new_pwd = StringValuePtr(v_new_pwd);
int iRubyRetCode=-1;
krb5_error_code krbret;
krb5_context ctx;
krb5_creds creds;
krb5_principal princ;
int pw_result;
krb5_data pw_res_string, res_string;
memset(&princ, 0, sizeof(princ));
memset(&creds, 0, sizeof(creds));
#ifdef DEBUG
printf("Old=%s\n", old_pwd);
printf("New=%s\n", new_pwd);
#endif
if ((krbret = krb5_init_context(&ctx))) {
#ifdef DEBUG
printf("Error to init.\n");
#endif
iRubyRetCode=1;
return INT2NUM(iRubyRetCode);
}
if ((krbret = krb5_parse_name(ctx, user, &princ))) {
krb5_free_context(ctx);
#ifdef DEBUG
printf("Error to parse name.\n");
#endif
iRubyRetCode=2;
return INT2NUM(iRubyRetCode);
}
if ((krbret = krb5_get_init_creds_password( ctx, &creds, princ, old_pwd, NULL, NULL, 0, KADM5_CHANGEPW_SERVICE, NULL))) {
#ifdef DEBUG
printf("Error to init cred %d %s.\n", krbret, error_message(krbret));
#endif
krb5_free_principal(ctx, princ);
krb5_free_context(ctx);
iRubyRetCode=3;
return INT2NUM(iRubyRetCode);
}
if ((krbret = krb5_change_password(ctx, &creds, new_pwd, &pw_result, &pw_res_string, &res_string ))) {
iRubyRetCode=4;
pw_result=0;
#ifdef DEBUG
printf("Error set password.\n");
#endif
}
if (pw_result!=0) {
iRubyRetCode=5;
#ifdef DEBUG
printf("DEBUG: Fehler to change pwd.\n");
#endif
}
else {
iRubyRetCode=0;
#ifdef DEBUG
printf("DEBUG: Pwd changed.\n");
#endif
}
krb5_free_cred_contents(ctx, &creds);
krb5_free_principal(ctx, princ);
krb5_free_context(ctx);
return INT2NUM(iRubyRetCode);
}
|