version 1.21, 1998/07/27 07:41:53 |
version 1.32.2.1, 2000/06/23 16:17:25 |
Line 47 __RCSID("$NetBSD$"); |
|
Line 47 __RCSID("$NetBSD$"); |
|
|
|
#include "namespace.h" |
#include "namespace.h" |
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <db.h> |
#include <db.h> |
#include <errno.h> |
#include <errno.h> |
Line 58 __RCSID("$NetBSD$"); |
|
Line 60 __RCSID("$NetBSD$"); |
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#ifdef __weak_alias |
#ifdef __weak_alias |
__weak_alias(cgetcap,_cgetcap); |
__weak_alias(cgetcap,_cgetcap) |
__weak_alias(cgetclose,_cgetclose); |
__weak_alias(cgetclose,_cgetclose) |
__weak_alias(cgetent,_cgetent); |
__weak_alias(cgetent,_cgetent) |
__weak_alias(cgetfirst,_cgetfirst); |
__weak_alias(cgetfirst,_cgetfirst) |
__weak_alias(cgetmatch,_cgetmatch); |
__weak_alias(cgetmatch,_cgetmatch) |
__weak_alias(cgetnext,_cgetnext); |
__weak_alias(cgetnext,_cgetnext) |
__weak_alias(cgetnum,_cgetnum); |
__weak_alias(cgetnum,_cgetnum) |
__weak_alias(cgetset,_cgetset); |
__weak_alias(cgetset,_cgetset) |
__weak_alias(cgetstr,_cgetstr); |
__weak_alias(cgetstr,_cgetstr) |
__weak_alias(cgetustr,_cgetustr); |
__weak_alias(cgetustr,_cgetustr) |
#endif |
#endif |
|
|
#define BFRAG 1024 |
#define BFRAG 1024 |
|
|
cgetset(ent) |
cgetset(ent) |
const char *ent; |
const char *ent; |
{ |
{ |
|
const char *source, *check; |
|
char *dest; |
|
|
if (ent == NULL) { |
if (ent == NULL) { |
if (toprec) |
if (toprec) |
free(toprec); |
free(toprec); |
|
|
return (-1); |
return (-1); |
} |
} |
gottoprec = 0; |
gottoprec = 0; |
(void)strcpy(toprec, ent); /* XXX: strcpy is safe */ |
|
|
source=ent; |
|
dest=toprec; |
|
while (*source) { /* Strip whitespace */ |
|
*dest++ = *source++; /* Do not check first field */ |
|
while (*source == ':') { |
|
check=source+1; |
|
while (*check && (isspace((unsigned char)*check) || |
|
(*check=='\\' && isspace((unsigned char)check[1])))) |
|
++check; |
|
if( *check == ':' ) |
|
source=check; |
|
else |
|
break; |
|
|
|
} |
|
} |
|
*dest=0; |
|
|
return (0); |
return (0); |
} |
} |
|
|
Line 135 cgetcap(buf, cap, type) |
|
Line 158 cgetcap(buf, cap, type) |
|
char *bp; |
char *bp; |
const char *cp; |
const char *cp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
|
bp = buf; |
bp = buf; |
for (;;) { |
for (;;) { |
/* |
/* |
Line 187 cgetent(buf, db_array, name) |
|
Line 213 cgetent(buf, db_array, name) |
|
{ |
{ |
size_t dummy; |
size_t dummy; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
} |
} |
|
|
Line 219 getent(cap, len, db_array, fd, name, dep |
|
Line 249 getent(cap, len, db_array, fd, name, dep |
|
char *r_end, *rp = NULL, **db_p; /* pacify gcc */ |
char *r_end, *rp = NULL, **db_p; /* pacify gcc */ |
int myfd = 0, eof, foundit, retval; |
int myfd = 0, eof, foundit, retval; |
size_t clen; |
size_t clen; |
char *record, *cbuf; |
char *record, *cbuf, *newrecord; |
int tc_not_resolved; |
int tc_not_resolved; |
char pbuf[_POSIX_PATH_MAX]; |
char pbuf[_POSIX_PATH_MAX]; |
|
|
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(len != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
/* fd may be -1 */ |
|
_DIAGASSERT(name != NULL); |
|
/* nfield may be NULL */ |
|
|
/* |
/* |
* Return with ``loop detected'' error if we've recursed more than |
* Return with ``loop detected'' error if we've recursed more than |
* MAX_RECURSION times. |
* MAX_RECURSION times. |
Line 280 getent(cap, len, db_array, fd, name, dep |
|
Line 317 getent(cap, len, db_array, fd, name, dep |
|
/* save the data; close frees it */ |
/* save the data; close frees it */ |
clen = strlen(record); |
clen = strlen(record); |
cbuf = malloc(clen + 1); |
cbuf = malloc(clen + 1); |
memcpy(cbuf, record, clen + 1); |
memmove(cbuf, record, clen + 1); |
if (capdbp->close(capdbp) < 0) { |
if (capdbp->close(capdbp) < 0) { |
|
int serrno = errno; |
|
|
free(cbuf); |
free(cbuf); |
|
errno = serrno; |
return (-2); |
return (-2); |
} |
} |
*len = clen; |
*len = clen; |
Line 334 getent(cap, len, db_array, fd, name, dep |
|
Line 374 getent(cap, len, db_array, fd, name, dep |
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
if (n < 0) { |
if (n < 0) { |
|
int serrno = errno; |
|
|
free(record); |
free(record); |
|
errno = serrno; |
return (-2); |
return (-2); |
} else { |
} else { |
fd = -1; |
fd = -1; |
Line 392 getent(cap, len, db_array, fd, name, dep |
|
Line 435 getent(cap, len, db_array, fd, name, dep |
|
|
|
pos = rp - record; |
pos = rp - record; |
newsize = r_end - record + BFRAG; |
newsize = r_end - record + BFRAG; |
record = realloc(record, newsize); |
newrecord = realloc(record, newsize); |
if (record == NULL) { |
if (newrecord == NULL) { |
errno = ENOMEM; |
free(record); |
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
r_end = record + newsize; |
r_end = record + newsize; |
rp = record + pos; |
rp = record + pos; |
} |
} |
|
|
newsize = r_end - record + diff + BFRAG; |
newsize = r_end - record + diff + BFRAG; |
tcpos = tcstart - record; |
tcpos = tcstart - record; |
tcposend = tcend - record; |
tcposend = tcend - record; |
record = realloc(record, newsize); |
newrecord = realloc(record, newsize); |
if (record == NULL) { |
if (newrecord == NULL) { |
errno = ENOMEM; |
free(record); |
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
free(icap); |
free(icap); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
r_end = record + newsize; |
r_end = record + newsize; |
rp = record + pos; |
rp = record + pos; |
tcstart = record + tcpos; |
tcstart = record + tcpos; |
|
|
* Insert tc'ed record into our record. |
* Insert tc'ed record into our record. |
*/ |
*/ |
s = tcstart + newilen; |
s = tcstart + newilen; |
bcopy(tcend, s, (size_t)(rp - tcend)); |
memmove(s, tcend, (size_t)(rp - tcend)); |
bcopy(newicap, tcstart, newilen); |
memmove(tcstart, newicap, newilen); |
rp += diff; |
rp += diff; |
free(icap); |
free(icap); |
|
|
|
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
*len = rp - record - 1; /* don't count NUL */ |
*len = rp - record - 1; /* don't count NUL */ |
if (r_end > rp) |
if (r_end > rp) { |
if ((record = |
if ((newrecord = |
realloc(record, (size_t)(rp - record))) == NULL) { |
realloc(record, (size_t)(rp - record))) == NULL) { |
|
free(record); |
errno = ENOMEM; |
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
|
record = newrecord; |
|
} |
|
|
*cap = record; |
*cap = record; |
if (tc_not_resolved) |
if (tc_not_resolved) |
Line 591 cdbget(capdbp, bp, name) |
|
Line 641 cdbget(capdbp, bp, name) |
|
char **bp; |
char **bp; |
const char *name; |
const char *name; |
{ |
{ |
DBT key, data; |
DBT key; |
|
DBT data; |
|
|
|
_DIAGASSERT(capdbp != NULL); |
|
_DIAGASSERT(bp != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
|
/* LINTED key is not modified */ |
key.data = (char *)name; |
key.data = (char *)name; |
key.size = strlen(name); |
key.size = strlen(name); |
|
|
Line 627 cgetmatch(buf, name) |
|
Line 683 cgetmatch(buf, name) |
|
{ |
{ |
const char *np, *bp; |
const char *np, *bp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
/* |
/* |
* Start search at beginning of record. |
* Start search at beginning of record. |
*/ |
*/ |
Line 637 cgetmatch(buf, name) |
|
Line 696 cgetmatch(buf, name) |
|
*/ |
*/ |
np = name; |
np = name; |
for (;;) |
for (;;) |
if (*np == '\0') |
if (*np == '\0') { |
if (*bp == '|' || *bp == ':' || *bp == '\0') |
if (*bp == '|' || *bp == ':' || *bp == '\0') |
return (0); |
return (0); |
else |
else |
break; |
break; |
else |
} else |
if (*bp++ != *np++) |
if (*bp++ != *np++) |
break; |
break; |
|
|
|
|
cgetfirst(buf, db_array) |
cgetfirst(buf, db_array) |
char **buf, **db_array; |
char **buf, **db_array; |
{ |
{ |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
|
(void)cgetclose(); |
(void)cgetclose(); |
return (cgetnext(buf, db_array)); |
return (cgetnext(buf, db_array)); |
} |
} |
Line 699 cgetnext(bp, db_array) |
|
Line 762 cgetnext(bp, db_array) |
|
char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; |
char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; |
size_t dummy; |
size_t dummy; |
|
|
|
_DIAGASSERT(bp != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
|
if (dbp == NULL) |
if (dbp == NULL) |
dbp = db_array; |
dbp = db_array; |
|
|
Line 735 cgetnext(bp, db_array) |
|
Line 801 cgetnext(bp, db_array) |
|
slash = 0; |
slash = 0; |
continue; |
continue; |
} |
} |
if (isspace(*line) || |
if (isspace((unsigned char)*line) || |
*line == ':' || *line == '#' || slash) { |
*line == ':' || *line == '#' || slash) { |
if (line[len - 2] == '\\') |
if (line[len - 2] == '\\') |
slash = 1; |
slash = 1; |
Line 828 cgetstr(buf, cap, str) |
|
Line 894 cgetstr(buf, cap, str) |
|
const char *bp; |
const char *bp; |
char *mp; |
char *mp; |
int len; |
int len; |
char *mem; |
char *mem, *newmem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
Line 915 cgetstr(buf, cap, str) |
|
Line 985 cgetstr(buf, cap, str) |
|
if (m_room == 0) { |
if (m_room == 0) { |
size_t size = mp - mem; |
size_t size = mp - mem; |
|
|
if ((mem = realloc(mem, size + SFRAG)) == NULL) |
if ((newmem = realloc(mem, size + SFRAG)) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
m_room = SFRAG; |
m_room = SFRAG; |
mp = mem + size; |
mp = mem + size; |
} |
} |
Line 928 cgetstr(buf, cap, str) |
|
Line 1001 cgetstr(buf, cap, str) |
|
/* |
/* |
* Give back any extra memory and return value and success. |
* Give back any extra memory and return value and success. |
*/ |
*/ |
if (m_room != 0) |
if (m_room != 0) { |
if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) |
if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
|
} |
*str = mem; |
*str = mem; |
return (len); |
return (len); |
} |
} |
Line 955 cgetustr(buf, cap, str) |
|
Line 1032 cgetustr(buf, cap, str) |
|
const char *bp; |
const char *bp; |
char *mp; |
char *mp; |
int len; |
int len; |
char *mem; |
char *mem, *newmem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
Line 991 cgetustr(buf, cap, str) |
|
Line 1072 cgetustr(buf, cap, str) |
|
if (m_room == 0) { |
if (m_room == 0) { |
size_t size = mp - mem; |
size_t size = mp - mem; |
|
|
if ((mem = realloc(mem, size + SFRAG)) == NULL) |
if ((newmem = realloc(mem, size + SFRAG)) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
m_room = SFRAG; |
m_room = SFRAG; |
mp = mem + size; |
mp = mem + size; |
} |
} |
Line 1004 cgetustr(buf, cap, str) |
|
Line 1088 cgetustr(buf, cap, str) |
|
/* |
/* |
* Give back any extra memory and return value and success. |
* Give back any extra memory and return value and success. |
*/ |
*/ |
if (m_room != 0) |
if (m_room != 0) { |
if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) |
if ((newmem = realloc(mem, (size_t)(mp - mem))) == NULL) { |
|
free(mem); |
return (-2); |
return (-2); |
|
} |
|
mem = newmem; |
|
} |
*str = mem; |
*str = mem; |
return (len); |
return (len); |
} |
} |
Line 1027 cgetnum(buf, cap, num) |
|
Line 1115 cgetnum(buf, cap, num) |
|
int base, digit; |
int base, digit; |
const char *bp; |
const char *bp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(num != NULL); |
|
|
/* |
/* |
* Find numeric capability cap |
* Find numeric capability cap |
*/ |
*/ |
|
|
{ |
{ |
char *cp, tmp; |
char *cp, tmp; |
int ret; |
int ret; |
|
|
|
_DIAGASSERT(nf != NULL); |
|
_DIAGASSERT(rec != NULL); |
|
|
for (cp = rec; *cp != ':'; cp++) |
for (cp = rec; *cp != ':'; cp++) |
; |
; |
|
|