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.
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.
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]
22 * files/printers_getbyname.c -- "files" backend for
23 * nsswitch "printers" database.
25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 static const char *printers
= "/etc/printers.conf";
33 #pragma weak _nss_files__printers_constr = _nss_files_printers_constr
35 #include "files_common.h"
41 check_name(nss_XbyY_args_t
*argp
, const char *line
, int linelen
)
44 const char *limit
, *linep
;
45 const char *keyp
= argp
->key
.name
;
46 int klen
= strlen(keyp
);
49 limit
= line
+ linelen
;
52 * find the name in the namelist a|b|c...:
54 while (linep
+klen
< limit
&& *linep
!= '|' && *linep
!= ':') {
55 if ((strncmp(linep
, keyp
, klen
) == 0) &&
56 ((*(linep
+ klen
) == '|') || (*(linep
+ klen
) == ':'))) {
59 while (linep
< limit
&& *linep
!= '|' && *linep
!= ':')
61 if (linep
>= limit
|| *linep
== ':')
71 _nss_files_XY_printer(be
, args
, filter
, check
)
72 files_backend_ptr_t be
;
73 nss_XbyY_args_t
*args
;
74 const char *filter
; /* advisory, to speed up */
76 files_XY_check_func check
; /* NULL means one-shot, for getXXent */
82 if (filter
!= NULL
&& *filter
== '\0')
83 return (NSS_NOTFOUND
);
85 (be
->buf
= malloc(be
->minbuf
)) == 0) {
86 return (NSS_UNAVAIL
); /* really panic, malloc failed */
89 if (check
!= 0 || be
->f
== 0) {
90 if ((res
= _nss_files_setent(be
, 0)) != NSS_SUCCESS
) {
99 char *instr
= be
->buf
;
102 if ((linelen
= _nss_files_read_line(be
->f
, instr
,
110 /* begin at the first non-blank character */
111 while (isspace(*instr
)) {
116 /* comment line, skip it. */
120 /* blank line, skip it */
121 if ((*instr
== '\n') || (*instr
== '\0'))
124 if (filter
!= 0 && strstr(instr
, filter
) == 0) {
126 * Optimization: if the entry doesn't contain the
127 * filter string then it can't be the entry we want,
128 * so don't bother looking more closely at it.
136 if (check
!= NULL
&& (*check
)(args
, instr
, linelen
) == 0)
139 func
= args
->str2ent
;
140 parsestat
= (*func
)(instr
, linelen
, args
->buf
.result
,
141 args
->buf
.buffer
, args
->buf
.buflen
);
143 if (parsestat
== NSS_STR_PARSE_SUCCESS
) {
144 args
->returnval
= (args
->buf
.result
!= NULL
)?
145 args
->buf
.result
: args
->buf
.buffer
;
146 args
->returnlen
= linelen
;
149 } else if (parsestat
== NSS_STR_PARSE_ERANGE
) {
152 } else if (parsestat
== NSS_STR_PARSE_PARSE
)
157 * stayopen is set to 0 by default in order to close the opened
158 * file. Some applications may break if it is set to 1.
160 if (check
!= 0 && !args
->stayopen
) {
161 (void) _nss_files_endent(be
, 0);
169 files_backend_ptr_t be
;
172 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
174 return (_nss_files_XY_printer(be
, argp
, (const char *)0,
175 (files_XY_check_func
)0));
180 files_backend_ptr_t be
;
183 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
185 return (_nss_files_XY_printer(be
, argp
, argp
->key
.name
, check_name
));
188 static files_backend_op_t printers_ops
[] = {
198 _nss_files_printers_constr(dummy1
, dummy2
, dummy3
)
199 const char *dummy1
, *dummy2
, *dummy3
;
201 return (_nss_files_constr(printers_ops
,
202 sizeof (printers_ops
) / sizeof (printers_ops
[0]),
204 NSS_LINELEN_PRINTERS
,