~ubuntu-branches/debian/sid/nss-pam-ldapd/sid

« back to all changes in this revision

Viewing changes to compat/ldap_parse_passwordpolicy_control.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2014-06-08 14:00:00 UTC
  • mfrom: (16.1.8) (14.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140608140000-rt6fspljmk9252zd
Tags: 0.9.4-1
* upload to unstable
* new upstream release:
  - also handle password policy information on BIND failure (this makes it
    possible to distinguish between a wrong password and an expired
    password)
  - fix mapping the member attribute to an empty string
  - any buffers that may have held passwords are cleared before the memory
    is released
  - increase buffer size for passwords to support extremely long passwords
    (thanks ushi)
  - increase buffer size for DN to support very long names or names with
    non-ASCII characters
  - log an error in almost all places where a defined buffer is not large
    enough to hold the provided data instead of just (sometimes silently)
    failing
  - logging improvements (start-up problems, login failures)
* add signature checking option to watch file
* add a debian/upstream/metadata file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   ldap_parse_passwordpolicy_control.c - replacement function
 
3
 
 
4
   Copyright (C) 2013 Arthur de Jong
 
5
 
 
6
   This library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Lesser General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
   This library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Lesser General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Lesser General Public
 
17
   License along with this library; if not, write to the Free Software
 
18
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
   02110-1301 USA
 
20
*/
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <stdlib.h>
 
25
#include <lber.h>
 
26
#include <ldap.h>
 
27
#include <string.h>
 
28
 
 
29
#include "compat/ldap_compat.h"
 
30
#include "compat/attrs.h"
 
31
 
 
32
#ifndef PPOLICY_WARNING
 
33
#define PPOLICY_WARNING 160
 
34
#endif
 
35
#ifndef PPOLICY_ERROR
 
36
#define PPOLICY_ERROR 129
 
37
#endif
 
38
#ifndef PPOLICY_EXPIRE
 
39
#define PPOLICY_EXPIRE 128
 
40
#endif
 
41
#ifndef PPOLICY_GRACE
 
42
#define PPOLICY_GRACE 129
 
43
#endif
 
44
 
 
45
/* based on Openldap and pam_ldap implementations */
 
46
 
 
47
int ldap_parse_passwordpolicy_control(LDAP UNUSED(*ld), LDAPControl *ctrl,
 
48
                                      ber_int_t *expirep, ber_int_t *gracep,
 
49
                                      LDAPPasswordPolicyError UNUSED(*errorp))
 
50
{
 
51
  BerElement *ber;
 
52
  ber_tag_t tag;
 
53
  ber_len_t berLen;
 
54
  char *last;
 
55
#ifdef HAVE_BER_GET_ENUM
 
56
  int err = PP_noError;
 
57
#endif /* HAVE_BER_GET_ENUM */
 
58
  /* get a BerElement from the control */
 
59
  ber = ber_init(&ctrl->ldctl_value);
 
60
  if (ber == NULL)
 
61
    return LDAP_LOCAL_ERROR;
 
62
  /* go over tags */
 
63
  for(tag = ber_first_element(ber, &berLen, &last); tag != LBER_DEFAULT; tag = ber_next_element(ber, &berLen, last))
 
64
  {
 
65
    switch (tag)
 
66
    {
 
67
      case PPOLICY_WARNING:
 
68
        ber_skip_tag(ber, &berLen);
 
69
        tag = ber_peek_tag(ber, &berLen);
 
70
        switch (tag)
 
71
        {
 
72
          case PPOLICY_EXPIRE:
 
73
            if (ber_get_int(ber, expirep) == LBER_DEFAULT)
 
74
            {
 
75
              ber_free(ber, 1);
 
76
              return LDAP_DECODING_ERROR;
 
77
            }
 
78
            break;
 
79
          case PPOLICY_GRACE:
 
80
            if (ber_get_int(ber, gracep) == LBER_DEFAULT)
 
81
            {
 
82
              ber_free(ber, 1);
 
83
              return LDAP_DECODING_ERROR;
 
84
            }
 
85
            break;
 
86
          default:
 
87
            ber_free(ber, 1);
 
88
            return LDAP_DECODING_ERROR;
 
89
        }
 
90
        break;
 
91
#ifdef HAVE_BER_GET_ENUM
 
92
      case PPOLICY_ERROR:
 
93
        if (ber_get_enum(ber, &err) == LBER_DEFAULT)
 
94
        {
 
95
          ber_free(ber, 1);
 
96
          return LDAP_DECODING_ERROR;
 
97
        }
 
98
        break;
 
99
#endif /* HAVE_BER_GET_ENUM */
 
100
      default:
 
101
        ber_free(ber, 1);
 
102
        return LDAP_DECODING_ERROR;
 
103
    }
 
104
  }
 
105
  ber_free(ber, 1);
 
106
  return LDAP_SUCCESS;
 
107
}