4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
29 * Utility to add /etc files into LDAP.
30 * Can also be used to dump entries from a ldap container in /etc format.
37 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
48 #include <nss_dbdefs.h>
50 #include <rpc/rpcent.h>
55 #include <sys/systeminfo.h>
56 #include "ns_internal.h"
57 #include "ldapaddent.h"
58 #include "standalone.h"
63 static struct ttypelist_t
{
64 char *ttype
; /* type tag */
65 int (*genent
)(char *, int(*)());
66 /* routine to turn line into ldap entries */
67 void (*dump
)(ns_ldap_result_t
*);
68 /* routine to print ldap containers */
69 int (*filedbmline
)(); /* routine to turn file line into dbm line */
70 char *objclass
; /* Objectclass for the servicetype */
71 char *sortattr
; /* Sort attr for enumeration */
74 char parse_err_msg
[PARSE_ERR_MSG_LEN
];
75 int continue_onerror
= 0; /* do not exit on error */
77 static int get_basedn(char *service
, char **basedn
);
78 static int check_ipaddr(char *addr
, char **newaddr
);
79 static int check_projname(char *addr
);
84 extern char *__nis_quote_key(const char *, char *, int);
86 static char *inputbasedn
= NULL
;
87 static char *databasetype
= NULL
;
88 static int exit_val
= 0;
89 static unsigned nent_add
= 0;
90 static FILE *etcf
= 0;
91 static ns_cred_t authority
;
95 perr(ns_ldap_error_t
*e
)
98 (void) fprintf(stderr
, "%d: %s\n",
99 e
->status
, e
->message
);
104 ascii_to_int(char *str
)
109 if (c
== NULL
|| *c
== '\0')
112 while (c
!= '\0' && *c
== ' ')
117 for (i
= 0; i
< strlen(c
); i
++)
125 * Internet network address interpretation routine.
126 * The library routines call this routine to interpret
130 encode_network(const char *cp
)
136 in_addr_t parts
[4], *pp
= parts
;
142 if (*++cp
== 'x' || *cp
== 'X')
147 while ((c
= *cp
) != NULL
) {
149 if ((c
- '0') >= base
)
151 val
= (val
* base
) + (c
- '0');
155 if (base
== 16 && isxdigit(c
)) {
156 val
= (val
<< 4) + (c
+ 10 - (islower(c
) ? 'a' : 'A'));
164 return ((in_addr_t
)-1);
168 if (*cp
&& !isspace(*cp
))
169 return ((in_addr_t
)-1);
173 return ((in_addr_t
)-1);
174 for (val
= 0, i
= 0; i
< n
; i
++) {
176 val
|= parts
[i
] & 0xff;
178 for (/* no init */; i
< 4; i
++)
184 replace_tab2space(char *str
)
188 while ((str
) && (str
[i
])) {
196 blankline(char *line
)
200 for (p
= line
; *p
; p
++)
201 if (*p
!= ' ' && *p
!= '\t')
207 * check whether the token <tok> is a triplet,
208 * i. e. <tok> := (<hostname>,<username>,<domainname>)
209 * where <hostname>, <username>, <domainname> are IA5String
210 * <tok> supposes to contain NO spaces and start with '('
213 is_triplet(char *tok
)
216 return (strchr(++tok
, '(') == NULL
&& /* no more '(' */
217 (s
= strchr(tok
, ')')) != NULL
&& /* find ')' */
218 !*++s
&& /* ')' ends token */
219 (tok
= strchr(tok
, ',')) != NULL
&& /* host up to ',' */
220 (tok
= strchr(++tok
, ',')) != NULL
&& /* user up to ',' */
221 strchr(++tok
, ',') == NULL
); /* no more ',' */
225 line_buf_expand(struct line_buf
*line
)
227 line
->alloc
+= BUFSIZ
;
228 line
->str
= (char *)realloc(line
->str
, line
->alloc
);
230 if (line
->str
== NULL
) {
231 (void) fprintf(stderr
,
232 gettext("line_buf_expand: out of memory\n"));
238 line_buf_init(struct line_buf
*line
)
240 (void) memset((char *)line
, 0, sizeof (*line
));
241 line_buf_expand(line
);
245 __s_add_attr(ns_ldap_entry_t
*e
, char *attrname
, char *value
)
250 a
= (ns_ldap_attr_t
*)calloc(1, sizeof (ns_ldap_attr_t
));
252 return (NS_LDAP_MEMORY
);
253 a
->attrname
= strdup(attrname
);
254 if (a
->attrname
== NULL
) {
256 return (NS_LDAP_MEMORY
);
258 a
->attrvalue
= (char **)calloc(1, sizeof (char **));
259 if (a
->attrvalue
== NULL
) {
262 return (NS_LDAP_MEMORY
);
265 a
->attrvalue
[0] = NULL
;
271 return (NS_LDAP_MEMORY
);
274 e
->attr_pair
[e
->attr_count
] = a
;
276 return (NS_LDAP_SUCCESS
);
280 __s_add_attrlist(ns_ldap_entry_t
*e
, char *attrname
, char **argv
)
287 a
= (ns_ldap_attr_t
*)calloc(1, sizeof (ns_ldap_attr_t
));
289 return (NS_LDAP_MEMORY
);
290 a
->attrname
= strdup(attrname
);
291 if (a
->attrname
== NULL
) {
293 return (NS_LDAP_MEMORY
);
296 for (i
= 0, av
= argv
; *av
!= NULL
; av
++, i
++)
299 a
->attrvalue
= (char **)calloc(i
, sizeof (char **));
301 if (a
->attrvalue
== NULL
) {
304 return (NS_LDAP_MEMORY
);
307 for (j
= 0; j
< i
; j
++) {
313 return (NS_LDAP_MEMORY
);
317 e
->attr_pair
[e
->attr_count
] = a
;
319 return (NS_LDAP_SUCCESS
);
322 static ns_ldap_entry_t
*
323 __s_mk_entry(char **objclass
, int max_attr
)
326 e
= (ns_ldap_entry_t
*)calloc(1, sizeof (ns_ldap_entry_t
));
329 e
->attr_pair
= (ns_ldap_attr_t
**)calloc(max_attr
+1,
330 sizeof (ns_ldap_attr_t
*));
331 if (e
->attr_pair
== NULL
) {
336 if (__s_add_attrlist(e
, "objectClass", objclass
) != NS_LDAP_SUCCESS
) {
345 ldap_freeEntry(ns_ldap_entry_t
*ep
)
352 if (ep
->attr_pair
== NULL
) {
356 for (j
= 0; j
< ep
->attr_count
; j
++) {
357 if (ep
->attr_pair
[j
] == NULL
)
359 if (ep
->attr_pair
[j
]->attrname
)
360 free(ep
->attr_pair
[j
]->attrname
);
361 if (ep
->attr_pair
[j
]->attrvalue
) {
362 for (k
= 0; (k
< ep
->attr_pair
[j
]->value_count
) &&
363 (ep
->attr_pair
[j
]->attrvalue
[k
]); k
++) {
364 free(ep
->attr_pair
[j
]->attrvalue
[k
]);
366 free(ep
->attr_pair
[j
]->attrvalue
);
368 free(ep
->attr_pair
[j
]);
375 addentry(void *entry
, int mod
)
378 ns_ldap_error_t
*eres
= NULL
;
382 /* adds entry into the LDAP tree */
384 result
= __ns_ldap_addTypedEntry(databasetype
, inputbasedn
,
385 entry
, 0, &authority
, NS_LDAP_FOLLOWREF
| NS_LDAP_KEEP_CONN
,
388 result
= __ns_ldap_addTypedEntry(databasetype
, inputbasedn
,
389 entry
, 1, &authority
, NS_LDAP_FOLLOWREF
| NS_LDAP_KEEP_CONN
,
392 * Return 0 on success
393 * LDAP_ALREADY_EXISTS if entry exists already
394 * 1 for all other non-fatal errors.
395 * Exit on fatal errors.
398 case NS_LDAP_SUCCESS
:
403 case NS_LDAP_OP_FAILED
:
404 (void) fprintf(stderr
, gettext("operation failed.\n"));
408 case NS_LDAP_INVALID_PARAM
:
409 (void) fprintf(stderr
,
410 gettext("invalid parameter(s) passed.\n"));
414 case NS_LDAP_NOTFOUND
:
415 (void) fprintf(stderr
, gettext("entry not found.\n"));
420 (void) fprintf(stderr
,
421 gettext("internal memory allocation error.\n"));
426 (void) fprintf(stderr
,
427 gettext("LDAP Configuration problem.\n"));
432 case NS_LDAP_PARTIAL
:
433 (void) fprintf(stderr
,
434 gettext("partial result returned\n"));
439 case NS_LDAP_INTERNAL
:
440 if (eres
->status
== LDAP_ALREADY_EXISTS
||
441 eres
->status
== LDAP_NO_SUCH_OBJECT
)
443 else if (eres
->status
== LDAP_INSUFFICIENT_ACCESS
) {
444 (void) fprintf(stderr
,
445 gettext("The user does not have permission"
446 " to add/modify entries\n"));
457 (void) __ns_ldap_freeError(&eres
);
463 * Display usage message to STDERR.
469 (void) fprintf(stderr
, "%s\n", msg
);
471 (void) fprintf(stderr
, gettext(
472 "usage: ldapaddent [-cpv] [-a authenticationMethod] [-b baseDN]\n"
473 "-D bindDN [-w bindPassword] [-j passwdFile] [-f filename]\n"
476 "usage: ldapaddent [-cpv] -asasl/GSSAPI [-b baseDN] [-f filename]\n"
479 "usage: ldapaddent -d [-v] [-a authenticationMethod] [-D bindDN]\n"
480 "[-w bindPassword] [-j passwdFile] database\n"
482 "usage: ldapaddent [-cpv] -h LDAP_server[:serverPort] [-M domainName]\n"
483 "[-N profileName] [-P certifPath] [-a authenticationMethod]\n"
484 "[-b baseDN] -D bindDN [-w bindPassword] [-f filename]\n"
485 "[-j passwdFile] database\n"
487 "usage: ldapaddent [-cpv] -h LDAP_server[:serverPort] [-M domainName]\n"
488 "[-N profileName] [-P certifPath] -asasl/GSSAPI [-b baseDN]\n"
489 "[-f filename] database\n"
491 "usage: ldapaddent -d [-v] -h LDAP_server[:serverPort]"
493 "[-N profileName] [-P certifPath] [-a authenticationMethod]\n"
494 "[-b baseDN] -D bindDN [-w bindPassword] [-j passwdFile]\n"
500 * Determine if the given string is an IP address (IPv4 or IPv6).
501 * If so, it's converted to the preferred form (rfc2373) and
502 * *newaddr will point to the new address.
504 * Returns -2 : inet_ntop error
505 * -1 : not an IP address
506 * 0 : unsupported IP address (future use)
511 check_ipaddr(char *addr
, char **newaddr
) {
512 ipaddr_t addr_ipv4
= 0;
513 in6_addr_t addr_ipv6
;
516 if (inet_pton(AF_INET6
, addr
, &addr_ipv6
) == 1) {
520 /* Convert IPv4-mapped IPv6 address to IPv4 */
521 if (IN6_IS_ADDR_V4MAPPED(&addr_ipv6
) ||
522 IN6_IS_ADDR_V4COMPAT(&addr_ipv6
)) {
523 IN6_V4MAPPED_TO_IPADDR(&addr_ipv6
, addr_ipv4
);
524 if ((*newaddr
= calloc(1, INET_ADDRSTRLEN
)) == NULL
) {
525 (void) fprintf(stderr
,
526 gettext("out of memory\n"));
529 if (inet_ntop(AF_INET
, &addr_ipv4
, *newaddr
,
536 /* Processing general IPv6 addresses */
537 if ((*newaddr
= calloc(1, INET6_ADDRSTRLEN
)) == NULL
) {
538 (void) fprintf(stderr
, gettext("out of memory\n"));
541 if (inet_ntop(AF_INET6
, &addr_ipv6
, *newaddr
, INET6_ADDRSTRLEN
))
547 /* Processing IPv4 addresses of the type d.d.d.d. */
548 if (inet_pton(AF_INET
, addr
, &addr_ipv4
) == 1) {
551 if ((*newaddr
= calloc(1, INET_ADDRSTRLEN
)) == NULL
) {
552 (void) fprintf(stderr
, gettext("out of memory\n"));
555 if (inet_ntop(AF_INET
, &addr_ipv4
, *newaddr
, INET_ADDRSTRLEN
))
561 /* Processing IPv4 addresses d.d.d , d.d and d */
562 if (inet_addr(addr
) != (in_addr_t
)-1) {
565 if ((*newaddr
= strdup(addr
)) == NULL
) {
566 (void) fprintf(stderr
, gettext("out of memory\n"));
576 * Verifies that project name meets the restrictions defined by project(4).
579 check_projname(char *addr
)
582 if (addr
== NULL
|| *addr
== '\0')
585 for (i
= 0; i
< strlen(addr
); i
++) {
586 if (!isalpha(addr
[i
]) &&
598 genent_hosts(char *line
, int (*cback
)())
603 char *cname
, *pref_addr
;
604 int ctr
= 0, retval
= 1;
605 int rc
= GENENT_OK
, af
;
611 * don't clobber our argument
613 if (strlen(line
) >= sizeof (buf
)) {
614 (void) strlcpy(parse_err_msg
, gettext("line too long"),
616 return (GENENT_PARSEERR
);
618 (void) strcpy(buf
, line
);
623 (void) memset((char *)ecol
, 0, sizeof (ecol
));
627 * All leading spaces will be deleted from the comment
629 ecol
[3].ec_value
.ec_value_val
= "";
630 ecol
[3].ec_value
.ec_value_len
= 0;
631 comment
= t
= strchr(buf
, '#');
635 } while (*comment
!= '\0' && isspace(*comment
));
636 if (*comment
!= '\0') {
638 ecol
[3].ec_value
.ec_value_val
= strdup(comment
);
639 ecol
[3].ec_value
.ec_value_len
= strlen(comment
)+1;
648 if ((t
= strtok(buf
, " \t")) == 0) {
649 (void) strlcpy(parse_err_msg
, gettext("no host"),
651 return (GENENT_PARSEERR
);
654 af
= check_ipaddr(t
, &pref_addr
);
656 (void) strlcpy(parse_err_msg
, gettext("Internal error"),
658 } else if (af
== -1) {
659 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
660 gettext("Invalid IP address: %s"), t
);
661 } else if (flags
& F_VERBOSE
) {
662 if ((strncasecmp(t
, pref_addr
, strlen(t
))) != 0) {
663 (void) fprintf(stdout
,
664 gettext("IP address %s converted to %s\n"),
670 (void) fprintf(stderr
, "%s\n", parse_err_msg
);
671 if (continue_onerror
== 0)
672 return (GENENT_CBERR
);
677 ecol
[2].ec_value
.ec_value_val
= pref_addr
;
678 ecol
[2].ec_value
.ec_value_len
= strlen(pref_addr
)+1;
683 if ((t
= strtok(NULL
, " \t")) == 0) {
684 (void) strlcpy(parse_err_msg
, gettext("no cname"),
686 return (GENENT_PARSEERR
);
688 ecol
[0].ec_value
.ec_value_val
= t
;
689 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
694 if ((data
.h_addr_list
= (char **)calloc(2, sizeof (char **))) == NULL
) {
695 (void) fprintf(stderr
, gettext("out of memory\n"));
698 data
.h_addr_list
[0] = strdup(ecol
[2].ec_value
.ec_value_val
);
699 data
.h_addr_list
[1] = NULL
;
702 data
.h_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
708 data
.h_aliases
= NULL
;
712 * don't clobber comment in canonical entry
715 /* This call to AddEntry may move out of the loop */
716 /* This is because we have to call the function just once */
717 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
719 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
722 ecol
[1].ec_value
.ec_value_val
= t
;
723 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
726 alias
= strdup(ecol
[1].ec_value
.ec_value_val
);
727 if ((data
.h_aliases
= (char **)realloc(data
.h_aliases
,
728 ctr
* sizeof (char **))) == NULL
) {
729 (void) fprintf(stderr
, gettext("out of memory\n"));
732 data
.h_aliases
[ctr
-1] = alias
;
733 } while (t
= strtok(NULL
, " \t"));
736 * End the list of all the aliases by NULL
737 * If there is some comment, it will be stored as the last entry
738 * in the list of the host aliases
740 if ((data
.h_aliases
= (char **)realloc(data
.h_aliases
,
741 (ecol
[3].ec_value
.ec_value_len
!= 0 ?
742 ctr
+ 2 : ctr
+ 1) * sizeof (char **))) == NULL
) {
743 (void) fprintf(stderr
, gettext("out of memory\n"));
747 if (ecol
[3].ec_value
.ec_value_len
!= 0) {
748 data
.h_aliases
[ctr
++] = ecol
[3].ec_value
.ec_value_val
;
750 data
.h_aliases
[ctr
] = NULL
;
752 if (flags
& F_VERBOSE
)
753 (void) fprintf(stdout
,
754 gettext("Adding entry : cn=%s+ipHostNumber=%s\n"),
755 data
.h_name
, data
.h_addr_list
[0]);
757 retval
= (*cback
)(&data
, 0);
759 if (ecol
[3].ec_value
.ec_value_len
!= 0) {
760 free(ecol
[3].ec_value
.ec_value_val
);
763 if (retval
== LDAP_ALREADY_EXISTS
) {
764 if (continue_onerror
)
765 (void) fprintf(stderr
,
766 gettext("Entry: cn=%s+ipHostNumber=%s "
767 "already Exists -skipping it\n"),
768 data
.h_name
, data
.h_addr_list
[0]);
771 (void) fprintf(stderr
,
772 gettext("Entry: cn=%s+ipHostNumber=%s"
773 " already Exists\n"),
774 data
.h_name
, data
.h_addr_list
[0]);
780 free(data
.h_aliases
);
781 free(data
.h_addr_list
);
789 dump_hosts(ns_ldap_result_t
*res
)
791 ns_ldap_attr_t
*attrptr
= NULL
,
793 *iphostnumber
= NULL
,
796 char *name
; /* host name */
798 if (res
== NULL
|| res
->entry
== NULL
)
800 for (i
= 0; i
< res
->entry
->attr_count
; i
++) {
801 attrptr
= res
->entry
->attr_pair
[i
];
802 if (strcasecmp(attrptr
->attrname
, "cn") == 0)
804 else if (strcasecmp(attrptr
->attrname
, "iphostnumber") == 0)
805 iphostnumber
= attrptr
;
806 else if (strcasecmp(attrptr
->attrname
, "description") == 0) {
811 if (cn
== NULL
|| cn
->attrvalue
== NULL
|| cn
->attrvalue
[0] == NULL
||
812 iphostnumber
== NULL
|| iphostnumber
->attrvalue
== NULL
||
813 iphostnumber
->attrvalue
[0] == NULL
)
816 if ((name
= __s_api_get_canonical_name(res
->entry
, cn
, 1)) == NULL
)
819 /* ip host/ipnode number */
820 if (strlen(iphostnumber
->attrvalue
[0]) <= INET_ADDRSTRLEN
)
821 /* IPV4 or IPV6 but <= NET_ADDRSTRLEN */
822 (void) fprintf(stdout
, "%-18s", iphostnumber
->attrvalue
[0]);
825 (void) fprintf(stdout
, "%-48s", iphostnumber
->attrvalue
[0]);
827 /* host/ipnode name */
828 (void) fprintf(stdout
, "%s ", name
);
831 for (j
= 0; j
< cn
->value_count
; j
++) {
832 if (cn
->attrvalue
[j
]) {
833 if (strcasecmp(name
, cn
->attrvalue
[j
]) == 0)
836 (void) fprintf(stdout
, "%s ", cn
->attrvalue
[j
]);
841 if (desc
!= NULL
&& desc
->attrvalue
!= NULL
&&
842 desc
->attrvalue
[0] != NULL
) {
843 (void) fprintf(stdout
, "#%s", desc
->attrvalue
[0]);
847 (void) fprintf(stdout
, "\n");
855 genent_rpc(char *line
, int (*cback
)())
869 * don't clobber our argument
871 if (strlen(line
) >= sizeof (buf
)) {
872 (void) strlcpy(parse_err_msg
, gettext("line too long"),
874 return (GENENT_PARSEERR
);
876 (void) strcpy(buf
, line
);
881 (void) memset((char *)ecol
, 0, sizeof (ecol
));
886 t
= strchr(buf
, '#');
889 ecol
[3].ec_value
.ec_value_val
= t
;
890 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
892 ecol
[3].ec_value
.ec_value_val
= 0;
893 ecol
[3].ec_value
.ec_value_len
= 0;
899 if ((t
= strtok(buf
, " \t")) == 0) {
900 (void) strlcpy(parse_err_msg
, gettext("no number"),
902 return (GENENT_PARSEERR
);
904 ecol
[0].ec_value
.ec_value_val
= t
;
905 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
911 if ((t
= strtok(NULL
, " \t")) == 0) {
912 (void) strlcpy(parse_err_msg
, gettext("no number"),
914 return (GENENT_PARSEERR
);
916 ecol
[2].ec_value
.ec_value_val
= t
;
917 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
924 data
.r_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
925 if (ecol
[2].ec_value
.ec_value_val
!= NULL
&&
926 ecol
[2].ec_value
.ec_value_val
[0] != '\0') {
928 data
.r_number
= ascii_to_int(ecol
[2].ec_value
.ec_value_val
);
929 if (data
.r_number
== -1) {
930 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
931 gettext("invalid program number: %s"),
932 ecol
[2].ec_value
.ec_value_val
);
933 return (GENENT_PARSEERR
);
942 data
.r_aliases
= NULL
;
946 * don't clobber comment in canonical entry
948 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
950 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
953 ecol
[1].ec_value
.ec_value_val
= t
;
954 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
957 alias
= strdup(ecol
[1].ec_value
.ec_value_val
);
958 if ((data
.r_aliases
= (char **)realloc(data
.r_aliases
,
959 ctr
* sizeof (char **))) == NULL
) {
960 (void) fprintf(stderr
, gettext("out of memory\n"));
963 data
.r_aliases
[ctr
-1] = alias
;
967 * only put comment in canonical entry
969 ecol
[3].ec_value
.ec_value_val
= 0;
970 ecol
[3].ec_value
.ec_value_len
= 0;
972 } while (t
= strtok(NULL
, " \t"));
974 /* End the list of all the aliases by NULL */
975 if ((data
.r_aliases
= (char **)realloc(data
.r_aliases
,
976 (ctr
+ 1) * sizeof (char **))) == NULL
) {
977 (void) fprintf(stderr
, gettext("out of memory\n"));
980 data
.r_aliases
[ctr
] = NULL
;
982 if (flags
& F_VERBOSE
)
983 (void) fprintf(stdout
,
984 gettext("Adding entry : %s\n"), data
.r_name
);
986 retval
= (*cback
)(&data
, 0);
988 if (retval
== LDAP_ALREADY_EXISTS
) {
989 if (continue_onerror
)
990 (void) fprintf(stderr
,
991 gettext("Entry: %s - already Exists,"
992 " skipping it.\n"), data
.r_name
);
995 (void) fprintf(stderr
,
996 gettext("Entry: %s - already Exists\n"),
1003 free(data
.r_aliases
);
1011 dump_rpc(ns_ldap_result_t
*res
)
1013 ns_ldap_attr_t
*attrptr
= NULL
, *cn
= NULL
, *rpcnumber
= NULL
;
1015 char *name
; /* rpc name */
1017 if (res
== NULL
|| res
->entry
== NULL
)
1019 for (i
= 0; i
< res
->entry
->attr_count
; i
++) {
1020 attrptr
= res
->entry
->attr_pair
[i
];
1021 if (strcasecmp(attrptr
->attrname
, "cn") == 0)
1023 else if (strcasecmp(attrptr
->attrname
, "oncRpcNumber") == 0)
1024 rpcnumber
= attrptr
;
1027 if (cn
== NULL
|| cn
->attrvalue
== NULL
|| cn
->attrvalue
[0] == NULL
||
1028 rpcnumber
== NULL
|| rpcnumber
->attrvalue
== NULL
||
1029 rpcnumber
->attrvalue
[0] == NULL
)
1032 if ((name
= __s_api_get_canonical_name(res
->entry
, cn
, 1)) == NULL
)
1036 if (strlen(name
) < 8)
1037 (void) fprintf(stdout
, "%s\t\t", name
);
1039 (void) fprintf(stdout
, "%s\t", name
);
1042 (void) fprintf(stdout
, "%-8s", rpcnumber
->attrvalue
[0]);
1046 for (j
= 0; j
< cn
->value_count
; j
++) {
1047 if (cn
->attrvalue
[j
]) {
1048 if (strcasecmp(name
, cn
->attrvalue
[j
]) == 0)
1051 (void) fprintf(stdout
, "%s ", cn
->attrvalue
[j
]);
1056 (void) fprintf(stdout
, "\n");
1066 genent_protocols(char *line
, int (*cback
)())
1073 struct protoent data
;
1080 * don't clobber our argument
1082 if (strlen(line
) >= sizeof (buf
)) {
1083 (void) strlcpy(parse_err_msg
, gettext("line too long"),
1085 return (GENENT_PARSEERR
);
1087 (void) strcpy(buf
, line
);
1092 (void) memset((char *)ecol
, 0, sizeof (ecol
));
1097 t
= strchr(buf
, '#');
1100 ecol
[3].ec_value
.ec_value_val
= t
;
1101 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
1103 ecol
[3].ec_value
.ec_value_val
= 0;
1104 ecol
[3].ec_value
.ec_value_len
= 0;
1110 if ((t
= strtok(buf
, " \t")) == 0) {
1111 (void) strlcpy(parse_err_msg
, gettext("no number"),
1113 return (GENENT_PARSEERR
);
1115 ecol
[0].ec_value
.ec_value_val
= t
;
1116 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
1122 if ((t
= strtok(NULL
, " \t")) == 0) {
1123 (void) strlcpy(parse_err_msg
, gettext("no number"),
1125 return (GENENT_PARSEERR
);
1127 ecol
[2].ec_value
.ec_value_val
= t
;
1128 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
1134 data
.p_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
1136 if (ecol
[2].ec_value
.ec_value_val
!= NULL
&&
1137 ecol
[2].ec_value
.ec_value_val
[0] != '\0') {
1139 data
.p_proto
= ascii_to_int(ecol
[2].ec_value
.ec_value_val
);
1140 if (data
.p_proto
== -1) {
1141 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
1142 gettext("invalid protocol number: %s"),
1143 ecol
[2].ec_value
.ec_value_val
);
1144 return (GENENT_PARSEERR
);
1154 data
.p_aliases
= NULL
;
1158 * don't clobber comment in canonical entry
1160 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
1162 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
1165 ecol
[1].ec_value
.ec_value_val
= t
;
1166 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
1169 alias
= strdup(ecol
[1].ec_value
.ec_value_val
);
1170 if ((data
.p_aliases
= (char **)realloc(data
.p_aliases
,
1171 ctr
* sizeof (char **))) == NULL
) {
1172 (void) fprintf(stderr
, gettext("out of memory\n"));
1175 data
.p_aliases
[ctr
-1] = alias
;
1178 * only put comment in canonical entry
1180 ecol
[3].ec_value
.ec_value_val
= 0;
1181 ecol
[3].ec_value
.ec_value_len
= 0;
1183 } while (t
= strtok(NULL
, " \t"));
1185 /* End the list of all the aliases by NULL */
1186 if ((data
.p_aliases
= (char **)realloc(data
.p_aliases
,
1187 (ctr
+ 1) * sizeof (char **))) == NULL
) {
1188 (void) fprintf(stderr
, gettext("out of memory\n"));
1191 data
.p_aliases
[ctr
] = NULL
;
1193 if (flags
& F_VERBOSE
)
1194 (void) fprintf(stdout
,
1195 gettext("Adding entry : %s\n"), data
.p_name
);
1197 retval
= (*cback
)(&data
, 0);
1199 if (retval
== LDAP_ALREADY_EXISTS
) {
1200 if (continue_onerror
)
1201 (void) fprintf(stderr
,
1202 gettext("Entry: %s - already Exists,"
1203 " skipping it.\n"), data
.p_name
);
1206 (void) fprintf(stderr
,
1207 gettext("Entry: %s - already Exists\n"),
1214 free(data
.p_aliases
);
1221 dump_protocols(ns_ldap_result_t
*res
)
1223 ns_ldap_attr_t
*attrptr
= NULL
, *cn
= NULL
, *protocolnumber
= NULL
;
1227 if (res
== NULL
|| res
->entry
== NULL
)
1229 for (i
= 0; i
< res
->entry
->attr_count
; i
++) {
1230 attrptr
= res
->entry
->attr_pair
[i
];
1231 if (strcasecmp(attrptr
->attrname
, "cn") == 0)
1233 else if (strcasecmp(attrptr
->attrname
, "ipProtocolNumber")
1235 protocolnumber
= attrptr
;
1238 if (cn
== NULL
|| cn
->attrvalue
== NULL
|| cn
->attrvalue
[0] == NULL
||
1239 protocolnumber
== NULL
|| protocolnumber
->attrvalue
== NULL
||
1240 protocolnumber
->attrvalue
[0] == NULL
)
1243 if ((name
= __s_api_get_canonical_name(res
->entry
, cn
, 1)) == NULL
)
1247 if (strlen(name
) < 8)
1248 (void) fprintf(stdout
, "%s\t\t", name
);
1250 (void) fprintf(stdout
, "%s\t", name
);
1252 /* protocol number */
1253 (void) fprintf(stdout
, "%-16s", protocolnumber
->attrvalue
[0]);
1256 for (j
= 0; j
< cn
->value_count
; j
++) {
1257 if (cn
->attrvalue
[j
]) {
1258 if (strcasecmp(name
, cn
->attrvalue
[j
]) == 0) {
1259 if (cn
->value_count
> 1)
1260 /* Do not replicate */
1263 * Replicate name in uppercase as an aliase
1265 for (cp
= cn
->attrvalue
[j
]; *cp
; cp
++)
1268 (void) fprintf(stdout
, "%s ", cn
->attrvalue
[j
]);
1273 (void) fprintf(stdout
, "\n");
1287 genent_networks(char *line
, int (*cback
)())
1302 * don't clobber our argument
1304 if (strlen(line
) >= sizeof (buf
)) {
1305 (void) strlcpy(parse_err_msg
, gettext("line too long"),
1307 return (GENENT_PARSEERR
);
1309 (void) strcpy(buf
, line
);
1314 (void) memset((char *)ecol
, 0, sizeof (ecol
));
1319 t
= strchr(buf
, '#');
1322 ecol
[3].ec_value
.ec_value_val
= t
;
1323 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
1325 ecol
[3].ec_value
.ec_value_val
= 0;
1326 ecol
[3].ec_value
.ec_value_len
= 0;
1332 if ((t
= strtok(buf
, " \t")) == 0) {
1333 (void) strlcpy(parse_err_msg
, gettext("no number"),
1335 return (GENENT_PARSEERR
);
1337 ecol
[0].ec_value
.ec_value_val
= t
;
1338 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
1344 if ((t
= strtok(NULL
, " \t")) == 0) {
1345 (void) strlcpy(parse_err_msg
, gettext("no number"),
1347 return (GENENT_PARSEERR
);
1349 ecol
[2].ec_value
.ec_value_val
= t
;
1350 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
1357 data
.n_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
1359 * data.n_net is an unsigned field,
1360 * assign -1 to it, make no sense.
1361 * Use enet here to avoid lint warning.
1363 enet
= encode_network(ecol
[2].ec_value
.ec_value_val
);
1365 if (enet
== -1 && continue_onerror
== 0) {
1366 (void) fprintf(stderr
, gettext("Invalid network number\n"));
1367 if (continue_onerror
== 0)
1368 return (GENENT_CBERR
);
1376 data
.n_aliases
= NULL
;
1380 * don't clobber comment in canonical entry
1382 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
1384 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
1387 ecol
[1].ec_value
.ec_value_val
= t
;
1388 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
1391 alias
= strdup(ecol
[1].ec_value
.ec_value_val
);
1392 if ((data
.n_aliases
= (char **)realloc(data
.n_aliases
,
1393 ctr
* sizeof (char **))) == NULL
) {
1394 (void) fprintf(stderr
, gettext("out of memory\n"));
1397 data
.n_aliases
[ctr
-1] = alias
;
1400 * only put comment in canonical entry
1402 ecol
[3].ec_value
.ec_value_val
= 0;
1403 ecol
[3].ec_value
.ec_value_len
= 0;
1405 } while (t
= strtok(NULL
, " \t"));
1407 /* End the list of all the aliases by NULL */
1408 if ((data
.n_aliases
= (char **)realloc(data
.n_aliases
,
1409 (ctr
+ 1) * sizeof (char **))) == NULL
) {
1410 (void) fprintf(stderr
, gettext("out of memory\n"));
1413 data
.n_aliases
[ctr
] = NULL
;
1415 if (flags
& F_VERBOSE
)
1416 (void) fprintf(stdout
,
1417 gettext("Adding entry : %s\n"), data
.n_name
);
1419 retval
= (*cback
)(&data
, 0);
1421 if (retval
== LDAP_ALREADY_EXISTS
) {
1422 if (continue_onerror
)
1423 (void) fprintf(stderr
,
1424 gettext("Entry: %s - already Exists,"
1425 " skipping it.\n"), data
.n_name
);
1428 (void) fprintf(stderr
,
1429 gettext("Entry: %s - already Exists\n"),
1436 free(data
.n_aliases
);
1443 dump_networks(ns_ldap_result_t
*res
)
1445 ns_ldap_attr_t
*attrptr
= NULL
, *cn
= NULL
, *networknumber
= NULL
;
1449 if (res
== NULL
|| res
->entry
== NULL
)
1451 for (i
= 0; i
< res
->entry
->attr_count
; i
++) {
1452 attrptr
= res
->entry
->attr_pair
[i
];
1453 if (strcasecmp(attrptr
->attrname
, "cn") == 0)
1455 else if (strcasecmp(attrptr
->attrname
, "ipNetworkNumber")
1457 networknumber
= attrptr
;
1460 if (cn
== NULL
|| cn
->attrvalue
== NULL
|| cn
->attrvalue
[0] == NULL
||
1461 networknumber
== NULL
|| networknumber
->attrvalue
== NULL
||
1462 networknumber
->attrvalue
[0] == NULL
)
1466 * cn can be a MUST attribute(RFC 2307) or MAY attribute(2307bis).
1467 * If the canonical name can not be found (2307bis), use the 1st
1468 * value as the official name.
1472 if ((name
= __s_api_get_canonical_name(res
->entry
, cn
, 1)) == NULL
)
1473 name
= cn
->attrvalue
[0];
1475 if (strlen(name
) < 8)
1476 (void) fprintf(stdout
, "%s\t\t", name
);
1478 (void) fprintf(stdout
, "%s\t", name
);
1480 /* network number */
1481 (void) fprintf(stdout
, "%-16s", networknumber
->attrvalue
[0]);
1484 for (j
= 0; j
< cn
->value_count
; j
++) {
1485 if (cn
->attrvalue
[j
]) {
1486 if (strcasecmp(name
, cn
->attrvalue
[j
]) == 0)
1489 (void) fprintf(stdout
, "%s ", cn
->attrvalue
[j
]);
1494 (void) fprintf(stdout
, "\n");
1507 genent_services(char *line
, int (*cback
)())
1514 struct servent data
;
1521 * don't clobber our argument
1523 if (strlen(line
) >= sizeof (buf
)) {
1524 (void) strlcpy(parse_err_msg
, gettext("line too long"),
1526 return (GENENT_PARSEERR
);
1528 (void) strcpy(buf
, line
);
1533 (void) memset((char *)ecol
, 0, sizeof (ecol
));
1538 t
= strchr(buf
, '#');
1541 ecol
[4].ec_value
.ec_value_val
= t
;
1542 ecol
[4].ec_value
.ec_value_len
= strlen(t
)+1;
1544 ecol
[4].ec_value
.ec_value_val
= 0;
1545 ecol
[4].ec_value
.ec_value_len
= 0;
1551 if ((t
= strtok(buf
, " \t")) == 0) {
1552 (void) strlcpy(parse_err_msg
, gettext("no port"),
1554 return (GENENT_PARSEERR
);
1556 ecol
[0].ec_value
.ec_value_val
= t
;
1557 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
1563 if ((t
= strtok(NULL
, " \t")) == 0) {
1564 (void) strlcpy(parse_err_msg
, gettext("no protocol"),
1566 return (GENENT_PARSEERR
);
1568 if ((p
= strchr(t
, '/')) == 0) {
1569 (void) strlcpy(parse_err_msg
, gettext("bad port/proto"),
1571 return (GENENT_PARSEERR
);
1574 ecol
[3].ec_value
.ec_value_val
= t
;
1575 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
1580 ecol
[2].ec_value
.ec_value_val
= p
;
1581 ecol
[2].ec_value
.ec_value_len
= strlen(p
)+1;
1588 data
.s_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
1589 data
.s_proto
= strdup(ecol
[2].ec_value
.ec_value_val
);
1591 if (ecol
[3].ec_value
.ec_value_val
!= NULL
&&
1592 ecol
[3].ec_value
.ec_value_val
[0] != '\0') {
1594 data
.s_port
= ascii_to_int(ecol
[3].ec_value
.ec_value_val
);
1595 if (data
.s_port
== -1) {
1596 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
1597 gettext("invalid port number: %s"),
1598 ecol
[3].ec_value
.ec_value_val
);
1599 return (GENENT_PARSEERR
);
1608 data
.s_aliases
= NULL
;
1612 * don't clobber comment in canonical entry
1614 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
1616 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
1619 ecol
[1].ec_value
.ec_value_val
= t
;
1620 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
1623 alias
= strdup(ecol
[1].ec_value
.ec_value_val
);
1624 if ((data
.s_aliases
= (char **)realloc(data
.s_aliases
,
1625 ctr
* sizeof (char **))) == NULL
) {
1626 (void) fprintf(stderr
, gettext("out of memory\n"));
1629 data
.s_aliases
[ctr
-1] = alias
;
1632 * only put comment in canonical entry
1634 ecol
[4].ec_value
.ec_value_val
= 0;
1635 ecol
[4].ec_value
.ec_value_len
= 0;
1637 } while (t
= strtok(NULL
, " \t"));
1639 /* End the list of all the aliases by NULL */
1640 if ((data
.s_aliases
= (char **)realloc(data
.s_aliases
,
1641 (ctr
+ 1) * sizeof (char **))) == NULL
) {
1642 (void) fprintf(stderr
, gettext("out of memory\n"));
1645 data
.s_aliases
[ctr
] = NULL
;
1647 if (flags
& F_VERBOSE
)
1648 (void) fprintf(stdout
,
1649 gettext("Adding entry : %s\n"), line
);
1651 retval
= (*cback
)(&data
, 0);
1653 if (retval
== LDAP_ALREADY_EXISTS
) {
1654 if (continue_onerror
)
1655 (void) fprintf(stderr
, gettext(
1656 "Entry: cn=%s+ipServiceProtocol=%s"
1657 " already Exists, skipping it.\n"),
1658 data
.s_name
, data
.s_proto
);
1661 (void) fprintf(stderr
,
1662 gettext("Entry: cn=%s+ipServiceProtocol=%s"
1663 " - already Exists\n"),
1664 data
.s_name
, data
.s_proto
);
1671 free(data
.s_aliases
);
1679 dump_services(ns_ldap_result_t
*res
)
1681 ns_ldap_attr_t
*attrptr
= NULL
, *cn
= NULL
, *port
= NULL
;
1682 ns_ldap_attr_t
*protocol
= NULL
;
1684 char *name
; /* service name */
1687 * cn can have multiple values.(service name and its aliases)
1688 * In order to support RFC 2307, section 5.5, ipserviceprotocol can
1689 * have multiple values too.
1690 * The output format should look like
1692 * test 2345/udp mytest
1693 * test 2345/tcp mytest
1695 if (res
== NULL
|| res
->entry
== NULL
)
1697 for (i
= 0; i
< res
->entry
->attr_count
; i
++) {
1698 attrptr
= res
->entry
->attr_pair
[i
];
1699 if (strcasecmp(attrptr
->attrname
, "cn") == 0)
1701 else if (strcasecmp(attrptr
->attrname
, "ipServicePort") == 0)
1703 else if (strcasecmp(attrptr
->attrname
,
1704 "ipServiceProtocol") == 0)
1708 if (cn
== NULL
|| cn
->attrvalue
== NULL
|| cn
->attrvalue
[0] == NULL
||
1709 port
== NULL
|| port
->attrvalue
== NULL
||
1710 port
->attrvalue
[0] == NULL
|| protocol
== NULL
||
1711 protocol
->attrvalue
== NULL
|| protocol
->attrvalue
[0] == NULL
)
1714 if ((name
= __s_api_get_canonical_name(res
->entry
, cn
, 1)) == NULL
)
1716 for (i
= 0; i
< protocol
->value_count
; i
++) {
1717 if (protocol
->attrvalue
[i
] == NULL
)
1720 (void) fprintf(stdout
, "%-16s", name
);
1722 /* port & protocol */
1723 (void) fprintf(stdout
, "%s/%s%n", port
->attrvalue
[0],
1724 protocol
->attrvalue
[i
], &len
);
1727 (void) fprintf(stdout
, "\t\t");
1729 (void) fprintf(stdout
, "\t");
1732 for (j
= 0; j
< cn
->value_count
; j
++) {
1733 if (cn
->attrvalue
[j
]) {
1734 if (strcasecmp(name
, cn
->attrvalue
[j
]) == 0)
1735 /* skip service name */
1737 (void) fprintf(stdout
, "%s ", cn
->attrvalue
[j
]);
1742 (void) fprintf(stdout
, "\n");
1752 genent_group(char *line
, int (*cback
)())
1764 * don't clobber our argument
1766 if (strlen(line
) >= sizeof (buf
)) {
1767 (void) strlcpy(parse_err_msg
, gettext("line too long"),
1769 return (GENENT_PARSEERR
);
1771 (void) strcpy(buf
, line
);
1774 /* ignore empty entries */
1781 (void) memset((char *)ecol
, 0, sizeof (ecol
));
1786 if ((s
= strchr(t
, ':')) == 0) {
1787 (void) strlcpy(parse_err_msg
, gettext("no passwd"),
1789 return (GENENT_PARSEERR
);
1792 ecol
[0].ec_value
.ec_value_val
= t
;
1793 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
1799 if ((s
= strchr(t
, ':')) == 0) {
1800 (void) strlcpy(parse_err_msg
, gettext("no gid"),
1802 return (GENENT_PARSEERR
);
1805 ecol
[1].ec_value
.ec_value_val
= t
;
1806 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
1813 if ((s
= strchr(t
, ':')) == 0 || s
== t
) {
1814 (void) strlcpy(parse_err_msg
, gettext("no members"),
1816 return (GENENT_PARSEERR
);
1819 ecol
[2].ec_value
.ec_value_val
= t
;
1820 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
1826 ecol
[3].ec_value
.ec_value_val
= t
;
1827 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
1833 data
.gr_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
1834 data
.gr_passwd
= strdup(ecol
[1].ec_value
.ec_value_val
);
1835 if (ecol
[2].ec_value
.ec_value_val
!= NULL
&&
1836 ecol
[2].ec_value
.ec_value_val
[0] != '\0') {
1838 data
.gr_gid
= ascii_to_int(ecol
[2].ec_value
.ec_value_val
);
1839 if (data
.gr_gid
== (uid_t
)-1) {
1840 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
1841 gettext("invalid group id: %s"),
1842 ecol
[2].ec_value
.ec_value_val
);
1843 return (GENENT_PARSEERR
);
1846 data
.gr_gid
= (uid_t
)-1;
1850 /* Compute maximum amount of members */
1852 while (s
= strchr(s
, ',')) {
1857 /* Allocate memory for all members */
1858 data
.gr_mem
= calloc(ctr
+ 2, sizeof (char **));
1859 if (data
.gr_mem
== NULL
) {
1860 (void) fprintf(stderr
, gettext("out of memory\n"));
1865 while (s
= strchr(t
, ',')) {
1868 ecol
[3].ec_value
.ec_value_val
= t
;
1870 /* Send to server only non empty member names */
1871 if (strlen(ecol
[3].ec_value
.ec_value_val
) != 0)
1872 data
.gr_mem
[ctr
++] = ecol
[3].ec_value
.ec_value_val
;
1875 /* Send to server only non empty member names */
1877 data
.gr_mem
[ctr
++] = t
;
1879 /* Array of members completed, finished by NULL, see calloc() */
1881 if (flags
& F_VERBOSE
)
1882 (void) fprintf(stdout
,
1883 gettext("Adding entry : %s\n"), data
.gr_name
);
1885 retval
= (*cback
)(&data
, 0);
1887 if (retval
== LDAP_ALREADY_EXISTS
) {
1888 if (continue_onerror
)
1889 (void) fprintf(stderr
,
1890 gettext("Entry: %s - already Exists,"
1891 " skipping it.\n"), data
.gr_name
);
1894 (void) fprintf(stderr
,
1895 gettext("Entry: %s - already Exists\n"),
1902 free(data
.gr_passwd
);
1909 dump_group(ns_ldap_result_t
*res
)
1911 char **value
= NULL
;
1915 value
= __ns_ldap_getAttr(res
->entry
, "cn");
1916 if (value
&& value
[0])
1917 (void) fprintf(stdout
, "%s:", value
[0]);
1918 value
= __ns_ldap_getAttr(res
->entry
, "userPassword");
1919 if (value
== NULL
|| value
[0] == NULL
)
1920 (void) fprintf(stdout
, "*:");
1922 (void) strcpy(pnam
, value
[0]);
1923 if (strncasecmp(value
[0], "{crypt}", 7) == 0)
1924 (void) fprintf(stdout
, "%s:", (pnam
+7));
1926 (void) fprintf(stdout
, "*:");
1928 value
= __ns_ldap_getAttr(res
->entry
, "gidNumber");
1929 if (value
&& value
[0])
1930 (void) fprintf(stdout
, "%s:", value
[0]);
1932 value
= __ns_ldap_getAttr(res
->entry
, "memberUid");
1933 if (value
!= NULL
&& value
[0] != NULL
) {
1934 while (value
[attr_count
] != NULL
) {
1935 if (value
[attr_count
+1] == NULL
)
1936 (void) fprintf(stdout
, "%s", value
[attr_count
]);
1938 (void) fprintf(stdout
, "%s,",
1942 (void) fprintf(stdout
, "\n");
1945 (void) fprintf(stdout
, "\n");
1957 genent_ethers(char *line
, int (*cback
)())
1963 struct _ns_ethers data
;
1967 * don't clobber our argument
1969 if (strlen(line
) >= sizeof (buf
)) {
1970 (void) strlcpy(parse_err_msg
, gettext("line too long"),
1972 return (GENENT_PARSEERR
);
1974 (void) strcpy(buf
, line
);
1979 (void) memset((char *)ecol
, 0, sizeof (ecol
));
1984 t
= strchr(buf
, '#');
1987 ecol
[2].ec_value
.ec_value_val
= t
;
1988 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
1990 ecol
[2].ec_value
.ec_value_val
= 0;
1991 ecol
[2].ec_value
.ec_value_len
= 0;
1997 if ((t
= strtok(buf
, " \t")) == 0) {
1998 (void) strlcpy(parse_err_msg
, gettext("no name"),
2000 return (GENENT_PARSEERR
);
2002 ecol
[0].ec_value
.ec_value_val
= t
;
2003 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
2008 if ((t
= strtok(NULL
, " \t")) == 0) {
2009 (void) strlcpy(parse_err_msg
,
2010 gettext("no white space allowed in name"),
2012 return (GENENT_PARSEERR
);
2014 ecol
[1].ec_value
.ec_value_val
= t
;
2015 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2022 data
.ether
= strdup(ecol
[0].ec_value
.ec_value_val
);
2023 data
.name
= strdup(ecol
[1].ec_value
.ec_value_val
);
2026 if (flags
& F_VERBOSE
)
2027 (void) fprintf(stdout
,
2028 gettext("Adding entry : %s\n"), data
.name
);
2030 retval
= (*cback
)(&data
, 0);
2032 if (retval
== LDAP_ALREADY_EXISTS
) {
2033 if (continue_onerror
)
2034 (void) fprintf(stderr
,
2035 gettext("Entry: %s - already Exists,"
2036 " skipping it.\n"), data
.name
);
2039 (void) fprintf(stderr
,
2040 gettext("Entry: %s - already Exists\n"),
2054 dump_ethers(ns_ldap_result_t
*res
)
2056 char **value
= NULL
;
2058 value
= __ns_ldap_getAttr(res
->entry
, "macAddress");
2059 if (value
&& value
[0])
2060 (void) fprintf(stdout
, "%s", value
[0]);
2063 value
= __ns_ldap_getAttr(res
->entry
, "cn");
2064 if (value
&& value
[0])
2065 (void) fprintf(stdout
, " %s\n", value
[0]);
2069 genent_aliases(char *line
, int (*cback
)())
2078 struct _ns_alias data
;
2083 * don't clobber our argument
2085 if (strlen(line
) >= sizeof (buf
)) {
2086 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2088 return (GENENT_PARSEERR
);
2091 (void) strcpy(buf
, line
);
2093 if ((t
= strchr(buf
, ':')) == 0) {
2094 (void) strlcpy(parse_err_msg
, gettext("no alias name"),
2096 return (GENENT_PARSEERR
);
2101 (void) strlcpy(parse_err_msg
, gettext("no alias value"),
2103 return (GENENT_PARSEERR
);
2110 data
.alias
= strdup(cname
);
2112 (void) fprintf(stderr
, gettext("out of memory\n"));
2117 t
= strtok(aliases
, ",");
2123 if ((alias
== NULL
) ||
2124 ((data
.member
= (char **)realloc(data
.member
,
2125 (ctr
+ 1) * sizeof (char **))) == NULL
)) {
2126 (void) fprintf(stderr
, gettext("out of memory\n"));
2129 data
.member
[ctr
-1] = alias
;
2131 } while (t
= strtok(NULL
, ","));
2133 data
.member
[ctr
] = NULL
;
2135 if (flags
& F_VERBOSE
)
2136 (void) fprintf(stdout
,
2137 gettext("Adding entry : %s\n"), data
.alias
);
2139 retval
= (*cback
)(&data
, 0);
2141 if (retval
== LDAP_ALREADY_EXISTS
) {
2142 if (continue_onerror
)
2143 (void) fprintf(stderr
,
2144 gettext("Entry: %s - already Exists,"
2145 " skipping it.\n"), data
.alias
);
2148 (void) fprintf(stderr
,
2149 gettext("Entry: %s - already Exists\n"),
2157 while (data
.member
[i
])
2158 free(data
.member
[i
++]);
2166 dump_aliases(ns_ldap_result_t
*res
)
2169 char **value
= NULL
;
2172 value
= __ns_ldap_getAttr(res
->entry
, "mail");
2173 if (value
&& value
[0])
2174 (void) fprintf(stdout
, "%s:", value
[0]);
2175 value
= __ns_ldap_getAttr(res
->entry
, "mgrpRFC822MailMember");
2177 while (value
[attr_count
] != NULL
) {
2178 (void) fprintf(stdout
, "%s,", value
[attr_count
]);
2181 (void) fprintf(stdout
, "\n");
2189 static char *h_errno2str(int h_errno
);
2192 genent_publickey(char *line
, int (*cback
)())
2194 char buf
[BUFSIZ
+1], tmpbuf
[BUFSIZ
+1], cname
[BUFSIZ
+1];
2195 char *t
, *p
, *tmppubkey
, *tmpprivkey
;
2197 int buflen
, uid
, retval
= 1, errnum
= 0;
2199 char auth_type
[BUFSIZ
+1], *dot
;
2202 struct _ns_pubkey data
;
2205 struct in6_addr in6
;
2206 char abuf
[INET6_ADDRSTRLEN
];
2209 * don't clobber our argument
2211 if (strlen(line
) >= sizeof (buf
)) {
2212 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2214 return (GENENT_PARSEERR
);
2216 (void) strcpy(buf
, line
);
2221 (void) memset((char *)ecol
, 0, sizeof (ecol
));
2223 if ((t
= strtok(buf
, " \t")) == 0) {
2224 (void) strlcpy(parse_err_msg
, gettext("no cname"),
2226 return (GENENT_PARSEERR
);
2230 * Special case: /etc/publickey usually has an entry
2231 * for principal "nobody". We skip it.
2233 if (strcmp(t
, "nobody") == 0)
2239 if (strncmp(t
, "unix.", 5)) {
2240 (void) strlcpy(parse_err_msg
, gettext("bad cname"),
2242 return (GENENT_PARSEERR
);
2244 (void) strcpy(tmpbuf
, &(t
[5]));
2245 if ((p
= strchr(tmpbuf
, '@')) == 0) {
2246 (void) strlcpy(parse_err_msg
, gettext("bad cname"),
2248 return (GENENT_PARSEERR
);
2251 if (isdigit(*tmpbuf
)) {
2255 * don't generate entries for uids without passwd entries
2257 if ((pwd
= getpwuid(uid
)) == 0) {
2258 (void) fprintf(stderr
,
2259 gettext("can't map uid %d to username, skipping\n"),
2263 (void) strcpy(cname
, pwd
->pw_name
);
2264 data
.hostcred
= NS_HOSTCRED_FALSE
;
2266 if ((hp
= getipnodebyname(tmpbuf
, AF_INET6
,
2267 AI_ALL
| AI_V4MAPPED
, &errnum
)) == NULL
) {
2268 (void) fprintf(stderr
,
2269 gettext("can't map hostname %s to hostaddress, "
2270 "errnum %d %s skipping\n"), tmpbuf
, errnum
,
2271 h_errno2str(errnum
));
2274 (void) memcpy((char *)&in6
.s6_addr
, hp
->h_addr_list
[0],
2276 if (IN6_IS_ADDR_V4MAPPED(&in6
) ||
2277 IN6_IS_ADDR_V4COMPAT(&in6
)) {
2278 IN6_V4MAPPED_TO_INADDR(&in6
, &in
);
2279 if (inet_ntop(AF_INET
, (const void *)&in
, abuf
,
2280 INET6_ADDRSTRLEN
) == NULL
) {
2281 (void) fprintf(stderr
,
2282 gettext("can't convert IPV4 address of"
2283 " hostname %s to string, "
2284 "skipping\n"), tmpbuf
);
2288 if (inet_ntop(AF_INET6
, (const void *)&in6
, abuf
,
2289 INET6_ADDRSTRLEN
) == NULL
) {
2290 (void) fprintf(stderr
,
2291 gettext("can't convert IPV6 address of"
2292 " hostname %s to string, "
2293 "skipping\n"), tmpbuf
);
2297 data
.hostcred
= NS_HOSTCRED_TRUE
;
2299 * tmpbuf could be an alias, use hp->h_name instead.
2300 * hp->h_name is in FQDN format, so extract 1st field.
2302 if ((dot
= strchr(hp
->h_name
, '.')) != NULL
)
2304 (void) snprintf(cname
, sizeof (cname
),
2305 "%s+ipHostNumber=%s", hp
->h_name
, abuf
);
2310 ecol
[0].ec_value
.ec_value_val
= cname
;
2311 ecol
[0].ec_value
.ec_value_len
= strlen(cname
)+1;
2314 * public_data (col 1)
2316 if ((t
= strtok(NULL
, " \t")) == 0) {
2317 (void) strlcpy(parse_err_msg
, gettext("no private_data"),
2319 return (GENENT_PARSEERR
);
2321 if ((p
= strchr(t
, ':')) == 0) {
2322 (void) strlcpy(parse_err_msg
, gettext("bad public_data"),
2324 return (GENENT_PARSEERR
);
2327 ecol
[1].ec_value
.ec_value_val
= t
;
2328 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2329 keylen
= (strlen(t
) / 2) * 8;
2332 * private_data (col 2) and algtype extraction
2337 if (!(t
= strchr(t
, ':'))) {
2338 (void) fprintf(stderr
,
2339 gettext("WARNING: No algorithm type data found "
2340 "in publickey file, assuming 0\n"));
2347 ecol
[2].ec_value
.ec_value_val
= p
;
2348 ecol
[2].ec_value
.ec_value_len
= strlen(p
)+1;
2353 if (AUTH_DES_KEY(keylen
, algtype
))
2355 * {DES} and {DH192-0} means same thing.
2356 * However, nisplus uses "DES" and ldap uses "DH192-0"
2358 * See newkey(1M), __nis_mechalias2authtype() which is
2359 * called by __nis_keyalg2authtype() and getkey_ldap_g()
2361 (void) strlcpy(auth_type
, "DH192-0", BUFSIZ
+1);
2362 else if (!(__nis_keyalg2authtype(keylen
, algtype
, auth_type
,
2364 (void) fprintf(stderr
,
2365 gettext("Could not convert algorithm type to "
2366 "corresponding auth type string\n"));
2367 return (GENENT_ERR
);
2373 data
.name
= strdup(ecol
[0].ec_value
.ec_value_val
);
2374 if (data
.name
== NULL
) {
2375 (void) fprintf(stderr
, gettext("out of memory\n"));
2379 buflen
= sizeof (auth_type
) + strlen(ecol
[1].ec_value
.ec_value_val
) + 3;
2380 if ((tmppubkey
= (char *)malloc(buflen
)) == NULL
) {
2381 (void) fprintf(stderr
, gettext("out of memory\n"));
2384 (void) snprintf(tmppubkey
, buflen
, "{%s}%s", auth_type
,
2385 ecol
[1].ec_value
.ec_value_val
);
2386 data
.pubkey
= tmppubkey
;
2388 buflen
= sizeof (auth_type
) + strlen(ecol
[2].ec_value
.ec_value_val
) + 3;
2389 if ((tmpprivkey
= (char *)malloc(buflen
)) == NULL
) {
2390 (void) fprintf(stderr
, gettext("out of memory\n"));
2394 (void) snprintf(tmpprivkey
, buflen
, "{%s}%s", auth_type
,
2395 ecol
[2].ec_value
.ec_value_val
);
2396 data
.privkey
= tmpprivkey
;
2398 retval
= (*cback
)(&data
, 1);
2399 if (retval
!= NS_LDAP_SUCCESS
) {
2400 if (retval
== LDAP_NO_SUCH_OBJECT
) {
2401 if (data
.hostcred
== NS_HOSTCRED_TRUE
)
2402 (void) fprintf(stdout
,
2403 gettext("Cannot add publickey entry"" (%s),"
2404 " add host entry first\n"),
2407 (void) fprintf(stdout
,
2408 gettext("Cannot add publickey entry (%s), "
2409 "add passwd entry first\n"),
2412 if (continue_onerror
== 0)
2413 return (GENENT_CBERR
);
2423 dump_publickey(ns_ldap_result_t
*res
, char *container
)
2425 char **value
= NULL
;
2427 char domainname
[BUFSIZ
];
2428 char *pubptr
, *prvptr
;
2433 if (sysinfo(SI_SRPC_DOMAIN
, domainname
, BUFSIZ
) < 0) {
2434 (void) fprintf(stderr
,
2435 gettext("could not obtain domainname\n"));
2440 * Retrieve all the attributes, but don't print
2441 * until we have all the required ones.
2444 if (strcmp(container
, "passwd") == 0)
2445 value
= __ns_ldap_getAttr(res
->entry
, "uidNumber");
2447 value
= __ns_ldap_getAttr(res
->entry
, "cn");
2449 if (value
&& value
[0])
2450 (void) snprintf(buf
, sizeof (buf
), "unix.%s@%s",
2451 value
[0], domainname
);
2455 value
= __ns_ldap_getAttr(res
->entry
, "nisPublickey");
2456 if (value
!= NULL
&& value
[0] != NULL
) {
2457 if ((pubptr
= strchr(value
[0], '}')) == NULL
)
2461 value
= __ns_ldap_getAttr(res
->entry
, "nisSecretkey");
2462 if (value
!= NULL
&& value
[0] != NULL
)
2463 if ((prvptr
= strchr(value
[0], '}')) == NULL
)
2466 /* print the attributes, algorithm type is always 0 */
2467 (void) fprintf(stdout
, "%s %s:%s:0\n", buf
, ++pubptr
, ++prvptr
);
2477 genent_netmasks(char *line
, int (*cback
)())
2484 struct _ns_netmasks data
;
2488 * don't clobber our argument
2490 if (strlen(line
) >= sizeof (buf
)) {
2491 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2493 return (GENENT_PARSEERR
);
2495 (void) strcpy(buf
, line
);
2500 (void) memset((char *)ecol
, 0, sizeof (ecol
));
2505 t
= strchr(buf
, '#');
2508 ecol
[2].ec_value
.ec_value_val
= t
;
2509 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
2511 ecol
[2].ec_value
.ec_value_val
= 0;
2512 ecol
[2].ec_value
.ec_value_len
= 0;
2518 if ((t
= strtok(buf
, " \t")) == 0) {
2519 (void) strlcpy(parse_err_msg
, gettext("no mask"),
2521 return (GENENT_PARSEERR
);
2523 ecol
[0].ec_value
.ec_value_val
= t
;
2524 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
2529 if ((t
= strtok(NULL
, " \t")) == 0) {
2530 (void) strlcpy(parse_err_msg
, gettext("no mask"),
2532 return (GENENT_PARSEERR
);
2534 ecol
[1].ec_value
.ec_value_val
= t
;
2535 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2538 data
.netnumber
= ecol
[0].ec_value
.ec_value_val
;
2539 data
.netmask
= ecol
[1].ec_value
.ec_value_val
;
2541 if (flags
& F_VERBOSE
)
2542 (void) fprintf(stdout
,
2543 gettext("Adding entry : %s\n"), data
.netnumber
);
2545 retval
= (*cback
)(&data
, 1);
2546 if (retval
!= NS_LDAP_SUCCESS
) {
2547 if (retval
== LDAP_NO_SUCH_OBJECT
)
2548 (void) fprintf(stdout
,
2549 gettext("Cannot add netmask entry (%s), "
2550 "add network entry first\n"), data
.netnumber
);
2551 if (continue_onerror
== 0)
2552 return (GENENT_CBERR
);
2559 dump_netmasks(ns_ldap_result_t
*res
)
2561 char **value
= NULL
;
2563 value
= __ns_ldap_getAttr(res
->entry
, "ipNetworkNumber");
2564 if (value
&& value
[0])
2565 (void) fprintf(stdout
, "%s", value
[0]);
2566 value
= __ns_ldap_getAttr(res
->entry
, "ipNetmaskNumber");
2567 if (value
&& value
[0])
2568 (void) fprintf(stdout
, " %s\n", value
[0]);
2574 * column data format is:
2575 * col 0: netgroup name (or cname)
2576 * col 1: netgroup member, if this is a triplet
2577 * col 2: netgroup member, if not a triplet
2582 genent_netgroup(char *line
, int (*cback
)())
2584 char buf
[BIGBUF
+1]; /* netgroup entries tend to be big */
2588 char *netg_tmp
= NULL
, *triplet_tmp
= NULL
;
2589 int netgcount
= 0, tripletcount
= 0, retval
= 1, i
;
2590 struct _ns_netgroups data
;
2593 /* don't clobber our argument */
2594 if (strlen(line
) >= sizeof (buf
)) {
2595 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2597 return (GENENT_PARSEERR
);
2599 (void) strcpy(buf
, line
);
2601 /* clear column data */
2602 (void) memset((char *)ecol
, 0, sizeof (ecol
));
2605 * process 1st minimal entry, to validate that there is no
2607 * start with comment(col 3)
2609 t
= strchr(buf
, '#');
2612 ecol
[3].ec_value
.ec_value_val
= t
;
2613 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
2615 ecol
[3].ec_value
.ec_value_val
= "";
2616 ecol
[3].ec_value
.ec_value_len
= 0;
2619 ecol
[1].ec_value
.ec_value_val
= NULL
;
2620 ecol
[2].ec_value
.ec_value_val
= NULL
;
2623 if ((t
= strtok(buf
, " \t")) == 0) {
2624 (void) strlcpy(parse_err_msg
, gettext("no cname"),
2626 return (GENENT_PARSEERR
);
2629 ecol
[0].ec_value
.ec_value_val
= t
;
2630 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
2633 /* addr(col 1 and 2) */
2634 if ((t
= strtok(NULL
, " \t")) == 0) {
2635 (void) strlcpy(parse_err_msg
,
2636 gettext("no members for netgroup"), PARSE_ERR_MSG_LEN
);
2637 return (GENENT_PARSEERR
);
2641 /* if token starts with '(' it must be a valid triplet */
2642 if (is_triplet(t
)) {
2643 ecol
[1].ec_value
.ec_value_val
= t
;
2644 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2646 (void) strlcpy(parse_err_msg
,
2647 gettext("invalid triplet"), PARSE_ERR_MSG_LEN
);
2648 return (GENENT_PARSEERR
);
2651 ecol
[2].ec_value
.ec_value_val
= t
;
2652 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
2657 * start by clearing entry data
2659 (void) memset((struct _ns_netgroups
*)&data
, 0, sizeof (data
));
2661 data
.name
= strdup(ecol
[0].ec_value
.ec_value_val
);
2663 if (ecol
[1].ec_value
.ec_value_val
!= NULL
) {
2664 if ((data
.triplet
= calloc(1, sizeof (char **))) == NULL
) {
2665 (void) fprintf(stderr
,
2666 gettext("out of memory\n"));
2669 data
.triplet
[tripletcount
++] =
2670 strdup(ecol
[1].ec_value
.ec_value_val
);
2671 } else if (ecol
[2].ec_value
.ec_value_val
!= NULL
) {
2672 if ((data
.netgroup
= calloc(1, sizeof (char **)))
2674 (void) fprintf(stderr
,
2675 gettext("out of memory\n"));
2678 data
.netgroup
[netgcount
++] =
2679 strdup(ecol
[2].ec_value
.ec_value_val
);
2683 * we now have a valid entry (at least 1 netgroup name and
2684 * 1 netgroup member), proceed with the rest of the line
2686 while (rc
== GENENT_OK
&& (t
= strtok(NULL
, " \t"))) {
2688 /* if next token is equal to netgroup name, ignore */
2689 if (t
!= cname
&& strcasecmp(t
, cname
) == 0)
2691 if (strcasecmp(t
, ecol
[0].ec_value
.ec_value_val
) == 0)
2695 if (is_triplet(t
)) {
2696 /* skip a triplet if it is added already */
2697 for (i
= 0; i
< tripletcount
&&
2698 strcmp(t
, data
.triplet
[i
]); i
++)
2700 if (i
< tripletcount
)
2704 triplet_tmp
= strdup(t
);
2705 if ((data
.triplet
= (char **)realloc(
2707 tripletcount
* sizeof (char **))) == NULL
) {
2708 (void) fprintf(stderr
,
2709 gettext("out of memory\n"));
2712 data
.triplet
[tripletcount
-1] = triplet_tmp
;
2714 (void) strlcpy(parse_err_msg
,
2715 gettext("invalid triplet"),
2717 rc
= GENENT_PARSEERR
;
2720 /* skip a netgroup if it is added already */
2721 for (i
= 0; i
< netgcount
&&
2722 strcmp(t
, data
.netgroup
[i
]); i
++)
2728 netg_tmp
= strdup(t
);
2729 if ((data
.netgroup
= (char **)realloc(data
.netgroup
,
2730 netgcount
* sizeof (char **))) == NULL
) {
2731 (void) fprintf(stderr
,
2732 gettext("out of memory\n"));
2735 data
.netgroup
[netgcount
-1] = netg_tmp
;
2739 /* End the list with NULL */
2740 if ((data
.triplet
= (char **)realloc(data
.triplet
,
2741 (tripletcount
+ 1) * sizeof (char **))) == NULL
) {
2742 (void) fprintf(stderr
, gettext("out of memory\n"));
2745 data
.triplet
[tripletcount
] = NULL
;
2746 if ((data
.netgroup
= (char **)realloc(data
.netgroup
,
2747 (netgcount
+ 1) * sizeof (char **))) == NULL
) {
2748 (void) fprintf(stderr
, gettext("out of memory\n"));
2751 data
.netgroup
[netgcount
] = NULL
;
2753 if (rc
== GENENT_OK
) {
2754 if (flags
& F_VERBOSE
)
2755 (void) fprintf(stdout
,
2756 gettext("Adding entry : %s\n"), data
.name
);
2758 retval
= (*cback
)(&data
, 0);
2760 if (retval
== LDAP_ALREADY_EXISTS
) {
2761 if (continue_onerror
)
2762 (void) fprintf(stderr
, gettext(
2763 "Entry: %s - already Exists,"
2764 " skipping it.\n"), data
.name
);
2767 (void) fprintf(stderr
,
2768 gettext("Entry: %s - already Exists\n"),
2775 /* release memory allocated by strdup() */
2776 for (i
= 0; i
< tripletcount
; i
++) {
2777 free(data
.triplet
[i
]);
2779 for (i
= 0; i
< netgcount
; i
++) {
2780 free(data
.netgroup
[i
]);
2785 free(data
.netgroup
);
2791 dump_netgroup(ns_ldap_result_t
*res
)
2793 char **value
= NULL
;
2796 value
= __ns_ldap_getAttr(res
->entry
, "cn");
2797 if ((value
!= NULL
) && (value
[0] != NULL
))
2798 (void) fprintf(stdout
, "%s", value
[0]);
2801 value
= __ns_ldap_getAttr(res
->entry
, "nisNetgroupTriple");
2803 while (value
[attr_count
] != NULL
) {
2804 (void) fprintf(stdout
, " %s", value
[attr_count
]);
2808 value
= __ns_ldap_getAttr(res
->entry
, "memberNisNetgroup");
2810 while (value
[attr_count
] != NULL
) {
2811 (void) fprintf(stdout
, " %s", value
[attr_count
]);
2814 (void) fprintf(stdout
, "\n");
2819 genent_automount(char *line
, int (*cback
)())
2824 struct _ns_automount data
;
2829 * don't clobber our argument
2831 if (strlen(line
) >= sizeof (buf
)) {
2832 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2834 return (GENENT_PARSEERR
);
2837 /* replace every tabspace with single space */
2838 replace_tab2space(line
);
2839 (void) strcpy(buf
, line
);
2844 (void) memset((char *)ecol
, 0, sizeof (ecol
));
2853 if ((s
= strchr(t
, ' ')) == 0) {
2854 return (GENENT_PARSEERR
);
2858 ecol
[0].ec_value
.ec_value_val
= t
;
2859 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
2869 ecol
[1].ec_value
.ec_value_val
= t
;
2870 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2872 data
.mapname
= strdup(databasetype
);
2873 data
.key
= strdup(ecol
[0].ec_value
.ec_value_val
);
2874 data
.value
= strdup(ecol
[1].ec_value
.ec_value_val
);
2876 if (flags
& F_VERBOSE
)
2877 (void) fprintf(stdout
,
2878 gettext("Adding entry : %s\n"), data
.key
);
2880 retval
= (*cback
)(&data
, 0);
2882 if (retval
== LDAP_ALREADY_EXISTS
) {
2883 if (continue_onerror
)
2884 (void) fprintf(stderr
,
2885 gettext("Entry: %s - already Exists,"
2886 " skipping it.\n"), data
.key
);
2889 (void) fprintf(stderr
,
2890 gettext("Entry: %s - already Exists\n"),
2903 dump_automount(ns_ldap_result_t
*res
)
2905 char **value
= NULL
;
2910 value
= __ns_ldap_getAttr(res
->entry
, "automountKey");
2911 if (value
!= NULL
) {
2912 (void) fprintf(stdout
, "%s", value
[0]);
2913 value
= __ns_ldap_getAttr(res
->entry
, "automountInformation");
2915 (void) fprintf(stdout
, " %s\n", value
[0]);
2917 (void) fprintf(stdout
, "\n");
2928 genent_passwd(char *line
, int (*cback
)())
2941 * don't clobber our argument
2943 if (strlen(line
) >= sizeof (buf
)) {
2944 (void) strlcpy(parse_err_msg
, gettext("line too long"),
2946 return (GENENT_PARSEERR
);
2948 (void) strcpy(buf
, line
);
2951 /* ignore empty entries */
2958 (void) memset((char *)ecol
, 0, sizeof (ecol
));
2963 if ((s
= strchr(t
, ':')) == 0) {
2964 (void) strlcpy(parse_err_msg
, gettext("no password"),
2966 return (GENENT_PARSEERR
);
2969 ecol
[0].ec_value
.ec_value_val
= t
;
2970 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
2976 if ((s
= strchr(t
, ':')) == 0) {
2977 (void) strlcpy(parse_err_msg
, gettext("no uid"),
2979 return (GENENT_PARSEERR
);
2983 ecol
[1].ec_value
.ec_value_val
= t
;
2984 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
2991 if ((s
= strchr(t
, ':')) == 0 || s
== t
) {
2992 (void) strlcpy(parse_err_msg
, gettext("no gid"),
2994 return (GENENT_PARSEERR
);
2997 ecol
[2].ec_value
.ec_value_val
= t
;
2998 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
3004 if ((s
= strchr(t
, ':')) == 0 || s
== t
) {
3005 (void) strlcpy(parse_err_msg
, gettext("no gcos"),
3007 return (GENENT_PARSEERR
);
3010 ecol
[3].ec_value
.ec_value_val
= t
;
3011 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
3017 if ((s
= strchr(t
, ':')) == 0) {
3018 (void) strlcpy(parse_err_msg
, gettext("no home"),
3020 return (GENENT_PARSEERR
);
3023 ecol
[4].ec_value
.ec_value_val
= t
;
3024 ecol
[4].ec_value
.ec_value_len
= strlen(t
)+1;
3030 if ((s
= strchr(t
, ':')) == 0) {
3031 (void) strlcpy(parse_err_msg
, gettext("no shell"),
3033 return (GENENT_PARSEERR
);
3036 ecol
[5].ec_value
.ec_value_val
= t
;
3037 ecol
[5].ec_value
.ec_value_len
= strlen(t
)+1;
3043 ecol
[6].ec_value
.ec_value_val
= t
;
3044 ecol
[6].ec_value
.ec_value_len
= strlen(t
)+1;
3049 data
.pw_name
= strdup(ecol
[0].ec_value
.ec_value_val
);
3051 if (flags
& F_PASSWD
) {
3052 /* Add {crypt} before passwd entry */
3053 (void) snprintf(pname
, sizeof (pname
), "{crypt}%s",
3054 ecol
[1].ec_value
.ec_value_val
);
3055 data
.pw_passwd
= strdup(pname
);
3058 data
.pw_passwd
= NULL
;
3060 if (ecol
[2].ec_value
.ec_value_val
!= NULL
&&
3061 ecol
[2].ec_value
.ec_value_val
[0] != '\0') {
3062 data
.pw_uid
= ascii_to_int(ecol
[2].ec_value
.ec_value_val
);
3063 if (data
.pw_uid
== (uid_t
)-1) {
3064 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3065 gettext("invalid uid : %s"),
3066 ecol
[2].ec_value
.ec_value_val
);
3067 return (GENENT_PARSEERR
);
3070 data
.pw_uid
= (uid_t
)-1;
3072 if (ecol
[3].ec_value
.ec_value_val
!= NULL
&&
3073 ecol
[3].ec_value
.ec_value_val
[0] != '\0') {
3075 data
.pw_gid
= ascii_to_int(ecol
[3].ec_value
.ec_value_val
);
3076 if (data
.pw_gid
== (uid_t
)-1) {
3077 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3078 gettext("invalid gid : %s"),
3079 ecol
[3].ec_value
.ec_value_val
);
3080 return (GENENT_PARSEERR
);
3083 data
.pw_gid
= (uid_t
)-1;
3086 data
.pw_comment
= NULL
;
3087 data
.pw_gecos
= strdup(ecol
[4].ec_value
.ec_value_val
);
3088 data
.pw_dir
= strdup(ecol
[5].ec_value
.ec_value_val
);
3089 data
.pw_shell
= strdup(ecol
[6].ec_value
.ec_value_val
);
3091 if (flags
& F_VERBOSE
)
3092 (void) fprintf(stdout
,
3093 gettext("Adding entry : %s\n"), data
.pw_name
);
3095 retval
= (*cback
)(&data
, 0);
3097 if (retval
== LDAP_ALREADY_EXISTS
) {
3098 if (continue_onerror
)
3099 (void) fprintf(stderr
,
3100 gettext("Entry: %s - already Exists,"
3101 " skipping it.\n"), data
.pw_name
);
3104 (void) fprintf(stderr
,
3105 gettext("Entry: %s - already Exists\n"),
3112 free(data
.pw_gecos
);
3114 free(data
.pw_shell
);
3120 dump_passwd(ns_ldap_result_t
*res
)
3122 char **value
= NULL
;
3124 value
= __ns_ldap_getAttr(res
->entry
, "uid");
3128 (void) fprintf(stdout
, "%s:", value
[0]);
3129 value
= __ns_ldap_getAttr(res
->entry
, "userPassword");
3132 * Don't print the encrypted password, Use x to
3133 * indicate it is in the shadow database.
3135 (void) fprintf(stdout
, "x:");
3137 value
= __ns_ldap_getAttr(res
->entry
, "uidNumber");
3138 if (value
&& value
[0])
3139 (void) fprintf(stdout
, "%s:", value
[0]);
3140 value
= __ns_ldap_getAttr(res
->entry
, "gidNumber");
3141 if (value
&& value
[0])
3142 (void) fprintf(stdout
, "%s:", value
[0]);
3143 value
= __ns_ldap_getAttr(res
->entry
, "gecos");
3145 (void) fprintf(stdout
, ":");
3147 (void) fprintf(stdout
, "%s:", value
[0]);
3148 value
= __ns_ldap_getAttr(res
->entry
, "homeDirectory");
3150 (void) fprintf(stdout
, ":");
3152 (void) fprintf(stdout
, "%s:", value
[0]);
3153 value
= __ns_ldap_getAttr(res
->entry
, "loginShell");
3155 (void) fprintf(stdout
, "\n");
3157 (void) fprintf(stdout
, "%s\n", value
[0]);
3166 genent_shadow(char *line
, int (*cback
)())
3179 * don't clobber our argument
3181 if (strlen(line
) >= sizeof (buf
)) {
3182 (void) strlcpy(parse_err_msg
, gettext("line too long"),
3184 return (GENENT_PARSEERR
);
3186 (void) strcpy(buf
, line
);
3189 /* ignore empty entries */
3196 (void) memset((char *)ecol
, 0, sizeof (ecol
));
3201 if ((s
= strchr(t
, ':')) == 0) {
3202 (void) strlcpy(parse_err_msg
, gettext("no uid"),
3204 return (GENENT_PARSEERR
);
3207 ecol
[0].ec_value
.ec_value_val
= t
;
3208 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
3214 if ((s
= strchr(t
, ':')) == 0) {
3215 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3217 return (GENENT_PARSEERR
);
3221 ecol
[1].ec_value
.ec_value_val
= t
;
3222 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
3227 * shadow last change (col 2)
3229 if ((s
= strchr(t
, ':')) == 0) {
3230 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3232 return (GENENT_PARSEERR
);
3235 ecol
[2].ec_value
.ec_value_val
= t
;
3236 ecol
[2].ec_value
.ec_value_len
= strlen(t
)+1;
3240 * shadow min (col 3)
3242 if ((s
= strchr(t
, ':')) == 0) {
3243 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3245 return (GENENT_PARSEERR
);
3248 ecol
[3].ec_value
.ec_value_val
= t
;
3249 ecol
[3].ec_value
.ec_value_len
= strlen(t
)+1;
3253 * shadow max (col 4)
3255 if ((s
= strchr(t
, ':')) == 0) {
3256 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3258 return (GENENT_PARSEERR
);
3261 ecol
[4].ec_value
.ec_value_val
= t
;
3262 ecol
[4].ec_value
.ec_value_len
= strlen(t
)+1;
3266 * shadow warn (col 5)
3268 if ((s
= strchr(t
, ':')) == 0) {
3269 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3271 return (GENENT_PARSEERR
);
3274 ecol
[5].ec_value
.ec_value_val
= t
;
3275 ecol
[5].ec_value
.ec_value_len
= strlen(t
)+1;
3279 * shadow inactive (col 6)
3281 if ((s
= strchr(t
, ':')) != 0) {
3283 ecol
[6].ec_value
.ec_value_val
= t
;
3284 ecol
[6].ec_value
.ec_value_len
= strlen(t
)+1;
3289 * shadow expire (col 7)
3291 if ((s
= strchr(t
, ':')) != 0) {
3293 ecol
[7].ec_value
.ec_value_val
= t
;
3294 ecol
[7].ec_value
.ec_value_len
= strlen(t
)+1;
3300 ecol
[8].ec_value
.ec_value_val
= t
;
3301 ecol
[8].ec_value
.ec_value_len
= strlen(t
)+1;
3308 data
.sp_namp
= strdup(ecol
[0].ec_value
.ec_value_val
);
3310 if (ecol
[1].ec_value
.ec_value_val
!= NULL
&&
3311 ecol
[1].ec_value
.ec_value_val
[0] != '\0') {
3312 /* Add {crypt} before passwd entry */
3313 (void) snprintf(pname
, sizeof (pname
), "{crypt}%s",
3314 ecol
[1].ec_value
.ec_value_val
);
3315 data
.sp_pwdp
= strdup(pname
);
3318 * no password (e.g., deleted by "passwd -d"):
3319 * use the special value NS_LDAP_NO_UNIX_PASSWORD
3322 (void) snprintf(pname
, sizeof (pname
), "{crypt}%s",
3323 NS_LDAP_NO_UNIX_PASSWORD
);
3324 data
.sp_pwdp
= strdup(pname
);
3327 if (ecol
[2].ec_value
.ec_value_val
!= NULL
&&
3328 ecol
[2].ec_value
.ec_value_val
[0] != '\0') {
3330 data
.sp_lstchg
= ascii_to_int(ecol
[2].ec_value
.ec_value_val
);
3331 if (data
.sp_lstchg
< -1) {
3332 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3333 gettext("invalid last changed date: %s"),
3334 ecol
[2].ec_value
.ec_value_val
);
3335 return (GENENT_PARSEERR
);
3338 data
.sp_lstchg
= -1;
3340 if (ecol
[3].ec_value
.ec_value_val
!= NULL
&&
3341 ecol
[3].ec_value
.ec_value_val
[0] != '\0') {
3343 data
.sp_min
= ascii_to_int(ecol
[3].ec_value
.ec_value_val
);
3344 if (data
.sp_min
< -1) {
3345 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3346 gettext("invalid sp_min : %s"),
3347 ecol
[3].ec_value
.ec_value_val
);
3348 return (GENENT_PARSEERR
);
3353 if (ecol
[4].ec_value
.ec_value_val
!= NULL
&&
3354 ecol
[4].ec_value
.ec_value_val
[0] != '\0') {
3356 data
.sp_max
= ascii_to_int(ecol
[4].ec_value
.ec_value_val
);
3357 if (data
.sp_max
< -1) {
3358 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3359 gettext("invalid sp_max : %s"),
3360 ecol
[4].ec_value
.ec_value_val
);
3361 return (GENENT_PARSEERR
);
3366 if (ecol
[5].ec_value
.ec_value_val
!= NULL
&&
3367 ecol
[5].ec_value
.ec_value_val
[0] != '\0') {
3369 data
.sp_warn
= ascii_to_int(ecol
[5].ec_value
.ec_value_val
);
3370 if (data
.sp_warn
< -1) {
3371 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3372 gettext("invalid sp_warn : %s"),
3373 ecol
[5].ec_value
.ec_value_val
);
3374 return (GENENT_PARSEERR
);
3379 if (ecol
[6].ec_value
.ec_value_val
!= NULL
&&
3380 ecol
[6].ec_value
.ec_value_val
[0] != '\0') {
3382 data
.sp_inact
= ascii_to_int(ecol
[6].ec_value
.ec_value_val
);
3383 if (data
.sp_inact
< -1) {
3384 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3385 gettext("invalid sp_inact : %s"),
3386 ecol
[6].ec_value
.ec_value_val
);
3387 return (GENENT_PARSEERR
);
3392 if (ecol
[7].ec_value
.ec_value_val
!= NULL
&&
3393 ecol
[7].ec_value
.ec_value_val
[0] != '\0') {
3395 data
.sp_expire
= ascii_to_int(ecol
[7].ec_value
.ec_value_val
);
3396 if (data
.sp_expire
< -1) {
3397 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3398 gettext("invalid login expiry date : %s"),
3399 ecol
[7].ec_value
.ec_value_val
);
3400 return (GENENT_PARSEERR
);
3403 data
.sp_expire
= -1;
3405 if (ecol
[8].ec_value
.ec_value_val
!= NULL
&&
3406 ecol
[8].ec_value
.ec_value_val
[0] != '\0') {
3409 * data.sp_flag is an unsigned int,
3410 * assign -1 to it, make no sense.
3411 * Use spflag here to avoid lint warning.
3413 spflag
= ascii_to_int(ecol
[8].ec_value
.ec_value_val
);
3415 (void) snprintf(parse_err_msg
, sizeof (parse_err_msg
),
3416 gettext("invalid flag value: %s"),
3417 ecol
[8].ec_value
.ec_value_val
);
3418 return (GENENT_PARSEERR
);
3420 data
.sp_flag
= spflag
;
3424 if (flags
& F_VERBOSE
)
3425 (void) fprintf(stdout
,
3426 gettext("Adding entry : %s\n"), data
.sp_namp
);
3428 retval
= (*cback
)(&data
, 1);
3429 if (retval
!= NS_LDAP_SUCCESS
) {
3430 if (retval
== LDAP_NO_SUCH_OBJECT
)
3431 (void) fprintf(stdout
,
3432 gettext("Cannot add shadow entry (%s), "
3433 "add passwd entry first\n"), data
.sp_namp
);
3434 if (continue_onerror
== 0)
3435 return (GENENT_CBERR
);
3444 dump_shadow(ns_ldap_result_t
*res
)
3446 char **value
= NULL
;
3449 value
= __ns_ldap_getAttr(res
->entry
, "uid");
3453 (void) fprintf(stdout
, "%s:", value
[0]);
3454 value
= __ns_ldap_getAttr(res
->entry
, "userPassword");
3456 (void) fprintf(stdout
, "*:");
3458 (void) strcpy(pnam
, value
[0]);
3459 if (strncasecmp(value
[0], "{crypt}", 7) == 0) {
3460 if (strcmp(pnam
+ 7, NS_LDAP_NO_UNIX_PASSWORD
) == 0)
3461 (void) fprintf(stdout
, ":");
3463 (void) fprintf(stdout
, "%s:", (pnam
+7));
3465 (void) fprintf(stdout
, "*:");
3467 value
= __ns_ldap_getAttr(res
->entry
, "shadowLastChange");
3469 (void) fprintf(stdout
, ":");
3471 (void) fprintf(stdout
, "%s:", value
[0]);
3472 value
= __ns_ldap_getAttr(res
->entry
, "shadowMin");
3474 (void) fprintf(stdout
, ":");
3476 (void) fprintf(stdout
, "%s:", value
[0]);
3477 value
= __ns_ldap_getAttr(res
->entry
, "shadowMax");
3479 (void) fprintf(stdout
, ":");
3481 (void) fprintf(stdout
, "%s:", value
[0]);
3483 value
= __ns_ldap_getAttr(res
->entry
, "shadowWarning");
3485 (void) fprintf(stdout
, ":");
3487 (void) fprintf(stdout
, "%s:", value
[0]);
3489 value
= __ns_ldap_getAttr(res
->entry
, "shadowInactive");
3491 (void) fprintf(stdout
, ":");
3493 (void) fprintf(stdout
, "%s:", value
[0]);
3495 value
= __ns_ldap_getAttr(res
->entry
, "shadowExpire");
3497 (void) fprintf(stdout
, ":");
3499 (void) fprintf(stdout
, "%s:", value
[0]);
3501 value
= __ns_ldap_getAttr(res
->entry
, "shadowFlag");
3502 if (value
== NULL
|| value
[0] == NULL
|| strcmp(value
[0], "0") == 0)
3503 (void) fprintf(stdout
, "\n");
3505 (void) fprintf(stdout
, "%s\n", value
[0]);
3509 genent_bootparams(char *line
, int (*cback
)())
3514 int ctr
= 0, retval
= 1;
3516 struct _ns_bootp data
;
3521 * don't clobber our argument
3523 if (strlen(line
) >= sizeof (buf
)) {
3524 (void) strlcpy(parse_err_msg
, gettext("line too long"),
3526 return (GENENT_PARSEERR
);
3528 (void) strcpy(buf
, line
);
3533 (void) memset((char *)ecol
, 0, sizeof (ecol
));
3539 if ((t
= strtok(buf
, " \t")) == 0) {
3540 (void) strlcpy(parse_err_msg
, gettext("no cname"),
3542 return (GENENT_PARSEERR
);
3544 ecol
[0].ec_value
.ec_value_val
= t
;
3545 ecol
[0].ec_value
.ec_value_len
= strlen(t
)+1;
3550 data
.name
= strdup(ecol
[0].ec_value
.ec_value_val
);
3558 while (t
= strtok(NULL
, " \t")) {
3561 * don't clobber comment in canonical entry
3565 ecol
[1].ec_value
.ec_value_val
= t
;
3566 ecol
[1].ec_value
.ec_value_len
= strlen(t
)+1;
3569 parameter
= strdup(ecol
[1].ec_value
.ec_value_val
);
3570 if ((data
.param
= (char **)realloc(data
.param
,
3571 (ctr
+ 1) * sizeof (char **))) == NULL
) {
3572 (void) fprintf(stderr
, gettext("out of memory\n"));
3575 data
.param
[ctr
-1] = parameter
;
3580 /* End the list of all the aliases by NULL */
3581 if ((data
.param
= (char **)realloc(data
.param
,
3582 (ctr
+ 1) * sizeof (char **))) == NULL
) {
3583 (void) fprintf(stderr
, gettext("out of memory\n"));
3586 data
.param
[ctr
] = NULL
;
3588 if (flags
& F_VERBOSE
)
3589 (void) fprintf(stdout
,
3590 gettext("Adding entry : %s\n"), data
.name
);
3592 retval
= (*cback
)(&data
, 0);
3594 if (retval
== LDAP_ALREADY_EXISTS
) {
3595 if (continue_onerror
)
3596 (void) fprintf(stderr
,
3597 gettext("Entry: %s - already Exists,"
3598 " skipping it.\n"), data
.name
);
3601 (void) fprintf(stderr
,
3602 gettext("Entry: %s - already Exists\n"),
3616 * Count number of tokens in string which has tokens separated by colons.
3618 * NULL or "" - 0 tokens
3620 * "foo:bar" - 2 tokens
3621 * ":bar" - 2 tokens, first empty
3622 * "::" - 3 tokens, all empty
3625 count_tokens(char *string
, char delim
)
3630 if (string
== NULL
|| *string
== '\0')
3633 /* Count delimiters */
3634 while ((s
= strchr(s
, delim
)) != NULL
&& *s
!= '\0') {
3643 genent_project(char *line
, int (*cback
)())
3648 int rc
= GENENT_OK
, retval
;
3650 struct project data
;
3652 (void) memset(&data
, 0, sizeof (struct project
));
3655 * don't clobber our argument
3657 if (strlen(line
) >= sizeof (buf
)) {
3658 (void) strlcpy(parse_err_msg
, gettext("line too long"),
3660 return (GENENT_PARSEERR
);
3663 if (count_tokens(line
, ':') != 6) {
3664 (void) strlcpy(parse_err_msg
, gettext("Improper format"),
3666 return (GENENT_PARSEERR
);
3669 (void) strcpy(buf
, line
);
3671 s
= strsep(&b
, ":");
3676 if (check_projname(s
) != 0) {
3677 (void) strlcpy(parse_err_msg
,
3678 gettext("invalid project name"),
3680 return (GENENT_PARSEERR
);
3682 data
.pj_name
= strdup(s
);
3689 char *endptr
= NULL
;
3690 int projid
= strtoul(s
, &endptr
, 10);
3692 if (*s
== '\0' || strlen(endptr
) != 0 || projid
< 0 ||
3693 projid
> MAXPROJID
) {
3694 (void) strlcpy(parse_err_msg
,
3695 gettext("invalid project id"),
3697 return (GENENT_PARSEERR
);
3699 data
.pj_projid
= projid
;
3704 /* Project description */
3707 data
.pj_comment
= strdup(s
);
3716 char *usrlist
= strdup(s
);
3718 int usr_count
= count_tokens(usrlist
, ',');
3719 char *u
= strsep(&usrlist
, ",");
3721 if (usr_count
== 0) {
3726 /* +1 to NULL-terminate the array */
3727 data
.pj_users
= (char **)calloc(usr_count
+ 1,
3731 data
.pj_users
[i
++] = strdup(u
);
3732 u
= strsep(&usrlist
, ",");
3739 /* Project groups */
3745 char *grouplist
= strdup(s
);
3747 int grp_count
= count_tokens(grouplist
, ',');
3748 char *g
= strsep(&grouplist
, ",");
3750 if (grp_count
== 0) {
3755 /* +1 to NULL-terminate the array */
3756 data
.pj_groups
= (char **)calloc(grp_count
+ 1,
3760 data
.pj_groups
[i
++] = strdup(g
);
3761 g
= strsep(&grouplist
, ",");
3771 data
.pj_attr
= strdup(s
);
3777 s
= strsep(&b
, ":");
3781 if (flags
& F_VERBOSE
)
3782 (void) fprintf(stdout
,
3783 gettext("Adding entry : %s\n"), data
.pj_name
);
3785 retval
= (*cback
)(&data
, 0);
3787 if (retval
== LDAP_ALREADY_EXISTS
) {
3788 if (continue_onerror
)
3789 (void) fprintf(stderr
,
3790 gettext("Entry: %s - already Exists,"
3791 " skipping it.\n"), data
.pj_name
);
3794 (void) fprintf(stderr
,
3795 gettext("Entry: %s - already Exists\n"),
3804 if (data
.pj_users
!= NULL
) {
3805 for (index
= 0; data
.pj_users
[index
] != NULL
; index
++)
3806 free(data
.pj_users
[index
]);
3807 free(data
.pj_users
);
3809 if (data
.pj_groups
!= NULL
) {
3810 for (index
= 0; data
.pj_groups
[index
] != NULL
; index
++)
3811 free(data
.pj_groups
[index
]);
3812 free(data
.pj_groups
);
3819 dump_project(ns_ldap_result_t
*res
)
3821 char **value
= NULL
;
3822 char *endptr
= NULL
;
3825 if (res
== NULL
|| res
->entry
== NULL
)
3828 /* Sanity checking */
3829 value
= __ns_ldap_getAttr(res
->entry
, "SolarisProjectID");
3831 if (value
[0] == NULL
)
3834 projid
= strtoul(value
[0], &endptr
, 10);
3835 if (*value
[0] == '\0' || strlen(endptr
) != 0 || projid
< 0 ||
3839 value
= __ns_ldap_getAttr(res
->entry
, "SolarisProjectName");
3840 if (value
&& value
[0] && check_projname(value
[0]) == 0)
3841 (void) fprintf(stdout
, "%s:", value
[0]);
3845 (void) fprintf(stdout
, "%d:", projid
);
3847 value
= __ns_ldap_getAttr(res
->entry
, "description");
3848 if (value
&& value
[0])
3849 (void) fprintf(stdout
, "%s:", value
[0]);
3851 (void) fprintf(stdout
, ":");
3853 value
= __ns_ldap_getAttr(res
->entry
, "memberUid");
3856 for (i
= 0; value
[i
] != NULL
; i
++)
3857 if (value
[i
+1] != NULL
)
3858 (void) fprintf(stdout
, "%s,", value
[i
]);
3860 (void) fprintf(stdout
, "%s:", value
[i
]);
3862 (void) fprintf(stdout
, ":");
3865 value
= __ns_ldap_getAttr(res
->entry
, "memberGid");
3868 for (i
= 0; value
[i
] != NULL
; i
++)
3869 if (value
[i
+1] != NULL
)
3870 (void) fprintf(stdout
, "%s,", value
[i
]);
3872 (void) fprintf(stdout
, "%s:", value
[i
]);
3874 (void) fprintf(stdout
, ":");
3877 value
= __ns_ldap_getAttr(res
->entry
, "SolarisProjectAttr");
3878 if (value
&& value
[0])
3879 (void) fprintf(stdout
, "%s\n", value
[0]);
3881 (void) fprintf(stdout
, "\n");
3886 dump_bootparams(ns_ldap_result_t
*res
)
3888 char **value
= NULL
;
3891 value
= __ns_ldap_getAttr(res
->entry
, "cn");
3892 if (value
[0] != NULL
)
3893 (void) fprintf(stdout
, "%s", value
[0]);
3894 value
= __ns_ldap_getAttr(res
->entry
, "bootParameter");
3896 while (value
[attr_count
] != NULL
) {
3897 (void) fprintf(stdout
, "\t%s", value
[attr_count
]);
3900 (void) fprintf(stdout
, "\n");
3906 fget_line_at(struct line_buf
*line
, int n
, FILE *fp
)
3916 if (line
->len
>= line
->alloc
)
3917 line_buf_expand(line
);
3918 line
->str
[line
->len
++] = c
;
3924 /* Null Terminate */
3925 if (line
->len
>= line
->alloc
)
3926 line_buf_expand(line
);
3927 line
->str
[line
->len
++] = 0;
3929 /* if no characters are read, return NULL to indicate EOF */
3930 if (line
->str
[0] == '\0')
3937 * return a line from the file, discarding comments and blank lines
3940 filedbmline_comment(struct line_buf
*line
, FILE *etcf
, int *lineno
,
3941 struct file_loc
*loc
)
3945 loc
->offset
= ftell(etcf
);
3947 if (fget_line_at(line
, len
, etcf
) == 0)
3953 len
= strlen(line
->str
);
3955 line
->str
[0] != '#' &&
3956 line
->str
[len
-2] == '\\' && line
->str
[len
-1] == '\n') {
3957 line
->str
[len
-2] = 0;
3959 continue; /* append next line at end */
3962 if (line
->str
[len
-1] == '\n') {
3963 line
->str
[len
-1] = 0;
3968 * Skip lines where '#' is the first non-blank character.
3970 for (i
= 0; i
< len
; i
++) {
3971 if (line
->str
[i
] == '#') {
3972 line
->str
[i
] = '\0';
3976 if (line
->str
[i
] != ' ' && line
->str
[i
] != '\t')
3981 * A line with one or more white space characters followed
3982 * by a comment will now be blank. The special case of a
3983 * line with '#' in the first byte will have len == 0.
3985 if (len
> 0 && !blankline(line
->str
))
3989 loc
->offset
= ftell(etcf
);
3997 * return a line from the file, discarding comments, blanks, and '+' lines
4000 filedbmline_plus(struct line_buf
*line
, FILE *etcf
, int *lineno
,
4001 struct file_loc
*loc
)
4005 loc
->offset
= ftell(etcf
);
4007 if (fget_line_at(line
, len
, etcf
) == 0)
4013 len
= strlen(line
->str
);
4014 if (line
->str
[len
-1] == '\n') {
4015 line
->str
[len
-1] = 0;
4019 if (!blankline(line
->str
) &&
4020 line
->str
[0] != '+' && line
->str
[0] != '-' &&
4021 line
->str
[0] != '#')
4025 loc
->offset
= ftell(etcf
);
4033 /* Populating the ttypelist structure */
4035 static struct ttypelist_t ttypelist
[] = {
4036 { NS_LDAP_TYPE_HOSTS
, genent_hosts
, dump_hosts
,
4037 filedbmline_comment
, "iphost", "cn" },
4038 { NS_LDAP_TYPE_IPNODES
, genent_hosts
, dump_hosts
,
4039 filedbmline_comment
, "iphost", "cn" },
4040 { NS_LDAP_TYPE_RPC
, genent_rpc
, dump_rpc
,
4041 filedbmline_comment
, "oncrpc", "cn" },
4042 { NS_LDAP_TYPE_PROTOCOLS
, genent_protocols
, dump_protocols
,
4043 filedbmline_comment
, "ipprotocol", "cn" },
4044 { NS_LDAP_TYPE_NETWORKS
, genent_networks
, dump_networks
,
4045 filedbmline_comment
, "ipnetwork", "ipnetworknumber" },
4046 { NS_LDAP_TYPE_SERVICES
, genent_services
, dump_services
,
4047 filedbmline_comment
, "ipservice", "cn" },
4048 { NS_LDAP_TYPE_GROUP
, genent_group
, dump_group
,
4049 filedbmline_plus
, "posixgroup", "gidnumber" },
4050 { NS_LDAP_TYPE_NETMASKS
, genent_netmasks
, dump_netmasks
,
4051 filedbmline_comment
, "ipnetwork", "ipnetworknumber"},
4052 { NS_LDAP_TYPE_ETHERS
, genent_ethers
, dump_ethers
,
4053 filedbmline_comment
, "ieee802Device", "cn" },
4054 { NS_LDAP_TYPE_NETGROUP
, genent_netgroup
, dump_netgroup
,
4055 filedbmline_comment
, "nisnetgroup", "cn" },
4056 { NS_LDAP_TYPE_BOOTPARAMS
, genent_bootparams
, dump_bootparams
,
4057 filedbmline_comment
, "bootableDevice", "cn" },
4058 { NS_LDAP_TYPE_PUBLICKEY
, genent_publickey
, NULL
/* dump_publickey */,
4059 filedbmline_comment
, "niskeyobject", "cn" },
4060 { NS_LDAP_TYPE_PASSWD
, genent_passwd
, dump_passwd
,
4061 filedbmline_plus
, "posixaccount", "uid" },
4062 { NS_LDAP_TYPE_SHADOW
, genent_shadow
, dump_shadow
,
4063 filedbmline_plus
, "shadowaccount", "uid" },
4064 { NS_LDAP_TYPE_ALIASES
, genent_aliases
, dump_aliases
,
4065 filedbmline_plus
, "mailGroup", "cn" },
4066 { NS_LDAP_TYPE_AUTOMOUNT
, genent_automount
, dump_automount
,
4067 filedbmline_comment
, "automount", "automountKey" },
4068 { NS_LDAP_TYPE_USERATTR
, genent_user_attr
, dump_user_attr
,
4069 filedbmline_comment
, "SolarisUserAttr", "uid" },
4070 { NS_LDAP_TYPE_PROFILE
, genent_prof_attr
, dump_prof_attr
,
4071 filedbmline_comment
, "SolarisProfAttr", "cn" },
4072 { NS_LDAP_TYPE_EXECATTR
, genent_exec_attr
, dump_exec_attr
,
4073 filedbmline_comment
, "SolarisExecAttr", "cn" },
4074 { NS_LDAP_TYPE_AUTHATTR
, genent_auth_attr
, dump_auth_attr
,
4075 filedbmline_comment
, "SolarisAuthAttr", "cn" },
4076 { NS_LDAP_TYPE_TNRHDB
, genent_tnrhdb
, dump_tnrhdb
,
4077 filedbmline_comment
, "ipTnetHost", "ipTnetNumber" },
4078 { NS_LDAP_TYPE_TNRHTP
, genent_tnrhtp
, dump_tnrhtp
,
4079 filedbmline_comment
, "ipTnetTemplate", "ipTnetTemplateName" },
4080 { NS_LDAP_TYPE_PROJECT
, genent_project
, dump_project
,
4081 filedbmline_comment
, "SolarisProject", "SolarisProjectName" },
4082 { 0, 0, 0, 0, 0, 0 }
4088 static int lineno
= 0;
4093 struct line_buf line
;
4094 struct file_loc loc
;
4096 /* Initializing the Line Buffer */
4097 line_buf_init(&line
);
4099 /* Loop through all the lines in the file */
4100 while (tt
->filedbmline(&line
, etcf
, &lineno
, &loc
)) {
4101 switch ((*(tt
->genent
))(line
.str
, addentry
)) {
4104 case GENENT_PARSEERR
:
4105 (void) fprintf(stderr
,
4106 gettext("parse error: %s (line %d)\n"),
4107 parse_err_msg
, lineno
);
4111 (void) fprintf(stderr
,
4112 gettext("Error while adding line: %s\n"),
4118 (void) fprintf(stderr
,
4119 gettext("Internal Error while adding line: %s\n"),
4130 dumptable(char *service
)
4133 ns_ldap_result_t
*eres
= NULL
;
4134 ns_ldap_error_t
*err
= NULL
;
4135 int rc
= 0, success
= 0;
4136 char filter
[BUFSIZ
];
4138 void *cookie
= NULL
;
4140 /* set the appropriate filter */
4141 if (strcmp(tt
->ttype
, NS_LDAP_TYPE_PROFILE
) == 0) {
4143 * prof_attr entries are SolarisProfAttr
4144 * without AUXILIARY SolarisExecAttr
4146 (void) snprintf(filter
, sizeof (filter
),
4147 "(&(objectclass=%s)(!(objectclass=SolarisExecAttr)))",
4149 } else if (strcmp(tt
->ttype
, NS_LDAP_TYPE_TNRHDB
) == 0) {
4151 * tnrhtp entries are ipTnet entries with SolarisAttrKeyValue
4153 (void) snprintf(filter
, sizeof (filter
),
4154 "(&(objectclass=%s)(SolarisAttrKeyValue=*)))",
4157 (void) snprintf(filter
, sizeof (filter
),
4158 "(objectclass=%s)", tt
->objclass
);
4161 if (flags
& F_VERBOSE
)
4162 (void) fprintf(stdout
, gettext("FILTER = %s\n"), filter
);
4164 /* Pass cred only if supplied. Cred is not always needed for dump */
4165 if (authority
.cred
.unix_cred
.userID
== NULL
||
4166 authority
.cred
.unix_cred
.passwd
== NULL
)
4167 rc
= __ns_ldap_firstEntry(service
, filter
, tt
->sortattr
, NULL
,
4168 NULL
, NULL
, NS_LDAP_HARD
, &cookie
, &eres
, &err
, NULL
);
4170 rc
= __ns_ldap_firstEntry(service
, filter
, tt
->sortattr
, NULL
,
4171 NULL
, &authority
, NS_LDAP_HARD
, &cookie
, &eres
, &err
, NULL
);
4174 case NS_LDAP_SUCCESS
:
4178 if (strcmp(databasetype
, "publickey") == 0)
4179 dump_publickey(eres
, service
);
4181 (*(tt
->dump
))(eres
);
4184 (void) fprintf(stderr
, gettext("No entries found.\n"));
4187 case NS_LDAP_OP_FAILED
:
4189 (void) fprintf(stderr
, gettext("operation failed.\n"));
4192 case NS_LDAP_INVALID_PARAM
:
4194 (void) fprintf(stderr
,
4195 gettext("invalid parameter(s) passed.\n"));
4198 case NS_LDAP_NOTFOUND
:
4200 (void) fprintf(stderr
, gettext("entry not found.\n"));
4203 case NS_LDAP_MEMORY
:
4205 (void) fprintf(stderr
,
4206 gettext("internal memory allocation error.\n"));
4209 case NS_LDAP_CONFIG
:
4211 (void) fprintf(stderr
,
4212 gettext("LDAP Configuration problem.\n"));
4216 case NS_LDAP_PARTIAL
:
4218 (void) fprintf(stderr
,
4219 gettext("partial result returned\n"));
4223 case NS_LDAP_INTERNAL
:
4225 (void) fprintf(stderr
,
4226 gettext("internal LDAP error occured.\n"));
4232 (void) __ns_ldap_freeResult(&eres
);
4238 rc
= __ns_ldap_nextEntry(cookie
, &eres
, &err
);
4239 if (rc
!= NS_LDAP_SUCCESS
|| eres
== NULL
) {
4244 /* Print the result */
4246 if (strcmp(databasetype
, "publickey") == 0)
4247 dump_publickey(eres
, service
);
4249 (*(tt
->dump
))(eres
);
4250 (void) __ns_ldap_freeResult(&eres
);
4258 main(int argc
, char **argv
)
4261 ns_standalone_conf_t standalone_cfg
= standaloneDefaults
;
4267 char *ttype
, *authmech
= 0, *etcfile
= 0;
4268 /* Temporary password variable */
4269 char ps
[LDAP_MAXNAMELEN
];
4270 char filter
[BUFSIZ
];
4271 void **paramVal
= NULL
;
4273 ns_auth_t
**authpp
= NULL
;
4274 ns_auth_t
*authp
= NULL
;
4275 ns_ldap_error_t
*errorp
= NULL
;
4276 ns_ldap_result_t
*resultp
;
4281 (void) setlocale(LC_ALL
, "");
4282 (void) textdomain(TEXT_DOMAIN
);
4284 openlog("ldapaddent", LOG_PID
, LOG_USER
);
4287 authority
.cred
.unix_cred
.passwd
= NULL
;
4288 authority
.cred
.unix_cred
.userID
= NULL
;
4289 authority
.auth
.type
= NS_LDAP_AUTH_SIMPLE
;
4291 while ((c
= getopt(argc
, argv
, "cdh:N:M:vpf:D:w:j:b:a:P:r:")) != EOF
) {
4296 "no other option should be specified"));
4300 continue_onerror
= 1;
4309 standalone_cfg
.type
= NS_LDAP_SERVER
;
4310 standalone_cfg
.SA_DOMAIN
= optarg
;
4313 standalone_cfg
.type
= NS_LDAP_SERVER
;
4314 if (separatePort(optarg
,
4315 &standalone_cfg
.SA_SERVER
,
4316 &standalone_cfg
.SA_PORT
) > 0) {
4321 standalone_cfg
.type
= NS_LDAP_SERVER
;
4322 authority
.hostcertpath
= optarg
;
4325 standalone_cfg
.type
= NS_LDAP_SERVER
;
4326 standalone_cfg
.SA_PROFILE_NAME
= optarg
;
4332 authority
.cred
.unix_cred
.userID
= strdup(optarg
);
4335 if (authority
.cred
.unix_cred
.passwd
) {
4336 (void) fprintf(stderr
,
4337 gettext("Warning: The -w option is mutually"
4338 " exclusive of -j. -w is ignored.\n"));
4342 if (optarg
!= NULL
&&
4343 optarg
[0] == '-' && optarg
[1] == '\0') {
4344 /* Ask for a password later */
4348 authority
.cred
.unix_cred
.passwd
= strdup(optarg
);
4351 if (authority
.cred
.unix_cred
.passwd
!= NULL
) {
4352 (void) fprintf(stderr
,
4353 gettext("The -w option is mutually "
4354 "exclusive of -j. -w is ignored.\n"));
4355 free(authority
.cred
.unix_cred
.passwd
);
4357 authority
.cred
.unix_cred
.passwd
= readPwd(optarg
);
4358 if (authority
.cred
.unix_cred
.passwd
== NULL
) {
4363 inputbasedn
= strdup(optarg
);
4366 authmech
= strdup(optarg
);
4369 usage(gettext("Invalid option"));
4373 if (standalone_cfg
.type
== NS_LDAP_SERVER
&&
4374 standalone_cfg
.SA_SERVER
== NULL
) {
4375 (void) fprintf(stderr
,
4376 gettext("Please specify an LDAP server you want "
4377 "to connect to. \n"));
4381 if (authmech
!= NULL
) {
4382 if (__ns_ldap_initAuth(authmech
, &authority
.auth
, &errorp
) !=
4385 (void) fprintf(stderr
, "%s", errorp
->message
);
4386 (void) __ns_ldap_freeError(&errorp
);
4392 if (authority
.auth
.saslmech
!= NS_LDAP_SASL_GSSAPI
&&
4393 authority
.cred
.unix_cred
.userID
== NULL
&&
4395 /* This is not an optional parameter. Exit */
4396 (void) fprintf(stderr
,
4397 gettext("DN must be specified unless SASL/GSSAPI is used."
4398 " Use option -D.\n"));
4402 if (authority
.auth
.saslmech
!= NS_LDAP_SASL_GSSAPI
&&
4403 authority
.cred
.unix_cred
.passwd
== NULL
&&
4405 standalone_cfg
.type
!= NS_CACHEMGR
&&
4406 authority
.cred
.unix_cred
.userID
!= NULL
)) {
4407 /* If password is not specified, then prompt user for it. */
4408 password
= getpassphrase("Enter password:");
4409 (void) strcpy(ps
, password
);
4410 authority
.cred
.unix_cred
.passwd
= strdup(ps
);
4413 standalone_cfg
.SA_AUTH
= authmech
== NULL
? NULL
: &authority
.auth
;
4414 standalone_cfg
.SA_CERT_PATH
= authority
.hostcertpath
;
4415 standalone_cfg
.SA_BIND_DN
= authority
.cred
.unix_cred
.userID
;
4416 standalone_cfg
.SA_BIND_PWD
= authority
.cred
.unix_cred
.passwd
;
4418 if (__ns_ldap_initStandalone(&standalone_cfg
,
4419 &errorp
) != NS_LDAP_SUCCESS
) {
4421 (void) fprintf(stderr
, "%s", errorp
->message
);
4426 if (authmech
== NULL
) {
4427 ldaprc
= __ns_ldap_getParam(NS_LDAP_AUTH_P
, (void ***)&authpp
,
4429 if (ldaprc
!= NS_LDAP_SUCCESS
||
4430 (authpp
== NULL
&& op
!= OP_DUMP
)) {
4431 (void) fprintf(stderr
,
4432 gettext("No legal authentication method "
4434 (void) fprintf(stderr
,
4435 gettext("Provide a legal authentication method "
4436 "using -a option\n"));
4440 /* Use the first authentication method which is not none */
4441 for (app
= authpp
; *app
; app
++) {
4443 if (authp
->type
!= NS_LDAP_AUTH_NONE
) {
4445 authority
.auth
.type
= authp
->type
;
4446 authority
.auth
.tlstype
= authp
->tlstype
;
4447 authority
.auth
.saslmech
= authp
->saslmech
;
4448 authority
.auth
.saslopt
= authp
->saslopt
;
4452 if (authstried
== 0 && op
!= OP_DUMP
) {
4453 (void) fprintf(stderr
,
4454 gettext("No legal authentication method configured."
4455 "\nProvide a legal authentication method using "
4459 if (authority
.auth
.saslmech
== NS_LDAP_SASL_GSSAPI
&&
4460 authority
.cred
.unix_cred
.passwd
!= NULL
&&
4461 authority
.cred
.unix_cred
.userID
!= NULL
) {
4463 * -a is not specified and the auth method sasl/GSSAPI
4464 * is defined in the configuration of the ldap profile.
4465 * Even -D and -w is provided it's not valid usage.
4466 * Drop them on the floor.
4469 (void) fprintf(stderr
,
4470 gettext("The default authentication is "
4472 "The bind DN and password will be ignored.\n"));
4473 authority
.cred
.unix_cred
.passwd
= NULL
;
4474 authority
.cred
.unix_cred
.userID
= NULL
;
4478 ttype
= argv
[optind
++];
4480 if (ttype
== NULL
) {
4481 usage(gettext("No database type specified"));
4485 if (strncasecmp(ttype
, "automount", 9) == 0) {
4486 (void) fprintf(stderr
,
4487 gettext("automount is not a valid service for ldapaddent.\n"
4488 "Please use auto_*.\n"
4489 "e.g. auto_home, auto_ws etc.\n "));
4493 for (tt
= ttypelist
; tt
->ttype
; tt
++) {
4494 if (strcmp(tt
->ttype
, ttype
) == 0)
4496 if (strcmp(tt
->ttype
, NS_LDAP_TYPE_AUTOMOUNT
) == 0 &&
4497 strncmp(ttype
, NS_LDAP_TYPE_AUTOMOUNT
,
4498 sizeof (NS_LDAP_TYPE_AUTOMOUNT
) - 1) == 0)
4502 if (tt
->ttype
== 0) {
4503 (void) fprintf(stderr
,
4504 gettext("database %s not supported;"
4505 " supported databases are:\n"), ttype
);
4506 for (tt
= ttypelist
; tt
->ttype
; tt
++)
4507 (void) fprintf(stderr
, gettext("\t%s\n"), tt
->ttype
);
4511 if (flags
& F_VERBOSE
)
4512 (void) fprintf(stdout
, gettext("SERVICE = %s\n"), tt
->ttype
);
4514 databasetype
= ttype
;
4516 if (strcmp(tt
->ttype
, NS_LDAP_TYPE_AUTOMOUNT
) == 0) {
4519 rc
= __ns_ldap_getParam(NS_LDAP_FILE_VERSION_P
, ¶mVal
,
4521 if (paramVal
&& *paramVal
&&
4522 strcasecmp(*paramVal
, NS_LDAP_VERSION_1
) == 0)
4525 (void) __ns_ldap_freeParam(¶mVal
);
4527 (void) __ns_ldap_freeError(&errorp
);
4530 /* Check if the container exists in first place */
4531 (void) strcpy(&filter
[0], "(objectclass=*)");
4533 rc
= __ns_ldap_list(databasetype
, filter
, NULL
, (const char **)NULL
,
4534 NULL
, NS_LDAP_SCOPE_BASE
, &resultp
, &errorp
, NULL
, NULL
);
4536 /* create a container for auto_* if it does not exist already */
4537 if ((rc
== NS_LDAP_NOTFOUND
) && (op
== OP_ADD
) &&
4538 (strcmp(tt
->ttype
, NS_LDAP_TYPE_AUTOMOUNT
) == 0)) {
4539 static char *oclist
[] = {NULL
, "top", NULL
};
4541 oclist
[0] = "nisMap";
4543 oclist
[0] = "automountMap";
4544 e
= __s_mk_entry(oclist
, 3);
4546 (void) fprintf(stderr
,
4547 gettext("internal memory allocation error.\n"));
4551 version1
? "nisMapName" : "automountMapName",
4552 databasetype
) != NS_LDAP_SUCCESS
) {
4553 (void) fprintf(stderr
,
4554 gettext("internal memory allocation error.\n"));
4559 if (inputbasedn
== NULL
) {
4560 if (get_basedn(databasetype
, &inputbasedn
) !=
4562 (void) fprintf(stderr
,
4563 gettext("Could not obtain basedn\n"));
4568 if (__ns_ldap_addEntry(databasetype
, inputbasedn
, e
,
4569 &authority
, flag
, &errorp
) != NS_LDAP_SUCCESS
) {
4570 (void) fprintf(stderr
,
4571 gettext("Could not create container for %s\n"),
4575 } else if (strcmp(databasetype
, "publickey") != 0) {
4576 if (rc
== NS_LDAP_NOTFOUND
) {
4577 (void) fprintf(stderr
,
4578 gettext("Container %s does not exist\n"),
4584 if (op
== OP_DUMP
) {
4585 if (strcmp(databasetype
, "publickey") == 0) {
4587 dumptable("passwd");
4589 dumptable(databasetype
);
4595 if ((etcf
= fopen(etcfile
, "r")) == 0) {
4596 (void) fprintf(stderr
,
4597 gettext("can't open file %s\n"), etcfile
);
4607 (void) fprintf(stdout
, gettext("%d entries added\n"), nent_add
);
4610 __ns_ldap_cancelStandalone();
4611 /* exit() -> return for make lint */
4617 * This is called when service == auto_*.
4618 * It calls __ns_ldap_getSearchDescriptors
4619 * to generate the dn from SSD's base dn.
4620 * If there is no SSD available,
4621 * default base dn will be used
4622 * Only the first baseDN in the SSD is used
4625 static int get_basedn(char *service
, char **basedn
) {
4626 int rc
= NS_LDAP_SUCCESS
;
4628 ns_ldap_search_desc_t
**desc
= NULL
;
4629 ns_ldap_error_t
*errp
= NULL
;
4630 void **paramVal
= NULL
;
4631 int prepend_automountmapname
= FALSE
;
4634 * Get auto_* SSD first
4637 if ((rc
= __ns_ldap_getSearchDescriptors(
4638 (const char *) service
,
4639 &desc
, &errp
)) == NS_LDAP_SUCCESS
&&
4642 if (desc
[0] != NULL
&& desc
[0]->basedn
!= NULL
) {
4643 dn
= strdup(desc
[0]->basedn
);
4645 (void) __ns_ldap_freeSearchDescriptors
4647 return (NS_LDAP_MEMORY
);
4653 if (desc
) (void) __ns_ldap_freeSearchDescriptors(&desc
);
4654 if (errp
) (void) __ns_ldap_freeError(&errp
);
4657 * If no dn is duplicated from auto_* SSD, try automount SSD
4660 if ((rc
= __ns_ldap_getSearchDescriptors(
4661 "automount", &desc
, &errp
))
4662 == NS_LDAP_SUCCESS
&& desc
!= NULL
) {
4664 if (desc
[0] != NULL
&& desc
[0]->basedn
!= NULL
) {
4665 dn
= strdup(desc
[0]->basedn
);
4667 (void) __ns_ldap_freeSearchDescriptors
4669 return (NS_LDAP_MEMORY
);
4671 prepend_automountmapname
= TRUE
;
4675 if (desc
) (void) __ns_ldap_freeSearchDescriptors(&desc
);
4676 if (errp
) (void) __ns_ldap_freeError(&errp
);
4680 * If no dn is duplicated from auto_* or automount SSD,
4685 if ((rc
= __ns_ldap_getParam(NS_LDAP_SEARCH_BASEDN_P
,
4686 ¶mVal
, &errp
)) == NS_LDAP_SUCCESS
) {
4687 dn
= strdup((char *)paramVal
[0]);
4689 (void) __ns_ldap_freeParam(¶mVal
);
4690 return (NS_LDAP_MEMORY
);
4692 prepend_automountmapname
= TRUE
;
4694 if (paramVal
) (void) __ns_ldap_freeParam(¶mVal
);
4695 if (errp
) (void) __ns_ldap_freeError(&errp
);
4700 return (NS_LDAP_OP_FAILED
);
4703 * If dn is duplicated from
4704 * automount SSD basedn or
4706 * then prepend automountMapName=auto_xxx
4708 if (prepend_automountmapname
)
4709 rc
= __s_api_prepend_automountmapname_to_dn(
4710 service
, &dn
, &errp
);
4712 if (rc
!= NS_LDAP_SUCCESS
) {
4713 (void) __ns_ldap_freeError(&errp
);
4720 return (NS_LDAP_SUCCESS
);
4724 h_errno2str(int h_errno
) {
4726 case HOST_NOT_FOUND
:
4727 return ("HOST_NOT_FOUND");
4729 return ("TRY_AGAIN");
4731 return ("NO_RECOVERY");
4737 return ("UNKNOWN_ERROR");