version 1.50, 2011/10/15 23:00:01 |
version 1.55, 2014/09/24 07:53:06 |
Line 52 __RCSID("$NetBSD$"); |
|
Line 52 __RCSID("$NetBSD$"); |
|
#include <sys/param.h> |
#include <sys/param.h> |
|
|
#include <assert.h> |
#include <assert.h> |
|
#include <stddef.h> |
#include <ctype.h> |
#include <ctype.h> |
#ifndef SMALL |
#ifndef SMALL |
#include <db.h> |
#include <db.h> |
Line 64 __RCSID("$NetBSD$"); |
|
Line 65 __RCSID("$NetBSD$"); |
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
|
#ifndef O_CLOEXEC /* For tools, as in NetBSD 5.2 or earlier... */ |
|
#define O_CLOEXEC 0 |
|
#endif |
|
|
#if defined(__weak_alias) && !defined(SMALL) |
#if defined(__weak_alias) && !defined(SMALL) |
__weak_alias(cgetcap,_cgetcap) |
__weak_alias(cgetcap,_cgetcap) |
__weak_alias(cgetclose,_cgetclose) |
__weak_alias(cgetclose,_cgetclose) |
Line 159 cgetset(const char *ent) |
|
Line 164 cgetset(const char *ent) |
|
* return NULL. |
* return NULL. |
*/ |
*/ |
char * |
char * |
cgetcap(buf, cap, type) |
cgetcap(char *buf, const char *cap, int type) |
char *buf; |
|
const char *cap; |
|
int type; |
|
{ |
{ |
char *bp; |
char *bp; |
const char *cp; |
const char *cp; |
|
|
getent(char **cap, size_t *len, const char * const *db_array, int fd, |
getent(char **cap, size_t *len, const char * const *db_array, int fd, |
const char *name, int depth, char *nfield) |
const char *name, int depth, char *nfield) |
{ |
{ |
#ifndef SMALL |
|
DB *capdbp; |
|
char pbuf[MAXPATHLEN]; |
|
char *cbuf; |
|
int retval; |
|
size_t clen; |
|
#endif |
|
char *record, *newrecord; |
char *record, *newrecord; |
char *r_end, *rp; /* pacify gcc */ |
char *r_end, *rp; /* pacify gcc */ |
const char * const *db_p; |
const char * const *db_p; |
Line 324 getent(char **cap, size_t *len, const ch |
|
Line 319 getent(char **cap, size_t *len, const ch |
|
(void)lseek(fd, (off_t)0, SEEK_SET); |
(void)lseek(fd, (off_t)0, SEEK_SET); |
} else { |
} else { |
#ifndef SMALL |
#ifndef SMALL |
|
DB *capdbp; |
|
char pbuf[MAXPATHLEN]; |
|
char *cbuf; |
|
int retval; |
|
size_t clen; |
|
|
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
(void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); |
if (expandtc && |
if ((capdbp = dbopen(pbuf, O_RDONLY | O_CLOEXEC, 0, |
(capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) |
DB_HASH, 0)) != NULL) { |
!= NULL) { |
|
free(record); |
free(record); |
retval = cdbget(capdbp, &record, name); |
retval = cdbget(capdbp, &record, name); |
if (retval < 0) { |
if (retval < 0) { |
Line 356 getent(char **cap, size_t *len, const ch |
|
Line 356 getent(char **cap, size_t *len, const ch |
|
} else |
} else |
#endif |
#endif |
{ |
{ |
fd = open(*db_p, O_RDONLY, 0); |
fd = open(*db_p, O_RDONLY | O_CLOEXEC, 0); |
if (fd < 0) { |
if (fd < 0) { |
/* No error on unfound file. */ |
/* No error on unfound file. */ |
continue; |
continue; |
Line 393 getent(char **cap, size_t *len, const ch |
|
Line 393 getent(char **cap, size_t *len, const ch |
|
rp = record; |
rp = record; |
for (;;) { |
for (;;) { |
if (bp >= b_end) { |
if (bp >= b_end) { |
int n; |
ssize_t n; |
|
|
n = read(fd, buf, sizeof(buf)); |
n = read(fd, buf, sizeof(buf)); |
if (n <= 0) { |
if (n <= 0) { |
Line 456 getent(char **cap, size_t *len, const ch |
|
Line 456 getent(char **cap, size_t *len, const ch |
|
* some more. |
* some more. |
*/ |
*/ |
if (rp >= r_end) { |
if (rp >= r_end) { |
u_int pos; |
ptrdiff_t pos; |
size_t newsize; |
size_t newsize; |
|
|
pos = rp - record; |
pos = rp - record; |
|
|
if (expandtc) { |
if (expandtc) { |
char *newicap, *s; |
char *newicap, *s; |
size_t ilen, newilen; |
size_t ilen, newilen; |
int diff, iret, tclen; |
int iret; |
|
ptrdiff_t diff, tclen; |
char *icap, *scan, *tc, *tcstart, *tcend; |
char *icap, *scan, *tc, *tcstart, *tcend; |
|
|
/* |
/* |
|
|
*/ |
*/ |
diff = newilen - tclen; |
diff = newilen - tclen; |
if (diff >= r_end - rp) { |
if (diff >= r_end - rp) { |
u_int pos, tcpos, tcposend; |
ptrdiff_t pos, tcpos, tcposend; |
size_t newsize; |
size_t newsize; |
|
|
pos = rp - record; |
pos = rp - record; |
Line 917 cgetstr(char *buf, const char *cap, char |
|
Line 918 cgetstr(char *buf, const char *cap, char |
|
u_int m_room; |
u_int m_room; |
const char *bp; |
const char *bp; |
char *mp; |
char *mp; |
int len; |
ptrdiff_t len; |
char *mem, *newmem; |
char *mem, *newmem; |
|
|
_DIAGASSERT(buf != NULL); |
_DIAGASSERT(buf != NULL); |
Line 1033 cgetstr(char *buf, const char *cap, char |
|
Line 1034 cgetstr(char *buf, const char *cap, char |
|
mem = newmem; |
mem = newmem; |
} |
} |
*str = mem; |
*str = mem; |
return len; |
_DIAGASSERT(__type_fit(int, len)); |
|
return (int)len; |
} |
} |
|
|
/* |
/* |
Line 1052 cgetustr(char *buf, const char *cap, cha |
|
Line 1054 cgetustr(char *buf, const char *cap, cha |
|
u_int m_room; |
u_int m_room; |
const char *bp; |
const char *bp; |
char *mp; |
char *mp; |
int len; |
size_t len; |
char *mem, *newmem; |
char *mem, *newmem; |
|
|
_DIAGASSERT(buf != NULL); |
_DIAGASSERT(buf != NULL); |
Line 1117 cgetustr(char *buf, const char *cap, cha |
|
Line 1119 cgetustr(char *buf, const char *cap, cha |
|
mem = newmem; |
mem = newmem; |
} |
} |
*str = mem; |
*str = mem; |
return len; |
_DIAGASSERT(__type_fit(int, len)); |
|
return (int)len; |
} |
} |
|
|
/* |
/* |