/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2011 Nexenta Systems, Inc. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <strings.h>
#include <locale.h>
#include <syslog.h>
#include "standalone.h"
extern char *set_filter(char **, char *, char **);
extern char *set_filter_publickey(char **, char *, int, char **);
extern void _printResult(ns_ldap_result_t *);
extern void printMapping();
int listflag = 0;
static struct database_t {
const char *database;
const char *sortattr;
}databaselist[] = {
{ NS_LDAP_TYPE_HOSTS, "cn" },
{ NS_LDAP_TYPE_IPNODES, "cn" },
{ NS_LDAP_TYPE_RPC, "cn" },
{ NS_LDAP_TYPE_PROTOCOLS, "cn" },
{ NS_LDAP_TYPE_NETWORKS, "ipnetworknumber" },
{ NS_LDAP_TYPE_SERVICES, "cn" },
{ NS_LDAP_TYPE_GROUP, "gidnumber" },
{ NS_LDAP_TYPE_NETMASKS, "ipnetworknumber"},
{ NS_LDAP_TYPE_ETHERS, "cn" },
{ NS_LDAP_TYPE_NETGROUP, "cn" },
{ NS_LDAP_TYPE_BOOTPARAMS, "cn" },
{ NS_LDAP_TYPE_PUBLICKEY, "cn" },
{ NS_LDAP_TYPE_PASSWD, "uid" },
{ NS_LDAP_TYPE_SHADOW, "uid" },
{ NS_LDAP_TYPE_ALIASES, "cn" },
{ NS_LDAP_TYPE_AUTOMOUNT, "automountKey" },
{ NS_LDAP_TYPE_USERATTR, "uid" },
{ NS_LDAP_TYPE_PROFILE, "cn" },
{ NS_LDAP_TYPE_EXECATTR, "cn" },
{ NS_LDAP_TYPE_AUTHATTR, "cn" },
{ NS_LDAP_TYPE_AUUSER, "uid" },
{ NS_LDAP_TYPE_TNRHDB, "ipTnetNumber" },
{ NS_LDAP_TYPE_TNRHTP, "ipTnetTemplateName" },
{ NS_LDAP_TYPE_PROJECT, "SolarisProjectName" },
{ 0, 0 }
};
void
if (msg)
"\n"
"usage: ldaplist [-dlv] [-h LDAP_server[:serverPort] [-M domainName]\n"
"[-N profileName] [-a authenticationMethod] [-P certifPath]\n"
"[-D bindDN] [-w bindPassword] [-j passwdFile]]\n"
"[<database> [<key>] ...]\n\n"
"usage: ldaplist -h\n"
"\n"
"usage: ldaplist -g\n\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 -g list the database mappings.\n"
"\t -h An address (or a name) and a port of the LDAP server in\n"
"\t which the entries will be stored. The default value for\n"
"\t the port is 389 (or 636 for TLS connections).\n"
"\t -M The name of a domain served by the specified server.\n"
"\t If not specified, the default domain name will be used.\n"
"\t -N Specifies a DUAProfile name.\n"
"\t The default value is \"default\".\n"
"\t -a Specifies an authentication method.\n"
"\t -P The certificate path for the location of the certificate\n"
"\t database.\n"
"\t -D Specifies an entry which has read permission to\n"
"\t the requested database.\n"
"\t -w Password to be used for authenticating the bindDN.\n"
"\t -j File containing the password for bindDN or SSL key db.\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"
"\nNOTE: The old -h option printing the mapping information is "
"deprecated.\nFor backward compatibility the following mode is "
"available:\nldaplist -h\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;
char *checker;
/* sanity check */
if (realfilter == NULL)
return (NS_LDAP_INVALID_PARAM);
*realfilter = NULL;
return (NS_LDAP_INVALID_PARAM);
/* Parameter check. We only want one %s here, otherwise bail. */
len = 0; /* Reuse 'len' as "Number of %s hits"... */
do {
return (NS_LDAP_INVALID_PARAM);
len++; /* Got our %s. */
checker += 2;
} else if (len != 1)
return (NS_LDAP_INVALID_PARAM);
if (*realfilter == NULL)
return (NS_LDAP_MEMORY);
return (NS_LDAP_SUCCESS);
}
/* returns 0=success, 1=error */
int
{
int rc;
int i;
if (database) {
for (i = 0; databaselist[i].database; i++) {
break;
}
NS_LDAP_TYPE_AUTOMOUNT) == 0 &&
sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) {
break;
}
}
}
buf[0] = '\0';
if (rc != NS_LDAP_SUCCESS) {
char *p;
(void) __ns_ldap_err2str(rc, &p);
(void) __ns_ldap_freeError(&errorp);
} else
return (rc);
}
(void) __ns_ldap_freeResult(&result);
return (0);
}
int
{
switch (rc) {
case NS_LDAP_SUCCESS:
return (0);
case NS_LDAP_NOTFOUND:
return (1);
}
return (2);
}
int
{
extern int optind;
char *p;
int c;
int rc;
int verbose = 0;
(void) textdomain(TEXT_DOMAIN);
if (argc == 2 &&
/* preserve backwards compatability, support old -h option */
(void) printMapping();
exit(0);
}
switch (c) {
case 'd':
break;
case 'g':
(void) printMapping();
exit(0);
break; /* Never reached */
case 'l':
attribute = "NULL";
break;
case 'v':
verbose = 1;
break;
case 'M':
break;
case 'h':
if (separatePort(optarg,
&standalone_cfg.SA_PORT) > 0) {
exit(1);
}
break;
case 'P':
break;
case 'N':
break;
case 'D':
break;
case 'w':
gettext("The -w option is mutually "
"exclusive of -j. -w is ignored.\n"));
break;
}
/* Ask for a password later */
break;
}
break;
case 'j':
gettext("The -w option is mutually "
"exclusive of -j. -w is ignored.\n"));
}
exit(1);
}
break;
case 'a':
break;
default:
}
}
gettext("Please specify an LDAP server you want "
"to connect to. \n"));
exit(1);
}
if ((--c) > 0)
&auth,
&errorp) != NS_LDAP_SUCCESS) {
if (errorp) {
(void) __ns_ldap_freeError(&errorp);
}
exit(1);
}
}
/* If password is not specified, then prompt user for it. */
}
&errorp) != NS_LDAP_SUCCESS) {
if (errorp) {
(void) __ns_ldap_freeError(&errorp);
}
exit(1);
}
(void) __ns_ldap_freeError(&errorp);
}
exit(1);
}
}
(void) __ns_ldap_freeError(&errorp);
}
exit(1);
}
}
(void ***)&authpp,
(void) __ns_ldap_freeParam((void ***)&authpp);
if (errorp) {
(void) __ns_ldap_freeError(&errorp);
}
exit(1);
}
/*
* For now we have no use for bindDN and
*/
"used as an authentication method"
"The bind DN and password will "
"be ignored.\n"));
break;
}
}
}
/*
* 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("+++ database=%s\n"),
gettext("+++ filter=%s\n"),
gettext("+++ template for merging"
"SSD filter=%s\n"),
}
}
/* hosts publickey lookup */
if (ldapfilter) {
if (verbose) {
gettext("+++ database=%s\n"),
gettext("+++ filter=%s\n"),
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)
return (0); /* Never reached */
}