ldaplist.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <strings.h>
#include <locale.h>
#include <syslog.h>
#include "../../../lib/libsldap/common/ns_sldap.h"
extern char *set_filter(char **, char *, char **);
extern char *set_filter_publickey(char **, char *, int, char **);
extern void _printResult(ns_ldap_result_t *);
int listflag = 0;
void
if (msg)
"ldaplist [-lvh] [<database> [<key>] ...]\n"
"\tOptions:\n"
"\t -l list all the attributes found in entry.\n"
"\t By default, it lists only the DNs.\n"
"\t -d list attributes for the database instead of its entries\n"
"\t -v print out the LDAP search filter.\n"
"\t -h list the database mappings.\n"
"\t<database> is the database to be searched in. Standard system\n"
"\tdatabases are:\n"
"\t\tpassword, printers, group, hosts, ethers, networks, netmasks,\n"
"\t\trpc, bootparams, protocols, services, netgroup, auto_*.\n"
"\tNon-standard system databases can be specified as follows:\n"
"\t\tby specific container: ou=<dbname> or\n"
"\t\tby default container: <dbname>. In this case, 'nismapname'\n"
"\t\twill be used, thus mapping this to nismapname=<dbname>.\n"
"\t<key> is the key to search in the database. For the standard\n"
"\tdatabases, the search type for the key is predefined. You can\n"
"\toverride this by specifying <type>=<key>.\n"));
exit(1);
}
/*
* This is a generic filter call back function for
* merging the filter from service search descriptor with
* an existing search filter. This routine expects userdata
* contain a format string with a single %s in it, and will
* use the format string with sprintf() to insert the SSD filter.
*
* This routine is passed to the __ns_ldap_list() or
* __ns_ldap_firstEntry() APIs as the filter call back
* together with the userdata. For example,
* the "ldaplist hosts sys1" processing may call __ns_ldap_list()
* with "(&(objectClass=ipHost)(cn=sys1))" as filter, this function
* as the filter call back, and "(&(%s)(cn=sys1))" as the
* userdata, this routine will in turn gets call to produce
* "(&(department=sds)(cn=sys1))" as the real search
* filter, if the input SSD contains a filter "department=sds".
*/
static int
char **realfilter,
const void *userdata)
{
int len;
/* sanity check */
if (realfilter == NULL)
return (NS_LDAP_INVALID_PARAM);
*realfilter = NULL;
return (NS_LDAP_INVALID_PARAM);
if (*realfilter == NULL)
return (NS_LDAP_MEMORY);
return (NS_LDAP_SUCCESS);
}
/* returns 0=success, 1=error */
int
{
int rc;
char buf[500];
buf[0] = '\0';
if (rc != NS_LDAP_SUCCESS) {
char *p;
(void) __ns_ldap_err2str(rc, &p);
} else
return (rc);
}
return (0);
}
int
switch_err(int rc)
{
switch (rc) {
case NS_LDAP_SUCCESS:
return (0);
case NS_LDAP_NOTFOUND:
return (1);
}
return (2);
}
{
extern char *optarg;
extern int optind;
char *ldapfilter = NULL;
char *attribute = "dn";
char **ldapattribute = NULL;
char *buffer[100];
char *p;
int index = 1;
int c, repeat = 1;
int rc;
int verbose = 0;
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'd':
break;
case 'h':
(void) printMapping();
exit(0);
case 'l':
attribute = "NULL";
break;
case 'v':
verbose = 1;
break;
default:
}
}
if ((--c) > 0)
/*
* If dumpping a database,
* or all the containers,
* use page control just
* in case there are too many entries
*/
/* build the attribute array */
else {
*p = '\0';
}
}
/* build the filter */
/* user publickey lookup */
int rc1;
if (ldapfilter) {
if (verbose) {
gettext("+++ template for merging"
"SSD filter=%s\n"),
}
}
/* hosts publickey lookup */
if (ldapfilter) {
if (verbose) {
gettext("+++ template for merging"
"SSD filter=%s\n"),
}
}
/* this should never happen */
gettext("ldaplist: invalid publickey lookup\n"));
rc = 2;
if (rc == -1)
} else
rc = 0;
}
/*
* we set the search filter to (objectclass=*) when we want
* to list the directory attribute instead of the entries
* (the -d option).
*/
(listflag == NS_LDAP_SCOPE_BASE)) {
}
if (verbose) {
gettext("+++ template for merging SSD filter=%s\n"),
}
if (ldapfilter)
if (udata)
}