#!/bin/bash
#
# File: ldap-schema
# Description: LDAP schema display
# Author: Bill MacAllister <bill@ca-zephyr.org>
# Copyright 2022 Bill MacAllister <bill@ca-zephyr.org>
# Copyright 2023 CZ Software

function read_schema {
    thisHost=$1
    ldapsearch -x -LLL \
               -H ldap://$this_host \
               -o ldif-wrap=no \
               -b cn=schema,cn=config | ldap-schema-pp
}

case $1 in
    help)
        echo "Usage: ldap-schema [help|manual|<hostname>]"
        exit 1
        ;;
    manual)
        pod2text $0
        exit
        ;;
    *)
        if [ "$1" = "" ]
        then
            thisHost="127.0.0.1"
        fi
        read_schema $thisHost
        ;;
esac

exit

DOCUMENTATION=<<EOF

=head1 NAME

ldap-schema - Display Human Readable LDAP schema

=head1 SYNOPSIS

ldap-schema [help|manual|<hostname>]"

=head1 DESCRIPTION

This script performs a simple schema search of cn=config and passes
the output through the ldap-schema-pp script.  ldap-schema-pp reformats
the output to make it more readable.

=head1 AUTHOR

Bill MacAllister <bill@ca-zephyr.org>

=head1 COPYRIGHT

Copyright (C) Bill MacAllister <bill@ca-zephyr.org>

License: Apache License, Version 2.0.

You may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

EOF
