Print this page
5910 libnisdb won't build with modern GCC


   2  * CDDL HEADER START
   3  *
   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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #include <sys/types.h>
  27 #include <time.h>
  28 #include <sys/time.h>
  29 #include <lber.h>
  30 #include <ldap.h>
  31 #include <signal.h>
  32 #include <pthread.h>
  33 #include "db_headers.h"
  34 #include "db.h"
  35 #include "db_mindex.h"
  36 #include "db_dictionary.h"
  37 #include "nisdb_mt.h"
  38 #include "ldap_map.h"
  39 #include "ldap_glob.h"
  40 #include "ldap_util.h"
  41 
  42 
  43 extern db_dictionary    *InUseDictionary;


 197                 table->mapping.enumDeferred = 0;
 198         }
 199 
 200         /* If enumerating, perform the operation in a separate thread */
 201         if (doAsynch && qin == 0) {
 202                 pthread_t       tid;
 203                 pthread_attr_t  attr;
 204 
 205                 (void) pthread_attr_init(&attr);
 206 #ifdef  FORCE_SYNCHRONOUS
 207 #else
 208                 (void) pthread_attr_setdetachstate(&attr,
 209                                                 PTHREAD_CREATE_DETACHED);
 210 #endif  /* FORCE_SYNCHRONOUS */
 211                 stat = pthread_create(&tid, &attr, entriesFromLDAPthread, arg);
 212                 if (stat != 0) {
 213                         (void) mutex_unlock(&table->mapping.enumLock);
 214                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 215                         "%s: Error %d creating new thread; using current one",
 216                                 myself, stat);
 217                         stat = (int)entriesFromLDAPthread(arg);
 218                         return (stat);
 219                 }
 220 
 221                 table->mapping.enumTid = tid;
 222                 table->mapping.enumStat = -1;
 223 
 224                 /*
 225                  * We're now returning to the caller, who will get data
 226                  * from:
 227                  *
 228                  *      The deferred DB, if an enumeration thread already
 229                  *      was running, and deferred mode was on, or
 230                  *
 231                  *      The original DB, if we just started an enumeration
 232                  *      thread. In this case, our caller (several levels up)
 233                  *      is holding a lock on the db_mindex/db_table, which
 234                  *      means that the enum thread will have to wait for
 235                  *      our caller once it's done the LDAP retrieval, and
 236                  *      wants to update the DB.
 237                  */


 240 #ifdef  FORCE_SYNCHRONOUS
 241                 {
 242                         int     tstat;
 243 
 244                         stat = pthread_join(tid, (void **)&tstat);
 245                         if (stat == 0) {
 246                                 stat = tstat;
 247                                 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 248                                         "%s: thread %d => %d",
 249                                         myself, tid, tstat);
 250                         } else {
 251                                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
 252                                         "%s: pthread_join(%d) => %d",
 253                                         myself, tid, stat);
 254                                 stat = LDAP_OPERATIONS_ERROR;
 255                         }
 256                 }
 257 #endif  /* FORCE_SYNCHRONOUS */
 258         } else {
 259                 (void) mutex_unlock(&table->mapping.enumLock);
 260                 stat = (int)entriesFromLDAPthread(arg);
 261         }
 262 
 263         return (stat);
 264 }
 265 
 266 extern "C" {
 267 
 268 /*
 269  * We use this 'extern "C"' function in order to make sure that
 270  * pthread_create() doesn't have any problems trying to invoke a
 271  * C++ function.
 272  */
 273 static void *
 274 entriesFromLDAPthread(void *voidarg) {
 275         __entries_from_ldap_arg_t       *arg;
 276         int                             stat;
 277         db                              *dbase;
 278         db_table_desc                   *tbl = 0;
 279         char                            *tableName;
 280 
 281         arg = (__entries_from_ldap_arg_t *)voidarg;
 282 
 283         /* Lock to prevent removal */
 284         (void) __nis_lock_db_table(arg->tableName, 1, 0,
 285                                         "entriesFromLDAPthread");
 286 
 287         /*
 288          * It's possible that the db_mindex for the table has changed,
 289          * or disappeared, between now and the time when our parent
 290          * thread released its lock on the table. Hence, we search the
 291          * dictionary to re-acquire the 'db', and the db_mindex.
 292          */
 293         tableName = internalTableName(arg->tableName);
 294         if (tableName != 0) {
 295 #ifdef  NISDB_LDAP_DEBUG
 296                 db_mindex       *oldMindex = arg->mindex;
 297 #endif  /* NISDB_LDAP_DEBUG */
 298 
 299                 dbase = InUseDictionary->find_table(tableName, &tbl, FALSE);
 300                 if (dbase != 0)
 301                         arg->mindex = dbase->mindex();
 302                 else
 303                         arg->mindex = 0;
 304 #ifdef  NISDB_LDAP_DEBUG
 305                 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 306                         "entriesFromLDAPthread: %s -> %s -> 0x%x (0x%x)",
 307                         NIL(arg->tableName), NIL(tableName),
 308                         arg->mindex, oldMindex);
 309 #endif  /* NISDB_LDAP_DEBUG */
 310                 sfree(tableName);
 311                 tableName = 0;
 312         }
 313 
 314         stat = entriesFromLDAPreal(arg);
 315 
 316         (void) __nis_ulock_db_table(arg->tableName, 1, 0,
 317                                         "entriesFromLDAPthread");
 318 
 319         freeQuery(arg->q);
 320         if (arg->dirObj != 0)
 321                 nis_destroy_object(arg->dirObj);
 322         sfree(arg);
 323         return ((void *)stat);
 324 }
 325 
 326 }
 327 
 328 int
 329 entriesFromLDAPreal(__entries_from_ldap_arg_t *arg) {
 330         db_mindex                       *mindex;
 331         db_table                        *table;
 332         __nis_table_mapping_t           *t;
 333         db_query                        *q, *qin;
 334         char                            *dbId;
 335         nis_object                      *dirObj;
 336         int                             i, na, nau, nq = 0, xid = 0;
 337         int                             ret, stat = LDAP_SUCCESS, stat2, stat3;
 338         int                             lstat;
 339         __nis_obj_attr_t                **oa = 0;
 340         db_query                        **res;
 341         entry_object                    **ea;
 342         long                            numEa;
 343         bool_t                          doEnum;




   2  * CDDL HEADER START
   3  *
   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  * Copyright 2015 Gary Mills
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Copyright 2015 RackTop Systems.
  27  */
  28 
  29 #include <sys/types.h>
  30 #include <time.h>
  31 #include <sys/time.h>
  32 #include <lber.h>
  33 #include <ldap.h>
  34 #include <signal.h>
  35 #include <pthread.h>
  36 #include "db_headers.h"
  37 #include "db.h"
  38 #include "db_mindex.h"
  39 #include "db_dictionary.h"
  40 #include "nisdb_mt.h"
  41 #include "ldap_map.h"
  42 #include "ldap_glob.h"
  43 #include "ldap_util.h"
  44 
  45 
  46 extern db_dictionary    *InUseDictionary;


 200                 table->mapping.enumDeferred = 0;
 201         }
 202 
 203         /* If enumerating, perform the operation in a separate thread */
 204         if (doAsynch && qin == 0) {
 205                 pthread_t       tid;
 206                 pthread_attr_t  attr;
 207 
 208                 (void) pthread_attr_init(&attr);
 209 #ifdef  FORCE_SYNCHRONOUS
 210 #else
 211                 (void) pthread_attr_setdetachstate(&attr,
 212                                                 PTHREAD_CREATE_DETACHED);
 213 #endif  /* FORCE_SYNCHRONOUS */
 214                 stat = pthread_create(&tid, &attr, entriesFromLDAPthread, arg);
 215                 if (stat != 0) {
 216                         (void) mutex_unlock(&table->mapping.enumLock);
 217                         logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 218                         "%s: Error %d creating new thread; using current one",
 219                                 myself, stat);
 220                         stat = entriesFromLDAPreal(arg);
 221                         return (stat);
 222                 }
 223 
 224                 table->mapping.enumTid = tid;
 225                 table->mapping.enumStat = -1;
 226 
 227                 /*
 228                  * We're now returning to the caller, who will get data
 229                  * from:
 230                  *
 231                  *      The deferred DB, if an enumeration thread already
 232                  *      was running, and deferred mode was on, or
 233                  *
 234                  *      The original DB, if we just started an enumeration
 235                  *      thread. In this case, our caller (several levels up)
 236                  *      is holding a lock on the db_mindex/db_table, which
 237                  *      means that the enum thread will have to wait for
 238                  *      our caller once it's done the LDAP retrieval, and
 239                  *      wants to update the DB.
 240                  */


 243 #ifdef  FORCE_SYNCHRONOUS
 244                 {
 245                         int     tstat;
 246 
 247                         stat = pthread_join(tid, (void **)&tstat);
 248                         if (stat == 0) {
 249                                 stat = tstat;
 250                                 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 251                                         "%s: thread %d => %d",
 252                                         myself, tid, tstat);
 253                         } else {
 254                                 logmsg(MSG_NOTIMECHECK, LOG_ERR,
 255                                         "%s: pthread_join(%d) => %d",
 256                                         myself, tid, stat);
 257                                 stat = LDAP_OPERATIONS_ERROR;
 258                         }
 259                 }
 260 #endif  /* FORCE_SYNCHRONOUS */
 261         } else {
 262                 (void) mutex_unlock(&table->mapping.enumLock);
 263                 stat = entriesFromLDAPreal(arg);
 264         }
 265 
 266         return (stat);
 267 }
 268 
 269 extern "C" {
 270 
 271 /*
 272  * We use this 'extern "C"' function in order to make sure that
 273  * pthread_create() doesn't have any problems trying to invoke a
 274  * C++ function.
 275  */
 276 static void *
 277 entriesFromLDAPthread(void *voidarg) {
 278         __entries_from_ldap_arg_t       *arg;

 279         db                              *dbase;
 280         db_table_desc                   *tbl = 0;
 281         char                            *tableName;
 282 
 283         arg = (__entries_from_ldap_arg_t *)voidarg;
 284 
 285         /* Lock to prevent removal */
 286         (void) __nis_lock_db_table(arg->tableName, 1, 0,
 287                                         "entriesFromLDAPthread");
 288 
 289         /*
 290          * It's possible that the db_mindex for the table has changed,
 291          * or disappeared, between now and the time when our parent
 292          * thread released its lock on the table. Hence, we search the
 293          * dictionary to re-acquire the 'db', and the db_mindex.
 294          */
 295         tableName = internalTableName(arg->tableName);
 296         if (tableName != 0) {
 297 #ifdef  NISDB_LDAP_DEBUG
 298                 db_mindex       *oldMindex = arg->mindex;
 299 #endif  /* NISDB_LDAP_DEBUG */
 300 
 301                 dbase = InUseDictionary->find_table(tableName, &tbl, FALSE);
 302                 if (dbase != 0)
 303                         arg->mindex = dbase->mindex();
 304                 else
 305                         arg->mindex = 0;
 306 #ifdef  NISDB_LDAP_DEBUG
 307                 logmsg(MSG_NOTIMECHECK, LOG_WARNING,
 308                         "entriesFromLDAPthread: %s -> %s -> 0x%x (0x%x)",
 309                         NIL(arg->tableName), NIL(tableName),
 310                         arg->mindex, oldMindex);
 311 #endif  /* NISDB_LDAP_DEBUG */
 312                 sfree(tableName);
 313                 tableName = 0;
 314         }
 315 
 316         (void) entriesFromLDAPreal(arg);
 317 
 318         (void) __nis_ulock_db_table(arg->tableName, 1, 0,
 319                                         "entriesFromLDAPthread");
 320 
 321         freeQuery(arg->q);
 322         if (arg->dirObj != 0)
 323                 nis_destroy_object(arg->dirObj);
 324         sfree(arg);
 325         return (NULL);
 326 }
 327 
 328 }
 329 
 330 int
 331 entriesFromLDAPreal(__entries_from_ldap_arg_t *arg) {
 332         db_mindex                       *mindex;
 333         db_table                        *table;
 334         __nis_table_mapping_t           *t;
 335         db_query                        *q, *qin;
 336         char                            *dbId;
 337         nis_object                      *dirObj;
 338         int                             i, na, nau, nq = 0, xid = 0;
 339         int                             ret, stat = LDAP_SUCCESS, stat2, stat3;
 340         int                             lstat;
 341         __nis_obj_attr_t                **oa = 0;
 342         db_query                        **res;
 343         entry_object                    **ea;
 344         long                            numEa;
 345         bool_t                          doEnum;