version 1.29, 1999/03/29 09:27:29 |
version 1.30, 1999/09/16 11:44:57 |
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 156 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); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || cap == NULL) |
|
return (NULL); |
|
#endif |
|
|
bp = buf; |
bp = buf; |
for (;;) { |
for (;;) { |
/* |
/* |
Line 208 cgetent(buf, db_array, name) |
|
Line 217 cgetent(buf, db_array, name) |
|
{ |
{ |
size_t dummy; |
size_t dummy; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
_DIAGASSERT(name != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || db_array == NULL || name == NULL) { |
|
errno = EFAULT; |
|
return (-2); |
|
} |
|
#endif |
|
|
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); |
} |
} |
|
|
Line 244 getent(cap, len, db_array, fd, name, dep |
|
Line 263 getent(cap, len, db_array, fd, name, dep |
|
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 303 getent(cap, len, db_array, fd, name, dep |
|
Line 329 getent(cap, len, db_array, fd, name, dep |
|
cbuf = malloc(clen + 1); |
cbuf = malloc(clen + 1); |
memmove(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 355 getent(cap, len, db_array, fd, name, dep |
|
Line 384 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 415 getent(cap, len, db_array, fd, name, dep |
|
Line 447 getent(cap, len, db_array, fd, name, dep |
|
newsize = r_end - record + BFRAG; |
newsize = r_end - record + BFRAG; |
record = realloc(record, newsize); |
record = realloc(record, newsize); |
if (record == NULL) { |
if (record == NULL) { |
errno = ENOMEM; |
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
r_end = record + newsize; |
r_end = record + newsize; |
|
|
tcposend = tcend - record; |
tcposend = tcend - record; |
record = realloc(record, newsize); |
record = realloc(record, newsize); |
if (record == NULL) { |
if (record == NULL) { |
errno = ENOMEM; |
|
if (myfd) |
if (myfd) |
(void)close(fd); |
(void)close(fd); |
free(icap); |
free(icap); |
|
errno = ENOMEM; |
return (-2); |
return (-2); |
} |
} |
r_end = record + newsize; |
r_end = record + newsize; |
Line 615 cdbget(capdbp, bp, name) |
|
Line 647 cdbget(capdbp, bp, name) |
|
DBT key; |
DBT key; |
DBT data; |
DBT data; |
|
|
|
_DIAGASSERT(capdbp != NULL); |
|
_DIAGASSERT(bp != NULL); |
|
_DIAGASSERT(name != NULL); |
|
|
/* LINTED key is not modified */ |
/* LINTED key is not modified */ |
key.data = (char *)name; |
key.data = (char *)name; |
key.size = strlen(name); |
key.size = strlen(name); |
Line 650 cgetmatch(buf, name) |
|
Line 686 cgetmatch(buf, name) |
|
{ |
{ |
const char *np, *bp; |
const char *np, *bp; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(name != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || name == NULL) |
|
return (-1); |
|
#endif |
|
|
/* |
/* |
* Start search at beginning of record. |
* Start search at beginning of record. |
*/ |
*/ |
|
|
cgetfirst(buf, db_array) |
cgetfirst(buf, db_array) |
char **buf, **db_array; |
char **buf, **db_array; |
{ |
{ |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(db_array != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || db_array == NULL) { |
|
errno = EFAULT; |
|
return (-2); |
|
} |
|
#endif |
|
|
(void)cgetclose(); |
(void)cgetclose(); |
return (cgetnext(buf, db_array)); |
return (cgetnext(buf, db_array)); |
} |
} |
Line 722 cgetnext(bp, db_array) |
|
Line 775 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); |
|
#ifdef _DIAGNOSTIC |
|
if (bp == NULL || db_array == NULL) { |
|
errno = EFAULT; |
|
return (-2); |
|
} |
|
#endif |
|
|
if (dbp == NULL) |
if (dbp == NULL) |
dbp = db_array; |
dbp = db_array; |
|
|
Line 853 cgetstr(buf, cap, str) |
|
Line 915 cgetstr(buf, cap, str) |
|
int len; |
int len; |
char *mem; |
char *mem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || cap == NULL || str == NULL) { |
|
errno = EFAULT; |
|
return (-2); |
|
} |
|
#endif |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
*/ |
*/ |
Line 980 cgetustr(buf, cap, str) |
|
Line 1052 cgetustr(buf, cap, str) |
|
int len; |
int len; |
char *mem; |
char *mem; |
|
|
|
_DIAGASSERT(buf != NULL); |
|
_DIAGASSERT(cap != NULL); |
|
_DIAGASSERT(str != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || cap == NULL || str == NULL) { |
|
errno = EFAULT; |
|
return (-2); |
|
} |
|
#endif |
|
|
/* |
/* |
* Find string capability cap |
* Find string capability cap |
*/ |
*/ |
Line 1050 cgetnum(buf, cap, num) |
|
Line 1132 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); |
|
#ifdef _DIAGNOSTIC |
|
if (buf == NULL || cap == NULL || num == NULL) |
|
return (-1); |
|
#endif |
|
|
/* |
/* |
* 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++) |
; |
; |
|
|