17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5f31b640dSvl * Common Development and Distribution License (the "License"). 6f31b640dSvl * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22f31b640dSvl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * ldapaddent.c 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * Utility to add /etc files into LDAP. 327c478bd9Sstevel@tonic-gate * Can also be used to dump entries from a ldap container in /etc format. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <stdio.h> 367c478bd9Sstevel@tonic-gate #include <stdlib.h> 377c478bd9Sstevel@tonic-gate #include <libintl.h> 387c478bd9Sstevel@tonic-gate #include <strings.h> 397c478bd9Sstevel@tonic-gate #include <sys/param.h> 407c478bd9Sstevel@tonic-gate #include <ctype.h> 417c478bd9Sstevel@tonic-gate #include <sys/types.h> 427c478bd9Sstevel@tonic-gate #include <sys/socket.h> 437c478bd9Sstevel@tonic-gate #include <netinet/in.h> 447c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 457c478bd9Sstevel@tonic-gate #include <locale.h> 467c478bd9Sstevel@tonic-gate #include <syslog.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #undef opaque 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h> 517c478bd9Sstevel@tonic-gate #include <netdb.h> 527c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h> 537c478bd9Sstevel@tonic-gate #include <grp.h> 547c478bd9Sstevel@tonic-gate #include <pwd.h> 557c478bd9Sstevel@tonic-gate #include <shadow.h> 567c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 577c478bd9Sstevel@tonic-gate #include "ns_internal.h" 587c478bd9Sstevel@tonic-gate #include "ldapaddent.h" 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate #define OP_ADD 0 617c478bd9Sstevel@tonic-gate #define OP_DUMP 3 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate static struct ttypelist_t { 647c478bd9Sstevel@tonic-gate char *ttype; /* type tag */ 657c478bd9Sstevel@tonic-gate int (*genent)(char *, int(*)()); 667c478bd9Sstevel@tonic-gate /* routine to turn line into ldap entries */ 677c478bd9Sstevel@tonic-gate void (*dump)(ns_ldap_result_t *); 687c478bd9Sstevel@tonic-gate /* routine to print ldap containers */ 697c478bd9Sstevel@tonic-gate int (*filedbmline)(); /* routine to turn file line into dbm line */ 707c478bd9Sstevel@tonic-gate char *objclass; /* Objectclass for the servicetype */ 717c478bd9Sstevel@tonic-gate } *tt; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate char parse_err_msg [PARSE_ERR_MSG_LEN]; 747c478bd9Sstevel@tonic-gate int continue_onerror = 0; /* do not exit on error */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate static int get_basedn(char *service, char **basedn); 777c478bd9Sstevel@tonic-gate static int check_ipaddr(char *addr, char **newaddr); 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate extern int optind; 807c478bd9Sstevel@tonic-gate extern char *optarg; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate extern char *__nis_quote_key(const char *, char *, int); 837c478bd9Sstevel@tonic-gate /* from ns_internal.h */ 847c478bd9Sstevel@tonic-gate extern int __s_api_prepend_automountmapname_to_dn( 857c478bd9Sstevel@tonic-gate const char *, char **, ns_ldap_error_t **); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate static char *inputbasedn = NULL; 887c478bd9Sstevel@tonic-gate static char *databasetype = NULL; 897c478bd9Sstevel@tonic-gate static int exit_val = 0; 907c478bd9Sstevel@tonic-gate static unsigned nent_add = 0; 917c478bd9Sstevel@tonic-gate static FILE *etcf = 0; 927c478bd9Sstevel@tonic-gate static ns_cred_t authority; 937c478bd9Sstevel@tonic-gate unsigned flags = 0; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate static void 967c478bd9Sstevel@tonic-gate perr(ns_ldap_error_t *e) 977c478bd9Sstevel@tonic-gate { 987c478bd9Sstevel@tonic-gate if (e) 997c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%d: %s\n"), 1007c478bd9Sstevel@tonic-gate e->status, e->message); 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate static int 1057c478bd9Sstevel@tonic-gate ascii_to_int(char *str) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate int i; 1087c478bd9Sstevel@tonic-gate char *c = str; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if (c == NULL || *c == '\0') 1117c478bd9Sstevel@tonic-gate return (-1); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate while (c != '\0' && *c == ' ') 1147c478bd9Sstevel@tonic-gate c++; 1157c478bd9Sstevel@tonic-gate if (*c == '\0') 1167c478bd9Sstevel@tonic-gate return (-1); 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate for (i = 0; i < strlen(c); i++) 1197c478bd9Sstevel@tonic-gate if (!isdigit(c[i])) 1207c478bd9Sstevel@tonic-gate return (-1); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate return (atoi(c)); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Internet network address interpretation routine. 1277c478bd9Sstevel@tonic-gate * The library routines call this routine to interpret 1287c478bd9Sstevel@tonic-gate * network numbers. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate static in_addr_t 1317c478bd9Sstevel@tonic-gate encode_network(const char *cp) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate in_addr_t val; 1347c478bd9Sstevel@tonic-gate int base; 1357c478bd9Sstevel@tonic-gate ptrdiff_t n; 1367c478bd9Sstevel@tonic-gate char c; 1377c478bd9Sstevel@tonic-gate in_addr_t parts[4], *pp = parts; 1387c478bd9Sstevel@tonic-gate int i; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate again: 1417c478bd9Sstevel@tonic-gate val = 0; base = 10; 1427c478bd9Sstevel@tonic-gate if (*cp == '0') { 1437c478bd9Sstevel@tonic-gate if (*++cp == 'x' || *cp == 'X') 1447c478bd9Sstevel@tonic-gate base = 16, cp++; 1457c478bd9Sstevel@tonic-gate else 1467c478bd9Sstevel@tonic-gate base = 8; 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate while ((c = *cp) != NULL) { 1497c478bd9Sstevel@tonic-gate if (isdigit(c)) { 1507c478bd9Sstevel@tonic-gate if ((c - '0') >= base) 1517c478bd9Sstevel@tonic-gate break; 1527c478bd9Sstevel@tonic-gate val = (val * base) + (c - '0'); 1537c478bd9Sstevel@tonic-gate cp++; 1547c478bd9Sstevel@tonic-gate continue; 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate if (base == 16 && isxdigit(c)) { 1577c478bd9Sstevel@tonic-gate val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); 1587c478bd9Sstevel@tonic-gate cp++; 1597c478bd9Sstevel@tonic-gate continue; 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate break; 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate if (*cp == '.') { 1647c478bd9Sstevel@tonic-gate if (pp >= parts + 4) 1657c478bd9Sstevel@tonic-gate return ((in_addr_t)-1); 1667c478bd9Sstevel@tonic-gate *pp++ = val, cp++; 1677c478bd9Sstevel@tonic-gate goto again; 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate if (*cp && !isspace(*cp)) 1707c478bd9Sstevel@tonic-gate return ((in_addr_t)-1); 1717c478bd9Sstevel@tonic-gate *pp++ = val; 1727c478bd9Sstevel@tonic-gate n = pp - parts; 1737c478bd9Sstevel@tonic-gate if (n > 4) 1747c478bd9Sstevel@tonic-gate return ((in_addr_t)-1); 1757c478bd9Sstevel@tonic-gate for (val = 0, i = 0; i < n; i++) { 1767c478bd9Sstevel@tonic-gate val <<= 8; 1777c478bd9Sstevel@tonic-gate val |= parts[i] & 0xff; 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate for (/* no init */; i < 4; i++) 1807c478bd9Sstevel@tonic-gate val <<= 8; 1817c478bd9Sstevel@tonic-gate return (val); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate static void 1857c478bd9Sstevel@tonic-gate replace_tab2space(char *str) 1867c478bd9Sstevel@tonic-gate { 1877c478bd9Sstevel@tonic-gate int i = 0; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate while ((str) && (str[i])) { 1907c478bd9Sstevel@tonic-gate if (str[i] == '\t') 1917c478bd9Sstevel@tonic-gate str[i] = ' '; 1927c478bd9Sstevel@tonic-gate i++; 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate static int 1977c478bd9Sstevel@tonic-gate blankline(char *line) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate char *p; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate for (p = line; *p; p++) 2027c478bd9Sstevel@tonic-gate if (*p != ' ' && *p != '\t') 2037c478bd9Sstevel@tonic-gate return (0); 2047c478bd9Sstevel@tonic-gate return (1); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 207f31b640dSvl /* 208f31b640dSvl * check whether the token <tok> is a triplet, 209f31b640dSvl * i. e. <tok> := (<hostname>,<username>,<domainname>) 210f31b640dSvl * where <hostname>, <username>, <domainname> are IA5String 211f31b640dSvl * <tok> supposes to contain NO spaces and start with '(' 212f31b640dSvl */ 213f31b640dSvl static int 214f31b640dSvl is_triplet(char *tok) 215f31b640dSvl { 216f31b640dSvl char *s; 217f31b640dSvl return (strchr(++tok, '(') == NULL && /* no more '(' */ 218f31b640dSvl (s = strchr(tok, ')')) != NULL && /* find ')' */ 219f31b640dSvl !*++s && /* ')' ends token */ 220f31b640dSvl (tok = strchr(tok, ',')) != NULL && /* host up to ',' */ 221f31b640dSvl (tok = strchr(++tok, ',')) != NULL && /* user up to ',' */ 222f31b640dSvl strchr(++tok, ',') == NULL); /* no more ',' */ 223f31b640dSvl } 224f31b640dSvl 2257c478bd9Sstevel@tonic-gate static void 2267c478bd9Sstevel@tonic-gate line_buf_expand(struct line_buf *line) 2277c478bd9Sstevel@tonic-gate { 2287c478bd9Sstevel@tonic-gate line->alloc += BUFSIZ; 2297c478bd9Sstevel@tonic-gate line->str = (char *)realloc(line->str, line->alloc); 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate if (line->str == NULL) { 2327c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2337c478bd9Sstevel@tonic-gate gettext("line_buf_expand: out of memory\n")); 2347c478bd9Sstevel@tonic-gate exit(1); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate static void 2397c478bd9Sstevel@tonic-gate line_buf_init(struct line_buf *line) 2407c478bd9Sstevel@tonic-gate { 2417c478bd9Sstevel@tonic-gate (void) memset((char *)line, 0, sizeof (*line)); 2427c478bd9Sstevel@tonic-gate line_buf_expand(line); 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate static int 2467c478bd9Sstevel@tonic-gate __s_add_attr(ns_ldap_entry_t *e, char *attrname, char *value) 2477c478bd9Sstevel@tonic-gate { 2487c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 2497c478bd9Sstevel@tonic-gate char *v; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 2527c478bd9Sstevel@tonic-gate if (a == NULL) 2537c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2547c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 2557c478bd9Sstevel@tonic-gate if (a->attrname == NULL) { 2567c478bd9Sstevel@tonic-gate free(a); 2577c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(1, sizeof (char **)); 2607c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) { 2617c478bd9Sstevel@tonic-gate free(a->attrname); 2627c478bd9Sstevel@tonic-gate free(a); 2637c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate a->value_count = 1; 2667c478bd9Sstevel@tonic-gate a->attrvalue[0] = NULL; 2677c478bd9Sstevel@tonic-gate v = strdup(value); 2687c478bd9Sstevel@tonic-gate if (v == NULL) { 2697c478bd9Sstevel@tonic-gate free(a->attrname); 2707c478bd9Sstevel@tonic-gate free(a->attrvalue); 2717c478bd9Sstevel@tonic-gate free(a); 2727c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate a->attrvalue[0] = v; 2757c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 2767c478bd9Sstevel@tonic-gate e->attr_count++; 2777c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate static int 2817c478bd9Sstevel@tonic-gate __s_add_attrlist(ns_ldap_entry_t *e, char *attrname, char **argv) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate ns_ldap_attr_t *a; 2847c478bd9Sstevel@tonic-gate char *v; 2857c478bd9Sstevel@tonic-gate char **av; 2867c478bd9Sstevel@tonic-gate int i, j; 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate a = (ns_ldap_attr_t *)calloc(1, sizeof (ns_ldap_attr_t)); 2897c478bd9Sstevel@tonic-gate if (a == NULL) 2907c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2917c478bd9Sstevel@tonic-gate a->attrname = strdup(attrname); 2927c478bd9Sstevel@tonic-gate if (a->attrname == NULL) { 2937c478bd9Sstevel@tonic-gate free(a); 2947c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate for (i = 0, av = argv; *av != NULL; av++, i++) 2987c478bd9Sstevel@tonic-gate ; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate a->attrvalue = (char **)calloc(i, sizeof (char **)); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if (a->attrvalue == NULL) { 3037c478bd9Sstevel@tonic-gate free(a->attrname); 3047c478bd9Sstevel@tonic-gate free(a); 3057c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate a->value_count = i; 3087c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 3097c478bd9Sstevel@tonic-gate v = strdup(argv[j]); 3107c478bd9Sstevel@tonic-gate if (v == NULL) { 3117c478bd9Sstevel@tonic-gate free(a->attrname); 3127c478bd9Sstevel@tonic-gate free(a->attrvalue); 3137c478bd9Sstevel@tonic-gate free(a); 3147c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate a->attrvalue[j] = v; 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate e->attr_pair[e->attr_count] = a; 3197c478bd9Sstevel@tonic-gate e->attr_count++; 3207c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate static ns_ldap_entry_t * 3247c478bd9Sstevel@tonic-gate __s_mk_entry(char **objclass, int max_attr) 3257c478bd9Sstevel@tonic-gate { 3267c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 3277c478bd9Sstevel@tonic-gate e = (ns_ldap_entry_t *)calloc(1, sizeof (ns_ldap_entry_t)); 3287c478bd9Sstevel@tonic-gate if (e == NULL) 3297c478bd9Sstevel@tonic-gate return (NULL); 3307c478bd9Sstevel@tonic-gate e->attr_pair = (ns_ldap_attr_t **)calloc(max_attr+1, 3317c478bd9Sstevel@tonic-gate sizeof (ns_ldap_attr_t *)); 3327c478bd9Sstevel@tonic-gate if (e->attr_pair == NULL) { 3337c478bd9Sstevel@tonic-gate free(e); 3347c478bd9Sstevel@tonic-gate return (NULL); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate e->attr_count = 0; 3377c478bd9Sstevel@tonic-gate if (__s_add_attrlist(e, "objectClass", objclass) != NS_LDAP_SUCCESS) { 3387c478bd9Sstevel@tonic-gate free(e->attr_pair); 3397c478bd9Sstevel@tonic-gate free(e); 3407c478bd9Sstevel@tonic-gate return (NULL); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate return (e); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate static void 3467c478bd9Sstevel@tonic-gate ldap_freeEntry(ns_ldap_entry_t *ep) 3477c478bd9Sstevel@tonic-gate { 3487c478bd9Sstevel@tonic-gate int j, k = 0; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate if (ep == NULL) 3517c478bd9Sstevel@tonic-gate return; 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate if (ep->attr_pair == NULL) { 3547c478bd9Sstevel@tonic-gate free(ep); 3557c478bd9Sstevel@tonic-gate return; 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate for (j = 0; j < ep->attr_count; j++) { 3587c478bd9Sstevel@tonic-gate if (ep->attr_pair[j] == NULL) 3597c478bd9Sstevel@tonic-gate continue; 3607c478bd9Sstevel@tonic-gate if (ep->attr_pair[j]->attrname) 3617c478bd9Sstevel@tonic-gate free(ep->attr_pair[j]->attrname); 3627c478bd9Sstevel@tonic-gate if (ep->attr_pair[j]->attrvalue) { 3637c478bd9Sstevel@tonic-gate for (k = 0; (k < ep->attr_pair[j]->value_count) && 3647c478bd9Sstevel@tonic-gate (ep->attr_pair[j]->attrvalue[k]); k++) { 3657c478bd9Sstevel@tonic-gate free(ep->attr_pair[j]->attrvalue[k]); 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate free(ep->attr_pair[j]->attrvalue); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate free(ep->attr_pair[j]); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate free(ep->attr_pair); 3727c478bd9Sstevel@tonic-gate free(ep); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate static int 3767c478bd9Sstevel@tonic-gate addentry(void *entry, int mod) 3777c478bd9Sstevel@tonic-gate { 3787c478bd9Sstevel@tonic-gate int result = 0; 3797c478bd9Sstevel@tonic-gate ns_ldap_error_t *eres = NULL; 3807c478bd9Sstevel@tonic-gate int rc = 1; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate /* adds entry into the LDAP tree */ 3847c478bd9Sstevel@tonic-gate if (mod) 3857c478bd9Sstevel@tonic-gate result = __ns_ldap_addTypedEntry(databasetype, inputbasedn, 3867c478bd9Sstevel@tonic-gate entry, 0, &authority, NS_LDAP_FOLLOWREF, &eres); 3877c478bd9Sstevel@tonic-gate else 3887c478bd9Sstevel@tonic-gate result = __ns_ldap_addTypedEntry(databasetype, inputbasedn, 3897c478bd9Sstevel@tonic-gate entry, 1, &authority, NS_LDAP_FOLLOWREF, &eres); 3907c478bd9Sstevel@tonic-gate /* 3917c478bd9Sstevel@tonic-gate * Return 0 on success 3927c478bd9Sstevel@tonic-gate * LDAP_ALREADY_EXISTS if entry exists already 3937c478bd9Sstevel@tonic-gate * 1 for all other non-fatal errors. 3947c478bd9Sstevel@tonic-gate * Exit on fatal errors. 3957c478bd9Sstevel@tonic-gate */ 3967c478bd9Sstevel@tonic-gate switch (result) { 3977c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 3987c478bd9Sstevel@tonic-gate nent_add++; 3997c478bd9Sstevel@tonic-gate rc = 0; 4007c478bd9Sstevel@tonic-gate break; 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate case NS_LDAP_OP_FAILED: 4037c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("operation failed.\n")); 4047c478bd9Sstevel@tonic-gate rc = 1; 4057c478bd9Sstevel@tonic-gate break; 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate case NS_LDAP_INVALID_PARAM: 4087c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 4097c478bd9Sstevel@tonic-gate gettext("invalid parameter(s) passed.\n")); 4107c478bd9Sstevel@tonic-gate rc = 1; 4117c478bd9Sstevel@tonic-gate break; 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 4147c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("entry not found.\n")); 4157c478bd9Sstevel@tonic-gate rc = 1; 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate case NS_LDAP_MEMORY: 4197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 4207c478bd9Sstevel@tonic-gate gettext("internal memory allocation error.\n")); 4217c478bd9Sstevel@tonic-gate exit(1); 4227c478bd9Sstevel@tonic-gate break; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate case NS_LDAP_CONFIG: 4257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 4267c478bd9Sstevel@tonic-gate gettext("LDAP Configuration problem.\n")); 4277c478bd9Sstevel@tonic-gate perr(eres); 4287c478bd9Sstevel@tonic-gate exit(1); 4297c478bd9Sstevel@tonic-gate break; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate case NS_LDAP_PARTIAL: 4327c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 4337c478bd9Sstevel@tonic-gate gettext("partial result returned\n")); 4347c478bd9Sstevel@tonic-gate perr(eres); 4357c478bd9Sstevel@tonic-gate rc = 1; 4367c478bd9Sstevel@tonic-gate break; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate case NS_LDAP_INTERNAL: 439*12fbe00aSjs if (eres->status == LDAP_ALREADY_EXISTS || 440*12fbe00aSjs eres->status == LDAP_NO_SUCH_OBJECT) 4417c478bd9Sstevel@tonic-gate rc = eres->status; 4427c478bd9Sstevel@tonic-gate else { 4437c478bd9Sstevel@tonic-gate rc = 1; 4447c478bd9Sstevel@tonic-gate perr(eres); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate break; 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate if (eres) 4507c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(&eres); 4517c478bd9Sstevel@tonic-gate return (rc); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate /* 4567c478bd9Sstevel@tonic-gate * usage(char *msg) 4577c478bd9Sstevel@tonic-gate * Display usage message to STDERR. 4587c478bd9Sstevel@tonic-gate */ 4597c478bd9Sstevel@tonic-gate static void 4607c478bd9Sstevel@tonic-gate usage(char *msg) { 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate if (msg) 4637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s\n"), msg); 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 4667c478bd9Sstevel@tonic-gate "usage: ldapaddent [ -cpv ] [ -a authenticationMethod ]\n" 4677c478bd9Sstevel@tonic-gate "[ -b baseDN ] -D bindDN -w bind_password [ -f file ] database\n\n" 4687c478bd9Sstevel@tonic-gate "usage: ldapaddent -d [ -cpv ] [ -a authenticationMethod ]\n" 4697c478bd9Sstevel@tonic-gate "[ -b baseDN ] [ -D bindDN ] [ -w bind_password ] database\n")); 4707c478bd9Sstevel@tonic-gate exit(1); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate /* 4747c478bd9Sstevel@tonic-gate * Determine if the given string is an IP address (IPv4 or IPv6). 4757c478bd9Sstevel@tonic-gate * If so, it's converted to the preferred form (rfc2373) and 4767c478bd9Sstevel@tonic-gate * *newaddr will point to the new address. 4777c478bd9Sstevel@tonic-gate * 4787c478bd9Sstevel@tonic-gate * Returns -2 : inet_ntop error 4797c478bd9Sstevel@tonic-gate * -1 : not an IP address 4807c478bd9Sstevel@tonic-gate * 0 : unsupported IP address (future use) 4817c478bd9Sstevel@tonic-gate * AF_INET : IPv4 4827c478bd9Sstevel@tonic-gate * AF_INET6 : IPv6 4837c478bd9Sstevel@tonic-gate */ 4847c478bd9Sstevel@tonic-gate static int 4857c478bd9Sstevel@tonic-gate check_ipaddr(char *addr, char **newaddr) { 4867c478bd9Sstevel@tonic-gate ipaddr_t addr_ipv4 = 0; 4877c478bd9Sstevel@tonic-gate in6_addr_t addr_ipv6; 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate /* IPv6 */ 4907c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET6, addr, &addr_ipv6) == 1) { 4917c478bd9Sstevel@tonic-gate if (newaddr == NULL) 4927c478bd9Sstevel@tonic-gate return (AF_INET6); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* Convert IPv4-mapped IPv6 address to IPv4 */ 4957c478bd9Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(&addr_ipv6) || 4967c478bd9Sstevel@tonic-gate IN6_IS_ADDR_V4COMPAT(&addr_ipv6)) { 4977c478bd9Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&addr_ipv6, addr_ipv4); 4987c478bd9Sstevel@tonic-gate if ((*newaddr = calloc(1, INET_ADDRSTRLEN)) == NULL) { 4997c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 5007c478bd9Sstevel@tonic-gate gettext("out of memory\n")); 5017c478bd9Sstevel@tonic-gate exit(1); 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate if (inet_ntop(AF_INET, &addr_ipv4, *newaddr, 5047c478bd9Sstevel@tonic-gate INET_ADDRSTRLEN)) 5057c478bd9Sstevel@tonic-gate return (AF_INET6); 5067c478bd9Sstevel@tonic-gate free(*newaddr); 5077c478bd9Sstevel@tonic-gate return (-2); 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* Processing general IPv6 addresses */ 5117c478bd9Sstevel@tonic-gate if ((*newaddr = calloc(1, INET6_ADDRSTRLEN)) == NULL) { 5127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 5137c478bd9Sstevel@tonic-gate exit(1); 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate if (inet_ntop(AF_INET6, &addr_ipv6, *newaddr, INET6_ADDRSTRLEN)) 5167c478bd9Sstevel@tonic-gate return (AF_INET6); 5177c478bd9Sstevel@tonic-gate free(*newaddr); 5187c478bd9Sstevel@tonic-gate return (-2); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* Processing IPv4 addresses of the type d.d.d.d. */ 5227c478bd9Sstevel@tonic-gate if (inet_pton(AF_INET, addr, &addr_ipv4) == 1) { 5237c478bd9Sstevel@tonic-gate if (newaddr == NULL) 5247c478bd9Sstevel@tonic-gate return (AF_INET); 5257c478bd9Sstevel@tonic-gate if ((*newaddr = calloc(1, INET_ADDRSTRLEN)) == NULL) { 5267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 5277c478bd9Sstevel@tonic-gate exit(1); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate if (inet_ntop(AF_INET, &addr_ipv4, *newaddr, INET_ADDRSTRLEN)) 5307c478bd9Sstevel@tonic-gate return (AF_INET); 5317c478bd9Sstevel@tonic-gate free(*newaddr); 5327c478bd9Sstevel@tonic-gate return (-2); 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate /* Processing IPv4 addresses d.d.d , d.d and d */ 5367c478bd9Sstevel@tonic-gate if (inet_addr(addr) != (in_addr_t)-1) { 5377c478bd9Sstevel@tonic-gate if (newaddr == NULL) 5387c478bd9Sstevel@tonic-gate return (AF_INET); 5397c478bd9Sstevel@tonic-gate if ((*newaddr = strdup(addr)) == NULL) { 5407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 5417c478bd9Sstevel@tonic-gate exit(1); 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate return (AF_INET); 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate return (-1); 5477c478bd9Sstevel@tonic-gate } 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate static int 5507c478bd9Sstevel@tonic-gate genent_hosts(char *line, int (*cback)()) 5517c478bd9Sstevel@tonic-gate { 5527c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 5537c478bd9Sstevel@tonic-gate char *t; 5547c478bd9Sstevel@tonic-gate entry_col ecol[4]; 5557c478bd9Sstevel@tonic-gate char *cname, *pref_addr; 5567c478bd9Sstevel@tonic-gate int ctr = 0, retval = 1; 5577c478bd9Sstevel@tonic-gate int rc = GENENT_OK, af; 5587c478bd9Sstevel@tonic-gate 5597c478bd9Sstevel@tonic-gate struct hostent data; 5607c478bd9Sstevel@tonic-gate char *alias; 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate /* 5637c478bd9Sstevel@tonic-gate * don't clobber our argument 5647c478bd9Sstevel@tonic-gate */ 5657c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 5667c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 5677c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate /* 5727c478bd9Sstevel@tonic-gate * clear column data 5737c478bd9Sstevel@tonic-gate */ 5747c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate /* 5777c478bd9Sstevel@tonic-gate * comment (col 3) 5787c478bd9Sstevel@tonic-gate */ 5797c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 5807c478bd9Sstevel@tonic-gate if (t) { 5817c478bd9Sstevel@tonic-gate *t++ = 0; 5827c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 5837c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 5847c478bd9Sstevel@tonic-gate } else { 5857c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = ""; 5867c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate /* 5917c478bd9Sstevel@tonic-gate * addr(col 2) 5927c478bd9Sstevel@tonic-gate */ 5937c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 5947c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no host"); 5957c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate af = check_ipaddr(t, &pref_addr); 5997c478bd9Sstevel@tonic-gate if (af == -2) { 6007c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Internal error"); 6017c478bd9Sstevel@tonic-gate } else if (af == -1) { 6027c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 6037c478bd9Sstevel@tonic-gate "Invalid IP address: %s", t); 6047c478bd9Sstevel@tonic-gate } else if (flags & F_VERBOSE) { 6057c478bd9Sstevel@tonic-gate if ((strncasecmp(t, pref_addr, strlen(t))) != 0) { 6067c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 6077c478bd9Sstevel@tonic-gate gettext("IP address %s converted to %s\n"), 6087c478bd9Sstevel@tonic-gate t, pref_addr); 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate } 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate if (af < 0) { 6137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s\n"), parse_err_msg); 6147c478bd9Sstevel@tonic-gate if (continue_onerror == 0) 6157c478bd9Sstevel@tonic-gate return (GENENT_CBERR); 6167c478bd9Sstevel@tonic-gate else 6177c478bd9Sstevel@tonic-gate return (rc); 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = pref_addr; 6217c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(pref_addr)+1; 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate /* 6247c478bd9Sstevel@tonic-gate * cname (col 0) 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 6277c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no cname"); 6287c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 6317c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 6327c478bd9Sstevel@tonic-gate cname = t; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate /* build entry */ 6367c478bd9Sstevel@tonic-gate if ((data.h_addr_list = (char **)calloc(2, sizeof (char **))) == NULL) { 6377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 6387c478bd9Sstevel@tonic-gate exit(1); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate data.h_addr_list[0] = strdup(ecol[2].ec_value.ec_value_val); 6417c478bd9Sstevel@tonic-gate data.h_addr_list[1] = NULL; 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate free(pref_addr); 6447c478bd9Sstevel@tonic-gate data.h_name = strdup(ecol[0].ec_value.ec_value_val); 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* 6477c478bd9Sstevel@tonic-gate * name (col 1) 6487c478bd9Sstevel@tonic-gate */ 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate data.h_aliases = NULL; 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate do { 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 6557c478bd9Sstevel@tonic-gate */ 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate /* This call to AddEntry may move out of the loop */ 6587c478bd9Sstevel@tonic-gate /* This is because we have to call the function just once */ 6597c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 6607c478bd9Sstevel@tonic-gate continue; 6617c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 6627c478bd9Sstevel@tonic-gate continue; 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 6657c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate ctr++; 6687c478bd9Sstevel@tonic-gate alias = strdup(ecol[1].ec_value.ec_value_val); 6697c478bd9Sstevel@tonic-gate if ((data.h_aliases = (char **)realloc(data.h_aliases, 6707c478bd9Sstevel@tonic-gate ctr * sizeof (char **))) == NULL) { 6717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 6727c478bd9Sstevel@tonic-gate exit(1); 6737c478bd9Sstevel@tonic-gate } 6747c478bd9Sstevel@tonic-gate data.h_aliases[ctr-1] = alias; 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /* 6777c478bd9Sstevel@tonic-gate * only put comment in canonical entry 6787c478bd9Sstevel@tonic-gate */ 6797c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 6807c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, " \t")); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 6857c478bd9Sstevel@tonic-gate if ((data.h_aliases = (char **)realloc(data.h_aliases, 6867c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 6877c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 6887c478bd9Sstevel@tonic-gate exit(1); 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate data.h_aliases[ctr] = NULL; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 6937c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 6947c478bd9Sstevel@tonic-gate gettext("Adding entry : cn=%s+ipHostNumber=%s\n"), 6957c478bd9Sstevel@tonic-gate data.h_name, data.h_addr_list[0]); 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 7007c478bd9Sstevel@tonic-gate if (continue_onerror) 7017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 7027c478bd9Sstevel@tonic-gate gettext("Entry: cn=%s+ipHostNumber=%s " 7037c478bd9Sstevel@tonic-gate "already Exists -skipping it\n"), 7047c478bd9Sstevel@tonic-gate data.h_name, data.h_addr_list[0]); 7057c478bd9Sstevel@tonic-gate else { 7067c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 7077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 7087c478bd9Sstevel@tonic-gate gettext("Entry: cn=%s+ipHostNumber=%s" 7097c478bd9Sstevel@tonic-gate " already Exists\n"), 7107c478bd9Sstevel@tonic-gate data.h_name, data.h_addr_list[0]); 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } else if (retval) 7137c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate free(data.h_name); 7167c478bd9Sstevel@tonic-gate free(data.h_aliases); 7177c478bd9Sstevel@tonic-gate free(data.h_addr_list); 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate return (rc); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate static void 7257c478bd9Sstevel@tonic-gate dump_hosts(ns_ldap_result_t *res) 7267c478bd9Sstevel@tonic-gate { 7277c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr = NULL, *cn = NULL, *iphostnumber = NULL; 7287c478bd9Sstevel@tonic-gate int i, j; 7297c478bd9Sstevel@tonic-gate char *name; /* host name */ 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate if (res == NULL || res->entry == NULL) 7327c478bd9Sstevel@tonic-gate return; 7337c478bd9Sstevel@tonic-gate for (i = 0; i < res->entry->attr_count; i++) { 7347c478bd9Sstevel@tonic-gate attrptr = res->entry->attr_pair[i]; 7357c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, "cn") == 0) 7367c478bd9Sstevel@tonic-gate cn = attrptr; 7377c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, "iphostnumber") == 0) 7387c478bd9Sstevel@tonic-gate iphostnumber = attrptr; 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate /* sanity check */ 7417c478bd9Sstevel@tonic-gate if (cn == NULL || cn->attrvalue == NULL || cn->attrvalue[0] == NULL || 7427c478bd9Sstevel@tonic-gate iphostnumber == NULL || iphostnumber->attrvalue == NULL || 7437c478bd9Sstevel@tonic-gate iphostnumber->attrvalue[0] == NULL) 7447c478bd9Sstevel@tonic-gate return; 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate if ((name = __s_api_get_canonical_name(res->entry, cn, 1)) == NULL) 7477c478bd9Sstevel@tonic-gate return; 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate /* ip host/ipnode number */ 7507c478bd9Sstevel@tonic-gate if (strlen(iphostnumber->attrvalue[0]) <= INET_ADDRSTRLEN) 7517c478bd9Sstevel@tonic-gate /* IPV4 or IPV6 but <= NET_ADDRSTRLEN */ 7527c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-18s", iphostnumber->attrvalue[0]); 7537c478bd9Sstevel@tonic-gate else 7547c478bd9Sstevel@tonic-gate /* IPV6 */ 7557c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-48s", iphostnumber->attrvalue[0]); 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate /* host/ipnode name */ 7587c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", name); 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate /* aliases */ 7617c478bd9Sstevel@tonic-gate for (j = 0; j < cn->value_count; j++) { 7627c478bd9Sstevel@tonic-gate if (cn->attrvalue[j]) { 7637c478bd9Sstevel@tonic-gate if (strcasecmp(name, cn->attrvalue[j]) == 0) 7647c478bd9Sstevel@tonic-gate /* skip host name */ 7657c478bd9Sstevel@tonic-gate continue; 7667c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", cn->attrvalue[j]); 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate /* end of line */ 7717c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * /etc/rpc 7767c478bd9Sstevel@tonic-gate */ 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate static int 7797c478bd9Sstevel@tonic-gate genent_rpc(char *line, int (*cback)()) 7807c478bd9Sstevel@tonic-gate { 7817c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 7827c478bd9Sstevel@tonic-gate char *t; 7837c478bd9Sstevel@tonic-gate entry_col ecol[4]; 7847c478bd9Sstevel@tonic-gate char *cname; 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate struct rpcent data; 7877c478bd9Sstevel@tonic-gate char *alias; 7887c478bd9Sstevel@tonic-gate int ctr = 0; 7897c478bd9Sstevel@tonic-gate int retval = 1; 7907c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate /* 7937c478bd9Sstevel@tonic-gate * don't clobber our argument 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 7967c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 7977c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 7987c478bd9Sstevel@tonic-gate } 7997c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate /* 8027c478bd9Sstevel@tonic-gate * clear column data 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate /* 8077c478bd9Sstevel@tonic-gate * comment (col 3) 8087c478bd9Sstevel@tonic-gate */ 8097c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 8107c478bd9Sstevel@tonic-gate if (t) { 8117c478bd9Sstevel@tonic-gate *t++ = 0; 8127c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 8137c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 8147c478bd9Sstevel@tonic-gate } else { 8157c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 8167c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 8177c478bd9Sstevel@tonic-gate } 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate /* 8207c478bd9Sstevel@tonic-gate * cname(col 0) 8217c478bd9Sstevel@tonic-gate */ 8227c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 8237c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 8247c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 8277c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 8287c478bd9Sstevel@tonic-gate cname = t; 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate /* 8317c478bd9Sstevel@tonic-gate * number (col 2) 8327c478bd9Sstevel@tonic-gate */ 8337c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 8347c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 8357c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 8367c478bd9Sstevel@tonic-gate } 8377c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 8387c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate /* 8427c478bd9Sstevel@tonic-gate * build entry 8437c478bd9Sstevel@tonic-gate */ 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate data.r_name = strdup(ecol[0].ec_value.ec_value_val); 8467c478bd9Sstevel@tonic-gate if (ecol[2].ec_value.ec_value_val != NULL && 8477c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val[0] != '\0') { 8487c478bd9Sstevel@tonic-gate 8497c478bd9Sstevel@tonic-gate data.r_number = ascii_to_int(ecol[2].ec_value.ec_value_val); 8507c478bd9Sstevel@tonic-gate if (data.r_number == -1) { 8517c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 8527c478bd9Sstevel@tonic-gate "invalid program number: %s", 8537c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val); 8547c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 8557c478bd9Sstevel@tonic-gate } 8567c478bd9Sstevel@tonic-gate } else 8577c478bd9Sstevel@tonic-gate data.r_number = -1; 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * name (col 1) 8617c478bd9Sstevel@tonic-gate */ 8627c478bd9Sstevel@tonic-gate t = cname; 8637c478bd9Sstevel@tonic-gate data.r_aliases = NULL; 8647c478bd9Sstevel@tonic-gate do { 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate /* 8677c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 8687c478bd9Sstevel@tonic-gate */ 8697c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 8707c478bd9Sstevel@tonic-gate continue; 8717c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 8727c478bd9Sstevel@tonic-gate continue; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 8757c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate ctr++; 8787c478bd9Sstevel@tonic-gate alias = strdup(ecol[1].ec_value.ec_value_val); 8797c478bd9Sstevel@tonic-gate if ((data.r_aliases = (char **)realloc(data.r_aliases, 8807c478bd9Sstevel@tonic-gate ctr * sizeof (char **))) == NULL) { 8817c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 8827c478bd9Sstevel@tonic-gate exit(1); 8837c478bd9Sstevel@tonic-gate } 8847c478bd9Sstevel@tonic-gate data.r_aliases[ctr-1] = alias; 8857c478bd9Sstevel@tonic-gate 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate /* 8887c478bd9Sstevel@tonic-gate * only put comment in canonical entry 8897c478bd9Sstevel@tonic-gate */ 8907c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 8917c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, " \t")); 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 8967c478bd9Sstevel@tonic-gate if ((data.r_aliases = (char **)realloc(data.r_aliases, 8977c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 8987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 8997c478bd9Sstevel@tonic-gate exit(1); 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate data.r_aliases[ctr] = NULL; 9027c478bd9Sstevel@tonic-gate 9037c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 9047c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 9057c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.r_name); 9067c478bd9Sstevel@tonic-gate 9077c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 9107c478bd9Sstevel@tonic-gate if (continue_onerror) 9117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 9127c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 9137c478bd9Sstevel@tonic-gate data.r_name); 9147c478bd9Sstevel@tonic-gate else { 9157c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 9167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 9177c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 9187c478bd9Sstevel@tonic-gate data.r_name); 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate } else if (retval) 9217c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate free(data.r_name); 9247c478bd9Sstevel@tonic-gate free(data.r_aliases); 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate return (rc); 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate static void 9327c478bd9Sstevel@tonic-gate dump_rpc(ns_ldap_result_t *res) 9337c478bd9Sstevel@tonic-gate { 9347c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr = NULL, *cn = NULL, *rpcnumber = NULL; 9357c478bd9Sstevel@tonic-gate int i, j; 9367c478bd9Sstevel@tonic-gate char *name; /* rpc name */ 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate if (res == NULL || res->entry == NULL) 9397c478bd9Sstevel@tonic-gate return; 9407c478bd9Sstevel@tonic-gate for (i = 0; i < res->entry->attr_count; i++) { 9417c478bd9Sstevel@tonic-gate attrptr = res->entry->attr_pair[i]; 9427c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, "cn") == 0) 9437c478bd9Sstevel@tonic-gate cn = attrptr; 9447c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, "oncRpcNumber") == 0) 9457c478bd9Sstevel@tonic-gate rpcnumber = attrptr; 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate /* sanity check */ 9487c478bd9Sstevel@tonic-gate if (cn == NULL || cn->attrvalue == NULL || cn->attrvalue[0] == NULL || 9497c478bd9Sstevel@tonic-gate rpcnumber == NULL || rpcnumber->attrvalue == NULL || 9507c478bd9Sstevel@tonic-gate rpcnumber->attrvalue[0] == NULL) 9517c478bd9Sstevel@tonic-gate return; 9527c478bd9Sstevel@tonic-gate 9537c478bd9Sstevel@tonic-gate if ((name = __s_api_get_canonical_name(res->entry, cn, 1)) == NULL) 9547c478bd9Sstevel@tonic-gate return; 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate /* rpc name */ 9577c478bd9Sstevel@tonic-gate if (strlen(name) < 8) 9587c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t\t", name); 9597c478bd9Sstevel@tonic-gate else 9607c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t", name); 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* rpc number */ 9637c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-8s", rpcnumber->attrvalue[0]); 9647c478bd9Sstevel@tonic-gate 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate /* aliases */ 9677c478bd9Sstevel@tonic-gate for (j = 0; j < cn->value_count; j++) { 9687c478bd9Sstevel@tonic-gate if (cn->attrvalue[j]) { 9697c478bd9Sstevel@tonic-gate if (strcasecmp(name, cn->attrvalue[j]) == 0) 9707c478bd9Sstevel@tonic-gate /* skip rpc name */ 9717c478bd9Sstevel@tonic-gate continue; 9727c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", cn->attrvalue[j]); 9737c478bd9Sstevel@tonic-gate } 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate /* end of line */ 9777c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate } 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * /etc/protocols 9837c478bd9Sstevel@tonic-gate * 9847c478bd9Sstevel@tonic-gate */ 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate static int 9877c478bd9Sstevel@tonic-gate genent_protocols(char *line, int (*cback)()) 9887c478bd9Sstevel@tonic-gate { 9897c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 9907c478bd9Sstevel@tonic-gate char *t; 9917c478bd9Sstevel@tonic-gate entry_col ecol[4]; 9927c478bd9Sstevel@tonic-gate char *cname; 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate struct protoent data; 9957c478bd9Sstevel@tonic-gate char *alias; 9967c478bd9Sstevel@tonic-gate int ctr = 0; 9977c478bd9Sstevel@tonic-gate int retval = 1; 9987c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate /* 10017c478bd9Sstevel@tonic-gate * don't clobber our argument 10027c478bd9Sstevel@tonic-gate */ 10037c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 10047c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 10057c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate /* 10107c478bd9Sstevel@tonic-gate * clear column data 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate /* 10157c478bd9Sstevel@tonic-gate * comment (col 3) 10167c478bd9Sstevel@tonic-gate */ 10177c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 10187c478bd9Sstevel@tonic-gate if (t) { 10197c478bd9Sstevel@tonic-gate *t++ = 0; 10207c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 10217c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 10227c478bd9Sstevel@tonic-gate } else { 10237c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 10247c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate /* 10287c478bd9Sstevel@tonic-gate * cname(col 0) 10297c478bd9Sstevel@tonic-gate */ 10307c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 10317c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 10327c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 10337c478bd9Sstevel@tonic-gate } 10347c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 10357c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 10367c478bd9Sstevel@tonic-gate cname = t; 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate /* 10397c478bd9Sstevel@tonic-gate * number (col 2) 10407c478bd9Sstevel@tonic-gate */ 10417c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 10427c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 10437c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 10467c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate 10497c478bd9Sstevel@tonic-gate /* 10507c478bd9Sstevel@tonic-gate * build entry 10517c478bd9Sstevel@tonic-gate */ 10527c478bd9Sstevel@tonic-gate data.p_name = strdup(ecol[0].ec_value.ec_value_val); 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate if (ecol[2].ec_value.ec_value_val != NULL && 10557c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val[0] != '\0') { 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate data.p_proto = ascii_to_int(ecol[2].ec_value.ec_value_val); 10587c478bd9Sstevel@tonic-gate if (data.p_proto == -1) { 10597c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 10607c478bd9Sstevel@tonic-gate "invalid protocol number: %s", 10617c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val); 10627c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 10637c478bd9Sstevel@tonic-gate } 10647c478bd9Sstevel@tonic-gate } else 10657c478bd9Sstevel@tonic-gate data.p_proto = -1; 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate /* 10687c478bd9Sstevel@tonic-gate * name (col 1) 10697c478bd9Sstevel@tonic-gate */ 10707c478bd9Sstevel@tonic-gate t = cname; 10717c478bd9Sstevel@tonic-gate ctr = 0; 10727c478bd9Sstevel@tonic-gate data.p_aliases = NULL; 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate do { 10757c478bd9Sstevel@tonic-gate /* 10767c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 10777c478bd9Sstevel@tonic-gate */ 10787c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 10797c478bd9Sstevel@tonic-gate continue; 10807c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 10817c478bd9Sstevel@tonic-gate continue; 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 10847c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate ctr++; 10877c478bd9Sstevel@tonic-gate alias = strdup(ecol[1].ec_value.ec_value_val); 10887c478bd9Sstevel@tonic-gate if ((data.p_aliases = (char **)realloc(data.p_aliases, 10897c478bd9Sstevel@tonic-gate ctr * sizeof (char **))) == NULL) { 10907c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 10917c478bd9Sstevel@tonic-gate exit(1); 10927c478bd9Sstevel@tonic-gate } 10937c478bd9Sstevel@tonic-gate data.p_aliases[ctr-1] = alias; 10947c478bd9Sstevel@tonic-gate 10957c478bd9Sstevel@tonic-gate /* 10967c478bd9Sstevel@tonic-gate * only put comment in canonical entry 10977c478bd9Sstevel@tonic-gate */ 10987c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 10997c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, " \t")); 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 11047c478bd9Sstevel@tonic-gate if ((data.p_aliases = (char **)realloc(data.p_aliases, 11057c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 11067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 11077c478bd9Sstevel@tonic-gate exit(1); 11087c478bd9Sstevel@tonic-gate } 11097c478bd9Sstevel@tonic-gate data.p_aliases[ctr] = NULL; 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 11127c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 11137c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.p_name); 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 11187c478bd9Sstevel@tonic-gate if (continue_onerror) 11197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 11207c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 11217c478bd9Sstevel@tonic-gate data.p_name); 11227c478bd9Sstevel@tonic-gate else { 11237c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 11247c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 11257c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 11267c478bd9Sstevel@tonic-gate data.p_name); 11277c478bd9Sstevel@tonic-gate } 11287c478bd9Sstevel@tonic-gate } else if (retval) 11297c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate free(data.p_name); 11327c478bd9Sstevel@tonic-gate free(data.p_aliases); 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate return (rc); 11357c478bd9Sstevel@tonic-gate } 11367c478bd9Sstevel@tonic-gate 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate static void 11397c478bd9Sstevel@tonic-gate dump_protocols(ns_ldap_result_t *res) 11407c478bd9Sstevel@tonic-gate { 11417c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr = NULL, *cn = NULL, *protocolnumber = NULL; 11427c478bd9Sstevel@tonic-gate int i, j; 11437c478bd9Sstevel@tonic-gate char *name, *cp; 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate if (res == NULL || res->entry == NULL) 11467c478bd9Sstevel@tonic-gate return; 11477c478bd9Sstevel@tonic-gate for (i = 0; i < res->entry->attr_count; i++) { 11487c478bd9Sstevel@tonic-gate attrptr = res->entry->attr_pair[i]; 11497c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, "cn") == 0) 11507c478bd9Sstevel@tonic-gate cn = attrptr; 11517c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, "ipProtocolNumber") 11527c478bd9Sstevel@tonic-gate == 0) 11537c478bd9Sstevel@tonic-gate protocolnumber = attrptr; 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate /* sanity check */ 11567c478bd9Sstevel@tonic-gate if (cn == NULL || cn->attrvalue == NULL || cn->attrvalue[0] == NULL || 11577c478bd9Sstevel@tonic-gate protocolnumber == NULL || protocolnumber->attrvalue == NULL || 11587c478bd9Sstevel@tonic-gate protocolnumber->attrvalue[0] == NULL) 11597c478bd9Sstevel@tonic-gate return; 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate if ((name = __s_api_get_canonical_name(res->entry, cn, 1)) == NULL) 11627c478bd9Sstevel@tonic-gate return; 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate /* protocol name */ 11657c478bd9Sstevel@tonic-gate if (strlen(name) < 8) 11667c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t\t", name); 11677c478bd9Sstevel@tonic-gate else 11687c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t", name); 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate /* protocol number */ 11717c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-16s", protocolnumber->attrvalue[0]); 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate /* aliases */ 11747c478bd9Sstevel@tonic-gate for (j = 0; j < cn->value_count; j++) { 11757c478bd9Sstevel@tonic-gate if (cn->attrvalue[j]) { 11767c478bd9Sstevel@tonic-gate if (strcasecmp(name, cn->attrvalue[j]) == 0) { 11777c478bd9Sstevel@tonic-gate if (cn->value_count > 1) 11787c478bd9Sstevel@tonic-gate /* Do not replicate */ 11797c478bd9Sstevel@tonic-gate continue; 11807c478bd9Sstevel@tonic-gate /* 11817c478bd9Sstevel@tonic-gate * Replicate name in uppercase as an aliase 11827c478bd9Sstevel@tonic-gate */ 11837c478bd9Sstevel@tonic-gate for (cp = cn->attrvalue[j]; *cp; cp++) 11847c478bd9Sstevel@tonic-gate *cp = toupper(*cp); 11857c478bd9Sstevel@tonic-gate } 11867c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", cn->attrvalue[j]); 11877c478bd9Sstevel@tonic-gate } 11887c478bd9Sstevel@tonic-gate } 11897c478bd9Sstevel@tonic-gate 11907c478bd9Sstevel@tonic-gate /* end of line */ 11917c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 11927c478bd9Sstevel@tonic-gate 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate 11987c478bd9Sstevel@tonic-gate 11997c478bd9Sstevel@tonic-gate /* 12007c478bd9Sstevel@tonic-gate * /etc/networks 12017c478bd9Sstevel@tonic-gate * 12027c478bd9Sstevel@tonic-gate */ 12037c478bd9Sstevel@tonic-gate 12047c478bd9Sstevel@tonic-gate static int 12057c478bd9Sstevel@tonic-gate genent_networks(char *line, int (*cback)()) 12067c478bd9Sstevel@tonic-gate { 12077c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 12087c478bd9Sstevel@tonic-gate char *t; 12097c478bd9Sstevel@tonic-gate entry_col ecol[4]; 12107c478bd9Sstevel@tonic-gate char *cname; 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate struct netent data; 12137c478bd9Sstevel@tonic-gate char *alias; 12147c478bd9Sstevel@tonic-gate int ctr = 0; 12157c478bd9Sstevel@tonic-gate int retval = 1; 12167c478bd9Sstevel@tonic-gate int enet; 12177c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 12187c478bd9Sstevel@tonic-gate 12197c478bd9Sstevel@tonic-gate /* 12207c478bd9Sstevel@tonic-gate * don't clobber our argument 12217c478bd9Sstevel@tonic-gate */ 12227c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 12237c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 12247c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 12257c478bd9Sstevel@tonic-gate } 12267c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate /* 12297c478bd9Sstevel@tonic-gate * clear column data 12307c478bd9Sstevel@tonic-gate */ 12317c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate /* 12347c478bd9Sstevel@tonic-gate * comment (col 3) 12357c478bd9Sstevel@tonic-gate */ 12367c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 12377c478bd9Sstevel@tonic-gate if (t) { 12387c478bd9Sstevel@tonic-gate *t++ = 0; 12397c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 12407c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 12417c478bd9Sstevel@tonic-gate } else { 12427c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 12437c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 12447c478bd9Sstevel@tonic-gate } 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate /* 12477c478bd9Sstevel@tonic-gate * cname(col 0) 12487c478bd9Sstevel@tonic-gate */ 12497c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 12507c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 12517c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 12527c478bd9Sstevel@tonic-gate } 12537c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 12547c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 12557c478bd9Sstevel@tonic-gate cname = t; 12567c478bd9Sstevel@tonic-gate 12577c478bd9Sstevel@tonic-gate /* 12587c478bd9Sstevel@tonic-gate * number (col 2) 12597c478bd9Sstevel@tonic-gate */ 12607c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 12617c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no number"); 12627c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 12657c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 12667c478bd9Sstevel@tonic-gate 12677c478bd9Sstevel@tonic-gate 12687c478bd9Sstevel@tonic-gate /* 12697c478bd9Sstevel@tonic-gate * build entry 12707c478bd9Sstevel@tonic-gate */ 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate data.n_name = strdup(ecol[0].ec_value.ec_value_val); 12737c478bd9Sstevel@tonic-gate /* 12747c478bd9Sstevel@tonic-gate * data.n_net is an unsigned field, 12757c478bd9Sstevel@tonic-gate * assign -1 to it, make no sense. 12767c478bd9Sstevel@tonic-gate * Use enet here to avoid lint warning. 12777c478bd9Sstevel@tonic-gate */ 12787c478bd9Sstevel@tonic-gate enet = encode_network(ecol[2].ec_value.ec_value_val); 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate if (enet == -1 && continue_onerror == 0) { 12817c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Invalid network number\n")); 12827c478bd9Sstevel@tonic-gate if (continue_onerror == 0) 12837c478bd9Sstevel@tonic-gate return (GENENT_CBERR); 12847c478bd9Sstevel@tonic-gate } else 12857c478bd9Sstevel@tonic-gate data.n_net = enet; 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate /* 12887c478bd9Sstevel@tonic-gate * name (col 1) 12897c478bd9Sstevel@tonic-gate */ 12907c478bd9Sstevel@tonic-gate t = cname; 12917c478bd9Sstevel@tonic-gate data.n_aliases = NULL; 12927c478bd9Sstevel@tonic-gate 12937c478bd9Sstevel@tonic-gate do { 12947c478bd9Sstevel@tonic-gate /* 12957c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 12967c478bd9Sstevel@tonic-gate */ 12977c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 12987c478bd9Sstevel@tonic-gate continue; 12997c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 13007c478bd9Sstevel@tonic-gate continue; 13017c478bd9Sstevel@tonic-gate 13027c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 13037c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate ctr++; 13067c478bd9Sstevel@tonic-gate alias = strdup(ecol[1].ec_value.ec_value_val); 13077c478bd9Sstevel@tonic-gate if ((data.n_aliases = (char **)realloc(data.n_aliases, 13087c478bd9Sstevel@tonic-gate ctr * sizeof (char **))) == NULL) { 13097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 13107c478bd9Sstevel@tonic-gate exit(1); 13117c478bd9Sstevel@tonic-gate } 13127c478bd9Sstevel@tonic-gate data.n_aliases[ctr-1] = alias; 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate /* 13157c478bd9Sstevel@tonic-gate * only put comment in canonical entry 13167c478bd9Sstevel@tonic-gate */ 13177c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = 0; 13187c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 13197c478bd9Sstevel@tonic-gate 13207c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, " \t")); 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 13237c478bd9Sstevel@tonic-gate if ((data.n_aliases = (char **)realloc(data.n_aliases, 13247c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 13257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 13267c478bd9Sstevel@tonic-gate exit(1); 13277c478bd9Sstevel@tonic-gate } 13287c478bd9Sstevel@tonic-gate data.n_aliases[ctr] = NULL; 13297c478bd9Sstevel@tonic-gate 13307c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 13317c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 13327c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.n_name); 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 13357c478bd9Sstevel@tonic-gate 13367c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 13377c478bd9Sstevel@tonic-gate if (continue_onerror) 13387c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13397c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 13407c478bd9Sstevel@tonic-gate data.n_name); 13417c478bd9Sstevel@tonic-gate else { 13427c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 13437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 13447c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 13457c478bd9Sstevel@tonic-gate data.n_name); 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate } else if (retval) 13487c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 13497c478bd9Sstevel@tonic-gate 13507c478bd9Sstevel@tonic-gate free(data.n_name); 13517c478bd9Sstevel@tonic-gate free(data.n_aliases); 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate return (rc); 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate static void 13587c478bd9Sstevel@tonic-gate dump_networks(ns_ldap_result_t *res) 13597c478bd9Sstevel@tonic-gate { 13607c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr = NULL, *cn = NULL, *networknumber = NULL; 13617c478bd9Sstevel@tonic-gate int i, j; 13627c478bd9Sstevel@tonic-gate char *name; 13637c478bd9Sstevel@tonic-gate 13647c478bd9Sstevel@tonic-gate if (res == NULL || res->entry == NULL) 13657c478bd9Sstevel@tonic-gate return; 13667c478bd9Sstevel@tonic-gate for (i = 0; i < res->entry->attr_count; i++) { 13677c478bd9Sstevel@tonic-gate attrptr = res->entry->attr_pair[i]; 13687c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, "cn") == 0) 13697c478bd9Sstevel@tonic-gate cn = attrptr; 13707c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, "ipNetworkNumber") 13717c478bd9Sstevel@tonic-gate == 0) 13727c478bd9Sstevel@tonic-gate networknumber = attrptr; 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate /* sanity check */ 13757c478bd9Sstevel@tonic-gate if (cn == NULL || cn->attrvalue == NULL || cn->attrvalue[0] == NULL || 13767c478bd9Sstevel@tonic-gate networknumber == NULL || networknumber->attrvalue == NULL || 13777c478bd9Sstevel@tonic-gate networknumber->attrvalue[0] == NULL) 13787c478bd9Sstevel@tonic-gate return; 13797c478bd9Sstevel@tonic-gate 13807c478bd9Sstevel@tonic-gate /* 13817c478bd9Sstevel@tonic-gate * cn can be a MUST attribute(RFC 2307) or MAY attribute(2307bis). 13827c478bd9Sstevel@tonic-gate * If the canonical name can not be found (2307bis), use the 1st 13837c478bd9Sstevel@tonic-gate * value as the official name. 13847c478bd9Sstevel@tonic-gate */ 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate /* network name */ 13877c478bd9Sstevel@tonic-gate if ((name = __s_api_get_canonical_name(res->entry, cn, 1)) == NULL) 13887c478bd9Sstevel@tonic-gate name = cn->attrvalue[0]; 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate if (strlen(name) < 8) 13917c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t\t", name); 13927c478bd9Sstevel@tonic-gate else 13937c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\t", name); 13947c478bd9Sstevel@tonic-gate 13957c478bd9Sstevel@tonic-gate /* network number */ 13967c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-16s", networknumber->attrvalue[0]); 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate /* aliases */ 13997c478bd9Sstevel@tonic-gate for (j = 0; j < cn->value_count; j++) { 14007c478bd9Sstevel@tonic-gate if (cn->attrvalue[j]) { 14017c478bd9Sstevel@tonic-gate if (strcasecmp(name, cn->attrvalue[j]) == 0) 14027c478bd9Sstevel@tonic-gate /* skip name */ 14037c478bd9Sstevel@tonic-gate continue; 14047c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", cn->attrvalue[j]); 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate } 14077c478bd9Sstevel@tonic-gate 14087c478bd9Sstevel@tonic-gate /* end of line */ 14097c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 14107c478bd9Sstevel@tonic-gate 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate 14167c478bd9Sstevel@tonic-gate /* 14177c478bd9Sstevel@tonic-gate * /etc/services 14187c478bd9Sstevel@tonic-gate * 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate static int 14227c478bd9Sstevel@tonic-gate genent_services(char *line, int (*cback)()) 14237c478bd9Sstevel@tonic-gate { 14247c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 14257c478bd9Sstevel@tonic-gate char *t, *p; 14267c478bd9Sstevel@tonic-gate entry_col ecol[5]; 14277c478bd9Sstevel@tonic-gate char *cname; 14287c478bd9Sstevel@tonic-gate 14297c478bd9Sstevel@tonic-gate struct servent data; 14307c478bd9Sstevel@tonic-gate char *alias; 14317c478bd9Sstevel@tonic-gate int ctr = 0; 14327c478bd9Sstevel@tonic-gate int retval = 1; 14337c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate /* 14367c478bd9Sstevel@tonic-gate * don't clobber our argument 14377c478bd9Sstevel@tonic-gate */ 14387c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 14397c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 14407c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate /* 14457c478bd9Sstevel@tonic-gate * clear column data 14467c478bd9Sstevel@tonic-gate */ 14477c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate /* 14507c478bd9Sstevel@tonic-gate * comment (col 4) 14517c478bd9Sstevel@tonic-gate */ 14527c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 14537c478bd9Sstevel@tonic-gate if (t) { 14547c478bd9Sstevel@tonic-gate *t++ = 0; 14557c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val = t; 14567c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_len = strlen(t)+1; 14577c478bd9Sstevel@tonic-gate } else { 14587c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val = 0; 14597c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_len = 0; 14607c478bd9Sstevel@tonic-gate } 14617c478bd9Sstevel@tonic-gate 14627c478bd9Sstevel@tonic-gate /* 14637c478bd9Sstevel@tonic-gate * cname(col 0) 14647c478bd9Sstevel@tonic-gate */ 14657c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 14667c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no port"); 14677c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 14687c478bd9Sstevel@tonic-gate } 14697c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 14707c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 14717c478bd9Sstevel@tonic-gate cname = t; 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate /* 14747c478bd9Sstevel@tonic-gate * port (col 3) 14757c478bd9Sstevel@tonic-gate */ 14767c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 14777c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no protocol"); 14787c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate if ((p = strchr(t, '/')) == 0) { 14817c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "bad port/proto"); 14827c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 14837c478bd9Sstevel@tonic-gate } 14847c478bd9Sstevel@tonic-gate *(p++) = 0; 14857c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 14867c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate /* 14897c478bd9Sstevel@tonic-gate * proto (col 2) 14907c478bd9Sstevel@tonic-gate */ 14917c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = p; 14927c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(p)+1; 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate /* 14967c478bd9Sstevel@tonic-gate * build entry 14977c478bd9Sstevel@tonic-gate */ 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate data.s_name = strdup(ecol[0].ec_value.ec_value_val); 15007c478bd9Sstevel@tonic-gate data.s_proto = strdup(ecol[2].ec_value.ec_value_val); 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate if (ecol[3].ec_value.ec_value_val != NULL && 15037c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val[0] != '\0') { 15047c478bd9Sstevel@tonic-gate 15057c478bd9Sstevel@tonic-gate data.s_port = ascii_to_int(ecol[3].ec_value.ec_value_val); 15067c478bd9Sstevel@tonic-gate if (data.s_port == -1) { 15077c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 15087c478bd9Sstevel@tonic-gate "invalid port number: %s", 15097c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val); 15107c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 15117c478bd9Sstevel@tonic-gate } 15127c478bd9Sstevel@tonic-gate } else 15137c478bd9Sstevel@tonic-gate data.s_port = -1; 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate /* 15167c478bd9Sstevel@tonic-gate * name (col 1) 15177c478bd9Sstevel@tonic-gate */ 15187c478bd9Sstevel@tonic-gate t = cname; 15197c478bd9Sstevel@tonic-gate data.s_aliases = NULL; 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate do { 15227c478bd9Sstevel@tonic-gate /* 15237c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 15247c478bd9Sstevel@tonic-gate */ 15257c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 15267c478bd9Sstevel@tonic-gate continue; 15277c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 15287c478bd9Sstevel@tonic-gate continue; 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 15317c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 15327c478bd9Sstevel@tonic-gate 15337c478bd9Sstevel@tonic-gate ctr++; 15347c478bd9Sstevel@tonic-gate alias = strdup(ecol[1].ec_value.ec_value_val); 15357c478bd9Sstevel@tonic-gate if ((data.s_aliases = (char **)realloc(data.s_aliases, 15367c478bd9Sstevel@tonic-gate ctr * sizeof (char **))) == NULL) { 15377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 15387c478bd9Sstevel@tonic-gate exit(1); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate data.s_aliases[ctr-1] = alias; 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate /* 15437c478bd9Sstevel@tonic-gate * only put comment in canonical entry 15447c478bd9Sstevel@tonic-gate */ 15457c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val = 0; 15467c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_len = 0; 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, " \t")); 15497c478bd9Sstevel@tonic-gate 15507c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 15517c478bd9Sstevel@tonic-gate if ((data.s_aliases = (char **)realloc(data.s_aliases, 15527c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 15537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 15547c478bd9Sstevel@tonic-gate exit(1); 15557c478bd9Sstevel@tonic-gate } 15567c478bd9Sstevel@tonic-gate data.s_aliases[ctr] = NULL; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 15597c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 15607c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), line); 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 15657c478bd9Sstevel@tonic-gate if (continue_onerror) 15667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 15677c478bd9Sstevel@tonic-gate "Entry: cn=%s+ipServiceProtocol=%s" 15687c478bd9Sstevel@tonic-gate " already Exists, skipping it.\n"), 15697c478bd9Sstevel@tonic-gate data.s_name, data.s_proto); 15707c478bd9Sstevel@tonic-gate else { 15717c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 15727c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 15737c478bd9Sstevel@tonic-gate gettext("Entry: cn=%s+ipServiceProtocol=%s" 15747c478bd9Sstevel@tonic-gate " - already Exists\n"), 15757c478bd9Sstevel@tonic-gate data.s_name, data.s_proto); 15767c478bd9Sstevel@tonic-gate } 15777c478bd9Sstevel@tonic-gate } else if (retval) 15787c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate free(data.s_name); 15817c478bd9Sstevel@tonic-gate free(data.s_proto); 15827c478bd9Sstevel@tonic-gate free(data.s_aliases); 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate return (rc); 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate 15887c478bd9Sstevel@tonic-gate 15897c478bd9Sstevel@tonic-gate static void 15907c478bd9Sstevel@tonic-gate dump_services(ns_ldap_result_t *res) 15917c478bd9Sstevel@tonic-gate { 15927c478bd9Sstevel@tonic-gate ns_ldap_attr_t *attrptr = NULL, *cn = NULL, *port = NULL; 15937c478bd9Sstevel@tonic-gate ns_ldap_attr_t *protocol = NULL; 15947c478bd9Sstevel@tonic-gate int i, j, len; 15957c478bd9Sstevel@tonic-gate char *name; /* service name */ 15967c478bd9Sstevel@tonic-gate 15977c478bd9Sstevel@tonic-gate /* 15987c478bd9Sstevel@tonic-gate * cn can have multiple values.(service name and its aliases) 15997c478bd9Sstevel@tonic-gate * In order to support RFC 2307, section 5.5, ipserviceprotocol can 16007c478bd9Sstevel@tonic-gate * have multiple values too. 16017c478bd9Sstevel@tonic-gate * The output format should look like 16027c478bd9Sstevel@tonic-gate * 16037c478bd9Sstevel@tonic-gate * test 2345/udp mytest 16047c478bd9Sstevel@tonic-gate * test 2345/tcp mytest 16057c478bd9Sstevel@tonic-gate */ 16067c478bd9Sstevel@tonic-gate if (res == NULL || res->entry == NULL) 16077c478bd9Sstevel@tonic-gate return; 16087c478bd9Sstevel@tonic-gate for (i = 0; i < res->entry->attr_count; i++) { 16097c478bd9Sstevel@tonic-gate attrptr = res->entry->attr_pair[i]; 16107c478bd9Sstevel@tonic-gate if (strcasecmp(attrptr->attrname, "cn") == 0) 16117c478bd9Sstevel@tonic-gate cn = attrptr; 16127c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, "ipServicePort") == 0) 16137c478bd9Sstevel@tonic-gate port = attrptr; 16147c478bd9Sstevel@tonic-gate else if (strcasecmp(attrptr->attrname, 16157c478bd9Sstevel@tonic-gate "ipServiceProtocol") == 0) 16167c478bd9Sstevel@tonic-gate protocol = attrptr; 16177c478bd9Sstevel@tonic-gate } 16187c478bd9Sstevel@tonic-gate /* sanity check */ 16197c478bd9Sstevel@tonic-gate if (cn == NULL || cn->attrvalue == NULL || cn->attrvalue[0] == NULL || 16207c478bd9Sstevel@tonic-gate port == NULL || port->attrvalue == NULL || 16217c478bd9Sstevel@tonic-gate port->attrvalue[0] == NULL || protocol == NULL || 16227c478bd9Sstevel@tonic-gate protocol->attrvalue == NULL || protocol->attrvalue[0] == NULL) 16237c478bd9Sstevel@tonic-gate return; 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate if ((name = __s_api_get_canonical_name(res->entry, cn, 1)) == NULL) 16267c478bd9Sstevel@tonic-gate return; 16277c478bd9Sstevel@tonic-gate for (i = 0; i < protocol->value_count; i++) { 16287c478bd9Sstevel@tonic-gate if (protocol->attrvalue[i] == NULL) 16297c478bd9Sstevel@tonic-gate return; 16307c478bd9Sstevel@tonic-gate /* service name */ 16317c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%-16s", name); 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate /* port & protocol */ 16347c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s/%s%n", port->attrvalue[0], 16357c478bd9Sstevel@tonic-gate protocol->attrvalue[i], &len); 16367c478bd9Sstevel@tonic-gate 16377c478bd9Sstevel@tonic-gate if (len < 8) 16387c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\t\t"); 16397c478bd9Sstevel@tonic-gate else 16407c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\t"); 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate /* aliases */ 16437c478bd9Sstevel@tonic-gate for (j = 0; j < cn->value_count; j++) { 16447c478bd9Sstevel@tonic-gate if (cn->attrvalue[j]) { 16457c478bd9Sstevel@tonic-gate if (strcasecmp(name, cn->attrvalue[j]) == 0) 16467c478bd9Sstevel@tonic-gate /* skip service name */ 16477c478bd9Sstevel@tonic-gate continue; 16487c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s ", cn->attrvalue[j]); 16497c478bd9Sstevel@tonic-gate } 16507c478bd9Sstevel@tonic-gate } 16517c478bd9Sstevel@tonic-gate 16527c478bd9Sstevel@tonic-gate /* end of line */ 16537c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate 16587c478bd9Sstevel@tonic-gate /* 16597c478bd9Sstevel@tonic-gate * /etc/group 16607c478bd9Sstevel@tonic-gate */ 16617c478bd9Sstevel@tonic-gate 16627c478bd9Sstevel@tonic-gate static int 16637c478bd9Sstevel@tonic-gate genent_group(char *line, int (*cback)()) 16647c478bd9Sstevel@tonic-gate { 16657c478bd9Sstevel@tonic-gate char buf[BIGBUF+1]; 16667c478bd9Sstevel@tonic-gate char *s, *t; 16677c478bd9Sstevel@tonic-gate entry_col ecol[5]; 16687c478bd9Sstevel@tonic-gate 16697c478bd9Sstevel@tonic-gate struct group data; 16707c478bd9Sstevel@tonic-gate int ctr = 0; 16717c478bd9Sstevel@tonic-gate int retval = 1; 16727c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 16737c478bd9Sstevel@tonic-gate 16747c478bd9Sstevel@tonic-gate /* 16757c478bd9Sstevel@tonic-gate * don't clobber our argument 16767c478bd9Sstevel@tonic-gate */ 16777c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 16787c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 16797c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 16807c478bd9Sstevel@tonic-gate } 16817c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 16827c478bd9Sstevel@tonic-gate t = buf; 16837c478bd9Sstevel@tonic-gate 16847c478bd9Sstevel@tonic-gate /* ignore empty entries */ 16857c478bd9Sstevel@tonic-gate if (*t == '\0') 16867c478bd9Sstevel@tonic-gate return (GENENT_OK); 16877c478bd9Sstevel@tonic-gate 16887c478bd9Sstevel@tonic-gate /* 16897c478bd9Sstevel@tonic-gate * clear column data 16907c478bd9Sstevel@tonic-gate */ 16917c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate /* 16947c478bd9Sstevel@tonic-gate * name (col 0) 16957c478bd9Sstevel@tonic-gate */ 16967c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 16977c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no passwd"); 16987c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate *s++ = 0; 17017c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 17027c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 17037c478bd9Sstevel@tonic-gate t = s; 17047c478bd9Sstevel@tonic-gate 17057c478bd9Sstevel@tonic-gate /* 17067c478bd9Sstevel@tonic-gate * passwd (col 1) 17077c478bd9Sstevel@tonic-gate */ 17087c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 17097c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no gid"); 17107c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 17117c478bd9Sstevel@tonic-gate } 17127c478bd9Sstevel@tonic-gate *s++ = 0; 17137c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 17147c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 17157c478bd9Sstevel@tonic-gate t = s; 17167c478bd9Sstevel@tonic-gate 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* 17197c478bd9Sstevel@tonic-gate * gid (col 2) 17207c478bd9Sstevel@tonic-gate */ 17217c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0 || s == t) { 17227c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no members"); 17237c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 17247c478bd9Sstevel@tonic-gate } 17257c478bd9Sstevel@tonic-gate *s++ = 0; 17267c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 17277c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 17287c478bd9Sstevel@tonic-gate t = s; 17297c478bd9Sstevel@tonic-gate 17307c478bd9Sstevel@tonic-gate /* 17317c478bd9Sstevel@tonic-gate * members (col 3) 17327c478bd9Sstevel@tonic-gate */ 17337c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 17347c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate /* 17387c478bd9Sstevel@tonic-gate * build entry 17397c478bd9Sstevel@tonic-gate */ 17407c478bd9Sstevel@tonic-gate data.gr_name = strdup(ecol[0].ec_value.ec_value_val); 17417c478bd9Sstevel@tonic-gate data.gr_passwd = strdup(ecol[1].ec_value.ec_value_val); 17427c478bd9Sstevel@tonic-gate if (ecol[2].ec_value.ec_value_val != NULL && 17437c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val[0] != '\0') { 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate data.gr_gid = ascii_to_int(ecol[2].ec_value.ec_value_val); 17467c478bd9Sstevel@tonic-gate if (data.gr_gid == -1) { 17477c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 17487c478bd9Sstevel@tonic-gate "invalid group id: %s", 17497c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val); 17507c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 17517c478bd9Sstevel@tonic-gate } 17527c478bd9Sstevel@tonic-gate } else 17537c478bd9Sstevel@tonic-gate data.gr_gid = -1; 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate data.gr_mem = NULL; 17567c478bd9Sstevel@tonic-gate 175784ad75deSmj /* Compute maximum amount of members */ 175884ad75deSmj s = t; 175984ad75deSmj while (s = strchr(s, ',')) { 176084ad75deSmj s++; 176184ad75deSmj ctr++; 176284ad75deSmj } 176384ad75deSmj 176484ad75deSmj /* Allocate memory for all members */ 176584ad75deSmj data.gr_mem = calloc(ctr + 2, sizeof (char **)); 176684ad75deSmj if (data.gr_mem == NULL) { 176784ad75deSmj (void) fprintf(stderr, gettext("out of memory\n")); 176884ad75deSmj exit(1); 176984ad75deSmj } 177084ad75deSmj 177184ad75deSmj ctr = 0; 17727c478bd9Sstevel@tonic-gate while (s = strchr(t, ',')) { 17737c478bd9Sstevel@tonic-gate 17747c478bd9Sstevel@tonic-gate *s++ = 0; 17757c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 17767c478bd9Sstevel@tonic-gate t = s; 177784ad75deSmj /* Send to server only non empty member names */ 177884ad75deSmj if (strlen(ecol[3].ec_value.ec_value_val) != 0) 177984ad75deSmj data.gr_mem[ctr++] = ecol[3].ec_value.ec_value_val; 17807c478bd9Sstevel@tonic-gate } 17817c478bd9Sstevel@tonic-gate 178284ad75deSmj /* Send to server only non empty member names */ 178384ad75deSmj if (strlen(t) != 0) 178484ad75deSmj data.gr_mem[ctr++] = t; 178584ad75deSmj 178684ad75deSmj /* Array of members completed, finished by NULL, see calloc() */ 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 17897c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 17907c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.gr_name); 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 17937c478bd9Sstevel@tonic-gate 17947c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 17957c478bd9Sstevel@tonic-gate if (continue_onerror) 17967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 17977c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 17987c478bd9Sstevel@tonic-gate data.gr_name); 17997c478bd9Sstevel@tonic-gate else { 18007c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 18017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 18027c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 18037c478bd9Sstevel@tonic-gate data.gr_name); 18047c478bd9Sstevel@tonic-gate } 18057c478bd9Sstevel@tonic-gate } else if (retval) 18067c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate free(data.gr_name); 18097c478bd9Sstevel@tonic-gate free(data.gr_passwd); 18107c478bd9Sstevel@tonic-gate free(data.gr_mem); 18117c478bd9Sstevel@tonic-gate 18127c478bd9Sstevel@tonic-gate return (rc); 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate 18157c478bd9Sstevel@tonic-gate static void 18167c478bd9Sstevel@tonic-gate dump_group(ns_ldap_result_t *res) 18177c478bd9Sstevel@tonic-gate { 18187c478bd9Sstevel@tonic-gate char **value = NULL; 18197c478bd9Sstevel@tonic-gate char pnam[256]; 18207c478bd9Sstevel@tonic-gate int attr_count = 0; 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "cn"); 18237c478bd9Sstevel@tonic-gate if (value && value[0]) 18247c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 18257c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "userPassword"); 18267c478bd9Sstevel@tonic-gate if (value == NULL || value[0] == NULL) 18277c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 18287c478bd9Sstevel@tonic-gate else { 18297c478bd9Sstevel@tonic-gate (void) strcpy(pnam, value[0]); 18307c478bd9Sstevel@tonic-gate if (strncasecmp(value[0], "{crypt}", 7) == 0) 18317c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", (pnam+7)); 18327c478bd9Sstevel@tonic-gate else 18337c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 18347c478bd9Sstevel@tonic-gate } 18357c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "gidNumber"); 18367c478bd9Sstevel@tonic-gate if (value && value[0]) 18377c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 18387c478bd9Sstevel@tonic-gate 18397c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "memberUid"); 18407c478bd9Sstevel@tonic-gate if (value != NULL && value[0] != NULL) { 18417c478bd9Sstevel@tonic-gate while (value[attr_count] != NULL) { 18427c478bd9Sstevel@tonic-gate if (value[attr_count+1] == NULL) 18437c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[attr_count]); 18447c478bd9Sstevel@tonic-gate else 18457c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s,", 18467c478bd9Sstevel@tonic-gate value[attr_count]); 18477c478bd9Sstevel@tonic-gate attr_count++; 18487c478bd9Sstevel@tonic-gate } 18497c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 18507c478bd9Sstevel@tonic-gate } 18517c478bd9Sstevel@tonic-gate else 18527c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 18537c478bd9Sstevel@tonic-gate } 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate 18587c478bd9Sstevel@tonic-gate 18597c478bd9Sstevel@tonic-gate /* 18607c478bd9Sstevel@tonic-gate * /etc/ethers 18617c478bd9Sstevel@tonic-gate */ 18627c478bd9Sstevel@tonic-gate 18637c478bd9Sstevel@tonic-gate static int 18647c478bd9Sstevel@tonic-gate genent_ethers(char *line, int (*cback)()) 18657c478bd9Sstevel@tonic-gate { 18667c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 18677c478bd9Sstevel@tonic-gate char *t; 18687c478bd9Sstevel@tonic-gate entry_col ecol[3]; 18697c478bd9Sstevel@tonic-gate int retval = 1; 18707c478bd9Sstevel@tonic-gate struct _ns_ethers data; 18717c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate /* 18747c478bd9Sstevel@tonic-gate * don't clobber our argument 18757c478bd9Sstevel@tonic-gate */ 18767c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 18777c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 18787c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate /* 18837c478bd9Sstevel@tonic-gate * clear column data 18847c478bd9Sstevel@tonic-gate */ 18857c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 18867c478bd9Sstevel@tonic-gate 18877c478bd9Sstevel@tonic-gate /* 18887c478bd9Sstevel@tonic-gate * comment (col 2) 18897c478bd9Sstevel@tonic-gate */ 18907c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 18917c478bd9Sstevel@tonic-gate if (t) { 18927c478bd9Sstevel@tonic-gate *t++ = 0; 18937c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 18947c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 18957c478bd9Sstevel@tonic-gate } else { 18967c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = 0; 18977c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = 0; 18987c478bd9Sstevel@tonic-gate } 18997c478bd9Sstevel@tonic-gate 19007c478bd9Sstevel@tonic-gate /* 19017c478bd9Sstevel@tonic-gate * addr(col 0) 19027c478bd9Sstevel@tonic-gate */ 19037c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 19047c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no name"); 19057c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 19067c478bd9Sstevel@tonic-gate } 19077c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 19087c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate /* 19117c478bd9Sstevel@tonic-gate * name(col 1) 19127c478bd9Sstevel@tonic-gate */ 19137c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 19147c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no white space allowed in name"); 19157c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 19167c478bd9Sstevel@tonic-gate } 19177c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 19187c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 19197c478bd9Sstevel@tonic-gate 19207c478bd9Sstevel@tonic-gate 19217c478bd9Sstevel@tonic-gate /* 19227c478bd9Sstevel@tonic-gate * build entry 19237c478bd9Sstevel@tonic-gate */ 19247c478bd9Sstevel@tonic-gate 19257c478bd9Sstevel@tonic-gate data.ether = strdup(ecol[0].ec_value.ec_value_val); 19267c478bd9Sstevel@tonic-gate data.name = strdup(ecol[1].ec_value.ec_value_val); 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate 19297c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 19307c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 19317c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.name); 19327c478bd9Sstevel@tonic-gate 19337c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 19367c478bd9Sstevel@tonic-gate if (continue_onerror) 19377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 19387c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 19397c478bd9Sstevel@tonic-gate data.name); 19407c478bd9Sstevel@tonic-gate else { 19417c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 19427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 19437c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 19447c478bd9Sstevel@tonic-gate data.name); 19457c478bd9Sstevel@tonic-gate } 19467c478bd9Sstevel@tonic-gate } else if (retval) 19477c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate free(data.ether); 19507c478bd9Sstevel@tonic-gate free(data.name); 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate return (rc); 19537c478bd9Sstevel@tonic-gate } 19547c478bd9Sstevel@tonic-gate 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate static void 19577c478bd9Sstevel@tonic-gate dump_ethers(ns_ldap_result_t *res) 19587c478bd9Sstevel@tonic-gate { 19597c478bd9Sstevel@tonic-gate char **value = NULL; 19607c478bd9Sstevel@tonic-gate 19617c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "macAddress"); 19627c478bd9Sstevel@tonic-gate if (value && value[0]) 19637c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[0]); 19647c478bd9Sstevel@tonic-gate else 19657c478bd9Sstevel@tonic-gate return; 19667c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "cn"); 19677c478bd9Sstevel@tonic-gate if (value && value[0]) 19687c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s\n", value[0]); 19697c478bd9Sstevel@tonic-gate } 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate static int 19727c478bd9Sstevel@tonic-gate genent_aliases(char *line, int (*cback)()) 19737c478bd9Sstevel@tonic-gate { 19747c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 19757c478bd9Sstevel@tonic-gate char *t, *aliases; 19767c478bd9Sstevel@tonic-gate char *cname; 19777c478bd9Sstevel@tonic-gate int ctr = 0; 19787c478bd9Sstevel@tonic-gate int retval = 1; 19797c478bd9Sstevel@tonic-gate int i; 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate struct _ns_alias data; 19827c478bd9Sstevel@tonic-gate char *alias; 19837c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 19847c478bd9Sstevel@tonic-gate 19857c478bd9Sstevel@tonic-gate /* 19867c478bd9Sstevel@tonic-gate * don't clobber our argument 19877c478bd9Sstevel@tonic-gate */ 19887c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 19897c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 19907c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 19917c478bd9Sstevel@tonic-gate } 19927c478bd9Sstevel@tonic-gate 19937c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 19947c478bd9Sstevel@tonic-gate 19957c478bd9Sstevel@tonic-gate if ((t = strchr(buf, ':')) == 0) { 19967c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no alias name"); 19977c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 19987c478bd9Sstevel@tonic-gate } 19997c478bd9Sstevel@tonic-gate 20007c478bd9Sstevel@tonic-gate t[0] = '\0'; 20017c478bd9Sstevel@tonic-gate if (++t == '\0') { 20027c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no alias value"); 20037c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 20047c478bd9Sstevel@tonic-gate } 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate cname = buf; 20077c478bd9Sstevel@tonic-gate aliases = t; 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate /* build entry */ 20107c478bd9Sstevel@tonic-gate data.alias = strdup(cname); 20117c478bd9Sstevel@tonic-gate if (!data.alias) { 20127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 20137c478bd9Sstevel@tonic-gate exit(1); 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate data.member = NULL; 20177c478bd9Sstevel@tonic-gate t = strtok(aliases, ","); 20187c478bd9Sstevel@tonic-gate do { 20197c478bd9Sstevel@tonic-gate ctr++; 20207c478bd9Sstevel@tonic-gate while (t[0] == ' ') 20217c478bd9Sstevel@tonic-gate t++; 20227c478bd9Sstevel@tonic-gate alias = strdup(t); 20237c478bd9Sstevel@tonic-gate if ((alias == NULL) || 20247c478bd9Sstevel@tonic-gate ((data.member = (char **)realloc(data.member, 20257c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL)) { 20267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 20277c478bd9Sstevel@tonic-gate exit(1); 20287c478bd9Sstevel@tonic-gate } 20297c478bd9Sstevel@tonic-gate data.member[ctr-1] = alias; 20307c478bd9Sstevel@tonic-gate 20317c478bd9Sstevel@tonic-gate } while (t = strtok(NULL, ",")); 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate data.member[ctr] = NULL; 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 20367c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 20377c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.alias); 20387c478bd9Sstevel@tonic-gate 20397c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 20427c478bd9Sstevel@tonic-gate if (continue_onerror) 20437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 20447c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 20457c478bd9Sstevel@tonic-gate data.alias); 20467c478bd9Sstevel@tonic-gate else { 20477c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 20487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 20497c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 20507c478bd9Sstevel@tonic-gate data.alias); 20517c478bd9Sstevel@tonic-gate } 20527c478bd9Sstevel@tonic-gate } else if (retval) 20537c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 20547c478bd9Sstevel@tonic-gate 20557c478bd9Sstevel@tonic-gate free(data.alias); 20567c478bd9Sstevel@tonic-gate i = 0; 20577c478bd9Sstevel@tonic-gate while (data.member[i]) 20587c478bd9Sstevel@tonic-gate free(data.member[i++]); 20597c478bd9Sstevel@tonic-gate free(data.member); 20607c478bd9Sstevel@tonic-gate 20617c478bd9Sstevel@tonic-gate return (rc); 20627c478bd9Sstevel@tonic-gate } 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate 20657c478bd9Sstevel@tonic-gate static void 20667c478bd9Sstevel@tonic-gate dump_aliases(ns_ldap_result_t *res) 20677c478bd9Sstevel@tonic-gate { 20687c478bd9Sstevel@tonic-gate 20697c478bd9Sstevel@tonic-gate char **value = NULL; 20707c478bd9Sstevel@tonic-gate int attr_count = 0; 20717c478bd9Sstevel@tonic-gate 20727c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "mail"); 20737c478bd9Sstevel@tonic-gate if (value && value[0]) 20747c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 20757c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "mgrpRFC822MailMember"); 20767c478bd9Sstevel@tonic-gate if (value != NULL) 20777c478bd9Sstevel@tonic-gate while (value[attr_count] != NULL) { 20787c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s,", value[attr_count]); 20797c478bd9Sstevel@tonic-gate attr_count++; 20807c478bd9Sstevel@tonic-gate } 20817c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 20827c478bd9Sstevel@tonic-gate 20837c478bd9Sstevel@tonic-gate } 20847c478bd9Sstevel@tonic-gate 20857c478bd9Sstevel@tonic-gate /* 20867c478bd9Sstevel@tonic-gate * /etc/publickey 20877c478bd9Sstevel@tonic-gate */ 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate static int 20907c478bd9Sstevel@tonic-gate genent_publickey(char *line, int (*cback)()) 20917c478bd9Sstevel@tonic-gate { 20927c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1], tmpbuf[BUFSIZ+1], cname[BUFSIZ+1]; 20937c478bd9Sstevel@tonic-gate char *t, *p, *tmppubkey, *tmpprivkey; 20947c478bd9Sstevel@tonic-gate entry_col ecol[3]; 20957c478bd9Sstevel@tonic-gate int buflen, uid, retval = 1; 20967c478bd9Sstevel@tonic-gate struct passwd *pwd; 20977c478bd9Sstevel@tonic-gate char auth_type[BUFSIZ+1]; 20987c478bd9Sstevel@tonic-gate keylen_t keylen; 20997c478bd9Sstevel@tonic-gate algtype_t algtype; 21007c478bd9Sstevel@tonic-gate struct _ns_pubkey data; 21017c478bd9Sstevel@tonic-gate struct hostent *hp; 21027c478bd9Sstevel@tonic-gate struct in_addr in; 21037c478bd9Sstevel@tonic-gate 21047c478bd9Sstevel@tonic-gate /* 21057c478bd9Sstevel@tonic-gate * don't clobber our argument 21067c478bd9Sstevel@tonic-gate */ 21077c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 21087c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 21097c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21107c478bd9Sstevel@tonic-gate } 21117c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 21127c478bd9Sstevel@tonic-gate 21137c478bd9Sstevel@tonic-gate /* 21147c478bd9Sstevel@tonic-gate * clear column data 21157c478bd9Sstevel@tonic-gate */ 21167c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 21177c478bd9Sstevel@tonic-gate 21187c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 21197c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no cname"); 21207c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21217c478bd9Sstevel@tonic-gate } 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate /* 21247c478bd9Sstevel@tonic-gate * Special case: /etc/publickey usually has an entry 21257c478bd9Sstevel@tonic-gate * for principal "nobody". We skip it. 21267c478bd9Sstevel@tonic-gate */ 21277c478bd9Sstevel@tonic-gate if (strcmp(t, "nobody") == 0) 21287c478bd9Sstevel@tonic-gate return (GENENT_OK); 21297c478bd9Sstevel@tonic-gate 21307c478bd9Sstevel@tonic-gate /* 21317c478bd9Sstevel@tonic-gate * cname (col 0) 21327c478bd9Sstevel@tonic-gate */ 21337c478bd9Sstevel@tonic-gate if (strncmp(t, "unix.", 5)) { 21347c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "bad cname"); 21357c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21367c478bd9Sstevel@tonic-gate } 21377c478bd9Sstevel@tonic-gate (void) strcpy(tmpbuf, &(t[5])); 21387c478bd9Sstevel@tonic-gate if ((p = strchr(tmpbuf, '@')) == 0) { 21397c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "bad cname"); 21407c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21417c478bd9Sstevel@tonic-gate } 21427c478bd9Sstevel@tonic-gate *(p++) = 0; 21437c478bd9Sstevel@tonic-gate if (isdigit(*tmpbuf)) { 21447c478bd9Sstevel@tonic-gate 21457c478bd9Sstevel@tonic-gate uid = atoi(tmpbuf); 21467c478bd9Sstevel@tonic-gate /* 21477c478bd9Sstevel@tonic-gate * don't generate entries for uids without passwd entries 21487c478bd9Sstevel@tonic-gate */ 21497c478bd9Sstevel@tonic-gate if ((pwd = getpwuid(uid)) == 0) { 21507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 21517c478bd9Sstevel@tonic-gate gettext("can't map uid %d to username, skipping\n"), 21527c478bd9Sstevel@tonic-gate uid); 21537c478bd9Sstevel@tonic-gate return (GENENT_OK); 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate (void) strcpy(cname, pwd->pw_name); 21567c478bd9Sstevel@tonic-gate data.hostcred = NS_HOSTCRED_FALSE; 21577c478bd9Sstevel@tonic-gate } else { 21587c478bd9Sstevel@tonic-gate if ((hp = gethostbyname(tmpbuf)) == 0) { 21597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 21607c478bd9Sstevel@tonic-gate gettext("can't map hostname %s to hostaddress, skipping\n"), 21617c478bd9Sstevel@tonic-gate tmpbuf); 21627c478bd9Sstevel@tonic-gate return (GENENT_OK); 21637c478bd9Sstevel@tonic-gate } 21647c478bd9Sstevel@tonic-gate (void) memcpy((char *)&in.s_addr, hp->h_addr_list[0], 21657c478bd9Sstevel@tonic-gate sizeof (in)); 21667c478bd9Sstevel@tonic-gate data.hostcred = NS_HOSTCRED_TRUE; 21677c478bd9Sstevel@tonic-gate (void) snprintf(cname, sizeof (cname), 21687c478bd9Sstevel@tonic-gate "%s+ipHostNumber=%s", tmpbuf, inet_ntoa(in)); 21697c478bd9Sstevel@tonic-gate } 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = cname; 21727c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(cname)+1; 21737c478bd9Sstevel@tonic-gate 21747c478bd9Sstevel@tonic-gate /* 21757c478bd9Sstevel@tonic-gate * public_data (col 1) 21767c478bd9Sstevel@tonic-gate */ 21777c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 21787c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no private_data"); 21797c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate if ((p = strchr(t, ':')) == 0) { 21827c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "bad public_data"); 21837c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 21847c478bd9Sstevel@tonic-gate } 21857c478bd9Sstevel@tonic-gate *(p++) = 0; 21867c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 21877c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 21887c478bd9Sstevel@tonic-gate keylen = (strlen(t) / 2) * 8; 21897c478bd9Sstevel@tonic-gate 21907c478bd9Sstevel@tonic-gate /* 21917c478bd9Sstevel@tonic-gate * private_data (col 2) and algtype extraction 21927c478bd9Sstevel@tonic-gate */ 21937c478bd9Sstevel@tonic-gate if (*p == ':') 21947c478bd9Sstevel@tonic-gate p++; 21957c478bd9Sstevel@tonic-gate t = p; 21967c478bd9Sstevel@tonic-gate if (!(t = strchr(t, ':'))) { 21977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 21987c478bd9Sstevel@tonic-gate gettext("WARNING: No algorithm type data found " 21997c478bd9Sstevel@tonic-gate "in publickey file, assuming 0\n")); 22007c478bd9Sstevel@tonic-gate algtype = 0; 22017c478bd9Sstevel@tonic-gate } else { 22027c478bd9Sstevel@tonic-gate *t = '\0'; 22037c478bd9Sstevel@tonic-gate t++; 22047c478bd9Sstevel@tonic-gate algtype = atoi(t); 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = p; 22077c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(p)+1; 22087c478bd9Sstevel@tonic-gate 22097c478bd9Sstevel@tonic-gate /* 22107c478bd9Sstevel@tonic-gate * auth_type (col 1) 22117c478bd9Sstevel@tonic-gate */ 22127c478bd9Sstevel@tonic-gate if (!(__nis_keyalg2authtype(keylen, algtype, auth_type, 22137c478bd9Sstevel@tonic-gate MECH_MAXATNAME))) { 22147c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 22157c478bd9Sstevel@tonic-gate gettext("Could not convert algorithm type to " 22167c478bd9Sstevel@tonic-gate "corresponding auth type string\n")); 22177c478bd9Sstevel@tonic-gate return (GENENT_ERR); 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate /* 22217c478bd9Sstevel@tonic-gate * build entry 22227c478bd9Sstevel@tonic-gate */ 22237c478bd9Sstevel@tonic-gate data.name = strdup(ecol[0].ec_value.ec_value_val); 22247c478bd9Sstevel@tonic-gate if (data.name == NULL) { 22257c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 22267c478bd9Sstevel@tonic-gate exit(1); 22277c478bd9Sstevel@tonic-gate } 22287c478bd9Sstevel@tonic-gate 22297c478bd9Sstevel@tonic-gate buflen = sizeof (auth_type) + strlen(ecol[1].ec_value.ec_value_val) + 3; 22307c478bd9Sstevel@tonic-gate if ((tmppubkey = (char *)malloc(buflen)) == NULL) { 22317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 22327c478bd9Sstevel@tonic-gate exit(1); 22337c478bd9Sstevel@tonic-gate } 22347c478bd9Sstevel@tonic-gate (void) snprintf(tmppubkey, buflen, "{%s}%s", auth_type, 22357c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val); 22367c478bd9Sstevel@tonic-gate data.pubkey = tmppubkey; 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate buflen = sizeof (auth_type) + strlen(ecol[2].ec_value.ec_value_val) + 3; 22397c478bd9Sstevel@tonic-gate if ((tmpprivkey = (char *)malloc(buflen)) == NULL) { 22407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 22417c478bd9Sstevel@tonic-gate exit(1); 22427c478bd9Sstevel@tonic-gate } 22437c478bd9Sstevel@tonic-gate 22447c478bd9Sstevel@tonic-gate (void) snprintf(tmpprivkey, buflen, "{%s}%s", auth_type, 22457c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val); 22467c478bd9Sstevel@tonic-gate data.privkey = tmpprivkey; 22477c478bd9Sstevel@tonic-gate 22487c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 1); 2249*12fbe00aSjs if (retval != NS_LDAP_SUCCESS) { 2250*12fbe00aSjs if (retval == LDAP_NO_SUCH_OBJECT) { 2251*12fbe00aSjs if (data.hostcred == NS_HOSTCRED_TRUE) 2252*12fbe00aSjs (void) fprintf(stdout, 2253*12fbe00aSjs gettext("Cannot add publickey entry (%s), " 2254*12fbe00aSjs "add host entry first\n"), 2255*12fbe00aSjs tmpbuf); 2256*12fbe00aSjs else 2257*12fbe00aSjs (void) fprintf(stdout, 2258*12fbe00aSjs gettext("Cannot add publickey entry (%s), " 2259*12fbe00aSjs "add passwd entry first\n"), 2260*12fbe00aSjs data.name); 2261*12fbe00aSjs } 2262*12fbe00aSjs if (continue_onerror == 0) 2263*12fbe00aSjs return (GENENT_CBERR); 22647c478bd9Sstevel@tonic-gate } 2265*12fbe00aSjs 2266*12fbe00aSjs free(data.name); 2267*12fbe00aSjs free(data.pubkey); 2268*12fbe00aSjs free(data.privkey); 2269*12fbe00aSjs return (GENENT_OK); 22707c478bd9Sstevel@tonic-gate } 22717c478bd9Sstevel@tonic-gate 22727c478bd9Sstevel@tonic-gate static void 22737c478bd9Sstevel@tonic-gate dump_publickey(ns_ldap_result_t *res, char *container) 22747c478bd9Sstevel@tonic-gate { 22757c478bd9Sstevel@tonic-gate char **value = NULL; 22767c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 22777c478bd9Sstevel@tonic-gate char domainname[BUFSIZ]; 22787c478bd9Sstevel@tonic-gate char *pubptr, *prvptr; 22797c478bd9Sstevel@tonic-gate 22807c478bd9Sstevel@tonic-gate if (res == NULL) 22817c478bd9Sstevel@tonic-gate return; 22827c478bd9Sstevel@tonic-gate 22837c478bd9Sstevel@tonic-gate if (sysinfo(SI_SRPC_DOMAIN, domainname, BUFSIZ) < 0) { 22847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 22857c478bd9Sstevel@tonic-gate gettext("could not obtain domainname\n")); 22867c478bd9Sstevel@tonic-gate exit(1); 22877c478bd9Sstevel@tonic-gate } 22887c478bd9Sstevel@tonic-gate 22897c478bd9Sstevel@tonic-gate /* 22907c478bd9Sstevel@tonic-gate * Retrieve all the attributes, but don't print 22917c478bd9Sstevel@tonic-gate * until we have all the required ones. 22927c478bd9Sstevel@tonic-gate */ 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate if (strcmp(container, "passwd") == 0) 22957c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "uidNumber"); 22967c478bd9Sstevel@tonic-gate else 22977c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "cn"); 22987c478bd9Sstevel@tonic-gate 22997c478bd9Sstevel@tonic-gate if (value && value[0]) 23007c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "unix.%s@%s", 23017c478bd9Sstevel@tonic-gate value[0], domainname); 23027c478bd9Sstevel@tonic-gate else 23037c478bd9Sstevel@tonic-gate return; 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "nisPublickey"); 23067c478bd9Sstevel@tonic-gate if (value != NULL && value[0] != NULL) { 23077c478bd9Sstevel@tonic-gate if ((pubptr = strchr(value[0], '}')) == NULL) 23087c478bd9Sstevel@tonic-gate return; 23097c478bd9Sstevel@tonic-gate } 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "nisSecretkey"); 23127c478bd9Sstevel@tonic-gate if (value != NULL && value[0] != NULL) 23137c478bd9Sstevel@tonic-gate if ((prvptr = strchr(value[0], '}')) == NULL) 23147c478bd9Sstevel@tonic-gate return; 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate /* print the attributes, algorithm type is always 0 */ 23177c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s %s:%s:0\n", buf, ++pubptr, ++prvptr); 23187c478bd9Sstevel@tonic-gate } 23197c478bd9Sstevel@tonic-gate 23207c478bd9Sstevel@tonic-gate 23217c478bd9Sstevel@tonic-gate 23227c478bd9Sstevel@tonic-gate /* 23237c478bd9Sstevel@tonic-gate * /etc/netmasks 23247c478bd9Sstevel@tonic-gate */ 23257c478bd9Sstevel@tonic-gate 23267c478bd9Sstevel@tonic-gate static int 23277c478bd9Sstevel@tonic-gate genent_netmasks(char *line, int (*cback)()) 23287c478bd9Sstevel@tonic-gate { 23297c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 23307c478bd9Sstevel@tonic-gate char *t; 23317c478bd9Sstevel@tonic-gate entry_col ecol[3]; 2332*12fbe00aSjs int retval; 23337c478bd9Sstevel@tonic-gate 23347c478bd9Sstevel@tonic-gate struct _ns_netmasks data; 23357c478bd9Sstevel@tonic-gate 23367c478bd9Sstevel@tonic-gate 23377c478bd9Sstevel@tonic-gate /* 23387c478bd9Sstevel@tonic-gate * don't clobber our argument 23397c478bd9Sstevel@tonic-gate */ 23407c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 23417c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 23427c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 23437c478bd9Sstevel@tonic-gate } 23447c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate /* 23477c478bd9Sstevel@tonic-gate * clear column data 23487c478bd9Sstevel@tonic-gate */ 23497c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 23507c478bd9Sstevel@tonic-gate 23517c478bd9Sstevel@tonic-gate /* 23527c478bd9Sstevel@tonic-gate * comment (col 2) 23537c478bd9Sstevel@tonic-gate */ 23547c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 23557c478bd9Sstevel@tonic-gate if (t) { 23567c478bd9Sstevel@tonic-gate *t++ = 0; 23577c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 23587c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 23597c478bd9Sstevel@tonic-gate } else { 23607c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = 0; 23617c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = 0; 23627c478bd9Sstevel@tonic-gate } 23637c478bd9Sstevel@tonic-gate 23647c478bd9Sstevel@tonic-gate /* 23657c478bd9Sstevel@tonic-gate * addr(col 0) 23667c478bd9Sstevel@tonic-gate */ 23677c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 23687c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no mask"); 23697c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 23707c478bd9Sstevel@tonic-gate } 23717c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 23727c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 23737c478bd9Sstevel@tonic-gate 23747c478bd9Sstevel@tonic-gate /* 23757c478bd9Sstevel@tonic-gate * mask (col 1) 23767c478bd9Sstevel@tonic-gate */ 23777c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 23787c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no mask"); 23797c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 23807c478bd9Sstevel@tonic-gate } 23817c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 23827c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 23837c478bd9Sstevel@tonic-gate 23847c478bd9Sstevel@tonic-gate /* build entry */ 23857c478bd9Sstevel@tonic-gate data.netnumber = ecol[0].ec_value.ec_value_val; 23867c478bd9Sstevel@tonic-gate data.netmask = ecol[1].ec_value.ec_value_val; 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 23897c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 23907c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.netnumber); 23917c478bd9Sstevel@tonic-gate 2392*12fbe00aSjs retval = (*cback)(&data, 1); 2393*12fbe00aSjs if (retval != NS_LDAP_SUCCESS) { 2394*12fbe00aSjs if (retval == LDAP_NO_SUCH_OBJECT) 2395*12fbe00aSjs (void) fprintf(stdout, 2396*12fbe00aSjs gettext("Cannot add netmask entry (%s), " 2397*12fbe00aSjs "add network entry first\n"), data.netnumber); 2398*12fbe00aSjs if (continue_onerror == 0) 2399*12fbe00aSjs return (GENENT_CBERR); 2400*12fbe00aSjs } 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate return (GENENT_OK); 24037c478bd9Sstevel@tonic-gate } 24047c478bd9Sstevel@tonic-gate 24057c478bd9Sstevel@tonic-gate static void 24067c478bd9Sstevel@tonic-gate dump_netmasks(ns_ldap_result_t *res) 24077c478bd9Sstevel@tonic-gate { 24087c478bd9Sstevel@tonic-gate char **value = NULL; 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "ipNetworkNumber"); 24117c478bd9Sstevel@tonic-gate if (value && value[0]) 24127c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[0]); 24137c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "ipNetmaskNumber"); 24147c478bd9Sstevel@tonic-gate if (value && value[0]) 24157c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s\n", value[0]); 24167c478bd9Sstevel@tonic-gate } 24177c478bd9Sstevel@tonic-gate 24187c478bd9Sstevel@tonic-gate 24197c478bd9Sstevel@tonic-gate /* 24207c478bd9Sstevel@tonic-gate * /etc/netgroup 24217c478bd9Sstevel@tonic-gate * column data format is: 24227c478bd9Sstevel@tonic-gate * col 0: netgroup name (or cname) 24237c478bd9Sstevel@tonic-gate * col 1: netgroup member, if this is a triplet 24247c478bd9Sstevel@tonic-gate * col 2: netgroup member, if not a triplet 24257c478bd9Sstevel@tonic-gate * col 3: comment 24267c478bd9Sstevel@tonic-gate */ 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate static int 24297c478bd9Sstevel@tonic-gate genent_netgroup(char *line, int (*cback)()) 24307c478bd9Sstevel@tonic-gate { 24317c478bd9Sstevel@tonic-gate char buf[BIGBUF+1]; /* netgroup entries tend to be big */ 24327c478bd9Sstevel@tonic-gate char *t; 24337c478bd9Sstevel@tonic-gate char *cname = NULL; 24347c478bd9Sstevel@tonic-gate entry_col ecol[4]; 24357c478bd9Sstevel@tonic-gate char *netg_tmp = NULL, *triplet_tmp = NULL; 2436f31b640dSvl int netgcount = 0, tripletcount = 0, retval = 1, i; 24377c478bd9Sstevel@tonic-gate struct _ns_netgroups data; 24387c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 24397c478bd9Sstevel@tonic-gate 24407c478bd9Sstevel@tonic-gate /* don't clobber our argument */ 24417c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 24427c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 24437c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 24447c478bd9Sstevel@tonic-gate } 24457c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 24467c478bd9Sstevel@tonic-gate 24477c478bd9Sstevel@tonic-gate /* clear column data */ 24487c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate /* 24517c478bd9Sstevel@tonic-gate * process 1st minimal entry, to validate that there is no 24527c478bd9Sstevel@tonic-gate * parsing error. 24537c478bd9Sstevel@tonic-gate * start with comment(col 3) 24547c478bd9Sstevel@tonic-gate */ 24557c478bd9Sstevel@tonic-gate t = strchr(buf, '#'); 24567c478bd9Sstevel@tonic-gate if (t) { 24577c478bd9Sstevel@tonic-gate *t++ = 0; 24587c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 24597c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 24607c478bd9Sstevel@tonic-gate } else { 24617c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = ""; 24627c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = 0; 24637c478bd9Sstevel@tonic-gate } 24647c478bd9Sstevel@tonic-gate 24657c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = NULL; 24667c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = NULL; 24677c478bd9Sstevel@tonic-gate 24687c478bd9Sstevel@tonic-gate /* cname (col 0) */ 24697c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 24707c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no cname"); 24717c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 24727c478bd9Sstevel@tonic-gate } 2473f31b640dSvl 24747c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 24757c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 24767c478bd9Sstevel@tonic-gate cname = t; 24777c478bd9Sstevel@tonic-gate 24787c478bd9Sstevel@tonic-gate /* addr(col 1 and 2) */ 24797c478bd9Sstevel@tonic-gate if ((t = strtok(NULL, " \t")) == 0) { 24807c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no members for netgroup"); 24817c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 24827c478bd9Sstevel@tonic-gate } 24837c478bd9Sstevel@tonic-gate 24847c478bd9Sstevel@tonic-gate if (*t == '(') { 2485f31b640dSvl /* if token starts with '(' it must be a valid triplet */ 2486f31b640dSvl if (is_triplet(t)) { 2487f31b640dSvl ecol[1].ec_value.ec_value_val = t; 2488f31b640dSvl ecol[1].ec_value.ec_value_len = strlen(t)+1; 2489f31b640dSvl } else { 2490f31b640dSvl (void) strcpy(parse_err_msg, "invalid triplet"); 2491f31b640dSvl return (GENENT_PARSEERR); 2492f31b640dSvl } 24937c478bd9Sstevel@tonic-gate } else { 24947c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 24957c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 24967c478bd9Sstevel@tonic-gate } 24977c478bd9Sstevel@tonic-gate 24987c478bd9Sstevel@tonic-gate /* 24997c478bd9Sstevel@tonic-gate * now build entry. 25007c478bd9Sstevel@tonic-gate * start by clearing entry data 25017c478bd9Sstevel@tonic-gate */ 25027c478bd9Sstevel@tonic-gate (void) memset((struct _ns_netgroups *)&data, 0, sizeof (data)); 25037c478bd9Sstevel@tonic-gate 25047c478bd9Sstevel@tonic-gate data.name = strdup(ecol[0].ec_value.ec_value_val); 25057c478bd9Sstevel@tonic-gate 25067c478bd9Sstevel@tonic-gate if (ecol[1].ec_value.ec_value_val != NULL) { 25077c478bd9Sstevel@tonic-gate if ((data.triplet = calloc(1, sizeof (char **))) == NULL) { 25087c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 25097c478bd9Sstevel@tonic-gate gettext("out of memory\n")); 25107c478bd9Sstevel@tonic-gate exit(1); 25117c478bd9Sstevel@tonic-gate } 25127c478bd9Sstevel@tonic-gate data.triplet[tripletcount++] = 25137c478bd9Sstevel@tonic-gate strdup(ecol[1].ec_value.ec_value_val); 25147c478bd9Sstevel@tonic-gate } else if (ecol[2].ec_value.ec_value_val != NULL) { 25157c478bd9Sstevel@tonic-gate if ((data.netgroup = calloc(1, sizeof (char **))) 25167c478bd9Sstevel@tonic-gate == NULL) { 25177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 25187c478bd9Sstevel@tonic-gate gettext("out of memory\n")); 25197c478bd9Sstevel@tonic-gate exit(1); 25207c478bd9Sstevel@tonic-gate } 25217c478bd9Sstevel@tonic-gate data.netgroup[netgcount++] = 25227c478bd9Sstevel@tonic-gate strdup(ecol[2].ec_value.ec_value_val); 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25257c478bd9Sstevel@tonic-gate /* 25267c478bd9Sstevel@tonic-gate * we now have a valid entry (at least 1 netgroup name and 25277c478bd9Sstevel@tonic-gate * 1 netgroup member), proceed with the rest of the line 25287c478bd9Sstevel@tonic-gate */ 2529f31b640dSvl while (rc == GENENT_OK && (t = strtok(NULL, " \t"))) { 25307c478bd9Sstevel@tonic-gate 25317c478bd9Sstevel@tonic-gate /* if next token is equal to netgroup name, ignore */ 25327c478bd9Sstevel@tonic-gate if (t != cname && strcasecmp(t, cname) == 0) 25337c478bd9Sstevel@tonic-gate continue; 25347c478bd9Sstevel@tonic-gate if (strcasecmp(t, ecol[0].ec_value.ec_value_val) == 0) 25357c478bd9Sstevel@tonic-gate continue; 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate if (*t == '(') { 2538f31b640dSvl if (is_triplet(t)) { 2539f31b640dSvl /* skip a triplet if it is added already */ 2540f31b640dSvl for (i = 0; i < tripletcount && 2541f31b640dSvl strcmp(t, data.triplet[i]); i++) 2542f31b640dSvl ; 2543f31b640dSvl if (i < tripletcount) 2544f31b640dSvl continue; 2545f31b640dSvl 2546f31b640dSvl tripletcount++; 2547f31b640dSvl triplet_tmp = strdup(t); 2548f31b640dSvl if ((data.triplet = (char **)realloc( 2549f31b640dSvl data.triplet, 2550f31b640dSvl tripletcount * sizeof (char **))) 2551f31b640dSvl == NULL) { 2552f31b640dSvl (void) fprintf(stderr, 2553f31b640dSvl gettext("out of memory\n")); 2554f31b640dSvl exit(1); 2555f31b640dSvl } 2556f31b640dSvl data.triplet[tripletcount-1] = triplet_tmp; 2557f31b640dSvl } else { 2558f31b640dSvl (void) strcpy(parse_err_msg, "invalid triplet"); 2559f31b640dSvl rc = GENENT_PARSEERR; 25607c478bd9Sstevel@tonic-gate } 25617c478bd9Sstevel@tonic-gate } else { 2562f31b640dSvl /* skip a netgroup if it is added already */ 2563f31b640dSvl for (i = 0; i < netgcount && 2564f31b640dSvl strcmp(t, data.netgroup[i]); i++) 2565f31b640dSvl ; 2566f31b640dSvl if (i < netgcount) 2567f31b640dSvl continue; 2568f31b640dSvl 25697c478bd9Sstevel@tonic-gate netgcount++; 25707c478bd9Sstevel@tonic-gate netg_tmp = strdup(t); 25717c478bd9Sstevel@tonic-gate if ((data.netgroup = (char **)realloc(data.netgroup, 25727c478bd9Sstevel@tonic-gate netgcount * sizeof (char **))) == NULL) { 25737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 25747c478bd9Sstevel@tonic-gate gettext("out of memory\n")); 25757c478bd9Sstevel@tonic-gate exit(1); 25767c478bd9Sstevel@tonic-gate } 25777c478bd9Sstevel@tonic-gate data.netgroup[netgcount-1] = netg_tmp; 25787c478bd9Sstevel@tonic-gate } 25797c478bd9Sstevel@tonic-gate } 25807c478bd9Sstevel@tonic-gate 25817c478bd9Sstevel@tonic-gate /* End the list with NULL */ 25827c478bd9Sstevel@tonic-gate if ((data.triplet = (char **)realloc(data.triplet, 25837c478bd9Sstevel@tonic-gate (tripletcount + 1) * sizeof (char **))) == NULL) { 25847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 25857c478bd9Sstevel@tonic-gate exit(1); 25867c478bd9Sstevel@tonic-gate } 25877c478bd9Sstevel@tonic-gate data.triplet[tripletcount] = NULL; 25887c478bd9Sstevel@tonic-gate if ((data.netgroup = (char **)realloc(data.netgroup, 25897c478bd9Sstevel@tonic-gate (netgcount + 1) * sizeof (char **))) == NULL) { 25907c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 25917c478bd9Sstevel@tonic-gate exit(1); 25927c478bd9Sstevel@tonic-gate } 25937c478bd9Sstevel@tonic-gate data.netgroup[netgcount] = NULL; 25947c478bd9Sstevel@tonic-gate 2595f31b640dSvl if (rc == GENENT_OK) { 2596f31b640dSvl if (flags & F_VERBOSE) 2597f31b640dSvl (void) fprintf(stdout, 2598f31b640dSvl gettext("Adding entry : %s\n"), data.name); 25997c478bd9Sstevel@tonic-gate 2600f31b640dSvl retval = (*cback)(&data, 0); 26017c478bd9Sstevel@tonic-gate 2602f31b640dSvl if (retval == LDAP_ALREADY_EXISTS) { 2603f31b640dSvl if (continue_onerror) 2604f31b640dSvl (void) fprintf(stderr, gettext( 2605f31b640dSvl "Entry: %s - already Exists, skipping it.\n"), 26067c478bd9Sstevel@tonic-gate data.name); 2607f31b640dSvl else { 2608f31b640dSvl rc = GENENT_CBERR; 2609f31b640dSvl (void) fprintf(stderr, 2610f31b640dSvl gettext("Entry: %s - already Exists\n"), 2611f31b640dSvl data.name); 2612f31b640dSvl } 2613f31b640dSvl } else if (retval) 2614f31b640dSvl rc = GENENT_CBERR; 2615f31b640dSvl } 2616f31b640dSvl 2617f31b640dSvl /* release memory allocated by strdup() */ 2618f31b640dSvl for (i = 0; i < tripletcount; i++) { 2619f31b640dSvl free(data.triplet[i]); 2620f31b640dSvl } 2621f31b640dSvl for (i = 0; i < netgcount; i++) { 2622f31b640dSvl free(data.netgroup[i]); 2623f31b640dSvl } 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate free(data.name); 26267c478bd9Sstevel@tonic-gate free(data.triplet); 26277c478bd9Sstevel@tonic-gate free(data.netgroup); 26287c478bd9Sstevel@tonic-gate 26297c478bd9Sstevel@tonic-gate return (rc); 26307c478bd9Sstevel@tonic-gate } 26317c478bd9Sstevel@tonic-gate 26327c478bd9Sstevel@tonic-gate static void 26337c478bd9Sstevel@tonic-gate dump_netgroup(ns_ldap_result_t *res) 26347c478bd9Sstevel@tonic-gate { 26357c478bd9Sstevel@tonic-gate char **value = NULL; 26367c478bd9Sstevel@tonic-gate int attr_count = 0; 26377c478bd9Sstevel@tonic-gate 26387c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "cn"); 26397c478bd9Sstevel@tonic-gate if ((value != NULL) && (value[0] != NULL)) 26407c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[0]); 26417c478bd9Sstevel@tonic-gate else 26427c478bd9Sstevel@tonic-gate return; 26437c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "nisNetgroupTriple"); 26447c478bd9Sstevel@tonic-gate if (value != NULL) 26457c478bd9Sstevel@tonic-gate while (value[attr_count] != NULL) { 26467c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s", value[attr_count]); 26477c478bd9Sstevel@tonic-gate attr_count++; 26487c478bd9Sstevel@tonic-gate } 26497c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "memberNisNetgroup"); 26507c478bd9Sstevel@tonic-gate if (value != NULL) 26517c478bd9Sstevel@tonic-gate while (value[attr_count] != NULL) { 26527c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s", value[attr_count]); 26537c478bd9Sstevel@tonic-gate attr_count++; 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 26567c478bd9Sstevel@tonic-gate 26577c478bd9Sstevel@tonic-gate } 26587c478bd9Sstevel@tonic-gate 26597c478bd9Sstevel@tonic-gate static int 26607c478bd9Sstevel@tonic-gate genent_automount(char *line, int (*cback)()) 26617c478bd9Sstevel@tonic-gate { 26627c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 26637c478bd9Sstevel@tonic-gate char *t, *s; 26647c478bd9Sstevel@tonic-gate entry_col ecol[2]; 26657c478bd9Sstevel@tonic-gate struct _ns_automount data; 26667c478bd9Sstevel@tonic-gate int retval = 1; 26677c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate /* 26707c478bd9Sstevel@tonic-gate * don't clobber our argument 26717c478bd9Sstevel@tonic-gate */ 26727c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 26737c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 26747c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 26757c478bd9Sstevel@tonic-gate } 26767c478bd9Sstevel@tonic-gate 26777c478bd9Sstevel@tonic-gate /* replace every tabspace with single space */ 26787c478bd9Sstevel@tonic-gate replace_tab2space(line); 26797c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 26807c478bd9Sstevel@tonic-gate 26817c478bd9Sstevel@tonic-gate /* 26827c478bd9Sstevel@tonic-gate * clear column data 26837c478bd9Sstevel@tonic-gate */ 26847c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 26857c478bd9Sstevel@tonic-gate 26867c478bd9Sstevel@tonic-gate /* 26877c478bd9Sstevel@tonic-gate * key (col 0) 26887c478bd9Sstevel@tonic-gate */ 26897c478bd9Sstevel@tonic-gate t = buf; 26907c478bd9Sstevel@tonic-gate while (t[0] == ' ') 26917c478bd9Sstevel@tonic-gate t++; 26927c478bd9Sstevel@tonic-gate 26937c478bd9Sstevel@tonic-gate if ((s = strchr(t, ' ')) == 0) { 26947c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 26957c478bd9Sstevel@tonic-gate } 26967c478bd9Sstevel@tonic-gate *s++ = 0; 26977c478bd9Sstevel@tonic-gate 26987c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 26997c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 27007c478bd9Sstevel@tonic-gate t = s; 27017c478bd9Sstevel@tonic-gate 27027c478bd9Sstevel@tonic-gate while (t[0] == ' ') 27037c478bd9Sstevel@tonic-gate t++; 27047c478bd9Sstevel@tonic-gate 27057c478bd9Sstevel@tonic-gate /* 27067c478bd9Sstevel@tonic-gate * mapentry (col 1) 27077c478bd9Sstevel@tonic-gate */ 27087c478bd9Sstevel@tonic-gate 27097c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 27107c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 27117c478bd9Sstevel@tonic-gate 27127c478bd9Sstevel@tonic-gate data.mapname = strdup(databasetype); 27137c478bd9Sstevel@tonic-gate data.key = strdup(ecol[0].ec_value.ec_value_val); 27147c478bd9Sstevel@tonic-gate data.value = strdup(ecol[1].ec_value.ec_value_val); 27157c478bd9Sstevel@tonic-gate 27167c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 27177c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 27187c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.key); 27197c478bd9Sstevel@tonic-gate 27207c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 27217c478bd9Sstevel@tonic-gate 27227c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 27237c478bd9Sstevel@tonic-gate if (continue_onerror) 27247c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 27257c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 27267c478bd9Sstevel@tonic-gate data.key); 27277c478bd9Sstevel@tonic-gate else { 27287c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 27297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 27307c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 27317c478bd9Sstevel@tonic-gate data.key); 27327c478bd9Sstevel@tonic-gate } 27337c478bd9Sstevel@tonic-gate } else if (retval) 27347c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 27357c478bd9Sstevel@tonic-gate 27367c478bd9Sstevel@tonic-gate free(data.mapname); 27377c478bd9Sstevel@tonic-gate free(data.key); 27387c478bd9Sstevel@tonic-gate free(data.value); 27397c478bd9Sstevel@tonic-gate return (rc); 27407c478bd9Sstevel@tonic-gate } 27417c478bd9Sstevel@tonic-gate 27427c478bd9Sstevel@tonic-gate static void 27437c478bd9Sstevel@tonic-gate dump_automount(ns_ldap_result_t *res) 27447c478bd9Sstevel@tonic-gate { 27457c478bd9Sstevel@tonic-gate char **value = NULL; 27467c478bd9Sstevel@tonic-gate 27477c478bd9Sstevel@tonic-gate if (res == NULL) 27487c478bd9Sstevel@tonic-gate return; 27497c478bd9Sstevel@tonic-gate 27507c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "automountKey"); 27517c478bd9Sstevel@tonic-gate if (value != NULL) { 27527c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[0]); 27537c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "automountInformation"); 27547c478bd9Sstevel@tonic-gate if (value != NULL) 27557c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s\n", value[0]); 27567c478bd9Sstevel@tonic-gate else 27577c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 27587c478bd9Sstevel@tonic-gate } 27597c478bd9Sstevel@tonic-gate } 27607c478bd9Sstevel@tonic-gate 27617c478bd9Sstevel@tonic-gate 27627c478bd9Sstevel@tonic-gate /* 27637c478bd9Sstevel@tonic-gate * /etc/passwd 27647c478bd9Sstevel@tonic-gate * 27657c478bd9Sstevel@tonic-gate */ 27667c478bd9Sstevel@tonic-gate 27677c478bd9Sstevel@tonic-gate static int 27687c478bd9Sstevel@tonic-gate genent_passwd(char *line, int (*cback)()) 27697c478bd9Sstevel@tonic-gate { 27707c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 27717c478bd9Sstevel@tonic-gate char *s, *t; 27727c478bd9Sstevel@tonic-gate entry_col ecol[8]; 27737c478bd9Sstevel@tonic-gate int retval = 1; 27747c478bd9Sstevel@tonic-gate char pname[BUFSIZ]; 27757c478bd9Sstevel@tonic-gate 27767c478bd9Sstevel@tonic-gate struct passwd data; 27777c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate 27807c478bd9Sstevel@tonic-gate /* 27817c478bd9Sstevel@tonic-gate * don't clobber our argument 27827c478bd9Sstevel@tonic-gate */ 27837c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 27847c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 27857c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 27867c478bd9Sstevel@tonic-gate } 27877c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 27887c478bd9Sstevel@tonic-gate t = buf; 27897c478bd9Sstevel@tonic-gate 27907c478bd9Sstevel@tonic-gate /* ignore empty entries */ 27917c478bd9Sstevel@tonic-gate if (*t == '\0') 27927c478bd9Sstevel@tonic-gate return (GENENT_OK); 27937c478bd9Sstevel@tonic-gate 27947c478bd9Sstevel@tonic-gate /* 27957c478bd9Sstevel@tonic-gate * clear column data 27967c478bd9Sstevel@tonic-gate */ 27977c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 27987c478bd9Sstevel@tonic-gate 27997c478bd9Sstevel@tonic-gate /* 28007c478bd9Sstevel@tonic-gate * name (col 0) 28017c478bd9Sstevel@tonic-gate */ 28027c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 28037c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no password"); 28047c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28057c478bd9Sstevel@tonic-gate } 28067c478bd9Sstevel@tonic-gate *s++ = 0; 28077c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 28087c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 28097c478bd9Sstevel@tonic-gate t = s; 28107c478bd9Sstevel@tonic-gate 28117c478bd9Sstevel@tonic-gate /* 28127c478bd9Sstevel@tonic-gate * passwd (col 1) 28137c478bd9Sstevel@tonic-gate */ 28147c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 28157c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no uid"); 28167c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28177c478bd9Sstevel@tonic-gate } 28187c478bd9Sstevel@tonic-gate *s++ = 0; 28197c478bd9Sstevel@tonic-gate 28207c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 28217c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 28227c478bd9Sstevel@tonic-gate 28237c478bd9Sstevel@tonic-gate t = s; 28247c478bd9Sstevel@tonic-gate 28257c478bd9Sstevel@tonic-gate /* 28267c478bd9Sstevel@tonic-gate * uid (col 2) 28277c478bd9Sstevel@tonic-gate */ 28287c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0 || s == t) { 28297c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no gid"); 28307c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28317c478bd9Sstevel@tonic-gate } 28327c478bd9Sstevel@tonic-gate *s++ = 0; 28337c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 28347c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 28357c478bd9Sstevel@tonic-gate t = s; 28367c478bd9Sstevel@tonic-gate 28377c478bd9Sstevel@tonic-gate /* 28387c478bd9Sstevel@tonic-gate * gid (col 3) 28397c478bd9Sstevel@tonic-gate */ 28407c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0 || s == t) { 28417c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no gcos"); 28427c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28437c478bd9Sstevel@tonic-gate } 28447c478bd9Sstevel@tonic-gate *s++ = 0; 28457c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 28467c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 28477c478bd9Sstevel@tonic-gate t = s; 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate /* 28507c478bd9Sstevel@tonic-gate * gcos (col 4) 28517c478bd9Sstevel@tonic-gate */ 28527c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 28537c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no home"); 28547c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28557c478bd9Sstevel@tonic-gate } 28567c478bd9Sstevel@tonic-gate *s++ = 0; 28577c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val = t; 28587c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_len = strlen(t)+1; 28597c478bd9Sstevel@tonic-gate t = s; 28607c478bd9Sstevel@tonic-gate 28617c478bd9Sstevel@tonic-gate /* 28627c478bd9Sstevel@tonic-gate * home (col 5) 28637c478bd9Sstevel@tonic-gate */ 28647c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 28657c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no shell"); 28667c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 28677c478bd9Sstevel@tonic-gate } 28687c478bd9Sstevel@tonic-gate *s++ = 0; 28697c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_val = t; 28707c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_len = strlen(t)+1; 28717c478bd9Sstevel@tonic-gate t = s; 28727c478bd9Sstevel@tonic-gate 28737c478bd9Sstevel@tonic-gate /* 28747c478bd9Sstevel@tonic-gate * shell (col 6) 28757c478bd9Sstevel@tonic-gate */ 28767c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_val = t; 28777c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_len = strlen(t)+1; 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate /* 28807c478bd9Sstevel@tonic-gate * build entry 28817c478bd9Sstevel@tonic-gate */ 28827c478bd9Sstevel@tonic-gate data.pw_name = strdup(ecol[0].ec_value.ec_value_val); 28837c478bd9Sstevel@tonic-gate 28847c478bd9Sstevel@tonic-gate if (flags & F_PASSWD) { 28857c478bd9Sstevel@tonic-gate /* Add {crypt} before passwd entry */ 28867c478bd9Sstevel@tonic-gate (void) snprintf(pname, sizeof (pname), "{crypt}%s", 28877c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val); 28887c478bd9Sstevel@tonic-gate data.pw_passwd = strdup(pname); 28897c478bd9Sstevel@tonic-gate } 28907c478bd9Sstevel@tonic-gate else 28917c478bd9Sstevel@tonic-gate data.pw_passwd = NULL; 28927c478bd9Sstevel@tonic-gate 28937c478bd9Sstevel@tonic-gate if (ecol[2].ec_value.ec_value_val != NULL && 28947c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val[0] != '\0') { 28957c478bd9Sstevel@tonic-gate data.pw_uid = ascii_to_int(ecol[2].ec_value.ec_value_val); 28967c478bd9Sstevel@tonic-gate if (data.pw_uid == -1) { 28977c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 28987c478bd9Sstevel@tonic-gate "invalid uid : %s", ecol[2].ec_value.ec_value_val); 28997c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 29007c478bd9Sstevel@tonic-gate } 29017c478bd9Sstevel@tonic-gate } else 29027c478bd9Sstevel@tonic-gate data.pw_uid = -1; 29037c478bd9Sstevel@tonic-gate 29047c478bd9Sstevel@tonic-gate if (ecol[3].ec_value.ec_value_val != NULL && 29057c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val[0] != '\0') { 29067c478bd9Sstevel@tonic-gate 29077c478bd9Sstevel@tonic-gate data.pw_gid = ascii_to_int(ecol[3].ec_value.ec_value_val); 29087c478bd9Sstevel@tonic-gate if (data.pw_gid == -1) { 29097c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 29107c478bd9Sstevel@tonic-gate "invalid gid : %s", ecol[3].ec_value.ec_value_val); 29117c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 29127c478bd9Sstevel@tonic-gate } 29137c478bd9Sstevel@tonic-gate } else 29147c478bd9Sstevel@tonic-gate data.pw_gid = -1; 29157c478bd9Sstevel@tonic-gate 29167c478bd9Sstevel@tonic-gate data.pw_age = NULL; 29177c478bd9Sstevel@tonic-gate data.pw_comment = NULL; 29187c478bd9Sstevel@tonic-gate data.pw_gecos = strdup(ecol[4].ec_value.ec_value_val); 29197c478bd9Sstevel@tonic-gate data.pw_dir = strdup(ecol[5].ec_value.ec_value_val); 29207c478bd9Sstevel@tonic-gate data.pw_shell = strdup(ecol[6].ec_value.ec_value_val); 29217c478bd9Sstevel@tonic-gate 29227c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 29237c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 29247c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.pw_name); 29257c478bd9Sstevel@tonic-gate 29267c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 29277c478bd9Sstevel@tonic-gate 29287c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 29297c478bd9Sstevel@tonic-gate if (continue_onerror) 29307c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 29317c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 29327c478bd9Sstevel@tonic-gate data.pw_name); 29337c478bd9Sstevel@tonic-gate else { 29347c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 29357c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 29367c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 29377c478bd9Sstevel@tonic-gate data.pw_name); 29387c478bd9Sstevel@tonic-gate } 29397c478bd9Sstevel@tonic-gate } else if (retval) 29407c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate free(data.pw_name); 29437c478bd9Sstevel@tonic-gate free(data.pw_gecos); 29447c478bd9Sstevel@tonic-gate free(data.pw_dir); 29457c478bd9Sstevel@tonic-gate free(data.pw_shell); 29467c478bd9Sstevel@tonic-gate return (rc); 29477c478bd9Sstevel@tonic-gate } 29487c478bd9Sstevel@tonic-gate 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate static void 29517c478bd9Sstevel@tonic-gate dump_passwd(ns_ldap_result_t *res) 29527c478bd9Sstevel@tonic-gate { 29537c478bd9Sstevel@tonic-gate char **value = NULL; 29547c478bd9Sstevel@tonic-gate char pnam[256]; 29557c478bd9Sstevel@tonic-gate 29567c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "uid"); 29577c478bd9Sstevel@tonic-gate if (value == NULL) 29587c478bd9Sstevel@tonic-gate return; 29597c478bd9Sstevel@tonic-gate else 29607c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 29617c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "userPassword"); 29627c478bd9Sstevel@tonic-gate if (value == NULL) 29637c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 29647c478bd9Sstevel@tonic-gate else { 29657c478bd9Sstevel@tonic-gate (void) strcpy(pnam, value[0]); 29667c478bd9Sstevel@tonic-gate if (strncasecmp(value[0], "{crypt}", 7) == 0) 29677c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", (pnam+7)); 29687c478bd9Sstevel@tonic-gate else 29697c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 29707c478bd9Sstevel@tonic-gate } 29717c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "uidNumber"); 29727c478bd9Sstevel@tonic-gate if (value && value[0]) 29737c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 29747c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "gidNumber"); 29757c478bd9Sstevel@tonic-gate if (value && value[0]) 29767c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 29777c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "gecos"); 29787c478bd9Sstevel@tonic-gate if (value == NULL) 29797c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":"); 29807c478bd9Sstevel@tonic-gate else 29817c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 29827c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "homeDirectory"); 29837c478bd9Sstevel@tonic-gate if (value == NULL) 29847c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":"); 29857c478bd9Sstevel@tonic-gate else 29867c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 29877c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "loginShell"); 29887c478bd9Sstevel@tonic-gate if (value == NULL) 29897c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 29907c478bd9Sstevel@tonic-gate else 29917c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", value[0]); 29927c478bd9Sstevel@tonic-gate 29937c478bd9Sstevel@tonic-gate } 29947c478bd9Sstevel@tonic-gate 29957c478bd9Sstevel@tonic-gate /* 29967c478bd9Sstevel@tonic-gate * /etc/shadow 29977c478bd9Sstevel@tonic-gate */ 29987c478bd9Sstevel@tonic-gate 29997c478bd9Sstevel@tonic-gate static int 30007c478bd9Sstevel@tonic-gate genent_shadow(char *line, int (*cback)()) 30017c478bd9Sstevel@tonic-gate { 30027c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 30037c478bd9Sstevel@tonic-gate char *s, *t; 30047c478bd9Sstevel@tonic-gate entry_col ecol[9]; 30057c478bd9Sstevel@tonic-gate char pname[BUFSIZ]; 30067c478bd9Sstevel@tonic-gate 30077c478bd9Sstevel@tonic-gate struct spwd data; 30087c478bd9Sstevel@tonic-gate int spflag; 3009*12fbe00aSjs int retval; 30107c478bd9Sstevel@tonic-gate 30117c478bd9Sstevel@tonic-gate 30127c478bd9Sstevel@tonic-gate /* 30137c478bd9Sstevel@tonic-gate * don't clobber our argument 30147c478bd9Sstevel@tonic-gate */ 30157c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 30167c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 30177c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30187c478bd9Sstevel@tonic-gate } 30197c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 30207c478bd9Sstevel@tonic-gate t = buf; 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate /* ignore empty entries */ 30237c478bd9Sstevel@tonic-gate if (*t == '\0') 30247c478bd9Sstevel@tonic-gate return (GENENT_OK); 30257c478bd9Sstevel@tonic-gate 30267c478bd9Sstevel@tonic-gate /* 30277c478bd9Sstevel@tonic-gate * clear column data 30287c478bd9Sstevel@tonic-gate */ 30297c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 30307c478bd9Sstevel@tonic-gate 30317c478bd9Sstevel@tonic-gate /* 30327c478bd9Sstevel@tonic-gate * name (col 0) 30337c478bd9Sstevel@tonic-gate */ 30347c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30357c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no uid"); 30367c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30377c478bd9Sstevel@tonic-gate } 30387c478bd9Sstevel@tonic-gate *s++ = 0; 30397c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 30407c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 30417c478bd9Sstevel@tonic-gate t = s; 30427c478bd9Sstevel@tonic-gate 30437c478bd9Sstevel@tonic-gate /* 30447c478bd9Sstevel@tonic-gate * passwd (col 1) 30457c478bd9Sstevel@tonic-gate */ 30467c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30477c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Improper format"); 30487c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30497c478bd9Sstevel@tonic-gate } 30507c478bd9Sstevel@tonic-gate *s++ = 0; 30517c478bd9Sstevel@tonic-gate 30527c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 30537c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 30547c478bd9Sstevel@tonic-gate 30557c478bd9Sstevel@tonic-gate t = s; 30567c478bd9Sstevel@tonic-gate 30577c478bd9Sstevel@tonic-gate /* 30587c478bd9Sstevel@tonic-gate * shadow last change (col 2) 30597c478bd9Sstevel@tonic-gate */ 30607c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30617c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Improper format"); 30627c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30637c478bd9Sstevel@tonic-gate } 30647c478bd9Sstevel@tonic-gate *s++ = 0; 30657c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val = t; 30667c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_len = strlen(t)+1; 30677c478bd9Sstevel@tonic-gate t = s; 30687c478bd9Sstevel@tonic-gate 30697c478bd9Sstevel@tonic-gate /* 30707c478bd9Sstevel@tonic-gate * shadow min (col 3) 30717c478bd9Sstevel@tonic-gate */ 30727c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30737c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Improper format"); 30747c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30757c478bd9Sstevel@tonic-gate } 30767c478bd9Sstevel@tonic-gate *s++ = 0; 30777c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val = t; 30787c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_len = strlen(t)+1; 30797c478bd9Sstevel@tonic-gate t = s; 30807c478bd9Sstevel@tonic-gate 30817c478bd9Sstevel@tonic-gate /* 30827c478bd9Sstevel@tonic-gate * shadow max (col 4) 30837c478bd9Sstevel@tonic-gate */ 30847c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30857c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Improper format"); 30867c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30877c478bd9Sstevel@tonic-gate } 30887c478bd9Sstevel@tonic-gate *s++ = 0; 30897c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val = t; 30907c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_len = strlen(t)+1; 30917c478bd9Sstevel@tonic-gate t = s; 30927c478bd9Sstevel@tonic-gate 30937c478bd9Sstevel@tonic-gate /* 30947c478bd9Sstevel@tonic-gate * shadow warn (col 5) 30957c478bd9Sstevel@tonic-gate */ 30967c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) == 0) { 30977c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "Improper format"); 30987c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 30997c478bd9Sstevel@tonic-gate } 31007c478bd9Sstevel@tonic-gate *s++ = 0; 31017c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_val = t; 31027c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_len = strlen(t)+1; 31037c478bd9Sstevel@tonic-gate t = s; 31047c478bd9Sstevel@tonic-gate 31057c478bd9Sstevel@tonic-gate /* 31067c478bd9Sstevel@tonic-gate * shadow inactive (col 6) 31077c478bd9Sstevel@tonic-gate */ 31087c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) != 0) { 31097c478bd9Sstevel@tonic-gate *s++ = 0; 31107c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_val = t; 31117c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_len = strlen(t)+1; 31127c478bd9Sstevel@tonic-gate t = s; 31137c478bd9Sstevel@tonic-gate } 31147c478bd9Sstevel@tonic-gate 31157c478bd9Sstevel@tonic-gate /* 31167c478bd9Sstevel@tonic-gate * shadow expire (col 7) 31177c478bd9Sstevel@tonic-gate */ 31187c478bd9Sstevel@tonic-gate if ((s = strchr(t, ':')) != 0) { 31197c478bd9Sstevel@tonic-gate *s++ = 0; 31207c478bd9Sstevel@tonic-gate ecol[7].ec_value.ec_value_val = t; 31217c478bd9Sstevel@tonic-gate ecol[7].ec_value.ec_value_len = strlen(t)+1; 31227c478bd9Sstevel@tonic-gate t = s; 31237c478bd9Sstevel@tonic-gate 31247c478bd9Sstevel@tonic-gate /* 31257c478bd9Sstevel@tonic-gate * flag (col 8) 31267c478bd9Sstevel@tonic-gate */ 31277c478bd9Sstevel@tonic-gate ecol[8].ec_value.ec_value_val = t; 31287c478bd9Sstevel@tonic-gate ecol[8].ec_value.ec_value_len = strlen(t)+1; 31297c478bd9Sstevel@tonic-gate } 31307c478bd9Sstevel@tonic-gate 31317c478bd9Sstevel@tonic-gate /* 31327c478bd9Sstevel@tonic-gate * build entry 31337c478bd9Sstevel@tonic-gate */ 31347c478bd9Sstevel@tonic-gate 31357c478bd9Sstevel@tonic-gate data.sp_namp = strdup(ecol[0].ec_value.ec_value_val); 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate if (ecol[1].ec_value.ec_value_val != NULL && 31387c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val[0] != '\0') { 31397c478bd9Sstevel@tonic-gate /* Add {crypt} before passwd entry */ 31407c478bd9Sstevel@tonic-gate (void) snprintf(pname, sizeof (pname), "{crypt}%s", 31417c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val); 31427c478bd9Sstevel@tonic-gate data.sp_pwdp = strdup(pname); 31437c478bd9Sstevel@tonic-gate } else 31447c478bd9Sstevel@tonic-gate data.sp_pwdp = NULL; 31457c478bd9Sstevel@tonic-gate 31467c478bd9Sstevel@tonic-gate if (ecol[2].ec_value.ec_value_val != NULL && 31477c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val[0] != '\0') { 31487c478bd9Sstevel@tonic-gate 31497c478bd9Sstevel@tonic-gate data.sp_lstchg = ascii_to_int(ecol[2].ec_value.ec_value_val); 31507c478bd9Sstevel@tonic-gate if (data.sp_lstchg < -1) { 31517c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 31527c478bd9Sstevel@tonic-gate "invalid last changed date: %s", 31537c478bd9Sstevel@tonic-gate ecol[2].ec_value.ec_value_val); 31547c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 31557c478bd9Sstevel@tonic-gate } 31567c478bd9Sstevel@tonic-gate } else 31577c478bd9Sstevel@tonic-gate data.sp_lstchg = -1; 31587c478bd9Sstevel@tonic-gate 31597c478bd9Sstevel@tonic-gate if (ecol[3].ec_value.ec_value_val != NULL && 31607c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val[0] != '\0') { 31617c478bd9Sstevel@tonic-gate 31627c478bd9Sstevel@tonic-gate data.sp_min = ascii_to_int(ecol[3].ec_value.ec_value_val); 31637c478bd9Sstevel@tonic-gate if (data.sp_min < -1) { 31647c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 31657c478bd9Sstevel@tonic-gate "invalid sp_min : %s", 31667c478bd9Sstevel@tonic-gate ecol[3].ec_value.ec_value_val); 31677c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 31687c478bd9Sstevel@tonic-gate } 31697c478bd9Sstevel@tonic-gate } else 31707c478bd9Sstevel@tonic-gate data.sp_min = -1; 31717c478bd9Sstevel@tonic-gate 31727c478bd9Sstevel@tonic-gate if (ecol[4].ec_value.ec_value_val != NULL && 31737c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val[0] != '\0') { 31747c478bd9Sstevel@tonic-gate 31757c478bd9Sstevel@tonic-gate data.sp_max = ascii_to_int(ecol[4].ec_value.ec_value_val); 31767c478bd9Sstevel@tonic-gate if (data.sp_max < -1) { 31777c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 31787c478bd9Sstevel@tonic-gate "invalid sp_max : %s", 31797c478bd9Sstevel@tonic-gate ecol[4].ec_value.ec_value_val); 31807c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 31817c478bd9Sstevel@tonic-gate } 31827c478bd9Sstevel@tonic-gate } else 31837c478bd9Sstevel@tonic-gate data.sp_max = -1; 31847c478bd9Sstevel@tonic-gate 31857c478bd9Sstevel@tonic-gate if (ecol[5].ec_value.ec_value_val != NULL && 31867c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_val[0] != '\0') { 31877c478bd9Sstevel@tonic-gate 31887c478bd9Sstevel@tonic-gate data.sp_warn = ascii_to_int(ecol[5].ec_value.ec_value_val); 31897c478bd9Sstevel@tonic-gate if (data.sp_warn < -1) { 31907c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 31917c478bd9Sstevel@tonic-gate "invalid sp_warn : %s", 31927c478bd9Sstevel@tonic-gate ecol[5].ec_value.ec_value_val); 31937c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 31947c478bd9Sstevel@tonic-gate } 31957c478bd9Sstevel@tonic-gate } else 31967c478bd9Sstevel@tonic-gate data.sp_warn = -1; 31977c478bd9Sstevel@tonic-gate 31987c478bd9Sstevel@tonic-gate if (ecol[6].ec_value.ec_value_val != NULL && 31997c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_val[0] != '\0') { 32007c478bd9Sstevel@tonic-gate 32017c478bd9Sstevel@tonic-gate data.sp_inact = ascii_to_int(ecol[6].ec_value.ec_value_val); 32027c478bd9Sstevel@tonic-gate if (data.sp_inact < -1) { 32037c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 32047c478bd9Sstevel@tonic-gate "invalid sp_inact : %s", 32057c478bd9Sstevel@tonic-gate ecol[6].ec_value.ec_value_val); 32067c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 32077c478bd9Sstevel@tonic-gate } 32087c478bd9Sstevel@tonic-gate } else 32097c478bd9Sstevel@tonic-gate data.sp_inact = -1; 32107c478bd9Sstevel@tonic-gate 32117c478bd9Sstevel@tonic-gate if (ecol[7].ec_value.ec_value_val != NULL && 32127c478bd9Sstevel@tonic-gate ecol[7].ec_value.ec_value_val[0] != '\0') { 32137c478bd9Sstevel@tonic-gate 32147c478bd9Sstevel@tonic-gate data.sp_expire = ascii_to_int(ecol[7].ec_value.ec_value_val); 32157c478bd9Sstevel@tonic-gate if (data.sp_expire < -1) { 32167c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 32177c478bd9Sstevel@tonic-gate "invalid login expiry date : %s", 32187c478bd9Sstevel@tonic-gate ecol[7].ec_value.ec_value_val); 32197c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 32207c478bd9Sstevel@tonic-gate } 32217c478bd9Sstevel@tonic-gate } else 32227c478bd9Sstevel@tonic-gate data.sp_expire = -1; 32237c478bd9Sstevel@tonic-gate 32247c478bd9Sstevel@tonic-gate if (ecol[8].ec_value.ec_value_val != NULL && 32257c478bd9Sstevel@tonic-gate ecol[8].ec_value.ec_value_val[0] != '\0') { 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate /* 32287c478bd9Sstevel@tonic-gate * data.sp_flag is an unsigned int, 32297c478bd9Sstevel@tonic-gate * assign -1 to it, make no sense. 32307c478bd9Sstevel@tonic-gate * Use spflag here to avoid lint warning. 32317c478bd9Sstevel@tonic-gate */ 32327c478bd9Sstevel@tonic-gate spflag = ascii_to_int(ecol[8].ec_value.ec_value_val); 32337c478bd9Sstevel@tonic-gate if (spflag < 0) { 32347c478bd9Sstevel@tonic-gate (void) snprintf(parse_err_msg, sizeof (parse_err_msg), 32357c478bd9Sstevel@tonic-gate "invalid flag value: %s", 32367c478bd9Sstevel@tonic-gate ecol[8].ec_value.ec_value_val); 32377c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 32387c478bd9Sstevel@tonic-gate } else 32397c478bd9Sstevel@tonic-gate data.sp_flag = spflag; 32407c478bd9Sstevel@tonic-gate } else 32417c478bd9Sstevel@tonic-gate data.sp_flag = 0; 32427c478bd9Sstevel@tonic-gate 32437c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 32447c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 32457c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.sp_namp); 32467c478bd9Sstevel@tonic-gate 3247*12fbe00aSjs retval = (*cback)(&data, 1); 3248*12fbe00aSjs if (retval != NS_LDAP_SUCCESS) { 3249*12fbe00aSjs if (retval == LDAP_NO_SUCH_OBJECT) 3250*12fbe00aSjs (void) fprintf(stdout, 3251*12fbe00aSjs gettext("Cannot add shadow entry (%s), " 3252*12fbe00aSjs "add passwd entry first\n"), data.sp_namp); 3253*12fbe00aSjs if (continue_onerror == 0) 3254*12fbe00aSjs return (GENENT_CBERR); 3255*12fbe00aSjs } 32567c478bd9Sstevel@tonic-gate 32577c478bd9Sstevel@tonic-gate free(data.sp_namp); 32587c478bd9Sstevel@tonic-gate free(data.sp_pwdp); 32597c478bd9Sstevel@tonic-gate return (GENENT_OK); 32607c478bd9Sstevel@tonic-gate } 32617c478bd9Sstevel@tonic-gate 32627c478bd9Sstevel@tonic-gate static void 32637c478bd9Sstevel@tonic-gate dump_shadow(ns_ldap_result_t *res) 32647c478bd9Sstevel@tonic-gate { 32657c478bd9Sstevel@tonic-gate char **value = NULL; 32667c478bd9Sstevel@tonic-gate char pnam[256]; 32677c478bd9Sstevel@tonic-gate 32687c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "uid"); 32697c478bd9Sstevel@tonic-gate if (value == NULL) 32707c478bd9Sstevel@tonic-gate return; 32717c478bd9Sstevel@tonic-gate else 32727c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 32737c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "userPassword"); 32747c478bd9Sstevel@tonic-gate if (value == NULL) 32757c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 32767c478bd9Sstevel@tonic-gate else { 32777c478bd9Sstevel@tonic-gate (void) strcpy(pnam, value[0]); 32787c478bd9Sstevel@tonic-gate if (strncasecmp(value[0], "{crypt}", 7) == 0) 32797c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", (pnam+7)); 32807c478bd9Sstevel@tonic-gate else 32817c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "*:"); 32827c478bd9Sstevel@tonic-gate } 32837c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "shadowLastChange"); 32847c478bd9Sstevel@tonic-gate if (value == NULL) 32857c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":"); 32867c478bd9Sstevel@tonic-gate else 32877c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 32887c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "shadowMin"); 32897c478bd9Sstevel@tonic-gate if (value == NULL) 32907c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":"); 32917c478bd9Sstevel@tonic-gate else 32927c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 32937c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "shadowMax"); 32947c478bd9Sstevel@tonic-gate if (value == NULL) 32957c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":"); 32967c478bd9Sstevel@tonic-gate else 32977c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s:", value[0]); 32987c478bd9Sstevel@tonic-gate 32997c478bd9Sstevel@tonic-gate /* ignore shadowWarning, shadowInactive, shadowExpire, shadowFlag */ 33007c478bd9Sstevel@tonic-gate (void) fprintf(stdout, ":::\n"); 33017c478bd9Sstevel@tonic-gate 33027c478bd9Sstevel@tonic-gate } 33037c478bd9Sstevel@tonic-gate 33047c478bd9Sstevel@tonic-gate 33057c478bd9Sstevel@tonic-gate static int 33067c478bd9Sstevel@tonic-gate genent_bootparams(char *line, int (*cback)()) 33077c478bd9Sstevel@tonic-gate { 33087c478bd9Sstevel@tonic-gate char buf[BUFSIZ+1]; 33097c478bd9Sstevel@tonic-gate char *t; 33107c478bd9Sstevel@tonic-gate entry_col ecol[2]; 33117c478bd9Sstevel@tonic-gate int ctr = 0, retval = 1; 33127c478bd9Sstevel@tonic-gate 33137c478bd9Sstevel@tonic-gate struct _ns_bootp data; 33147c478bd9Sstevel@tonic-gate char *parameter; 33157c478bd9Sstevel@tonic-gate int rc = GENENT_OK; 33167c478bd9Sstevel@tonic-gate 33177c478bd9Sstevel@tonic-gate /* 33187c478bd9Sstevel@tonic-gate * don't clobber our argument 33197c478bd9Sstevel@tonic-gate */ 33207c478bd9Sstevel@tonic-gate if (strlen(line) >= sizeof (buf)) { 33217c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "line too long"); 33227c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 33237c478bd9Sstevel@tonic-gate } 33247c478bd9Sstevel@tonic-gate (void) strcpy(buf, line); 33257c478bd9Sstevel@tonic-gate 33267c478bd9Sstevel@tonic-gate /* 33277c478bd9Sstevel@tonic-gate * clear column data 33287c478bd9Sstevel@tonic-gate */ 33297c478bd9Sstevel@tonic-gate (void) memset((char *)ecol, 0, sizeof (ecol)); 33307c478bd9Sstevel@tonic-gate 33317c478bd9Sstevel@tonic-gate 33327c478bd9Sstevel@tonic-gate /* 33337c478bd9Sstevel@tonic-gate * cname (col 0) 33347c478bd9Sstevel@tonic-gate */ 33357c478bd9Sstevel@tonic-gate if ((t = strtok(buf, " \t")) == 0) { 33367c478bd9Sstevel@tonic-gate (void) strcpy(parse_err_msg, "no cname"); 33377c478bd9Sstevel@tonic-gate return (GENENT_PARSEERR); 33387c478bd9Sstevel@tonic-gate } 33397c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_val = t; 33407c478bd9Sstevel@tonic-gate ecol[0].ec_value.ec_value_len = strlen(t)+1; 33417c478bd9Sstevel@tonic-gate 33427c478bd9Sstevel@tonic-gate 33437c478bd9Sstevel@tonic-gate 33447c478bd9Sstevel@tonic-gate /* build entry */ 33457c478bd9Sstevel@tonic-gate data.name = strdup(ecol[0].ec_value.ec_value_val); 33467c478bd9Sstevel@tonic-gate 33477c478bd9Sstevel@tonic-gate /* 33487c478bd9Sstevel@tonic-gate * name (col 1) 33497c478bd9Sstevel@tonic-gate */ 33507c478bd9Sstevel@tonic-gate 33517c478bd9Sstevel@tonic-gate data.param = NULL; 33527c478bd9Sstevel@tonic-gate 3353f07af016Sdm while (t = strtok(NULL, " \t")) { 33547c478bd9Sstevel@tonic-gate 33557c478bd9Sstevel@tonic-gate /* 33567c478bd9Sstevel@tonic-gate * don't clobber comment in canonical entry 33577c478bd9Sstevel@tonic-gate */ 33587c478bd9Sstevel@tonic-gate 33597c478bd9Sstevel@tonic-gate 33607c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_val = t; 33617c478bd9Sstevel@tonic-gate ecol[1].ec_value.ec_value_len = strlen(t)+1; 33627c478bd9Sstevel@tonic-gate 33637c478bd9Sstevel@tonic-gate ctr++; 33647c478bd9Sstevel@tonic-gate parameter = strdup(ecol[1].ec_value.ec_value_val); 33657c478bd9Sstevel@tonic-gate if ((data.param = (char **)realloc(data.param, 33667c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 33677c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 33687c478bd9Sstevel@tonic-gate exit(1); 33697c478bd9Sstevel@tonic-gate } 33707c478bd9Sstevel@tonic-gate data.param[ctr-1] = parameter; 33717c478bd9Sstevel@tonic-gate 3372f07af016Sdm } 33737c478bd9Sstevel@tonic-gate 33747c478bd9Sstevel@tonic-gate 33757c478bd9Sstevel@tonic-gate /* End the list of all the aliases by NULL */ 33767c478bd9Sstevel@tonic-gate if ((data.param = (char **)realloc(data.param, 33777c478bd9Sstevel@tonic-gate (ctr + 1) * sizeof (char **))) == NULL) { 33787c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("out of memory\n")); 33797c478bd9Sstevel@tonic-gate exit(1); 33807c478bd9Sstevel@tonic-gate } 33817c478bd9Sstevel@tonic-gate data.param[ctr] = NULL; 33827c478bd9Sstevel@tonic-gate 33837c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 33847c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 33857c478bd9Sstevel@tonic-gate gettext("Adding entry : %s\n"), data.name); 33867c478bd9Sstevel@tonic-gate 33877c478bd9Sstevel@tonic-gate retval = (*cback)(&data, 0); 33887c478bd9Sstevel@tonic-gate 33897c478bd9Sstevel@tonic-gate if (retval == LDAP_ALREADY_EXISTS) { 33907c478bd9Sstevel@tonic-gate if (continue_onerror) 33917c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 33927c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists, skipping it.\n"), 33937c478bd9Sstevel@tonic-gate data.name); 33947c478bd9Sstevel@tonic-gate else { 33957c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 33967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 33977c478bd9Sstevel@tonic-gate gettext("Entry: %s - already Exists\n"), 33987c478bd9Sstevel@tonic-gate data.name); 33997c478bd9Sstevel@tonic-gate } 34007c478bd9Sstevel@tonic-gate } else if (retval) 34017c478bd9Sstevel@tonic-gate rc = GENENT_CBERR; 34027c478bd9Sstevel@tonic-gate 34037c478bd9Sstevel@tonic-gate free(data.name); 34047c478bd9Sstevel@tonic-gate free(data.param); 34057c478bd9Sstevel@tonic-gate 34067c478bd9Sstevel@tonic-gate return (rc); 34077c478bd9Sstevel@tonic-gate 34087c478bd9Sstevel@tonic-gate } 34097c478bd9Sstevel@tonic-gate 34107c478bd9Sstevel@tonic-gate 34117c478bd9Sstevel@tonic-gate static void 34127c478bd9Sstevel@tonic-gate dump_bootparams(ns_ldap_result_t *res) 34137c478bd9Sstevel@tonic-gate { 34147c478bd9Sstevel@tonic-gate char **value = NULL; 34157c478bd9Sstevel@tonic-gate int attr_count = 0; 34167c478bd9Sstevel@tonic-gate 34177c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "cn"); 34187c478bd9Sstevel@tonic-gate if (value[0] != NULL) 34197c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s", value[0]); 34207c478bd9Sstevel@tonic-gate value = __ns_ldap_getAttr(res->entry, "bootParameter"); 34217c478bd9Sstevel@tonic-gate if (value != NULL) 34227c478bd9Sstevel@tonic-gate while (value[attr_count] != NULL) { 34237c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\t%s", value[attr_count]); 34247c478bd9Sstevel@tonic-gate attr_count++; 34257c478bd9Sstevel@tonic-gate } 34267c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 34277c478bd9Sstevel@tonic-gate 34287c478bd9Sstevel@tonic-gate 34297c478bd9Sstevel@tonic-gate } 34307c478bd9Sstevel@tonic-gate 34317c478bd9Sstevel@tonic-gate static char * 34327c478bd9Sstevel@tonic-gate fget_line_at(struct line_buf *line, int n, FILE *fp) 34337c478bd9Sstevel@tonic-gate { 34347c478bd9Sstevel@tonic-gate int c; 34357c478bd9Sstevel@tonic-gate 34367c478bd9Sstevel@tonic-gate line->len = n; 34377c478bd9Sstevel@tonic-gate 34387c478bd9Sstevel@tonic-gate for (;;) { 34397c478bd9Sstevel@tonic-gate c = fgetc(fp); 34407c478bd9Sstevel@tonic-gate if (c == -1) 34417c478bd9Sstevel@tonic-gate break; 34427c478bd9Sstevel@tonic-gate if (line->len >= line->alloc) 34437c478bd9Sstevel@tonic-gate line_buf_expand(line); 34447c478bd9Sstevel@tonic-gate line->str[line->len++] = c; 34457c478bd9Sstevel@tonic-gate 34467c478bd9Sstevel@tonic-gate if (c == '\n') 34477c478bd9Sstevel@tonic-gate break; 34487c478bd9Sstevel@tonic-gate } 34497c478bd9Sstevel@tonic-gate 34507c478bd9Sstevel@tonic-gate /* Null Terminate */ 34517c478bd9Sstevel@tonic-gate if (line->len >= line->alloc) 34527c478bd9Sstevel@tonic-gate line_buf_expand(line); 34537c478bd9Sstevel@tonic-gate line->str[line->len++] = 0; 34547c478bd9Sstevel@tonic-gate 34557c478bd9Sstevel@tonic-gate /* if no characters are read, return NULL to indicate EOF */ 34567c478bd9Sstevel@tonic-gate if (line->str[0] == '\0') 34577c478bd9Sstevel@tonic-gate return (0); 34587c478bd9Sstevel@tonic-gate 34597c478bd9Sstevel@tonic-gate return (line->str); 34607c478bd9Sstevel@tonic-gate } 34617c478bd9Sstevel@tonic-gate 34627c478bd9Sstevel@tonic-gate /* 34637c478bd9Sstevel@tonic-gate * return a line from the file, discarding comments and blank lines 34647c478bd9Sstevel@tonic-gate */ 34657c478bd9Sstevel@tonic-gate static int 34667c478bd9Sstevel@tonic-gate filedbmline_comment(struct line_buf *line, FILE *etcf, int *lineno, 34677c478bd9Sstevel@tonic-gate struct file_loc *loc) 34687c478bd9Sstevel@tonic-gate { 34697c478bd9Sstevel@tonic-gate int i, len = 0; 34707c478bd9Sstevel@tonic-gate 34717c478bd9Sstevel@tonic-gate loc->offset = ftell(etcf); 34727c478bd9Sstevel@tonic-gate for (;;) { 34737c478bd9Sstevel@tonic-gate if (fget_line_at(line, len, etcf) == 0) 34747c478bd9Sstevel@tonic-gate return (0); 34757c478bd9Sstevel@tonic-gate 34767c478bd9Sstevel@tonic-gate if (lineno) 34777c478bd9Sstevel@tonic-gate (*lineno)++; 34787c478bd9Sstevel@tonic-gate 34797c478bd9Sstevel@tonic-gate len = strlen(line->str); 34807c478bd9Sstevel@tonic-gate if (len >= 2 && 34817c478bd9Sstevel@tonic-gate line->str[0] != '#' && 34827c478bd9Sstevel@tonic-gate line->str[len-2] == '\\' && line->str[len-1] == '\n') { 34837c478bd9Sstevel@tonic-gate line->str[len-2] = 0; 34847c478bd9Sstevel@tonic-gate len -= 2; 34857c478bd9Sstevel@tonic-gate continue; /* append next line at end */ 34867c478bd9Sstevel@tonic-gate } 34877c478bd9Sstevel@tonic-gate 34887c478bd9Sstevel@tonic-gate if (line->str[len-1] == '\n') { 34897c478bd9Sstevel@tonic-gate line->str[len-1] = 0; 34907c478bd9Sstevel@tonic-gate len -= 1; 34917c478bd9Sstevel@tonic-gate } 34927c478bd9Sstevel@tonic-gate 34937c478bd9Sstevel@tonic-gate /* 34947c478bd9Sstevel@tonic-gate * Skip lines where '#' is the first non-blank character. 34957c478bd9Sstevel@tonic-gate */ 34967c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) { 34977c478bd9Sstevel@tonic-gate if (line->str[i] == '#') { 34987c478bd9Sstevel@tonic-gate line->str[i] = '\0'; 34997c478bd9Sstevel@tonic-gate len = i; 35007c478bd9Sstevel@tonic-gate break; 35017c478bd9Sstevel@tonic-gate } 35027c478bd9Sstevel@tonic-gate if (line->str[i] != ' ' && line->str[i] != '\t') 35037c478bd9Sstevel@tonic-gate break; 35047c478bd9Sstevel@tonic-gate } 35057c478bd9Sstevel@tonic-gate 35067c478bd9Sstevel@tonic-gate /* 35077c478bd9Sstevel@tonic-gate * A line with one or more white space characters followed 35087c478bd9Sstevel@tonic-gate * by a comment will now be blank. The special case of a 35097c478bd9Sstevel@tonic-gate * line with '#' in the first byte will have len == 0. 35107c478bd9Sstevel@tonic-gate */ 35117c478bd9Sstevel@tonic-gate if (len > 0 && !blankline(line->str)) 35127c478bd9Sstevel@tonic-gate break; 35137c478bd9Sstevel@tonic-gate 35147c478bd9Sstevel@tonic-gate len = 0; 35157c478bd9Sstevel@tonic-gate loc->offset = ftell(etcf); 35167c478bd9Sstevel@tonic-gate } 35177c478bd9Sstevel@tonic-gate 35187c478bd9Sstevel@tonic-gate loc->size = len; 35197c478bd9Sstevel@tonic-gate return (1); 35207c478bd9Sstevel@tonic-gate } 35217c478bd9Sstevel@tonic-gate 35227c478bd9Sstevel@tonic-gate /* 35237c478bd9Sstevel@tonic-gate * return a line from the file, discarding comments, blanks, and '+' lines 35247c478bd9Sstevel@tonic-gate */ 35257c478bd9Sstevel@tonic-gate static int 35267c478bd9Sstevel@tonic-gate filedbmline_plus(struct line_buf *line, FILE *etcf, int *lineno, 35277c478bd9Sstevel@tonic-gate struct file_loc *loc) 35287c478bd9Sstevel@tonic-gate { 35297c478bd9Sstevel@tonic-gate int len = 0; 35307c478bd9Sstevel@tonic-gate 35317c478bd9Sstevel@tonic-gate loc->offset = ftell(etcf); 35327c478bd9Sstevel@tonic-gate for (;;) { 35337c478bd9Sstevel@tonic-gate if (fget_line_at(line, len, etcf) == 0) 35347c478bd9Sstevel@tonic-gate return (0); 35357c478bd9Sstevel@tonic-gate 35367c478bd9Sstevel@tonic-gate if (lineno) 35377c478bd9Sstevel@tonic-gate (*lineno)++; 35387c478bd9Sstevel@tonic-gate 35397c478bd9Sstevel@tonic-gate len = strlen(line->str); 35407c478bd9Sstevel@tonic-gate if (line->str[len-1] == '\n') { 35417c478bd9Sstevel@tonic-gate line->str[len-1] = 0; 35427c478bd9Sstevel@tonic-gate len -= 1; 35437c478bd9Sstevel@tonic-gate } 35447c478bd9Sstevel@tonic-gate 35457c478bd9Sstevel@tonic-gate if (!blankline(line->str) && 35467c478bd9Sstevel@tonic-gate line->str[0] != '+' && line->str[0] != '-' && 35477c478bd9Sstevel@tonic-gate line->str[0] != '#') 35487c478bd9Sstevel@tonic-gate break; 35497c478bd9Sstevel@tonic-gate 35507c478bd9Sstevel@tonic-gate len = 0; 35517c478bd9Sstevel@tonic-gate loc->offset = ftell(etcf); 35527c478bd9Sstevel@tonic-gate } 35537c478bd9Sstevel@tonic-gate 35547c478bd9Sstevel@tonic-gate loc->size = len; 35557c478bd9Sstevel@tonic-gate return (1); 35567c478bd9Sstevel@tonic-gate } 35577c478bd9Sstevel@tonic-gate 35587c478bd9Sstevel@tonic-gate 35597c478bd9Sstevel@tonic-gate /* Populating the ttypelist structure */ 35607c478bd9Sstevel@tonic-gate 35617c478bd9Sstevel@tonic-gate static struct ttypelist_t ttypelist[] = { 35627c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_HOSTS, genent_hosts, dump_hosts, 35637c478bd9Sstevel@tonic-gate filedbmline_comment, "iphost" }, 35647c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_IPNODES, genent_hosts, dump_hosts, 35657c478bd9Sstevel@tonic-gate filedbmline_comment, "iphost" }, 35667c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_RPC, genent_rpc, dump_rpc, 35677c478bd9Sstevel@tonic-gate filedbmline_comment, "oncrpc" }, 35687c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROTOCOLS, genent_protocols, dump_protocols, 35697c478bd9Sstevel@tonic-gate filedbmline_comment, "ipprotocol" }, 35707c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETWORKS, genent_networks, dump_networks, 35717c478bd9Sstevel@tonic-gate filedbmline_comment, "ipnetwork" }, 35727c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SERVICES, genent_services, dump_services, 35737c478bd9Sstevel@tonic-gate filedbmline_comment, "ipservice" }, 35747c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_GROUP, genent_group, dump_group, 35757c478bd9Sstevel@tonic-gate filedbmline_plus, "posixgroup" }, 35767c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETMASKS, genent_netmasks, dump_netmasks, 35777c478bd9Sstevel@tonic-gate filedbmline_comment, "ipnetwork" }, 35787c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ETHERS, genent_ethers, dump_ethers, 35797c478bd9Sstevel@tonic-gate filedbmline_comment, "ieee802Device" }, 35807c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_NETGROUP, genent_netgroup, dump_netgroup, 35817c478bd9Sstevel@tonic-gate filedbmline_comment, "nisnetgroup" }, 35827c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_BOOTPARAMS, genent_bootparams, dump_bootparams, 35837c478bd9Sstevel@tonic-gate filedbmline_comment, "bootableDevice" }, 35847c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PUBLICKEY, genent_publickey, NULL /* dump_publickey */, 35857c478bd9Sstevel@tonic-gate filedbmline_comment, "niskeyobject" }, 35867c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PASSWD, genent_passwd, dump_passwd, 35877c478bd9Sstevel@tonic-gate filedbmline_plus, "posixaccount" }, 35887c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_SHADOW, genent_shadow, dump_shadow, 35897c478bd9Sstevel@tonic-gate filedbmline_plus, "shadowaccount" }, 35907c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_ALIASES, genent_aliases, dump_aliases, 35917c478bd9Sstevel@tonic-gate filedbmline_plus, "mailGroup" }, 35927c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTOMOUNT, genent_automount, dump_automount, 35937c478bd9Sstevel@tonic-gate filedbmline_comment, "automount" }, 35947c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_USERATTR, genent_user_attr, dump_user_attr, 35957c478bd9Sstevel@tonic-gate filedbmline_comment, "SolarisUserAttr" }, 35967c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_PROFILE, genent_prof_attr, dump_prof_attr, 35977c478bd9Sstevel@tonic-gate filedbmline_comment, "SolarisProfAttr" }, 35987c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_EXECATTR, genent_exec_attr, dump_exec_attr, 35997c478bd9Sstevel@tonic-gate filedbmline_comment, "SolarisExecAttr" }, 36007c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUTHATTR, genent_auth_attr, dump_auth_attr, 36017c478bd9Sstevel@tonic-gate filedbmline_comment, "SolarisAuthAttr" }, 36027c478bd9Sstevel@tonic-gate { NS_LDAP_TYPE_AUUSER, genent_audit_user, dump_audit_user, 36037c478bd9Sstevel@tonic-gate filedbmline_comment, "SolarisAuditUser" }, 360445916cd2Sjpk { NS_LDAP_TYPE_TNRHDB, genent_tnrhdb, dump_tnrhdb, 360545916cd2Sjpk filedbmline_comment, "ipTnetHost" }, 360645916cd2Sjpk { NS_LDAP_TYPE_TNRHTP, genent_tnrhtp, dump_tnrhtp, 360745916cd2Sjpk filedbmline_comment, "ipTnetTemplate" }, 36087c478bd9Sstevel@tonic-gate { 0, 0, 0, 0, 0 } 36097c478bd9Sstevel@tonic-gate }; 36107c478bd9Sstevel@tonic-gate 36117c478bd9Sstevel@tonic-gate 36127c478bd9Sstevel@tonic-gate 36137c478bd9Sstevel@tonic-gate 36147c478bd9Sstevel@tonic-gate static int lineno = 0; 36157c478bd9Sstevel@tonic-gate 36167c478bd9Sstevel@tonic-gate static void 36177c478bd9Sstevel@tonic-gate addfile() 36187c478bd9Sstevel@tonic-gate { 36197c478bd9Sstevel@tonic-gate struct line_buf line; 36207c478bd9Sstevel@tonic-gate struct file_loc loc; 36217c478bd9Sstevel@tonic-gate 36227c478bd9Sstevel@tonic-gate /* Initializing the Line Buffer */ 36237c478bd9Sstevel@tonic-gate line_buf_init(&line); 36247c478bd9Sstevel@tonic-gate 36257c478bd9Sstevel@tonic-gate /* Loop through all the lines in the file */ 36267c478bd9Sstevel@tonic-gate while (tt->filedbmline(&line, etcf, &lineno, &loc)) { 36277c478bd9Sstevel@tonic-gate switch ((*(tt->genent))(line.str, addentry)) { 36287c478bd9Sstevel@tonic-gate case GENENT_OK: 36297c478bd9Sstevel@tonic-gate break; 36307c478bd9Sstevel@tonic-gate case GENENT_PARSEERR: 36317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 36327c478bd9Sstevel@tonic-gate gettext("parse error: %s (line %d)\n"), 36337c478bd9Sstevel@tonic-gate parse_err_msg, lineno); 36347c478bd9Sstevel@tonic-gate exit_val = 1; 36357c478bd9Sstevel@tonic-gate break; 36367c478bd9Sstevel@tonic-gate case GENENT_CBERR: 36377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 36387c478bd9Sstevel@tonic-gate gettext("Error while adding line: %s\n"), 36397c478bd9Sstevel@tonic-gate line.str); 36407c478bd9Sstevel@tonic-gate exit_val = 2; 36417c478bd9Sstevel@tonic-gate free(line.str); 36427c478bd9Sstevel@tonic-gate return; 36437c478bd9Sstevel@tonic-gate break; 36447c478bd9Sstevel@tonic-gate case GENENT_ERR: 36457c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 36467c478bd9Sstevel@tonic-gate gettext("Internal Error while adding line: %s\n"), 36477c478bd9Sstevel@tonic-gate line.str); 36487c478bd9Sstevel@tonic-gate exit_val = 3; 36497c478bd9Sstevel@tonic-gate free(line.str); 36507c478bd9Sstevel@tonic-gate return; 36517c478bd9Sstevel@tonic-gate break; 36527c478bd9Sstevel@tonic-gate } 36537c478bd9Sstevel@tonic-gate } 36547c478bd9Sstevel@tonic-gate free(line.str); 36557c478bd9Sstevel@tonic-gate } 36567c478bd9Sstevel@tonic-gate 36577c478bd9Sstevel@tonic-gate static void 36587c478bd9Sstevel@tonic-gate dumptable(char *service) 36597c478bd9Sstevel@tonic-gate { 36607c478bd9Sstevel@tonic-gate 36617c478bd9Sstevel@tonic-gate ns_ldap_result_t *eres = NULL; 36627c478bd9Sstevel@tonic-gate ns_ldap_error_t *err = NULL; 36637c478bd9Sstevel@tonic-gate int rc = 0, success = 0; 36647c478bd9Sstevel@tonic-gate char filter[BUFSIZ]; 36657c478bd9Sstevel@tonic-gate int done = 0; 36667c478bd9Sstevel@tonic-gate void *cookie = NULL; 36677c478bd9Sstevel@tonic-gate 36687c478bd9Sstevel@tonic-gate /* set the appropriate filter */ 36697c478bd9Sstevel@tonic-gate if (strcmp(tt->ttype, NS_LDAP_TYPE_PROFILE) == 0) { 36707c478bd9Sstevel@tonic-gate /* 36717c478bd9Sstevel@tonic-gate * prof_attr entries are SolarisProfAttr 36727c478bd9Sstevel@tonic-gate * without AUXILIARY SolarisExecAttr 36737c478bd9Sstevel@tonic-gate */ 36747c478bd9Sstevel@tonic-gate (void) snprintf(filter, sizeof (filter), 36757c478bd9Sstevel@tonic-gate "(&(objectclass=%s)(!(objectclass=SolarisExecAttr)))", 36767c478bd9Sstevel@tonic-gate tt->objclass); 367745916cd2Sjpk } else if (strcmp(tt->ttype, NS_LDAP_TYPE_TNRHDB) == 0) { 367845916cd2Sjpk /* 367945916cd2Sjpk * tnrhtp entries are ipTnet entries with SolarisAttrKeyValue 368045916cd2Sjpk */ 368145916cd2Sjpk (void) snprintf(filter, sizeof (filter), 368245916cd2Sjpk "(&(objectclass=%s)(SolarisAttrKeyValue=*)))", 368345916cd2Sjpk tt->objclass); 368445916cd2Sjpk } else { 36857c478bd9Sstevel@tonic-gate (void) snprintf(filter, sizeof (filter), 36867c478bd9Sstevel@tonic-gate "(objectclass=%s)", tt->objclass); 368745916cd2Sjpk } 36887c478bd9Sstevel@tonic-gate 36897c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 36907c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("FILTER = %s\n"), filter); 36917c478bd9Sstevel@tonic-gate 36927c478bd9Sstevel@tonic-gate /* Pass cred only if supplied. Cred is not always needed for dump */ 36937c478bd9Sstevel@tonic-gate if (authority.cred.unix_cred.userID == NULL || 36947c478bd9Sstevel@tonic-gate authority.cred.unix_cred.passwd == NULL) 36957c478bd9Sstevel@tonic-gate rc = __ns_ldap_firstEntry(service, filter, NULL, NULL, 36967c478bd9Sstevel@tonic-gate NULL, NS_LDAP_HARD, &cookie, &eres, &err, NULL); 36977c478bd9Sstevel@tonic-gate else 36987c478bd9Sstevel@tonic-gate rc = __ns_ldap_firstEntry(service, filter, NULL, NULL, 36997c478bd9Sstevel@tonic-gate &authority, NS_LDAP_HARD, &cookie, &eres, &err, NULL); 37007c478bd9Sstevel@tonic-gate 37017c478bd9Sstevel@tonic-gate switch (rc) { 37027c478bd9Sstevel@tonic-gate case NS_LDAP_SUCCESS: 37037c478bd9Sstevel@tonic-gate nent_add++; 37047c478bd9Sstevel@tonic-gate success = 1; 37057c478bd9Sstevel@tonic-gate if (eres != NULL) { 37067c478bd9Sstevel@tonic-gate if (strcmp(databasetype, "publickey") == 0) 37077c478bd9Sstevel@tonic-gate dump_publickey(eres, service); 37087c478bd9Sstevel@tonic-gate else 37097c478bd9Sstevel@tonic-gate (*(tt->dump))(eres); 37107c478bd9Sstevel@tonic-gate } 37117c478bd9Sstevel@tonic-gate else 37127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("No entries found.\n")); 37137c478bd9Sstevel@tonic-gate break; 37147c478bd9Sstevel@tonic-gate 37157c478bd9Sstevel@tonic-gate case NS_LDAP_OP_FAILED: 37167c478bd9Sstevel@tonic-gate exit_val = 2; 37177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("operation failed.\n")); 37187c478bd9Sstevel@tonic-gate break; 37197c478bd9Sstevel@tonic-gate 37207c478bd9Sstevel@tonic-gate case NS_LDAP_INVALID_PARAM: 37217c478bd9Sstevel@tonic-gate exit_val = 2; 37227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 37237c478bd9Sstevel@tonic-gate gettext("invalid parameter(s) passed.\n")); 37247c478bd9Sstevel@tonic-gate break; 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate case NS_LDAP_NOTFOUND: 37277c478bd9Sstevel@tonic-gate exit_val = 2; 37287c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("entry not found.\n")); 37297c478bd9Sstevel@tonic-gate break; 37307c478bd9Sstevel@tonic-gate 37317c478bd9Sstevel@tonic-gate case NS_LDAP_MEMORY: 37327c478bd9Sstevel@tonic-gate exit_val = 2; 37337c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 37347c478bd9Sstevel@tonic-gate gettext("internal memory allocation error.\n")); 37357c478bd9Sstevel@tonic-gate break; 37367c478bd9Sstevel@tonic-gate 37377c478bd9Sstevel@tonic-gate case NS_LDAP_CONFIG: 37387c478bd9Sstevel@tonic-gate exit_val = 2; 37397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 37407c478bd9Sstevel@tonic-gate gettext("LDAP Configuration problem.\n")); 37417c478bd9Sstevel@tonic-gate perr(err); 37427c478bd9Sstevel@tonic-gate break; 37437c478bd9Sstevel@tonic-gate 37447c478bd9Sstevel@tonic-gate case NS_LDAP_PARTIAL: 37457c478bd9Sstevel@tonic-gate exit_val = 2; 37467c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 37477c478bd9Sstevel@tonic-gate gettext("partial result returned\n")); 37487c478bd9Sstevel@tonic-gate perr(err); 37497c478bd9Sstevel@tonic-gate break; 37507c478bd9Sstevel@tonic-gate 37517c478bd9Sstevel@tonic-gate case NS_LDAP_INTERNAL: 37527c478bd9Sstevel@tonic-gate exit_val = 2; 37537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 37547c478bd9Sstevel@tonic-gate gettext("internal LDAP error occured.\n")); 37557c478bd9Sstevel@tonic-gate perr(err); 37567c478bd9Sstevel@tonic-gate break; 37577c478bd9Sstevel@tonic-gate } 37587c478bd9Sstevel@tonic-gate 37597c478bd9Sstevel@tonic-gate if (eres != NULL) { 37607c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&eres); 37617c478bd9Sstevel@tonic-gate eres = NULL; 37627c478bd9Sstevel@tonic-gate } 37637c478bd9Sstevel@tonic-gate 37647c478bd9Sstevel@tonic-gate if (success) { 37657c478bd9Sstevel@tonic-gate while (!done) { 37667c478bd9Sstevel@tonic-gate rc = __ns_ldap_nextEntry(cookie, &eres, &err); 37677c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS || eres == NULL) { 37687c478bd9Sstevel@tonic-gate done = 1; 37697c478bd9Sstevel@tonic-gate continue; 37707c478bd9Sstevel@tonic-gate } 37717c478bd9Sstevel@tonic-gate 37727c478bd9Sstevel@tonic-gate /* Print the result */ 37737c478bd9Sstevel@tonic-gate if (eres != NULL) { 37747c478bd9Sstevel@tonic-gate if (strcmp(databasetype, "publickey") == 0) 37757c478bd9Sstevel@tonic-gate dump_publickey(eres, service); 37767c478bd9Sstevel@tonic-gate else 37777c478bd9Sstevel@tonic-gate (*(tt->dump))(eres); 37787c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeResult(&eres); 37797c478bd9Sstevel@tonic-gate eres = NULL; 37807c478bd9Sstevel@tonic-gate } 37817c478bd9Sstevel@tonic-gate } 37827c478bd9Sstevel@tonic-gate } 37837c478bd9Sstevel@tonic-gate } 37847c478bd9Sstevel@tonic-gate 3785a506a34cSth int 37867c478bd9Sstevel@tonic-gate main(int argc, char **argv) 37877c478bd9Sstevel@tonic-gate { 37887c478bd9Sstevel@tonic-gate char *password; 37897c478bd9Sstevel@tonic-gate int c; 37907c478bd9Sstevel@tonic-gate int rc; 37917c478bd9Sstevel@tonic-gate int ldaprc; 37927c478bd9Sstevel@tonic-gate int authstried = 0; 37937c478bd9Sstevel@tonic-gate int supportedauth = 0; 37947c478bd9Sstevel@tonic-gate int op = OP_ADD; 37957c478bd9Sstevel@tonic-gate char *ttype, *authmech = 0, *etcfile = 0; 37967c478bd9Sstevel@tonic-gate char ps[LDAP_MAXNAMELEN]; /* Temporary password variable */ 37977c478bd9Sstevel@tonic-gate char filter[BUFSIZ]; 37987c478bd9Sstevel@tonic-gate void **paramVal = NULL; 37997c478bd9Sstevel@tonic-gate ns_auth_t **app; 38007c478bd9Sstevel@tonic-gate ns_auth_t **authpp = NULL; 38017c478bd9Sstevel@tonic-gate ns_auth_t *authp = NULL; 38027c478bd9Sstevel@tonic-gate ns_ldap_error_t *errorp = NULL; 38037c478bd9Sstevel@tonic-gate ns_ldap_result_t *resultp; 38047c478bd9Sstevel@tonic-gate ns_ldap_entry_t *e; 38057c478bd9Sstevel@tonic-gate int flag = 0; 38067c478bd9Sstevel@tonic-gate int version1 = 0; 38077c478bd9Sstevel@tonic-gate 38087c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 38097c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 38107c478bd9Sstevel@tonic-gate 38117c478bd9Sstevel@tonic-gate openlog("ldapaddent", LOG_PID, LOG_USER); 38127c478bd9Sstevel@tonic-gate 38137c478bd9Sstevel@tonic-gate inputbasedn = NULL; 38147c478bd9Sstevel@tonic-gate authority.cred.unix_cred.passwd = NULL; 38157c478bd9Sstevel@tonic-gate authority.cred.unix_cred.userID = NULL; 38167c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_SIMPLE; 38177c478bd9Sstevel@tonic-gate 38187c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "cdhvpf:D:w:b:a:")) != EOF) { 38197c478bd9Sstevel@tonic-gate switch (c) { 38207c478bd9Sstevel@tonic-gate case 'd': 38217c478bd9Sstevel@tonic-gate if (op) 38227c478bd9Sstevel@tonic-gate usage("no other option should be specified"); 38237c478bd9Sstevel@tonic-gate op = OP_DUMP; 38247c478bd9Sstevel@tonic-gate break; 38257c478bd9Sstevel@tonic-gate case 'c': 38267c478bd9Sstevel@tonic-gate continue_onerror = 1; 38277c478bd9Sstevel@tonic-gate break; 38287c478bd9Sstevel@tonic-gate case 'v': 38297c478bd9Sstevel@tonic-gate flags |= F_VERBOSE; 38307c478bd9Sstevel@tonic-gate break; 38317c478bd9Sstevel@tonic-gate case 'p': 38327c478bd9Sstevel@tonic-gate flags |= F_PASSWD; 38337c478bd9Sstevel@tonic-gate break; 38347c478bd9Sstevel@tonic-gate case 'f': 38357c478bd9Sstevel@tonic-gate etcfile = optarg; 38367c478bd9Sstevel@tonic-gate break; 38377c478bd9Sstevel@tonic-gate case 'D': 38387c478bd9Sstevel@tonic-gate authority.cred.unix_cred.userID = strdup(optarg); 38397c478bd9Sstevel@tonic-gate break; 38407c478bd9Sstevel@tonic-gate case 'w': 38417c478bd9Sstevel@tonic-gate authority.cred.unix_cred.passwd = strdup(optarg); 38427c478bd9Sstevel@tonic-gate break; 38437c478bd9Sstevel@tonic-gate case 'b': 38447c478bd9Sstevel@tonic-gate inputbasedn = strdup(optarg); 38457c478bd9Sstevel@tonic-gate break; 38467c478bd9Sstevel@tonic-gate case 'a': 38477c478bd9Sstevel@tonic-gate authmech = strdup(optarg); 38487c478bd9Sstevel@tonic-gate break; 38497c478bd9Sstevel@tonic-gate 38507c478bd9Sstevel@tonic-gate default: 38517c478bd9Sstevel@tonic-gate usage(gettext("Invalid option")); 38527c478bd9Sstevel@tonic-gate } 38537c478bd9Sstevel@tonic-gate } 38547c478bd9Sstevel@tonic-gate 38557c478bd9Sstevel@tonic-gate 38567c478bd9Sstevel@tonic-gate if (authority.cred.unix_cred.userID == NULL && op != OP_DUMP) { 38577c478bd9Sstevel@tonic-gate /* This is not an optional parameter. Exit */ 38587c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 38597c478bd9Sstevel@tonic-gate gettext("Distinguished Name to bind to directory" 38607c478bd9Sstevel@tonic-gate " must be specified. use option -D.\n")); 38617c478bd9Sstevel@tonic-gate exit(1); 38627c478bd9Sstevel@tonic-gate } 38637c478bd9Sstevel@tonic-gate 38647c478bd9Sstevel@tonic-gate if (authority.cred.unix_cred.passwd == NULL && op != OP_DUMP) { 38657c478bd9Sstevel@tonic-gate /* If password is not specified, then prompt user for it. */ 38667c478bd9Sstevel@tonic-gate password = getpassphrase("Enter password:"); 38677c478bd9Sstevel@tonic-gate (void) strcpy(ps, password); 38687c478bd9Sstevel@tonic-gate authority.cred.unix_cred.passwd = strdup(ps); 38697c478bd9Sstevel@tonic-gate } 38707c478bd9Sstevel@tonic-gate 38717c478bd9Sstevel@tonic-gate if (authmech != NULL) { 38727c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "simple") == 0) { 38737c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_SIMPLE; 38747c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_NONE; 38757c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_NONE; 38767c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 38777c478bd9Sstevel@tonic-gate supportedauth = 1; 38787c478bd9Sstevel@tonic-gate } 38797c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "sasl/CRAM-MD5") == 0) { 38807c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_SASL; 38817c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_SASL; 38827c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_CRAM_MD5; 38837c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 38847c478bd9Sstevel@tonic-gate supportedauth = 1; 38857c478bd9Sstevel@tonic-gate } 38867c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "sasl/DIGEST-MD5") == 0) { 38877c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_SASL; 38887c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_SASL; 38897c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_DIGEST_MD5; 38907c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 38917c478bd9Sstevel@tonic-gate supportedauth = 1; 38927c478bd9Sstevel@tonic-gate } 38937c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "tls:simple") == 0) { 38947c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_TLS; 38957c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_SIMPLE; 38967c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_NONE; 38977c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 38987c478bd9Sstevel@tonic-gate supportedauth = 1; 38997c478bd9Sstevel@tonic-gate } 39007c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "tls:sasl/CRAM-MD5") == 0) { 39017c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_TLS; 39027c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_SASL; 39037c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_CRAM_MD5; 39047c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 39057c478bd9Sstevel@tonic-gate supportedauth = 1; 39067c478bd9Sstevel@tonic-gate } 39077c478bd9Sstevel@tonic-gate if (strcasecmp(authmech, "tls:sasl/DIGEST-MD5") == 0) { 39087c478bd9Sstevel@tonic-gate authority.auth.type = NS_LDAP_AUTH_TLS; 39097c478bd9Sstevel@tonic-gate authority.auth.tlstype = NS_LDAP_TLS_SASL; 39107c478bd9Sstevel@tonic-gate authority.auth.saslmech = NS_LDAP_SASL_DIGEST_MD5; 39117c478bd9Sstevel@tonic-gate authority.auth.saslopt = NS_LDAP_SASLOPT_NONE; 39127c478bd9Sstevel@tonic-gate supportedauth = 1; 39137c478bd9Sstevel@tonic-gate } 39147c478bd9Sstevel@tonic-gate if (!supportedauth) { 39157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39167c478bd9Sstevel@tonic-gate gettext("Invalid authentication method specified")); 39177c478bd9Sstevel@tonic-gate exit(1); 39187c478bd9Sstevel@tonic-gate } 39197c478bd9Sstevel@tonic-gate } 39207c478bd9Sstevel@tonic-gate 39217c478bd9Sstevel@tonic-gate if (authmech == NULL) { 39227c478bd9Sstevel@tonic-gate ldaprc = __ns_ldap_getParam(NS_LDAP_AUTH_P, (void ***)&authpp, 39237c478bd9Sstevel@tonic-gate &errorp); 39247c478bd9Sstevel@tonic-gate if (ldaprc != NS_LDAP_SUCCESS || 39257c478bd9Sstevel@tonic-gate (authpp == NULL && op != OP_DUMP)) { 39267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39277c478bd9Sstevel@tonic-gate gettext("No legal authentication method " 39287c478bd9Sstevel@tonic-gate "configured.\n")); 39297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39307c478bd9Sstevel@tonic-gate gettext("Provide a legal authentication method " 39317c478bd9Sstevel@tonic-gate "using -a option\n")); 39327c478bd9Sstevel@tonic-gate exit(1); 39337c478bd9Sstevel@tonic-gate } 39347c478bd9Sstevel@tonic-gate 39357c478bd9Sstevel@tonic-gate /* Use the first authentication method which is not none */ 39367c478bd9Sstevel@tonic-gate for (app = authpp; *app; app++) { 39377c478bd9Sstevel@tonic-gate authp = *app; 39387c478bd9Sstevel@tonic-gate if (authp->type != NS_LDAP_AUTH_NONE) { 39397c478bd9Sstevel@tonic-gate authstried++; 39407c478bd9Sstevel@tonic-gate authority.auth.type = authp->type; 39417c478bd9Sstevel@tonic-gate authority.auth.tlstype = authp->tlstype; 39427c478bd9Sstevel@tonic-gate authority.auth.saslmech = authp->saslmech; 39437c478bd9Sstevel@tonic-gate authority.auth.saslopt = authp->saslopt; 39447c478bd9Sstevel@tonic-gate break; 39457c478bd9Sstevel@tonic-gate } 39467c478bd9Sstevel@tonic-gate } 39477c478bd9Sstevel@tonic-gate if (authstried == 0 && op != OP_DUMP) { 39487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39497c478bd9Sstevel@tonic-gate gettext("No legal authentication method configured.\n" 39507c478bd9Sstevel@tonic-gate "Provide a legal authentication method using " 39517c478bd9Sstevel@tonic-gate "-a option")); 39527c478bd9Sstevel@tonic-gate exit(1); 39537c478bd9Sstevel@tonic-gate } 39547c478bd9Sstevel@tonic-gate } 39557c478bd9Sstevel@tonic-gate 39567c478bd9Sstevel@tonic-gate ttype = argv[optind++]; 39577c478bd9Sstevel@tonic-gate 39587c478bd9Sstevel@tonic-gate if (ttype == NULL) { 39597c478bd9Sstevel@tonic-gate usage(gettext("No database type specified")); 39607c478bd9Sstevel@tonic-gate exit(1); 39617c478bd9Sstevel@tonic-gate } 39627c478bd9Sstevel@tonic-gate 39637c478bd9Sstevel@tonic-gate if (strncasecmp(ttype, "automount", 9) == 0) { 39647c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39657c478bd9Sstevel@tonic-gate gettext("automount is not a valid service for ldapaddent.\n" 39667c478bd9Sstevel@tonic-gate "Please use auto_*.\n" 39677c478bd9Sstevel@tonic-gate "e.g. auto_home, auto_ws etc.\n ")); 39687c478bd9Sstevel@tonic-gate exit(1); 39697c478bd9Sstevel@tonic-gate } 39707c478bd9Sstevel@tonic-gate 39717c478bd9Sstevel@tonic-gate for (tt = ttypelist; tt->ttype; tt++) { 39727c478bd9Sstevel@tonic-gate if (strcmp(tt->ttype, ttype) == 0) 39737c478bd9Sstevel@tonic-gate break; 39747c478bd9Sstevel@tonic-gate if (strcmp(tt->ttype, NS_LDAP_TYPE_AUTOMOUNT) == 0 && 39757c478bd9Sstevel@tonic-gate strncmp(ttype, NS_LDAP_TYPE_AUTOMOUNT, 39767c478bd9Sstevel@tonic-gate sizeof (NS_LDAP_TYPE_AUTOMOUNT) - 1) == 0) 39777c478bd9Sstevel@tonic-gate break; 39787c478bd9Sstevel@tonic-gate } 39797c478bd9Sstevel@tonic-gate 39807c478bd9Sstevel@tonic-gate if (tt->ttype == 0) { 39817c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 39827c478bd9Sstevel@tonic-gate gettext("database %s not supported;" 39837c478bd9Sstevel@tonic-gate " supported databases are:\n"), ttype); 39847c478bd9Sstevel@tonic-gate for (tt = ttypelist; tt->ttype; tt++) 39857c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("\t%s\n"), tt->ttype); 39867c478bd9Sstevel@tonic-gate exit(1); 39877c478bd9Sstevel@tonic-gate } 39887c478bd9Sstevel@tonic-gate 39897c478bd9Sstevel@tonic-gate if (flags & F_VERBOSE) 39907c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("SERVICE = %s\n"), tt->ttype); 39917c478bd9Sstevel@tonic-gate 39927c478bd9Sstevel@tonic-gate databasetype = ttype; 39937c478bd9Sstevel@tonic-gate 39947c478bd9Sstevel@tonic-gate if (strcmp(tt->ttype, NS_LDAP_TYPE_AUTOMOUNT) == 0) { 39957c478bd9Sstevel@tonic-gate paramVal = NULL; 39967c478bd9Sstevel@tonic-gate errorp = NULL; 39977c478bd9Sstevel@tonic-gate rc = __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P, ¶mVal, 39987c478bd9Sstevel@tonic-gate &errorp); 39997c478bd9Sstevel@tonic-gate if (paramVal && *paramVal && 40007c478bd9Sstevel@tonic-gate strcasecmp(*paramVal, NS_LDAP_VERSION_1) == 0) 40017c478bd9Sstevel@tonic-gate version1 = 1; 40027c478bd9Sstevel@tonic-gate if (paramVal) 40037c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 40047c478bd9Sstevel@tonic-gate if (errorp) 40057c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(&errorp); 40067c478bd9Sstevel@tonic-gate } 40077c478bd9Sstevel@tonic-gate 40087c478bd9Sstevel@tonic-gate /* Check if the container exists in first place */ 40097c478bd9Sstevel@tonic-gate (void) strcpy(&filter[0], "(objectclass=*)"); 40107c478bd9Sstevel@tonic-gate 40117c478bd9Sstevel@tonic-gate rc = __ns_ldap_list(databasetype, filter, NULL, (const char **)NULL, 40127c478bd9Sstevel@tonic-gate NULL, NS_LDAP_SCOPE_BASE, &resultp, &errorp, NULL, NULL); 40137c478bd9Sstevel@tonic-gate 40147c478bd9Sstevel@tonic-gate /* create a container for auto_* if it does not exist already */ 40157c478bd9Sstevel@tonic-gate if ((rc == NS_LDAP_NOTFOUND) && (op == OP_ADD) && 40167c478bd9Sstevel@tonic-gate (strcmp(tt->ttype, NS_LDAP_TYPE_AUTOMOUNT) == 0)) { 40177c478bd9Sstevel@tonic-gate static char *oclist[] = {NULL, "top", NULL}; 40187c478bd9Sstevel@tonic-gate if (version1) 40197c478bd9Sstevel@tonic-gate oclist[0] = "nisMap"; 40207c478bd9Sstevel@tonic-gate else 40217c478bd9Sstevel@tonic-gate oclist[0] = "automountMap"; 40227c478bd9Sstevel@tonic-gate e = __s_mk_entry(oclist, 3); 40237c478bd9Sstevel@tonic-gate if (e == NULL) { 40247c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40257c478bd9Sstevel@tonic-gate gettext("internal memory allocation error.\n")); 40267c478bd9Sstevel@tonic-gate exit(1); 40277c478bd9Sstevel@tonic-gate } 40287c478bd9Sstevel@tonic-gate if (__s_add_attr(e, 40297c478bd9Sstevel@tonic-gate version1 ? "nisMapName" : "automountMapName", 40307c478bd9Sstevel@tonic-gate databasetype) != NS_LDAP_SUCCESS) { 40317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40327c478bd9Sstevel@tonic-gate gettext("internal memory allocation error.\n")); 40337c478bd9Sstevel@tonic-gate ldap_freeEntry(e); 40347c478bd9Sstevel@tonic-gate exit(1); 40357c478bd9Sstevel@tonic-gate } 40367c478bd9Sstevel@tonic-gate 40377c478bd9Sstevel@tonic-gate if (inputbasedn == NULL) { 40387c478bd9Sstevel@tonic-gate if (get_basedn(databasetype, &inputbasedn) != 40397c478bd9Sstevel@tonic-gate NS_LDAP_SUCCESS) { 40407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40417c478bd9Sstevel@tonic-gate gettext("Could not obtain basedn\n")); 40427c478bd9Sstevel@tonic-gate ldap_freeEntry(e); 40437c478bd9Sstevel@tonic-gate exit(1); 40447c478bd9Sstevel@tonic-gate } 40457c478bd9Sstevel@tonic-gate } 40467c478bd9Sstevel@tonic-gate if (__ns_ldap_addEntry(databasetype, inputbasedn, e, 40477c478bd9Sstevel@tonic-gate &authority, flag, &errorp) != NS_LDAP_SUCCESS) { 40487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40497c478bd9Sstevel@tonic-gate gettext("Could not create container for %s\n"), 40507c478bd9Sstevel@tonic-gate databasetype); 40517c478bd9Sstevel@tonic-gate ldap_freeEntry(e); 40527c478bd9Sstevel@tonic-gate } 40537c478bd9Sstevel@tonic-gate } else if (strcmp(databasetype, "publickey") != 0) { 40547c478bd9Sstevel@tonic-gate if (rc == NS_LDAP_NOTFOUND) { 40557c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40567c478bd9Sstevel@tonic-gate gettext("Container %s does not exist\n"), 40577c478bd9Sstevel@tonic-gate databasetype); 40587c478bd9Sstevel@tonic-gate exit(1); 40597c478bd9Sstevel@tonic-gate } 40607c478bd9Sstevel@tonic-gate } 40617c478bd9Sstevel@tonic-gate 40627c478bd9Sstevel@tonic-gate if (op == OP_DUMP) { 40637c478bd9Sstevel@tonic-gate if (strcmp(databasetype, "publickey") == 0) { 40647c478bd9Sstevel@tonic-gate dumptable("hosts"); 40657c478bd9Sstevel@tonic-gate dumptable("passwd"); 40667c478bd9Sstevel@tonic-gate } else { 40677c478bd9Sstevel@tonic-gate dumptable(databasetype); 40687c478bd9Sstevel@tonic-gate } 40697c478bd9Sstevel@tonic-gate exit(exit_val); 40707c478bd9Sstevel@tonic-gate } 40717c478bd9Sstevel@tonic-gate 40727c478bd9Sstevel@tonic-gate if (etcfile) { 40737c478bd9Sstevel@tonic-gate if ((etcf = fopen(etcfile, "r")) == 0) { 40747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 40757c478bd9Sstevel@tonic-gate gettext("can't open file %s\n"), etcfile); 40767c478bd9Sstevel@tonic-gate exit(1); 40777c478bd9Sstevel@tonic-gate } 40787c478bd9Sstevel@tonic-gate } else { 40797c478bd9Sstevel@tonic-gate etcfile = "stdin"; 40807c478bd9Sstevel@tonic-gate etcf = stdin; 40817c478bd9Sstevel@tonic-gate } 40827c478bd9Sstevel@tonic-gate 40837c478bd9Sstevel@tonic-gate if (op == OP_ADD) { 40847c478bd9Sstevel@tonic-gate (void) addfile(); 40857c478bd9Sstevel@tonic-gate (void) fprintf(stdout, gettext("%d entries added\n"), nent_add); 40867c478bd9Sstevel@tonic-gate } 40877c478bd9Sstevel@tonic-gate 408884ad75deSmj /* exit() -> return for make lint */ 408984ad75deSmj return (exit_val); 40907c478bd9Sstevel@tonic-gate } 40917c478bd9Sstevel@tonic-gate 40927c478bd9Sstevel@tonic-gate 40937c478bd9Sstevel@tonic-gate /* 40947c478bd9Sstevel@tonic-gate * This is called when service == auto_*. 40957c478bd9Sstevel@tonic-gate * It calls __ns_ldap_getSearchDescriptors 40967c478bd9Sstevel@tonic-gate * to generate the dn from SSD's base dn. 40977c478bd9Sstevel@tonic-gate * If there is no SSD available, 40987c478bd9Sstevel@tonic-gate * default base dn will be used 40997c478bd9Sstevel@tonic-gate * Only the first baseDN in the SSD is used 41007c478bd9Sstevel@tonic-gate */ 41017c478bd9Sstevel@tonic-gate 41027c478bd9Sstevel@tonic-gate static int get_basedn(char *service, char **basedn) { 41037c478bd9Sstevel@tonic-gate int rc = NS_LDAP_SUCCESS; 41047c478bd9Sstevel@tonic-gate char *dn = NULL; 41057c478bd9Sstevel@tonic-gate ns_ldap_search_desc_t **desc = NULL; 41067c478bd9Sstevel@tonic-gate ns_ldap_error_t *errp = NULL; 41077c478bd9Sstevel@tonic-gate void **paramVal = NULL; 41087c478bd9Sstevel@tonic-gate int prepend_automountmapname = FALSE; 41097c478bd9Sstevel@tonic-gate 41107c478bd9Sstevel@tonic-gate /* 41117c478bd9Sstevel@tonic-gate * Get auto_* SSD first 41127c478bd9Sstevel@tonic-gate */ 41137c478bd9Sstevel@tonic-gate 41147c478bd9Sstevel@tonic-gate if ((rc = __ns_ldap_getSearchDescriptors( 41157c478bd9Sstevel@tonic-gate (const char *) service, 41167c478bd9Sstevel@tonic-gate &desc, &errp)) == NS_LDAP_SUCCESS && 41177c478bd9Sstevel@tonic-gate desc != NULL) { 41187c478bd9Sstevel@tonic-gate 41197c478bd9Sstevel@tonic-gate if (desc[0] != NULL && desc[0]->basedn != NULL) { 41207c478bd9Sstevel@tonic-gate dn = strdup(desc[0]->basedn); 41217c478bd9Sstevel@tonic-gate if (dn == NULL) { 41227c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeSearchDescriptors 41237c478bd9Sstevel@tonic-gate (&desc); 41247c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 41257c478bd9Sstevel@tonic-gate } 41267c478bd9Sstevel@tonic-gate } 41277c478bd9Sstevel@tonic-gate } 41287c478bd9Sstevel@tonic-gate 41297c478bd9Sstevel@tonic-gate /* clean up */ 41307c478bd9Sstevel@tonic-gate if (desc) (void) __ns_ldap_freeSearchDescriptors(&desc); 41317c478bd9Sstevel@tonic-gate if (errp) (void) __ns_ldap_freeError(&errp); 41327c478bd9Sstevel@tonic-gate 41337c478bd9Sstevel@tonic-gate /* 41347c478bd9Sstevel@tonic-gate * If no dn is duplicated from auto_* SSD, try automount SSD 41357c478bd9Sstevel@tonic-gate */ 41367c478bd9Sstevel@tonic-gate if (dn == NULL) { 41377c478bd9Sstevel@tonic-gate if ((rc = __ns_ldap_getSearchDescriptors( 41387c478bd9Sstevel@tonic-gate "automount", &desc, &errp)) 41397c478bd9Sstevel@tonic-gate == NS_LDAP_SUCCESS && desc != NULL) { 41407c478bd9Sstevel@tonic-gate 41417c478bd9Sstevel@tonic-gate if (desc[0] != NULL && desc[0]->basedn != NULL) { 41427c478bd9Sstevel@tonic-gate dn = strdup(desc[0]->basedn); 41437c478bd9Sstevel@tonic-gate if (dn == NULL) { 41447c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeSearchDescriptors 41457c478bd9Sstevel@tonic-gate (&desc); 41467c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 41477c478bd9Sstevel@tonic-gate } 41487c478bd9Sstevel@tonic-gate prepend_automountmapname = TRUE; 41497c478bd9Sstevel@tonic-gate } 41507c478bd9Sstevel@tonic-gate } 41517c478bd9Sstevel@tonic-gate /* clean up */ 41527c478bd9Sstevel@tonic-gate if (desc) (void) __ns_ldap_freeSearchDescriptors(&desc); 41537c478bd9Sstevel@tonic-gate if (errp) (void) __ns_ldap_freeError(&errp); 41547c478bd9Sstevel@tonic-gate } 41557c478bd9Sstevel@tonic-gate 41567c478bd9Sstevel@tonic-gate /* 41577c478bd9Sstevel@tonic-gate * If no dn is duplicated from auto_* or automount SSD, 41587c478bd9Sstevel@tonic-gate * use default DN 41597c478bd9Sstevel@tonic-gate */ 41607c478bd9Sstevel@tonic-gate 41617c478bd9Sstevel@tonic-gate if (dn == NULL) { 41627c478bd9Sstevel@tonic-gate if ((rc = __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P, 41637c478bd9Sstevel@tonic-gate ¶mVal, &errp)) == NS_LDAP_SUCCESS) { 41647c478bd9Sstevel@tonic-gate dn = strdup((char *)paramVal[0]); 41657c478bd9Sstevel@tonic-gate if (dn == NULL) { 41667c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeParam(¶mVal); 41677c478bd9Sstevel@tonic-gate return (NS_LDAP_MEMORY); 41687c478bd9Sstevel@tonic-gate } 41697c478bd9Sstevel@tonic-gate prepend_automountmapname = TRUE; 41707c478bd9Sstevel@tonic-gate } 41717c478bd9Sstevel@tonic-gate if (paramVal) (void) __ns_ldap_freeParam(¶mVal); 41727c478bd9Sstevel@tonic-gate if (errp) (void) __ns_ldap_freeError(&errp); 41737c478bd9Sstevel@tonic-gate } 41747c478bd9Sstevel@tonic-gate 41757c478bd9Sstevel@tonic-gate 41767c478bd9Sstevel@tonic-gate if (dn == NULL) { 41777c478bd9Sstevel@tonic-gate return (NS_LDAP_OP_FAILED); 41787c478bd9Sstevel@tonic-gate } else { 41797c478bd9Sstevel@tonic-gate /* 41807c478bd9Sstevel@tonic-gate * If dn is duplicated from 41817c478bd9Sstevel@tonic-gate * automount SSD basedn or 41827c478bd9Sstevel@tonic-gate * default base dn 41837c478bd9Sstevel@tonic-gate * then prepend automountMapName=auto_xxx 41847c478bd9Sstevel@tonic-gate */ 41857c478bd9Sstevel@tonic-gate if (prepend_automountmapname) 41867c478bd9Sstevel@tonic-gate rc = __s_api_prepend_automountmapname_to_dn( 41877c478bd9Sstevel@tonic-gate service, &dn, &errp); 41887c478bd9Sstevel@tonic-gate 41897c478bd9Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) { 41907c478bd9Sstevel@tonic-gate (void) __ns_ldap_freeError(&errp); 41917c478bd9Sstevel@tonic-gate free(dn); 41927c478bd9Sstevel@tonic-gate return (rc); 41937c478bd9Sstevel@tonic-gate } 41947c478bd9Sstevel@tonic-gate 41957c478bd9Sstevel@tonic-gate *basedn = dn; 41967c478bd9Sstevel@tonic-gate 41977c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS); 41987c478bd9Sstevel@tonic-gate } 41997c478bd9Sstevel@tonic-gate } 4200