passwdqc.xs

filter: Statementstmt 94.3% 50 / 53 Branchbran 76.9% 20 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 88.6% 70 / 79 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Data/Password/passwdqc.pm ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include "ppport.h"
6  
7 #include "passwdqc.h"
8  
9 SV *
10 3 password_generate(const char *packed_params)
11 {
12 const char *pass;
13 3 const passwdqc_params_qc_t *params = (passwdqc_params_qc_t *)packed_params;
14  
15 3 pass = passwdqc_random(params);
16  
17 3 ▶ if (!pass)
Branch: 1 branch
BranchTrueFalseTotal
if (!pass) 0 3 3
18 0 return &PL_sv_undef;
19 3 return newSVpvn(pass, strlen(pass));
20 }
21  
22 SV *
23 26 password_check(const char *packed_params, const char *new_pass, const char *old_pass, const char *pw_name, const char *pw_gecos)
24 {
25 const char *reason;
26 26 const passwdqc_params_qc_t *params = (passwdqc_params_qc_t *)packed_params;
27  
28 /* this is inspired by what passwdqc does on non-unix platforms */
29 struct passwd fake_pw, *pw;
30 26 memset(&fake_pw, 0, sizeof(fake_pw));
31 26 ▶ fake_pw.pw_name = pw_name ? (char *)pw_name : "";
Branch: 1 branch
BranchTrueFalseTotal
fake_pw.pw_name = pw_name ? (char *)pw_name : ""; 4 22 26
32 26 ▶ fake_pw.pw_gecos = pw_gecos ? (char *)pw_gecos : "";
Branch: 1 branch
BranchTrueFalseTotal
fake_pw.pw_gecos = pw_gecos ? (char *)pw_gecos : ""; 2 24 26
33 26 fake_pw.pw_dir = "";
34 26 ▶ if (pw_name != NULL || pw_gecos != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (pw_name != NULL || pw_gecos != NULL) { 22 4 26
if (pw_name != NULL || pw_gecos != NULL) { 1 21 22
35 5 pw = &fake_pw;
36 }
37 else {
38 21 pw = NULL;
39 }
40  
41 26 reason = passwdqc_check(params, new_pass, old_pass, pw);
42  
43 26 ▶ if (!reason)
Branch: 1 branch
BranchTrueFalseTotal
if (!reason) 8 18 26
44 8 return &PL_sv_undef;
45 18 return newSVpvn(reason, strlen(reason));
46 }
47  
48  
49 MODULE = Data::Password::passwdqc PACKAGE = Data::Password::passwdqc
50  
51 PROTOTYPES: DISABLE
52  
53  
54 SV *
55 password_generate (packed_params)
56 const char * packed_params
57  
58 SV *
59 password_check (packed_params, new_pass, ...)
60 const char * packed_params
61 const char * new_pass
62 CODE:
63 26 switch (items) {
64 2 case 5:
65 3 RETVAL = password_check(packed_params, new_pass,
66 2 ▶ SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL, 0 2 2
67 3 ▶ SvOK(ST(3)) ? (char *)SvPV_nolen(ST(3)) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(3)) ? (char *)SvPV_nolen(ST(3)) : NULL, 1 1 2
68 4 ▶ SvOK(ST(4)) ? (char *)SvPV_nolen(ST(4)) : NULL);
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(4)) ? (char *)SvPV_nolen(ST(4)) : NULL); 2 0 2
69 2 break;
70 3 case 4:
71 3 RETVAL = password_check(packed_params, new_pass,
72 4 ▶ SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL, 1 2 3
73 6 ▶ SvOK(ST(3)) ? (char *)SvPV_nolen(ST(3)) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(3)) ? (char *)SvPV_nolen(ST(3)) : NULL, 3 0 3
74 NULL);
75 3 break;
76 8 case 3:
77 8 RETVAL = password_check(packed_params, new_pass,
78 16 ▶ SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
SvOK(ST(2)) ? (char *)SvPV_nolen(ST(2)) : NULL, 8 0 8
79 NULL,
80 NULL);
81 8 break;
82 13 case 2:
83 13 RETVAL = password_check(packed_params, new_pass, NULL, NULL, NULL);
84 13 break;
85 0 default:
86 0 croak("password_check() called with too few arguments!");
87 break;
88 }
89 OUTPUT:
90 RETVAL
91  
92 void
93 _test_params (packed_params)
94 const char * packed_params
95 PREINIT:
96 const passwdqc_params_qc_t * params;
97 PPCODE:
98 1 params = (passwdqc_params_qc_t *)packed_params;
99 1 ▶ EXTEND(SP, 10);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 10); 0 1 1
100 1 PUSHs(sv_2mortal(newSViv(params->min[0])));
101 1 PUSHs(sv_2mortal(newSViv(params->min[1])));
102 1 PUSHs(sv_2mortal(newSViv(params->min[2])));
103 1 PUSHs(sv_2mortal(newSViv(params->min[3])));
104 1 PUSHs(sv_2mortal(newSViv(params->min[4])));
105 1 PUSHs(sv_2mortal(newSViv(params->max)));
106 1 PUSHs(sv_2mortal(newSViv(params->passphrase_words)));
107 1 PUSHs(sv_2mortal(newSViv(params->match_length)));
108 1 PUSHs(sv_2mortal(newSViv(params->similar_deny)));
109 1 PUSHs(sv_2mortal(newSViv(params->random_bits)));
110  
111 SV *
112 _test_int_max ()
113 CODE:
114 1 RETVAL = newSViv(INT_MAX);
115 OUTPUT:
116 RETVAL
117  
« blib/lib/Data/Password/passwdqc.pm ↑ Summary