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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Helper functions for standalone functionality
37 #include "ns_internal.h"
39 ns_standalone_conf_t standaloneDefaults
=
40 { {NULL
, /* A directory server's IP/name. No default. */
41 0, /* A directory server's port. No default. */
42 NULL
, /* A domain name. */
43 /* libsldap uses its own default. */
44 "default", /* A DUAProfile's name. */
45 NULL
, /* Authentication information used. */
46 /* If not specified by the user, */
47 /* libsldap will use its own data */
48 NULL
, /* A credential level to be used */
49 /* along with the authentication info. */
50 /* See the previous comment. */
51 NSLDAPDIRECTORY
, /* The default path to */
52 /* the certificate database. */
53 NULL
, /* A bind DN to be used during */
54 /* subsequent LDAP Bind requests */
55 NULL
}, /* A bind password to be used during */
56 /* subsequent LDAP Bind requests */
57 NS_CACHEMGR
}; /* If the -H option is not given, libsldap */
58 /* will obtain all the configuration */
59 /* information from ldap_cachemgr. */
62 separatePort(char *peer
, char **name
, uint16_t *port
)
64 char *chr
, *portStr
= NULL
;
66 chr
= strchr(peer
, '[');
71 chr
= strchr(peer
, ']');
73 (void) fprintf(stderr
,
74 gettext("Server address is wrong: "
81 chr
= strchr(chr
, ':');
82 if (chr
!= NULL
&& *(chr
+ 1) != '\0') {
87 chr
= strchr(peer
, ']');
89 (void) fprintf(stderr
,
90 gettext("Server address is wrong: "
95 chr
= strchr(peer
, ':');
96 if (chr
!= NULL
&& *(chr
+ 1) != '\0') {
104 if ((*name
)[0] == '\0') {
105 (void) fprintf(stderr
,
106 gettext("Server address or name must be"
111 if (portStr
&& sscanf(portStr
, "%hu", port
) != 1) {
112 (void) fprintf(stderr
,
113 gettext("Server port is wrong. "
114 "The default port 389/636 "
121 readPwd(char *pwd_file
)
125 char passwdBuf
[BUFSIZE
];
127 if ((f
= fopen(pwd_file
, "r")) == NULL
) {
128 (void) fprintf(stderr
,
129 gettext("Unable to open '%s' file\n"), pwd_file
);
132 if (fgets(passwdBuf
, BUFSIZE
, f
) == NULL
) {
133 (void) fprintf(stderr
,
134 gettext("Unable to read '%s' file\n"), pwd_file
);
141 if (passwdBuf
[strlen(passwdBuf
) - 1] == '\n') {
142 passwdBuf
[strlen(passwdBuf
) - 1] = '\0';
144 if ((pwd
= strdup(passwdBuf
)) == NULL
) {
145 (void) fprintf(stderr
,
146 gettext("Memory allocation error\n"));