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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* libsldap - cachemgr side configuration components */
29 #include <sys/types.h>
44 #include "ns_internal.h"
45 #include "ns_cache_door.h"
51 * **************************************************************
52 * Configuration File Routines
53 * **************************************************************
57 /* Size of the errstr buffer needs to be MAXERROR */
59 read_line(FILE *fp
, char *buffer
, int buflen
, char *errstr
)
66 for (linelen
= 0; linelen
< buflen
; ) {
72 if (linelen
> 0 && buffer
[linelen
- 1] == '\\') {
73 /* Continuation line found */
76 /* end of line found */
77 buffer
[linelen
] = '\0';
82 buffer
[linelen
++] = c
;
86 if (linelen
>= buflen
) {
87 (void) snprintf(errstr
, MAXERROR
,
88 gettext("Buffer overflow, line too long."));
90 } else if (linelen
> 0 && buffer
[linelen
- 1] == '\\') {
91 (void) snprintf(errstr
, MAXERROR
,
92 gettext("Unterminated continuation line."));
96 buffer
[linelen
] = '\0';
98 return (linelen
> 0 ? linelen
: -1);
102 static ns_parse_status
103 read_file(ns_config_t
*ptr
, int cred_file
, ns_ldap_error_t
**error
)
105 ParamIndexType i
= 0;
106 char errstr
[MAXERROR
];
107 char buffer
[BUFSIZE
], *name
, *value
;
108 int emptyfile
, lineno
;
121 fp
= fopen(file
, "rF");
123 (void) snprintf(errstr
, sizeof (errstr
),
124 gettext("Unable to open filename '%s' "
125 "for reading (errno=%d)."), file
, errno
);
126 MKERROR(LOG_ERR
, *error
, NS_CONFIG_FILE
, strdup(errstr
), NULL
);
127 return (NS_NOTFOUND
);
133 if ((linelen
= read_line(fp
, buffer
, sizeof (buffer
),
140 /* get rid of comment lines */
141 if (buffer
[0] == '#')
146 __s_api_split_key_value(buffer
, &name
, &value
);
147 if (name
== NULL
|| value
== NULL
) {
148 (void) snprintf(errstr
, sizeof (errstr
),
149 gettext("Missing Name or Value on line %d."),
151 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
152 strdup(errstr
), NULL
);
154 return (NS_PARSE_ERR
);
156 if (__s_api_get_versiontype(ptr
, name
, &i
) != 0) {
157 (void) snprintf(errstr
, sizeof (errstr
),
158 gettext("Illegal profile type on line %d."),
160 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
161 strdup(errstr
), NULL
);
163 return (NS_PARSE_ERR
);
165 if (!first
&& i
== NS_LDAP_FILE_VERSION_P
) {
166 (void) snprintf(errstr
, sizeof (errstr
),
167 gettext("Illegal NS_LDAP_FILE_VERSION "
168 "on line %d."), lineno
);
169 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
170 strdup(errstr
), NULL
);
172 return (NS_PARSE_ERR
);
175 switch (__s_api_get_configtype(i
)) {
178 if (cred_file
== 0) {
179 ret
= __ns_ldap_setParamValue(ptr
, i
, value
,
181 if (ret
!= NS_SUCCESS
) {
185 } else if (i
!= NS_LDAP_FILE_VERSION_P
) {
186 (void) snprintf(errstr
, sizeof (errstr
),
187 gettext("Illegal entry in '%s' on "
188 "line %d"), file
, lineno
);
189 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
190 strdup(errstr
), NULL
);
192 return (NS_PARSE_ERR
);
196 if (i
== NS_LDAP_FILE_VERSION_P
)
199 ret
= __ns_ldap_setParamValue(ptr
, i
, value
,
201 if (ret
!= NS_SUCCESS
) {
206 (void) snprintf(errstr
, sizeof (errstr
),
207 gettext("Illegal entry in '%s' on "
208 "line %d"), file
, lineno
);
209 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
210 strdup(errstr
), NULL
);
212 return (NS_PARSE_ERR
);
217 if (!cred_file
&& emptyfile
) {
218 /* Error in read_line */
219 (void) snprintf(errstr
, sizeof (errstr
),
220 gettext("Empty config file: '%s'"), file
);
221 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
223 return (NS_PARSE_ERR
);
226 /* Error in read_line */
227 (void) snprintf(errstr
, sizeof (errstr
),
228 gettext("Line too long in '%s'"), file
);
229 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
231 return (NS_PARSE_ERR
);
239 set_attr(ns_config_t
*config_struct
,
242 ns_ldap_error_t
**errorp
)
245 char errmsg
[MAXERROR
];
247 if (errorp
== NULL
) {
248 return (NS_LDAP_INVALID_PARAM
);
254 * This double call is made due to the presence of
255 * two sets of LDAP config. attribute names.
256 * An LDAP configuration can be obtained either from a server
257 * or from SMF. The former sends a DUA with attributes' names
258 * styled like "preferredServerList". But local configurations
259 * will have names inherited from the /var/ldap/ldap* files such as
260 * "NS_LDAP_SERVER_PREF".
261 * So, the standalone bits are able to process both sets of
264 if (__s_api_get_profiletype(attr_name
, &idx
) < 0 &&
265 __s_api_get_versiontype(config_struct
, attr_name
, &idx
) < 0) {
266 (void) snprintf(errmsg
, sizeof (errmsg
),
267 gettext("Illegal DUAProfile property: <%s>."), attr_name
);
268 MKERROR(LOG_ERR
, *errorp
, NS_LDAP_CONFIG
, strdup(errmsg
), NULL
);
269 return (NS_LDAP_CONFIG
);
272 return (__ns_ldap_setParamValue(config_struct
, idx
, attr_val
, errorp
));
277 * This function creates a configuration which will be used
278 * for all LDAP requests in the Standalone mode.
281 * config - a buffer returned by __ns_ldap_getConnectionInfo()'s
282 * dua_profile parameter.
286 __s_api_create_config_door_str(char *config
, ns_ldap_error_t
**errorp
)
288 char *attr
, *attrName
, *attrVal
, *rest
;
289 ns_config_t
*configStruct
= NULL
;
290 char errmsg
[MAXERROR
];
292 if (config
== NULL
|| errorp
== NULL
)
295 if ((configStruct
= __s_api_create_config()) == NULL
) {
301 attr
= strtok_r(config
, DOORLINESEP
, &rest
);
303 __s_api_destroy_config(configStruct
);
304 (void) snprintf(errmsg
, sizeof (errmsg
),
305 gettext("DUAProfile received from the server"
307 MKERROR(LOG_ERR
, *errorp
, NS_LDAP_CONFIG
, strdup(errmsg
), NULL
);
312 __s_api_split_key_value(attr
, &attrName
, &attrVal
);
314 if (attrName
== NULL
|| attrVal
== NULL
) {
315 __s_api_destroy_config(configStruct
);
316 (void) snprintf(errmsg
, sizeof (errmsg
),
317 gettext("Attribute %s is not valid"), attr
);
318 MKERROR(LOG_ERR
, *errorp
, NS_LDAP_CONFIG
,
319 strdup(errmsg
), NULL
);
323 /* Get the version of the profile. */
324 if (strcasecmp(attrName
, "objectclass") == 0) {
325 if (strcasecmp(attrVal
, _PROFILE2_OBJECTCLASS
) == 0) {
326 if (__ns_ldap_setParamValue(configStruct
,
327 NS_LDAP_FILE_VERSION_P
,
329 errorp
) != NS_LDAP_SUCCESS
) {
330 __s_api_destroy_config(configStruct
);
333 } else if (strcasecmp(attrVal
,
334 _PROFILE1_OBJECTCLASS
) == 0) {
335 if (__ns_ldap_setParamValue(configStruct
,
336 NS_LDAP_FILE_VERSION_P
,
338 errorp
) != NS_LDAP_SUCCESS
) {
339 __s_api_destroy_config(configStruct
);
346 if (set_attr(configStruct
, attrName
, attrVal
, errorp
) !=
348 __s_api_destroy_config(configStruct
);
351 } while (attr
= strtok_r(NULL
, DOORLINESEP
, &rest
));
353 if (__s_api_crosscheck(configStruct
, errmsg
, B_FALSE
) != NS_SUCCESS
) {
354 MKERROR(LOG_ERR
, *errorp
, NS_LDAP_CONFIG
, strdup(errmsg
), NULL
);
355 __s_api_destroy_config(configStruct
);
359 return (configStruct
);
364 * Cache Manager side of configuration file loading
368 __ns_ldap_LoadConfiguration()
370 ns_ldap_error_t
*error
= NULL
;
371 ns_config_t
*ptr
= NULL
;
372 char errstr
[MAXERROR
];
376 ptr
= __s_api_create_config();
378 (void) snprintf(errstr
, sizeof (errstr
),
379 gettext("__ns_ldap_LoadConfiguration: Out of memory."));
380 MKERROR(LOG_ERR
, error
, NS_CONFIG_NOTLOADED
,
381 strdup(errstr
), NULL
);
385 /* Load in Configuration file */
386 ret
= read_file(ptr
, 0, &error
);
387 if (ret
!= NS_SUCCESS
) {
388 __s_api_destroy_config(ptr
);
392 /* Load in Credential file */
393 ret
= read_file(ptr
, 1, &error
);
394 if (ret
!= NS_SUCCESS
) {
395 __s_api_destroy_config(ptr
);
399 if (__s_api_crosscheck(ptr
, errstr
, B_TRUE
) != NS_SUCCESS
) {
400 __s_api_destroy_config(ptr
);
401 MKERROR(LOG_ERR
, error
, NS_CONFIG_SYNTAX
, strdup(errstr
), NULL
);
405 __s_api_init_config(ptr
);
411 __print2buf(LineBuf
*line
, const char *toprint
, char *sep
)
420 newsz
= strlen(toprint
) + line
->len
+ 1;
422 newsz
+= strlen(sep
);
424 if (line
->alloc
== 0 || newsz
> line
->alloc
) {
425 /* Round up to next buffer and add 1 */
426 newmax
= (((newsz
+(BUFSIZ
-1))/BUFSIZ
)+1) * BUFSIZ
;
427 if (line
->alloc
== 0)
428 line
->str
= (char *)calloc(newmax
, 1);
431 * if realloc() returns NULL,
432 * the original buffer is untouched.
433 * It needs to be freed.
435 str
= (char *)realloc(line
->str
, newmax
);
443 line
->alloc
= newmax
;
444 if (line
->str
== NULL
) {
450 /* now add new 'toprint' data to buffer */
451 (void) strlcat(line
->str
, toprint
, line
->alloc
);
453 (void) strlcat(line
->str
, sep
, line
->alloc
);
461 * __ns_ldap_LoadDoorInfo is a routine used by the ldapcachemgr
462 * to create a configuration buffer to transmit back to a client
463 * domainname is transmitted to ldapcachemgr and ldapcachemgr uses
464 * it to select a configuration to transmit back. Otherwise it
465 * is essentially unused in sldap.
466 * If cred_only is not 0, then only the credentials for shadow
467 * update are taken care of.
471 __ns_ldap_LoadDoorInfo(LineBuf
*configinfo
, char *domainname
,
472 ns_config_t
*new, int cred_only
)
475 char errstr
[MAXERROR
];
476 ns_ldap_error_t
*errorp
;
478 ParamIndexType i
= 0;
480 ldap_config_out_t
*cout
;
483 * If new is NULL, it outputs the flatten data of current default
484 * config, if it's non-NULL, it outputs the flatten data of a temporary
485 * config. It's used to compare the new config data with the current
486 * default config data.
489 ptr
= __s_api_get_default_config();
493 (void) snprintf(errstr
, sizeof (errstr
),
494 gettext("No configuration information available for %s."),
495 domainname
== NULL
? "<no domain specified>" : domainname
);
496 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_NOTLOADED
,
497 strdup(errstr
), NULL
);
500 (void) memset((char *)configinfo
, 0, sizeof (LineBuf
));
501 for (i
= 0; i
<= NS_LDAP_MAX_PIT_P
; i
++) {
503 /* only exposed credential for shadow update */
504 if (i
!= NS_LDAP_ADMIN_BINDDN_P
&&
505 i
!= NS_LDAP_ADMIN_BINDPASSWD_P
)
508 /* credential for shadow update is not to be exposed */
509 if (i
== NS_LDAP_ADMIN_BINDDN_P
||
510 i
== NS_LDAP_ADMIN_BINDPASSWD_P
)
513 str
= __s_api_strValue(ptr
, i
, NS_DOOR_FMT
);
516 if (__print2buf(configinfo
, str
, DOORLINESEP
)) {
517 (void) snprintf(errstr
, sizeof (errstr
),
518 gettext("__print2buf: Out of memory."));
519 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_NOTLOADED
,
520 strdup(errstr
), NULL
);
521 __s_api_release_config(ptr
);
528 __s_api_release_config(ptr
);
531 * The new interface of the configuration between ldap_cachemgr
532 * & libsldap contains a header structure ldap_config_out_t.
533 * The flatten configuration data configinfo->str is cloned
534 * to cout->config_str, configinfo->len is saved in
535 * cout->data_size and cout->cookie is set later after this function
536 * is returned in ldap_cachemgr.
537 * configinfo->str & configinfo->len are reused to save info of
540 * [cookie|data_size|config_str .............]
543 if (configinfo
->str
) {
544 len
= sizeof (ldap_config_out_t
) - sizeof (int) +
546 if ((cout
= calloc(1, len
)) == NULL
) {
547 free(configinfo
->str
);
548 configinfo
->str
= NULL
;
550 (void) snprintf(errstr
, sizeof (errstr
),
551 gettext("calloc: Out of memory."));
552 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_NOTLOADED
,
553 strdup(errstr
), NULL
);
557 * cout->cookie is set by the caller,
558 * which is in ldap_cachemgr.
560 cout
->data_size
= configinfo
->len
;
561 (void) memcpy(cout
->config_str
, configinfo
->str
,
563 free(configinfo
->str
);
564 configinfo
->str
= (char *)cout
;
565 configinfo
->len
= len
;
572 __ns_ldap_DumpLdif(char *filename
)
575 char errstr
[MAXERROR
];
576 ns_ldap_error_t
*errorp
;
579 ParamIndexType i
= 0;
580 char *profile
, *container
, *base
;
582 ptr
= __s_api_get_default_config();
584 (void) snprintf(errstr
, sizeof (errstr
),
585 gettext("No configuration information available."));
586 MKERROR(LOG_ERR
, errorp
, NS_CONFIG_NOTLOADED
, strdup(errstr
),
591 if (filename
== NULL
) {
594 fp
= fopen(filename
, "wF");
596 (void) snprintf(errstr
, sizeof (errstr
),
597 gettext("Unable to open filename %s for ldif "
598 "dump (errno=%d)."), filename
, errno
);
599 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_FILE
,
600 strdup(errstr
), NULL
);
601 __s_api_release_config(ptr
);
604 (void) fchmod(fileno(fp
), 0444);
607 if (ptr
->paramList
[NS_LDAP_SEARCH_BASEDN_P
].ns_ptype
!= CHARPTR
||
608 ptr
->paramList
[NS_LDAP_PROFILE_P
].ns_ptype
!= CHARPTR
) {
609 (void) snprintf(errstr
, sizeof (errstr
),
610 gettext("Required BaseDN and/or Profile name "
611 "ldif fields not present"));
612 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_FILE
, strdup(errstr
),
614 __s_api_release_config(ptr
);
618 profile
= ptr
->paramList
[NS_LDAP_PROFILE_P
].ns_pc
;
619 base
= ptr
->paramList
[NS_LDAP_SEARCH_BASEDN_P
].ns_pc
;
620 container
= _PROFILE_CONTAINER
;
623 * Construct DN, but since this is the profile, there is no need
624 * to worry about mapping. The profile itself can not be mapped
626 (void) fprintf(fp
, "dn: cn=%s,ou=%s,%s\n", profile
, container
, base
);
628 /* dump objectclass names */
629 if (ptr
->version
== NS_LDAP_V1
) {
630 (void) fprintf(fp
, "ObjectClass: top\nObjectClass: %s\n",
631 _PROFILE1_OBJECTCLASS
);
633 (void) fprintf(fp
, "ObjectClass: top\nObjectClass: %s\n",
634 _PROFILE2_OBJECTCLASS
);
637 /* For each parameter - construct value */
638 for (i
= 0; i
<= NS_LDAP_MAX_PIT_P
; i
++) {
639 str
= __s_api_strValue(ptr
, i
, NS_LDIF_FMT
);
643 * don't dump binddn, bind password, admin binddn, admin
644 * bind password, enableShadowUpdate flag, or cert path
645 * as they are not part of version 2 profiles
647 if ((i
!= NS_LDAP_BINDDN_P
) &&
648 (i
!= NS_LDAP_BINDPASSWD_P
) &&
649 (i
!= NS_LDAP_ADMIN_BINDDN_P
) &&
650 (i
!= NS_LDAP_ADMIN_BINDPASSWD_P
) &&
651 (i
!= NS_LDAP_ENABLE_SHADOW_UPDATE_P
) &&
652 (i
!= NS_LDAP_HOST_CERTPATH_P
))
653 (void) fprintf(fp
, "%s\n", str
);
657 if (filename
!= NULL
)
660 __s_api_release_config(ptr
);
665 * This routine can process the configuration and/or
666 * the credential files at the same time.
667 * files is char *[3] = { "config", "cred", NULL };
672 __ns_ldap_DumpConfigFiles(char **files
)
679 char errstr
[MAXERROR
];
680 ParamIndexType i
= 0;
683 ns_ldap_error_t
*errorp
= NULL
;
686 boolean_t file_export_error
= B_FALSE
;
688 ptr
= __s_api_get_default_config();
690 (void) snprintf(errstr
, sizeof (errstr
),
691 gettext("No configuration information available."));
692 MKERROR(LOG_ERR
, errorp
, NS_CONFIG_NOTLOADED
, strdup(errstr
),
697 for (fi
= 0; fi
< 2; fi
++) {
699 filename
= files
[fi
];
700 if (filename
== NULL
)
704 rc
= stat(filename
, &buf
);
705 fp
= fopen(filename
, "wF");
707 (void) snprintf(errstr
, sizeof (errstr
),
708 gettext("Unable to open filename %s"
709 " for configuration dump (%s)."),
710 filename
, strerror(errno
));
711 MKERROR(LOG_ERR
, errorp
, NS_CONFIG_FILE
,
712 strdup(errstr
), NULL
);
713 __s_api_release_config(ptr
);
717 if (fchmod(fileno(fp
), buf
.st_mode
) != 0) {
718 (void) snprintf(errstr
, sizeof (errstr
),
719 gettext("Unable to set permissions for file"
720 " %s for configuration dump (%s)."),
721 filename
, strerror(errno
));
723 file_export_error
= B_TRUE
;
727 if (fchmod(fileno(fp
), 0400) != 0) {
728 (void) snprintf(errstr
, sizeof (errstr
),
729 gettext("Unable to set permissions for file"
730 " %s for configuration dump (%s)."),
731 filename
, strerror(errno
));
733 file_export_error
= B_TRUE
;
737 if (fprintf(fp
, "#\n# %s\n#\n", DONOTEDIT
) < 0) {
738 (void) snprintf(errstr
, sizeof (errstr
), gettext(
739 "Writing to file %s for configuration dump failed "
740 "(%s)."), filename
, strerror(errno
));
741 file_export_error
= B_TRUE
;
744 /* assume VERSION is set and it outputs first */
746 /* For each parameter - construct value */
747 for (i
= 0; !file_export_error
&& (i
<= NS_LDAP_MAX_PIT_P
);
749 cfgtype
= __s_api_get_configtype(i
);
750 if ((docred
== 0 && cfgtype
== CREDCONFIG
) ||
751 (docred
== 1 && cfgtype
!= CREDCONFIG
))
754 str
= __s_api_strValue(ptr
, i
, NS_FILE_FMT
);
757 if (fprintf(fp
, "%s\n", str
) < 0) {
758 (void) snprintf(errstr
, sizeof (errstr
),
759 gettext("Writing to file %s for"
760 "configuration dump failed (%s)."),
761 filename
, strerror(errno
));
762 file_export_error
= B_TRUE
;
767 if (fclose(fp
) != 0) {
768 /* Break if error already hit */
769 if (file_export_error
)
772 (void) snprintf(errstr
, sizeof (errstr
), gettext(
773 "Writing to file %s for configuration dump failed "
774 "during file close (%s)."), filename
,
776 file_export_error
= B_TRUE
;
782 if (file_export_error
) {
783 MKERROR(LOG_ERR
, errorp
, NS_CONFIG_FILE
,
784 strdup(errstr
), NULL
);
785 (void) unlink(filename
);
788 __s_api_release_config(ptr
);
793 __ns_ldap_DumpConfiguration(char *file
)
795 ns_ldap_error_t
*ret
;
801 if (strcmp(file
, NSCONFIGFILE
) == 0) {
803 } else if (strcmp(file
, NSCONFIGREFRESH
) == 0) {
805 } else if (strcmp(file
, NSCREDFILE
) == 0) {
807 } else if (strcmp(file
, NSCREDREFRESH
) == 0) {
810 ret
= __ns_ldap_DumpConfigFiles(files
);
815 * **************************************************************
817 * **************************************************************
821 __ns_ldap_make_config(ns_ldap_result_t
*result
)
826 ns_ldap_entry_t
*entry
;
827 ns_ldap_attr_t
*attr
;
829 ParamIndexType index
;
831 ns_ldap_error_t
*error
= NULL
;
833 ns_config_t
*curr_ptr
= NULL
;
834 char errstr
[MAXERROR
];
835 ns_ldap_error_t
*errorp
;
842 if (result
->entries_count
> 1) {
843 (void) snprintf(errstr
, MAXERROR
,
844 gettext("Configuration Error: More than one profile "
846 MKERROR(LOG_ERR
, errorp
, NS_PARSE_ERR
, strdup(errstr
), NULL
);
847 (void) __ns_ldap_freeError(&errorp
);
851 ptr
= __s_api_create_config();
855 curr_ptr
= __s_api_get_default_config();
856 if (curr_ptr
== NULL
) {
857 __s_api_destroy_config(ptr
);
861 /* Check to see if the profile is version 1 or version 2 */
863 entry
= result
->entry
;
864 for (l
= 0; l
< entry
->attr_count
; l
++) {
865 attr
= entry
->attr_pair
[l
];
867 attrname
= attr
->attrname
;
868 if (attrname
== NULL
)
870 if (strcasecmp(attrname
, "objectclass") == 0) {
871 for (m
= 0; m
< attr
->value_count
; m
++) {
872 if (strcasecmp(_PROFILE2_OBJECTCLASS
,
873 attr
->attrvalue
[m
]) == 0) {
880 /* update the configuration to accept v1 or v2 attributes */
882 (void) strcpy(val
, NS_LDAP_VERSION_1
);
883 (void) __ns_ldap_setParamValue(ptr
, NS_LDAP_FILE_VERSION_P
,
886 (void) strcpy(val
, NS_LDAP_VERSION_2
);
887 (void) __ns_ldap_setParamValue(ptr
, NS_LDAP_FILE_VERSION_P
,
891 for (l
= 0; l
< entry
->attr_count
; l
++) {
892 attr
= entry
->attr_pair
[l
];
894 attrname
= attr
->attrname
;
895 if (attrname
== NULL
)
897 if (__s_api_get_profiletype(attrname
, &index
) != 0)
900 attrval
= attr
->attrvalue
;
902 case NS_LDAP_SEARCH_DN_P
:
903 case NS_LDAP_SERVICE_SEARCH_DESC_P
:
904 case NS_LDAP_ATTRIBUTEMAP_P
:
905 case NS_LDAP_OBJECTCLASSMAP_P
:
906 case NS_LDAP_SERVICE_CRED_LEVEL_P
:
907 case NS_LDAP_SERVICE_AUTH_METHOD_P
:
908 /* Multiple Value - insert 1 at a time */
909 for (m
= 0; m
< attr
->value_count
; m
++) {
910 (void) __ns_ldap_setParamValue(ptr
, index
,
915 (void) memset((void *)&buffer
, 0, sizeof (LineBuf
));
917 /* Single or Multiple Value */
918 for (m
= 0; m
< attr
->value_count
; m
++) {
920 if (m
!= attr
->value_count
- 1) {
923 if (__print2buf(&buffer
, attrval
[m
], sepstr
))
924 goto makeconfigerror
;
926 (void) __ns_ldap_setParamValue(ptr
, index
, buffer
.str
,
928 if (buffer
.len
> 0) {
935 if (ptr
->version
!= NS_LDAP_V1
) {
937 if (curr_ptr
->paramList
[NS_LDAP_BINDDN_P
].ns_ptype
== CHARPTR
) {
938 (void) __ns_ldap_setParamValue(ptr
, NS_LDAP_BINDDN_P
,
939 curr_ptr
->paramList
[NS_LDAP_BINDDN_P
].ns_pc
,
942 if (curr_ptr
->paramList
[NS_LDAP_BINDPASSWD_P
].ns_ptype
==
944 (void) __ns_ldap_setParamValue(ptr
,
945 NS_LDAP_BINDPASSWD_P
,
946 curr_ptr
->paramList
[NS_LDAP_BINDPASSWD_P
].ns_pc
,
949 i
= NS_LDAP_ENABLE_SHADOW_UPDATE_P
;
950 if (curr_ptr
->paramList
[i
].ns_ptype
== INT
) {
952 valt
= __s_get_shadowupdate_name(
953 curr_ptr
->paramList
[i
].ns_i
);
954 (void) __ns_ldap_setParamValue(ptr
, i
, valt
, &error
);
956 if (curr_ptr
->paramList
[NS_LDAP_ADMIN_BINDDN_P
].ns_ptype
==
958 (void) __ns_ldap_setParamValue(ptr
,
959 NS_LDAP_ADMIN_BINDDN_P
,
960 curr_ptr
->paramList
[NS_LDAP_ADMIN_BINDDN_P
].ns_pc
,
963 if (curr_ptr
->paramList
[NS_LDAP_ADMIN_BINDPASSWD_P
].ns_ptype
==
965 (void) __ns_ldap_setParamValue(ptr
,
966 NS_LDAP_ADMIN_BINDPASSWD_P
,
968 paramList
[NS_LDAP_ADMIN_BINDPASSWD_P
].ns_pc
,
971 if (curr_ptr
->paramList
[NS_LDAP_HOST_CERTPATH_P
].ns_ptype
==
973 (void) __ns_ldap_setParamValue(ptr
,
974 NS_LDAP_HOST_CERTPATH_P
,
975 curr_ptr
->paramList
[NS_LDAP_HOST_CERTPATH_P
].ns_pc
,
979 __s_api_release_config(curr_ptr
);
986 __s_api_debug_pause(LOG_ERR
, NS_PARSE_ERR
,
987 "__ns_ldap_make_config: Not enough memory");
992 * Download a profile into our internal structure. The calling application
993 * needs to DumpConfig() to save the information to NSCONFIGFILE and NSCREDFILE
997 __ns_ldap_download(const char *profile
, char *addr
, char *baseDN
,
998 ns_ldap_error_t
**errorp
)
1000 char filter
[BUFSIZE
];
1002 ns_ldap_result_t
*result
= NULL
;
1003 ns_config_t
*ptr
= NULL
;
1004 ns_config_t
*new_ptr
= NULL
;
1005 char errstr
[MAXERROR
];
1009 return (NS_LDAP_INVALID_PARAM
);
1011 ptr
= __s_api_get_default_config();
1013 (void) snprintf(errstr
, sizeof (errstr
),
1014 gettext("No configuration information available."));
1015 MKERROR(LOG_ERR
, *errorp
, NS_CONFIG_NOTLOADED
, strdup(errstr
),
1017 return (NS_LDAP_CONFIG
);
1020 rc
= __ns_ldap_setParamValue(ptr
, NS_LDAP_SEARCH_BASEDN_P
, baseDN
,
1022 if (rc
!= NS_LDAP_SUCCESS
) {
1023 __s_api_release_config(ptr
);
1027 rc
= __ns_ldap_setParamValue(ptr
, NS_LDAP_SERVERS_P
, addr
, errorp
);
1028 __s_api_release_config(ptr
);
1029 if (rc
!= NS_LDAP_SUCCESS
)
1032 (void) snprintf(filter
, sizeof (filter
), _PROFILE_FILTER
,
1033 _PROFILE1_OBJECTCLASS
, _PROFILE2_OBJECTCLASS
, profile
);
1034 rc
= __ns_ldap_list(_PROFILE_CONTAINER
, (const char *)filter
,
1035 NULL
, NULL
, NULL
, 0, &result
, errorp
, NULL
, NULL
);
1037 if (rc
!= NS_LDAP_SUCCESS
)
1040 new_ptr
= __ns_ldap_make_config(result
);
1041 (void) __ns_ldap_freeResult(&result
);
1043 if (new_ptr
== NULL
)
1044 return (NS_LDAP_OP_FAILED
);
1046 rc
= __s_api_crosscheck(new_ptr
, errstr
, B_FALSE
);
1047 if (rc
!= NS_LDAP_SUCCESS
) {
1048 __s_api_destroy_config(new_ptr
);
1049 MKERROR(LOG_ERR
, *errorp
, NS_CONFIG_NOTLOADED
, strdup(errstr
),
1051 return (NS_LDAP_CONFIG
);
1054 __s_api_init_config(new_ptr
);
1059 * **************************************************************
1060 * Configuration Printing Routines
1061 * **************************************************************
1065 * Yes the use of stdio is okay here because all we are doing is sending
1066 * output to stdout. This would not be necessary if we could get to the
1067 * configuration pointer outside this file.
1070 __ns_ldap_print_config(int verbose
)
1073 char errstr
[MAXERROR
];
1074 ns_ldap_error_t
*errorp
;
1078 ptr
= __s_api_get_default_config();
1080 errorp
= __ns_ldap_LoadConfiguration();
1083 ptr
= __s_api_get_default_config();
1085 (void) snprintf(errstr
, sizeof (errstr
),
1086 gettext("No configuration information."));
1087 MKERROR(LOG_WARNING
, errorp
, NS_CONFIG_NOTLOADED
,
1088 strdup(errstr
), NULL
);
1093 if (verbose
&& (ptr
->domainName
!= NULL
)) {
1094 (void) fputs("ptr->domainName ", stdout
);
1095 (void) fputs(ptr
->domainName
, stdout
);
1096 (void) putchar('\n');
1098 /* For each parameter - construct value */
1099 for (i
= 0; i
<= NS_LDAP_MAX_PIT_P
; i
++) {
1101 * Version 1 skipped this entry because:
1103 * don't print default cache TTL for now since
1104 * we don't store it in the ldap_client_file.
1106 if ((i
== NS_LDAP_CACHETTL_P
) && (ptr
->version
== NS_LDAP_V1
))
1109 /* the credential for shadow update is not to be exposed */
1110 if (i
== NS_LDAP_ADMIN_BINDDN_P
||
1111 i
== NS_LDAP_ADMIN_BINDPASSWD_P
)
1114 str
= __s_api_strValue(ptr
, i
, NS_FILE_FMT
);
1118 (void) putchar('\t');
1119 (void) fprintf(stdout
, "%s\n", str
);
1123 __s_api_release_config(ptr
);