10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*12783SRitwik.Ghoshal@Sun.COM * Common Development and Distribution License (the "License").
6*12783SRitwik.Ghoshal@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12783SRitwik.Ghoshal@Sun.COM * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <stdlib.h>
270Sstevel@tonic-gate #include <libintl.h>
280Sstevel@tonic-gate #include "ns_sldap.h"
290Sstevel@tonic-gate #include "ns_internal.h"
300Sstevel@tonic-gate
310Sstevel@tonic-gate struct ns_ldaperror {
320Sstevel@tonic-gate int e_code;
330Sstevel@tonic-gate char *e_reason;
340Sstevel@tonic-gate };
350Sstevel@tonic-gate
360Sstevel@tonic-gate static mutex_t ns_error_lock = DEFAULTMUTEX;
370Sstevel@tonic-gate static boolean_t error_inited = B_FALSE;
380Sstevel@tonic-gate
390Sstevel@tonic-gate static struct ns_ldaperror ns_ldap_errlist[] = {
400Sstevel@tonic-gate {NS_LDAP_SUCCESS, NULL},
410Sstevel@tonic-gate {NS_LDAP_OP_FAILED, NULL},
420Sstevel@tonic-gate {NS_LDAP_NOTFOUND, NULL},
430Sstevel@tonic-gate {NS_LDAP_MEMORY, NULL},
440Sstevel@tonic-gate {NS_LDAP_CONFIG, NULL},
450Sstevel@tonic-gate {NS_LDAP_PARTIAL, NULL},
460Sstevel@tonic-gate {NS_LDAP_INTERNAL, NULL},
470Sstevel@tonic-gate {NS_LDAP_INVALID_PARAM, NULL},
480Sstevel@tonic-gate {-1, NULL}
490Sstevel@tonic-gate };
500Sstevel@tonic-gate
510Sstevel@tonic-gate
520Sstevel@tonic-gate static void
ns_ldaperror_init()530Sstevel@tonic-gate ns_ldaperror_init()
540Sstevel@tonic-gate {
550Sstevel@tonic-gate int i = 0;
560Sstevel@tonic-gate
570Sstevel@tonic-gate (void) mutex_lock(&ns_error_lock);
580Sstevel@tonic-gate if (!error_inited) {
590Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Success");
600Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Operation failed");
610Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Object not found");
620Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Memory failure");
630Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason =
64*12783SRitwik.Ghoshal@Sun.COM gettext("LDAP configuration problem");
650Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Partial result");
660Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("LDAP error");
670Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Invalid parameter");
680Sstevel@tonic-gate ns_ldap_errlist[i++].e_reason = gettext("Unknown error");
690Sstevel@tonic-gate error_inited = B_TRUE;
700Sstevel@tonic-gate }
710Sstevel@tonic-gate (void) mutex_unlock(&ns_error_lock);
720Sstevel@tonic-gate }
730Sstevel@tonic-gate
740Sstevel@tonic-gate
750Sstevel@tonic-gate int
__ns_ldap_err2str(int err,char ** strmsg)760Sstevel@tonic-gate __ns_ldap_err2str(int err, char **strmsg)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate int i;
790Sstevel@tonic-gate
800Sstevel@tonic-gate if (!error_inited)
810Sstevel@tonic-gate ns_ldaperror_init();
820Sstevel@tonic-gate
830Sstevel@tonic-gate for (i = 0; (ns_ldap_errlist[i].e_code != err) &&
84*12783SRitwik.Ghoshal@Sun.COM (ns_ldap_errlist[i].e_code != -1); i++) {
850Sstevel@tonic-gate /* empty for loop */
860Sstevel@tonic-gate }
870Sstevel@tonic-gate *strmsg = ns_ldap_errlist[i].e_reason;
880Sstevel@tonic-gate return (NS_LDAP_SUCCESS);
890Sstevel@tonic-gate }
900Sstevel@tonic-gate
910Sstevel@tonic-gate
920Sstevel@tonic-gate int
__ns_ldap_freeError(ns_ldap_error_t ** errorp)930Sstevel@tonic-gate __ns_ldap_freeError(ns_ldap_error_t **errorp)
940Sstevel@tonic-gate {
95*12783SRitwik.Ghoshal@Sun.COM ns_ldap_error_t *err;
96*12783SRitwik.Ghoshal@Sun.COM
97*12783SRitwik.Ghoshal@Sun.COM if (errorp == NULL || *errorp == NULL)
98*12783SRitwik.Ghoshal@Sun.COM return (NS_LDAP_SUCCESS);
99*12783SRitwik.Ghoshal@Sun.COM
100*12783SRitwik.Ghoshal@Sun.COM err = *errorp;
101*12783SRitwik.Ghoshal@Sun.COM if (err->message)
102*12783SRitwik.Ghoshal@Sun.COM free(err->message);
103*12783SRitwik.Ghoshal@Sun.COM
104*12783SRitwik.Ghoshal@Sun.COM free(err);
1050Sstevel@tonic-gate *errorp = NULL;
1060Sstevel@tonic-gate return (NS_LDAP_SUCCESS);
1070Sstevel@tonic-gate }
108