Print this page
3285 memory leaks in libsldap


   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.

  24  */
  25 
  26 #include <stdlib.h>
  27 #include <stdio.h>
  28 #include <errno.h>
  29 #include <string.h>
  30 #include <synch.h>
  31 #include <time.h>
  32 #include <libintl.h>
  33 #include <thread.h>
  34 #include <syslog.h>
  35 #include <sys/mman.h>
  36 #include <nsswitch.h>
  37 #include <nss_dbdefs.h>
  38 #include "solaris-priv.h"
  39 #include "solaris-int.h"
  40 #include "ns_sldap.h"
  41 #include "ns_internal.h"
  42 #include "ns_cache_door.h"
  43 #include "ns_connmgmt.h"


 458         *error = NULL;
 459 
 460         return (NS_LDAP_SUCCESS);
 461 }
 462 
 463 
 464 #ifdef DEBUG
 465 /*
 466  * printCred(): prints the credential structure
 467  */
 468 static void
 469 printCred(FILE *fp, const ns_cred_t *cred)
 470 {
 471         thread_t        t = thr_self();
 472 
 473         if (cred == NULL) {
 474                 (void) fprintf(fp, "tid= %d: printCred: cred is NULL\n", t);
 475                 return;
 476         }
 477 
 478         (void) fprintf(fp, "tid= %d: AuthType=%d", t, cred->auth.type);
 479         (void) fprintf(fp, "tid= %d: TlsType=%d", t, cred->auth.tlstype);
 480         (void) fprintf(fp, "tid= %d: SaslMech=%d", t, cred->auth.saslmech);
 481         (void) fprintf(fp, "tid= %d: SaslOpt=%d", t, cred->auth.saslopt);
 482         if (cred->hostcertpath)
 483                 (void) fprintf(fp, "tid= %d: hostCertPath=%s\n",
 484                     t, cred->hostcertpath);
 485         if (cred->cred.unix_cred.userID)
 486                 (void) fprintf(fp, "tid= %d: userID=%s\n",
 487                     t, cred->cred.unix_cred.userID);
 488         if (cred->cred.unix_cred.passwd)
 489                 (void) fprintf(fp, "tid= %d: passwd=%s\n",
 490                     t, cred->cred.unix_cred.passwd);
 491 }
 492 
 493 /*
 494  * printConnection(): prints the connection structure
 495  */
 496 static void
 497 printConnection(FILE *fp, Connection *con)
 498 {
 499         thread_t        t = thr_self();
 500 
 501         if (con == NULL)


 684         const ns_cred_t *auth, ConnectionID *cID, int timeoutSec,
 685         ns_ldap_error_t **errorp, int fail_if_new_pwd_reqd,
 686         int nopasswd_acct_mgmt, int flags, char ***badsrvrs,
 687         ns_conn_user_t *conn_user)
 688 {
 689         Connection *con = NULL;
 690         ConnectionID id;
 691         char errmsg[MAXERROR];
 692         int rc, exit_rc = NS_LDAP_SUCCESS;
 693         ns_server_info_t sinfo;
 694         char *hReq, *host = NULL;
 695         LDAP *ld = NULL;
 696         int passwd_mgmt = 0;
 697         int totalbad = 0; /* Number of servers contacted unsuccessfully */
 698         short   memerr = 0; /* Variable for tracking memory allocation */
 699         char *serverAddrType = NULL, **bindHost = NULL;
 700 
 701 
 702         if (conp == NULL || errorp == NULL || auth == NULL)
 703                 return (NS_LDAP_INVALID_PARAM);
 704         *errorp = NULL;

 705         *conp = NULL;
 706         (void) memset(&sinfo, 0, sizeof (sinfo));
 707 
 708         if ((id = findConnection(flags, serverAddr, auth, &con)) != -1) {
 709                 /* connection found in cache */
 710 #ifdef DEBUG
 711                 (void) fprintf(stderr, "tid= %d: connection found in "
 712                     "cache %d\n", thr_self(), id);
 713                 fflush(stderr);
 714 #endif /* DEBUG */
 715                 *cID = id;
 716                 *conp = con;
 717                 return (NS_LDAP_SUCCESS);
 718         }
 719 
 720         if (auth->auth.saslmech == NS_LDAP_SASL_GSSAPI) {
 721                 serverAddrType = NS_CACHE_ADDR_HOSTNAME;
 722                 bindHost = &sinfo.serverFQDN;
 723         } else {
 724                 serverAddrType = NS_CACHE_ADDR_IP;




   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  25  */
  26 
  27 #include <stdlib.h>
  28 #include <stdio.h>
  29 #include <errno.h>
  30 #include <string.h>
  31 #include <synch.h>
  32 #include <time.h>
  33 #include <libintl.h>
  34 #include <thread.h>
  35 #include <syslog.h>
  36 #include <sys/mman.h>
  37 #include <nsswitch.h>
  38 #include <nss_dbdefs.h>
  39 #include "solaris-priv.h"
  40 #include "solaris-int.h"
  41 #include "ns_sldap.h"
  42 #include "ns_internal.h"
  43 #include "ns_cache_door.h"
  44 #include "ns_connmgmt.h"


 459         *error = NULL;
 460 
 461         return (NS_LDAP_SUCCESS);
 462 }
 463 
 464 
 465 #ifdef DEBUG
 466 /*
 467  * printCred(): prints the credential structure
 468  */
 469 static void
 470 printCred(FILE *fp, const ns_cred_t *cred)
 471 {
 472         thread_t        t = thr_self();
 473 
 474         if (cred == NULL) {
 475                 (void) fprintf(fp, "tid= %d: printCred: cred is NULL\n", t);
 476                 return;
 477         }
 478 
 479         (void) fprintf(fp, "tid= %d: AuthType=%d\n", t, cred->auth.type);
 480         (void) fprintf(fp, "tid= %d: TlsType=%d\n", t, cred->auth.tlstype);
 481         (void) fprintf(fp, "tid= %d: SaslMech=%d\n", t, cred->auth.saslmech);
 482         (void) fprintf(fp, "tid= %d: SaslOpt=%d\n", t, cred->auth.saslopt);
 483         if (cred->hostcertpath)
 484                 (void) fprintf(fp, "tid= %d: hostCertPath=%s\n",
 485                     t, cred->hostcertpath);
 486         if (cred->cred.unix_cred.userID)
 487                 (void) fprintf(fp, "tid= %d: userID=%s\n",
 488                     t, cred->cred.unix_cred.userID);
 489         if (cred->cred.unix_cred.passwd)
 490                 (void) fprintf(fp, "tid= %d: passwd=%s\n",
 491                     t, cred->cred.unix_cred.passwd);
 492 }
 493 
 494 /*
 495  * printConnection(): prints the connection structure
 496  */
 497 static void
 498 printConnection(FILE *fp, Connection *con)
 499 {
 500         thread_t        t = thr_self();
 501 
 502         if (con == NULL)


 685         const ns_cred_t *auth, ConnectionID *cID, int timeoutSec,
 686         ns_ldap_error_t **errorp, int fail_if_new_pwd_reqd,
 687         int nopasswd_acct_mgmt, int flags, char ***badsrvrs,
 688         ns_conn_user_t *conn_user)
 689 {
 690         Connection *con = NULL;
 691         ConnectionID id;
 692         char errmsg[MAXERROR];
 693         int rc, exit_rc = NS_LDAP_SUCCESS;
 694         ns_server_info_t sinfo;
 695         char *hReq, *host = NULL;
 696         LDAP *ld = NULL;
 697         int passwd_mgmt = 0;
 698         int totalbad = 0; /* Number of servers contacted unsuccessfully */
 699         short   memerr = 0; /* Variable for tracking memory allocation */
 700         char *serverAddrType = NULL, **bindHost = NULL;
 701 
 702 
 703         if (conp == NULL || errorp == NULL || auth == NULL)
 704                 return (NS_LDAP_INVALID_PARAM);
 705         if (*errorp)
 706                 __ns_ldap_freeError(errorp);
 707         *conp = NULL;
 708         (void) memset(&sinfo, 0, sizeof (sinfo));
 709 
 710         if ((id = findConnection(flags, serverAddr, auth, &con)) != -1) {
 711                 /* connection found in cache */
 712 #ifdef DEBUG
 713                 (void) fprintf(stderr, "tid= %d: connection found in "
 714                     "cache %d\n", thr_self(), id);
 715                 fflush(stderr);
 716 #endif /* DEBUG */
 717                 *cID = id;
 718                 *conp = con;
 719                 return (NS_LDAP_SUCCESS);
 720         }
 721 
 722         if (auth->auth.saslmech == NS_LDAP_SASL_GSSAPI) {
 723                 serverAddrType = NS_CACHE_ADDR_HOSTNAME;
 724                 bindHost = &sinfo.serverFQDN;
 725         } else {
 726                 serverAddrType = NS_CACHE_ADDR_IP;