17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*ebe05b7fSRitwik Ghoshal * Common Development and Distribution License (the "License").
6*ebe05b7fSRitwik Ghoshal * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*ebe05b7fSRitwik Ghoshal * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #include <stdlib.h>
277c478bd9Sstevel@tonic-gate #include <libintl.h>
287c478bd9Sstevel@tonic-gate #include "ns_sldap.h"
297c478bd9Sstevel@tonic-gate #include "ns_internal.h"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate struct ns_ldaperror {
327c478bd9Sstevel@tonic-gate int e_code;
337c478bd9Sstevel@tonic-gate char *e_reason;
347c478bd9Sstevel@tonic-gate };
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate static mutex_t ns_error_lock = DEFAULTMUTEX;
377c478bd9Sstevel@tonic-gate static boolean_t error_inited = B_FALSE;
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate static struct ns_ldaperror ns_ldap_errlist[] = {
407c478bd9Sstevel@tonic-gate {NS_LDAP_SUCCESS, NULL},
417c478bd9Sstevel@tonic-gate {NS_LDAP_OP_FAILED, NULL},
427c478bd9Sstevel@tonic-gate {NS_LDAP_NOTFOUND, NULL},
437c478bd9Sstevel@tonic-gate {NS_LDAP_MEMORY, NULL},
447c478bd9Sstevel@tonic-gate {NS_LDAP_CONFIG, NULL},
457c478bd9Sstevel@tonic-gate {NS_LDAP_PARTIAL, NULL},
467c478bd9Sstevel@tonic-gate {NS_LDAP_INTERNAL, NULL},
477c478bd9Sstevel@tonic-gate {NS_LDAP_INVALID_PARAM, NULL},
487c478bd9Sstevel@tonic-gate {-1, NULL}
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate static void
ns_ldaperror_init()537c478bd9Sstevel@tonic-gate ns_ldaperror_init()
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate int i = 0;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate (void) mutex_lock(&ns_error_lock);
587c478bd9Sstevel@tonic-gate if (!error_inited) {
597c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Success");
607c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Operation failed");
617c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Object not found");
627c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Memory failure");
637c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason =
647c478bd9Sstevel@tonic-gate gettext("LDAP configuration problem");
657c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Partial result");
667c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("LDAP error");
677c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Invalid parameter");
687c478bd9Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Unknown error");
697c478bd9Sstevel@tonic-gate error_inited = B_TRUE;
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ns_error_lock);
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate int
__ns_ldap_err2str(int err,char ** strmsg)767c478bd9Sstevel@tonic-gate __ns_ldap_err2str(int err, char **strmsg)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate int i;
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate if (!error_inited)
817c478bd9Sstevel@tonic-gate ns_ldaperror_init();
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate for (i = 0; (ns_ldap_errlist[i].e_code != err) &&
847c478bd9Sstevel@tonic-gate (ns_ldap_errlist[i].e_code != -1); i++) {
857c478bd9Sstevel@tonic-gate /* empty for loop */
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate *strmsg = ns_ldap_errlist[i].e_reason;
887c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate int
__ns_ldap_freeError(ns_ldap_error_t ** errorp)937c478bd9Sstevel@tonic-gate __ns_ldap_freeError(ns_ldap_error_t **errorp)
947c478bd9Sstevel@tonic-gate {
95*ebe05b7fSRitwik Ghoshal ns_ldap_error_t *err;
96*ebe05b7fSRitwik Ghoshal
97*ebe05b7fSRitwik Ghoshal if (errorp == NULL || *errorp == NULL)
98*ebe05b7fSRitwik Ghoshal return (NS_LDAP_SUCCESS);
99*ebe05b7fSRitwik Ghoshal
100*ebe05b7fSRitwik Ghoshal err = *errorp;
1017c478bd9Sstevel@tonic-gate if (err->message)
1027c478bd9Sstevel@tonic-gate free(err->message);
103*ebe05b7fSRitwik Ghoshal
1047c478bd9Sstevel@tonic-gate free(err);
1057c478bd9Sstevel@tonic-gate *errorp = NULL;
1067c478bd9Sstevel@tonic-gate return (NS_LDAP_SUCCESS);
1077c478bd9Sstevel@tonic-gate }
108