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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
ldap_parse_passwordpolicy_control.c - replacement function
Copyright (C) 2013 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "config.h"
#include <stdlib.h>
#include <lber.h>
#include <ldap.h>
#include <string.h>
#include "compat/ldap_compat.h"
#include "compat/attrs.h"
#ifndef PPOLICY_WARNING
#define PPOLICY_WARNING 160
#endif
#ifndef PPOLICY_ERROR
#define PPOLICY_ERROR 129
#endif
#ifndef PPOLICY_EXPIRE
#define PPOLICY_EXPIRE 128
#endif
#ifndef PPOLICY_GRACE
#define PPOLICY_GRACE 129
#endif
/* based on Openldap and pam_ldap implementations */
int ldap_parse_passwordpolicy_control(LDAP UNUSED(*ld), LDAPControl *ctrl,
ber_int_t *expirep, ber_int_t *gracep,
LDAPPasswordPolicyError UNUSED(*errorp))
{
BerElement *ber;
ber_tag_t tag;
ber_len_t berLen;
char *last;
#ifdef HAVE_BER_GET_ENUM
int err = PP_noError;
#endif /* HAVE_BER_GET_ENUM */
/* get a BerElement from the control */
ber = ber_init(&ctrl->ldctl_value);
if (ber == NULL)
return LDAP_LOCAL_ERROR;
/* go over tags */
for(tag = ber_first_element(ber, &berLen, &last); tag != LBER_DEFAULT; tag = ber_next_element(ber, &berLen, last))
{
switch (tag)
{
case PPOLICY_WARNING:
ber_skip_tag(ber, &berLen);
tag = ber_peek_tag(ber, &berLen);
switch (tag)
{
case PPOLICY_EXPIRE:
if (ber_get_int(ber, expirep) == LBER_DEFAULT)
{
ber_free(ber, 1);
return LDAP_DECODING_ERROR;
}
break;
case PPOLICY_GRACE:
if (ber_get_int(ber, gracep) == LBER_DEFAULT)
{
ber_free(ber, 1);
return LDAP_DECODING_ERROR;
}
break;
default:
ber_free(ber, 1);
return LDAP_DECODING_ERROR;
}
break;
#ifdef HAVE_BER_GET_ENUM
case PPOLICY_ERROR:
if (ber_get_enum(ber, &err) == LBER_DEFAULT)
{
ber_free(ber, 1);
return LDAP_DECODING_ERROR;
}
break;
#endif /* HAVE_BER_GET_ENUM */
default:
ber_free(ber, 1);
return LDAP_DECODING_ERROR;
}
}
ber_free(ber, 1);
return LDAP_SUCCESS;
}
|