account_usability.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* $OpenLDAP$ */
  2. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  3. *
  4. * Copyright 2004-2022 The OpenLDAP Foundation.
  5. * Portions Copyright 2004 Hewlett-Packard Company.
  6. * Portions Copyright 2004 Howard Chu, Symas Corp.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted only as authorized by the OpenLDAP
  11. * Public License.
  12. *
  13. * A copy of this license is available in the file LICENSE in the
  14. * top-level directory of the distribution or, alternatively, at
  15. * <http://www.OpenLDAP.org/license.html>.
  16. */
  17. /* ACKNOWLEDGEMENTS:
  18. * This work was developed by Howard Chu for inclusion in
  19. * OpenLDAP Software, based on prior work by Neil Dunbar (HP).
  20. * This work was sponsored by the Hewlett-Packard Company.
  21. */
  22. #include "portable.h"
  23. #include "ldap-int.h"
  24. #ifdef LDAP_CONTROL_X_ACCOUNT_USABILITY
  25. int
  26. ldap_create_accountusability_control( LDAP *ld,
  27. LDAPControl **ctrlp )
  28. {
  29. assert( ld != NULL );
  30. assert( LDAP_VALID( ld ) );
  31. assert( ctrlp != NULL );
  32. ld->ld_errno = ldap_control_create( LDAP_CONTROL_X_ACCOUNT_USABILITY,
  33. 0, NULL, 0, ctrlp );
  34. return ld->ld_errno;
  35. }
  36. int
  37. ldap_parse_accountusability_control(
  38. LDAP *ld,
  39. LDAPControl *ctrl,
  40. int *availablep,
  41. LDAPAccountUsability *usabilityp )
  42. {
  43. BerElement *ber;
  44. int available = 0;
  45. ber_tag_t tag;
  46. ber_len_t berLen;
  47. char *last;
  48. assert( ld != NULL );
  49. assert( LDAP_VALID( ld ) );
  50. assert( ctrl != NULL );
  51. if ( !ctrl->ldctl_value.bv_val ) {
  52. ld->ld_errno = LDAP_DECODING_ERROR;
  53. return(ld->ld_errno);
  54. }
  55. /* Create a BerElement from the berval returned in the control. */
  56. ber = ber_init(&ctrl->ldctl_value);
  57. if (ber == NULL) {
  58. ld->ld_errno = LDAP_NO_MEMORY;
  59. return(ld->ld_errno);
  60. }
  61. tag = ber_peek_tag( ber, &berLen );
  62. if ( tag == LDAP_TAG_X_ACCOUNT_USABILITY_AVAILABLE ) {
  63. available = 1;
  64. if ( usabilityp != NULL ) {
  65. if (ber_get_int( ber, &usabilityp->seconds_remaining ) == LBER_DEFAULT) goto exit;
  66. }
  67. } else if ( tag == LDAP_TAG_X_ACCOUNT_USABILITY_NOT_AVAILABLE ) {
  68. available = 0;
  69. LDAPAccountUsabilityMoreInfo more_info = { 0, 0, 0, -1, -1 };
  70. ber_skip_tag( ber, &berLen );
  71. while ( (tag = ber_peek_tag( ber, &berLen )) != LBER_DEFAULT ) {
  72. switch (tag) {
  73. case LDAP_TAG_X_ACCOUNT_USABILITY_INACTIVE:
  74. if (ber_get_boolean( ber, &more_info.inactive ) == LBER_DEFAULT) goto exit;
  75. break;
  76. case LDAP_TAG_X_ACCOUNT_USABILITY_RESET:
  77. if (ber_get_boolean( ber, &more_info.reset ) == LBER_DEFAULT) goto exit;
  78. break;
  79. case LDAP_TAG_X_ACCOUNT_USABILITY_EXPIRED:
  80. if (ber_get_boolean( ber, &more_info.expired ) == LBER_DEFAULT) goto exit;
  81. break;
  82. case LDAP_TAG_X_ACCOUNT_USABILITY_REMAINING_GRACE:
  83. if (ber_get_int( ber, &more_info.remaining_grace ) == LBER_DEFAULT) goto exit;
  84. break;
  85. case LDAP_TAG_X_ACCOUNT_USABILITY_UNTIL_UNLOCK:
  86. if (ber_get_int( ber, &more_info.seconds_before_unlock ) == LBER_DEFAULT) goto exit;
  87. break;
  88. default:
  89. goto exit;
  90. }
  91. }
  92. if ( usabilityp != NULL ) {
  93. usabilityp->more_info = more_info;
  94. }
  95. } else {
  96. goto exit;
  97. }
  98. if ( availablep != NULL ) {
  99. *availablep = available;
  100. }
  101. ber_free(ber, 1);
  102. ld->ld_errno = LDAP_SUCCESS;
  103. return(ld->ld_errno);
  104. exit:
  105. ber_free(ber, 1);
  106. ld->ld_errno = LDAP_DECODING_ERROR;
  107. return(ld->ld_errno);
  108. }
  109. #endif /* LDAP_CONTROL_X_ACCOUNT_USABILITY */