# HG changeset patch # User jacobs # Date 1159826643 25200 # Node ID 05bae185f48ce8a5cd556b06c8fecd41b6e4e8e3 # Parent d2693e8a5243005fb092afd0802e0bcc1dd2d4ea 6476321 fix for 6461190 breaks lpstat -p, -o, -v, ... 6477108 sparks (6225323) breaks lpget -n and papiPrintersList() diff -r d2693e8a5243 -r 05bae185f48c usr/src/lib/nsswitch/files/common/getprinter.c --- a/usr/src/lib/nsswitch/files/common/getprinter.c Mon Oct 02 14:44:57 2006 -0700 +++ b/usr/src/lib/nsswitch/files/common/getprinter.c Mon Oct 02 15:04:03 2006 -0700 @@ -35,6 +35,7 @@ #include "files_common.h" #include #include +#include static int check_name(nss_XbyY_args_t *argp, const char *line, int linelen) @@ -66,6 +67,115 @@ return (0); } +nss_status_t +_nss_files_XY_printer(be, args, filter, check) + files_backend_ptr_t be; + nss_XbyY_args_t *args; + const char *filter; /* advisory, to speed up */ + /* string search */ + files_XY_check_func check; /* NULL means one-shot, for getXXent */ +{ + nss_status_t res; + int parsestat; + int (*func)(); + + if (filter != NULL && *filter == '\0') + return (NSS_NOTFOUND); + if (be->buf == 0 && + (be->buf = malloc(be->minbuf)) == 0) { + return (NSS_UNAVAIL); /* really panic, malloc failed */ + } + + if (check != 0 || be->f == 0) { + if ((res = _nss_files_setent(be, 0)) != NSS_SUCCESS) { + return (res); + } + } + + res = NSS_NOTFOUND; + + /*CONSTCOND*/ + while (1) { + char *instr = be->buf; + int linelen; + + if ((linelen = _nss_files_read_line(be->f, instr, + be->minbuf)) < 0) { + /* End of file */ + args->returnval = 0; + args->returnlen = 0; + break; + } + + /* begin at the first non-blank character */ + while (isspace(*instr)) { + instr++; + linelen--; + } + + /* comment line, skip it. */ + if (*instr == '#') + continue; + + /* blank line, skip it */ + if ((*instr == '\n') || (*instr == '\0')) + continue; + + if (filter != 0 && strstr(instr, filter) == 0) { + /* + * Optimization: if the entry doesn't contain the + * filter string then it can't be the entry we want, + * so don't bother looking more closely at it. + */ + continue; + } + + args->returnval = 0; + args->returnlen = 0; + + if (check != NULL && (*check)(args, instr, linelen) == 0) + continue; + + func = args->str2ent; + parsestat = (*func)(instr, linelen, args->buf.result, + args->buf.buffer, args->buf.buflen); + + if (parsestat == NSS_STR_PARSE_SUCCESS) { + args->returnval = (args->buf.result != NULL)? + args->buf.result : args->buf.buffer; + args->returnlen = linelen; + res = NSS_SUCCESS; + break; + } else if (parsestat == NSS_STR_PARSE_ERANGE) { + args->erange = 1; + break; + } else if (parsestat == NSS_STR_PARSE_PARSE) + continue; + } + + /* + * stayopen is set to 0 by default in order to close the opened + * file. Some applications may break if it is set to 1. + */ + if (check != 0 && !args->stayopen) { + (void) _nss_files_endent(be, 0); + } + + return (res); +} + +static nss_status_t +getent(be, a) + files_backend_ptr_t be; + void *a; +{ + nss_status_t status; + nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; + + return (_nss_files_XY_printer(be, argp, (files_XY_check_func)0, + (const char *)0)); +} + static nss_status_t getbyname(be, a) files_backend_ptr_t be; @@ -73,15 +183,14 @@ { nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a; - return (_nss_files_XY_all(be, argp, 1, argp->key.name, - check_name)); + return (_nss_files_XY_printer(be, argp, argp->key.name, check_name)); } static files_backend_op_t printers_ops[] = { _nss_files_destr, _nss_files_endent, _nss_files_setent, - _nss_files_getent_rigid, + getent, getbyname }; diff -r d2693e8a5243 -r 05bae185f48c usr/src/lib/print/libpapi-dynamic/common/nss.c --- a/usr/src/lib/print/libpapi-dynamic/common/nss.c Mon Oct 02 14:44:57 2006 -0700 +++ b/usr/src/lib/print/libpapi-dynamic/common/nss.c Mon Oct 02 15:04:03 2006 -0700 @@ -443,7 +443,6 @@ static DEFINE_NSS_GETENT(context); static char *private_ns = NULL; -static char initialized = 0; static void _nss_initf_printers(p) @@ -459,14 +458,12 @@ */ p->name = NSS_DBNAM__PRINTERS; /* "_printers" */ p->default_config = private_ns; - private_ns = NULL; - } else if (initialized == 0) { + } else { /* regular behaviour */ p->name = NSS_DBNAM_PRINTERS; /* "printers" */ p->default_config = NSS_DEFCONF_PRINTERS; - initialized = 1; } - syslog(LOG_DEBUG, "database: %s, services: %s", + syslog(LOG_DEBUG, "database: %s, default: %s", (p->name ? p->name : "NULL"), (p->default_config ? p->default_config : "NULL")); } @@ -504,9 +501,9 @@ #ifdef NSS_EMULATION emul_setprinterentry(stayopen); #elif NSS_SOLARIS - initialized = 0; private_ns = ns; nss_setent(&db_root, _nss_initf_printers, &context); + private_ns = NULL; #endif return (0); } @@ -518,9 +515,9 @@ #ifdef NSS_EMULATION emul_endprinterentry(); #elif NSS_SOLARIS - initialized = 0; nss_endent(&db_root, _nss_initf_printers, &context); nss_delete(&db_root); + private_ns = NULL; #endif return (0); } @@ -540,9 +537,11 @@ #elif NSS_SOLARIS nss_XbyY_args_t arg; + private_ns = ns; NSS_XbyY_INIT(&arg, buf, buf, sizeof (buf), str2printer); res = nss_getent(&db_root, _nss_initf_printers, &context, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; #endif if (res != NSS_SUCCESS) @@ -607,6 +606,7 @@ res = nss_search(&db_root, _nss_initf_printers, NSS_DBOP_PRINTERS_BYNAME, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; if (res != NSS_SUCCESS) buf[0] = '\0'; diff -r d2693e8a5243 -r 05bae185f48c usr/src/lib/print/libprint/common/nss_printer.c --- a/usr/src/lib/print/libprint/common/nss_printer.c Mon Oct 02 14:44:57 2006 -0700 +++ b/usr/src/lib/print/libprint/common/nss_printer.c Mon Oct 02 15:04:03 2006 -0700 @@ -42,8 +42,6 @@ static int printers_stayopen; static char *private_ns = NULL; -static char initialized = 0; - static void _nss_initf_printers(p) @@ -59,14 +57,12 @@ */ p->name = NSS_DBNAM__PRINTERS; /* "_printers" */ p->default_config = normalize_ns_name(private_ns); - private_ns = NULL; - } else if (initialized == 0) { + } else { /* regular behaviour */ p->name = NSS_DBNAM_PRINTERS; /* "printers" */ p->default_config = NSS_DEFCONF_PRINTERS; - /* keep reinitializing as needed was: initialized = 1; */ } - syslog(LOG_DEBUG, "database: %s, services: %s", + syslog(LOG_DEBUG, "database: %s, default: %s", (p->name ? p->name : "NULL"), (p->default_config ? p->default_config : "NULL")); } @@ -102,9 +98,9 @@ setprinterentry(int stayopen, char *ns) { printers_stayopen |= stayopen; - initialized = 0; private_ns = ns; nss_setent(&db_root, _nss_initf_printers, &context); + private_ns = NULL; return (0); } @@ -113,9 +109,9 @@ endprinterentry() { printers_stayopen = 0; - initialized = 0; nss_endent(&db_root, _nss_initf_printers, &context); nss_delete(&db_root); + private_ns = NULL; return (0); } @@ -127,9 +123,12 @@ nss_XbyY_args_t arg; nss_status_t res; + private_ns = ns; NSS_XbyY_INIT(&arg, linebuf, linebuf, linelen, str2printer); res = nss_getent(&db_root, _nss_initf_printers, &context, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; + return (arg.status = res); } @@ -146,5 +145,7 @@ res = nss_search(&db_root, _nss_initf_printers, NSS_DBOP_PRINTERS_BYNAME, &arg); (void) NSS_XbyY_FINI(&arg); + private_ns = NULL; + return (arg.status = res); }