usr/src/lib/print/libpapi-dynamic/common/nss.c
changeset 2847 05bae185f48c
parent 2571 2fe9e3540b04
child 6817 413cac950261
equal deleted inserted replaced
2846:d2693e8a5243 2847:05bae185f48c
   441 
   441 
   442 static DEFINE_NSS_DB_ROOT(db_root);
   442 static DEFINE_NSS_DB_ROOT(db_root);
   443 static DEFINE_NSS_GETENT(context);
   443 static DEFINE_NSS_GETENT(context);
   444 
   444 
   445 static char *private_ns = NULL;
   445 static char *private_ns = NULL;
   446 static char initialized = 0;
       
   447 
   446 
   448 static void
   447 static void
   449 _nss_initf_printers(p)
   448 _nss_initf_printers(p)
   450     nss_db_params_t *p;
   449     nss_db_params_t *p;
   451 {
   450 {
   457 		 * the * default_config entry to the name service we are
   456 		 * the * default_config entry to the name service we are
   458 		 * looking into.
   457 		 * looking into.
   459 		 */
   458 		 */
   460 		p->name = NSS_DBNAM__PRINTERS;		/* "_printers" */
   459 		p->name = NSS_DBNAM__PRINTERS;		/* "_printers" */
   461 		p->default_config = private_ns;
   460 		p->default_config = private_ns;
   462 		private_ns = NULL;
   461 	} else {
   463 	} else if (initialized == 0) {
       
   464 		/* regular behaviour */
   462 		/* regular behaviour */
   465 		p->name = NSS_DBNAM_PRINTERS;	 /* "printers" */
   463 		p->name = NSS_DBNAM_PRINTERS;	 /* "printers" */
   466 		p->default_config = NSS_DEFCONF_PRINTERS;
   464 		p->default_config = NSS_DEFCONF_PRINTERS;
   467 		initialized = 1;
   465 	}
   468 	}
   466 	syslog(LOG_DEBUG, "database: %s, default: %s",
   469 	syslog(LOG_DEBUG, "database: %s, services: %s",
       
   470 		(p->name ? p->name : "NULL"),
   467 		(p->name ? p->name : "NULL"),
   471 		(p->default_config ? p->default_config : "NULL"));
   468 		(p->default_config ? p->default_config : "NULL"));
   472 }
   469 }
   473 
   470 
   474 /*
   471 /*
   502 setprinterentry(int stayopen, char *ns)
   499 setprinterentry(int stayopen, char *ns)
   503 {
   500 {
   504 #ifdef NSS_EMULATION
   501 #ifdef NSS_EMULATION
   505 	emul_setprinterentry(stayopen);
   502 	emul_setprinterentry(stayopen);
   506 #elif NSS_SOLARIS
   503 #elif NSS_SOLARIS
   507 	initialized = 0;
       
   508 	private_ns = ns;
   504 	private_ns = ns;
   509 	nss_setent(&db_root, _nss_initf_printers, &context);
   505 	nss_setent(&db_root, _nss_initf_printers, &context);
       
   506 	private_ns = NULL;
   510 #endif
   507 #endif
   511 	return (0);
   508 	return (0);
   512 }
   509 }
   513 
   510 
   514 
   511 
   516 endprinterentry(int i)
   513 endprinterentry(int i)
   517 {
   514 {
   518 #ifdef NSS_EMULATION
   515 #ifdef NSS_EMULATION
   519 	emul_endprinterentry();
   516 	emul_endprinterentry();
   520 #elif NSS_SOLARIS
   517 #elif NSS_SOLARIS
   521 	initialized = 0;
       
   522 	nss_endent(&db_root, _nss_initf_printers, &context);
   518 	nss_endent(&db_root, _nss_initf_printers, &context);
   523 	nss_delete(&db_root);
   519 	nss_delete(&db_root);
       
   520 	private_ns = NULL;
   524 #endif
   521 #endif
   525 	return (0);
   522 	return (0);
   526 }
   523 }
   527 
   524 
   528 /* ARGSUSED2 */
   525 /* ARGSUSED2 */
   538 #ifdef NSS_EMULATION
   535 #ifdef NSS_EMULATION
   539 	res = emul_getprinterentry_r(buf, sizeof (buf));
   536 	res = emul_getprinterentry_r(buf, sizeof (buf));
   540 #elif NSS_SOLARIS
   537 #elif NSS_SOLARIS
   541 	nss_XbyY_args_t arg;
   538 	nss_XbyY_args_t arg;
   542 
   539 
       
   540 	private_ns = ns;
   543 	NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer);
   541 	NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer);
   544 	res = nss_getent(&db_root, _nss_initf_printers, &context, &arg);
   542 	res = nss_getent(&db_root, _nss_initf_printers, &context, &arg);
   545 	(void) NSS_XbyY_FINI(&arg);
   543 	(void) NSS_XbyY_FINI(&arg);
       
   544 	private_ns = NULL;
   546 #endif
   545 #endif
   547 
   546 
   548 	if (res != NSS_SUCCESS)
   547 	if (res != NSS_SUCCESS)
   549 		buf[0] = '\0';
   548 		buf[0] = '\0';
   550 
   549 
   605 		NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer);
   604 		NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer);
   606 		arg.key.name = name;
   605 		arg.key.name = name;
   607 		res = nss_search(&db_root, _nss_initf_printers,
   606 		res = nss_search(&db_root, _nss_initf_printers,
   608 				NSS_DBOP_PRINTERS_BYNAME, &arg);
   607 				NSS_DBOP_PRINTERS_BYNAME, &arg);
   609 		(void) NSS_XbyY_FINI(&arg);
   608 		(void) NSS_XbyY_FINI(&arg);
       
   609 		private_ns = NULL;
   610 
   610 
   611 		if (res != NSS_SUCCESS)
   611 		if (res != NSS_SUCCESS)
   612 			buf[0] = '\0';
   612 			buf[0] = '\0';
   613 #endif
   613 #endif
   614 
   614