-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple.xs
83 lines (68 loc) · 1.55 KB
/
Simple.xs
1
2
3
4
5
6
7
8
9
10
11
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
/*
******************************************************************************
*
* File: Simple.xs
*
* Author: Damien S. Stuart
*
* Purpose: .xs file for the Authen::Krb5::Simple Perl module.
*
*
******************************************************************************
*/
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <krb5.h>
int _krb5_auth(char* user, char* pass)
{
int krbret;
krb5_context ctx;
krb5_creds creds;
krb5_principal princ;
int ret = 0;
/* Initialize krb5 context...
*/
if ((krbret = krb5_init_context(&ctx))) {
return krbret;
}
memset(&creds, 0, sizeof(krb5_creds));
/* Get principal name...
*/
if ((krbret = krb5_parse_name(ctx, user, &princ))) {
ret = krbret;
goto free_context;
}
/* Check the user's pasword...
*/
if ((krbret = krb5_get_init_creds_password(
ctx, &creds, princ, pass, 0, NULL, 0, NULL, NULL))) {
ret = krbret;
}
krb5_free_cred_contents(ctx, &creds);
krb5_free_principal(ctx, princ);
free_context:
krb5_free_context(ctx);
return(ret);
}
MODULE = Authen::Krb5::Simple PACKAGE = Authen::Krb5::Simple
PROTOTYPES: DISABLE
int
krb5_auth(user, password)
INPUT:
char * user;
char * password;
CODE:
RETVAL = _krb5_auth(user, password);
OUTPUT:
RETVAL
char*
krb5_errstr(errcode)
INPUT:
int errcode;
INIT:
char* result = (char*)error_message(errcode);
CODE:
RETVAL = result;
OUTPUT:
RETVAL