nsdispatch.c (127012) | nsdispatch.c (127625) |
---|---|
1/* $NetBSD: nsdispatch.c,v 1.9 1999/01/25 00:16:17 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. --- 54 unchanged lines hidden (view full) --- 63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * SUCH DAMAGE. 68 * 69 */ 70#include <sys/cdefs.h> | 1/* $NetBSD: nsdispatch.c,v 1.9 1999/01/25 00:16:17 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. --- 54 unchanged lines hidden (view full) --- 63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * SUCH DAMAGE. 68 * 69 */ 70#include <sys/cdefs.h> |
71__FBSDID("$FreeBSD: head/lib/libc/net/nsdispatch.c 127012 2004-03-15 08:14:35Z des $"); | 71__FBSDID("$FreeBSD: head/lib/libc/net/nsdispatch.c 127625 2004-03-30 15:56:15Z nectar $"); |
72 73#include "namespace.h" 74#include <sys/param.h> 75#include <sys/stat.h> 76 77#include <dlfcn.h> 78#include <errno.h> 79#include <fcntl.h> --- 231 unchanged lines hidden (view full) --- 311 * prepare global data needed by NSS. 312 */ 313static int 314nss_configure(void) 315{ 316 static pthread_mutex_t conf_lock = PTHREAD_MUTEX_INITIALIZER; 317 static time_t confmod; 318 struct stat statbuf; | 72 73#include "namespace.h" 74#include <sys/param.h> 75#include <sys/stat.h> 76 77#include <dlfcn.h> 78#include <errno.h> 79#include <fcntl.h> --- 231 unchanged lines hidden (view full) --- 311 * prepare global data needed by NSS. 312 */ 313static int 314nss_configure(void) 315{ 316 static pthread_mutex_t conf_lock = PTHREAD_MUTEX_INITIALIZER; 317 static time_t confmod; 318 struct stat statbuf; |
319 int result; | 319 int result, isthreaded; |
320 const char *path; 321 | 320 const char *path; 321 |
322 result = 0; 323 isthreaded = __isthreaded; |
|
322#if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT) 323 /* NOTE WELL: THIS IS A SECURITY HOLE. This must only be built 324 * for debugging purposes and MUST NEVER be used in production. 325 */ 326 path = getenv("NSSWITCH_CONF"); 327 if (path == NULL) 328#endif 329 path = _PATH_NS_CONF; 330 if (stat(path, &statbuf) != 0) 331 return (0); 332 if (statbuf.st_mtime <= confmod) 333 return (0); | 324#if defined(_NSS_DEBUG) && defined(_NSS_SHOOT_FOOT) 325 /* NOTE WELL: THIS IS A SECURITY HOLE. This must only be built 326 * for debugging purposes and MUST NEVER be used in production. 327 */ 328 path = getenv("NSSWITCH_CONF"); 329 if (path == NULL) 330#endif 331 path = _PATH_NS_CONF; 332 if (stat(path, &statbuf) != 0) 333 return (0); 334 if (statbuf.st_mtime <= confmod) 335 return (0); |
334 result = _pthread_mutex_trylock(&conf_lock); 335 if (result != 0) 336 return (0); 337 (void)_pthread_rwlock_unlock(&nss_lock); 338 result = _pthread_rwlock_wrlock(&nss_lock); 339 if (result != 0) 340 goto fin2; | 336 if (isthreaded) { 337 result = _pthread_mutex_trylock(&conf_lock); 338 if (result != 0) 339 return (0); 340 (void)_pthread_rwlock_unlock(&nss_lock); 341 result = _pthread_rwlock_wrlock(&nss_lock); 342 if (result != 0) 343 goto fin2; 344 } |
341 _nsyyin = fopen(path, "r"); | 345 _nsyyin = fopen(path, "r"); |
342 if (_nsyyin == NULL) | 346 if (_nsyyin == NULL) { 347 result = errno; |
343 goto fin; | 348 goto fin; |
349 } |
|
344 VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap), 345 (vector_free_elem)ns_dbt_free); 346 VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod), 347 (vector_free_elem)ns_mod_free); 348 nss_load_builtin_modules(); 349 _nsyyparse(); 350 (void)fclose(_nsyyin); 351 vector_sort(_nsmap, _nsmapsize, sizeof(*_nsmap), string_compare); 352 if (confmod == 0) 353 (void)atexit(nss_atexit); 354 confmod = statbuf.st_mtime; 355fin: | 350 VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap), 351 (vector_free_elem)ns_dbt_free); 352 VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod), 353 (vector_free_elem)ns_mod_free); 354 nss_load_builtin_modules(); 355 _nsyyparse(); 356 (void)fclose(_nsyyin); 357 vector_sort(_nsmap, _nsmapsize, sizeof(*_nsmap), string_compare); 358 if (confmod == 0) 359 (void)atexit(nss_atexit); 360 confmod = statbuf.st_mtime; 361fin: |
356 (void)_pthread_rwlock_unlock(&nss_lock); 357 result = _pthread_rwlock_rdlock(&nss_lock); | 362 if (isthreaded) { 363 (void)_pthread_rwlock_unlock(&nss_lock); 364 if (result == 0) 365 result = _pthread_rwlock_rdlock(&nss_lock); 366 } |
358fin2: | 367fin2: |
359 (void)_pthread_mutex_unlock(&conf_lock); | 368 if (isthreaded) 369 (void)_pthread_mutex_unlock(&conf_lock); |
360 return (result); 361} 362 363 364void 365_nsdbtput(const ns_dbt *dbt) 366{ 367 unsigned int i; --- 137 unchanged lines hidden (view full) --- 505 506 507/* 508 * Cleanup 509 */ 510static void 511nss_atexit(void) 512{ | 370 return (result); 371} 372 373 374void 375_nsdbtput(const ns_dbt *dbt) 376{ 377 unsigned int i; --- 137 unchanged lines hidden (view full) --- 515 516 517/* 518 * Cleanup 519 */ 520static void 521nss_atexit(void) 522{ |
513 (void)_pthread_rwlock_wrlock(&nss_lock); | 523 int isthreaded; 524 525 isthreaded = __isthreaded; 526 if (isthreaded) 527 (void)_pthread_rwlock_wrlock(&nss_lock); |
514 VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap), 515 (vector_free_elem)ns_dbt_free); 516 VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod), 517 (vector_free_elem)ns_mod_free); | 528 VECTOR_FREE(_nsmap, &_nsmapsize, sizeof(*_nsmap), 529 (vector_free_elem)ns_dbt_free); 530 VECTOR_FREE(_nsmod, &_nsmodsize, sizeof(*_nsmod), 531 (vector_free_elem)ns_mod_free); |
518 (void)_pthread_rwlock_unlock(&nss_lock); | 532 if (isthreaded) 533 (void)_pthread_rwlock_unlock(&nss_lock); |
519} 520 521 522 523/* 524 * Finally, the actual implementation. 525 */ 526static nss_method --- 36 unchanged lines hidden (view full) --- 563_nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, 564 const char *method_name, const ns_src defaults[], ...) 565{ 566 va_list ap; 567 const ns_dbt *dbt; 568 const ns_src *srclist; 569 nss_method method; 570 void *mdata; | 534} 535 536 537 538/* 539 * Finally, the actual implementation. 540 */ 541static nss_method --- 36 unchanged lines hidden (view full) --- 578_nsdispatch(void *retval, const ns_dtab disp_tab[], const char *database, 579 const char *method_name, const ns_src defaults[], ...) 580{ 581 va_list ap; 582 const ns_dbt *dbt; 583 const ns_src *srclist; 584 nss_method method; 585 void *mdata; |
571 int serrno, i, result, srclistsize; | 586 int isthreaded, serrno, i, result, srclistsize; |
572 | 587 |
588 isthreaded = __isthreaded; |
|
573 serrno = errno; | 589 serrno = errno; |
574 result = _pthread_rwlock_rdlock(&nss_lock); 575 if (result != 0) { 576 result = NS_UNAVAIL; 577 goto fin; | 590 if (isthreaded) { 591 result = _pthread_rwlock_rdlock(&nss_lock); 592 if (result != 0) { 593 result = NS_UNAVAIL; 594 goto fin; 595 } |
578 } 579 result = nss_configure(); 580 if (result != 0) { 581 result = NS_UNAVAIL; 582 goto fin; 583 } 584 dbt = vector_search(&database, _nsmap, _nsmapsize, sizeof(*_nsmap), 585 string_compare); --- 13 unchanged lines hidden (view full) --- 599 if (method != NULL) { 600 va_start(ap, defaults); 601 result = method(retval, mdata, ap); 602 va_end(ap); 603 if (result & (srclist[i].flags)) 604 break; 605 } 606 } | 596 } 597 result = nss_configure(); 598 if (result != 0) { 599 result = NS_UNAVAIL; 600 goto fin; 601 } 602 dbt = vector_search(&database, _nsmap, _nsmapsize, sizeof(*_nsmap), 603 string_compare); --- 13 unchanged lines hidden (view full) --- 617 if (method != NULL) { 618 va_start(ap, defaults); 619 result = method(retval, mdata, ap); 620 va_end(ap); 621 if (result & (srclist[i].flags)) 622 break; 623 } 624 } |
607 (void)_pthread_rwlock_unlock(&nss_lock); | 625 if (isthreaded) 626 (void)_pthread_rwlock_unlock(&nss_lock); |
608fin: 609 errno = serrno; 610 return (result); 611} | 627fin: 628 errno = serrno; 629 return (result); 630} |