/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Common code and structures used by name-service-switch "user" backends.
* Much of this was taken directly from the files_common.c source.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* An implementation that used mmap() sensibly would be a wonderful thing,
* but this here is just yer standard fgets() thang.
*/
#include "user_common.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
#include <string.h>
/*ARGSUSED*/
void *dummy;
{
if (be->f == 0) {
/* Backend isn't initialized properly? */
return (NSS_UNAVAIL);
}
return (NSS_UNAVAIL);
}
} else {
}
return (NSS_SUCCESS);
}
/*ARGSUSED*/
void *dummy;
{
if (be->f != 0) {
be->f = 0;
}
}
return (NSS_SUCCESS);
}
/*
* This routine reads a line, including the processing of continuation
* characters. It always leaves (or inserts) \n\0 at the end of the line.
* It returns the length of the line read, excluding the \n\0. Who's idea
* was this?
* Returns -1 on EOF.
*
* Note that since each concurrent call to _nss_user_read_line has
* it's own FILE pointer, we can use getc_unlocked w/o difficulties,
* a substantial performance win.
*/
int
FILE *f;
char *buffer;
int buflen;
{
int c;
/*CONSTCOND*/
while (1) {
linelen = 0;
switch (c = getc_unlocked(f)) {
case EOF:
if (linelen == 0 ||
return (-1);
} else {
return (linelen);
}
case '\n':
if (linelen > 0 &&
--linelen; /* remove the '\\' */
} else {
return (linelen);
}
break;
default:
}
}
/* Buffer overflow -- eat rest of line and loop again */
/* ===> Should syslog() */
do {
c = getc_unlocked(f);
if (c == EOF) {
return (-1);
}
} while (c != '\n');
}
/*NOTREACHED*/
}
/*
* Could implement this as an iterator function on top of _nss_user_do_all(),
* but the shared code is small enough that it'd be pretty silly.
*/
int netdb; /* whether it uses netdb */
/* format or not */
const char *filter; /* advisory, to speed up */
/* string search */
{
int parsestat;
return (NSS_UNAVAIL); /* really panic, malloc failed */
}
return (res);
}
}
res = NSS_NOTFOUND;
/*CONSTCOND*/
while (1) {
int linelen;
/* End of file */
break;
}
/*
* 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;
}
if (netdb) {
char *first;
char *last;
}
/*
* Skip leading whitespace. Normally there isn't
* any, so it's not worth calling strspn().
*/
;
}
if (*first == '\0') {
continue;
}
/*
* Found something non-blank on the line. Skip back
* over any trailing whitespace; since we know
* there's non-whitespace earlier in the line,
* checking for termination is easy.
*/
--last;
}
}
}
if (parsestat == NSS_STR_PARSE_SUCCESS) {
res = NSS_SUCCESS;
break;
}
} else if (parsestat == NSS_STR_PARSE_ERANGE) {
/* one long line ?? */
} /* else if (parsestat == NSS_STR_PARSE_PARSE) don't care ! */
}
/*
* stayopen is set to 0 by default in order to close the opened
* file. Some applications may break if it is set to 1.
*/
(void) _nss_user_endent(be, 0);
}
return (res);
}
/*ARGSUSED*/
void *dummy;
{
if (be != 0) {
if (be->f != 0) {
(void) _nss_user_endent(be, 0);
}
}
return (NSS_SUCCESS); /* In case anyone is dumb enough to check */
}
int n_ops;
const char *filename;
int min_bufsize;
{
return (0);
}
return (NULL);
}
be->f = 0;
return ((nss_backend_t *)be);
}