ldapaddent.c revision f31b640de2d61c32eb0eb71bd91a516628cb22b6
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* Utility to add /etc files into LDAP.
* Can also be used to dump entries from a ldap container in /etc format.
*/
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <strings.h>
#include <ctype.h>
#include <locale.h>
#include <syslog.h>
#include <nss_dbdefs.h>
#include <netdb.h>
#include <grp.h>
#include <pwd.h>
#include <shadow.h>
#include <sys/systeminfo.h>
#include "ns_internal.h"
#include "ldapaddent.h"
#define OP_ADD 0
#define OP_DUMP 3
static struct ttypelist_t {
char *ttype; /* type tag */
int (*genent)(char *, int(*)());
/* routine to turn line into ldap entries */
void (*dump)(ns_ldap_result_t *);
/* routine to print ldap containers */
int (*filedbmline)(); /* routine to turn file line into dbm line */
char *objclass; /* Objectclass for the servicetype */
} *tt;
char parse_err_msg [PARSE_ERR_MSG_LEN];
int continue_onerror = 0; /* do not exit on error */
extern int optind;
extern char *optarg;
extern char *__nis_quote_key(const char *, char *, int);
/* from ns_internal.h */
extern int __s_api_prepend_automountmapname_to_dn(
const char *, char **, ns_ldap_error_t **);
static char *inputbasedn = NULL;
static char *databasetype = NULL;
static int exit_val = 0;
static unsigned nent_add = 0;
unsigned flags = 0;
static void
perr(ns_ldap_error_t *e)
{
if (e)
}
static int
ascii_to_int(char *str)
{
int i;
char *c = str;
if (c == NULL || *c == '\0')
return (-1);
while (c != '\0' && *c == ' ')
c++;
if (*c == '\0')
return (-1);
for (i = 0; i < strlen(c); i++)
if (!isdigit(c[i]))
return (-1);
return (atoi(c));
}
/*
* Internet network address interpretation routine.
* The library routines call this routine to interpret
* network numbers.
*/
static in_addr_t
encode_network(const char *cp)
{
int base;
ptrdiff_t n;
char c;
int i;
if (*cp == '0') {
else
base = 8;
}
if (isdigit(c)) {
if ((c - '0') >= base)
break;
cp++;
continue;
}
cp++;
continue;
}
break;
}
if (*cp == '.') {
return ((in_addr_t)-1);
goto again;
}
return ((in_addr_t)-1);
if (n > 4)
return ((in_addr_t)-1);
for (val = 0, i = 0; i < n; i++) {
val <<= 8;
}
for (/* no init */; i < 4; i++)
val <<= 8;
return (val);
}
static void
replace_tab2space(char *str)
{
int i = 0;
if (str[i] == '\t')
str[i] = ' ';
i++;
}
}
static int
{
char *p;
for (p = line; *p; p++)
if (*p != ' ' && *p != '\t')
return (0);
return (1);
}
/*
* check whether the token <tok> is a triplet,
* i. e. <tok> := (<hostname>,<username>,<domainname>)
* where <hostname>, <username>, <domainname> are IA5String
* <tok> supposes to contain NO spaces and start with '('
*/
static int
is_triplet(char *tok)
{
char *s;
!*++s && /* ')' ends token */
}
static void
{
gettext("line_buf_expand: out of memory\n"));
exit(1);
}
}
static void
{
}
static int
{
ns_ldap_attr_t *a;
char *v;
if (a == NULL)
return (NS_LDAP_MEMORY);
free(a);
return (NS_LDAP_MEMORY);
}
free(a);
return (NS_LDAP_MEMORY);
}
a->value_count = 1;
if (v == NULL) {
free(a);
return (NS_LDAP_MEMORY);
}
a->attrvalue[0] = v;
e->attr_pair[e->attr_count] = a;
e->attr_count++;
return (NS_LDAP_SUCCESS);
}
static int
{
ns_ldap_attr_t *a;
char *v;
char **av;
int i, j;
if (a == NULL)
return (NS_LDAP_MEMORY);
free(a);
return (NS_LDAP_MEMORY);
}
;
free(a);
return (NS_LDAP_MEMORY);
}
a->value_count = i;
for (j = 0; j < i; j++) {
if (v == NULL) {
free(a);
return (NS_LDAP_MEMORY);
}
a->attrvalue[j] = v;
}
e->attr_pair[e->attr_count] = a;
e->attr_count++;
return (NS_LDAP_SUCCESS);
}
static ns_ldap_entry_t *
{
ns_ldap_entry_t *e;
if (e == NULL)
return (NULL);
sizeof (ns_ldap_attr_t *));
free(e);
return (NULL);
}
e->attr_count = 0;
free(e);
return (NULL);
}
return (e);
}
static void
{
int j, k = 0;
return;
return;
}
for (j = 0; j < ep->attr_count; j++) {
continue;
}
}
}
}
static int
{
int result = 0;
int rc = 1;
/* adds entry into the LDAP tree */
if (mod)
else
/*
* Return 0 on success
* LDAP_ALREADY_EXISTS if entry exists already
* 1 for all other non-fatal errors.
* Exit on fatal errors.
*/
switch (result) {
case NS_LDAP_SUCCESS:
nent_add++;
rc = 0;
break;
case NS_LDAP_OP_FAILED:
rc = 1;
break;
case NS_LDAP_INVALID_PARAM:
gettext("invalid parameter(s) passed.\n"));
rc = 1;
break;
case NS_LDAP_NOTFOUND:
rc = 1;
break;
case NS_LDAP_MEMORY:
gettext("internal memory allocation error.\n"));
exit(1);
break;
case NS_LDAP_CONFIG:
gettext("LDAP Configuration problem.\n"));
exit(1);
break;
case NS_LDAP_PARTIAL:
gettext("partial result returned\n"));
rc = 1;
break;
case NS_LDAP_INTERNAL:
else {
rc = 1;
}
break;
}
if (eres)
(void) __ns_ldap_freeError(&eres);
return (rc);
}
/*
* usage(char *msg)
* Display usage message to STDERR.
*/
static void
if (msg)
"usage: ldapaddent [ -cpv ] [ -a authenticationMethod ]\n"
"[ -b baseDN ] -D bindDN -w bind_password [ -f file ] database\n\n"
"usage: ldapaddent -d [ -cpv ] [ -a authenticationMethod ]\n"
"[ -b baseDN ] [ -D bindDN ] [ -w bind_password ] database\n"));
exit(1);
}
/*
* Determine if the given string is an IP address (IPv4 or IPv6).
* If so, it's converted to the preferred form (rfc2373) and
* *newaddr will point to the new address.
*
* Returns -2 : inet_ntop error
* -1 : not an IP address
* 0 : unsupported IP address (future use)
* AF_INET : IPv4
* AF_INET6 : IPv6
*/
static int
/* IPv6 */
return (AF_INET6);
/* Convert IPv4-mapped IPv6 address to IPv4 */
if (IN6_IS_ADDR_V4MAPPED(&addr_ipv6) ||
gettext("out of memory\n"));
exit(1);
}
return (AF_INET6);
return (-2);
}
/* Processing general IPv6 addresses */
exit(1);
}
return (AF_INET6);
return (-2);
}
/* Processing IPv4 addresses of the type d.d.d.d. */
return (AF_INET);
exit(1);
}
return (AF_INET);
return (-2);
}
/* Processing IPv4 addresses d.d.d , d.d and d */
return (AF_INET);
exit(1);
}
return (AF_INET);
}
return (-1);
}
static int
{
char *t;
char *alias;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 3)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* addr(col 2)
*/
return (GENENT_PARSEERR);
}
if (af == -2) {
} else if (af == -1) {
"Invalid IP address: %s", t);
gettext("IP address %s converted to %s\n"),
t, pref_addr);
}
}
if (af < 0) {
if (continue_onerror == 0)
return (GENENT_CBERR);
else
return (rc);
}
/*
* cname (col 0)
*/
return (GENENT_PARSEERR);
}
cname = t;
/* build entry */
exit(1);
}
/*
* name (col 1)
*/
do {
/*
* don't clobber comment in canonical entry
*/
/* This call to AddEntry may move out of the loop */
/* This is because we have to call the function just once */
continue;
continue;
ctr++;
exit(1);
}
/*
* only put comment in canonical entry
*/
/* End the list of all the aliases by NULL */
exit(1);
}
gettext("Adding entry : cn=%s+ipHostNumber=%s\n"),
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: cn=%s+ipHostNumber=%s "
"already Exists -skipping it\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: cn=%s+ipHostNumber=%s"
" already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int i, j;
char *name; /* host name */
return;
}
/* sanity check */
return;
return;
/* IPV4 or IPV6 but <= NET_ADDRSTRLEN */
else
/* IPV6 */
/* aliases */
for (j = 0; j < cn->value_count; j++) {
/* skip host name */
continue;
}
}
/* end of line */
}
/*
*/
static int
{
char *t;
char *cname;
char *alias;
int ctr = 0;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 3)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* cname(col 0)
*/
return (GENENT_PARSEERR);
}
cname = t;
/*
* number (col 2)
*/
return (GENENT_PARSEERR);
}
/*
* build entry
*/
"invalid program number: %s",
return (GENENT_PARSEERR);
}
} else
/*
* name (col 1)
*/
t = cname;
do {
/*
* don't clobber comment in canonical entry
*/
continue;
continue;
ctr++;
exit(1);
}
/*
* only put comment in canonical entry
*/
/* End the list of all the aliases by NULL */
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int i, j;
char *name; /* rpc name */
return;
}
/* sanity check */
return;
return;
/* rpc name */
else
/* rpc number */
/* aliases */
for (j = 0; j < cn->value_count; j++) {
/* skip rpc name */
continue;
}
}
/* end of line */
}
/*
*
*/
static int
{
char *t;
char *cname;
char *alias;
int ctr = 0;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 3)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* cname(col 0)
*/
return (GENENT_PARSEERR);
}
cname = t;
/*
* number (col 2)
*/
return (GENENT_PARSEERR);
}
/*
* build entry
*/
"invalid protocol number: %s",
return (GENENT_PARSEERR);
}
} else
/*
* name (col 1)
*/
t = cname;
ctr = 0;
do {
/*
* don't clobber comment in canonical entry
*/
continue;
continue;
ctr++;
exit(1);
}
/*
* only put comment in canonical entry
*/
/* End the list of all the aliases by NULL */
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int i, j;
return;
== 0)
}
/* sanity check */
return;
return;
/* protocol name */
else
/* protocol number */
/* aliases */
for (j = 0; j < cn->value_count; j++) {
/* Do not replicate */
continue;
/*
* Replicate name in uppercase as an aliase
*/
}
}
}
/* end of line */
}
/*
*
*/
static int
{
char *t;
char *cname;
char *alias;
int ctr = 0;
int retval = 1;
int enet;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 3)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* cname(col 0)
*/
return (GENENT_PARSEERR);
}
cname = t;
/*
* number (col 2)
*/
return (GENENT_PARSEERR);
}
/*
* build entry
*/
/*
* data.n_net is an unsigned field,
* assign -1 to it, make no sense.
* Use enet here to avoid lint warning.
*/
if (continue_onerror == 0)
return (GENENT_CBERR);
} else
/*
* name (col 1)
*/
t = cname;
do {
/*
* don't clobber comment in canonical entry
*/
continue;
continue;
ctr++;
exit(1);
}
/*
* only put comment in canonical entry
*/
/* End the list of all the aliases by NULL */
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int i, j;
char *name;
return;
== 0)
}
/* sanity check */
return;
/*
* cn can be a MUST attribute(RFC 2307) or MAY attribute(2307bis).
* If the canonical name can not be found (2307bis), use the 1st
* value as the official name.
*/
/* network name */
else
/* network number */
/* aliases */
for (j = 0; j < cn->value_count; j++) {
/* skip name */
continue;
}
}
/* end of line */
}
/*
*
*/
static int
{
char *t, *p;
char *cname;
char *alias;
int ctr = 0;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 4)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* cname(col 0)
*/
return (GENENT_PARSEERR);
}
cname = t;
/*
* port (col 3)
*/
return (GENENT_PARSEERR);
}
if ((p = strchr(t, '/')) == 0) {
return (GENENT_PARSEERR);
}
*(p++) = 0;
/*
* proto (col 2)
*/
/*
* build entry
*/
"invalid port number: %s",
return (GENENT_PARSEERR);
}
} else
/*
* name (col 1)
*/
t = cname;
do {
/*
* don't clobber comment in canonical entry
*/
continue;
continue;
ctr++;
exit(1);
}
/*
* only put comment in canonical entry
*/
/* End the list of all the aliases by NULL */
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
"Entry: cn=%s+ipServiceProtocol=%s"
" already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: cn=%s+ipServiceProtocol=%s"
" - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int i, j, len;
char *name; /* service name */
/*
* cn can have multiple values.(service name and its aliases)
* In order to support RFC 2307, section 5.5, ipserviceprotocol can
* have multiple values too.
* The output format should look like
*
* test 2345/udp mytest
* test 2345/tcp mytest
*/
return;
"ipServiceProtocol") == 0)
}
/* sanity check */
return;
return;
for (i = 0; i < protocol->value_count; i++) {
return;
/* service name */
/* port & protocol */
if (len < 8)
else
/* aliases */
for (j = 0; j < cn->value_count; j++) {
/* skip service name */
continue;
}
}
/* end of line */
}
}
/*
*/
static int
{
char *s, *t;
int ctr = 0;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
t = buf;
/* ignore empty entries */
if (*t == '\0')
return (GENENT_OK);
/*
* clear column data
*/
/*
* name (col 0)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* passwd (col 1)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* gid (col 2)
*/
if ((s = strchr(t, ':')) == 0 || s == t) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* members (col 3)
*/
/*
* build entry
*/
"invalid group id: %s",
return (GENENT_PARSEERR);
}
} else
/* Compute maximum amount of members */
s = t;
while (s = strchr(s, ',')) {
s++;
ctr++;
}
/* Allocate memory for all members */
exit(1);
}
ctr = 0;
while (s = strchr(t, ',')) {
*s++ = 0;
t = s;
/* Send to server only non empty member names */
}
/* Send to server only non empty member names */
if (strlen(t) != 0)
/* Array of members completed, finished by NULL, see calloc() */
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
char pnam[256];
int attr_count = 0;
else {
else
}
else
value[attr_count]);
attr_count++;
}
}
else
}
/*
*/
static int
{
char *t;
int retval = 1;
struct _ns_ethers data;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 2)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* addr(col 0)
*/
return (GENENT_PARSEERR);
}
/*
* name(col 1)
*/
return (GENENT_PARSEERR);
}
/*
* build entry
*/
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
else
return;
}
static int
{
char *t, *aliases;
char *cname;
int ctr = 0;
int retval = 1;
int i;
char *alias;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
return (GENENT_PARSEERR);
}
t[0] = '\0';
if (++t == '\0') {
return (GENENT_PARSEERR);
}
aliases = t;
/* build entry */
exit(1);
}
do {
ctr++;
while (t[0] == ' ')
t++;
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
i = 0;
return (rc);
}
static void
{
int attr_count = 0;
attr_count++;
}
}
/*
*/
static int
{
char *t, *p, *tmppubkey, *tmpprivkey;
struct _ns_pubkey data;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
return (GENENT_PARSEERR);
}
/*
* for principal "nobody". We skip it.
*/
if (strcmp(t, "nobody") == 0)
return (GENENT_OK);
/*
* cname (col 0)
*/
return (GENENT_PARSEERR);
}
return (GENENT_PARSEERR);
}
*(p++) = 0;
/*
* don't generate entries for uids without passwd entries
*/
gettext("can't map uid %d to username, skipping\n"),
uid);
return (GENENT_OK);
}
} else {
gettext("can't map hostname %s to hostaddress, skipping\n"),
tmpbuf);
return (GENENT_OK);
}
sizeof (in));
}
/*
* public_data (col 1)
*/
return (GENENT_PARSEERR);
}
if ((p = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*(p++) = 0;
/*
* private_data (col 2) and algtype extraction
*/
if (*p == ':')
p++;
t = p;
if (!(t = strchr(t, ':'))) {
gettext("WARNING: No algorithm type data found "
"in publickey file, assuming 0\n"));
algtype = 0;
} else {
*t = '\0';
t++;
}
/*
* auth_type (col 1)
*/
MECH_MAXATNAME))) {
gettext("Could not convert algorithm type to "
"corresponding auth type string\n"));
return (GENENT_ERR);
}
/*
* build entry
*/
exit(1);
}
exit(1);
}
exit(1);
}
return (GENENT_CBERR);
else {
return (GENENT_OK);
}
}
static void
{
char domainname[BUFSIZ];
return;
gettext("could not obtain domainname\n"));
exit(1);
}
/*
* Retrieve all the attributes, but don't print
* until we have all the required ones.
*/
else
value[0], domainname);
else
return;
return;
}
return;
/* print the attributes, algorithm type is always 0 */
}
/*
*/
static int
{
char *t;
struct _ns_netmasks data;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* comment (col 2)
*/
if (t) {
*t++ = 0;
} else {
}
/*
* addr(col 0)
*/
return (GENENT_PARSEERR);
}
/*
* mask (col 1)
*/
return (GENENT_PARSEERR);
}
/* build entry */
return (GENENT_CBERR);
return (GENENT_OK);
}
static void
{
}
/*
* column data format is:
* col 0: netgroup name (or cname)
* col 1: netgroup member, if this is a triplet
* col 2: netgroup member, if not a triplet
* col 3: comment
*/
static int
{
char *t;
struct _ns_netgroups data;
/* don't clobber our argument */
return (GENENT_PARSEERR);
}
/* clear column data */
/*
* process 1st minimal entry, to validate that there is no
* parsing error.
* start with comment(col 3)
*/
if (t) {
*t++ = 0;
} else {
}
/* cname (col 0) */
return (GENENT_PARSEERR);
}
cname = t;
/* addr(col 1 and 2) */
return (GENENT_PARSEERR);
}
if (*t == '(') {
/* if token starts with '(' it must be a valid triplet */
if (is_triplet(t)) {
} else {
return (GENENT_PARSEERR);
}
} else {
}
/*
* now build entry.
* start by clearing entry data
*/
gettext("out of memory\n"));
exit(1);
}
== NULL) {
gettext("out of memory\n"));
exit(1);
}
}
/*
* we now have a valid entry (at least 1 netgroup name and
* 1 netgroup member), proceed with the rest of the line
*/
/* if next token is equal to netgroup name, ignore */
continue;
continue;
if (*t == '(') {
if (is_triplet(t)) {
/* skip a triplet if it is added already */
for (i = 0; i < tripletcount &&
;
if (i < tripletcount)
continue;
tripletcount++;
triplet_tmp = strdup(t);
tripletcount * sizeof (char **)))
== NULL) {
gettext("out of memory\n"));
exit(1);
}
} else {
}
} else {
/* skip a netgroup if it is added already */
for (i = 0; i < netgcount &&
;
if (i < netgcount)
continue;
netgcount++;
gettext("out of memory\n"));
exit(1);
}
}
}
/* End the list with NULL */
exit(1);
}
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
"Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
}
/* release memory allocated by strdup() */
for (i = 0; i < tripletcount; i++) {
}
for (i = 0; i < netgcount; i++) {
}
return (rc);
}
static void
{
int attr_count = 0;
else
return;
attr_count++;
}
attr_count++;
}
}
static int
{
char *t, *s;
struct _ns_automount data;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/* replace every tabspace with single space */
/*
* clear column data
*/
/*
* key (col 0)
*/
t = buf;
while (t[0] == ' ')
t++;
if ((s = strchr(t, ' ')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
while (t[0] == ' ')
t++;
/*
* mapentry (col 1)
*/
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
return;
else
}
}
/*
*
*/
static int
{
char *s, *t;
int retval = 1;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
t = buf;
/* ignore empty entries */
if (*t == '\0')
return (GENENT_OK);
/*
* clear column data
*/
/*
* name (col 0)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* passwd (col 1)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* uid (col 2)
*/
if ((s = strchr(t, ':')) == 0 || s == t) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* gid (col 3)
*/
if ((s = strchr(t, ':')) == 0 || s == t) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* gcos (col 4)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* home (col 5)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shell (col 6)
*/
/*
* build entry
*/
/* Add {crypt} before passwd entry */
}
else
return (GENENT_PARSEERR);
}
} else
return (GENENT_PARSEERR);
}
} else
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
char pnam[256];
return;
else
else {
else
}
else
else
else
}
/*
*/
static int
{
char *s, *t;
int spflag;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
t = buf;
/* ignore empty entries */
if (*t == '\0')
return (GENENT_OK);
/*
* clear column data
*/
/*
* name (col 0)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* passwd (col 1)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shadow last change (col 2)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shadow min (col 3)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shadow max (col 4)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shadow warn (col 5)
*/
if ((s = strchr(t, ':')) == 0) {
return (GENENT_PARSEERR);
}
*s++ = 0;
t = s;
/*
* shadow inactive (col 6)
*/
if ((s = strchr(t, ':')) != 0) {
*s++ = 0;
t = s;
}
/*
* shadow expire (col 7)
*/
if ((s = strchr(t, ':')) != 0) {
*s++ = 0;
t = s;
/*
* flag (col 8)
*/
}
/*
* build entry
*/
/* Add {crypt} before passwd entry */
} else
"invalid last changed date: %s",
return (GENENT_PARSEERR);
}
} else
"invalid sp_min : %s",
return (GENENT_PARSEERR);
}
} else
"invalid sp_max : %s",
return (GENENT_PARSEERR);
}
} else
"invalid sp_warn : %s",
return (GENENT_PARSEERR);
}
} else
"invalid sp_inact : %s",
return (GENENT_PARSEERR);
}
} else
"invalid login expiry date : %s",
return (GENENT_PARSEERR);
}
} else
/*
* data.sp_flag is an unsigned int,
* assign -1 to it, make no sense.
* Use spflag here to avoid lint warning.
*/
if (spflag < 0) {
"invalid flag value: %s",
return (GENENT_PARSEERR);
} else
} else
return (GENENT_CBERR);
return (GENENT_OK);
}
static void
{
char pnam[256];
return;
else
else {
else
}
else
else
else
/* ignore shadowWarning, shadowInactive, shadowExpire, shadowFlag */
}
static int
{
char *t;
char *parameter;
/*
* don't clobber our argument
*/
return (GENENT_PARSEERR);
}
/*
* clear column data
*/
/*
* cname (col 0)
*/
return (GENENT_PARSEERR);
}
/* build entry */
/*
* name (col 1)
*/
do {
/*
* don't clobber comment in canonical entry
*/
ctr++;
exit(1);
}
/* End the list of all the aliases by NULL */
exit(1);
}
if (retval == LDAP_ALREADY_EXISTS) {
if (continue_onerror)
gettext("Entry: %s - already Exists, skipping it.\n"),
else {
rc = GENENT_CBERR;
gettext("Entry: %s - already Exists\n"),
}
} else if (retval)
rc = GENENT_CBERR;
return (rc);
}
static void
{
int attr_count = 0;
attr_count++;
}
}
static char *
{
int c;
for (;;) {
if (c == -1)
break;
if (c == '\n')
break;
}
/* Null Terminate */
/* if no characters are read, return NULL to indicate EOF */
return (0);
}
/*
* return a line from the file, discarding comments and blank lines
*/
static int
{
int i, len = 0;
for (;;) {
return (0);
if (lineno)
(*lineno)++;
if (len >= 2 &&
len -= 2;
continue; /* append next line at end */
}
len -= 1;
}
/*
* Skip lines where '#' is the first non-blank character.
*/
for (i = 0; i < len; i++) {
len = i;
break;
}
break;
}
/*
* A line with one or more white space characters followed
* by a comment will now be blank. The special case of a
* line with '#' in the first byte will have len == 0.
*/
break;
len = 0;
}
return (1);
}
/*
* return a line from the file, discarding comments, blanks, and '+' lines
*/
static int
{
int len = 0;
for (;;) {
return (0);
if (lineno)
(*lineno)++;
len -= 1;
}
break;
len = 0;
}
return (1);
}
/* Populating the ttypelist structure */
static struct ttypelist_t ttypelist[] = {
filedbmline_comment, "iphost" },
filedbmline_comment, "iphost" },
filedbmline_comment, "oncrpc" },
filedbmline_comment, "ipprotocol" },
filedbmline_comment, "ipnetwork" },
filedbmline_comment, "ipservice" },
filedbmline_plus, "posixgroup" },
filedbmline_comment, "ipnetwork" },
filedbmline_comment, "ieee802Device" },
filedbmline_comment, "nisnetgroup" },
filedbmline_comment, "bootableDevice" },
filedbmline_comment, "niskeyobject" },
filedbmline_plus, "posixaccount" },
filedbmline_plus, "shadowaccount" },
filedbmline_plus, "mailGroup" },
filedbmline_comment, "automount" },
filedbmline_comment, "SolarisUserAttr" },
filedbmline_comment, "SolarisProfAttr" },
filedbmline_comment, "SolarisExecAttr" },
filedbmline_comment, "SolarisAuthAttr" },
filedbmline_comment, "SolarisAuditUser" },
{ 0, 0, 0, 0, 0 }
};
static int lineno = 0;
static void
addfile()
{
/* Initializing the Line Buffer */
/* Loop through all the lines in the file */
case GENENT_OK:
break;
case GENENT_PARSEERR:
gettext("parse error: %s (line %d)\n"),
exit_val = 1;
break;
case GENENT_CBERR:
gettext("Error while adding line: %s\n"),
exit_val = 2;
return;
break;
case GENENT_ERR:
gettext("Internal Error while adding line: %s\n"),
exit_val = 3;
return;
break;
}
}
}
static void
{
int done = 0;
/* set the appropriate filter */
/*
* prof_attr entries are SolarisProfAttr
* without AUXILIARY SolarisExecAttr
*/
"(&(objectclass=%s)(!(objectclass=SolarisExecAttr)))",
} else
/* Pass cred only if supplied. Cred is not always needed for dump */
else
switch (rc) {
case NS_LDAP_SUCCESS:
nent_add++;
success = 1;
else
}
else
break;
case NS_LDAP_OP_FAILED:
exit_val = 2;
break;
case NS_LDAP_INVALID_PARAM:
exit_val = 2;
gettext("invalid parameter(s) passed.\n"));
break;
case NS_LDAP_NOTFOUND:
exit_val = 2;
break;
case NS_LDAP_MEMORY:
exit_val = 2;
gettext("internal memory allocation error.\n"));
break;
case NS_LDAP_CONFIG:
exit_val = 2;
gettext("LDAP Configuration problem.\n"));
break;
case NS_LDAP_PARTIAL:
exit_val = 2;
gettext("partial result returned\n"));
break;
case NS_LDAP_INTERNAL:
exit_val = 2;
gettext("internal LDAP error occured.\n"));
break;
}
(void) __ns_ldap_freeResult(&eres);
}
if (success) {
while (!done) {
done = 1;
continue;
}
/* Print the result */
else
(void) __ns_ldap_freeResult(&eres);
}
}
}
}
int
{
char *password;
int c;
int rc;
int ldaprc;
int authstried = 0;
int supportedauth = 0;
ns_ldap_entry_t *e;
int flag = 0;
int version1 = 0;
(void) textdomain(TEXT_DOMAIN);
inputbasedn = NULL;
switch (c) {
case 'd':
if (op)
usage("no other option should be specified");
break;
case 'c':
continue_onerror = 1;
break;
case 'v':
break;
case 'p':
break;
case 'f':
break;
case 'D':
break;
case 'w':
break;
case 'b':
break;
case 'a':
break;
default:
}
}
/* This is not an optional parameter. Exit */
gettext("Distinguished Name to bind to directory"
" must be specified. use option -D.\n"));
exit(1);
}
/* If password is not specified, then prompt user for it. */
}
supportedauth = 1;
}
supportedauth = 1;
}
supportedauth = 1;
}
supportedauth = 1;
}
supportedauth = 1;
}
supportedauth = 1;
}
if (!supportedauth) {
gettext("Invalid authentication method specified"));
exit(1);
}
}
&errorp);
if (ldaprc != NS_LDAP_SUCCESS ||
gettext("No legal authentication method "
"configured.\n"));
gettext("Provide a legal authentication method "
"using -a option\n"));
exit(1);
}
/* Use the first authentication method which is not none */
authstried++;
break;
}
}
gettext("No legal authentication method configured.\n"
"Provide a legal authentication method using "
"-a option"));
exit(1);
}
}
exit(1);
}
gettext("automount is not a valid service for ldapaddent.\n"
"Please use auto_*.\n"
"e.g. auto_home, auto_ws etc.\n "));
exit(1);
}
break;
sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0)
break;
}
gettext("database %s not supported;"
" supported databases are:\n"), ttype);
exit(1);
}
&errorp);
version1 = 1;
if (paramVal)
(void) __ns_ldap_freeParam(¶mVal);
if (errorp)
(void) __ns_ldap_freeError(&errorp);
}
/* Check if the container exists in first place */
/* create a container for auto_* if it does not exist already */
if (version1)
oclist[0] = "nisMap";
else
oclist[0] = "automountMap";
if (e == NULL) {
gettext("internal memory allocation error.\n"));
exit(1);
}
if (__s_add_attr(e,
databasetype) != NS_LDAP_SUCCESS) {
gettext("internal memory allocation error.\n"));
ldap_freeEntry(e);
exit(1);
}
if (inputbasedn == NULL) {
gettext("Could not obtain basedn\n"));
ldap_freeEntry(e);
exit(1);
}
}
gettext("Could not create container for %s\n"),
ldap_freeEntry(e);
}
if (rc == NS_LDAP_NOTFOUND) {
gettext("Container %s does not exist\n"),
exit(1);
}
}
dumptable("hosts");
dumptable("passwd");
} else {
}
}
if (etcfile) {
exit(1);
}
} else {
etcfile = "stdin";
}
(void) addfile();
}
/* exit() -> return for make lint */
return (exit_val);
}
/*
* This is called when service == auto_*.
* It calls __ns_ldap_getSearchDescriptors
* to generate the dn from SSD's base dn.
* If there is no SSD available,
* default base dn will be used
* Only the first baseDN in the SSD is used
*/
int rc = NS_LDAP_SUCCESS;
int prepend_automountmapname = FALSE;
/*
* Get auto_* SSD first
*/
if ((rc = __ns_ldap_getSearchDescriptors(
(const char *) service,
(&desc);
return (NS_LDAP_MEMORY);
}
}
}
/* clean up */
/*
* If no dn is duplicated from auto_* SSD, try automount SSD
*/
if ((rc = __ns_ldap_getSearchDescriptors(
(&desc);
return (NS_LDAP_MEMORY);
}
}
}
/* clean up */
}
/*
* If no dn is duplicated from auto_* or automount SSD,
* use default DN
*/
(void) __ns_ldap_freeParam(¶mVal);
return (NS_LDAP_MEMORY);
}
}
}
return (NS_LDAP_OP_FAILED);
} else {
/*
* If dn is duplicated from
* automount SSD basedn or
* default base dn
* then prepend automountMapName=auto_xxx
*/
if (rc != NS_LDAP_SUCCESS) {
(void) __ns_ldap_freeError(&errp);
return (rc);
}
return (NS_LDAP_SUCCESS);
}
}