version 1.3, 1993/07/30 08:22:19 |
version 1.14, 1997/07/21 14:07:03 |
|
|
|
/* $NetBSD$ */ |
|
|
/*- |
/*- |
* Copyright (c) 1992 The Regents of the University of California. |
* Copyright (c) 1992, 1993 |
* All rights reserved. |
* The Regents of the University of California. All rights reserved. |
* |
* |
* This code is derived from software contributed to Berkeley by |
* This code is derived from software contributed to Berkeley by |
* Casey Leedom of Lawrence Livermore National Laboratory. |
* Casey Leedom of Lawrence Livermore National Laboratory. |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
|
#include <sys/cdefs.h> |
#if defined(LIBC_SCCS) && !defined(lint) |
#if defined(LIBC_SCCS) && !defined(lint) |
/*static char sccsid[] = "from: @(#)getcap.c 5.15 (Berkeley) 3/19/93";*/ |
#if 0 |
static char rcsid[] = "$Id$"; |
static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; |
|
#else |
|
__RCSID("$NetBSD$"); |
|
#endif |
#endif /* LIBC_SCCS and not lint */ |
#endif /* LIBC_SCCS and not lint */ |
|
|
|
#include "namespace.h" |
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <db.h> |
#include <db.h> |
#include <errno.h> |
#include <errno.h> |
Line 51 static char rcsid[] = "$Id$"; |
|
Line 57 static char rcsid[] = "$Id$"; |
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
|
#ifdef __weak_alias |
|
__weak_alias(cgetcap,_cgetcap); |
|
__weak_alias(cgetclose,_cgetclose); |
|
__weak_alias(cgetent,_cgetent); |
|
__weak_alias(cgetfirst,_cgetfirst); |
|
__weak_alias(cgetmatch,_cgetmatch); |
|
__weak_alias(cgetnext,_cgetnext); |
|
__weak_alias(cgetnum,_cgetnum); |
|
__weak_alias(cgetset,_cgetset); |
|
__weak_alias(cgetstr,_cgetstr); |
|
__weak_alias(cgetustr,_cgetustr); |
|
#endif |
|
|
#define BFRAG 1024 |
#define BFRAG 1024 |
#define BSIZE 1024 |
#define BSIZE 1024 |
#define ESC ('[' & 037) /* ASCII ESC */ |
#define ESC ('[' & 037) /* ASCII ESC */ |
|
|
return (-1); |
return (-1); |
} |
} |
gottoprec = 0; |
gottoprec = 0; |
(void)strcpy(toprec, ent); |
(void)strcpy(toprec, ent); /* XXX: strcpy is safe */ |
return (0); |
return (0); |
} |
} |
|
|
Line 193 getent(cap, len, db_array, fd, name, dep |
|
Line 212 getent(cap, len, db_array, fd, name, dep |
|
int fd, depth; |
int fd, depth; |
{ |
{ |
DB *capdbp; |
DB *capdbp; |
DBT key, data; |
register char *r_end, *rp = NULL, **db_p; /* pacify gcc */ |
register char *r_end, *rp, **db_p; |
int myfd = 0, eof, foundit, retval, clen; |
int myfd, eof, foundit, retval; |
char *record, *cbuf; |
char *record; |
|
int tc_not_resolved; |
int tc_not_resolved; |
char pbuf[_POSIX_PATH_MAX]; |
char pbuf[_POSIX_PATH_MAX]; |
|
|
Line 215 getent(cap, len, db_array, fd, name, dep |
|
Line 233 getent(cap, len, db_array, fd, name, dep |
|
errno = ENOMEM; |
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
(void)strcpy(record, toprec); |
(void)strcpy(record, toprec); /* XXX: strcpy is safe */ |
myfd = 0; |
|
db_p = db_array; |
db_p = db_array; |
rp = record + topreclen + 1; |
rp = record + topreclen + 1; |
r_end = rp + BFRAG; |
r_end = rp + BFRAG; |
Line 244 getent(cap, len, db_array, fd, name, dep |
|
Line 261 getent(cap, len, db_array, fd, name, dep |
|
|
|
if (fd >= 0) { |
if (fd >= 0) { |
(void)lseek(fd, (off_t)0, L_SET); |
(void)lseek(fd, (off_t)0, L_SET); |
myfd = 0; |
|
} else { |
} else { |
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) |
if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) |
!= NULL) { |
!= NULL) { |
free(record); |
free(record); |
retval = cdbget(capdbp, &record, name); |
retval = cdbget(capdbp, &record, name); |
if (capdbp->close(capdbp) < 0) |
if (retval < 0) { |
|
/* no record available */ |
|
(void)capdbp->close(capdbp); |
|
return (retval); |
|
} |
|
/* save the data; close frees it */ |
|
clen = strlen(record); |
|
cbuf = malloc(clen + 1); |
|
memcpy(cbuf, record, clen + 1); |
|
if (capdbp->close(capdbp) < 0) { |
|
free(cbuf); |
return (-2); |
return (-2); |
*len = strlen(record); |
} |
*cap = malloc(*len + 1); |
*len = clen; |
memmove(*cap, record, *len + 1); |
*cap = cbuf; |
return (retval); |
return (retval); |
} else { |
} else { |
fd = open(*db_p, O_RDONLY, 0); |
fd = open(*db_p, O_RDONLY, 0); |
if (fd < 0) { |
if (fd < 0) { |
/* No error on unfound file. */ |
/* No error on unfound file. */ |
if (errno == ENOENT) |
continue; |
continue; |
|
free(record); |
|
return (-2); |
|
} |
} |
myfd = 1; |
myfd = 1; |
} |
} |
Line 533 cdbget(capdbp, bp, name) |
|
Line 556 cdbget(capdbp, bp, name) |
|
char **bp, *name; |
char **bp, *name; |
{ |
{ |
DBT key, data; |
DBT key, data; |
char *buf; |
|
int st; |
|
|
|
key.data = name; |
key.data = name; |
key.size = strlen(name); |
key.size = strlen(name); |
Line 658 cgetnext(bp, db_array) |
|
Line 679 cgetnext(bp, db_array) |
|
gottoprec = 1; |
gottoprec = 1; |
line = toprec; |
line = toprec; |
} else { |
} else { |
line = fgetline(pfp, &len); |
line = fgetln(pfp, &len); |
if (line == NULL && pfp) { |
if (line == NULL && pfp) { |
(void)fclose(pfp); |
(void)fclose(pfp); |
if (ferror(pfp)) { |
if (ferror(pfp)) { |
Line 675 cgetnext(bp, db_array) |
|
Line 696 cgetnext(bp, db_array) |
|
} else |
} else |
continue; |
continue; |
} |
} |
} |
} else |
if (len == 0) { |
line[len - 1] = '\0'; |
|
if (len == 1) { |
slash = 0; |
slash = 0; |
continue; |
continue; |
} |
} |
if (isspace(*line) || |
if (isspace(*line) || |
*line == ':' || *line == '#' || slash) { |
*line == ':' || *line == '#' || slash) { |
if (line[len - 1] == '\\') |
if (line[len - 2] == '\\') |
slash = 1; |
slash = 1; |
else |
else |
slash = 0; |
slash = 0; |
continue; |
continue; |
} |
} |
if (line[len - 1] == '\\') |
if (line[len - 2] == '\\') |
slash = 1; |
slash = 1; |
else |
else |
slash = 0; |
slash = 0; |
Line 716 cgetnext(bp, db_array) |
|
Line 738 cgetnext(bp, db_array) |
|
*np = '\0'; |
*np = '\0'; |
break; |
break; |
} else { /* name field extends beyond the line */ |
} else { /* name field extends beyond the line */ |
line = fgetline(pfp, &len); |
line = fgetln(pfp, &len); |
if (line == NULL && pfp) { |
if (line == NULL && pfp) { |
(void)fclose(pfp); |
(void)fclose(pfp); |
if (ferror(pfp)) { |
if (ferror(pfp)) { |
(void)cgetclose(); |
(void)cgetclose(); |
return (-1); |
return (-1); |
} |
} |
} |
} else |
|
line[len - 1] = '\0'; |
} |
} |
} |
} |
rp = buf; |
rp = buf; |
for(cp = nbuf; *cp != NULL; cp++) |
for(cp = nbuf; *cp != '\0'; cp++) |
if (*cp == '|' || *cp == ':') |
if (*cp == '|' || *cp == ':') |
break; |
break; |
else |
else |